1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2017 Free Software Foundation, Inc.
4 Parser actions based on the old Bison parser; structure somewhat
5 influenced by and fragments based on the C++ parser.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 Make sure all relevant comments, and all relevant code from all
26 actions, brought over from old parser. Verify exact correspondence
29 Add testcases covering every input symbol in every state in old and
32 Include full syntax for GNU C, including erroneous cases accepted
33 with error messages, in syntax productions in comments.
35 Make more diagnostics in the front end generally take an explicit
36 location rather than implicitly using input_location. */
39 #define INCLUDE_UNIQUE_PTR
41 #include "coretypes.h"
46 #include "stringpool.h"
49 #include "stor-layout.h"
51 #include "trans-mem.h"
52 #include "c-family/c-pragma.h"
54 #include "c-family/c-objc.h"
56 #include "omp-general.h"
57 #include "omp-offload.h"
59 #include "gomp-constants.h"
60 #include "c-family/c-indentation.h"
61 #include "gimple-expr.h"
63 #include "gcc-rich-location.h"
65 #include "gimple-parser.h"
66 #include "read-rtl-function.h"
67 #include "run-rtl-passes.h"
69 #include "c-family/name-hint.h"
70 #include "tree-iterator.h"
72 /* We need to walk over decls with incomplete struct/union/enum types
73 after parsing the whole translation unit.
74 In finish_decl(), if the decl is static, has incomplete
75 struct/union/enum type, it is appeneded to incomplete_record_decls.
76 In c_parser_translation_unit(), we iterate over incomplete_record_decls
77 and report error if any of the decls are still incomplete. */
79 vec
<tree
> incomplete_record_decls
;
82 set_c_expr_source_range (c_expr
*expr
,
83 location_t start
, location_t finish
)
85 expr
->src_range
.m_start
= start
;
86 expr
->src_range
.m_finish
= finish
;
88 set_source_range (expr
->value
, start
, finish
);
92 set_c_expr_source_range (c_expr
*expr
,
93 source_range src_range
)
95 expr
->src_range
= src_range
;
97 set_source_range (expr
->value
, src_range
);
101 /* Initialization routine for this file. */
106 /* The only initialization required is of the reserved word
112 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
113 the c_token structure. */
114 gcc_assert (RID_MAX
<= 255);
121 mask
|= D_ASM
| D_EXT
;
125 if (!c_dialect_objc ())
126 mask
|= D_OBJC
| D_CXX_OBJC
;
128 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
129 for (i
= 0; i
< num_c_common_reswords
; i
++)
131 /* If a keyword is disabled, do not enter it into the table
132 and so create a canonical spelling that isn't a keyword. */
133 if (c_common_reswords
[i
].disable
& mask
)
136 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
138 id
= get_identifier (c_common_reswords
[i
].word
);
139 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
140 C_IS_RESERVED_WORD (id
) = 1;
145 id
= get_identifier (c_common_reswords
[i
].word
);
146 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
147 C_IS_RESERVED_WORD (id
) = 1;
148 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
151 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
153 /* We always create the symbols but they aren't always supported. */
155 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
156 id
= get_identifier (name
);
157 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
158 C_IS_RESERVED_WORD (id
) = 1;
162 /* A parser structure recording information about the state and
163 context of parsing. Includes lexer information with up to two
164 tokens of look-ahead; more are not needed for C. */
165 struct GTY(()) c_parser
{
166 /* The look-ahead tokens. */
167 c_token
* GTY((skip
)) tokens
;
168 /* Buffer for look-ahead tokens. */
169 c_token tokens_buf
[4];
170 /* How many look-ahead tokens are available (0 - 4, or
171 more if parsing from pre-lexed tokens). */
172 unsigned int tokens_avail
;
173 /* True if a syntax error is being recovered from; false otherwise.
174 c_parser_error sets this flag. It should clear this flag when
175 enough tokens have been consumed to recover from the error. */
176 BOOL_BITFIELD error
: 1;
177 /* True if we're processing a pragma, and shouldn't automatically
178 consume CPP_PRAGMA_EOL. */
179 BOOL_BITFIELD in_pragma
: 1;
180 /* True if we're parsing the outermost block of an if statement. */
181 BOOL_BITFIELD in_if_block
: 1;
182 /* True if we want to lex an untranslated string. */
183 BOOL_BITFIELD lex_untranslated_string
: 1;
185 /* Objective-C specific parser/lexer information. */
187 /* True if we are in a context where the Objective-C "PQ" keywords
188 are considered keywords. */
189 BOOL_BITFIELD objc_pq_context
: 1;
190 /* True if we are parsing a (potential) Objective-C foreach
191 statement. This is set to true after we parsed 'for (' and while
192 we wait for 'in' or ';' to decide if it's a standard C for loop or an
193 Objective-C foreach loop. */
194 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
195 /* The following flag is needed to contextualize Objective-C lexical
196 analysis. In some cases (e.g., 'int NSObject;'), it is
197 undesirable to bind an identifier to an Objective-C class, even
198 if a class with that name exists. */
199 BOOL_BITFIELD objc_need_raw_identifier
: 1;
200 /* Nonzero if we're processing a __transaction statement. The value
201 is 1 | TM_STMT_ATTR_*. */
202 unsigned int in_transaction
: 4;
203 /* True if we are in a context where the Objective-C "Property attribute"
204 keywords are valid. */
205 BOOL_BITFIELD objc_property_attr_context
: 1;
207 /* Location of the last consumed token. */
208 location_t last_token_location
;
211 /* Return a pointer to the Nth token in PARSERs tokens_buf. */
214 c_parser_tokens_buf (c_parser
*parser
, unsigned n
)
216 return &parser
->tokens_buf
[n
];
219 /* Return the error state of PARSER. */
222 c_parser_error (c_parser
*parser
)
224 return parser
->error
;
227 /* Set the error state of PARSER to ERR. */
230 c_parser_set_error (c_parser
*parser
, bool err
)
236 /* The actual parser and external interface. ??? Does this need to be
237 garbage-collected? */
239 static GTY (()) c_parser
*the_parser
;
241 /* Read in and lex a single token, storing it in *TOKEN. */
244 c_lex_one_token (c_parser
*parser
, c_token
*token
)
246 timevar_push (TV_LEX
);
248 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
,
250 (parser
->lex_untranslated_string
251 ? C_LEX_STRING_NO_TRANSLATE
: 0));
252 token
->id_kind
= C_ID_NONE
;
253 token
->keyword
= RID_MAX
;
254 token
->pragma_kind
= PRAGMA_NONE
;
262 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
263 if (c_dialect_objc ())
264 parser
->objc_need_raw_identifier
= false;
266 if (C_IS_RESERVED_WORD (token
->value
))
268 enum rid rid_code
= C_RID_CODE (token
->value
);
270 if (rid_code
== RID_CXX_COMPAT_WARN
)
272 warning_at (token
->location
,
274 "identifier %qE conflicts with C++ keyword",
277 else if (rid_code
>= RID_FIRST_ADDR_SPACE
278 && rid_code
<= RID_LAST_ADDR_SPACE
)
281 as
= (addr_space_t
) (rid_code
- RID_FIRST_ADDR_SPACE
);
282 targetm
.addr_space
.diagnose_usage (as
, token
->location
);
283 token
->id_kind
= C_ID_ADDRSPACE
;
284 token
->keyword
= rid_code
;
287 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
289 /* We found an Objective-C "pq" keyword (in, out,
290 inout, bycopy, byref, oneway). They need special
291 care because the interpretation depends on the
293 if (parser
->objc_pq_context
)
295 token
->type
= CPP_KEYWORD
;
296 token
->keyword
= rid_code
;
299 else if (parser
->objc_could_be_foreach_context
300 && rid_code
== RID_IN
)
302 /* We are in Objective-C, inside a (potential)
303 foreach context (which means after having
304 parsed 'for (', but before having parsed ';'),
305 and we found 'in'. We consider it the keyword
306 which terminates the declaration at the
307 beginning of a foreach-statement. Note that
308 this means you can't use 'in' for anything else
309 in that context; in particular, in Objective-C
310 you can't use 'in' as the name of the running
311 variable in a C for loop. We could potentially
312 try to add code here to disambiguate, but it
313 seems a reasonable limitation. */
314 token
->type
= CPP_KEYWORD
;
315 token
->keyword
= rid_code
;
318 /* Else, "pq" keywords outside of the "pq" context are
319 not keywords, and we fall through to the code for
322 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
324 /* We found an Objective-C "property attribute"
325 keyword (getter, setter, readonly, etc). These are
326 only valid in the property context. */
327 if (parser
->objc_property_attr_context
)
329 token
->type
= CPP_KEYWORD
;
330 token
->keyword
= rid_code
;
333 /* Else they are not special keywords.
336 else if (c_dialect_objc ()
337 && (OBJC_IS_AT_KEYWORD (rid_code
)
338 || OBJC_IS_CXX_KEYWORD (rid_code
)))
340 /* We found one of the Objective-C "@" keywords (defs,
341 selector, synchronized, etc) or one of the
342 Objective-C "cxx" keywords (class, private,
343 protected, public, try, catch, throw) without a
344 preceding '@' sign. Do nothing and fall through to
345 the code for normal tokens (in C++ we would still
346 consider the CXX ones keywords, but not in C). */
351 token
->type
= CPP_KEYWORD
;
352 token
->keyword
= rid_code
;
357 decl
= lookup_name (token
->value
);
360 if (TREE_CODE (decl
) == TYPE_DECL
)
362 token
->id_kind
= C_ID_TYPENAME
;
366 else if (c_dialect_objc ())
368 tree objc_interface_decl
= objc_is_class_name (token
->value
);
369 /* Objective-C class names are in the same namespace as
370 variables and typedefs, and hence are shadowed by local
372 if (objc_interface_decl
373 && (!objc_force_identifier
|| global_bindings_p ()))
375 token
->value
= objc_interface_decl
;
376 token
->id_kind
= C_ID_CLASSNAME
;
380 token
->id_kind
= C_ID_ID
;
384 /* This only happens in Objective-C; it must be a keyword. */
385 token
->type
= CPP_KEYWORD
;
386 switch (C_RID_CODE (token
->value
))
388 /* Replace 'class' with '@class', 'private' with '@private',
389 etc. This prevents confusion with the C++ keyword
390 'class', and makes the tokens consistent with other
391 Objective-C 'AT' keywords. For example '@class' is
392 reported as RID_AT_CLASS which is consistent with
393 '@synchronized', which is reported as
396 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
397 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
398 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
399 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
400 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
401 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
402 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
403 case RID_SYNCHRONIZED
: token
->keyword
= RID_AT_SYNCHRONIZED
; break;
404 default: token
->keyword
= C_RID_CODE (token
->value
);
409 case CPP_CLOSE_PAREN
:
411 /* These tokens may affect the interpretation of any identifiers
412 following, if doing Objective-C. */
413 if (c_dialect_objc ())
414 parser
->objc_need_raw_identifier
= false;
417 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
418 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
424 timevar_pop (TV_LEX
);
427 /* Return a pointer to the next token from PARSER, reading it in if
431 c_parser_peek_token (c_parser
*parser
)
433 if (parser
->tokens_avail
== 0)
435 c_lex_one_token (parser
, &parser
->tokens
[0]);
436 parser
->tokens_avail
= 1;
438 return &parser
->tokens
[0];
441 /* Return a pointer to the next-but-one token from PARSER, reading it
442 in if necessary. The next token is already read in. */
445 c_parser_peek_2nd_token (c_parser
*parser
)
447 if (parser
->tokens_avail
>= 2)
448 return &parser
->tokens
[1];
449 gcc_assert (parser
->tokens_avail
== 1);
450 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
451 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
452 c_lex_one_token (parser
, &parser
->tokens
[1]);
453 parser
->tokens_avail
= 2;
454 return &parser
->tokens
[1];
457 /* Return a pointer to the Nth token from PARSER, reading it
458 in if necessary. The N-1th token is already read in. */
461 c_parser_peek_nth_token (c_parser
*parser
, unsigned int n
)
463 /* N is 1-based, not zero-based. */
466 if (parser
->tokens_avail
>= n
)
467 return &parser
->tokens
[n
- 1];
468 gcc_assert (parser
->tokens_avail
== n
- 1);
469 c_lex_one_token (parser
, &parser
->tokens
[n
- 1]);
470 parser
->tokens_avail
= n
;
471 return &parser
->tokens
[n
- 1];
475 c_keyword_starts_typename (enum rid keyword
)
510 if (keyword
>= RID_FIRST_INT_N
511 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
512 && int_n_enabled_p
[keyword
- RID_FIRST_INT_N
])
518 /* Return true if TOKEN can start a type name,
521 c_token_starts_typename (c_token
*token
)
526 switch (token
->id_kind
)
535 gcc_assert (c_dialect_objc ());
541 return c_keyword_starts_typename (token
->keyword
);
543 if (c_dialect_objc ())
551 /* Return true if the next token from PARSER can start a type name,
552 false otherwise. LA specifies how to do lookahead in order to
553 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
556 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
558 c_token
*token
= c_parser_peek_token (parser
);
559 if (c_token_starts_typename (token
))
562 /* Try a bit harder to detect an unknown typename. */
563 if (la
!= cla_prefer_id
564 && token
->type
== CPP_NAME
565 && token
->id_kind
== C_ID_ID
567 /* Do not try too hard when we could have "object in array". */
568 && !parser
->objc_could_be_foreach_context
570 && (la
== cla_prefer_type
571 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
572 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
574 /* Only unknown identifiers. */
575 && !lookup_name (token
->value
))
581 /* Return true if TOKEN is a type qualifier, false otherwise. */
583 c_token_is_qualifier (c_token
*token
)
588 switch (token
->id_kind
)
596 switch (token
->keyword
)
614 /* Return true if the next token from PARSER is a type qualifier,
617 c_parser_next_token_is_qualifier (c_parser
*parser
)
619 c_token
*token
= c_parser_peek_token (parser
);
620 return c_token_is_qualifier (token
);
623 /* Return true if TOKEN can start declaration specifiers, false
626 c_token_starts_declspecs (c_token
*token
)
631 switch (token
->id_kind
)
640 gcc_assert (c_dialect_objc ());
646 switch (token
->keyword
)
687 if (token
->keyword
>= RID_FIRST_INT_N
688 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
689 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
694 if (c_dialect_objc ())
703 /* Return true if TOKEN can start declaration specifiers or a static
704 assertion, false otherwise. */
706 c_token_starts_declaration (c_token
*token
)
708 if (c_token_starts_declspecs (token
)
709 || token
->keyword
== RID_STATIC_ASSERT
)
715 /* Return true if the next token from PARSER can start declaration
716 specifiers, false otherwise. */
718 c_parser_next_token_starts_declspecs (c_parser
*parser
)
720 c_token
*token
= c_parser_peek_token (parser
);
722 /* In Objective-C, a classname normally starts a declspecs unless it
723 is immediately followed by a dot. In that case, it is the
724 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
725 setter/getter on the class. c_token_starts_declspecs() can't
726 differentiate between the two cases because it only checks the
727 current token, so we have a special check here. */
728 if (c_dialect_objc ()
729 && token
->type
== CPP_NAME
730 && token
->id_kind
== C_ID_CLASSNAME
731 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
734 return c_token_starts_declspecs (token
);
737 /* Return true if the next tokens from PARSER can start declaration
738 specifiers or a static assertion, false otherwise. */
740 c_parser_next_tokens_start_declaration (c_parser
*parser
)
742 c_token
*token
= c_parser_peek_token (parser
);
745 if (c_dialect_objc ()
746 && token
->type
== CPP_NAME
747 && token
->id_kind
== C_ID_CLASSNAME
748 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
751 /* Labels do not start declarations. */
752 if (token
->type
== CPP_NAME
753 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
756 if (c_token_starts_declaration (token
))
759 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
765 /* Consume the next token from PARSER. */
768 c_parser_consume_token (c_parser
*parser
)
770 gcc_assert (parser
->tokens_avail
>= 1);
771 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
772 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
773 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
774 parser
->last_token_location
= parser
->tokens
[0].location
;
775 if (parser
->tokens
!= &parser
->tokens_buf
[0])
777 else if (parser
->tokens_avail
== 2)
778 parser
->tokens
[0] = parser
->tokens
[1];
779 parser
->tokens_avail
--;
782 /* Expect the current token to be a #pragma. Consume it and remember
783 that we've begun parsing a pragma. */
786 c_parser_consume_pragma (c_parser
*parser
)
788 gcc_assert (!parser
->in_pragma
);
789 gcc_assert (parser
->tokens_avail
>= 1);
790 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
791 if (parser
->tokens
!= &parser
->tokens_buf
[0])
793 else if (parser
->tokens_avail
== 2)
794 parser
->tokens
[0] = parser
->tokens
[1];
795 parser
->tokens_avail
--;
796 parser
->in_pragma
= true;
799 /* Update the global input_location from TOKEN. */
801 c_parser_set_source_position_from_token (c_token
*token
)
803 if (token
->type
!= CPP_EOF
)
805 input_location
= token
->location
;
809 /* Helper function for c_parser_error.
810 Having peeked a token of kind TOK1_KIND that might signify
811 a conflict marker, peek successor tokens to determine
812 if we actually do have a conflict marker.
813 Specifically, we consider a run of 7 '<', '=' or '>' characters
814 at the start of a line as a conflict marker.
815 These come through the lexer as three pairs and a single,
816 e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<').
817 If it returns true, *OUT_LOC is written to with the location/range
821 c_parser_peek_conflict_marker (c_parser
*parser
, enum cpp_ttype tok1_kind
,
824 c_token
*token2
= c_parser_peek_2nd_token (parser
);
825 if (token2
->type
!= tok1_kind
)
827 c_token
*token3
= c_parser_peek_nth_token (parser
, 3);
828 if (token3
->type
!= tok1_kind
)
830 c_token
*token4
= c_parser_peek_nth_token (parser
, 4);
831 if (token4
->type
!= conflict_marker_get_final_tok_kind (tok1_kind
))
834 /* It must be at the start of the line. */
835 location_t start_loc
= c_parser_peek_token (parser
)->location
;
836 if (LOCATION_COLUMN (start_loc
) != 1)
839 /* We have a conflict marker. Construct a location of the form:
842 with start == caret, finishing at the end of the marker. */
843 location_t finish_loc
= get_finish (token4
->location
);
844 *out_loc
= make_location (start_loc
, start_loc
, finish_loc
);
849 /* Issue a diagnostic of the form
850 FILE:LINE: MESSAGE before TOKEN
851 where TOKEN is the next token in the input stream of PARSER.
852 MESSAGE (specified by the caller) is usually of the form "expected
855 Use RICHLOC as the location of the diagnostic.
857 Do not issue a diagnostic if still recovering from an error.
859 Return true iff an error was actually emitted.
861 ??? This is taken from the C++ parser, but building up messages in
862 this way is not i18n-friendly and some other approach should be
866 c_parser_error_richloc (c_parser
*parser
, const char *gmsgid
,
867 rich_location
*richloc
)
869 c_token
*token
= c_parser_peek_token (parser
);
872 parser
->error
= true;
876 /* If this is actually a conflict marker, report it as such. */
877 if (token
->type
== CPP_LSHIFT
878 || token
->type
== CPP_RSHIFT
879 || token
->type
== CPP_EQ_EQ
)
882 if (c_parser_peek_conflict_marker (parser
, token
->type
, &loc
))
884 error_at (loc
, "version control conflict marker in file");
889 c_parse_error (gmsgid
,
890 /* Because c_parse_error does not understand
891 CPP_KEYWORD, keywords are treated like
893 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
894 /* ??? The C parser does not save the cpp flags of a
895 token, we need to pass 0 here and we will not get
896 the source spelling of some tokens but rather the
897 canonical spelling. */
898 token
->value
, /*flags=*/0, richloc
);
902 /* As c_parser_error_richloc, but issue the message at the
903 location of PARSER's next token, or at input_location
904 if the next token is EOF. */
907 c_parser_error (c_parser
*parser
, const char *gmsgid
)
909 c_token
*token
= c_parser_peek_token (parser
);
910 c_parser_set_source_position_from_token (token
);
911 rich_location
richloc (line_table
, input_location
);
912 return c_parser_error_richloc (parser
, gmsgid
, &richloc
);
915 /* Some tokens naturally come in pairs e.g.'(' and ')'.
916 This class is for tracking such a matching pair of symbols.
917 In particular, it tracks the location of the first token,
918 so that if the second token is missing, we can highlight the
919 location of the first token when notifying the user about the
922 template <typename traits_t
>
926 /* token_pair's ctor. */
927 token_pair () : m_open_loc (UNKNOWN_LOCATION
) {}
929 /* If the next token is the opening symbol for this pair, consume it and
931 Otherwise, issue an error and return false.
932 In either case, record the location of the opening token. */
934 bool require_open (c_parser
*parser
)
936 c_token
*token
= c_parser_peek_token (parser
);
938 m_open_loc
= token
->location
;
940 return c_parser_require (parser
, traits_t::open_token_type
,
941 traits_t::open_gmsgid
);
944 /* Consume the next token from PARSER, recording its location as
945 that of the opening token within the pair. */
947 void consume_open (c_parser
*parser
)
949 c_token
*token
= c_parser_peek_token (parser
);
950 gcc_assert (token
->type
== traits_t::open_token_type
);
951 m_open_loc
= token
->location
;
952 c_parser_consume_token (parser
);
955 /* If the next token is the closing symbol for this pair, consume it
957 Otherwise, issue an error, highlighting the location of the
958 corresponding opening token, and return false. */
960 bool require_close (c_parser
*parser
) const
962 return c_parser_require (parser
, traits_t::close_token_type
,
963 traits_t::close_gmsgid
, m_open_loc
);
966 /* Like token_pair::require_close, except that tokens will be skipped
967 until the desired token is found. An error message is still produced
968 if the next token is not as expected. */
970 void skip_until_found_close (c_parser
*parser
) const
972 c_parser_skip_until_found (parser
, traits_t::close_token_type
,
973 traits_t::close_gmsgid
, m_open_loc
);
977 location_t m_open_loc
;
980 /* Traits for token_pair<T> for tracking matching pairs of parentheses. */
982 struct matching_paren_traits
984 static const enum cpp_ttype open_token_type
= CPP_OPEN_PAREN
;
985 static const char * const open_gmsgid
;
986 static const enum cpp_ttype close_token_type
= CPP_CLOSE_PAREN
;
987 static const char * const close_gmsgid
;
990 const char * const matching_paren_traits::open_gmsgid
= "expected %<(%>";
991 const char * const matching_paren_traits::close_gmsgid
= "expected %<)%>";
993 /* "matching_parens" is a token_pair<T> class for tracking matching
994 pairs of parentheses. */
996 typedef token_pair
<matching_paren_traits
> matching_parens
;
998 /* Traits for token_pair<T> for tracking matching pairs of braces. */
1000 struct matching_brace_traits
1002 static const enum cpp_ttype open_token_type
= CPP_OPEN_BRACE
;
1003 static const char * const open_gmsgid
;
1004 static const enum cpp_ttype close_token_type
= CPP_CLOSE_BRACE
;
1005 static const char * const close_gmsgid
;
1008 const char * const matching_brace_traits::open_gmsgid
= "expected %<{%>";
1009 const char * const matching_brace_traits::close_gmsgid
= "expected %<}%>";
1011 /* "matching_braces" is a token_pair<T> class for tracking matching
1014 typedef token_pair
<matching_brace_traits
> matching_braces
;
1016 /* Get a description of the matching symbol to TYPE e.g. "(" for
1020 get_matching_symbol (enum cpp_ttype type
)
1027 case CPP_CLOSE_PAREN
:
1029 case CPP_CLOSE_BRACE
:
1034 /* If the next token is of the indicated TYPE, consume it. Otherwise,
1035 issue the error MSGID. If MSGID is NULL then a message has already
1036 been produced and no message will be produced this time. Returns
1037 true if found, false otherwise.
1039 If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1040 within any error as the location of an "opening" token matching
1041 the close token TYPE (e.g. the location of the '(' when TYPE is
1044 If TYPE_IS_UNIQUE is true (the default) then msgid describes exactly
1045 one type (e.g. "expected %<)%>") and thus it may be reasonable to
1046 attempt to generate a fix-it hint for the problem.
1047 Otherwise msgid describes multiple token types (e.g.
1048 "expected %<;%>, %<,%> or %<)%>"), and thus we shouldn't attempt to
1049 generate a fix-it hint. */
1052 c_parser_require (c_parser
*parser
,
1053 enum cpp_ttype type
,
1055 location_t matching_location
,
1056 bool type_is_unique
)
1058 if (c_parser_next_token_is (parser
, type
))
1060 c_parser_consume_token (parser
);
1065 location_t next_token_loc
= c_parser_peek_token (parser
)->location
;
1066 gcc_rich_location
richloc (next_token_loc
);
1068 /* Potentially supply a fix-it hint, suggesting to add the
1069 missing token immediately after the *previous* token.
1070 This may move the primary location within richloc. */
1071 if (!parser
->error
&& type_is_unique
)
1072 maybe_suggest_missing_token_insertion (&richloc
, type
,
1073 parser
->last_token_location
);
1075 /* If matching_location != UNKNOWN_LOCATION, highlight it.
1076 Attempt to consolidate diagnostics by printing it as a
1077 secondary range within the main diagnostic. */
1078 bool added_matching_location
= false;
1079 if (matching_location
!= UNKNOWN_LOCATION
)
1080 added_matching_location
1081 = richloc
.add_location_if_nearby (matching_location
);
1083 if (c_parser_error_richloc (parser
, msgid
, &richloc
))
1084 /* If we weren't able to consolidate matching_location, then
1085 print it as a secondary diagnostic. */
1086 if (matching_location
!= UNKNOWN_LOCATION
&& !added_matching_location
)
1087 inform (matching_location
, "to match this %qs",
1088 get_matching_symbol (type
));
1094 /* If the next token is the indicated keyword, consume it. Otherwise,
1095 issue the error MSGID. Returns true if found, false otherwise. */
1098 c_parser_require_keyword (c_parser
*parser
,
1102 if (c_parser_next_token_is_keyword (parser
, keyword
))
1104 c_parser_consume_token (parser
);
1109 c_parser_error (parser
, msgid
);
1114 /* Like c_parser_require, except that tokens will be skipped until the
1115 desired token is found. An error message is still produced if the
1116 next token is not as expected. If MSGID is NULL then a message has
1117 already been produced and no message will be produced this
1120 If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1121 within any error as the location of an "opening" token matching
1122 the close token TYPE (e.g. the location of the '(' when TYPE is
1123 CPP_CLOSE_PAREN). */
1126 c_parser_skip_until_found (c_parser
*parser
,
1127 enum cpp_ttype type
,
1129 location_t matching_location
)
1131 unsigned nesting_depth
= 0;
1133 if (c_parser_require (parser
, type
, msgid
, matching_location
))
1136 /* Skip tokens until the desired token is found. */
1139 /* Peek at the next token. */
1140 c_token
*token
= c_parser_peek_token (parser
);
1141 /* If we've reached the token we want, consume it and stop. */
1142 if (token
->type
== type
&& !nesting_depth
)
1144 c_parser_consume_token (parser
);
1148 /* If we've run out of tokens, stop. */
1149 if (token
->type
== CPP_EOF
)
1151 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1153 if (token
->type
== CPP_OPEN_BRACE
1154 || token
->type
== CPP_OPEN_PAREN
1155 || token
->type
== CPP_OPEN_SQUARE
)
1157 else if (token
->type
== CPP_CLOSE_BRACE
1158 || token
->type
== CPP_CLOSE_PAREN
1159 || token
->type
== CPP_CLOSE_SQUARE
)
1161 if (nesting_depth
-- == 0)
1164 /* Consume this token. */
1165 c_parser_consume_token (parser
);
1167 parser
->error
= false;
1170 /* Skip tokens until the end of a parameter is found, but do not
1171 consume the comma, semicolon or closing delimiter. */
1174 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
1176 unsigned nesting_depth
= 0;
1180 c_token
*token
= c_parser_peek_token (parser
);
1181 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
1184 /* If we've run out of tokens, stop. */
1185 if (token
->type
== CPP_EOF
)
1187 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1189 if (token
->type
== CPP_OPEN_BRACE
1190 || token
->type
== CPP_OPEN_PAREN
1191 || token
->type
== CPP_OPEN_SQUARE
)
1193 else if (token
->type
== CPP_CLOSE_BRACE
1194 || token
->type
== CPP_CLOSE_PAREN
1195 || token
->type
== CPP_CLOSE_SQUARE
)
1197 if (nesting_depth
-- == 0)
1200 /* Consume this token. */
1201 c_parser_consume_token (parser
);
1203 parser
->error
= false;
1206 /* Expect to be at the end of the pragma directive and consume an
1207 end of line marker. */
1210 c_parser_skip_to_pragma_eol (c_parser
*parser
, bool error_if_not_eol
= true)
1212 gcc_assert (parser
->in_pragma
);
1213 parser
->in_pragma
= false;
1215 if (error_if_not_eol
&& c_parser_peek_token (parser
)->type
!= CPP_PRAGMA_EOL
)
1216 c_parser_error (parser
, "expected end of line");
1218 cpp_ttype token_type
;
1221 c_token
*token
= c_parser_peek_token (parser
);
1222 token_type
= token
->type
;
1223 if (token_type
== CPP_EOF
)
1225 c_parser_consume_token (parser
);
1227 while (token_type
!= CPP_PRAGMA_EOL
);
1229 parser
->error
= false;
1232 /* Skip tokens until we have consumed an entire block, or until we
1233 have consumed a non-nested ';'. */
1236 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1238 unsigned nesting_depth
= 0;
1239 bool save_error
= parser
->error
;
1245 /* Peek at the next token. */
1246 token
= c_parser_peek_token (parser
);
1248 switch (token
->type
)
1253 case CPP_PRAGMA_EOL
:
1254 if (parser
->in_pragma
)
1259 /* If the next token is a ';', we have reached the
1260 end of the statement. */
1263 /* Consume the ';'. */
1264 c_parser_consume_token (parser
);
1269 case CPP_CLOSE_BRACE
:
1270 /* If the next token is a non-nested '}', then we have
1271 reached the end of the current block. */
1272 if (nesting_depth
== 0 || --nesting_depth
== 0)
1274 c_parser_consume_token (parser
);
1279 case CPP_OPEN_BRACE
:
1280 /* If it the next token is a '{', then we are entering a new
1281 block. Consume the entire block. */
1286 /* If we see a pragma, consume the whole thing at once. We
1287 have some safeguards against consuming pragmas willy-nilly.
1288 Normally, we'd expect to be here with parser->error set,
1289 which disables these safeguards. But it's possible to get
1290 here for secondary error recovery, after parser->error has
1292 c_parser_consume_pragma (parser
);
1293 c_parser_skip_to_pragma_eol (parser
);
1294 parser
->error
= save_error
;
1301 c_parser_consume_token (parser
);
1305 parser
->error
= false;
1308 /* CPP's options (initialized by c-opts.c). */
1309 extern cpp_options
*cpp_opts
;
1311 /* Save the warning flags which are controlled by __extension__. */
1314 disable_extension_diagnostics (void)
1317 | (warn_pointer_arith
<< 1)
1318 | (warn_traditional
<< 2)
1320 | (warn_long_long
<< 4)
1321 | (warn_cxx_compat
<< 5)
1322 | (warn_overlength_strings
<< 6)
1323 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1324 play tricks to properly restore it. */
1325 | ((warn_c90_c99_compat
== 1) << 7)
1326 | ((warn_c90_c99_compat
== -1) << 8)
1327 /* Similarly for warn_c99_c11_compat. */
1328 | ((warn_c99_c11_compat
== 1) << 9)
1329 | ((warn_c99_c11_compat
== -1) << 10)
1331 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1332 warn_pointer_arith
= 0;
1333 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1335 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1336 warn_cxx_compat
= 0;
1337 warn_overlength_strings
= 0;
1338 warn_c90_c99_compat
= 0;
1339 warn_c99_c11_compat
= 0;
1343 /* Restore the warning flags which are controlled by __extension__.
1344 FLAGS is the return value from disable_extension_diagnostics. */
1347 restore_extension_diagnostics (int flags
)
1349 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1350 warn_pointer_arith
= (flags
>> 1) & 1;
1351 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1352 flag_iso
= (flags
>> 3) & 1;
1353 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1354 warn_cxx_compat
= (flags
>> 5) & 1;
1355 warn_overlength_strings
= (flags
>> 6) & 1;
1356 /* See above for why is this needed. */
1357 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1358 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1361 /* Helper data structure for parsing #pragma acc routine. */
1362 struct oacc_routine_data
{
1363 bool error_seen
; /* Set if error has been reported. */
1364 bool fndecl_seen
; /* Set if one fn decl/definition has been seen already. */
1369 static void c_parser_external_declaration (c_parser
*);
1370 static void c_parser_asm_definition (c_parser
*);
1371 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1372 bool, bool, tree
*, vec
<c_token
>,
1373 struct oacc_routine_data
* = NULL
,
1375 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1376 static void c_parser_static_assert_declaration (c_parser
*);
1377 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1378 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1379 static tree
c_parser_struct_declaration (c_parser
*);
1380 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1381 static tree
c_parser_alignas_specifier (c_parser
*);
1382 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1384 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1386 struct c_declarator
*);
1387 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1388 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1390 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1391 static tree
c_parser_simple_asm_expr (c_parser
*);
1392 static tree
c_parser_attributes (c_parser
*);
1393 static struct c_expr
c_parser_initializer (c_parser
*);
1394 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool,
1396 static void c_parser_initelt (c_parser
*, struct obstack
*);
1397 static void c_parser_initval (c_parser
*, struct c_expr
*,
1399 static tree
c_parser_compound_statement (c_parser
*);
1400 static void c_parser_compound_statement_nostart (c_parser
*);
1401 static void c_parser_label (c_parser
*);
1402 static void c_parser_statement (c_parser
*, bool *, location_t
* = NULL
);
1403 static void c_parser_statement_after_labels (c_parser
*, bool *,
1404 vec
<tree
> * = NULL
);
1405 static tree
c_parser_c99_block_statement (c_parser
*, bool *,
1406 location_t
* = NULL
);
1407 static void c_parser_if_statement (c_parser
*, bool *, vec
<tree
> *);
1408 static void c_parser_switch_statement (c_parser
*, bool *);
1409 static void c_parser_while_statement (c_parser
*, bool, bool *);
1410 static void c_parser_do_statement (c_parser
*, bool);
1411 static void c_parser_for_statement (c_parser
*, bool, bool *);
1412 static tree
c_parser_asm_statement (c_parser
*);
1413 static tree
c_parser_asm_operands (c_parser
*);
1414 static tree
c_parser_asm_goto_operands (c_parser
*);
1415 static tree
c_parser_asm_clobbers (c_parser
*);
1416 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1418 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1419 struct c_expr
*, tree
);
1420 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1422 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1423 static struct c_expr
c_parser_unary_expression (c_parser
*);
1424 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1425 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1426 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1427 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1428 struct c_type_name
*,
1430 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1433 static tree
c_parser_transaction (c_parser
*, enum rid
);
1434 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1435 static tree
c_parser_transaction_cancel (c_parser
*);
1436 static struct c_expr
c_parser_expression (c_parser
*);
1437 static struct c_expr
c_parser_expression_conv (c_parser
*);
1438 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1439 vec
<tree
, va_gc
> **, location_t
*,
1440 tree
*, vec
<location_t
> *,
1441 unsigned int * = NULL
);
1442 static void c_parser_oacc_declare (c_parser
*);
1443 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1444 static void c_parser_oacc_update (c_parser
*);
1445 static void c_parser_omp_construct (c_parser
*, bool *);
1446 static void c_parser_omp_threadprivate (c_parser
*);
1447 static void c_parser_omp_barrier (c_parser
*);
1448 static void c_parser_omp_flush (c_parser
*);
1449 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1450 tree
, tree
*, bool *);
1451 static void c_parser_omp_taskwait (c_parser
*);
1452 static void c_parser_omp_taskyield (c_parser
*);
1453 static void c_parser_omp_cancel (c_parser
*);
1455 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1456 pragma_stmt
, pragma_compound
};
1457 static bool c_parser_pragma (c_parser
*, enum pragma_context
, bool *);
1458 static void c_parser_omp_cancellation_point (c_parser
*, enum pragma_context
);
1459 static bool c_parser_omp_target (c_parser
*, enum pragma_context
, bool *);
1460 static void c_parser_omp_end_declare_target (c_parser
*);
1461 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1462 static bool c_parser_omp_ordered (c_parser
*, enum pragma_context
, bool *);
1463 static void c_parser_oacc_routine (c_parser
*, enum pragma_context
);
1465 /* These Objective-C parser functions are only ever called when
1466 compiling Objective-C. */
1467 static void c_parser_objc_class_definition (c_parser
*, tree
);
1468 static void c_parser_objc_class_instance_variables (c_parser
*);
1469 static void c_parser_objc_class_declaration (c_parser
*);
1470 static void c_parser_objc_alias_declaration (c_parser
*);
1471 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1472 static bool c_parser_objc_method_type (c_parser
*);
1473 static void c_parser_objc_method_definition (c_parser
*);
1474 static void c_parser_objc_methodprotolist (c_parser
*);
1475 static void c_parser_objc_methodproto (c_parser
*);
1476 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1477 static tree
c_parser_objc_type_name (c_parser
*);
1478 static tree
c_parser_objc_protocol_refs (c_parser
*);
1479 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1480 static void c_parser_objc_synchronized_statement (c_parser
*);
1481 static tree
c_parser_objc_selector (c_parser
*);
1482 static tree
c_parser_objc_selector_arg (c_parser
*);
1483 static tree
c_parser_objc_receiver (c_parser
*);
1484 static tree
c_parser_objc_message_args (c_parser
*);
1485 static tree
c_parser_objc_keywordexpr (c_parser
*);
1486 static void c_parser_objc_at_property_declaration (c_parser
*);
1487 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1488 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1489 static bool c_parser_objc_diagnose_bad_element_prefix
1490 (c_parser
*, struct c_declspecs
*);
1492 static void c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
);
1494 /* Parse a translation unit (C90 6.7, C99 6.9, C11 6.9).
1497 external-declarations
1499 external-declarations:
1500 external-declaration
1501 external-declarations external-declaration
1510 c_parser_translation_unit (c_parser
*parser
)
1512 if (c_parser_next_token_is (parser
, CPP_EOF
))
1514 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1515 "ISO C forbids an empty translation unit");
1519 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1520 mark_valid_location_for_stdc_pragma (false);
1524 c_parser_external_declaration (parser
);
1525 obstack_free (&parser_obstack
, obstack_position
);
1527 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1532 FOR_EACH_VEC_ELT (incomplete_record_decls
, i
, decl
)
1533 if (DECL_SIZE (decl
) == NULL_TREE
&& TREE_TYPE (decl
) != error_mark_node
)
1534 error ("storage size of %q+D isn%'t known", decl
);
1537 /* Parse an external declaration (C90 6.7, C99 6.9, C11 6.9).
1539 external-declaration:
1545 external-declaration:
1548 __extension__ external-declaration
1552 external-declaration:
1553 objc-class-definition
1554 objc-class-declaration
1555 objc-alias-declaration
1556 objc-protocol-definition
1557 objc-method-definition
1562 c_parser_external_declaration (c_parser
*parser
)
1565 switch (c_parser_peek_token (parser
)->type
)
1568 switch (c_parser_peek_token (parser
)->keyword
)
1571 ext
= disable_extension_diagnostics ();
1572 c_parser_consume_token (parser
);
1573 c_parser_external_declaration (parser
);
1574 restore_extension_diagnostics (ext
);
1577 c_parser_asm_definition (parser
);
1579 case RID_AT_INTERFACE
:
1580 case RID_AT_IMPLEMENTATION
:
1581 gcc_assert (c_dialect_objc ());
1582 c_parser_objc_class_definition (parser
, NULL_TREE
);
1585 gcc_assert (c_dialect_objc ());
1586 c_parser_objc_class_declaration (parser
);
1589 gcc_assert (c_dialect_objc ());
1590 c_parser_objc_alias_declaration (parser
);
1592 case RID_AT_PROTOCOL
:
1593 gcc_assert (c_dialect_objc ());
1594 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1596 case RID_AT_PROPERTY
:
1597 gcc_assert (c_dialect_objc ());
1598 c_parser_objc_at_property_declaration (parser
);
1600 case RID_AT_SYNTHESIZE
:
1601 gcc_assert (c_dialect_objc ());
1602 c_parser_objc_at_synthesize_declaration (parser
);
1604 case RID_AT_DYNAMIC
:
1605 gcc_assert (c_dialect_objc ());
1606 c_parser_objc_at_dynamic_declaration (parser
);
1609 gcc_assert (c_dialect_objc ());
1610 c_parser_consume_token (parser
);
1611 objc_finish_implementation ();
1618 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1619 "ISO C does not allow extra %<;%> outside of a function");
1620 c_parser_consume_token (parser
);
1623 mark_valid_location_for_stdc_pragma (true);
1624 c_parser_pragma (parser
, pragma_external
, NULL
);
1625 mark_valid_location_for_stdc_pragma (false);
1629 if (c_dialect_objc ())
1631 c_parser_objc_method_definition (parser
);
1634 /* Else fall through, and yield a syntax error trying to parse
1635 as a declaration or function definition. */
1639 /* A declaration or a function definition (or, in Objective-C,
1640 an @interface or @protocol with prefix attributes). We can
1641 only tell which after parsing the declaration specifiers, if
1642 any, and the first declarator. */
1643 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1649 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1650 static void c_finish_oacc_routine (struct oacc_routine_data
*, tree
, bool);
1652 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1653 6.7, 6.9.1, C11 6.7, 6.9.1). If FNDEF_OK is true, a function definition
1654 is accepted; otherwise (old-style parameter declarations) only other
1655 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1656 assertion is accepted; otherwise (old-style parameter declarations)
1657 it is not. If NESTED is true, we are inside a function or parsing
1658 old-style parameter declarations; any functions encountered are
1659 nested functions and declaration specifiers are required; otherwise
1660 we are at top level and functions are normal functions and
1661 declaration specifiers may be optional. If EMPTY_OK is true, empty
1662 declarations are OK (subject to all other constraints); otherwise
1663 (old-style parameter declarations) they are diagnosed. If
1664 START_ATTR_OK is true, the declaration specifiers may start with
1665 attributes; otherwise they may not.
1666 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1667 declaration when parsing an Objective-C foreach statement.
1668 FALLTHRU_ATTR_P is used to signal whether this function parsed
1669 "__attribute__((fallthrough));".
1672 declaration-specifiers init-declarator-list[opt] ;
1673 static_assert-declaration
1675 function-definition:
1676 declaration-specifiers[opt] declarator declaration-list[opt]
1681 declaration-list declaration
1683 init-declarator-list:
1685 init-declarator-list , init-declarator
1688 declarator simple-asm-expr[opt] attributes[opt]
1689 declarator simple-asm-expr[opt] attributes[opt] = initializer
1693 nested-function-definition:
1694 declaration-specifiers declarator declaration-list[opt]
1700 attributes objc-class-definition
1701 attributes objc-category-definition
1702 attributes objc-protocol-definition
1704 The simple-asm-expr and attributes are GNU extensions.
1706 This function does not handle __extension__; that is handled in its
1707 callers. ??? Following the old parser, __extension__ may start
1708 external declarations, declarations in functions and declarations
1709 at the start of "for" loops, but not old-style parameter
1712 C99 requires declaration specifiers in a function definition; the
1713 absence is diagnosed through the diagnosis of implicit int. In GNU
1714 C we also allow but diagnose declarations without declaration
1715 specifiers, but only at top level (elsewhere they conflict with
1718 In Objective-C, declarations of the looping variable in a foreach
1719 statement are exceptionally terminated by 'in' (for example, 'for
1720 (NSObject *object in array) { ... }').
1725 threadprivate-directive
1729 gimple-function-definition:
1730 declaration-specifiers[opt] __GIMPLE (gimple-or-rtl-pass-list) declarator
1731 declaration-list[opt] compound-statement
1733 rtl-function-definition:
1734 declaration-specifiers[opt] __RTL (gimple-or-rtl-pass-list) declarator
1735 declaration-list[opt] compound-statement */
1738 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1739 bool static_assert_ok
, bool empty_ok
,
1740 bool nested
, bool start_attr_ok
,
1741 tree
*objc_foreach_object_declaration
,
1742 vec
<c_token
> omp_declare_simd_clauses
,
1743 struct oacc_routine_data
*oacc_routine_data
,
1744 bool *fallthru_attr_p
)
1746 struct c_declspecs
*specs
;
1748 tree all_prefix_attrs
;
1749 bool diagnosed_no_specs
= false;
1750 location_t here
= c_parser_peek_token (parser
)->location
;
1752 if (static_assert_ok
1753 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1755 c_parser_static_assert_declaration (parser
);
1758 specs
= build_null_declspecs ();
1760 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1761 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1762 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1763 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1764 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1765 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1767 tree name
= c_parser_peek_token (parser
)->value
;
1769 /* Issue a warning about NAME being an unknown type name, perhaps
1770 with some kind of hint.
1771 If the user forgot a "struct" etc, suggest inserting
1772 it. Otherwise, attempt to look for misspellings. */
1773 gcc_rich_location
richloc (here
);
1774 if (tag_exists_p (RECORD_TYPE
, name
))
1776 /* This is not C++ with its implicit typedef. */
1777 richloc
.add_fixit_insert_before ("struct ");
1779 "unknown type name %qE;"
1780 " use %<struct%> keyword to refer to the type",
1783 else if (tag_exists_p (UNION_TYPE
, name
))
1785 richloc
.add_fixit_insert_before ("union ");
1787 "unknown type name %qE;"
1788 " use %<union%> keyword to refer to the type",
1791 else if (tag_exists_p (ENUMERAL_TYPE
, name
))
1793 richloc
.add_fixit_insert_before ("enum ");
1795 "unknown type name %qE;"
1796 " use %<enum%> keyword to refer to the type",
1801 name_hint hint
= lookup_name_fuzzy (name
, FUZZY_LOOKUP_TYPENAME
,
1805 richloc
.add_fixit_replace (hint
.suggestion ());
1807 "unknown type name %qE; did you mean %qs?",
1808 name
, hint
.suggestion ());
1811 error_at (here
, "unknown type name %qE", name
);
1814 /* Parse declspecs normally to get a correct pointer type, but avoid
1815 a further "fails to be a type name" error. Refuse nested functions
1816 since it is not how the user likely wants us to recover. */
1817 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1818 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1819 c_parser_peek_token (parser
)->value
= error_mark_node
;
1823 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1824 true, true, cla_nonabstract_decl
);
1827 c_parser_skip_to_end_of_block_or_statement (parser
);
1830 if (nested
&& !specs
->declspecs_seen_p
)
1832 c_parser_error (parser
, "expected declaration specifiers");
1833 c_parser_skip_to_end_of_block_or_statement (parser
);
1837 finish_declspecs (specs
);
1838 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1839 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1842 error_at (here
, "%<__auto_type%> in empty declaration");
1843 else if (specs
->typespec_kind
== ctsk_none
1844 && attribute_fallthrough_p (specs
->attrs
))
1846 if (fallthru_attr_p
!= NULL
)
1847 *fallthru_attr_p
= true;
1848 tree fn
= build_call_expr_internal_loc (here
, IFN_FALLTHROUGH
,
1856 shadow_tag_warned (specs
, 1);
1857 pedwarn (here
, 0, "empty declaration");
1859 c_parser_consume_token (parser
);
1860 if (oacc_routine_data
)
1861 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1865 /* Provide better error recovery. Note that a type name here is usually
1866 better diagnosed as a redeclaration. */
1868 && specs
->typespec_kind
== ctsk_tagdef
1869 && c_parser_next_token_starts_declspecs (parser
)
1870 && !c_parser_next_token_is (parser
, CPP_NAME
))
1872 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1873 parser
->error
= false;
1874 shadow_tag_warned (specs
, 1);
1877 else if (c_dialect_objc () && !auto_type_p
)
1879 /* Prefix attributes are an error on method decls. */
1880 switch (c_parser_peek_token (parser
)->type
)
1884 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1888 warning_at (c_parser_peek_token (parser
)->location
,
1890 "prefix attributes are ignored for methods");
1891 specs
->attrs
= NULL_TREE
;
1894 c_parser_objc_method_definition (parser
);
1896 c_parser_objc_methodproto (parser
);
1902 /* This is where we parse 'attributes @interface ...',
1903 'attributes @implementation ...', 'attributes @protocol ...'
1904 (where attributes could be, for example, __attribute__
1907 switch (c_parser_peek_token (parser
)->keyword
)
1909 case RID_AT_INTERFACE
:
1911 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1913 c_parser_objc_class_definition (parser
, specs
->attrs
);
1917 case RID_AT_IMPLEMENTATION
:
1919 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1923 warning_at (c_parser_peek_token (parser
)->location
,
1925 "prefix attributes are ignored for implementations");
1926 specs
->attrs
= NULL_TREE
;
1928 c_parser_objc_class_definition (parser
, NULL_TREE
);
1932 case RID_AT_PROTOCOL
:
1934 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1936 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1943 case RID_AT_PROPERTY
:
1946 c_parser_error (parser
, "unexpected attribute");
1947 specs
->attrs
= NULL
;
1954 else if (attribute_fallthrough_p (specs
->attrs
))
1955 warning_at (here
, OPT_Wattributes
,
1956 "%<fallthrough%> attribute not followed by %<;%>");
1958 pending_xref_error ();
1959 prefix_attrs
= specs
->attrs
;
1960 all_prefix_attrs
= prefix_attrs
;
1961 specs
->attrs
= NULL_TREE
;
1964 struct c_declarator
*declarator
;
1967 tree fnbody
= NULL_TREE
;
1968 /* Declaring either one or more declarators (in which case we
1969 should diagnose if there were no declaration specifiers) or a
1970 function definition (in which case the diagnostic for
1971 implicit int suffices). */
1972 declarator
= c_parser_declarator (parser
,
1973 specs
->typespec_kind
!= ctsk_none
,
1974 C_DTR_NORMAL
, &dummy
);
1975 if (declarator
== NULL
)
1977 if (omp_declare_simd_clauses
.exists ())
1978 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1979 omp_declare_simd_clauses
);
1980 if (oacc_routine_data
)
1981 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1982 c_parser_skip_to_end_of_block_or_statement (parser
);
1985 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1988 "%<__auto_type%> requires a plain identifier"
1990 c_parser_skip_to_end_of_block_or_statement (parser
);
1993 if (c_parser_next_token_is (parser
, CPP_EQ
)
1994 || c_parser_next_token_is (parser
, CPP_COMMA
)
1995 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1996 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1997 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1998 || c_parser_next_token_is_keyword (parser
, RID_IN
))
2000 tree asm_name
= NULL_TREE
;
2001 tree postfix_attrs
= NULL_TREE
;
2002 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
2004 diagnosed_no_specs
= true;
2005 pedwarn (here
, 0, "data definition has no type or storage class");
2007 /* Having seen a data definition, there cannot now be a
2008 function definition. */
2010 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
2011 asm_name
= c_parser_simple_asm_expr (parser
);
2012 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2014 postfix_attrs
= c_parser_attributes (parser
);
2015 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2017 /* This means there is an attribute specifier after
2018 the declarator in a function definition. Provide
2019 some more information for the user. */
2020 error_at (here
, "attributes should be specified before the "
2021 "declarator in a function definition");
2022 c_parser_skip_to_end_of_block_or_statement (parser
);
2026 if (c_parser_next_token_is (parser
, CPP_EQ
))
2030 location_t init_loc
;
2031 c_parser_consume_token (parser
);
2034 init_loc
= c_parser_peek_token (parser
)->location
;
2035 rich_location
richloc (line_table
, init_loc
);
2036 start_init (NULL_TREE
, asm_name
, global_bindings_p (), &richloc
);
2037 /* A parameter is initialized, which is invalid. Don't
2038 attempt to instrument the initializer. */
2039 int flag_sanitize_save
= flag_sanitize
;
2040 if (nested
&& !empty_ok
)
2042 init
= c_parser_expr_no_commas (parser
, NULL
);
2043 flag_sanitize
= flag_sanitize_save
;
2044 if (TREE_CODE (init
.value
) == COMPONENT_REF
2045 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
2047 "%<__auto_type%> used with a bit-field"
2049 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
2050 tree init_type
= TREE_TYPE (init
.value
);
2051 /* As with typeof, remove all qualifiers from atomic types. */
2052 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
2054 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
2055 bool vm_type
= variably_modified_type_p (init_type
,
2058 init
.value
= save_expr (init
.value
);
2060 specs
->typespec_kind
= ctsk_typeof
;
2061 specs
->locations
[cdw_typedef
] = init_loc
;
2062 specs
->typedef_p
= true;
2063 specs
->type
= init_type
;
2066 bool maybe_const
= true;
2067 tree type_expr
= c_fully_fold (init
.value
, false,
2069 specs
->expr_const_operands
&= maybe_const
;
2071 specs
->expr
= build2 (COMPOUND_EXPR
,
2072 TREE_TYPE (type_expr
),
2073 specs
->expr
, type_expr
);
2075 specs
->expr
= type_expr
;
2077 d
= start_decl (declarator
, specs
, true,
2078 chainon (postfix_attrs
, all_prefix_attrs
));
2080 d
= error_mark_node
;
2081 if (omp_declare_simd_clauses
.exists ())
2082 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
2083 omp_declare_simd_clauses
);
2087 /* The declaration of the variable is in effect while
2088 its initializer is parsed. */
2089 d
= start_decl (declarator
, specs
, true,
2090 chainon (postfix_attrs
, all_prefix_attrs
));
2092 d
= error_mark_node
;
2093 if (omp_declare_simd_clauses
.exists ())
2094 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
2095 omp_declare_simd_clauses
);
2096 init_loc
= c_parser_peek_token (parser
)->location
;
2097 rich_location
richloc (line_table
, init_loc
);
2098 start_init (d
, asm_name
, global_bindings_p (), &richloc
);
2099 /* A parameter is initialized, which is invalid. Don't
2100 attempt to instrument the initializer. */
2101 int flag_sanitize_save
= flag_sanitize
;
2102 if (TREE_CODE (d
) == PARM_DECL
)
2104 init
= c_parser_initializer (parser
);
2105 flag_sanitize
= flag_sanitize_save
;
2108 if (oacc_routine_data
)
2109 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2110 if (d
!= error_mark_node
)
2112 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
2113 finish_decl (d
, init_loc
, init
.value
,
2114 init
.original_type
, asm_name
);
2122 "%<__auto_type%> requires an initialized "
2123 "data declaration");
2124 c_parser_skip_to_end_of_block_or_statement (parser
);
2127 tree d
= start_decl (declarator
, specs
, false,
2128 chainon (postfix_attrs
,
2130 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
2131 if (declarator
->kind
== cdk_function
)
2132 if (DECL_ARGUMENTS (d
) == NULL_TREE
)
2133 DECL_ARGUMENTS (d
) = declarator
->u
.arg_info
->parms
;
2134 if (omp_declare_simd_clauses
.exists ())
2136 tree parms
= NULL_TREE
;
2137 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
2139 struct c_declarator
*ce
= declarator
;
2141 if (ce
->kind
== cdk_function
)
2143 parms
= ce
->u
.arg_info
->parms
;
2147 ce
= ce
->declarator
;
2150 temp_store_parm_decls (d
, parms
);
2151 c_finish_omp_declare_simd (parser
, d
, parms
,
2152 omp_declare_simd_clauses
);
2154 temp_pop_parm_decls ();
2156 if (oacc_routine_data
)
2157 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2159 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
2160 NULL_TREE
, asm_name
);
2162 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2165 *objc_foreach_object_declaration
= d
;
2167 *objc_foreach_object_declaration
= error_mark_node
;
2170 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2175 "%<__auto_type%> may only be used with"
2176 " a single declarator");
2177 c_parser_skip_to_end_of_block_or_statement (parser
);
2180 c_parser_consume_token (parser
);
2181 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2182 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2185 all_prefix_attrs
= prefix_attrs
;
2188 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2190 c_parser_consume_token (parser
);
2193 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2195 /* This can only happen in Objective-C: we found the
2196 'in' that terminates the declaration inside an
2197 Objective-C foreach statement. Do not consume the
2198 token, so that the caller can use it to determine
2199 that this indeed is a foreach context. */
2204 c_parser_error (parser
, "expected %<,%> or %<;%>");
2205 c_parser_skip_to_end_of_block_or_statement (parser
);
2209 else if (auto_type_p
)
2212 "%<__auto_type%> requires an initialized data declaration");
2213 c_parser_skip_to_end_of_block_or_statement (parser
);
2218 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
2219 "%<asm%> or %<__attribute__%>");
2220 c_parser_skip_to_end_of_block_or_statement (parser
);
2223 /* Function definition (nested or otherwise). */
2226 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
2227 c_push_function_context ();
2229 if (!start_function (specs
, declarator
, all_prefix_attrs
))
2231 /* At this point we've consumed:
2232 declaration-specifiers declarator
2233 and the next token isn't CPP_EQ, CPP_COMMA, CPP_SEMICOLON,
2234 RID_ASM, RID_ATTRIBUTE, or RID_IN,
2236 declaration-specifiers declarator
2237 aren't grokkable as a function definition, so we have
2239 gcc_assert (!c_parser_next_token_is (parser
, CPP_SEMICOLON
));
2240 if (c_parser_next_token_starts_declspecs (parser
))
2243 declaration-specifiers declarator decl-specs
2244 then assume we have a missing semicolon, which would
2246 declaration-specifiers declarator decl-specs
2249 <~~~~~~~~~ declaration ~~~~~~~~~~>
2250 Use c_parser_require to get an error with a fix-it hint. */
2251 c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>");
2252 parser
->error
= false;
2256 /* This can appear in many cases looking nothing like a
2257 function definition, so we don't give a more specific
2258 error suggesting there was one. */
2259 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2260 "or %<__attribute__%>");
2263 c_pop_function_context ();
2267 if (DECL_DECLARED_INLINE_P (current_function_decl
))
2268 tv
= TV_PARSE_INLINE
;
2271 auto_timevar
at (g_timer
, tv
);
2273 /* Parse old-style parameter declarations. ??? Attributes are
2274 not allowed to start declaration specifiers here because of a
2275 syntax conflict between a function declaration with attribute
2276 suffix and a function definition with an attribute prefix on
2277 first old-style parameter declaration. Following the old
2278 parser, they are not accepted on subsequent old-style
2279 parameter declarations either. However, there is no
2280 ambiguity after the first declaration, nor indeed on the
2281 first as long as we don't allow postfix attributes after a
2282 declarator with a nonempty identifier list in a definition;
2283 and postfix attributes have never been accepted here in
2284 function definitions either. */
2285 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
2286 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
2287 c_parser_declaration_or_fndef (parser
, false, false, false,
2288 true, false, NULL
, vNULL
);
2289 store_parm_decls ();
2290 if (omp_declare_simd_clauses
.exists ())
2291 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
2292 omp_declare_simd_clauses
);
2293 if (oacc_routine_data
)
2294 c_finish_oacc_routine (oacc_routine_data
, current_function_decl
, true);
2295 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
2296 = c_parser_peek_token (parser
)->location
;
2298 /* If the definition was marked with __GIMPLE then parse the
2299 function body as GIMPLE. */
2300 if (specs
->gimple_p
)
2302 cfun
->pass_startwith
= specs
->gimple_or_rtl_pass
;
2303 bool saved
= in_late_binary_op
;
2304 in_late_binary_op
= true;
2305 c_parser_parse_gimple_body (parser
);
2306 in_late_binary_op
= saved
;
2308 /* Similarly, if it was marked with __RTL, use the RTL parser now,
2309 consuming the function body. */
2310 else if (specs
->rtl_p
)
2312 c_parser_parse_rtl_body (parser
, specs
->gimple_or_rtl_pass
);
2314 /* Normally, store_parm_decls sets next_is_function_body,
2315 anticipating a function body. We need a push_scope/pop_scope
2316 pair to flush out this state, or subsequent function parsing
2325 fnbody
= c_parser_compound_statement (parser
);
2326 tree fndecl
= current_function_decl
;
2329 tree decl
= current_function_decl
;
2330 /* Mark nested functions as needing static-chain initially.
2331 lower_nested_functions will recompute it but the
2332 DECL_STATIC_CHAIN flag is also used before that happens,
2333 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2334 DECL_STATIC_CHAIN (decl
) = 1;
2337 c_pop_function_context ();
2338 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
2346 /* Get rid of the empty stmt list for GIMPLE. */
2347 if (specs
->gimple_p
)
2348 DECL_SAVED_TREE (fndecl
) = NULL_TREE
;
2354 /* Parse an asm-definition (asm() outside a function body). This is a
2362 c_parser_asm_definition (c_parser
*parser
)
2364 tree asm_str
= c_parser_simple_asm_expr (parser
);
2366 symtab
->finalize_toplevel_asm (asm_str
);
2367 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2370 /* Parse a static assertion (C11 6.7.10).
2372 static_assert-declaration:
2373 static_assert-declaration-no-semi ;
2377 c_parser_static_assert_declaration (c_parser
*parser
)
2379 c_parser_static_assert_declaration_no_semi (parser
);
2381 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2382 c_parser_skip_to_end_of_block_or_statement (parser
);
2385 /* Parse a static assertion (C11 6.7.10), without the trailing
2388 static_assert-declaration-no-semi:
2389 _Static_assert ( constant-expression , string-literal )
2393 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2395 location_t assert_loc
, value_loc
;
2399 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2400 assert_loc
= c_parser_peek_token (parser
)->location
;
2402 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2403 "ISO C99 does not support %<_Static_assert%>");
2405 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2406 "ISO C90 does not support %<_Static_assert%>");
2407 c_parser_consume_token (parser
);
2408 matching_parens parens
;
2409 if (!parens
.require_open (parser
))
2411 location_t value_tok_loc
= c_parser_peek_token (parser
)->location
;
2412 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2413 value_loc
= EXPR_LOC_OR_LOC (value
, value_tok_loc
);
2414 parser
->lex_untranslated_string
= true;
2415 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2417 parser
->lex_untranslated_string
= false;
2420 switch (c_parser_peek_token (parser
)->type
)
2426 case CPP_UTF8STRING
:
2427 string
= c_parser_peek_token (parser
)->value
;
2428 c_parser_consume_token (parser
);
2429 parser
->lex_untranslated_string
= false;
2432 c_parser_error (parser
, "expected string literal");
2433 parser
->lex_untranslated_string
= false;
2436 parens
.require_close (parser
);
2438 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2440 error_at (value_loc
, "expression in static assertion is not an integer");
2443 if (TREE_CODE (value
) != INTEGER_CST
)
2445 value
= c_fully_fold (value
, false, NULL
);
2446 /* Strip no-op conversions. */
2447 STRIP_TYPE_NOPS (value
);
2448 if (TREE_CODE (value
) == INTEGER_CST
)
2449 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2450 "is not an integer constant expression");
2452 if (TREE_CODE (value
) != INTEGER_CST
)
2454 error_at (value_loc
, "expression in static assertion is not constant");
2457 constant_expression_warning (value
);
2458 if (integer_zerop (value
))
2459 error_at (assert_loc
, "static assertion failed: %E", string
);
2462 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2463 6.7, C11 6.7), adding them to SPECS (which may already include some).
2464 Storage class specifiers are accepted iff SCSPEC_OK; type
2465 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2466 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2467 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2469 declaration-specifiers:
2470 storage-class-specifier declaration-specifiers[opt]
2471 type-specifier declaration-specifiers[opt]
2472 type-qualifier declaration-specifiers[opt]
2473 function-specifier declaration-specifiers[opt]
2474 alignment-specifier declaration-specifiers[opt]
2476 Function specifiers (inline) are from C99, and are currently
2477 handled as storage class specifiers, as is __thread. Alignment
2478 specifiers are from C11.
2480 C90 6.5.1, C99 6.7.1, C11 6.7.1:
2481 storage-class-specifier:
2489 (_Thread_local is new in C11.)
2491 C99 6.7.4, C11 6.7.4:
2496 (_Noreturn is new in C11.)
2498 C90 6.5.2, C99 6.7.2, C11 6.7.2:
2511 [_Imaginary removed in C99 TC2]
2512 struct-or-union-specifier
2515 atomic-type-specifier
2517 (_Bool and _Complex are new in C99.)
2518 (atomic-type-specifier is new in C11.)
2520 C90 6.5.3, C99 6.7.3, C11 6.7.3:
2526 address-space-qualifier
2529 (restrict is new in C99.)
2530 (_Atomic is new in C11.)
2534 declaration-specifiers:
2535 attributes declaration-specifiers[opt]
2541 identifier recognized by the target
2543 storage-class-specifier:
2557 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2558 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2560 atomic-type-specifier
2561 _Atomic ( type-name )
2566 class-name objc-protocol-refs[opt]
2567 typedef-name objc-protocol-refs
2572 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2573 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2574 bool alignspec_ok
, bool auto_type_ok
,
2575 enum c_lookahead_kind la
)
2577 bool attrs_ok
= start_attr_ok
;
2578 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2581 gcc_assert (la
== cla_prefer_id
);
2583 while (c_parser_next_token_is (parser
, CPP_NAME
)
2584 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2585 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2587 struct c_typespec t
;
2590 location_t loc
= c_parser_peek_token (parser
)->location
;
2592 /* If we cannot accept a type, exit if the next token must start
2593 one. Also, if we already have seen a tagged definition,
2594 a typename would be an error anyway and likely the user
2595 has simply forgotten a semicolon, so we exit. */
2596 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2597 && c_parser_next_tokens_start_typename (parser
, la
)
2598 && !c_parser_next_token_is_qualifier (parser
)
2599 && !c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
))
2602 if (c_parser_next_token_is (parser
, CPP_NAME
))
2604 c_token
*name_token
= c_parser_peek_token (parser
);
2605 tree value
= name_token
->value
;
2606 c_id_kind kind
= name_token
->id_kind
;
2608 if (kind
== C_ID_ADDRSPACE
)
2611 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2612 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2613 c_parser_consume_token (parser
);
2618 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2620 /* If we cannot accept a type, and the next token must start one,
2621 exit. Do the same if we already have seen a tagged definition,
2622 since it would be an error anyway and likely the user has simply
2623 forgotten a semicolon. */
2624 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2627 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2628 a C_ID_CLASSNAME. */
2629 c_parser_consume_token (parser
);
2632 if (kind
== C_ID_ID
)
2634 error_at (loc
, "unknown type name %qE", value
);
2635 t
.kind
= ctsk_typedef
;
2636 t
.spec
= error_mark_node
;
2638 else if (kind
== C_ID_TYPENAME
2639 && (!c_dialect_objc ()
2640 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2642 t
.kind
= ctsk_typedef
;
2643 /* For a typedef name, record the meaning, not the name.
2644 In case of 'foo foo, bar;'. */
2645 t
.spec
= lookup_name (value
);
2649 tree proto
= NULL_TREE
;
2650 gcc_assert (c_dialect_objc ());
2652 if (c_parser_next_token_is (parser
, CPP_LESS
))
2653 proto
= c_parser_objc_protocol_refs (parser
);
2654 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2657 t
.expr_const_operands
= true;
2658 declspecs_add_type (name_token
->location
, specs
, t
);
2661 if (c_parser_next_token_is (parser
, CPP_LESS
))
2663 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2664 nisse@lysator.liu.se. */
2666 gcc_assert (c_dialect_objc ());
2667 if (!typespec_ok
|| seen_type
)
2669 proto
= c_parser_objc_protocol_refs (parser
);
2671 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2673 t
.expr_const_operands
= true;
2674 declspecs_add_type (loc
, specs
, t
);
2677 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2678 switch (c_parser_peek_token (parser
)->keyword
)
2691 /* TODO: Distinguish between function specifiers (inline, noreturn)
2692 and storage class specifiers, either here or in
2693 declspecs_add_scspec. */
2694 declspecs_add_scspec (loc
, specs
,
2695 c_parser_peek_token (parser
)->value
);
2696 c_parser_consume_token (parser
);
2728 if (c_dialect_objc ())
2729 parser
->objc_need_raw_identifier
= true;
2730 t
.kind
= ctsk_resword
;
2731 t
.spec
= c_parser_peek_token (parser
)->value
;
2733 t
.expr_const_operands
= true;
2734 declspecs_add_type (loc
, specs
, t
);
2735 c_parser_consume_token (parser
);
2742 t
= c_parser_enum_specifier (parser
);
2743 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2744 declspecs_add_type (loc
, specs
, t
);
2752 t
= c_parser_struct_or_union_specifier (parser
);
2753 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2754 declspecs_add_type (loc
, specs
, t
);
2757 /* ??? The old parser rejected typeof after other type
2758 specifiers, but is a syntax error the best way of
2760 if (!typespec_ok
|| seen_type
)
2764 t
= c_parser_typeof_specifier (parser
);
2765 declspecs_add_type (loc
, specs
, t
);
2768 /* C parser handling of Objective-C constructs needs
2769 checking for correct lvalue-to-rvalue conversions, and
2770 the code in build_modify_expr handling various
2771 Objective-C cases, and that in build_unary_op handling
2772 Objective-C cases for increment / decrement, also needs
2773 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2774 and objc_types_are_equivalent may also need updates. */
2775 if (c_dialect_objc ())
2776 sorry ("%<_Atomic%> in Objective-C");
2778 pedwarn_c99 (loc
, OPT_Wpedantic
,
2779 "ISO C99 does not support the %<_Atomic%> qualifier");
2781 pedwarn_c99 (loc
, OPT_Wpedantic
,
2782 "ISO C90 does not support the %<_Atomic%> qualifier");
2785 value
= c_parser_peek_token (parser
)->value
;
2786 c_parser_consume_token (parser
);
2787 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2789 /* _Atomic ( type-name ). */
2791 c_parser_consume_token (parser
);
2792 struct c_type_name
*type
= c_parser_type_name (parser
);
2793 t
.kind
= ctsk_typeof
;
2794 t
.spec
= error_mark_node
;
2796 t
.expr_const_operands
= true;
2798 t
.spec
= groktypename (type
, &t
.expr
,
2799 &t
.expr_const_operands
);
2800 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2802 if (t
.spec
!= error_mark_node
)
2804 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2805 error_at (loc
, "%<_Atomic%>-qualified array type");
2806 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2807 error_at (loc
, "%<_Atomic%>-qualified function type");
2808 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2809 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2811 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2813 declspecs_add_type (loc
, specs
, t
);
2816 declspecs_add_qual (loc
, specs
, value
);
2822 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2823 c_parser_consume_token (parser
);
2828 attrs
= c_parser_attributes (parser
);
2829 declspecs_add_attrs (loc
, specs
, attrs
);
2834 align
= c_parser_alignas_specifier (parser
);
2835 declspecs_add_alignas (loc
, specs
, align
);
2839 error_at (loc
, "%<__GIMPLE%> only valid with -fgimple");
2840 c_parser_consume_token (parser
);
2841 specs
->gimple_p
= true;
2842 specs
->locations
[cdw_gimple
] = loc
;
2843 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2846 c_parser_consume_token (parser
);
2847 specs
->rtl_p
= true;
2848 specs
->locations
[cdw_rtl
] = loc
;
2849 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2858 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2, C11 6.7.2.2).
2861 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2862 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2863 enum attributes[opt] identifier
2865 The form with trailing comma is new in C99. The forms with
2866 attributes are GNU extensions. In GNU C, we accept any expression
2867 without commas in the syntax (assignment expressions, not just
2868 conditional expressions); assignment expressions will be diagnosed
2873 enumerator-list , enumerator
2876 enumeration-constant
2877 enumeration-constant = constant-expression
2882 enumeration-constant attributes[opt]
2883 enumeration-constant attributes[opt] = constant-expression
2887 static struct c_typespec
2888 c_parser_enum_specifier (c_parser
*parser
)
2890 struct c_typespec ret
;
2892 tree ident
= NULL_TREE
;
2893 location_t enum_loc
;
2894 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2895 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2896 c_parser_consume_token (parser
);
2897 attrs
= c_parser_attributes (parser
);
2898 enum_loc
= c_parser_peek_token (parser
)->location
;
2899 /* Set the location in case we create a decl now. */
2900 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2901 if (c_parser_next_token_is (parser
, CPP_NAME
))
2903 ident
= c_parser_peek_token (parser
)->value
;
2904 ident_loc
= c_parser_peek_token (parser
)->location
;
2905 enum_loc
= ident_loc
;
2906 c_parser_consume_token (parser
);
2908 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2910 /* Parse an enum definition. */
2911 struct c_enum_contents the_enum
;
2914 /* We chain the enumerators in reverse order, then put them in
2915 forward order at the end. */
2917 timevar_push (TV_PARSE_ENUM
);
2918 type
= start_enum (enum_loc
, &the_enum
, ident
);
2920 c_parser_consume_token (parser
);
2928 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2929 location_t decl_loc
, value_loc
;
2930 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2932 /* Give a nicer error for "enum {}". */
2933 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2936 error_at (c_parser_peek_token (parser
)->location
,
2937 "empty enum is invalid");
2938 parser
->error
= true;
2941 c_parser_error (parser
, "expected identifier");
2942 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2943 values
= error_mark_node
;
2946 token
= c_parser_peek_token (parser
);
2947 enum_id
= token
->value
;
2948 /* Set the location in case we create a decl now. */
2949 c_parser_set_source_position_from_token (token
);
2950 decl_loc
= value_loc
= token
->location
;
2951 c_parser_consume_token (parser
);
2952 /* Parse any specified attributes. */
2953 tree enum_attrs
= c_parser_attributes (parser
);
2954 if (c_parser_next_token_is (parser
, CPP_EQ
))
2956 c_parser_consume_token (parser
);
2957 value_loc
= c_parser_peek_token (parser
)->location
;
2958 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2961 enum_value
= NULL_TREE
;
2962 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2963 &the_enum
, enum_id
, enum_value
);
2965 decl_attributes (&TREE_PURPOSE (enum_decl
), enum_attrs
, 0);
2966 TREE_CHAIN (enum_decl
) = values
;
2969 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2971 comma_loc
= c_parser_peek_token (parser
)->location
;
2973 c_parser_consume_token (parser
);
2975 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2978 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2979 "comma at end of enumerator list");
2980 c_parser_consume_token (parser
);
2985 c_parser_error (parser
, "expected %<,%> or %<}%>");
2986 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2987 values
= error_mark_node
;
2991 postfix_attrs
= c_parser_attributes (parser
);
2992 ret
.spec
= finish_enum (type
, nreverse (values
),
2993 chainon (attrs
, postfix_attrs
));
2994 ret
.kind
= ctsk_tagdef
;
2995 ret
.expr
= NULL_TREE
;
2996 ret
.expr_const_operands
= true;
2997 timevar_pop (TV_PARSE_ENUM
);
3002 c_parser_error (parser
, "expected %<{%>");
3003 ret
.spec
= error_mark_node
;
3004 ret
.kind
= ctsk_tagref
;
3005 ret
.expr
= NULL_TREE
;
3006 ret
.expr_const_operands
= true;
3009 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
3010 /* In ISO C, enumerated types can be referred to only if already
3012 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
3015 pedwarn (enum_loc
, OPT_Wpedantic
,
3016 "ISO C forbids forward references to %<enum%> types");
3021 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1).
3023 struct-or-union-specifier:
3024 struct-or-union attributes[opt] identifier[opt]
3025 { struct-contents } attributes[opt]
3026 struct-or-union attributes[opt] identifier
3029 struct-declaration-list
3031 struct-declaration-list:
3032 struct-declaration ;
3033 struct-declaration-list struct-declaration ;
3040 struct-declaration-list struct-declaration
3042 struct-declaration-list:
3043 struct-declaration-list ;
3046 (Note that in the syntax here, unlike that in ISO C, the semicolons
3047 are included here rather than in struct-declaration, in order to
3048 describe the syntax with extra semicolons and missing semicolon at
3053 struct-declaration-list:
3054 @defs ( class-name )
3056 (Note this does not include a trailing semicolon, but can be
3057 followed by further declarations, and gets a pedwarn-if-pedantic
3058 when followed by a semicolon.) */
3060 static struct c_typespec
3061 c_parser_struct_or_union_specifier (c_parser
*parser
)
3063 struct c_typespec ret
;
3065 tree ident
= NULL_TREE
;
3066 location_t struct_loc
;
3067 location_t ident_loc
= UNKNOWN_LOCATION
;
3068 enum tree_code code
;
3069 switch (c_parser_peek_token (parser
)->keyword
)
3080 struct_loc
= c_parser_peek_token (parser
)->location
;
3081 c_parser_consume_token (parser
);
3082 attrs
= c_parser_attributes (parser
);
3084 /* Set the location in case we create a decl now. */
3085 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
3087 if (c_parser_next_token_is (parser
, CPP_NAME
))
3089 ident
= c_parser_peek_token (parser
)->value
;
3090 ident_loc
= c_parser_peek_token (parser
)->location
;
3091 struct_loc
= ident_loc
;
3092 c_parser_consume_token (parser
);
3094 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3096 /* Parse a struct or union definition. Start the scope of the
3097 tag before parsing components. */
3098 struct c_struct_parse_info
*struct_info
;
3099 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
3101 /* We chain the components in reverse order, then put them in
3102 forward order at the end. Each struct-declaration may
3103 declare multiple components (comma-separated), so we must use
3104 chainon to join them, although when parsing each
3105 struct-declaration we can use TREE_CHAIN directly.
3107 The theory behind all this is that there will be more
3108 semicolon separated fields than comma separated fields, and
3109 so we'll be minimizing the number of node traversals required
3112 timevar_push (TV_PARSE_STRUCT
);
3113 contents
= NULL_TREE
;
3114 c_parser_consume_token (parser
);
3115 /* Handle the Objective-C @defs construct,
3116 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
3117 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
3120 gcc_assert (c_dialect_objc ());
3121 c_parser_consume_token (parser
);
3122 matching_parens parens
;
3123 if (!parens
.require_open (parser
))
3125 if (c_parser_next_token_is (parser
, CPP_NAME
)
3126 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
3128 name
= c_parser_peek_token (parser
)->value
;
3129 c_parser_consume_token (parser
);
3133 c_parser_error (parser
, "expected class name");
3134 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3137 parens
.skip_until_found_close (parser
);
3138 contents
= nreverse (objc_get_class_ivars (name
));
3141 /* Parse the struct-declarations and semicolons. Problems with
3142 semicolons are diagnosed here; empty structures are diagnosed
3147 /* Parse any stray semicolon. */
3148 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3150 location_t semicolon_loc
3151 = c_parser_peek_token (parser
)->location
;
3152 gcc_rich_location
richloc (semicolon_loc
);
3153 richloc
.add_fixit_remove ();
3154 pedwarn (&richloc
, OPT_Wpedantic
,
3155 "extra semicolon in struct or union specified");
3156 c_parser_consume_token (parser
);
3159 /* Stop if at the end of the struct or union contents. */
3160 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3162 c_parser_consume_token (parser
);
3165 /* Accept #pragmas at struct scope. */
3166 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3168 c_parser_pragma (parser
, pragma_struct
, NULL
);
3171 /* Parse some comma-separated declarations, but not the
3172 trailing semicolon if any. */
3173 decls
= c_parser_struct_declaration (parser
);
3174 contents
= chainon (decls
, contents
);
3175 /* If no semicolon follows, either we have a parse error or
3176 are at the end of the struct or union and should
3178 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3179 c_parser_consume_token (parser
);
3182 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3183 pedwarn (c_parser_peek_token (parser
)->location
, 0,
3184 "no semicolon at end of struct or union");
3185 else if (parser
->error
3186 || !c_parser_next_token_starts_declspecs (parser
))
3188 c_parser_error (parser
, "expected %<;%>");
3189 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
3193 /* If we come here, we have already emitted an error
3194 for an expected `;', identifier or `(', and we also
3195 recovered already. Go on with the next field. */
3198 postfix_attrs
= c_parser_attributes (parser
);
3199 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
3200 chainon (attrs
, postfix_attrs
), struct_info
);
3201 ret
.kind
= ctsk_tagdef
;
3202 ret
.expr
= NULL_TREE
;
3203 ret
.expr_const_operands
= true;
3204 timevar_pop (TV_PARSE_STRUCT
);
3209 c_parser_error (parser
, "expected %<{%>");
3210 ret
.spec
= error_mark_node
;
3211 ret
.kind
= ctsk_tagref
;
3212 ret
.expr
= NULL_TREE
;
3213 ret
.expr_const_operands
= true;
3216 ret
= parser_xref_tag (ident_loc
, code
, ident
);
3220 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1),
3221 *without* the trailing semicolon.
3224 specifier-qualifier-list struct-declarator-list
3225 static_assert-declaration-no-semi
3227 specifier-qualifier-list:
3228 type-specifier specifier-qualifier-list[opt]
3229 type-qualifier specifier-qualifier-list[opt]
3230 alignment-specifier specifier-qualifier-list[opt]
3231 attributes specifier-qualifier-list[opt]
3233 struct-declarator-list:
3235 struct-declarator-list , attributes[opt] struct-declarator
3238 declarator attributes[opt]
3239 declarator[opt] : constant-expression attributes[opt]
3244 __extension__ struct-declaration
3245 specifier-qualifier-list
3247 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
3248 of attributes where shown is a GNU extension. In GNU C, we accept
3249 any expression without commas in the syntax (assignment
3250 expressions, not just conditional expressions); assignment
3251 expressions will be diagnosed as non-constant. */
3254 c_parser_struct_declaration (c_parser
*parser
)
3256 struct c_declspecs
*specs
;
3258 tree all_prefix_attrs
;
3260 location_t decl_loc
;
3261 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3265 ext
= disable_extension_diagnostics ();
3266 c_parser_consume_token (parser
);
3267 decl
= c_parser_struct_declaration (parser
);
3268 restore_extension_diagnostics (ext
);
3271 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
3273 c_parser_static_assert_declaration_no_semi (parser
);
3276 specs
= build_null_declspecs ();
3277 decl_loc
= c_parser_peek_token (parser
)->location
;
3278 /* Strictly by the standard, we shouldn't allow _Alignas here,
3279 but it appears to have been intended to allow it there, so
3280 we're keeping it as it is until WG14 reaches a conclusion
3282 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
3283 c_parser_declspecs (parser
, specs
, false, true, true,
3284 true, false, cla_nonabstract_decl
);
3287 if (!specs
->declspecs_seen_p
)
3289 c_parser_error (parser
, "expected specifier-qualifier-list");
3292 finish_declspecs (specs
);
3293 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3294 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3297 if (specs
->typespec_kind
== ctsk_none
)
3299 pedwarn (decl_loc
, OPT_Wpedantic
,
3300 "ISO C forbids member declarations with no members");
3301 shadow_tag_warned (specs
, pedantic
);
3306 /* Support for unnamed structs or unions as members of
3307 structs or unions (which is [a] useful and [b] supports
3311 ret
= grokfield (c_parser_peek_token (parser
)->location
,
3312 build_id_declarator (NULL_TREE
), specs
,
3315 decl_attributes (&ret
, attrs
, 0);
3320 /* Provide better error recovery. Note that a type name here is valid,
3321 and will be treated as a field name. */
3322 if (specs
->typespec_kind
== ctsk_tagdef
3323 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
3324 && c_parser_next_token_starts_declspecs (parser
)
3325 && !c_parser_next_token_is (parser
, CPP_NAME
))
3327 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
3328 parser
->error
= false;
3332 pending_xref_error ();
3333 prefix_attrs
= specs
->attrs
;
3334 all_prefix_attrs
= prefix_attrs
;
3335 specs
->attrs
= NULL_TREE
;
3339 /* Declaring one or more declarators or un-named bit-fields. */
3340 struct c_declarator
*declarator
;
3342 if (c_parser_next_token_is (parser
, CPP_COLON
))
3343 declarator
= build_id_declarator (NULL_TREE
);
3345 declarator
= c_parser_declarator (parser
,
3346 specs
->typespec_kind
!= ctsk_none
,
3347 C_DTR_NORMAL
, &dummy
);
3348 if (declarator
== NULL
)
3350 c_parser_skip_to_end_of_block_or_statement (parser
);
3353 if (c_parser_next_token_is (parser
, CPP_COLON
)
3354 || c_parser_next_token_is (parser
, CPP_COMMA
)
3355 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3356 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
3357 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3359 tree postfix_attrs
= NULL_TREE
;
3360 tree width
= NULL_TREE
;
3362 if (c_parser_next_token_is (parser
, CPP_COLON
))
3364 c_parser_consume_token (parser
);
3365 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
3367 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3368 postfix_attrs
= c_parser_attributes (parser
);
3369 d
= grokfield (c_parser_peek_token (parser
)->location
,
3370 declarator
, specs
, width
, &all_prefix_attrs
);
3371 decl_attributes (&d
, chainon (postfix_attrs
,
3372 all_prefix_attrs
), 0);
3373 DECL_CHAIN (d
) = decls
;
3375 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3376 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
3379 all_prefix_attrs
= prefix_attrs
;
3380 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3381 c_parser_consume_token (parser
);
3382 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3383 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3385 /* Semicolon consumed in caller. */
3390 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3396 c_parser_error (parser
,
3397 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3398 "%<__attribute__%>");
3405 /* Parse a typeof specifier (a GNU extension).
3408 typeof ( expression )
3409 typeof ( type-name )
3412 static struct c_typespec
3413 c_parser_typeof_specifier (c_parser
*parser
)
3415 struct c_typespec ret
;
3416 ret
.kind
= ctsk_typeof
;
3417 ret
.spec
= error_mark_node
;
3418 ret
.expr
= NULL_TREE
;
3419 ret
.expr_const_operands
= true;
3420 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3421 c_parser_consume_token (parser
);
3422 c_inhibit_evaluation_warnings
++;
3424 matching_parens parens
;
3425 if (!parens
.require_open (parser
))
3427 c_inhibit_evaluation_warnings
--;
3431 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3433 struct c_type_name
*type
= c_parser_type_name (parser
);
3434 c_inhibit_evaluation_warnings
--;
3438 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3439 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3445 location_t here
= c_parser_peek_token (parser
)->location
;
3446 struct c_expr expr
= c_parser_expression (parser
);
3447 c_inhibit_evaluation_warnings
--;
3449 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3450 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3451 error_at (here
, "%<typeof%> applied to a bit-field");
3452 mark_exp_read (expr
.value
);
3453 ret
.spec
= TREE_TYPE (expr
.value
);
3454 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3455 /* This is returned with the type so that when the type is
3456 evaluated, this can be evaluated. */
3458 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3459 pop_maybe_used (was_vm
);
3460 /* For use in macros such as those in <stdatomic.h>, remove all
3461 qualifiers from atomic types. (const can be an issue for more macros
3462 using typeof than just the <stdatomic.h> ones.) */
3463 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3464 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3466 parens
.skip_until_found_close (parser
);
3470 /* Parse an alignment-specifier.
3474 alignment-specifier:
3475 _Alignas ( type-name )
3476 _Alignas ( constant-expression )
3480 c_parser_alignas_specifier (c_parser
* parser
)
3482 tree ret
= error_mark_node
;
3483 location_t loc
= c_parser_peek_token (parser
)->location
;
3484 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3485 c_parser_consume_token (parser
);
3487 pedwarn_c99 (loc
, OPT_Wpedantic
,
3488 "ISO C99 does not support %<_Alignas%>");
3490 pedwarn_c99 (loc
, OPT_Wpedantic
,
3491 "ISO C90 does not support %<_Alignas%>");
3492 matching_parens parens
;
3493 if (!parens
.require_open (parser
))
3495 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3497 struct c_type_name
*type
= c_parser_type_name (parser
);
3499 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3503 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3504 parens
.skip_until_found_close (parser
);
3508 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3509 6.5.5, C99 6.7.5, 6.7.6, C11 6.7.6, 6.7.7). If TYPE_SEEN_P then
3510 a typedef name may be redeclared; otherwise it may not. KIND
3511 indicates which kind of declarator is wanted. Returns a valid
3512 declarator except in the case of a syntax error in which case NULL is
3513 returned. *SEEN_ID is set to true if an identifier being declared is
3514 seen; this is used to diagnose bad forms of abstract array declarators
3515 and to determine whether an identifier list is syntactically permitted.
3518 pointer[opt] direct-declarator
3522 ( attributes[opt] declarator )
3523 direct-declarator array-declarator
3524 direct-declarator ( parameter-type-list )
3525 direct-declarator ( identifier-list[opt] )
3528 * type-qualifier-list[opt]
3529 * type-qualifier-list[opt] pointer
3531 type-qualifier-list:
3534 type-qualifier-list type-qualifier
3535 type-qualifier-list attributes
3538 [ type-qualifier-list[opt] assignment-expression[opt] ]
3539 [ static type-qualifier-list[opt] assignment-expression ]
3540 [ type-qualifier-list static assignment-expression ]
3541 [ type-qualifier-list[opt] * ]
3543 parameter-type-list:
3545 parameter-list , ...
3548 parameter-declaration
3549 parameter-list , parameter-declaration
3551 parameter-declaration:
3552 declaration-specifiers declarator attributes[opt]
3553 declaration-specifiers abstract-declarator[opt] attributes[opt]
3557 identifier-list , identifier
3559 abstract-declarator:
3561 pointer[opt] direct-abstract-declarator
3563 direct-abstract-declarator:
3564 ( attributes[opt] abstract-declarator )
3565 direct-abstract-declarator[opt] array-declarator
3566 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3571 direct-declarator ( parameter-forward-declarations
3572 parameter-type-list[opt] )
3574 direct-abstract-declarator:
3575 direct-abstract-declarator[opt] ( parameter-forward-declarations
3576 parameter-type-list[opt] )
3578 parameter-forward-declarations:
3580 parameter-forward-declarations parameter-list ;
3582 The uses of attributes shown above are GNU extensions.
3584 Some forms of array declarator are not included in C99 in the
3585 syntax for abstract declarators; these are disallowed elsewhere.
3586 This may be a defect (DR#289).
3588 This function also accepts an omitted abstract declarator as being
3589 an abstract declarator, although not part of the formal syntax. */
3591 struct c_declarator
*
3592 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3595 /* Parse any initial pointer part. */
3596 if (c_parser_next_token_is (parser
, CPP_MULT
))
3598 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3599 struct c_declarator
*inner
;
3600 c_parser_consume_token (parser
);
3601 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3602 false, false, cla_prefer_id
);
3603 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3607 return make_pointer_declarator (quals_attrs
, inner
);
3609 /* Now we have a direct declarator, direct abstract declarator or
3610 nothing (which counts as a direct abstract declarator here). */
3611 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3614 /* Parse a direct declarator or direct abstract declarator; arguments
3615 as c_parser_declarator. */
3617 static struct c_declarator
*
3618 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3621 /* The direct declarator must start with an identifier (possibly
3622 omitted) or a parenthesized declarator (possibly abstract). In
3623 an ordinary declarator, initial parentheses must start a
3624 parenthesized declarator. In an abstract declarator or parameter
3625 declarator, they could start a parenthesized declarator or a
3626 parameter list. To tell which, the open parenthesis and any
3627 following attributes must be read. If a declaration specifier
3628 follows, then it is a parameter list; if the specifier is a
3629 typedef name, there might be an ambiguity about redeclaring it,
3630 which is resolved in the direction of treating it as a typedef
3631 name. If a close parenthesis follows, it is also an empty
3632 parameter list, as the syntax does not permit empty abstract
3633 declarators. Otherwise, it is a parenthesized declarator (in
3634 which case the analysis may be repeated inside it, recursively).
3636 ??? There is an ambiguity in a parameter declaration "int
3637 (__attribute__((foo)) x)", where x is not a typedef name: it
3638 could be an abstract declarator for a function, or declare x with
3639 parentheses. The proper resolution of this ambiguity needs
3640 documenting. At present we follow an accident of the old
3641 parser's implementation, whereby the first parameter must have
3642 some declaration specifiers other than just attributes. Thus as
3643 a parameter declaration it is treated as a parenthesized
3644 parameter named x, and as an abstract declarator it is
3647 ??? Also following the old parser, attributes inside an empty
3648 parameter list are ignored, making it a list not yielding a
3649 prototype, rather than giving an error or making it have one
3650 parameter with implicit type int.
3652 ??? Also following the old parser, typedef names may be
3653 redeclared in declarators, but not Objective-C class names. */
3655 if (kind
!= C_DTR_ABSTRACT
3656 && c_parser_next_token_is (parser
, CPP_NAME
)
3658 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3659 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3660 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3662 struct c_declarator
*inner
3663 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3665 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3666 c_parser_consume_token (parser
);
3667 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3670 if (kind
!= C_DTR_NORMAL
3671 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3673 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3674 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3675 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3678 /* Either we are at the end of an abstract declarator, or we have
3681 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3684 struct c_declarator
*inner
;
3685 c_parser_consume_token (parser
);
3686 attrs
= c_parser_attributes (parser
);
3687 if (kind
!= C_DTR_NORMAL
3688 && (c_parser_next_token_starts_declspecs (parser
)
3689 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3691 struct c_arg_info
*args
3692 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3699 = build_function_declarator (args
,
3700 build_id_declarator (NULL_TREE
));
3701 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3705 /* A parenthesized declarator. */
3706 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3707 if (inner
!= NULL
&& attrs
!= NULL
)
3708 inner
= build_attrs_declarator (attrs
, inner
);
3709 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3711 c_parser_consume_token (parser
);
3715 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3719 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3726 if (kind
== C_DTR_NORMAL
)
3728 c_parser_error (parser
, "expected identifier or %<(%>");
3732 return build_id_declarator (NULL_TREE
);
3736 /* Parse part of a direct declarator or direct abstract declarator,
3737 given that some (in INNER) has already been parsed; ID_PRESENT is
3738 true if an identifier is present, false for an abstract
3741 static struct c_declarator
*
3742 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3743 struct c_declarator
*inner
)
3745 /* Parse a sequence of array declarators and parameter lists. */
3746 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3748 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3749 struct c_declarator
*declarator
;
3750 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3753 struct c_expr dimen
;
3754 dimen
.value
= NULL_TREE
;
3755 dimen
.original_code
= ERROR_MARK
;
3756 dimen
.original_type
= NULL_TREE
;
3757 c_parser_consume_token (parser
);
3758 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3759 false, false, cla_prefer_id
);
3760 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3762 c_parser_consume_token (parser
);
3763 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3764 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3765 false, false, cla_prefer_id
);
3766 if (!quals_attrs
->declspecs_seen_p
)
3768 /* If "static" is present, there must be an array dimension.
3769 Otherwise, there may be a dimension, "*", or no
3774 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3778 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3780 dimen
.value
= NULL_TREE
;
3783 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3785 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3787 dimen
.value
= NULL_TREE
;
3789 c_parser_consume_token (parser
);
3794 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3800 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3803 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3804 c_parser_consume_token (parser
);
3807 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3812 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3813 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3814 static_seen
, star_seen
);
3815 if (declarator
== NULL
)
3817 inner
= set_array_declarator_inner (declarator
, inner
);
3818 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3820 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3823 struct c_arg_info
*args
;
3824 c_parser_consume_token (parser
);
3825 attrs
= c_parser_attributes (parser
);
3826 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3831 inner
= build_function_declarator (args
, inner
);
3832 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3838 /* Parse a parameter list or identifier list, including the closing
3839 parenthesis but not the opening one. ATTRS are the attributes at
3840 the start of the list. ID_LIST_OK is true if an identifier list is
3841 acceptable; such a list must not have attributes at the start. */
3843 static struct c_arg_info
*
3844 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3847 declare_parm_level ();
3848 /* If the list starts with an identifier, it is an identifier list.
3849 Otherwise, it is either a prototype list or an empty list. */
3852 && c_parser_next_token_is (parser
, CPP_NAME
)
3853 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3855 /* Look ahead to detect typos in type names. */
3856 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3857 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3858 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3859 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
3860 && c_parser_peek_2nd_token (parser
)->type
!= CPP_KEYWORD
)
3862 tree list
= NULL_TREE
, *nextp
= &list
;
3863 while (c_parser_next_token_is (parser
, CPP_NAME
)
3864 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3866 *nextp
= build_tree_list (NULL_TREE
,
3867 c_parser_peek_token (parser
)->value
);
3868 nextp
= & TREE_CHAIN (*nextp
);
3869 c_parser_consume_token (parser
);
3870 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3872 c_parser_consume_token (parser
);
3873 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3875 c_parser_error (parser
, "expected identifier");
3879 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3881 struct c_arg_info
*ret
= build_arg_info ();
3883 c_parser_consume_token (parser
);
3889 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3897 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3904 /* Parse a parameter list (possibly empty), including the closing
3905 parenthesis but not the opening one. ATTRS are the attributes at
3906 the start of the list. EXPR is NULL or an expression that needs to
3907 be evaluated for the side effects of array size expressions in the
3910 static struct c_arg_info
*
3911 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3913 bool bad_parm
= false;
3915 /* ??? Following the old parser, forward parameter declarations may
3916 use abstract declarators, and if no real parameter declarations
3917 follow the forward declarations then this is not diagnosed. Also
3918 note as above that attributes are ignored as the only contents of
3919 the parentheses, or as the only contents after forward
3921 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3923 struct c_arg_info
*ret
= build_arg_info ();
3924 c_parser_consume_token (parser
);
3927 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3929 struct c_arg_info
*ret
= build_arg_info ();
3931 if (flag_allow_parameterless_variadic_functions
)
3933 /* F (...) is allowed. */
3934 ret
->types
= NULL_TREE
;
3938 /* Suppress -Wold-style-definition for this case. */
3939 ret
->types
= error_mark_node
;
3940 error_at (c_parser_peek_token (parser
)->location
,
3941 "ISO C requires a named argument before %<...%>");
3943 c_parser_consume_token (parser
);
3944 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3946 c_parser_consume_token (parser
);
3951 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3956 /* Nonempty list of parameters, either terminated with semicolon
3957 (forward declarations; recurse) or with close parenthesis (normal
3958 function) or with ", ... )" (variadic function). */
3961 /* Parse a parameter. */
3962 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3967 push_parm_decl (parm
, &expr
);
3968 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3971 c_parser_consume_token (parser
);
3972 mark_forward_parm_decls ();
3973 new_attrs
= c_parser_attributes (parser
);
3974 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3976 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3978 c_parser_consume_token (parser
);
3982 return get_parm_info (false, expr
);
3984 if (!c_parser_require (parser
, CPP_COMMA
,
3985 "expected %<;%>, %<,%> or %<)%>",
3986 UNKNOWN_LOCATION
, false))
3988 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3991 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3993 c_parser_consume_token (parser
);
3994 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3996 c_parser_consume_token (parser
);
4000 return get_parm_info (true, expr
);
4004 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4012 /* Parse a parameter declaration. ATTRS are the attributes at the
4013 start of the declaration if it is the first parameter. */
4015 static struct c_parm
*
4016 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
4018 struct c_declspecs
*specs
;
4019 struct c_declarator
*declarator
;
4021 tree postfix_attrs
= NULL_TREE
;
4024 /* Accept #pragmas between parameter declarations. */
4025 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4026 c_parser_pragma (parser
, pragma_param
, NULL
);
4028 if (!c_parser_next_token_starts_declspecs (parser
))
4030 c_token
*token
= c_parser_peek_token (parser
);
4033 c_parser_set_source_position_from_token (token
);
4034 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
4036 name_hint hint
= lookup_name_fuzzy (token
->value
,
4037 FUZZY_LOOKUP_TYPENAME
,
4041 gcc_rich_location
richloc (token
->location
);
4042 richloc
.add_fixit_replace (hint
.suggestion ());
4044 "unknown type name %qE; did you mean %qs?",
4045 token
->value
, hint
.suggestion ());
4048 error_at (token
->location
, "unknown type name %qE", token
->value
);
4049 parser
->error
= true;
4051 /* ??? In some Objective-C cases '...' isn't applicable so there
4052 should be a different message. */
4054 c_parser_error (parser
,
4055 "expected declaration specifiers or %<...%>");
4056 c_parser_skip_to_end_of_parameter (parser
);
4060 location_t start_loc
= c_parser_peek_token (parser
)->location
;
4062 specs
= build_null_declspecs ();
4065 declspecs_add_attrs (input_location
, specs
, attrs
);
4068 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
4069 cla_nonabstract_decl
);
4070 finish_declspecs (specs
);
4071 pending_xref_error ();
4072 prefix_attrs
= specs
->attrs
;
4073 specs
->attrs
= NULL_TREE
;
4074 declarator
= c_parser_declarator (parser
,
4075 specs
->typespec_kind
!= ctsk_none
,
4076 C_DTR_PARM
, &dummy
);
4077 if (declarator
== NULL
)
4079 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4082 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4083 postfix_attrs
= c_parser_attributes (parser
);
4085 /* Generate a location for the parameter, ranging from the start of the
4086 initial token to the end of the final token.
4088 If we have a identifier, then use it for the caret location, e.g.
4090 extern int callee (int one, int (*two)(int, int), float three);
4091 ~~~~~~^~~~~~~~~~~~~~
4093 otherwise, reuse the start location for the caret location e.g.:
4095 extern int callee (int one, int (*)(int, int), float three);
4098 location_t end_loc
= parser
->last_token_location
;
4100 /* Find any cdk_id declarator; determine if we have an identifier. */
4101 c_declarator
*id_declarator
= declarator
;
4102 while (id_declarator
&& id_declarator
->kind
!= cdk_id
)
4103 id_declarator
= id_declarator
->declarator
;
4104 location_t caret_loc
= (id_declarator
->u
.id
4105 ? id_declarator
->id_loc
4107 location_t param_loc
= make_location (caret_loc
, start_loc
, end_loc
);
4109 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
4110 declarator
, param_loc
);
4113 /* Parse a string literal in an asm expression. It should not be
4114 translated, and wide string literals are an error although
4115 permitted by the syntax. This is a GNU extension.
4120 ??? At present, following the old parser, the caller needs to have
4121 set lex_untranslated_string to 1. It would be better to follow the
4122 C++ parser rather than using this kludge. */
4125 c_parser_asm_string_literal (c_parser
*parser
)
4128 int save_flag
= warn_overlength_strings
;
4129 warn_overlength_strings
= 0;
4130 if (c_parser_next_token_is (parser
, CPP_STRING
))
4132 str
= c_parser_peek_token (parser
)->value
;
4133 c_parser_consume_token (parser
);
4135 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
4137 error_at (c_parser_peek_token (parser
)->location
,
4138 "wide string literal in %<asm%>");
4139 str
= build_string (1, "");
4140 c_parser_consume_token (parser
);
4144 c_parser_error (parser
, "expected string literal");
4147 warn_overlength_strings
= save_flag
;
4151 /* Parse a simple asm expression. This is used in restricted
4152 contexts, where a full expression with inputs and outputs does not
4153 make sense. This is a GNU extension.
4156 asm ( asm-string-literal )
4160 c_parser_simple_asm_expr (c_parser
*parser
)
4163 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4164 /* ??? Follow the C++ parser rather than using the
4165 lex_untranslated_string kludge. */
4166 parser
->lex_untranslated_string
= true;
4167 c_parser_consume_token (parser
);
4168 matching_parens parens
;
4169 if (!parens
.require_open (parser
))
4171 parser
->lex_untranslated_string
= false;
4174 str
= c_parser_asm_string_literal (parser
);
4175 parser
->lex_untranslated_string
= false;
4176 if (!parens
.require_close (parser
))
4178 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4185 c_parser_attribute_any_word (c_parser
*parser
)
4187 tree attr_name
= NULL_TREE
;
4189 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
4191 /* ??? See comment above about what keywords are accepted here. */
4193 switch (c_parser_peek_token (parser
)->keyword
)
4224 case RID_TRANSACTION_ATOMIC
:
4225 case RID_TRANSACTION_CANCEL
:
4241 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
4242 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
4244 else if (c_parser_next_token_is (parser
, CPP_NAME
))
4245 attr_name
= c_parser_peek_token (parser
)->value
;
4250 /* Parse (possibly empty) attributes. This is a GNU extension.
4254 attributes attribute
4257 __attribute__ ( ( attribute-list ) )
4261 attribute_list , attrib
4266 any-word ( identifier )
4267 any-word ( identifier , nonempty-expr-list )
4268 any-word ( expr-list )
4270 where the "identifier" must not be declared as a type, and
4271 "any-word" may be any identifier (including one declared as a
4272 type), a reserved word storage class specifier, type specifier or
4273 type qualifier. ??? This still leaves out most reserved keywords
4274 (following the old parser), shouldn't we include them, and why not
4275 allow identifiers declared as types to start the arguments? */
4278 c_parser_attributes (c_parser
*parser
)
4280 tree attrs
= NULL_TREE
;
4281 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4283 /* ??? Follow the C++ parser rather than using the
4284 lex_untranslated_string kludge. */
4285 parser
->lex_untranslated_string
= true;
4286 /* Consume the `__attribute__' keyword. */
4287 c_parser_consume_token (parser
);
4288 /* Look for the two `(' tokens. */
4289 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4291 parser
->lex_untranslated_string
= false;
4294 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4296 parser
->lex_untranslated_string
= false;
4297 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4300 /* Parse the attribute list. */
4301 while (c_parser_next_token_is (parser
, CPP_COMMA
)
4302 || c_parser_next_token_is (parser
, CPP_NAME
)
4303 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
4305 tree attr
, attr_name
, attr_args
;
4306 vec
<tree
, va_gc
> *expr_list
;
4307 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4309 c_parser_consume_token (parser
);
4313 attr_name
= c_parser_attribute_any_word (parser
);
4314 if (attr_name
== NULL
)
4316 attr_name
= canonicalize_attr_name (attr_name
);
4317 c_parser_consume_token (parser
);
4318 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
4320 attr
= build_tree_list (attr_name
, NULL_TREE
);
4321 /* Add this attribute to the list. */
4322 attrs
= chainon (attrs
, attr
);
4323 /* If the next token isn't a comma, we're done. */
4324 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4328 c_parser_consume_token (parser
);
4329 /* Parse the attribute contents. If they start with an
4330 identifier which is followed by a comma or close
4331 parenthesis, then the arguments start with that
4332 identifier; otherwise they are an expression list.
4333 In objective-c the identifier may be a classname. */
4334 if (c_parser_next_token_is (parser
, CPP_NAME
)
4335 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4336 || (c_dialect_objc ()
4337 && c_parser_peek_token (parser
)->id_kind
4339 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4340 || (c_parser_peek_2nd_token (parser
)->type
4341 == CPP_CLOSE_PAREN
))
4342 && (attribute_takes_identifier_p (attr_name
)
4343 || (c_dialect_objc ()
4344 && c_parser_peek_token (parser
)->id_kind
4345 == C_ID_CLASSNAME
)))
4347 tree arg1
= c_parser_peek_token (parser
)->value
;
4348 c_parser_consume_token (parser
);
4349 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4350 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4354 c_parser_consume_token (parser
);
4355 expr_list
= c_parser_expr_list (parser
, false, true,
4356 NULL
, NULL
, NULL
, NULL
);
4357 tree_list
= build_tree_list_vec (expr_list
);
4358 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4359 release_tree_vector (expr_list
);
4364 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4365 attr_args
= NULL_TREE
;
4368 expr_list
= c_parser_expr_list (parser
, false, true,
4369 NULL
, NULL
, NULL
, NULL
);
4370 attr_args
= build_tree_list_vec (expr_list
);
4371 release_tree_vector (expr_list
);
4375 attr
= build_tree_list (attr_name
, attr_args
);
4376 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4377 c_parser_consume_token (parser
);
4380 parser
->lex_untranslated_string
= false;
4381 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4385 /* Add this attribute to the list. */
4386 attrs
= chainon (attrs
, attr
);
4387 /* If the next token isn't a comma, we're done. */
4388 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4391 /* Look for the two `)' tokens. */
4392 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4393 c_parser_consume_token (parser
);
4396 parser
->lex_untranslated_string
= false;
4397 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4401 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4402 c_parser_consume_token (parser
);
4405 parser
->lex_untranslated_string
= false;
4406 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4410 parser
->lex_untranslated_string
= false;
4416 /* Parse a type name (C90 6.5.5, C99 6.7.6, C11 6.7.7). ALIGNAS_OK
4417 says whether alignment specifiers are OK (only in cases that might
4418 be the type name of a compound literal).
4421 specifier-qualifier-list abstract-declarator[opt]
4424 struct c_type_name
*
4425 c_parser_type_name (c_parser
*parser
, bool alignas_ok
)
4427 struct c_declspecs
*specs
= build_null_declspecs ();
4428 struct c_declarator
*declarator
;
4429 struct c_type_name
*ret
;
4431 c_parser_declspecs (parser
, specs
, false, true, true, alignas_ok
, false,
4433 if (!specs
->declspecs_seen_p
)
4435 c_parser_error (parser
, "expected specifier-qualifier-list");
4438 if (specs
->type
!= error_mark_node
)
4440 pending_xref_error ();
4441 finish_declspecs (specs
);
4443 declarator
= c_parser_declarator (parser
,
4444 specs
->typespec_kind
!= ctsk_none
,
4445 C_DTR_ABSTRACT
, &dummy
);
4446 if (declarator
== NULL
)
4448 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4450 ret
->declarator
= declarator
;
4454 /* Parse an initializer (C90 6.5.7, C99 6.7.8, C11 6.7.9).
4457 assignment-expression
4458 { initializer-list }
4459 { initializer-list , }
4462 designation[opt] initializer
4463 initializer-list , designation[opt] initializer
4470 designator-list designator
4477 [ constant-expression ]
4489 [ constant-expression ... constant-expression ]
4491 Any expression without commas is accepted in the syntax for the
4492 constant-expressions, with non-constant expressions rejected later.
4494 This function is only used for top-level initializers; for nested
4495 ones, see c_parser_initval. */
4497 static struct c_expr
4498 c_parser_initializer (c_parser
*parser
)
4500 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4501 return c_parser_braced_init (parser
, NULL_TREE
, false, NULL
);
4505 location_t loc
= c_parser_peek_token (parser
)->location
;
4506 ret
= c_parser_expr_no_commas (parser
, NULL
);
4507 if (TREE_CODE (ret
.value
) != STRING_CST
4508 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4509 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4514 /* The location of the last comma within the current initializer list,
4515 or UNKNOWN_LOCATION if not within one. */
4517 location_t last_init_list_comma
;
4519 /* Parse a braced initializer list. TYPE is the type specified for a
4520 compound literal, and NULL_TREE for other initializers and for
4521 nested braced lists. NESTED_P is true for nested braced lists,
4522 false for the list of a compound literal or the list that is the
4523 top-level initializer in a declaration. */
4525 static struct c_expr
4526 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
,
4527 struct obstack
*outer_obstack
)
4530 struct obstack braced_init_obstack
;
4531 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4532 gcc_obstack_init (&braced_init_obstack
);
4533 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4534 matching_braces braces
;
4535 braces
.consume_open (parser
);
4538 finish_implicit_inits (brace_loc
, outer_obstack
);
4539 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4542 really_start_incremental_init (type
);
4543 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4545 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4549 /* Parse a non-empty initializer list, possibly with a trailing
4553 c_parser_initelt (parser
, &braced_init_obstack
);
4556 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4558 last_init_list_comma
= c_parser_peek_token (parser
)->location
;
4559 c_parser_consume_token (parser
);
4563 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4567 c_token
*next_tok
= c_parser_peek_token (parser
);
4568 if (next_tok
->type
!= CPP_CLOSE_BRACE
)
4570 ret
.value
= error_mark_node
;
4571 ret
.original_code
= ERROR_MARK
;
4572 ret
.original_type
= NULL
;
4573 braces
.skip_until_found_close (parser
);
4574 pop_init_level (brace_loc
, 0, &braced_init_obstack
, last_init_list_comma
);
4575 obstack_free (&braced_init_obstack
, NULL
);
4578 location_t close_loc
= next_tok
->location
;
4579 c_parser_consume_token (parser
);
4580 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
, close_loc
);
4581 obstack_free (&braced_init_obstack
, NULL
);
4582 set_c_expr_source_range (&ret
, brace_loc
, close_loc
);
4586 /* Parse a nested initializer, including designators. */
4589 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4591 /* Parse any designator or designator list. A single array
4592 designator may have the subsequent "=" omitted in GNU C, but a
4593 longer list or a structure member designator may not. */
4594 if (c_parser_next_token_is (parser
, CPP_NAME
)
4595 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4597 /* Old-style structure member designator. */
4598 set_init_label (c_parser_peek_token (parser
)->location
,
4599 c_parser_peek_token (parser
)->value
,
4600 c_parser_peek_token (parser
)->location
,
4601 braced_init_obstack
);
4602 /* Use the colon as the error location. */
4603 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4604 "obsolete use of designated initializer with %<:%>");
4605 c_parser_consume_token (parser
);
4606 c_parser_consume_token (parser
);
4610 /* des_seen is 0 if there have been no designators, 1 if there
4611 has been a single array designator and 2 otherwise. */
4613 /* Location of a designator. */
4614 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4615 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4616 || c_parser_next_token_is (parser
, CPP_DOT
))
4618 int des_prev
= des_seen
;
4620 des_loc
= c_parser_peek_token (parser
)->location
;
4623 if (c_parser_next_token_is (parser
, CPP_DOT
))
4626 c_parser_consume_token (parser
);
4627 if (c_parser_next_token_is (parser
, CPP_NAME
))
4629 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4630 c_parser_peek_token (parser
)->location
,
4631 braced_init_obstack
);
4632 c_parser_consume_token (parser
);
4637 init
.value
= error_mark_node
;
4638 init
.original_code
= ERROR_MARK
;
4639 init
.original_type
= NULL
;
4640 c_parser_error (parser
, "expected identifier");
4641 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4642 process_init_element (input_location
, init
, false,
4643 braced_init_obstack
);
4650 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4651 location_t array_index_loc
= UNKNOWN_LOCATION
;
4652 /* ??? Following the old parser, [ objc-receiver
4653 objc-message-args ] is accepted as an initializer,
4654 being distinguished from a designator by what follows
4655 the first assignment expression inside the square
4656 brackets, but after a first array designator a
4657 subsequent square bracket is for Objective-C taken to
4658 start an expression, using the obsolete form of
4659 designated initializer without '=', rather than
4660 possibly being a second level of designation: in LALR
4661 terms, the '[' is shifted rather than reducing
4662 designator to designator-list. */
4663 if (des_prev
== 1 && c_dialect_objc ())
4665 des_seen
= des_prev
;
4668 if (des_prev
== 0 && c_dialect_objc ())
4670 /* This might be an array designator or an
4671 Objective-C message expression. If the former,
4672 continue parsing here; if the latter, parse the
4673 remainder of the initializer given the starting
4674 primary-expression. ??? It might make sense to
4675 distinguish when des_prev == 1 as well; see
4676 previous comment. */
4678 struct c_expr mexpr
;
4679 c_parser_consume_token (parser
);
4680 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4681 && ((c_parser_peek_token (parser
)->id_kind
4683 || (c_parser_peek_token (parser
)->id_kind
4684 == C_ID_CLASSNAME
)))
4686 /* Type name receiver. */
4687 tree id
= c_parser_peek_token (parser
)->value
;
4688 c_parser_consume_token (parser
);
4689 rec
= objc_get_class_reference (id
);
4690 goto parse_message_args
;
4692 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4693 mark_exp_read (first
);
4694 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4695 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4696 goto array_desig_after_first
;
4697 /* Expression receiver. So far only one part
4698 without commas has been parsed; there might be
4699 more of the expression. */
4701 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4704 location_t comma_loc
, exp_loc
;
4705 comma_loc
= c_parser_peek_token (parser
)->location
;
4706 c_parser_consume_token (parser
);
4707 exp_loc
= c_parser_peek_token (parser
)->location
;
4708 next
= c_parser_expr_no_commas (parser
, NULL
);
4709 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4711 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4714 /* Now parse the objc-message-args. */
4715 args
= c_parser_objc_message_args (parser
);
4716 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4719 = objc_build_message_expr (rec
, args
);
4720 mexpr
.original_code
= ERROR_MARK
;
4721 mexpr
.original_type
= NULL
;
4722 /* Now parse and process the remainder of the
4723 initializer, starting with this message
4724 expression as a primary-expression. */
4725 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4728 c_parser_consume_token (parser
);
4729 array_index_loc
= c_parser_peek_token (parser
)->location
;
4730 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4731 mark_exp_read (first
);
4732 array_desig_after_first
:
4733 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4735 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4736 c_parser_consume_token (parser
);
4737 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4738 mark_exp_read (second
);
4742 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4744 c_parser_consume_token (parser
);
4745 set_init_index (array_index_loc
, first
, second
,
4746 braced_init_obstack
);
4748 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4749 "ISO C forbids specifying range of elements to initialize");
4752 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4758 if (c_parser_next_token_is (parser
, CPP_EQ
))
4760 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4761 "ISO C90 forbids specifying subobject "
4763 c_parser_consume_token (parser
);
4768 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4769 "obsolete use of designated initializer without %<=%>");
4773 init
.value
= error_mark_node
;
4774 init
.original_code
= ERROR_MARK
;
4775 init
.original_type
= NULL
;
4776 c_parser_error (parser
, "expected %<=%>");
4777 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4778 process_init_element (input_location
, init
, false,
4779 braced_init_obstack
);
4785 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4788 /* Parse a nested initializer; as c_parser_initializer but parses
4789 initializers within braced lists, after any designators have been
4790 applied. If AFTER is not NULL then it is an Objective-C message
4791 expression which is the primary-expression starting the
4795 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4796 struct obstack
* braced_init_obstack
)
4799 gcc_assert (!after
|| c_dialect_objc ());
4800 location_t loc
= c_parser_peek_token (parser
)->location
;
4802 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4803 init
= c_parser_braced_init (parser
, NULL_TREE
, true,
4804 braced_init_obstack
);
4807 init
= c_parser_expr_no_commas (parser
, after
);
4808 if (init
.value
!= NULL_TREE
4809 && TREE_CODE (init
.value
) != STRING_CST
4810 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4811 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4813 process_init_element (loc
, init
, false, braced_init_obstack
);
4816 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4817 C99 6.8.2, C11 6.8.2).
4820 { block-item-list[opt] }
4821 { label-declarations block-item-list }
4825 block-item-list block-item
4837 { label-declarations block-item-list }
4840 __extension__ nested-declaration
4841 nested-function-definition
4845 label-declarations label-declaration
4848 __label__ identifier-list ;
4850 Allowing the mixing of declarations and code is new in C99. The
4851 GNU syntax also permits (not shown above) labels at the end of
4852 compound statements, which yield an error. We don't allow labels
4853 on declarations; this might seem like a natural extension, but
4854 there would be a conflict between attributes on the label and
4855 prefix attributes on the declaration. ??? The syntax follows the
4856 old parser in requiring something after label declarations.
4857 Although they are erroneous if the labels declared aren't defined,
4858 is it useful for the syntax to be this way?
4879 cancellation-point-directive */
4882 c_parser_compound_statement (c_parser
*parser
)
4885 location_t brace_loc
;
4886 brace_loc
= c_parser_peek_token (parser
)->location
;
4887 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4889 /* Ensure a scope is entered and left anyway to avoid confusion
4890 if we have just prepared to enter a function body. */
4891 stmt
= c_begin_compound_stmt (true);
4892 c_end_compound_stmt (brace_loc
, stmt
, true);
4893 return error_mark_node
;
4895 stmt
= c_begin_compound_stmt (true);
4896 c_parser_compound_statement_nostart (parser
);
4898 return c_end_compound_stmt (brace_loc
, stmt
, true);
4901 /* Parse a compound statement except for the opening brace. This is
4902 used for parsing both compound statements and statement expressions
4903 (which follow different paths to handling the opening). */
4906 c_parser_compound_statement_nostart (c_parser
*parser
)
4908 bool last_stmt
= false;
4909 bool last_label
= false;
4910 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4911 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4912 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4914 c_parser_consume_token (parser
);
4917 mark_valid_location_for_stdc_pragma (true);
4918 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4920 /* Read zero or more forward-declarations for labels that nested
4921 functions can jump to. */
4922 mark_valid_location_for_stdc_pragma (false);
4923 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4925 label_loc
= c_parser_peek_token (parser
)->location
;
4926 c_parser_consume_token (parser
);
4927 /* Any identifiers, including those declared as type names,
4932 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4934 c_parser_error (parser
, "expected identifier");
4938 = declare_label (c_parser_peek_token (parser
)->value
);
4939 C_DECLARED_LABEL_FLAG (label
) = 1;
4940 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4941 c_parser_consume_token (parser
);
4942 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4943 c_parser_consume_token (parser
);
4947 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4949 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4951 /* We must now have at least one statement, label or declaration. */
4952 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4954 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4955 c_parser_error (parser
, "expected declaration or statement");
4956 c_parser_consume_token (parser
);
4959 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4961 location_t loc
= c_parser_peek_token (parser
)->location
;
4962 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4963 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4964 || (c_parser_next_token_is (parser
, CPP_NAME
)
4965 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4967 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4968 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4970 label_loc
= c_parser_peek_token (parser
)->location
;
4973 mark_valid_location_for_stdc_pragma (false);
4974 c_parser_label (parser
);
4976 else if (!last_label
4977 && c_parser_next_tokens_start_declaration (parser
))
4980 mark_valid_location_for_stdc_pragma (false);
4981 bool fallthru_attr_p
= false;
4982 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4983 true, NULL
, vNULL
, NULL
,
4985 if (last_stmt
&& !fallthru_attr_p
)
4986 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4987 "ISO C90 forbids mixed declarations and code");
4988 last_stmt
= fallthru_attr_p
;
4990 else if (!last_label
4991 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4993 /* __extension__ can start a declaration, but is also an
4994 unary operator that can start an expression. Consume all
4995 but the last of a possible series of __extension__ to
4997 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4998 && (c_parser_peek_2nd_token (parser
)->keyword
5000 c_parser_consume_token (parser
);
5001 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5004 ext
= disable_extension_diagnostics ();
5005 c_parser_consume_token (parser
);
5007 mark_valid_location_for_stdc_pragma (false);
5008 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5010 /* Following the old parser, __extension__ does not
5011 disable this diagnostic. */
5012 restore_extension_diagnostics (ext
);
5014 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
5015 "ISO C90 forbids mixed declarations and code");
5021 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
5023 /* External pragmas, and some omp pragmas, are not associated
5024 with regular c code, and so are not to be considered statements
5025 syntactically. This ensures that the user doesn't put them
5026 places that would turn into syntax errors if the directive
5028 if (c_parser_pragma (parser
,
5029 last_label
? pragma_stmt
: pragma_compound
,
5031 last_label
= false, last_stmt
= true;
5033 else if (c_parser_next_token_is (parser
, CPP_EOF
))
5035 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5036 c_parser_error (parser
, "expected declaration or statement");
5039 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5041 if (parser
->in_if_block
)
5043 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5044 error_at (loc
, "expected %<}%> before %<else%>");
5049 error_at (loc
, "%<else%> without a previous %<if%>");
5050 c_parser_consume_token (parser
);
5059 mark_valid_location_for_stdc_pragma (false);
5060 c_parser_statement_after_labels (parser
, NULL
);
5063 parser
->error
= false;
5066 error_at (label_loc
, "label at end of compound statement");
5067 c_parser_consume_token (parser
);
5068 /* Restore the value we started with. */
5069 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5072 /* Parse all consecutive labels. */
5075 c_parser_all_labels (c_parser
*parser
)
5077 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5078 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5079 || (c_parser_next_token_is (parser
, CPP_NAME
)
5080 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5081 c_parser_label (parser
);
5084 /* Parse a label (C90 6.6.1, C99 6.8.1, C11 6.8.1).
5087 identifier : attributes[opt]
5088 case constant-expression :
5094 case constant-expression ... constant-expression :
5096 The use of attributes on labels is a GNU extension. The syntax in
5097 GNU C accepts any expressions without commas, non-constant
5098 expressions being rejected later. */
5101 c_parser_label (c_parser
*parser
)
5103 location_t loc1
= c_parser_peek_token (parser
)->location
;
5104 tree label
= NULL_TREE
;
5106 /* Remember whether this case or a user-defined label is allowed to fall
5108 bool fallthrough_p
= c_parser_peek_token (parser
)->flags
& PREV_FALLTHROUGH
;
5110 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
5113 c_parser_consume_token (parser
);
5114 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
5115 if (c_parser_next_token_is (parser
, CPP_COLON
))
5117 c_parser_consume_token (parser
);
5118 label
= do_case (loc1
, exp1
, NULL_TREE
);
5120 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
5122 c_parser_consume_token (parser
);
5123 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
5124 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5125 label
= do_case (loc1
, exp1
, exp2
);
5128 c_parser_error (parser
, "expected %<:%> or %<...%>");
5130 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
5132 c_parser_consume_token (parser
);
5133 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5134 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
5138 tree name
= c_parser_peek_token (parser
)->value
;
5141 location_t loc2
= c_parser_peek_token (parser
)->location
;
5142 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
5143 c_parser_consume_token (parser
);
5144 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
5145 c_parser_consume_token (parser
);
5146 attrs
= c_parser_attributes (parser
);
5147 tlab
= define_label (loc2
, name
);
5150 decl_attributes (&tlab
, attrs
, 0);
5151 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
5156 if (TREE_CODE (label
) == LABEL_EXPR
)
5157 FALLTHROUGH_LABEL_P (LABEL_EXPR_LABEL (label
)) = fallthrough_p
;
5159 FALLTHROUGH_LABEL_P (CASE_LABEL (label
)) = fallthrough_p
;
5161 /* Allow '__attribute__((fallthrough));'. */
5162 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
5164 location_t loc
= c_parser_peek_token (parser
)->location
;
5165 tree attrs
= c_parser_attributes (parser
);
5166 if (attribute_fallthrough_p (attrs
))
5168 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5170 tree fn
= build_call_expr_internal_loc (loc
,
5176 warning_at (loc
, OPT_Wattributes
, "%<fallthrough%> attribute "
5177 "not followed by %<;%>");
5179 else if (attrs
!= NULL_TREE
)
5180 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5181 " can be applied to a null statement");
5183 if (c_parser_next_tokens_start_declaration (parser
))
5185 error_at (c_parser_peek_token (parser
)->location
,
5186 "a label can only be part of a statement and "
5187 "a declaration is not a statement");
5188 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
5189 /*static_assert_ok*/ true,
5190 /*empty_ok*/ true, /*nested*/ true,
5191 /*start_attr_ok*/ true, NULL
,
5197 /* Parse a statement (C90 6.6, C99 6.8, C11 6.8).
5202 expression-statement
5210 expression-statement:
5213 selection-statement:
5217 iteration-statement:
5226 return expression[opt] ;
5236 expression-statement:
5242 objc-throw-statement
5243 objc-try-catch-statement
5244 objc-synchronized-statement
5246 objc-throw-statement:
5262 parallel-directive structured-block
5265 kernels-directive structured-block
5268 data-directive structured-block
5271 loop-directive structured-block
5285 parallel-for-construct
5286 parallel-for-simd-construct
5287 parallel-sections-construct
5294 parallel-directive structured-block
5297 for-directive iteration-statement
5300 simd-directive iteration-statements
5303 for-simd-directive iteration-statements
5306 sections-directive section-scope
5309 single-directive structured-block
5311 parallel-for-construct:
5312 parallel-for-directive iteration-statement
5314 parallel-for-simd-construct:
5315 parallel-for-simd-directive iteration-statement
5317 parallel-sections-construct:
5318 parallel-sections-directive section-scope
5321 master-directive structured-block
5324 critical-directive structured-block
5327 atomic-directive expression-statement
5330 ordered-directive structured-block
5332 Transactional Memory:
5335 transaction-statement
5336 transaction-cancel-statement
5338 IF_P is used to track whether there's a (possibly labeled) if statement
5339 which is not enclosed in braces and has an else clause. This is used to
5340 implement -Wparentheses. */
5343 c_parser_statement (c_parser
*parser
, bool *if_p
, location_t
*loc_after_labels
)
5345 c_parser_all_labels (parser
);
5346 if (loc_after_labels
)
5347 *loc_after_labels
= c_parser_peek_token (parser
)->location
;
5348 c_parser_statement_after_labels (parser
, if_p
, NULL
);
5351 /* Parse a statement, other than a labeled statement. CHAIN is a vector
5352 of if-else-if conditions.
5354 IF_P is used to track whether there's a (possibly labeled) if statement
5355 which is not enclosed in braces and has an else clause. This is used to
5356 implement -Wparentheses. */
5359 c_parser_statement_after_labels (c_parser
*parser
, bool *if_p
,
5362 location_t loc
= c_parser_peek_token (parser
)->location
;
5363 tree stmt
= NULL_TREE
;
5364 bool in_if_block
= parser
->in_if_block
;
5365 parser
->in_if_block
= false;
5368 switch (c_parser_peek_token (parser
)->type
)
5370 case CPP_OPEN_BRACE
:
5371 add_stmt (c_parser_compound_statement (parser
));
5374 switch (c_parser_peek_token (parser
)->keyword
)
5377 c_parser_if_statement (parser
, if_p
, chain
);
5380 c_parser_switch_statement (parser
, if_p
);
5383 c_parser_while_statement (parser
, false, if_p
);
5386 c_parser_do_statement (parser
, false);
5389 c_parser_for_statement (parser
, false, if_p
);
5392 c_parser_consume_token (parser
);
5393 if (c_parser_next_token_is (parser
, CPP_NAME
))
5395 stmt
= c_finish_goto_label (loc
,
5396 c_parser_peek_token (parser
)->value
);
5397 c_parser_consume_token (parser
);
5399 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5403 c_parser_consume_token (parser
);
5404 val
= c_parser_expression (parser
);
5405 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5406 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5409 c_parser_error (parser
, "expected identifier or %<*%>");
5410 goto expect_semicolon
;
5412 c_parser_consume_token (parser
);
5413 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5414 goto expect_semicolon
;
5416 c_parser_consume_token (parser
);
5417 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5418 goto expect_semicolon
;
5420 c_parser_consume_token (parser
);
5421 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5423 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5424 c_parser_consume_token (parser
);
5428 location_t xloc
= c_parser_peek_token (parser
)->location
;
5429 struct c_expr expr
= c_parser_expression_conv (parser
);
5430 mark_exp_read (expr
.value
);
5431 stmt
= c_finish_return (EXPR_LOC_OR_LOC (expr
.value
, xloc
),
5432 expr
.value
, expr
.original_type
);
5433 goto expect_semicolon
;
5437 stmt
= c_parser_asm_statement (parser
);
5439 case RID_TRANSACTION_ATOMIC
:
5440 case RID_TRANSACTION_RELAXED
:
5441 stmt
= c_parser_transaction (parser
,
5442 c_parser_peek_token (parser
)->keyword
);
5444 case RID_TRANSACTION_CANCEL
:
5445 stmt
= c_parser_transaction_cancel (parser
);
5446 goto expect_semicolon
;
5448 gcc_assert (c_dialect_objc ());
5449 c_parser_consume_token (parser
);
5450 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5452 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5453 c_parser_consume_token (parser
);
5457 struct c_expr expr
= c_parser_expression (parser
);
5458 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5459 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5460 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5461 goto expect_semicolon
;
5465 gcc_assert (c_dialect_objc ());
5466 c_parser_objc_try_catch_finally_statement (parser
);
5468 case RID_AT_SYNCHRONIZED
:
5469 gcc_assert (c_dialect_objc ());
5470 c_parser_objc_synchronized_statement (parser
);
5474 /* Allow '__attribute__((fallthrough));'. */
5475 tree attrs
= c_parser_attributes (parser
);
5476 if (attribute_fallthrough_p (attrs
))
5478 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5480 tree fn
= build_call_expr_internal_loc (loc
,
5485 c_parser_consume_token (parser
);
5488 warning_at (loc
, OPT_Wattributes
,
5489 "%<fallthrough%> attribute not followed "
5492 else if (attrs
!= NULL_TREE
)
5493 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5494 " can be applied to a null statement");
5502 c_parser_consume_token (parser
);
5504 case CPP_CLOSE_PAREN
:
5505 case CPP_CLOSE_SQUARE
:
5506 /* Avoid infinite loop in error recovery:
5507 c_parser_skip_until_found stops at a closing nesting
5508 delimiter without consuming it, but here we need to consume
5509 it to proceed further. */
5510 c_parser_error (parser
, "expected statement");
5511 c_parser_consume_token (parser
);
5514 c_parser_pragma (parser
, pragma_stmt
, if_p
);
5518 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5520 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5523 /* Two cases cannot and do not have line numbers associated: If stmt
5524 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5525 cannot hold line numbers. But that's OK because the statement
5526 will either be changed to a MODIFY_EXPR during gimplification of
5527 the statement expr, or discarded. If stmt was compound, but
5528 without new variables, we will have skipped the creation of a
5529 BIND and will have a bare STATEMENT_LIST. But that's OK because
5530 (recursively) all of the component statements should already have
5531 line numbers assigned. ??? Can we discard no-op statements
5533 if (EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5534 protected_set_expr_location (stmt
, loc
);
5536 parser
->in_if_block
= in_if_block
;
5539 /* Parse the condition from an if, do, while or for statements. */
5542 c_parser_condition (c_parser
*parser
)
5544 location_t loc
= c_parser_peek_token (parser
)->location
;
5546 cond
= c_parser_expression_conv (parser
).value
;
5547 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5548 cond
= c_fully_fold (cond
, false, NULL
);
5549 if (warn_sequence_point
)
5550 verify_sequence_points (cond
);
5554 /* Parse a parenthesized condition from an if, do or while statement.
5560 c_parser_paren_condition (c_parser
*parser
)
5563 matching_parens parens
;
5564 if (!parens
.require_open (parser
))
5565 return error_mark_node
;
5566 cond
= c_parser_condition (parser
);
5567 parens
.skip_until_found_close (parser
);
5571 /* Parse a statement which is a block in C99.
5573 IF_P is used to track whether there's a (possibly labeled) if statement
5574 which is not enclosed in braces and has an else clause. This is used to
5575 implement -Wparentheses. */
5578 c_parser_c99_block_statement (c_parser
*parser
, bool *if_p
,
5579 location_t
*loc_after_labels
)
5581 tree block
= c_begin_compound_stmt (flag_isoc99
);
5582 location_t loc
= c_parser_peek_token (parser
)->location
;
5583 c_parser_statement (parser
, if_p
, loc_after_labels
);
5584 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5587 /* Parse the body of an if statement. This is just parsing a
5588 statement but (a) it is a block in C99, (b) we track whether the
5589 body is an if statement for the sake of -Wparentheses warnings, (c)
5590 we handle an empty body specially for the sake of -Wempty-body
5591 warnings, and (d) we call parser_compound_statement directly
5592 because c_parser_statement_after_labels resets
5593 parser->in_if_block.
5595 IF_P is used to track whether there's a (possibly labeled) if statement
5596 which is not enclosed in braces and has an else clause. This is used to
5597 implement -Wparentheses. */
5600 c_parser_if_body (c_parser
*parser
, bool *if_p
,
5601 const token_indent_info
&if_tinfo
)
5603 tree block
= c_begin_compound_stmt (flag_isoc99
);
5604 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5605 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
5606 token_indent_info body_tinfo
5607 = get_token_indent_info (c_parser_peek_token (parser
));
5609 c_parser_all_labels (parser
);
5610 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5612 location_t loc
= c_parser_peek_token (parser
)->location
;
5613 add_stmt (build_empty_stmt (loc
));
5614 c_parser_consume_token (parser
);
5615 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5616 warning_at (loc
, OPT_Wempty_body
,
5617 "suggest braces around empty body in an %<if%> statement");
5619 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5620 add_stmt (c_parser_compound_statement (parser
));
5623 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5624 c_parser_statement_after_labels (parser
, if_p
);
5627 token_indent_info next_tinfo
5628 = get_token_indent_info (c_parser_peek_token (parser
));
5629 warn_for_misleading_indentation (if_tinfo
, body_tinfo
, next_tinfo
);
5630 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5631 && next_tinfo
.type
!= CPP_SEMICOLON
)
5632 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5633 if_tinfo
.location
, RID_IF
);
5635 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5638 /* Parse the else body of an if statement. This is just parsing a
5639 statement but (a) it is a block in C99, (b) we handle an empty body
5640 specially for the sake of -Wempty-body warnings. CHAIN is a vector
5641 of if-else-if conditions. */
5644 c_parser_else_body (c_parser
*parser
, const token_indent_info
&else_tinfo
,
5647 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5648 tree block
= c_begin_compound_stmt (flag_isoc99
);
5649 token_indent_info body_tinfo
5650 = get_token_indent_info (c_parser_peek_token (parser
));
5651 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
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
;
5659 "suggest braces around empty body in an %<else%> statement");
5660 add_stmt (build_empty_stmt (loc
));
5661 c_parser_consume_token (parser
);
5665 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5666 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5667 c_parser_statement_after_labels (parser
, NULL
, chain
);
5670 token_indent_info next_tinfo
5671 = get_token_indent_info (c_parser_peek_token (parser
));
5672 warn_for_misleading_indentation (else_tinfo
, body_tinfo
, next_tinfo
);
5673 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5674 && next_tinfo
.type
!= CPP_SEMICOLON
)
5675 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5676 else_tinfo
.location
, RID_ELSE
);
5678 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5681 /* We might need to reclassify any previously-lexed identifier, e.g.
5682 when we've left a for loop with an if-statement without else in the
5683 body - we might have used a wrong scope for the token. See PR67784. */
5686 c_parser_maybe_reclassify_token (c_parser
*parser
)
5688 if (c_parser_next_token_is (parser
, CPP_NAME
))
5690 c_token
*token
= c_parser_peek_token (parser
);
5692 if (token
->id_kind
!= C_ID_CLASSNAME
)
5694 tree decl
= lookup_name (token
->value
);
5696 token
->id_kind
= C_ID_ID
;
5699 if (TREE_CODE (decl
) == TYPE_DECL
)
5700 token
->id_kind
= C_ID_TYPENAME
;
5702 else if (c_dialect_objc ())
5704 tree objc_interface_decl
= objc_is_class_name (token
->value
);
5705 /* Objective-C class names are in the same namespace as
5706 variables and typedefs, and hence are shadowed by local
5708 if (objc_interface_decl
)
5710 token
->value
= objc_interface_decl
;
5711 token
->id_kind
= C_ID_CLASSNAME
;
5718 /* Parse an if statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5721 if ( expression ) statement
5722 if ( expression ) statement else statement
5724 CHAIN is a vector of if-else-if conditions.
5725 IF_P is used to track whether there's a (possibly labeled) if statement
5726 which is not enclosed in braces and has an else clause. This is used to
5727 implement -Wparentheses. */
5730 c_parser_if_statement (c_parser
*parser
, bool *if_p
, vec
<tree
> *chain
)
5735 bool nested_if
= false;
5736 tree first_body
, second_body
;
5739 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5740 token_indent_info if_tinfo
5741 = get_token_indent_info (c_parser_peek_token (parser
));
5742 c_parser_consume_token (parser
);
5743 block
= c_begin_compound_stmt (flag_isoc99
);
5744 loc
= c_parser_peek_token (parser
)->location
;
5745 cond
= c_parser_paren_condition (parser
);
5746 in_if_block
= parser
->in_if_block
;
5747 parser
->in_if_block
= true;
5748 first_body
= c_parser_if_body (parser
, &nested_if
, if_tinfo
);
5749 parser
->in_if_block
= in_if_block
;
5751 if (warn_duplicated_cond
)
5752 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond
), cond
, &chain
);
5754 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5756 token_indent_info else_tinfo
5757 = get_token_indent_info (c_parser_peek_token (parser
));
5758 c_parser_consume_token (parser
);
5759 if (warn_duplicated_cond
)
5761 if (c_parser_next_token_is_keyword (parser
, RID_IF
)
5764 /* We've got "if (COND) else if (COND2)". Start the
5765 condition chain and add COND as the first element. */
5766 chain
= new vec
<tree
> ();
5767 if (!CONSTANT_CLASS_P (cond
) && !TREE_SIDE_EFFECTS (cond
))
5768 chain
->safe_push (cond
);
5770 else if (!c_parser_next_token_is_keyword (parser
, RID_IF
))
5772 /* This is if-else without subsequent if. Zap the condition
5773 chain; we would have already warned at this point. */
5778 second_body
= c_parser_else_body (parser
, else_tinfo
, chain
);
5779 /* Set IF_P to true to indicate that this if statement has an
5780 else clause. This may trigger the Wparentheses warning
5781 below when we get back up to the parent if statement. */
5787 second_body
= NULL_TREE
;
5789 /* Diagnose an ambiguous else if if-then-else is nested inside
5792 warning_at (loc
, OPT_Wdangling_else
,
5793 "suggest explicit braces to avoid ambiguous %<else%>");
5795 if (warn_duplicated_cond
)
5797 /* This if statement does not have an else clause. We don't
5798 need the condition chain anymore. */
5803 c_finish_if_stmt (loc
, cond
, first_body
, second_body
);
5804 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5806 c_parser_maybe_reclassify_token (parser
);
5809 /* Parse a switch statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5812 switch (expression) statement
5816 c_parser_switch_statement (c_parser
*parser
, bool *if_p
)
5819 tree block
, expr
, body
, save_break
;
5820 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5821 location_t switch_cond_loc
;
5822 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5823 c_parser_consume_token (parser
);
5824 block
= c_begin_compound_stmt (flag_isoc99
);
5825 bool explicit_cast_p
= false;
5826 matching_parens parens
;
5827 if (parens
.require_open (parser
))
5829 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5830 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5831 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5832 explicit_cast_p
= true;
5833 ce
= c_parser_expression (parser
);
5834 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5836 /* ??? expr has no valid location? */
5837 parens
.skip_until_found_close (parser
);
5841 switch_cond_loc
= UNKNOWN_LOCATION
;
5842 expr
= error_mark_node
;
5843 ce
.original_type
= error_mark_node
;
5845 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5846 save_break
= c_break_label
;
5847 c_break_label
= NULL_TREE
;
5848 location_t loc_after_labels
;
5849 bool open_brace_p
= c_parser_peek_token (parser
)->type
== CPP_OPEN_BRACE
;
5850 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
5851 location_t next_loc
= c_parser_peek_token (parser
)->location
;
5852 if (!open_brace_p
&& c_parser_peek_token (parser
)->type
!= CPP_SEMICOLON
)
5853 warn_for_multistatement_macros (loc_after_labels
, next_loc
, switch_loc
,
5857 location_t here
= c_parser_peek_token (parser
)->location
;
5858 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5859 SET_EXPR_LOCATION (t
, here
);
5860 SWITCH_BREAK_LABEL_P (c_break_label
) = 1;
5861 append_to_statement_list_force (t
, &body
);
5863 c_finish_case (body
, ce
.original_type
);
5864 c_break_label
= save_break
;
5865 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5866 c_parser_maybe_reclassify_token (parser
);
5869 /* Parse a while statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5872 while (expression) statement
5874 IF_P is used to track whether there's a (possibly labeled) if statement
5875 which is not enclosed in braces and has an else clause. This is used to
5876 implement -Wparentheses. */
5879 c_parser_while_statement (c_parser
*parser
, bool ivdep
, bool *if_p
)
5881 tree block
, cond
, body
, save_break
, save_cont
;
5883 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5884 token_indent_info while_tinfo
5885 = get_token_indent_info (c_parser_peek_token (parser
));
5886 c_parser_consume_token (parser
);
5887 block
= c_begin_compound_stmt (flag_isoc99
);
5888 loc
= c_parser_peek_token (parser
)->location
;
5889 cond
= c_parser_paren_condition (parser
);
5890 if (ivdep
&& cond
!= error_mark_node
)
5891 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5892 build_int_cst (integer_type_node
,
5893 annot_expr_ivdep_kind
),
5895 save_break
= c_break_label
;
5896 c_break_label
= NULL_TREE
;
5897 save_cont
= c_cont_label
;
5898 c_cont_label
= NULL_TREE
;
5900 token_indent_info body_tinfo
5901 = get_token_indent_info (c_parser_peek_token (parser
));
5903 location_t loc_after_labels
;
5904 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
5905 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
5906 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5907 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5908 c_parser_maybe_reclassify_token (parser
);
5910 token_indent_info next_tinfo
5911 = get_token_indent_info (c_parser_peek_token (parser
));
5912 warn_for_misleading_indentation (while_tinfo
, body_tinfo
, next_tinfo
);
5914 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
5915 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
5916 while_tinfo
.location
, RID_WHILE
);
5918 c_break_label
= save_break
;
5919 c_cont_label
= save_cont
;
5922 /* Parse a do statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5925 do statement while ( expression ) ;
5929 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5931 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5933 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5934 c_parser_consume_token (parser
);
5935 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5936 warning_at (c_parser_peek_token (parser
)->location
,
5938 "suggest braces around empty body in %<do%> statement");
5939 block
= c_begin_compound_stmt (flag_isoc99
);
5940 loc
= c_parser_peek_token (parser
)->location
;
5941 save_break
= c_break_label
;
5942 c_break_label
= NULL_TREE
;
5943 save_cont
= c_cont_label
;
5944 c_cont_label
= NULL_TREE
;
5945 body
= c_parser_c99_block_statement (parser
, NULL
);
5946 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5947 new_break
= c_break_label
;
5948 c_break_label
= save_break
;
5949 new_cont
= c_cont_label
;
5950 c_cont_label
= save_cont
;
5951 cond
= c_parser_paren_condition (parser
);
5952 if (ivdep
&& cond
!= error_mark_node
)
5953 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5954 build_int_cst (integer_type_node
,
5955 annot_expr_ivdep_kind
),
5957 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5958 c_parser_skip_to_end_of_block_or_statement (parser
);
5959 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5960 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5963 /* Parse a for statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5966 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5967 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5969 The form with a declaration is new in C99.
5971 ??? In accordance with the old parser, the declaration may be a
5972 nested function, which is then rejected in check_for_loop_decls,
5973 but does it make any sense for this to be included in the grammar?
5974 Note in particular that the nested function does not include a
5975 trailing ';', whereas the "declaration" production includes one.
5976 Also, can we reject bad declarations earlier and cheaper than
5977 check_for_loop_decls?
5979 In Objective-C, there are two additional variants:
5982 for ( expression in expresssion ) statement
5983 for ( declaration in expression ) statement
5985 This is inconsistent with C, because the second variant is allowed
5986 even if c99 is not enabled.
5988 The rest of the comment documents these Objective-C foreach-statement.
5990 Here is the canonical example of the first variant:
5991 for (object in array) { do something with object }
5992 we call the first expression ("object") the "object_expression" and
5993 the second expression ("array") the "collection_expression".
5994 object_expression must be an lvalue of type "id" (a generic Objective-C
5995 object) because the loop works by assigning to object_expression the
5996 various objects from the collection_expression. collection_expression
5997 must evaluate to something of type "id" which responds to the method
5998 countByEnumeratingWithState:objects:count:.
6000 The canonical example of the second variant is:
6001 for (id object in array) { do something with object }
6002 which is completely equivalent to
6005 for (object in array) { do something with object }
6007 Note that initizializing 'object' in some way (eg, "for ((object =
6008 xxx) in array) { do something with object }") is possibly
6009 technically valid, but completely pointless as 'object' will be
6010 assigned to something else as soon as the loop starts. We should
6011 most likely reject it (TODO).
6013 The beginning of the Objective-C foreach-statement looks exactly
6014 like the beginning of the for-statement, and we can tell it is a
6015 foreach-statement only because the initial declaration or
6016 expression is terminated by 'in' instead of ';'.
6018 IF_P is used to track whether there's a (possibly labeled) if statement
6019 which is not enclosed in braces and has an else clause. This is used to
6020 implement -Wparentheses. */
6023 c_parser_for_statement (c_parser
*parser
, bool ivdep
, bool *if_p
)
6025 tree block
, cond
, incr
, save_break
, save_cont
, body
;
6026 /* The following are only used when parsing an ObjC foreach statement. */
6027 tree object_expression
;
6028 /* Silence the bogus uninitialized warning. */
6029 tree collection_expression
= NULL
;
6030 location_t loc
= c_parser_peek_token (parser
)->location
;
6031 location_t for_loc
= c_parser_peek_token (parser
)->location
;
6032 bool is_foreach_statement
= false;
6033 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
6034 token_indent_info for_tinfo
6035 = get_token_indent_info (c_parser_peek_token (parser
));
6036 c_parser_consume_token (parser
);
6037 /* Open a compound statement in Objective-C as well, just in case this is
6038 as foreach expression. */
6039 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
6040 cond
= error_mark_node
;
6041 incr
= error_mark_node
;
6042 matching_parens parens
;
6043 if (parens
.require_open (parser
))
6045 /* Parse the initialization declaration or expression. */
6046 object_expression
= error_mark_node
;
6047 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
6048 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6050 parser
->objc_could_be_foreach_context
= false;
6051 c_parser_consume_token (parser
);
6052 c_finish_expr_stmt (loc
, NULL_TREE
);
6054 else if (c_parser_next_tokens_start_declaration (parser
))
6056 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
6057 &object_expression
, vNULL
);
6058 parser
->objc_could_be_foreach_context
= false;
6060 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6062 c_parser_consume_token (parser
);
6063 is_foreach_statement
= true;
6064 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6065 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
6068 check_for_loop_decls (for_loc
, flag_isoc99
);
6070 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
6072 /* __extension__ can start a declaration, but is also an
6073 unary operator that can start an expression. Consume all
6074 but the last of a possible series of __extension__ to
6076 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
6077 && (c_parser_peek_2nd_token (parser
)->keyword
6079 c_parser_consume_token (parser
);
6080 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
6083 ext
= disable_extension_diagnostics ();
6084 c_parser_consume_token (parser
);
6085 c_parser_declaration_or_fndef (parser
, true, true, true, true,
6086 true, &object_expression
, vNULL
);
6087 parser
->objc_could_be_foreach_context
= false;
6089 restore_extension_diagnostics (ext
);
6090 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6092 c_parser_consume_token (parser
);
6093 is_foreach_statement
= true;
6094 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6095 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
6098 check_for_loop_decls (for_loc
, flag_isoc99
);
6108 tree init_expression
;
6109 ce
= c_parser_expression (parser
);
6110 init_expression
= ce
.value
;
6111 parser
->objc_could_be_foreach_context
= false;
6112 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6114 c_parser_consume_token (parser
);
6115 is_foreach_statement
= true;
6116 if (! lvalue_p (init_expression
))
6117 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
6118 object_expression
= c_fully_fold (init_expression
, false, NULL
);
6122 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6123 init_expression
= ce
.value
;
6124 c_finish_expr_stmt (loc
, init_expression
);
6125 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6129 /* Parse the loop condition. In the case of a foreach
6130 statement, there is no loop condition. */
6131 gcc_assert (!parser
->objc_could_be_foreach_context
);
6132 if (!is_foreach_statement
)
6134 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6138 c_parser_error (parser
, "missing loop condition in loop with "
6139 "%<GCC ivdep%> pragma");
6140 cond
= error_mark_node
;
6144 c_parser_consume_token (parser
);
6150 cond
= c_parser_condition (parser
);
6151 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
6154 if (ivdep
&& cond
!= error_mark_node
)
6155 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6156 build_int_cst (integer_type_node
,
6157 annot_expr_ivdep_kind
),
6160 /* Parse the increment expression (the third expression in a
6161 for-statement). In the case of a foreach-statement, this is
6162 the expression that follows the 'in'. */
6163 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6165 if (is_foreach_statement
)
6167 c_parser_error (parser
, "missing collection in fast enumeration");
6168 collection_expression
= error_mark_node
;
6171 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
6175 if (is_foreach_statement
)
6176 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
6180 struct c_expr ce
= c_parser_expression (parser
);
6181 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6182 incr
= c_process_expr_stmt (loc
, ce
.value
);
6185 parens
.skip_until_found_close (parser
);
6187 save_break
= c_break_label
;
6188 c_break_label
= NULL_TREE
;
6189 save_cont
= c_cont_label
;
6190 c_cont_label
= NULL_TREE
;
6192 token_indent_info body_tinfo
6193 = get_token_indent_info (c_parser_peek_token (parser
));
6195 location_t loc_after_labels
;
6196 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
6197 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
6199 if (is_foreach_statement
)
6200 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
6202 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
6203 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
6204 c_parser_maybe_reclassify_token (parser
);
6206 token_indent_info next_tinfo
6207 = get_token_indent_info (c_parser_peek_token (parser
));
6208 warn_for_misleading_indentation (for_tinfo
, body_tinfo
, next_tinfo
);
6210 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
6211 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
6212 for_tinfo
.location
, RID_FOR
);
6214 c_break_label
= save_break
;
6215 c_cont_label
= save_cont
;
6218 /* Parse an asm statement, a GNU extension. This is a full-blown asm
6219 statement with inputs, outputs, clobbers, and volatile tag
6223 asm type-qualifier[opt] ( asm-argument ) ;
6224 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
6228 asm-string-literal : asm-operands[opt]
6229 asm-string-literal : asm-operands[opt] : asm-operands[opt]
6230 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
6233 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
6236 Qualifiers other than volatile are accepted in the syntax but
6240 c_parser_asm_statement (c_parser
*parser
)
6242 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
6243 bool simple
, is_goto
;
6244 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
6245 int section
, nsections
;
6247 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
6248 c_parser_consume_token (parser
);
6249 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
6251 quals
= c_parser_peek_token (parser
)->value
;
6252 c_parser_consume_token (parser
);
6254 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
6255 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
6257 warning_at (c_parser_peek_token (parser
)->location
,
6259 "%E qualifier ignored on asm",
6260 c_parser_peek_token (parser
)->value
);
6262 c_parser_consume_token (parser
);
6268 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
6270 c_parser_consume_token (parser
);
6274 /* ??? Follow the C++ parser rather than using the
6275 lex_untranslated_string kludge. */
6276 parser
->lex_untranslated_string
= true;
6279 matching_parens parens
;
6280 if (!parens
.require_open (parser
))
6283 str
= c_parser_asm_string_literal (parser
);
6284 if (str
== NULL_TREE
)
6285 goto error_close_paren
;
6288 outputs
= NULL_TREE
;
6290 clobbers
= NULL_TREE
;
6293 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6296 /* Parse each colon-delimited section of operands. */
6297 nsections
= 3 + is_goto
;
6298 for (section
= 0; section
< nsections
; ++section
)
6300 if (!c_parser_require (parser
, CPP_COLON
,
6302 ? G_("expected %<:%>")
6303 : G_("expected %<:%> or %<)%>"),
6304 UNKNOWN_LOCATION
, is_goto
))
6305 goto error_close_paren
;
6307 /* Once past any colon, we're no longer a simple asm. */
6310 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
6311 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6316 /* For asm goto, we don't allow output operands, but reserve
6317 the slot for a future extension that does allow them. */
6319 outputs
= c_parser_asm_operands (parser
);
6322 inputs
= c_parser_asm_operands (parser
);
6325 clobbers
= c_parser_asm_clobbers (parser
);
6328 labels
= c_parser_asm_goto_operands (parser
);
6334 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6339 if (!parens
.require_close (parser
))
6341 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6345 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6346 c_parser_skip_to_end_of_block_or_statement (parser
);
6348 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
6349 clobbers
, labels
, simple
));
6352 parser
->lex_untranslated_string
= false;
6356 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6360 /* Parse asm operands, a GNU extension.
6364 asm-operands , asm-operand
6367 asm-string-literal ( expression )
6368 [ identifier ] asm-string-literal ( expression )
6372 c_parser_asm_operands (c_parser
*parser
)
6374 tree list
= NULL_TREE
;
6379 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
6381 c_parser_consume_token (parser
);
6382 if (c_parser_next_token_is (parser
, CPP_NAME
))
6384 tree id
= c_parser_peek_token (parser
)->value
;
6385 c_parser_consume_token (parser
);
6386 name
= build_string (IDENTIFIER_LENGTH (id
),
6387 IDENTIFIER_POINTER (id
));
6391 c_parser_error (parser
, "expected identifier");
6392 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
6395 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6400 str
= c_parser_asm_string_literal (parser
);
6401 if (str
== NULL_TREE
)
6403 parser
->lex_untranslated_string
= false;
6404 matching_parens parens
;
6405 if (!parens
.require_open (parser
))
6407 parser
->lex_untranslated_string
= true;
6410 expr
= c_parser_expression (parser
);
6411 mark_exp_read (expr
.value
);
6412 parser
->lex_untranslated_string
= true;
6413 if (!parens
.require_close (parser
))
6415 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6418 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
6420 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6421 c_parser_consume_token (parser
);
6428 /* Parse asm clobbers, a GNU extension.
6432 asm-clobbers , asm-string-literal
6436 c_parser_asm_clobbers (c_parser
*parser
)
6438 tree list
= NULL_TREE
;
6441 tree str
= c_parser_asm_string_literal (parser
);
6443 list
= tree_cons (NULL_TREE
, str
, list
);
6446 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6447 c_parser_consume_token (parser
);
6454 /* Parse asm goto labels, a GNU extension.
6458 asm-goto-operands , identifier
6462 c_parser_asm_goto_operands (c_parser
*parser
)
6464 tree list
= NULL_TREE
;
6469 if (c_parser_next_token_is (parser
, CPP_NAME
))
6471 c_token
*tok
= c_parser_peek_token (parser
);
6473 label
= lookup_label_for_goto (tok
->location
, name
);
6474 c_parser_consume_token (parser
);
6475 TREE_USED (label
) = 1;
6479 c_parser_error (parser
, "expected identifier");
6483 name
= build_string (IDENTIFIER_LENGTH (name
),
6484 IDENTIFIER_POINTER (name
));
6485 list
= tree_cons (name
, label
, list
);
6486 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6487 c_parser_consume_token (parser
);
6489 return nreverse (list
);
6493 /* Parse an expression other than a compound expression; that is, an
6494 assignment expression (C90 6.3.16, C99 6.5.16, C11 6.5.16). If
6495 AFTER is not NULL then it is an Objective-C message expression which
6496 is the primary-expression starting the expression as an initializer.
6498 assignment-expression:
6499 conditional-expression
6500 unary-expression assignment-operator assignment-expression
6502 assignment-operator: one of
6503 = *= /= %= += -= <<= >>= &= ^= |=
6505 In GNU C we accept any conditional expression on the LHS and
6506 diagnose the invalid lvalue rather than producing a syntax
6509 static struct c_expr
6510 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
6511 tree omp_atomic_lhs
)
6513 struct c_expr lhs
, rhs
, ret
;
6514 enum tree_code code
;
6515 location_t op_location
, exp_location
;
6516 gcc_assert (!after
|| c_dialect_objc ());
6517 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
6518 op_location
= c_parser_peek_token (parser
)->location
;
6519 switch (c_parser_peek_token (parser
)->type
)
6528 code
= TRUNC_DIV_EXPR
;
6531 code
= TRUNC_MOD_EXPR
;
6546 code
= BIT_AND_EXPR
;
6549 code
= BIT_XOR_EXPR
;
6552 code
= BIT_IOR_EXPR
;
6557 c_parser_consume_token (parser
);
6558 exp_location
= c_parser_peek_token (parser
)->location
;
6559 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6560 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6562 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6563 code
, exp_location
, rhs
.value
,
6565 set_c_expr_source_range (&ret
, lhs
.get_start (), rhs
.get_finish ());
6566 if (code
== NOP_EXPR
)
6567 ret
.original_code
= MODIFY_EXPR
;
6570 TREE_NO_WARNING (ret
.value
) = 1;
6571 ret
.original_code
= ERROR_MARK
;
6573 ret
.original_type
= NULL
;
6577 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15, C11 6.5.15). If
6578 AFTER is not NULL then it is an Objective-C message expression which is
6579 the primary-expression starting the expression as an initializer.
6581 conditional-expression:
6582 logical-OR-expression
6583 logical-OR-expression ? expression : conditional-expression
6587 conditional-expression:
6588 logical-OR-expression ? : conditional-expression
6591 static struct c_expr
6592 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6593 tree omp_atomic_lhs
)
6595 struct c_expr cond
, exp1
, exp2
, ret
;
6596 location_t start
, cond_loc
, colon_loc
;
6598 gcc_assert (!after
|| c_dialect_objc ());
6600 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6602 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6604 if (cond
.value
!= error_mark_node
)
6605 start
= cond
.get_start ();
6607 start
= UNKNOWN_LOCATION
;
6608 cond_loc
= c_parser_peek_token (parser
)->location
;
6609 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6610 c_parser_consume_token (parser
);
6611 if (c_parser_next_token_is (parser
, CPP_COLON
))
6613 tree eptype
= NULL_TREE
;
6615 location_t middle_loc
= c_parser_peek_token (parser
)->location
;
6616 pedwarn (middle_loc
, OPT_Wpedantic
,
6617 "ISO C forbids omitting the middle term of a ?: expression");
6618 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6620 eptype
= TREE_TYPE (cond
.value
);
6621 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6623 tree e
= cond
.value
;
6624 while (TREE_CODE (e
) == COMPOUND_EXPR
)
6625 e
= TREE_OPERAND (e
, 1);
6626 warn_for_omitted_condop (middle_loc
, e
);
6627 /* Make sure first operand is calculated only once. */
6628 exp1
.value
= save_expr (default_conversion (cond
.value
));
6630 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6631 exp1
.original_type
= NULL
;
6632 exp1
.src_range
= cond
.src_range
;
6633 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6634 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6639 = c_objc_common_truthvalue_conversion
6640 (cond_loc
, default_conversion (cond
.value
));
6641 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6642 exp1
= c_parser_expression_conv (parser
);
6643 mark_exp_read (exp1
.value
);
6644 c_inhibit_evaluation_warnings
+=
6645 ((cond
.value
== truthvalue_true_node
)
6646 - (cond
.value
== truthvalue_false_node
));
6649 colon_loc
= c_parser_peek_token (parser
)->location
;
6650 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6652 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6653 ret
.value
= error_mark_node
;
6654 ret
.original_code
= ERROR_MARK
;
6655 ret
.original_type
= NULL
;
6659 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6660 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6661 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6663 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6664 location_t loc1
= make_location (exp1
.get_start (), exp1
.src_range
);
6665 location_t loc2
= make_location (exp2
.get_start (), exp2
.src_range
);
6666 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6667 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6668 exp1
.value
, exp1
.original_type
, loc1
,
6669 exp2
.value
, exp2
.original_type
, loc2
);
6670 ret
.original_code
= ERROR_MARK
;
6671 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6672 ret
.original_type
= NULL
;
6677 /* If both sides are enum type, the default conversion will have
6678 made the type of the result be an integer type. We want to
6679 remember the enum types we started with. */
6680 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6681 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6682 ret
.original_type
= ((t1
!= error_mark_node
6683 && t2
!= error_mark_node
6684 && (TYPE_MAIN_VARIANT (t1
)
6685 == TYPE_MAIN_VARIANT (t2
)))
6689 set_c_expr_source_range (&ret
, start
, exp2
.get_finish ());
6693 /* Parse a binary expression; that is, a logical-OR-expression (C90
6694 6.3.5-6.3.14, C99 6.5.5-6.5.14, C11 6.5.5-6.5.14). If AFTER is not
6695 NULL then it is an Objective-C message expression which is the
6696 primary-expression starting the expression as an initializer.
6698 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6699 when it should be the unfolded lhs. In a valid OpenMP source,
6700 one of the operands of the toplevel binary expression must be equal
6701 to it. In that case, just return a build2 created binary operation
6702 rather than result of parser_build_binary_op.
6704 multiplicative-expression:
6706 multiplicative-expression * cast-expression
6707 multiplicative-expression / cast-expression
6708 multiplicative-expression % cast-expression
6710 additive-expression:
6711 multiplicative-expression
6712 additive-expression + multiplicative-expression
6713 additive-expression - multiplicative-expression
6717 shift-expression << additive-expression
6718 shift-expression >> additive-expression
6720 relational-expression:
6722 relational-expression < shift-expression
6723 relational-expression > shift-expression
6724 relational-expression <= shift-expression
6725 relational-expression >= shift-expression
6727 equality-expression:
6728 relational-expression
6729 equality-expression == relational-expression
6730 equality-expression != relational-expression
6734 AND-expression & equality-expression
6736 exclusive-OR-expression:
6738 exclusive-OR-expression ^ AND-expression
6740 inclusive-OR-expression:
6741 exclusive-OR-expression
6742 inclusive-OR-expression | exclusive-OR-expression
6744 logical-AND-expression:
6745 inclusive-OR-expression
6746 logical-AND-expression && inclusive-OR-expression
6748 logical-OR-expression:
6749 logical-AND-expression
6750 logical-OR-expression || logical-AND-expression
6753 static struct c_expr
6754 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6755 tree omp_atomic_lhs
)
6757 /* A binary expression is parsed using operator-precedence parsing,
6758 with the operands being cast expressions. All the binary
6759 operators are left-associative. Thus a binary expression is of
6762 E0 op1 E1 op2 E2 ...
6764 which we represent on a stack. On the stack, the precedence
6765 levels are strictly increasing. When a new operator is
6766 encountered of higher precedence than that at the top of the
6767 stack, it is pushed; its LHS is the top expression, and its RHS
6768 is everything parsed until it is popped. When a new operator is
6769 encountered with precedence less than or equal to that at the top
6770 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6771 by the result of the operation until the operator at the top of
6772 the stack has lower precedence than the new operator or there is
6773 only one element on the stack; then the top expression is the LHS
6774 of the new operator. In the case of logical AND and OR
6775 expressions, we also need to adjust c_inhibit_evaluation_warnings
6776 as appropriate when the operators are pushed and popped. */
6779 /* The expression at this stack level. */
6781 /* The precedence of the operator on its left, PREC_NONE at the
6782 bottom of the stack. */
6783 enum c_parser_prec prec
;
6784 /* The operation on its left. */
6786 /* The source location of this operation. */
6788 /* The sizeof argument if expr.original_code == SIZEOF_EXPR. */
6792 /* Location of the binary operator. */
6793 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6796 switch (stack[sp].op) \
6798 case TRUTH_ANDIF_EXPR: \
6799 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6800 == truthvalue_false_node); \
6802 case TRUTH_ORIF_EXPR: \
6803 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6804 == truthvalue_true_node); \
6806 case TRUNC_DIV_EXPR: \
6807 if (stack[sp - 1].expr.original_code == SIZEOF_EXPR \
6808 && stack[sp].expr.original_code == SIZEOF_EXPR) \
6810 tree type0 = stack[sp - 1].sizeof_arg; \
6811 tree type1 = stack[sp].sizeof_arg; \
6812 tree first_arg = type0; \
6813 if (!TYPE_P (type0)) \
6814 type0 = TREE_TYPE (type0); \
6815 if (!TYPE_P (type1)) \
6816 type1 = TREE_TYPE (type1); \
6817 if (POINTER_TYPE_P (type0) \
6818 && comptypes (TREE_TYPE (type0), type1) \
6819 && !(TREE_CODE (first_arg) == PARM_DECL \
6820 && C_ARRAY_PARAMETER (first_arg) \
6821 && warn_sizeof_array_argument)) \
6822 if (warning_at (stack[sp].loc, OPT_Wsizeof_pointer_div, \
6823 "division %<sizeof (%T) / sizeof (%T)%> does " \
6824 "not compute the number of array elements", \
6826 if (DECL_P (first_arg)) \
6827 inform (DECL_SOURCE_LOCATION (first_arg), \
6828 "first %<sizeof%> operand was declared here"); \
6834 stack[sp - 1].expr \
6835 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6836 stack[sp - 1].expr, true, true); \
6838 = convert_lvalue_to_rvalue (stack[sp].loc, \
6839 stack[sp].expr, true, true); \
6840 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6841 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6842 && ((1 << stack[sp].prec) \
6843 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6844 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6845 && stack[sp].op != TRUNC_MOD_EXPR \
6846 && stack[0].expr.value != error_mark_node \
6847 && stack[1].expr.value != error_mark_node \
6848 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6849 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6850 stack[0].expr.value \
6851 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6852 stack[0].expr.value, stack[1].expr.value); \
6854 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6856 stack[sp - 1].expr, \
6860 gcc_assert (!after
|| c_dialect_objc ());
6861 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6862 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6863 stack
[0].prec
= PREC_NONE
;
6864 stack
[0].sizeof_arg
= c_last_sizeof_arg
;
6868 enum c_parser_prec oprec
;
6869 enum tree_code ocode
;
6870 source_range src_range
;
6873 switch (c_parser_peek_token (parser
)->type
)
6881 ocode
= TRUNC_DIV_EXPR
;
6885 ocode
= TRUNC_MOD_EXPR
;
6897 ocode
= LSHIFT_EXPR
;
6901 ocode
= RSHIFT_EXPR
;
6915 case CPP_GREATER_EQ
:
6928 oprec
= PREC_BITAND
;
6929 ocode
= BIT_AND_EXPR
;
6932 oprec
= PREC_BITXOR
;
6933 ocode
= BIT_XOR_EXPR
;
6937 ocode
= BIT_IOR_EXPR
;
6940 oprec
= PREC_LOGAND
;
6941 ocode
= TRUTH_ANDIF_EXPR
;
6945 ocode
= TRUTH_ORIF_EXPR
;
6948 /* Not a binary operator, so end of the binary
6952 binary_loc
= c_parser_peek_token (parser
)->location
;
6953 while (oprec
<= stack
[sp
].prec
)
6955 c_parser_consume_token (parser
);
6958 case TRUTH_ANDIF_EXPR
:
6959 src_range
= stack
[sp
].expr
.src_range
;
6961 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6962 stack
[sp
].expr
, true, true);
6963 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6964 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6965 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6966 == truthvalue_false_node
);
6967 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
6969 case TRUTH_ORIF_EXPR
:
6970 src_range
= stack
[sp
].expr
.src_range
;
6972 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6973 stack
[sp
].expr
, true, true);
6974 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6975 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6976 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6977 == truthvalue_true_node
);
6978 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
6984 stack
[sp
].loc
= binary_loc
;
6985 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6986 stack
[sp
].prec
= oprec
;
6987 stack
[sp
].op
= ocode
;
6988 stack
[sp
].sizeof_arg
= c_last_sizeof_arg
;
6993 return stack
[0].expr
;
6997 /* Parse a cast expression (C90 6.3.4, C99 6.5.4, C11 6.5.4). If AFTER
6998 is not NULL then it is an Objective-C message expression which is the
6999 primary-expression starting the expression as an initializer.
7003 ( type-name ) unary-expression
7006 static struct c_expr
7007 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
7009 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
7010 gcc_assert (!after
|| c_dialect_objc ());
7012 return c_parser_postfix_expression_after_primary (parser
,
7014 /* If the expression begins with a parenthesized type name, it may
7015 be either a cast or a compound literal; we need to see whether
7016 the next character is '{' to tell the difference. If not, it is
7017 an unary expression. Full detection of unknown typenames here
7018 would require a 3-token lookahead. */
7019 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7020 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7022 struct c_type_name
*type_name
;
7025 matching_parens parens
;
7026 parens
.consume_open (parser
);
7027 type_name
= c_parser_type_name (parser
, true);
7028 parens
.skip_until_found_close (parser
);
7029 if (type_name
== NULL
)
7031 ret
.value
= error_mark_node
;
7032 ret
.original_code
= ERROR_MARK
;
7033 ret
.original_type
= NULL
;
7037 /* Save casted types in the function's used types hash table. */
7038 used_types_insert (type_name
->specs
->type
);
7040 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7041 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
7043 if (type_name
->specs
->alignas_p
)
7044 error_at (type_name
->specs
->locations
[cdw_alignas
],
7045 "alignment specified for type name in cast");
7047 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7048 expr
= c_parser_cast_expression (parser
, NULL
);
7049 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
7051 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
7052 if (ret
.value
&& expr
.value
)
7053 set_c_expr_source_range (&ret
, cast_loc
, expr
.get_finish ());
7054 ret
.original_code
= ERROR_MARK
;
7055 ret
.original_type
= NULL
;
7059 return c_parser_unary_expression (parser
);
7062 /* Parse an unary expression (C90 6.3.3, C99 6.5.3, C11 6.5.3).
7068 unary-operator cast-expression
7069 sizeof unary-expression
7070 sizeof ( type-name )
7072 unary-operator: one of
7078 __alignof__ unary-expression
7079 __alignof__ ( type-name )
7082 (C11 permits _Alignof with type names only.)
7084 unary-operator: one of
7085 __extension__ __real__ __imag__
7087 Transactional Memory:
7090 transaction-expression
7092 In addition, the GNU syntax treats ++ and -- as unary operators, so
7093 they may be applied to cast expressions with errors for non-lvalues
7096 static struct c_expr
7097 c_parser_unary_expression (c_parser
*parser
)
7100 struct c_expr ret
, op
;
7101 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7104 ret
.original_code
= ERROR_MARK
;
7105 ret
.original_type
= NULL
;
7106 switch (c_parser_peek_token (parser
)->type
)
7109 c_parser_consume_token (parser
);
7110 exp_loc
= c_parser_peek_token (parser
)->location
;
7111 op
= c_parser_cast_expression (parser
, NULL
);
7113 op
= default_function_array_read_conversion (exp_loc
, op
);
7114 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
7115 case CPP_MINUS_MINUS
:
7116 c_parser_consume_token (parser
);
7117 exp_loc
= c_parser_peek_token (parser
)->location
;
7118 op
= c_parser_cast_expression (parser
, NULL
);
7120 op
= default_function_array_read_conversion (exp_loc
, op
);
7121 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
7123 c_parser_consume_token (parser
);
7124 op
= c_parser_cast_expression (parser
, NULL
);
7125 mark_exp_read (op
.value
);
7126 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
7129 c_parser_consume_token (parser
);
7130 exp_loc
= c_parser_peek_token (parser
)->location
;
7131 op
= c_parser_cast_expression (parser
, NULL
);
7132 finish
= op
.get_finish ();
7133 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7134 location_t combined_loc
= make_location (op_loc
, op_loc
, finish
);
7135 ret
.value
= build_indirect_ref (combined_loc
, op
.value
, RO_UNARY_STAR
);
7136 ret
.src_range
.m_start
= op_loc
;
7137 ret
.src_range
.m_finish
= finish
;
7141 if (!c_dialect_objc () && !in_system_header_at (input_location
))
7144 "traditional C rejects the unary plus operator");
7145 c_parser_consume_token (parser
);
7146 exp_loc
= c_parser_peek_token (parser
)->location
;
7147 op
= c_parser_cast_expression (parser
, NULL
);
7148 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7149 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
7151 c_parser_consume_token (parser
);
7152 exp_loc
= c_parser_peek_token (parser
)->location
;
7153 op
= c_parser_cast_expression (parser
, NULL
);
7154 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7155 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
7157 c_parser_consume_token (parser
);
7158 exp_loc
= c_parser_peek_token (parser
)->location
;
7159 op
= c_parser_cast_expression (parser
, NULL
);
7160 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7161 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
7163 c_parser_consume_token (parser
);
7164 exp_loc
= c_parser_peek_token (parser
)->location
;
7165 op
= c_parser_cast_expression (parser
, NULL
);
7166 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7167 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
7169 /* Refer to the address of a label as a pointer. */
7170 c_parser_consume_token (parser
);
7171 if (c_parser_next_token_is (parser
, CPP_NAME
))
7173 ret
.value
= finish_label_address_expr
7174 (c_parser_peek_token (parser
)->value
, op_loc
);
7175 set_c_expr_source_range (&ret
, op_loc
,
7176 c_parser_peek_token (parser
)->get_finish ());
7177 c_parser_consume_token (parser
);
7181 c_parser_error (parser
, "expected identifier");
7186 switch (c_parser_peek_token (parser
)->keyword
)
7189 return c_parser_sizeof_expression (parser
);
7191 return c_parser_alignof_expression (parser
);
7193 c_parser_consume_token (parser
);
7194 ext
= disable_extension_diagnostics ();
7195 ret
= c_parser_cast_expression (parser
, NULL
);
7196 restore_extension_diagnostics (ext
);
7199 c_parser_consume_token (parser
);
7200 exp_loc
= c_parser_peek_token (parser
)->location
;
7201 op
= c_parser_cast_expression (parser
, NULL
);
7202 op
= default_function_array_conversion (exp_loc
, op
);
7203 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
7205 c_parser_consume_token (parser
);
7206 exp_loc
= c_parser_peek_token (parser
)->location
;
7207 op
= c_parser_cast_expression (parser
, NULL
);
7208 op
= default_function_array_conversion (exp_loc
, op
);
7209 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
7210 case RID_TRANSACTION_ATOMIC
:
7211 case RID_TRANSACTION_RELAXED
:
7212 return c_parser_transaction_expression (parser
,
7213 c_parser_peek_token (parser
)->keyword
);
7215 return c_parser_postfix_expression (parser
);
7218 return c_parser_postfix_expression (parser
);
7222 /* Parse a sizeof expression. */
7224 static struct c_expr
7225 c_parser_sizeof_expression (c_parser
*parser
)
7228 struct c_expr result
;
7229 location_t expr_loc
;
7230 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
7233 location_t finish
= UNKNOWN_LOCATION
;
7235 start
= c_parser_peek_token (parser
)->location
;
7237 c_parser_consume_token (parser
);
7238 c_inhibit_evaluation_warnings
++;
7240 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7241 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7243 /* Either sizeof ( type-name ) or sizeof unary-expression
7244 starting with a compound literal. */
7245 struct c_type_name
*type_name
;
7246 matching_parens parens
;
7247 parens
.consume_open (parser
);
7248 expr_loc
= c_parser_peek_token (parser
)->location
;
7249 type_name
= c_parser_type_name (parser
, true);
7250 parens
.skip_until_found_close (parser
);
7251 finish
= parser
->tokens_buf
[0].location
;
7252 if (type_name
== NULL
)
7255 c_inhibit_evaluation_warnings
--;
7257 ret
.value
= error_mark_node
;
7258 ret
.original_code
= ERROR_MARK
;
7259 ret
.original_type
= NULL
;
7262 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7264 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7267 finish
= expr
.get_finish ();
7270 /* sizeof ( type-name ). */
7271 if (type_name
->specs
->alignas_p
)
7272 error_at (type_name
->specs
->locations
[cdw_alignas
],
7273 "alignment specified for type name in %<sizeof%>");
7274 c_inhibit_evaluation_warnings
--;
7276 result
= c_expr_sizeof_type (expr_loc
, type_name
);
7280 expr_loc
= c_parser_peek_token (parser
)->location
;
7281 expr
= c_parser_unary_expression (parser
);
7282 finish
= expr
.get_finish ();
7284 c_inhibit_evaluation_warnings
--;
7286 mark_exp_read (expr
.value
);
7287 if (TREE_CODE (expr
.value
) == COMPONENT_REF
7288 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
7289 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
7290 result
= c_expr_sizeof_expr (expr_loc
, expr
);
7292 if (finish
!= UNKNOWN_LOCATION
)
7293 set_c_expr_source_range (&result
, start
, finish
);
7297 /* Parse an alignof expression. */
7299 static struct c_expr
7300 c_parser_alignof_expression (c_parser
*parser
)
7303 location_t start_loc
= c_parser_peek_token (parser
)->location
;
7305 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
7306 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
7307 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
7309 /* A diagnostic is not required for the use of this identifier in
7310 the implementation namespace; only diagnose it for the C11
7311 spelling because of existing code using the other spellings. */
7315 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
7318 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
7321 c_parser_consume_token (parser
);
7322 c_inhibit_evaluation_warnings
++;
7324 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7325 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7327 /* Either __alignof__ ( type-name ) or __alignof__
7328 unary-expression starting with a compound literal. */
7330 struct c_type_name
*type_name
;
7332 matching_parens parens
;
7333 parens
.consume_open (parser
);
7334 loc
= c_parser_peek_token (parser
)->location
;
7335 type_name
= c_parser_type_name (parser
, true);
7336 end_loc
= c_parser_peek_token (parser
)->location
;
7337 parens
.skip_until_found_close (parser
);
7338 if (type_name
== NULL
)
7341 c_inhibit_evaluation_warnings
--;
7343 ret
.value
= error_mark_node
;
7344 ret
.original_code
= ERROR_MARK
;
7345 ret
.original_type
= NULL
;
7348 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7350 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7355 /* alignof ( type-name ). */
7356 if (type_name
->specs
->alignas_p
)
7357 error_at (type_name
->specs
->locations
[cdw_alignas
],
7358 "alignment specified for type name in %qE",
7360 c_inhibit_evaluation_warnings
--;
7362 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
7364 false, is_c11_alignof
, 1);
7365 ret
.original_code
= ERROR_MARK
;
7366 ret
.original_type
= NULL
;
7367 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7373 expr
= c_parser_unary_expression (parser
);
7374 end_loc
= expr
.src_range
.m_finish
;
7376 mark_exp_read (expr
.value
);
7377 c_inhibit_evaluation_warnings
--;
7381 OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
7383 ret
.value
= c_alignof_expr (start_loc
, expr
.value
);
7384 ret
.original_code
= ERROR_MARK
;
7385 ret
.original_type
= NULL
;
7386 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7391 /* Helper function to read arguments of builtins which are interfaces
7392 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
7393 others. The name of the builtin is passed using BNAME parameter.
7394 Function returns true if there were no errors while parsing and
7395 stores the arguments in CEXPR_LIST. If it returns true,
7396 *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
7399 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
7400 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
7402 location_t
*out_close_paren_loc
)
7404 location_t loc
= c_parser_peek_token (parser
)->location
;
7405 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7407 bool saved_force_folding_builtin_constant_p
;
7409 *ret_cexpr_list
= NULL
;
7410 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
7412 error_at (loc
, "cannot take address of %qs", bname
);
7416 c_parser_consume_token (parser
);
7418 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7420 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7421 c_parser_consume_token (parser
);
7425 saved_force_folding_builtin_constant_p
7426 = force_folding_builtin_constant_p
;
7427 force_folding_builtin_constant_p
|= choose_expr_p
;
7428 expr
= c_parser_expr_no_commas (parser
, NULL
);
7429 force_folding_builtin_constant_p
7430 = saved_force_folding_builtin_constant_p
;
7431 vec_alloc (cexpr_list
, 1);
7432 vec_safe_push (cexpr_list
, expr
);
7433 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7435 c_parser_consume_token (parser
);
7436 expr
= c_parser_expr_no_commas (parser
, NULL
);
7437 vec_safe_push (cexpr_list
, expr
);
7440 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7441 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7444 *ret_cexpr_list
= cexpr_list
;
7448 /* This represents a single generic-association. */
7450 struct c_generic_association
7452 /* The location of the starting token of the type. */
7453 location_t type_location
;
7454 /* The association's type, or NULL_TREE for 'default'. */
7456 /* The association's expression. */
7457 struct c_expr expression
;
7460 /* Parse a generic-selection. (C11 6.5.1.1).
7463 _Generic ( assignment-expression , generic-assoc-list )
7467 generic-assoc-list , generic-association
7469 generic-association:
7470 type-name : assignment-expression
7471 default : assignment-expression
7474 static struct c_expr
7475 c_parser_generic_selection (c_parser
*parser
)
7477 struct c_expr selector
, error_expr
;
7479 struct c_generic_association matched_assoc
;
7480 bool match_found
= false;
7481 location_t generic_loc
, selector_loc
;
7483 error_expr
.original_code
= ERROR_MARK
;
7484 error_expr
.original_type
= NULL
;
7485 error_expr
.set_error ();
7486 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
7487 matched_assoc
.type
= NULL_TREE
;
7488 matched_assoc
.expression
= error_expr
;
7490 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
7491 generic_loc
= c_parser_peek_token (parser
)->location
;
7492 c_parser_consume_token (parser
);
7494 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7495 "ISO C99 does not support %<_Generic%>");
7497 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7498 "ISO C90 does not support %<_Generic%>");
7500 matching_parens parens
;
7501 if (!parens
.require_open (parser
))
7504 c_inhibit_evaluation_warnings
++;
7505 selector_loc
= c_parser_peek_token (parser
)->location
;
7506 selector
= c_parser_expr_no_commas (parser
, NULL
);
7507 selector
= default_function_array_conversion (selector_loc
, selector
);
7508 c_inhibit_evaluation_warnings
--;
7510 if (selector
.value
== error_mark_node
)
7512 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7515 selector_type
= TREE_TYPE (selector
.value
);
7516 /* In ISO C terms, rvalues (including the controlling expression of
7517 _Generic) do not have qualified types. */
7518 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
7519 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
7520 /* In ISO C terms, _Noreturn is not part of the type of expressions
7521 such as &abort, but in GCC it is represented internally as a type
7523 if (FUNCTION_POINTER_TYPE_P (selector_type
)
7524 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
7526 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
7528 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7530 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7534 auto_vec
<c_generic_association
> associations
;
7537 struct c_generic_association assoc
, *iter
;
7539 c_token
*token
= c_parser_peek_token (parser
);
7541 assoc
.type_location
= token
->location
;
7542 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
7544 c_parser_consume_token (parser
);
7545 assoc
.type
= NULL_TREE
;
7549 struct c_type_name
*type_name
;
7551 type_name
= c_parser_type_name (parser
);
7552 if (type_name
== NULL
)
7554 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7557 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
7558 if (assoc
.type
== error_mark_node
)
7560 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7564 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
7565 error_at (assoc
.type_location
,
7566 "%<_Generic%> association has function type");
7567 else if (!COMPLETE_TYPE_P (assoc
.type
))
7568 error_at (assoc
.type_location
,
7569 "%<_Generic%> association has incomplete type");
7571 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
7572 error_at (assoc
.type_location
,
7573 "%<_Generic%> association has "
7574 "variable length type");
7577 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7579 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7583 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
7584 if (assoc
.expression
.value
== error_mark_node
)
7586 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7590 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
7592 if (assoc
.type
== NULL_TREE
)
7594 if (iter
->type
== NULL_TREE
)
7596 error_at (assoc
.type_location
,
7597 "duplicate %<default%> case in %<_Generic%>");
7598 inform (iter
->type_location
, "original %<default%> is here");
7601 else if (iter
->type
!= NULL_TREE
)
7603 if (comptypes (assoc
.type
, iter
->type
))
7605 error_at (assoc
.type_location
,
7606 "%<_Generic%> specifies two compatible types");
7607 inform (iter
->type_location
, "compatible type is here");
7612 if (assoc
.type
== NULL_TREE
)
7616 matched_assoc
= assoc
;
7620 else if (comptypes (assoc
.type
, selector_type
))
7622 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7624 matched_assoc
= assoc
;
7629 error_at (assoc
.type_location
,
7630 "%<_Generic%> selector matches multiple associations");
7631 inform (matched_assoc
.type_location
,
7632 "other match is here");
7636 associations
.safe_push (assoc
);
7638 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7640 c_parser_consume_token (parser
);
7643 if (!parens
.require_close (parser
))
7645 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7651 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7652 "compatible with any association",
7657 return matched_assoc
.expression
;
7660 /* Check the validity of a function pointer argument *EXPR (argument
7661 position POS) to __builtin_tgmath. Return the number of function
7662 arguments if possibly valid; return 0 having reported an error if
7666 check_tgmath_function (c_expr
*expr
, unsigned int pos
)
7668 tree type
= TREE_TYPE (expr
->value
);
7669 if (!FUNCTION_POINTER_TYPE_P (type
))
7671 error_at (expr
->get_location (),
7672 "argument %u of %<__builtin_tgmath%> is not a function pointer",
7676 type
= TREE_TYPE (type
);
7677 if (!prototype_p (type
))
7679 error_at (expr
->get_location (),
7680 "argument %u of %<__builtin_tgmath%> is unprototyped", pos
);
7683 if (stdarg_p (type
))
7685 error_at (expr
->get_location (),
7686 "argument %u of %<__builtin_tgmath%> has variable arguments",
7690 unsigned int nargs
= 0;
7691 function_args_iterator iter
;
7693 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
7695 if (t
== void_type_node
)
7701 error_at (expr
->get_location (),
7702 "argument %u of %<__builtin_tgmath%> has no arguments", pos
);
7708 /* Ways in which a parameter or return value of a type-generic macro
7709 may vary between the different functions the macro may call. */
7710 enum tgmath_parm_kind
7712 tgmath_fixed
, tgmath_real
, tgmath_complex
7715 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2,
7716 C11 6.5.1-6.5.2). Compound literals aren't handled here; callers have to
7717 call c_parser_postfix_expression_after_paren_type on encountering them.
7721 postfix-expression [ expression ]
7722 postfix-expression ( argument-expression-list[opt] )
7723 postfix-expression . identifier
7724 postfix-expression -> identifier
7725 postfix-expression ++
7726 postfix-expression --
7727 ( type-name ) { initializer-list }
7728 ( type-name ) { initializer-list , }
7730 argument-expression-list:
7732 argument-expression-list , argument-expression
7745 (treated as a keyword in GNU C)
7748 ( compound-statement )
7749 __builtin_va_arg ( assignment-expression , type-name )
7750 __builtin_offsetof ( type-name , offsetof-member-designator )
7751 __builtin_choose_expr ( assignment-expression ,
7752 assignment-expression ,
7753 assignment-expression )
7754 __builtin_types_compatible_p ( type-name , type-name )
7755 __builtin_tgmath ( expr-list )
7756 __builtin_complex ( assignment-expression , assignment-expression )
7757 __builtin_shuffle ( assignment-expression , assignment-expression )
7758 __builtin_shuffle ( assignment-expression ,
7759 assignment-expression ,
7760 assignment-expression, )
7762 offsetof-member-designator:
7764 offsetof-member-designator . identifier
7765 offsetof-member-designator [ expression ]
7770 [ objc-receiver objc-message-args ]
7771 @selector ( objc-selector-arg )
7772 @protocol ( identifier )
7773 @encode ( type-name )
7775 Classname . identifier
7778 static struct c_expr
7779 c_parser_postfix_expression (c_parser
*parser
)
7781 struct c_expr expr
, e1
;
7782 struct c_type_name
*t1
, *t2
;
7783 location_t loc
= c_parser_peek_token (parser
)->location
;
7784 source_range tok_range
= c_parser_peek_token (parser
)->get_range ();
7785 expr
.original_code
= ERROR_MARK
;
7786 expr
.original_type
= NULL
;
7787 switch (c_parser_peek_token (parser
)->type
)
7790 expr
.value
= c_parser_peek_token (parser
)->value
;
7791 set_c_expr_source_range (&expr
, tok_range
);
7792 loc
= c_parser_peek_token (parser
)->location
;
7793 c_parser_consume_token (parser
);
7794 if (TREE_CODE (expr
.value
) == FIXED_CST
7795 && !targetm
.fixed_point_supported_p ())
7797 error_at (loc
, "fixed-point types not supported for this target");
7798 expr
.value
= error_mark_node
;
7805 expr
.value
= c_parser_peek_token (parser
)->value
;
7806 /* For the purpose of warning when a pointer is compared with
7807 a zero character constant. */
7808 expr
.original_type
= char_type_node
;
7809 set_c_expr_source_range (&expr
, tok_range
);
7810 c_parser_consume_token (parser
);
7816 case CPP_UTF8STRING
:
7817 expr
.value
= c_parser_peek_token (parser
)->value
;
7818 set_c_expr_source_range (&expr
, tok_range
);
7819 expr
.original_code
= STRING_CST
;
7820 c_parser_consume_token (parser
);
7822 case CPP_OBJC_STRING
:
7823 gcc_assert (c_dialect_objc ());
7825 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7826 set_c_expr_source_range (&expr
, tok_range
);
7827 c_parser_consume_token (parser
);
7830 switch (c_parser_peek_token (parser
)->id_kind
)
7834 tree id
= c_parser_peek_token (parser
)->value
;
7835 c_parser_consume_token (parser
);
7836 expr
.value
= build_external_ref (loc
, id
,
7837 (c_parser_peek_token (parser
)->type
7839 &expr
.original_type
);
7840 set_c_expr_source_range (&expr
, tok_range
);
7843 case C_ID_CLASSNAME
:
7845 /* Here we parse the Objective-C 2.0 Class.name dot
7847 tree class_name
= c_parser_peek_token (parser
)->value
;
7849 c_parser_consume_token (parser
);
7850 gcc_assert (c_dialect_objc ());
7851 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7856 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7858 c_parser_error (parser
, "expected identifier");
7862 c_token
*component_tok
= c_parser_peek_token (parser
);
7863 component
= component_tok
->value
;
7864 location_t end_loc
= component_tok
->get_finish ();
7865 c_parser_consume_token (parser
);
7866 expr
.value
= objc_build_class_component_ref (class_name
,
7868 set_c_expr_source_range (&expr
, loc
, end_loc
);
7872 c_parser_error (parser
, "expected expression");
7877 case CPP_OPEN_PAREN
:
7878 /* A parenthesized expression, statement expression or compound
7880 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7882 /* A statement expression. */
7884 location_t brace_loc
;
7885 c_parser_consume_token (parser
);
7886 brace_loc
= c_parser_peek_token (parser
)->location
;
7887 c_parser_consume_token (parser
);
7888 if (!building_stmt_list_p ())
7890 error_at (loc
, "braced-group within expression allowed "
7891 "only inside a function");
7892 parser
->error
= true;
7893 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7894 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7898 stmt
= c_begin_stmt_expr ();
7899 c_parser_compound_statement_nostart (parser
);
7900 location_t close_loc
= c_parser_peek_token (parser
)->location
;
7901 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7903 pedwarn (loc
, OPT_Wpedantic
,
7904 "ISO C forbids braced-groups within expressions");
7905 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7906 set_c_expr_source_range (&expr
, loc
, close_loc
);
7907 mark_exp_read (expr
.value
);
7911 /* A parenthesized expression. */
7912 location_t loc_open_paren
= c_parser_peek_token (parser
)->location
;
7913 c_parser_consume_token (parser
);
7914 expr
= c_parser_expression (parser
);
7915 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7916 TREE_NO_WARNING (expr
.value
) = 1;
7917 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
7918 && expr
.original_code
!= SIZEOF_EXPR
)
7919 expr
.original_code
= ERROR_MARK
;
7920 /* Don't change EXPR.ORIGINAL_TYPE. */
7921 location_t loc_close_paren
= c_parser_peek_token (parser
)->location
;
7922 set_c_expr_source_range (&expr
, loc_open_paren
, loc_close_paren
);
7923 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7924 "expected %<)%>", loc_open_paren
);
7928 switch (c_parser_peek_token (parser
)->keyword
)
7930 case RID_FUNCTION_NAME
:
7931 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7932 "%<__FUNCTION__%> predefined identifier");
7933 expr
.value
= fname_decl (loc
,
7934 c_parser_peek_token (parser
)->keyword
,
7935 c_parser_peek_token (parser
)->value
);
7936 set_c_expr_source_range (&expr
, loc
, loc
);
7937 c_parser_consume_token (parser
);
7939 case RID_PRETTY_FUNCTION_NAME
:
7940 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7941 "%<__PRETTY_FUNCTION__%> predefined identifier");
7942 expr
.value
= fname_decl (loc
,
7943 c_parser_peek_token (parser
)->keyword
,
7944 c_parser_peek_token (parser
)->value
);
7945 set_c_expr_source_range (&expr
, loc
, loc
);
7946 c_parser_consume_token (parser
);
7948 case RID_C99_FUNCTION_NAME
:
7949 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7950 "%<__func__%> predefined identifier");
7951 expr
.value
= fname_decl (loc
,
7952 c_parser_peek_token (parser
)->keyword
,
7953 c_parser_peek_token (parser
)->value
);
7954 set_c_expr_source_range (&expr
, loc
, loc
);
7955 c_parser_consume_token (parser
);
7959 location_t start_loc
= loc
;
7960 c_parser_consume_token (parser
);
7961 matching_parens parens
;
7962 if (!parens
.require_open (parser
))
7967 e1
= c_parser_expr_no_commas (parser
, NULL
);
7968 mark_exp_read (e1
.value
);
7969 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7970 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7972 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7976 loc
= c_parser_peek_token (parser
)->location
;
7977 t1
= c_parser_type_name (parser
);
7978 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
7979 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7987 tree type_expr
= NULL_TREE
;
7988 expr
.value
= c_build_va_arg (start_loc
, e1
.value
, loc
,
7989 groktypename (t1
, &type_expr
, NULL
));
7992 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7993 TREE_TYPE (expr
.value
), type_expr
,
7995 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7997 set_c_expr_source_range (&expr
, start_loc
, end_loc
);
8003 c_parser_consume_token (parser
);
8004 matching_parens parens
;
8005 if (!parens
.require_open (parser
))
8010 t1
= c_parser_type_name (parser
);
8012 parser
->error
= true;
8013 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8014 gcc_assert (parser
->error
);
8017 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8021 tree type
= groktypename (t1
, NULL
, NULL
);
8023 if (type
== error_mark_node
)
8024 offsetof_ref
= error_mark_node
;
8027 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
8028 SET_EXPR_LOCATION (offsetof_ref
, loc
);
8030 /* Parse the second argument to __builtin_offsetof. We
8031 must have one identifier, and beyond that we want to
8032 accept sub structure and sub array references. */
8033 if (c_parser_next_token_is (parser
, CPP_NAME
))
8035 c_token
*comp_tok
= c_parser_peek_token (parser
);
8036 offsetof_ref
= build_component_ref
8037 (loc
, offsetof_ref
, comp_tok
->value
, comp_tok
->location
);
8038 c_parser_consume_token (parser
);
8039 while (c_parser_next_token_is (parser
, CPP_DOT
)
8040 || c_parser_next_token_is (parser
,
8042 || c_parser_next_token_is (parser
,
8045 if (c_parser_next_token_is (parser
, CPP_DEREF
))
8047 loc
= c_parser_peek_token (parser
)->location
;
8048 offsetof_ref
= build_array_ref (loc
,
8053 else if (c_parser_next_token_is (parser
, CPP_DOT
))
8056 c_parser_consume_token (parser
);
8057 if (c_parser_next_token_is_not (parser
,
8060 c_parser_error (parser
, "expected identifier");
8063 c_token
*comp_tok
= c_parser_peek_token (parser
);
8064 offsetof_ref
= build_component_ref
8065 (loc
, offsetof_ref
, comp_tok
->value
,
8066 comp_tok
->location
);
8067 c_parser_consume_token (parser
);
8073 loc
= c_parser_peek_token (parser
)->location
;
8074 c_parser_consume_token (parser
);
8075 ce
= c_parser_expression (parser
);
8076 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8078 idx
= c_fully_fold (idx
, false, NULL
);
8079 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8081 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
8086 c_parser_error (parser
, "expected identifier");
8087 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
8088 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8090 expr
.value
= fold_offsetof (offsetof_ref
);
8091 set_c_expr_source_range (&expr
, loc
, end_loc
);
8094 case RID_CHOOSE_EXPR
:
8096 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8097 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
8099 location_t close_paren_loc
;
8101 c_parser_consume_token (parser
);
8102 if (!c_parser_get_builtin_args (parser
,
8103 "__builtin_choose_expr",
8111 if (vec_safe_length (cexpr_list
) != 3)
8113 error_at (loc
, "wrong number of arguments to "
8114 "%<__builtin_choose_expr%>");
8119 e1_p
= &(*cexpr_list
)[0];
8120 e2_p
= &(*cexpr_list
)[1];
8121 e3_p
= &(*cexpr_list
)[2];
8124 mark_exp_read (e2_p
->value
);
8125 mark_exp_read (e3_p
->value
);
8126 if (TREE_CODE (c
) != INTEGER_CST
8127 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
8129 "first argument to %<__builtin_choose_expr%> not"
8131 constant_expression_warning (c
);
8132 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
8133 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8136 case RID_TYPES_COMPATIBLE_P
:
8138 c_parser_consume_token (parser
);
8139 matching_parens parens
;
8140 if (!parens
.require_open (parser
))
8145 t1
= c_parser_type_name (parser
);
8151 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8153 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8157 t2
= c_parser_type_name (parser
);
8163 location_t close_paren_loc
= c_parser_peek_token (parser
)->location
;
8164 parens
.skip_until_found_close (parser
);
8166 e1
= groktypename (t1
, NULL
, NULL
);
8167 e2
= groktypename (t2
, NULL
, NULL
);
8168 if (e1
== error_mark_node
|| e2
== error_mark_node
)
8174 e1
= TYPE_MAIN_VARIANT (e1
);
8175 e2
= TYPE_MAIN_VARIANT (e2
);
8178 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
8179 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8182 case RID_BUILTIN_TGMATH
:
8184 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8185 location_t close_paren_loc
;
8187 c_parser_consume_token (parser
);
8188 if (!c_parser_get_builtin_args (parser
,
8197 if (vec_safe_length (cexpr_list
) < 3)
8199 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8206 FOR_EACH_VEC_ELT (*cexpr_list
, i
, p
)
8207 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8208 unsigned int nargs
= check_tgmath_function (&(*cexpr_list
)[0], 1);
8214 if (vec_safe_length (cexpr_list
) < nargs
)
8216 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8220 unsigned int num_functions
= vec_safe_length (cexpr_list
) - nargs
;
8221 if (num_functions
< 2)
8223 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8228 /* The first NUM_FUNCTIONS expressions are the function
8229 pointers. The remaining NARGS expressions are the
8230 arguments that are to be passed to one of those
8231 functions, chosen following <tgmath.h> rules. */
8232 for (unsigned int j
= 1; j
< num_functions
; j
++)
8234 unsigned int this_nargs
8235 = check_tgmath_function (&(*cexpr_list
)[j
], j
+ 1);
8236 if (this_nargs
== 0)
8241 if (this_nargs
!= nargs
)
8243 error_at ((*cexpr_list
)[j
].get_location (),
8244 "argument %u of %<__builtin_tgmath%> has "
8245 "wrong number of arguments", j
+ 1);
8251 /* The functions all have the same number of arguments.
8252 Determine whether arguments and return types vary in
8253 ways permitted for <tgmath.h> functions. */
8254 /* The first entry in each of these vectors is for the
8255 return type, subsequent entries for parameter
8257 auto_vec
<enum tgmath_parm_kind
> parm_kind (nargs
+ 1);
8258 auto_vec
<tree
> parm_first (nargs
+ 1);
8259 auto_vec
<bool> parm_complex (nargs
+ 1);
8260 auto_vec
<bool> parm_varies (nargs
+ 1);
8261 tree first_type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[0].value
));
8262 tree first_ret
= TYPE_MAIN_VARIANT (TREE_TYPE (first_type
));
8263 parm_first
.quick_push (first_ret
);
8264 parm_complex
.quick_push (TREE_CODE (first_ret
) == COMPLEX_TYPE
);
8265 parm_varies
.quick_push (false);
8266 function_args_iterator iter
;
8268 unsigned int argpos
;
8269 FOREACH_FUNCTION_ARGS (first_type
, t
, iter
)
8271 if (t
== void_type_node
)
8273 parm_first
.quick_push (TYPE_MAIN_VARIANT (t
));
8274 parm_complex
.quick_push (TREE_CODE (t
) == COMPLEX_TYPE
);
8275 parm_varies
.quick_push (false);
8277 for (unsigned int j
= 1; j
< num_functions
; j
++)
8279 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8280 tree ret
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
8281 if (ret
!= parm_first
[0])
8283 parm_varies
[0] = true;
8284 if (!SCALAR_FLOAT_TYPE_P (parm_first
[0])
8285 && !COMPLEX_FLOAT_TYPE_P (parm_first
[0]))
8287 error_at ((*cexpr_list
)[0].get_location (),
8288 "invalid type-generic return type for "
8289 "argument %u of %<__builtin_tgmath%>",
8294 if (!SCALAR_FLOAT_TYPE_P (ret
)
8295 && !COMPLEX_FLOAT_TYPE_P (ret
))
8297 error_at ((*cexpr_list
)[j
].get_location (),
8298 "invalid type-generic return type for "
8299 "argument %u of %<__builtin_tgmath%>",
8305 if (TREE_CODE (ret
) == COMPLEX_TYPE
)
8306 parm_complex
[0] = true;
8308 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8310 if (t
== void_type_node
)
8312 t
= TYPE_MAIN_VARIANT (t
);
8313 if (t
!= parm_first
[argpos
])
8315 parm_varies
[argpos
] = true;
8316 if (!SCALAR_FLOAT_TYPE_P (parm_first
[argpos
])
8317 && !COMPLEX_FLOAT_TYPE_P (parm_first
[argpos
]))
8319 error_at ((*cexpr_list
)[0].get_location (),
8320 "invalid type-generic type for "
8321 "argument %u of argument %u of "
8322 "%<__builtin_tgmath%>", argpos
, 1);
8326 if (!SCALAR_FLOAT_TYPE_P (t
)
8327 && !COMPLEX_FLOAT_TYPE_P (t
))
8329 error_at ((*cexpr_list
)[j
].get_location (),
8330 "invalid type-generic type for "
8331 "argument %u of argument %u of "
8332 "%<__builtin_tgmath%>", argpos
, j
+ 1);
8337 if (TREE_CODE (t
) == COMPLEX_TYPE
)
8338 parm_complex
[argpos
] = true;
8342 enum tgmath_parm_kind max_variation
= tgmath_fixed
;
8343 for (unsigned int j
= 0; j
<= nargs
; j
++)
8345 enum tgmath_parm_kind this_kind
;
8348 if (parm_complex
[j
])
8349 max_variation
= this_kind
= tgmath_complex
;
8352 this_kind
= tgmath_real
;
8353 if (max_variation
!= tgmath_complex
)
8354 max_variation
= tgmath_real
;
8358 this_kind
= tgmath_fixed
;
8359 parm_kind
.quick_push (this_kind
);
8361 if (max_variation
== tgmath_fixed
)
8363 error_at (loc
, "function arguments of %<__builtin_tgmath%> "
8364 "all have the same type");
8369 /* Identify a parameter (not the return type) that varies,
8370 including with complex types if any variation includes
8371 complex types; there must be at least one such
8373 unsigned int tgarg
= 0;
8374 for (unsigned int j
= 1; j
<= nargs
; j
++)
8375 if (parm_kind
[j
] == max_variation
)
8382 error_at (loc
, "function arguments of %<__builtin_tgmath%> "
8383 "lack type-generic parameter");
8388 /* Determine the type of the relevant parameter for each
8390 auto_vec
<tree
> tg_type (num_functions
);
8391 for (unsigned int j
= 0; j
< num_functions
; j
++)
8393 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8395 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8397 if (argpos
== tgarg
)
8399 tg_type
.quick_push (TYPE_MAIN_VARIANT (t
));
8406 /* Verify that the corresponding types are different for
8407 all the listed functions. Also determine whether all
8408 the types are complex, whether all the types are
8409 standard or binary, and whether all the types are
8411 bool all_complex
= true;
8412 bool all_binary
= true;
8413 bool all_decimal
= true;
8414 hash_set
<tree
> tg_types
;
8415 FOR_EACH_VEC_ELT (tg_type
, i
, t
)
8417 if (TREE_CODE (t
) == COMPLEX_TYPE
)
8418 all_decimal
= false;
8421 all_complex
= false;
8422 if (DECIMAL_FLOAT_TYPE_P (t
))
8425 all_decimal
= false;
8427 if (tg_types
.add (t
))
8429 error_at ((*cexpr_list
)[i
].get_location (),
8430 "duplicate type-generic parameter type for "
8431 "function argument %u of %<__builtin_tgmath%>",
8438 /* Verify that other parameters and the return type whose
8439 types vary have their types varying in the correct
8441 for (unsigned int j
= 0; j
< num_functions
; j
++)
8443 tree exp_type
= tg_type
[j
];
8444 tree exp_real_type
= exp_type
;
8445 if (TREE_CODE (exp_type
) == COMPLEX_TYPE
)
8446 exp_real_type
= TREE_TYPE (exp_type
);
8447 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8448 tree ret
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
8449 if ((parm_kind
[0] == tgmath_complex
&& ret
!= exp_type
)
8450 || (parm_kind
[0] == tgmath_real
&& ret
!= exp_real_type
))
8452 error_at ((*cexpr_list
)[j
].get_location (),
8453 "bad return type for function argument %u "
8454 "of %<__builtin_tgmath%>", j
+ 1);
8459 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8461 if (t
== void_type_node
)
8463 t
= TYPE_MAIN_VARIANT (t
);
8464 if ((parm_kind
[argpos
] == tgmath_complex
8466 || (parm_kind
[argpos
] == tgmath_real
8467 && t
!= exp_real_type
))
8469 error_at ((*cexpr_list
)[j
].get_location (),
8470 "bad type for argument %u of "
8471 "function argument %u of "
8472 "%<__builtin_tgmath%>", argpos
, j
+ 1);
8480 /* The functions listed are a valid set of functions for a
8481 <tgmath.h> macro to select between. Identify the
8482 matching function, if any. First, the argument types
8483 must be combined following <tgmath.h> rules. Integer
8484 types are treated as _Decimal64 if any type-generic
8485 argument is decimal, or if the only alternatives for
8486 type-generic arguments are of decimal types, and are
8487 otherwise treated as double (or _Complex double for
8488 complex integer types). After that adjustment, types
8489 are combined following the usual arithmetic
8490 conversions. If the function only accepts complex
8491 arguments, a complex type is produced. */
8492 bool arg_complex
= all_complex
;
8493 bool arg_binary
= all_binary
;
8494 bool arg_int_decimal
= all_decimal
;
8495 for (unsigned int j
= 1; j
<= nargs
; j
++)
8497 if (parm_kind
[j
] == tgmath_fixed
)
8499 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
- 1];
8500 tree type
= TREE_TYPE (ce
->value
);
8501 if (!INTEGRAL_TYPE_P (type
)
8502 && !SCALAR_FLOAT_TYPE_P (type
)
8503 && TREE_CODE (type
) != COMPLEX_TYPE
)
8505 error_at (ce
->get_location (),
8506 "invalid type of argument %u of type-generic "
8511 if (DECIMAL_FLOAT_TYPE_P (type
))
8513 arg_int_decimal
= true;
8516 error_at (ce
->get_location (),
8517 "decimal floating-point argument %u to "
8518 "complex-only type-generic function", j
);
8522 else if (all_binary
)
8524 error_at (ce
->get_location (),
8525 "decimal floating-point argument %u to "
8526 "binary-only type-generic function", j
);
8530 else if (arg_complex
)
8532 error_at (ce
->get_location (),
8533 "both complex and decimal floating-point "
8534 "arguments to type-generic function");
8538 else if (arg_binary
)
8540 error_at (ce
->get_location (),
8541 "both binary and decimal floating-point "
8542 "arguments to type-generic function");
8547 else if (TREE_CODE (type
) == COMPLEX_TYPE
)
8550 if (COMPLEX_FLOAT_TYPE_P (type
))
8554 error_at (ce
->get_location (),
8555 "complex argument %u to "
8556 "decimal-only type-generic function", j
);
8560 else if (arg_int_decimal
)
8562 error_at (ce
->get_location (),
8563 "both complex and decimal floating-point "
8564 "arguments to type-generic function");
8569 else if (SCALAR_FLOAT_TYPE_P (type
))
8574 error_at (ce
->get_location (),
8575 "binary argument %u to "
8576 "decimal-only type-generic function", j
);
8580 else if (arg_int_decimal
)
8582 error_at (ce
->get_location (),
8583 "both binary and decimal floating-point "
8584 "arguments to type-generic function");
8590 tree arg_real
= NULL_TREE
;
8591 for (unsigned int j
= 1; j
<= nargs
; j
++)
8593 if (parm_kind
[j
] == tgmath_fixed
)
8595 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
- 1];
8596 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (ce
->value
));
8597 if (TREE_CODE (type
) == COMPLEX_TYPE
)
8598 type
= TREE_TYPE (type
);
8599 if (INTEGRAL_TYPE_P (type
))
8600 type
= (arg_int_decimal
8601 ? dfloat64_type_node
8602 : double_type_node
);
8603 if (arg_real
== NULL_TREE
)
8606 arg_real
= common_type (arg_real
, type
);
8607 if (arg_real
== error_mark_node
)
8613 tree arg_type
= (arg_complex
8614 ? build_complex_type (arg_real
)
8617 /* Look for a function to call with type-generic parameter
8619 c_expr_t
*fn
= NULL
;
8620 for (unsigned int j
= 0; j
< num_functions
; j
++)
8622 if (tg_type
[j
] == arg_type
)
8624 fn
= &(*cexpr_list
)[j
];
8629 && parm_kind
[0] == tgmath_fixed
8630 && SCALAR_FLOAT_TYPE_P (parm_first
[0]))
8632 /* Presume this is a macro that rounds its result to a
8633 narrower type, and look for the first function with
8634 at least the range and precision of the argument
8636 for (unsigned int j
= 0; j
< num_functions
; j
++)
8639 != (TREE_CODE (tg_type
[j
]) == COMPLEX_TYPE
))
8641 tree real_tg_type
= (arg_complex
8642 ? TREE_TYPE (tg_type
[j
])
8644 if (DECIMAL_FLOAT_TYPE_P (arg_real
)
8645 != DECIMAL_FLOAT_TYPE_P (real_tg_type
))
8647 scalar_float_mode arg_mode
8648 = SCALAR_FLOAT_TYPE_MODE (arg_real
);
8649 scalar_float_mode tg_mode
8650 = SCALAR_FLOAT_TYPE_MODE (real_tg_type
);
8651 const real_format
*arg_fmt
= REAL_MODE_FORMAT (arg_mode
);
8652 const real_format
*tg_fmt
= REAL_MODE_FORMAT (tg_mode
);
8653 if (arg_fmt
->b
== tg_fmt
->b
8654 && arg_fmt
->p
<= tg_fmt
->p
8655 && arg_fmt
->emax
<= tg_fmt
->emax
8656 && (arg_fmt
->emin
- arg_fmt
->p
8657 >= tg_fmt
->emin
- tg_fmt
->p
))
8659 fn
= &(*cexpr_list
)[j
];
8666 error_at (loc
, "no matching function for type-generic call");
8671 /* Construct a call to FN. */
8672 vec
<tree
, va_gc
> *args
;
8673 vec_alloc (args
, nargs
);
8674 vec
<tree
, va_gc
> *origtypes
;
8675 vec_alloc (origtypes
, nargs
);
8676 auto_vec
<location_t
> arg_loc (nargs
);
8677 for (unsigned int j
= 0; j
< nargs
; j
++)
8679 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
];
8680 args
->quick_push (ce
->value
);
8681 arg_loc
.quick_push (ce
->get_location ());
8682 origtypes
->quick_push (ce
->original_type
);
8684 expr
.value
= c_build_function_call_vec (loc
, arg_loc
, fn
->value
,
8686 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8689 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
8691 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8694 location_t close_paren_loc
;
8696 c_parser_consume_token (parser
);
8697 if (!c_parser_get_builtin_args (parser
,
8698 "__builtin_call_with_static_chain",
8705 if (vec_safe_length (cexpr_list
) != 2)
8707 error_at (loc
, "wrong number of arguments to "
8708 "%<__builtin_call_with_static_chain%>");
8713 expr
= (*cexpr_list
)[0];
8714 e2_p
= &(*cexpr_list
)[1];
8715 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
8716 chain_value
= e2_p
->value
;
8717 mark_exp_read (chain_value
);
8719 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
8720 error_at (loc
, "first argument to "
8721 "%<__builtin_call_with_static_chain%> "
8722 "must be a call expression");
8723 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
8724 error_at (loc
, "second argument to "
8725 "%<__builtin_call_with_static_chain%> "
8726 "must be a pointer type");
8728 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
8729 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8732 case RID_BUILTIN_COMPLEX
:
8734 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8735 c_expr_t
*e1_p
, *e2_p
;
8736 location_t close_paren_loc
;
8738 c_parser_consume_token (parser
);
8739 if (!c_parser_get_builtin_args (parser
,
8740 "__builtin_complex",
8748 if (vec_safe_length (cexpr_list
) != 2)
8750 error_at (loc
, "wrong number of arguments to "
8751 "%<__builtin_complex%>");
8756 e1_p
= &(*cexpr_list
)[0];
8757 e2_p
= &(*cexpr_list
)[1];
8759 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
8760 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
8761 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
8762 TREE_OPERAND (e1_p
->value
, 0));
8763 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
8764 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
8765 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
8766 TREE_OPERAND (e2_p
->value
, 0));
8767 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8768 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8769 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
8770 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
8772 error_at (loc
, "%<__builtin_complex%> operand "
8773 "not of real binary floating-point type");
8777 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
8778 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
8781 "%<__builtin_complex%> operands of different types");
8785 pedwarn_c90 (loc
, OPT_Wpedantic
,
8786 "ISO C90 does not support complex types");
8787 expr
.value
= build2_loc (loc
, COMPLEX_EXPR
,
8790 (TREE_TYPE (e1_p
->value
))),
8791 e1_p
->value
, e2_p
->value
);
8792 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8795 case RID_BUILTIN_SHUFFLE
:
8797 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8800 location_t close_paren_loc
;
8802 c_parser_consume_token (parser
);
8803 if (!c_parser_get_builtin_args (parser
,
8804 "__builtin_shuffle",
8812 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
8813 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8815 if (vec_safe_length (cexpr_list
) == 2)
8817 c_build_vec_perm_expr
8818 (loc
, (*cexpr_list
)[0].value
,
8819 NULL_TREE
, (*cexpr_list
)[1].value
);
8821 else if (vec_safe_length (cexpr_list
) == 3)
8823 c_build_vec_perm_expr
8824 (loc
, (*cexpr_list
)[0].value
,
8825 (*cexpr_list
)[1].value
,
8826 (*cexpr_list
)[2].value
);
8829 error_at (loc
, "wrong number of arguments to "
8830 "%<__builtin_shuffle%>");
8833 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8836 case RID_AT_SELECTOR
:
8838 gcc_assert (c_dialect_objc ());
8839 c_parser_consume_token (parser
);
8840 matching_parens parens
;
8841 if (!parens
.require_open (parser
))
8846 tree sel
= c_parser_objc_selector_arg (parser
);
8847 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8848 parens
.skip_until_found_close (parser
);
8849 expr
.value
= objc_build_selector_expr (loc
, sel
);
8850 set_c_expr_source_range (&expr
, loc
, close_loc
);
8853 case RID_AT_PROTOCOL
:
8855 gcc_assert (c_dialect_objc ());
8856 c_parser_consume_token (parser
);
8857 matching_parens parens
;
8858 if (!parens
.require_open (parser
))
8863 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8865 c_parser_error (parser
, "expected identifier");
8866 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8870 tree id
= c_parser_peek_token (parser
)->value
;
8871 c_parser_consume_token (parser
);
8872 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8873 parens
.skip_until_found_close (parser
);
8874 expr
.value
= objc_build_protocol_expr (id
);
8875 set_c_expr_source_range (&expr
, loc
, close_loc
);
8880 /* Extension to support C-structures in the archiver. */
8881 gcc_assert (c_dialect_objc ());
8882 c_parser_consume_token (parser
);
8883 matching_parens parens
;
8884 if (!parens
.require_open (parser
))
8889 t1
= c_parser_type_name (parser
);
8893 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8896 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8897 parens
.skip_until_found_close (parser
);
8898 tree type
= groktypename (t1
, NULL
, NULL
);
8899 expr
.value
= objc_build_encode_expr (type
);
8900 set_c_expr_source_range (&expr
, loc
, close_loc
);
8904 expr
= c_parser_generic_selection (parser
);
8907 c_parser_error (parser
, "expected expression");
8912 case CPP_OPEN_SQUARE
:
8913 if (c_dialect_objc ())
8915 tree receiver
, args
;
8916 c_parser_consume_token (parser
);
8917 receiver
= c_parser_objc_receiver (parser
);
8918 args
= c_parser_objc_message_args (parser
);
8919 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8920 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8922 expr
.value
= objc_build_message_expr (receiver
, args
);
8923 set_c_expr_source_range (&expr
, loc
, close_loc
);
8926 /* Else fall through to report error. */
8929 c_parser_error (parser
, "expected expression");
8934 return c_parser_postfix_expression_after_primary
8935 (parser
, EXPR_LOC_OR_LOC (expr
.value
, loc
), expr
);
8938 /* Parse a postfix expression after a parenthesized type name: the
8939 brace-enclosed initializer of a compound literal, possibly followed
8940 by some postfix operators. This is separate because it is not
8941 possible to tell until after the type name whether a cast
8942 expression has a cast or a compound literal, or whether the operand
8943 of sizeof is a parenthesized type name or starts with a compound
8944 literal. TYPE_LOC is the location where TYPE_NAME starts--the
8945 location of the first token after the parentheses around the type
8948 static struct c_expr
8949 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
8950 struct c_type_name
*type_name
,
8951 location_t type_loc
)
8957 location_t start_loc
;
8958 tree type_expr
= NULL_TREE
;
8959 bool type_expr_const
= true;
8960 check_compound_literal_type (type_loc
, type_name
);
8961 rich_location
richloc (line_table
, type_loc
);
8962 start_init (NULL_TREE
, NULL
, 0, &richloc
);
8963 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
8964 start_loc
= c_parser_peek_token (parser
)->location
;
8965 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
8967 error_at (type_loc
, "compound literal has variable size");
8968 type
= error_mark_node
;
8970 init
= c_parser_braced_init (parser
, type
, false, NULL
);
8972 maybe_warn_string_init (type_loc
, type
, init
);
8974 if (type
!= error_mark_node
8975 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
8976 && current_function_decl
)
8978 error ("compound literal qualified by address-space qualifier");
8979 type
= error_mark_node
;
8982 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
8983 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
8984 ? CONSTRUCTOR_NON_CONST (init
.value
)
8985 : init
.original_code
== C_MAYBE_CONST_EXPR
);
8986 non_const
|= !type_expr_const
;
8987 unsigned int alignas_align
= 0;
8988 if (type
!= error_mark_node
8989 && type_name
->specs
->align_log
!= -1)
8991 alignas_align
= 1U << type_name
->specs
->align_log
;
8992 if (alignas_align
< min_align_of_type (type
))
8994 error_at (type_name
->specs
->locations
[cdw_alignas
],
8995 "%<_Alignas%> specifiers cannot reduce "
8996 "alignment of compound literal");
9000 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
,
9002 set_c_expr_source_range (&expr
, init
.src_range
);
9003 expr
.original_code
= ERROR_MARK
;
9004 expr
.original_type
= NULL
;
9005 if (type
!= error_mark_node
9006 && expr
.value
!= error_mark_node
9009 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
9011 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
9012 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
9016 gcc_assert (!non_const
);
9017 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
9018 type_expr
, expr
.value
);
9021 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
9024 /* Callback function for sizeof_pointer_memaccess_warning to compare
9028 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
9030 return comptypes (type1
, type2
) == 1;
9033 /* Parse a postfix expression after the initial primary or compound
9034 literal; that is, parse a series of postfix operators.
9036 EXPR_LOC is the location of the primary expression. */
9038 static struct c_expr
9039 c_parser_postfix_expression_after_primary (c_parser
*parser
,
9040 location_t expr_loc
,
9043 struct c_expr orig_expr
;
9045 location_t sizeof_arg_loc
[3], comp_loc
;
9047 unsigned int literal_zero_mask
;
9049 vec
<tree
, va_gc
> *exprlist
;
9050 vec
<tree
, va_gc
> *origtypes
= NULL
;
9051 vec
<location_t
> arg_loc
= vNULL
;
9057 location_t op_loc
= c_parser_peek_token (parser
)->location
;
9058 switch (c_parser_peek_token (parser
)->type
)
9060 case CPP_OPEN_SQUARE
:
9061 /* Array reference. */
9062 c_parser_consume_token (parser
);
9063 idx
= c_parser_expression (parser
).value
;
9064 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
9066 start
= expr
.get_start ();
9067 finish
= parser
->tokens_buf
[0].location
;
9068 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
9069 set_c_expr_source_range (&expr
, start
, finish
);
9070 expr
.original_code
= ERROR_MARK
;
9071 expr
.original_type
= NULL
;
9073 case CPP_OPEN_PAREN
:
9074 /* Function call. */
9075 c_parser_consume_token (parser
);
9076 for (i
= 0; i
< 3; i
++)
9078 sizeof_arg
[i
] = NULL_TREE
;
9079 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
9081 literal_zero_mask
= 0;
9082 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9085 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
9086 sizeof_arg_loc
, sizeof_arg
,
9087 &arg_loc
, &literal_zero_mask
);
9088 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9091 mark_exp_read (expr
.value
);
9092 if (warn_sizeof_pointer_memaccess
)
9093 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
9094 expr
.value
, exprlist
,
9096 sizeof_ptr_memacc_comptypes
);
9097 if (TREE_CODE (expr
.value
) == FUNCTION_DECL
9098 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
9099 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
9100 && vec_safe_length (exprlist
) == 3)
9102 tree arg0
= (*exprlist
)[0];
9103 tree arg2
= (*exprlist
)[2];
9104 warn_for_memset (expr_loc
, arg0
, arg2
, literal_zero_mask
);
9107 start
= expr
.get_start ();
9108 finish
= parser
->tokens_buf
[0].get_finish ();
9110 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
9111 exprlist
, origtypes
);
9112 set_c_expr_source_range (&expr
, start
, finish
);
9114 expr
.original_code
= ERROR_MARK
;
9115 if (TREE_CODE (expr
.value
) == INTEGER_CST
9116 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
9117 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
9118 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
9119 expr
.original_code
= C_MAYBE_CONST_EXPR
;
9120 expr
.original_type
= NULL
;
9123 release_tree_vector (exprlist
);
9124 release_tree_vector (origtypes
);
9129 /* Structure element reference. */
9130 c_parser_consume_token (parser
);
9131 expr
= default_function_array_conversion (expr_loc
, expr
);
9132 if (c_parser_next_token_is (parser
, CPP_NAME
))
9134 c_token
*comp_tok
= c_parser_peek_token (parser
);
9135 ident
= comp_tok
->value
;
9136 comp_loc
= comp_tok
->location
;
9140 c_parser_error (parser
, "expected identifier");
9142 expr
.original_code
= ERROR_MARK
;
9143 expr
.original_type
= NULL
;
9146 start
= expr
.get_start ();
9147 finish
= c_parser_peek_token (parser
)->get_finish ();
9148 c_parser_consume_token (parser
);
9149 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
,
9151 set_c_expr_source_range (&expr
, start
, finish
);
9152 expr
.original_code
= ERROR_MARK
;
9153 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
9154 expr
.original_type
= NULL
;
9157 /* Remember the original type of a bitfield. */
9158 tree field
= TREE_OPERAND (expr
.value
, 1);
9159 if (TREE_CODE (field
) != FIELD_DECL
)
9160 expr
.original_type
= NULL
;
9162 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
9166 /* Structure element reference. */
9167 c_parser_consume_token (parser
);
9168 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
9169 if (c_parser_next_token_is (parser
, CPP_NAME
))
9171 c_token
*comp_tok
= c_parser_peek_token (parser
);
9172 ident
= comp_tok
->value
;
9173 comp_loc
= comp_tok
->location
;
9177 c_parser_error (parser
, "expected identifier");
9179 expr
.original_code
= ERROR_MARK
;
9180 expr
.original_type
= NULL
;
9183 start
= expr
.get_start ();
9184 finish
= c_parser_peek_token (parser
)->get_finish ();
9185 c_parser_consume_token (parser
);
9186 expr
.value
= build_component_ref (op_loc
,
9187 build_indirect_ref (op_loc
,
9191 set_c_expr_source_range (&expr
, start
, finish
);
9192 expr
.original_code
= ERROR_MARK
;
9193 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
9194 expr
.original_type
= NULL
;
9197 /* Remember the original type of a bitfield. */
9198 tree field
= TREE_OPERAND (expr
.value
, 1);
9199 if (TREE_CODE (field
) != FIELD_DECL
)
9200 expr
.original_type
= NULL
;
9202 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
9206 /* Postincrement. */
9207 start
= expr
.get_start ();
9208 finish
= c_parser_peek_token (parser
)->get_finish ();
9209 c_parser_consume_token (parser
);
9210 expr
= default_function_array_read_conversion (expr_loc
, expr
);
9211 expr
.value
= build_unary_op (op_loc
, POSTINCREMENT_EXPR
,
9213 set_c_expr_source_range (&expr
, start
, finish
);
9214 expr
.original_code
= ERROR_MARK
;
9215 expr
.original_type
= NULL
;
9217 case CPP_MINUS_MINUS
:
9218 /* Postdecrement. */
9219 start
= expr
.get_start ();
9220 finish
= c_parser_peek_token (parser
)->get_finish ();
9221 c_parser_consume_token (parser
);
9222 expr
= default_function_array_read_conversion (expr_loc
, expr
);
9223 expr
.value
= build_unary_op (op_loc
, POSTDECREMENT_EXPR
,
9225 set_c_expr_source_range (&expr
, start
, finish
);
9226 expr
.original_code
= ERROR_MARK
;
9227 expr
.original_type
= NULL
;
9235 /* Parse an expression (C90 6.3.17, C99 6.5.17, C11 6.5.17).
9238 assignment-expression
9239 expression , assignment-expression
9242 static struct c_expr
9243 c_parser_expression (c_parser
*parser
)
9245 location_t tloc
= c_parser_peek_token (parser
)->location
;
9247 expr
= c_parser_expr_no_commas (parser
, NULL
);
9248 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9249 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
9250 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9254 location_t loc
= c_parser_peek_token (parser
)->location
;
9255 location_t expr_loc
;
9256 c_parser_consume_token (parser
);
9257 expr_loc
= c_parser_peek_token (parser
)->location
;
9258 lhsval
= expr
.value
;
9259 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
9260 lhsval
= TREE_OPERAND (lhsval
, 1);
9261 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
9262 mark_exp_read (lhsval
);
9263 next
= c_parser_expr_no_commas (parser
, NULL
);
9264 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
9265 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
9266 expr
.original_code
= COMPOUND_EXPR
;
9267 expr
.original_type
= next
.original_type
;
9272 /* Parse an expression and convert functions or arrays to pointers and
9273 lvalues to rvalues. */
9275 static struct c_expr
9276 c_parser_expression_conv (c_parser
*parser
)
9279 location_t loc
= c_parser_peek_token (parser
)->location
;
9280 expr
= c_parser_expression (parser
);
9281 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
9285 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
9286 argument is a literal zero alone and if so, set it in literal_zero_mask. */
9289 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
9292 if (idx
>= HOST_BITS_PER_INT
)
9295 c_token
*tok
= c_parser_peek_token (parser
);
9303 /* If a parameter is literal zero alone, remember it
9304 for -Wmemset-transposed-args warning. */
9305 if (integer_zerop (tok
->value
)
9306 && !TREE_OVERFLOW (tok
->value
)
9307 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9308 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
9309 *literal_zero_mask
|= 1U << idx
;
9315 /* Parse a non-empty list of expressions. If CONVERT_P, convert
9316 functions and arrays to pointers and lvalues to rvalues. If
9317 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
9318 locations of function arguments into this vector.
9321 assignment-expression
9322 nonempty-expr-list , assignment-expression
9325 static vec
<tree
, va_gc
> *
9326 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
9327 vec
<tree
, va_gc
> **p_orig_types
,
9328 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
9329 vec
<location_t
> *locations
,
9330 unsigned int *literal_zero_mask
)
9332 vec
<tree
, va_gc
> *ret
;
9333 vec
<tree
, va_gc
> *orig_types
;
9335 unsigned int idx
= 0;
9337 ret
= make_tree_vector ();
9338 if (p_orig_types
== NULL
)
9341 orig_types
= make_tree_vector ();
9343 if (literal_zero_mask
)
9344 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
9345 expr
= c_parser_expr_no_commas (parser
, NULL
);
9347 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true, true);
9349 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
9350 ret
->quick_push (expr
.value
);
9352 orig_types
->quick_push (expr
.original_type
);
9354 locations
->safe_push (expr
.get_location ());
9355 if (sizeof_arg
!= NULL
9356 && expr
.original_code
== SIZEOF_EXPR
)
9358 sizeof_arg
[0] = c_last_sizeof_arg
;
9359 sizeof_arg_loc
[0] = c_last_sizeof_loc
;
9361 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9363 c_parser_consume_token (parser
);
9364 if (literal_zero_mask
)
9365 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
9366 expr
= c_parser_expr_no_commas (parser
, NULL
);
9368 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true,
9371 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
9372 vec_safe_push (ret
, expr
.value
);
9374 vec_safe_push (orig_types
, expr
.original_type
);
9376 locations
->safe_push (expr
.get_location ());
9378 && sizeof_arg
!= NULL
9379 && expr
.original_code
== SIZEOF_EXPR
)
9381 sizeof_arg
[idx
] = c_last_sizeof_arg
;
9382 sizeof_arg_loc
[idx
] = c_last_sizeof_loc
;
9386 *p_orig_types
= orig_types
;
9390 /* Parse Objective-C-specific constructs. */
9392 /* Parse an objc-class-definition.
9394 objc-class-definition:
9395 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
9396 objc-class-instance-variables[opt] objc-methodprotolist @end
9397 @implementation identifier objc-superclass[opt]
9398 objc-class-instance-variables[opt]
9399 @interface identifier ( identifier ) objc-protocol-refs[opt]
9400 objc-methodprotolist @end
9401 @interface identifier ( ) objc-protocol-refs[opt]
9402 objc-methodprotolist @end
9403 @implementation identifier ( identifier )
9408 "@interface identifier (" must start "@interface identifier (
9409 identifier ) ...": objc-methodprotolist in the first production may
9410 not start with a parenthesized identifier as a declarator of a data
9411 definition with no declaration specifiers if the objc-superclass,
9412 objc-protocol-refs and objc-class-instance-variables are omitted. */
9415 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
9420 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
9422 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
9427 c_parser_consume_token (parser
);
9428 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9430 c_parser_error (parser
, "expected identifier");
9433 id1
= c_parser_peek_token (parser
)->value
;
9434 c_parser_consume_token (parser
);
9435 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9437 /* We have a category or class extension. */
9439 tree proto
= NULL_TREE
;
9440 matching_parens parens
;
9441 parens
.consume_open (parser
);
9442 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9444 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9446 /* We have a class extension. */
9451 c_parser_error (parser
, "expected identifier or %<)%>");
9452 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
9458 id2
= c_parser_peek_token (parser
)->value
;
9459 c_parser_consume_token (parser
);
9461 parens
.skip_until_found_close (parser
);
9464 objc_start_category_implementation (id1
, id2
);
9467 if (c_parser_next_token_is (parser
, CPP_LESS
))
9468 proto
= c_parser_objc_protocol_refs (parser
);
9469 objc_start_category_interface (id1
, id2
, proto
, attributes
);
9470 c_parser_objc_methodprotolist (parser
);
9471 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9472 objc_finish_interface ();
9475 if (c_parser_next_token_is (parser
, CPP_COLON
))
9477 c_parser_consume_token (parser
);
9478 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9480 c_parser_error (parser
, "expected identifier");
9483 superclass
= c_parser_peek_token (parser
)->value
;
9484 c_parser_consume_token (parser
);
9487 superclass
= NULL_TREE
;
9490 tree proto
= NULL_TREE
;
9491 if (c_parser_next_token_is (parser
, CPP_LESS
))
9492 proto
= c_parser_objc_protocol_refs (parser
);
9493 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
9496 objc_start_class_implementation (id1
, superclass
);
9497 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9498 c_parser_objc_class_instance_variables (parser
);
9501 objc_continue_interface ();
9502 c_parser_objc_methodprotolist (parser
);
9503 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9504 objc_finish_interface ();
9508 objc_continue_implementation ();
9513 /* Parse objc-class-instance-variables.
9515 objc-class-instance-variables:
9516 { objc-instance-variable-decl-list[opt] }
9518 objc-instance-variable-decl-list:
9519 objc-visibility-spec
9520 objc-instance-variable-decl ;
9522 objc-instance-variable-decl-list objc-visibility-spec
9523 objc-instance-variable-decl-list objc-instance-variable-decl ;
9524 objc-instance-variable-decl-list ;
9526 objc-visibility-spec:
9531 objc-instance-variable-decl:
9536 c_parser_objc_class_instance_variables (c_parser
*parser
)
9538 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
9539 c_parser_consume_token (parser
);
9540 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
9543 /* Parse any stray semicolon. */
9544 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9546 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9548 c_parser_consume_token (parser
);
9551 /* Stop if at the end of the instance variables. */
9552 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9554 c_parser_consume_token (parser
);
9557 /* Parse any objc-visibility-spec. */
9558 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
9560 c_parser_consume_token (parser
);
9561 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
9564 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
9566 c_parser_consume_token (parser
);
9567 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
9570 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
9572 c_parser_consume_token (parser
);
9573 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
9576 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
9578 c_parser_consume_token (parser
);
9579 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
9582 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
9584 c_parser_pragma (parser
, pragma_external
, NULL
);
9588 /* Parse some comma-separated declarations. */
9589 decls
= c_parser_struct_declaration (parser
);
9592 /* There is a syntax error. We want to skip the offending
9593 tokens up to the next ';' (included) or '}'
9596 /* First, skip manually a ')' or ']'. This is because they
9597 reduce the nesting level, so c_parser_skip_until_found()
9598 wouldn't be able to skip past them. */
9599 c_token
*token
= c_parser_peek_token (parser
);
9600 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
9601 c_parser_consume_token (parser
);
9603 /* Then, do the standard skipping. */
9604 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9606 /* We hopefully recovered. Start normal parsing again. */
9607 parser
->error
= false;
9612 /* Comma-separated instance variables are chained together
9613 in reverse order; add them one by one. */
9614 tree ivar
= nreverse (decls
);
9615 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
9616 objc_add_instance_variable (copy_node (ivar
));
9618 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9622 /* Parse an objc-class-declaration.
9624 objc-class-declaration:
9625 @class identifier-list ;
9629 c_parser_objc_class_declaration (c_parser
*parser
)
9631 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
9632 c_parser_consume_token (parser
);
9633 /* Any identifiers, including those declared as type names, are OK
9638 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9640 c_parser_error (parser
, "expected identifier");
9641 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9642 parser
->error
= false;
9645 id
= c_parser_peek_token (parser
)->value
;
9646 objc_declare_class (id
);
9647 c_parser_consume_token (parser
);
9648 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9649 c_parser_consume_token (parser
);
9653 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9656 /* Parse an objc-alias-declaration.
9658 objc-alias-declaration:
9659 @compatibility_alias identifier identifier ;
9663 c_parser_objc_alias_declaration (c_parser
*parser
)
9666 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
9667 c_parser_consume_token (parser
);
9668 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9670 c_parser_error (parser
, "expected identifier");
9671 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9674 id1
= c_parser_peek_token (parser
)->value
;
9675 c_parser_consume_token (parser
);
9676 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9678 c_parser_error (parser
, "expected identifier");
9679 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9682 id2
= c_parser_peek_token (parser
)->value
;
9683 c_parser_consume_token (parser
);
9684 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9685 objc_declare_alias (id1
, id2
);
9688 /* Parse an objc-protocol-definition.
9690 objc-protocol-definition:
9691 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
9692 @protocol identifier-list ;
9694 "@protocol identifier ;" should be resolved as "@protocol
9695 identifier-list ;": objc-methodprotolist may not start with a
9696 semicolon in the first alternative if objc-protocol-refs are
9700 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
9702 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
9704 c_parser_consume_token (parser
);
9705 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9707 c_parser_error (parser
, "expected identifier");
9710 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9711 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
9713 /* Any identifiers, including those declared as type names, are
9718 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9720 c_parser_error (parser
, "expected identifier");
9723 id
= c_parser_peek_token (parser
)->value
;
9724 objc_declare_protocol (id
, attributes
);
9725 c_parser_consume_token (parser
);
9726 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9727 c_parser_consume_token (parser
);
9731 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9735 tree id
= c_parser_peek_token (parser
)->value
;
9736 tree proto
= NULL_TREE
;
9737 c_parser_consume_token (parser
);
9738 if (c_parser_next_token_is (parser
, CPP_LESS
))
9739 proto
= c_parser_objc_protocol_refs (parser
);
9740 parser
->objc_pq_context
= true;
9741 objc_start_protocol (id
, proto
, attributes
);
9742 c_parser_objc_methodprotolist (parser
);
9743 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9744 parser
->objc_pq_context
= false;
9745 objc_finish_interface ();
9749 /* Parse an objc-method-type.
9755 Return true if it is a class method (+) and false if it is
9756 an instance method (-).
9759 c_parser_objc_method_type (c_parser
*parser
)
9761 switch (c_parser_peek_token (parser
)->type
)
9764 c_parser_consume_token (parser
);
9767 c_parser_consume_token (parser
);
9774 /* Parse an objc-method-definition.
9776 objc-method-definition:
9777 objc-method-type objc-method-decl ;[opt] compound-statement
9781 c_parser_objc_method_definition (c_parser
*parser
)
9783 bool is_class_method
= c_parser_objc_method_type (parser
);
9784 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
9785 parser
->objc_pq_context
= true;
9786 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9788 if (decl
== error_mark_node
)
9789 return; /* Bail here. */
9791 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9793 c_parser_consume_token (parser
);
9794 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9795 "extra semicolon in method definition specified");
9798 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9800 c_parser_error (parser
, "expected %<{%>");
9804 parser
->objc_pq_context
= false;
9805 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
9807 add_stmt (c_parser_compound_statement (parser
));
9808 objc_finish_method_definition (current_function_decl
);
9812 /* This code is executed when we find a method definition
9813 outside of an @implementation context (or invalid for other
9814 reasons). Parse the method (to keep going) but do not emit
9817 c_parser_compound_statement (parser
);
9821 /* Parse an objc-methodprotolist.
9823 objc-methodprotolist:
9825 objc-methodprotolist objc-methodproto
9826 objc-methodprotolist declaration
9827 objc-methodprotolist ;
9831 The declaration is a data definition, which may be missing
9832 declaration specifiers under the same rules and diagnostics as
9833 other data definitions outside functions, and the stray semicolon
9834 is diagnosed the same way as a stray semicolon outside a
9838 c_parser_objc_methodprotolist (c_parser
*parser
)
9842 /* The list is terminated by @end. */
9843 switch (c_parser_peek_token (parser
)->type
)
9846 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9847 "ISO C does not allow extra %<;%> outside of a function");
9848 c_parser_consume_token (parser
);
9852 c_parser_objc_methodproto (parser
);
9855 c_parser_pragma (parser
, pragma_external
, NULL
);
9860 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
9862 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
9863 c_parser_objc_at_property_declaration (parser
);
9864 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
9866 objc_set_method_opt (true);
9867 c_parser_consume_token (parser
);
9869 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
9871 objc_set_method_opt (false);
9872 c_parser_consume_token (parser
);
9875 c_parser_declaration_or_fndef (parser
, false, false, true,
9876 false, true, NULL
, vNULL
);
9882 /* Parse an objc-methodproto.
9885 objc-method-type objc-method-decl ;
9889 c_parser_objc_methodproto (c_parser
*parser
)
9891 bool is_class_method
= c_parser_objc_method_type (parser
);
9892 tree decl
, attributes
= NULL_TREE
;
9894 /* Remember protocol qualifiers in prototypes. */
9895 parser
->objc_pq_context
= true;
9896 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9898 /* Forget protocol qualifiers now. */
9899 parser
->objc_pq_context
= false;
9901 /* Do not allow the presence of attributes to hide an erroneous
9902 method implementation in the interface section. */
9903 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9905 c_parser_error (parser
, "expected %<;%>");
9909 if (decl
!= error_mark_node
)
9910 objc_add_method_declaration (is_class_method
, decl
, attributes
);
9912 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9915 /* If we are at a position that method attributes may be present, check that
9916 there are not any parsed already (a syntax error) and then collect any
9917 specified at the current location. Finally, if new attributes were present,
9918 check that the next token is legal ( ';' for decls and '{' for defs). */
9921 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
9926 c_parser_error (parser
,
9927 "method attributes must be specified at the end only");
9928 *attributes
= NULL_TREE
;
9932 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
9933 *attributes
= c_parser_attributes (parser
);
9935 /* If there were no attributes here, just report any earlier error. */
9936 if (*attributes
== NULL_TREE
|| bad
)
9939 /* If the attributes are followed by a ; or {, then just report any earlier
9941 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
9942 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9945 /* We've got attributes, but not at the end. */
9946 c_parser_error (parser
,
9947 "expected %<;%> or %<{%> after method attribute definition");
9951 /* Parse an objc-method-decl.
9954 ( objc-type-name ) objc-selector
9956 ( objc-type-name ) objc-keyword-selector objc-optparmlist
9957 objc-keyword-selector objc-optparmlist
9960 objc-keyword-selector:
9962 objc-keyword-selector objc-keyword-decl
9965 objc-selector : ( objc-type-name ) identifier
9966 objc-selector : identifier
9967 : ( objc-type-name ) identifier
9971 objc-optparms objc-optellipsis
9975 objc-opt-parms , parameter-declaration
9983 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
9984 tree
*attributes
, tree
*expr
)
9986 tree type
= NULL_TREE
;
9988 tree parms
= NULL_TREE
;
9989 bool ellipsis
= false;
9990 bool attr_err
= false;
9992 *attributes
= NULL_TREE
;
9993 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9995 matching_parens parens
;
9996 parens
.consume_open (parser
);
9997 type
= c_parser_objc_type_name (parser
);
9998 parens
.skip_until_found_close (parser
);
10000 sel
= c_parser_objc_selector (parser
);
10001 /* If there is no selector, or a colon follows, we have an
10002 objc-keyword-selector. If there is a selector, and a colon does
10003 not follow, that selector ends the objc-method-decl. */
10004 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
10007 tree list
= NULL_TREE
;
10010 tree atype
= NULL_TREE
, id
, keyworddecl
;
10011 tree param_attr
= NULL_TREE
;
10012 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10014 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10016 c_parser_consume_token (parser
);
10017 atype
= c_parser_objc_type_name (parser
);
10018 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10021 /* New ObjC allows attributes on method parameters. */
10022 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
10023 param_attr
= c_parser_attributes (parser
);
10024 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10026 c_parser_error (parser
, "expected identifier");
10027 return error_mark_node
;
10029 id
= c_parser_peek_token (parser
)->value
;
10030 c_parser_consume_token (parser
);
10031 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
10032 list
= chainon (list
, keyworddecl
);
10033 tsel
= c_parser_objc_selector (parser
);
10034 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10038 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
10040 /* Parse the optional parameter list. Optional Objective-C
10041 method parameters follow the C syntax, and may include '...'
10042 to denote a variable number of arguments. */
10043 parms
= make_node (TREE_LIST
);
10044 while (c_parser_next_token_is (parser
, CPP_COMMA
))
10046 struct c_parm
*parm
;
10047 c_parser_consume_token (parser
);
10048 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
10051 c_parser_consume_token (parser
);
10052 attr_err
|= c_parser_objc_maybe_method_attributes
10053 (parser
, attributes
) ;
10056 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
10059 parms
= chainon (parms
,
10060 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
10065 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
10069 c_parser_error (parser
, "objective-c method declaration is expected");
10070 return error_mark_node
;
10074 return error_mark_node
;
10076 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
10079 /* Parse an objc-type-name.
10082 objc-type-qualifiers[opt] type-name
10083 objc-type-qualifiers[opt]
10085 objc-type-qualifiers:
10086 objc-type-qualifier
10087 objc-type-qualifiers objc-type-qualifier
10089 objc-type-qualifier: one of
10090 in out inout bycopy byref oneway
10094 c_parser_objc_type_name (c_parser
*parser
)
10096 tree quals
= NULL_TREE
;
10097 struct c_type_name
*type_name
= NULL
;
10098 tree type
= NULL_TREE
;
10101 c_token
*token
= c_parser_peek_token (parser
);
10102 if (token
->type
== CPP_KEYWORD
10103 && (token
->keyword
== RID_IN
10104 || token
->keyword
== RID_OUT
10105 || token
->keyword
== RID_INOUT
10106 || token
->keyword
== RID_BYCOPY
10107 || token
->keyword
== RID_BYREF
10108 || token
->keyword
== RID_ONEWAY
))
10110 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
10111 c_parser_consume_token (parser
);
10116 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
10117 type_name
= c_parser_type_name (parser
);
10119 type
= groktypename (type_name
, NULL
, NULL
);
10121 /* If the type is unknown, and error has already been produced and
10122 we need to recover from the error. In that case, use NULL_TREE
10123 for the type, as if no type had been specified; this will use the
10124 default type ('id') which is good for error recovery. */
10125 if (type
== error_mark_node
)
10128 return build_tree_list (quals
, type
);
10131 /* Parse objc-protocol-refs.
10133 objc-protocol-refs:
10134 < identifier-list >
10138 c_parser_objc_protocol_refs (c_parser
*parser
)
10140 tree list
= NULL_TREE
;
10141 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
10142 c_parser_consume_token (parser
);
10143 /* Any identifiers, including those declared as type names, are OK
10148 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10150 c_parser_error (parser
, "expected identifier");
10153 id
= c_parser_peek_token (parser
)->value
;
10154 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
10155 c_parser_consume_token (parser
);
10156 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10157 c_parser_consume_token (parser
);
10161 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
10165 /* Parse an objc-try-catch-finally-statement.
10167 objc-try-catch-finally-statement:
10168 @try compound-statement objc-catch-list[opt]
10169 @try compound-statement objc-catch-list[opt] @finally compound-statement
10172 @catch ( objc-catch-parameter-declaration ) compound-statement
10173 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
10175 objc-catch-parameter-declaration:
10176 parameter-declaration
10179 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
10181 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
10182 for C++. Keep them in sync. */
10185 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
10187 location_t location
;
10190 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
10191 c_parser_consume_token (parser
);
10192 location
= c_parser_peek_token (parser
)->location
;
10193 objc_maybe_warn_exceptions (location
);
10194 stmt
= c_parser_compound_statement (parser
);
10195 objc_begin_try_stmt (location
, stmt
);
10197 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
10199 struct c_parm
*parm
;
10200 tree parameter_declaration
= error_mark_node
;
10201 bool seen_open_paren
= false;
10203 c_parser_consume_token (parser
);
10204 matching_parens parens
;
10205 if (!parens
.require_open (parser
))
10206 seen_open_paren
= true;
10207 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
10209 /* We have "@catch (...)" (where the '...' are literally
10210 what is in the code). Skip the '...'.
10211 parameter_declaration is set to NULL_TREE, and
10212 objc_being_catch_clauses() knows that that means
10214 c_parser_consume_token (parser
);
10215 parameter_declaration
= NULL_TREE
;
10219 /* We have "@catch (NSException *exception)" or something
10220 like that. Parse the parameter declaration. */
10221 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
10223 parameter_declaration
= error_mark_node
;
10225 parameter_declaration
= grokparm (parm
, NULL
);
10227 if (seen_open_paren
)
10228 parens
.require_close (parser
);
10231 /* If there was no open parenthesis, we are recovering from
10232 an error, and we are trying to figure out what mistake
10233 the user has made. */
10235 /* If there is an immediate closing parenthesis, the user
10236 probably forgot the opening one (ie, they typed "@catch
10237 NSException *e)". Parse the closing parenthesis and keep
10239 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
10240 c_parser_consume_token (parser
);
10242 /* If these is no immediate closing parenthesis, the user
10243 probably doesn't know that parenthesis are required at
10244 all (ie, they typed "@catch NSException *e"). So, just
10245 forget about the closing parenthesis and keep going. */
10247 objc_begin_catch_clause (parameter_declaration
);
10248 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
10249 c_parser_compound_statement_nostart (parser
);
10250 objc_finish_catch_clause ();
10252 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
10254 c_parser_consume_token (parser
);
10255 location
= c_parser_peek_token (parser
)->location
;
10256 stmt
= c_parser_compound_statement (parser
);
10257 objc_build_finally_clause (location
, stmt
);
10259 objc_finish_try_stmt ();
10262 /* Parse an objc-synchronized-statement.
10264 objc-synchronized-statement:
10265 @synchronized ( expression ) compound-statement
10269 c_parser_objc_synchronized_statement (c_parser
*parser
)
10273 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
10274 c_parser_consume_token (parser
);
10275 loc
= c_parser_peek_token (parser
)->location
;
10276 objc_maybe_warn_exceptions (loc
);
10277 matching_parens parens
;
10278 if (parens
.require_open (parser
))
10280 struct c_expr ce
= c_parser_expression (parser
);
10281 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
10283 expr
= c_fully_fold (expr
, false, NULL
);
10284 parens
.skip_until_found_close (parser
);
10287 expr
= error_mark_node
;
10288 stmt
= c_parser_compound_statement (parser
);
10289 objc_build_synchronized (loc
, expr
, stmt
);
10292 /* Parse an objc-selector; return NULL_TREE without an error if the
10293 next token is not an objc-selector.
10298 enum struct union if else while do for switch case default
10299 break continue return goto asm sizeof typeof __alignof
10300 unsigned long const short volatile signed restrict _Complex
10301 in out inout bycopy byref oneway int char float double void _Bool
10304 ??? Why this selection of keywords but not, for example, storage
10305 class specifiers? */
10308 c_parser_objc_selector (c_parser
*parser
)
10310 c_token
*token
= c_parser_peek_token (parser
);
10311 tree value
= token
->value
;
10312 if (token
->type
== CPP_NAME
)
10314 c_parser_consume_token (parser
);
10317 if (token
->type
!= CPP_KEYWORD
)
10319 switch (token
->keyword
)
10358 CASE_RID_FLOATN_NX
:
10362 case RID_AUTO_TYPE
:
10367 c_parser_consume_token (parser
);
10374 /* Parse an objc-selector-arg.
10378 objc-keywordname-list
10380 objc-keywordname-list:
10382 objc-keywordname-list objc-keywordname
10390 c_parser_objc_selector_arg (c_parser
*parser
)
10392 tree sel
= c_parser_objc_selector (parser
);
10393 tree list
= NULL_TREE
;
10394 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10398 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10400 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
10401 sel
= c_parser_objc_selector (parser
);
10402 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10408 /* Parse an objc-receiver.
10417 c_parser_objc_receiver (c_parser
*parser
)
10419 location_t loc
= c_parser_peek_token (parser
)->location
;
10421 if (c_parser_peek_token (parser
)->type
== CPP_NAME
10422 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
10423 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
10425 tree id
= c_parser_peek_token (parser
)->value
;
10426 c_parser_consume_token (parser
);
10427 return objc_get_class_reference (id
);
10429 struct c_expr ce
= c_parser_expression (parser
);
10430 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
10431 return c_fully_fold (ce
.value
, false, NULL
);
10434 /* Parse objc-message-args.
10438 objc-keywordarg-list
10440 objc-keywordarg-list:
10442 objc-keywordarg-list objc-keywordarg
10445 objc-selector : objc-keywordexpr
10450 c_parser_objc_message_args (c_parser
*parser
)
10452 tree sel
= c_parser_objc_selector (parser
);
10453 tree list
= NULL_TREE
;
10454 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10459 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10460 return error_mark_node
;
10461 keywordexpr
= c_parser_objc_keywordexpr (parser
);
10462 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
10463 sel
= c_parser_objc_selector (parser
);
10464 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10470 /* Parse an objc-keywordexpr.
10477 c_parser_objc_keywordexpr (c_parser
*parser
)
10480 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
10481 NULL
, NULL
, NULL
, NULL
);
10482 if (vec_safe_length (expr_list
) == 1)
10484 /* Just return the expression, remove a level of
10486 ret
= (*expr_list
)[0];
10490 /* We have a comma expression, we will collapse later. */
10491 ret
= build_tree_list_vec (expr_list
);
10493 release_tree_vector (expr_list
);
10497 /* A check, needed in several places, that ObjC interface, implementation or
10498 method definitions are not prefixed by incorrect items. */
10500 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
10501 struct c_declspecs
*specs
)
10503 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
10504 || specs
->typespec_kind
!= ctsk_none
)
10506 c_parser_error (parser
,
10507 "no type or storage class may be specified here,");
10508 c_parser_skip_to_end_of_block_or_statement (parser
);
10514 /* Parse an Objective-C @property declaration. The syntax is:
10516 objc-property-declaration:
10517 '@property' objc-property-attributes[opt] struct-declaration ;
10519 objc-property-attributes:
10520 '(' objc-property-attribute-list ')'
10522 objc-property-attribute-list:
10523 objc-property-attribute
10524 objc-property-attribute-list, objc-property-attribute
10526 objc-property-attribute
10527 'getter' = identifier
10528 'setter' = identifier
10537 @property NSString *name;
10538 @property (readonly) id object;
10539 @property (retain, nonatomic, getter=getTheName) id name;
10540 @property int a, b, c;
10542 PS: This function is identical to cp_parser_objc_at_propery_declaration
10543 for C++. Keep them in sync. */
10545 c_parser_objc_at_property_declaration (c_parser
*parser
)
10547 /* The following variables hold the attributes of the properties as
10548 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
10549 seen. When we see an attribute, we set them to 'true' (if they
10550 are boolean properties) or to the identifier (if they have an
10551 argument, ie, for getter and setter). Note that here we only
10552 parse the list of attributes, check the syntax and accumulate the
10553 attributes that we find. objc_add_property_declaration() will
10554 then process the information. */
10555 bool property_assign
= false;
10556 bool property_copy
= false;
10557 tree property_getter_ident
= NULL_TREE
;
10558 bool property_nonatomic
= false;
10559 bool property_readonly
= false;
10560 bool property_readwrite
= false;
10561 bool property_retain
= false;
10562 tree property_setter_ident
= NULL_TREE
;
10564 /* 'properties' is the list of properties that we read. Usually a
10565 single one, but maybe more (eg, in "@property int a, b, c;" there
10570 loc
= c_parser_peek_token (parser
)->location
;
10571 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
10573 c_parser_consume_token (parser
); /* Eat '@property'. */
10575 /* Parse the optional attribute list... */
10576 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10578 matching_parens parens
;
10581 parens
.consume_open (parser
);
10583 /* Property attribute keywords are valid now. */
10584 parser
->objc_property_attr_context
= true;
10588 bool syntax_error
= false;
10589 c_token
*token
= c_parser_peek_token (parser
);
10592 if (token
->type
!= CPP_KEYWORD
)
10594 if (token
->type
== CPP_CLOSE_PAREN
)
10595 c_parser_error (parser
, "expected identifier");
10598 c_parser_consume_token (parser
);
10599 c_parser_error (parser
, "unknown property attribute");
10603 keyword
= token
->keyword
;
10604 c_parser_consume_token (parser
);
10607 case RID_ASSIGN
: property_assign
= true; break;
10608 case RID_COPY
: property_copy
= true; break;
10609 case RID_NONATOMIC
: property_nonatomic
= true; break;
10610 case RID_READONLY
: property_readonly
= true; break;
10611 case RID_READWRITE
: property_readwrite
= true; break;
10612 case RID_RETAIN
: property_retain
= true; break;
10616 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
10618 if (keyword
== RID_GETTER
)
10619 c_parser_error (parser
,
10620 "missing %<=%> (after %<getter%> attribute)");
10622 c_parser_error (parser
,
10623 "missing %<=%> (after %<setter%> attribute)");
10624 syntax_error
= true;
10627 c_parser_consume_token (parser
); /* eat the = */
10628 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10630 c_parser_error (parser
, "expected identifier");
10631 syntax_error
= true;
10634 if (keyword
== RID_SETTER
)
10636 if (property_setter_ident
!= NULL_TREE
)
10637 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
10639 property_setter_ident
= c_parser_peek_token (parser
)->value
;
10640 c_parser_consume_token (parser
);
10641 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
10642 c_parser_error (parser
, "setter name must terminate with %<:%>");
10644 c_parser_consume_token (parser
);
10648 if (property_getter_ident
!= NULL_TREE
)
10649 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
10651 property_getter_ident
= c_parser_peek_token (parser
)->value
;
10652 c_parser_consume_token (parser
);
10656 c_parser_error (parser
, "unknown property attribute");
10657 syntax_error
= true;
10664 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10665 c_parser_consume_token (parser
);
10669 parser
->objc_property_attr_context
= false;
10670 parens
.skip_until_found_close (parser
);
10672 /* ... and the property declaration(s). */
10673 properties
= c_parser_struct_declaration (parser
);
10675 if (properties
== error_mark_node
)
10677 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10678 parser
->error
= false;
10682 if (properties
== NULL_TREE
)
10683 c_parser_error (parser
, "expected identifier");
10686 /* Comma-separated properties are chained together in
10687 reverse order; add them one by one. */
10688 properties
= nreverse (properties
);
10690 for (; properties
; properties
= TREE_CHAIN (properties
))
10691 objc_add_property_declaration (loc
, copy_node (properties
),
10692 property_readonly
, property_readwrite
,
10693 property_assign
, property_retain
,
10694 property_copy
, property_nonatomic
,
10695 property_getter_ident
, property_setter_ident
);
10698 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10699 parser
->error
= false;
10702 /* Parse an Objective-C @synthesize declaration. The syntax is:
10704 objc-synthesize-declaration:
10705 @synthesize objc-synthesize-identifier-list ;
10707 objc-synthesize-identifier-list:
10708 objc-synthesize-identifier
10709 objc-synthesize-identifier-list, objc-synthesize-identifier
10711 objc-synthesize-identifier
10713 identifier = identifier
10716 @synthesize MyProperty;
10717 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
10719 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
10720 for C++. Keep them in sync.
10723 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
10725 tree list
= NULL_TREE
;
10727 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
10728 loc
= c_parser_peek_token (parser
)->location
;
10730 c_parser_consume_token (parser
);
10733 tree property
, ivar
;
10734 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10736 c_parser_error (parser
, "expected identifier");
10737 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10738 /* Once we find the semicolon, we can resume normal parsing.
10739 We have to reset parser->error manually because
10740 c_parser_skip_until_found() won't reset it for us if the
10741 next token is precisely a semicolon. */
10742 parser
->error
= false;
10745 property
= c_parser_peek_token (parser
)->value
;
10746 c_parser_consume_token (parser
);
10747 if (c_parser_next_token_is (parser
, CPP_EQ
))
10749 c_parser_consume_token (parser
);
10750 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10752 c_parser_error (parser
, "expected identifier");
10753 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10754 parser
->error
= false;
10757 ivar
= c_parser_peek_token (parser
)->value
;
10758 c_parser_consume_token (parser
);
10762 list
= chainon (list
, build_tree_list (ivar
, property
));
10763 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10764 c_parser_consume_token (parser
);
10768 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10769 objc_add_synthesize_declaration (loc
, list
);
10772 /* Parse an Objective-C @dynamic declaration. The syntax is:
10774 objc-dynamic-declaration:
10775 @dynamic identifier-list ;
10778 @dynamic MyProperty;
10779 @dynamic MyProperty, AnotherProperty;
10781 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
10782 for C++. Keep them in sync.
10785 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
10787 tree list
= NULL_TREE
;
10789 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
10790 loc
= c_parser_peek_token (parser
)->location
;
10792 c_parser_consume_token (parser
);
10796 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10798 c_parser_error (parser
, "expected identifier");
10799 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10800 parser
->error
= false;
10803 property
= c_parser_peek_token (parser
)->value
;
10804 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
10805 c_parser_consume_token (parser
);
10806 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10807 c_parser_consume_token (parser
);
10811 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10812 objc_add_dynamic_declaration (loc
, list
);
10816 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
10817 should be considered, statements. ALLOW_STMT is true if we're within
10818 the context of a function and such pragmas are to be allowed. Returns
10819 true if we actually parsed such a pragma. */
10822 c_parser_pragma (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
10825 const char *construct
= NULL
;
10827 id
= c_parser_peek_token (parser
)->pragma_kind
;
10828 gcc_assert (id
!= PRAGMA_NONE
);
10832 case PRAGMA_OACC_DECLARE
:
10833 c_parser_oacc_declare (parser
);
10836 case PRAGMA_OACC_ENTER_DATA
:
10837 if (context
!= pragma_compound
)
10839 construct
= "acc enter data";
10841 if (context
== pragma_stmt
)
10843 error_at (c_parser_peek_token (parser
)->location
,
10844 "%<#pragma %s%> may only be used in compound "
10845 "statements", construct
);
10846 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10851 c_parser_oacc_enter_exit_data (parser
, true);
10854 case PRAGMA_OACC_EXIT_DATA
:
10855 if (context
!= pragma_compound
)
10857 construct
= "acc exit data";
10860 c_parser_oacc_enter_exit_data (parser
, false);
10863 case PRAGMA_OACC_ROUTINE
:
10864 if (context
!= pragma_external
)
10866 error_at (c_parser_peek_token (parser
)->location
,
10867 "%<#pragma acc routine%> must be at file scope");
10868 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10871 c_parser_oacc_routine (parser
, context
);
10874 case PRAGMA_OACC_UPDATE
:
10875 if (context
!= pragma_compound
)
10877 construct
= "acc update";
10880 c_parser_oacc_update (parser
);
10883 case PRAGMA_OMP_BARRIER
:
10884 if (context
!= pragma_compound
)
10886 construct
= "omp barrier";
10889 c_parser_omp_barrier (parser
);
10892 case PRAGMA_OMP_FLUSH
:
10893 if (context
!= pragma_compound
)
10895 construct
= "omp flush";
10898 c_parser_omp_flush (parser
);
10901 case PRAGMA_OMP_TASKWAIT
:
10902 if (context
!= pragma_compound
)
10904 construct
= "omp taskwait";
10907 c_parser_omp_taskwait (parser
);
10910 case PRAGMA_OMP_TASKYIELD
:
10911 if (context
!= pragma_compound
)
10913 construct
= "omp taskyield";
10916 c_parser_omp_taskyield (parser
);
10919 case PRAGMA_OMP_CANCEL
:
10920 if (context
!= pragma_compound
)
10922 construct
= "omp cancel";
10925 c_parser_omp_cancel (parser
);
10928 case PRAGMA_OMP_CANCELLATION_POINT
:
10929 c_parser_omp_cancellation_point (parser
, context
);
10932 case PRAGMA_OMP_THREADPRIVATE
:
10933 c_parser_omp_threadprivate (parser
);
10936 case PRAGMA_OMP_TARGET
:
10937 return c_parser_omp_target (parser
, context
, if_p
);
10939 case PRAGMA_OMP_END_DECLARE_TARGET
:
10940 c_parser_omp_end_declare_target (parser
);
10943 case PRAGMA_OMP_SECTION
:
10944 error_at (c_parser_peek_token (parser
)->location
,
10945 "%<#pragma omp section%> may only be used in "
10946 "%<#pragma omp sections%> construct");
10947 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10950 case PRAGMA_OMP_DECLARE
:
10951 c_parser_omp_declare (parser
, context
);
10954 case PRAGMA_OMP_ORDERED
:
10955 return c_parser_omp_ordered (parser
, context
, if_p
);
10958 c_parser_consume_pragma (parser
);
10959 c_parser_skip_to_pragma_eol (parser
);
10960 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
10961 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
10962 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
10964 c_parser_error (parser
, "for, while or do statement expected");
10967 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10968 c_parser_for_statement (parser
, true, if_p
);
10969 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
10970 c_parser_while_statement (parser
, true, if_p
);
10972 c_parser_do_statement (parser
, true);
10975 case PRAGMA_GCC_PCH_PREPROCESS
:
10976 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
10977 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10980 case PRAGMA_OACC_WAIT
:
10981 if (context
!= pragma_compound
)
10983 construct
= "acc wait";
10986 /* FALL THROUGH. */
10989 if (id
< PRAGMA_FIRST_EXTERNAL
)
10991 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
10994 c_parser_error (parser
, "expected declaration specifiers");
10995 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10998 c_parser_omp_construct (parser
, if_p
);
11004 c_parser_consume_pragma (parser
);
11005 c_invoke_pragma_handler (id
);
11007 /* Skip to EOL, but suppress any error message. Those will have been
11008 generated by the handler routine through calling error, as opposed
11009 to calling c_parser_error. */
11010 parser
->error
= true;
11011 c_parser_skip_to_pragma_eol (parser
);
11016 /* The interface the pragma parsers have to the lexer. */
11019 pragma_lex (tree
*value
, location_t
*loc
)
11021 c_token
*tok
= c_parser_peek_token (the_parser
);
11022 enum cpp_ttype ret
= tok
->type
;
11024 *value
= tok
->value
;
11026 *loc
= tok
->location
;
11028 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
11032 if (ret
== CPP_KEYWORD
)
11034 c_parser_consume_token (the_parser
);
11041 c_parser_pragma_pch_preprocess (c_parser
*parser
)
11045 c_parser_consume_pragma (parser
);
11046 if (c_parser_next_token_is (parser
, CPP_STRING
))
11048 name
= c_parser_peek_token (parser
)->value
;
11049 c_parser_consume_token (parser
);
11052 c_parser_error (parser
, "expected string literal");
11053 c_parser_skip_to_pragma_eol (parser
);
11056 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
11059 /* OpenACC and OpenMP parsing routines. */
11061 /* Returns name of the next clause.
11062 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
11063 the token is not consumed. Otherwise appropriate pragma_omp_clause is
11064 returned and the token is consumed. */
11066 static pragma_omp_clause
11067 c_parser_omp_clause_name (c_parser
*parser
)
11069 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
11071 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
11072 result
= PRAGMA_OACC_CLAUSE_AUTO
;
11073 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
11074 result
= PRAGMA_OMP_CLAUSE_IF
;
11075 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
11076 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
11077 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11078 result
= PRAGMA_OMP_CLAUSE_FOR
;
11079 else if (c_parser_next_token_is (parser
, CPP_NAME
))
11081 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11086 if (!strcmp ("aligned", p
))
11087 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
11088 else if (!strcmp ("async", p
))
11089 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
11092 if (!strcmp ("collapse", p
))
11093 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
11094 else if (!strcmp ("copy", p
))
11095 result
= PRAGMA_OACC_CLAUSE_COPY
;
11096 else if (!strcmp ("copyin", p
))
11097 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
11098 else if (!strcmp ("copyout", p
))
11099 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
11100 else if (!strcmp ("copyprivate", p
))
11101 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
11102 else if (!strcmp ("create", p
))
11103 result
= PRAGMA_OACC_CLAUSE_CREATE
;
11106 if (!strcmp ("defaultmap", p
))
11107 result
= PRAGMA_OMP_CLAUSE_DEFAULTMAP
;
11108 else if (!strcmp ("delete", p
))
11109 result
= PRAGMA_OACC_CLAUSE_DELETE
;
11110 else if (!strcmp ("depend", p
))
11111 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
11112 else if (!strcmp ("device", p
))
11113 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
11114 else if (!strcmp ("deviceptr", p
))
11115 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
11116 else if (!strcmp ("device_resident", p
))
11117 result
= PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
;
11118 else if (!strcmp ("dist_schedule", p
))
11119 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
11122 if (!strcmp ("final", p
))
11123 result
= PRAGMA_OMP_CLAUSE_FINAL
;
11124 else if (!strcmp ("firstprivate", p
))
11125 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
11126 else if (!strcmp ("from", p
))
11127 result
= PRAGMA_OMP_CLAUSE_FROM
;
11130 if (!strcmp ("gang", p
))
11131 result
= PRAGMA_OACC_CLAUSE_GANG
;
11132 else if (!strcmp ("grainsize", p
))
11133 result
= PRAGMA_OMP_CLAUSE_GRAINSIZE
;
11136 if (!strcmp ("hint", p
))
11137 result
= PRAGMA_OMP_CLAUSE_HINT
;
11138 else if (!strcmp ("host", p
))
11139 result
= PRAGMA_OACC_CLAUSE_HOST
;
11142 if (!strcmp ("inbranch", p
))
11143 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
11144 else if (!strcmp ("independent", p
))
11145 result
= PRAGMA_OACC_CLAUSE_INDEPENDENT
;
11146 else if (!strcmp ("is_device_ptr", p
))
11147 result
= PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
;
11150 if (!strcmp ("lastprivate", p
))
11151 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
11152 else if (!strcmp ("linear", p
))
11153 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
11154 else if (!strcmp ("link", p
))
11155 result
= PRAGMA_OMP_CLAUSE_LINK
;
11158 if (!strcmp ("map", p
))
11159 result
= PRAGMA_OMP_CLAUSE_MAP
;
11160 else if (!strcmp ("mergeable", p
))
11161 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
11164 if (!strcmp ("nogroup", p
))
11165 result
= PRAGMA_OMP_CLAUSE_NOGROUP
;
11166 else if (!strcmp ("notinbranch", p
))
11167 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
11168 else if (!strcmp ("nowait", p
))
11169 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
11170 else if (!strcmp ("num_gangs", p
))
11171 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
11172 else if (!strcmp ("num_tasks", p
))
11173 result
= PRAGMA_OMP_CLAUSE_NUM_TASKS
;
11174 else if (!strcmp ("num_teams", p
))
11175 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
11176 else if (!strcmp ("num_threads", p
))
11177 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
11178 else if (!strcmp ("num_workers", p
))
11179 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
11182 if (!strcmp ("ordered", p
))
11183 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
11186 if (!strcmp ("parallel", p
))
11187 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
11188 else if (!strcmp ("present", p
))
11189 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
11190 else if (!strcmp ("present_or_copy", p
)
11191 || !strcmp ("pcopy", p
))
11192 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
;
11193 else if (!strcmp ("present_or_copyin", p
)
11194 || !strcmp ("pcopyin", p
))
11195 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
;
11196 else if (!strcmp ("present_or_copyout", p
)
11197 || !strcmp ("pcopyout", p
))
11198 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
;
11199 else if (!strcmp ("present_or_create", p
)
11200 || !strcmp ("pcreate", p
))
11201 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
;
11202 else if (!strcmp ("priority", p
))
11203 result
= PRAGMA_OMP_CLAUSE_PRIORITY
;
11204 else if (!strcmp ("private", p
))
11205 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
11206 else if (!strcmp ("proc_bind", p
))
11207 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
11210 if (!strcmp ("reduction", p
))
11211 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
11214 if (!strcmp ("safelen", p
))
11215 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
11216 else if (!strcmp ("schedule", p
))
11217 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
11218 else if (!strcmp ("sections", p
))
11219 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
11220 else if (!strcmp ("seq", p
))
11221 result
= PRAGMA_OACC_CLAUSE_SEQ
;
11222 else if (!strcmp ("shared", p
))
11223 result
= PRAGMA_OMP_CLAUSE_SHARED
;
11224 else if (!strcmp ("simd", p
))
11225 result
= PRAGMA_OMP_CLAUSE_SIMD
;
11226 else if (!strcmp ("simdlen", p
))
11227 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
11228 else if (!strcmp ("self", p
))
11229 result
= PRAGMA_OACC_CLAUSE_SELF
;
11232 if (!strcmp ("taskgroup", p
))
11233 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
11234 else if (!strcmp ("thread_limit", p
))
11235 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
11236 else if (!strcmp ("threads", p
))
11237 result
= PRAGMA_OMP_CLAUSE_THREADS
;
11238 else if (!strcmp ("tile", p
))
11239 result
= PRAGMA_OACC_CLAUSE_TILE
;
11240 else if (!strcmp ("to", p
))
11241 result
= PRAGMA_OMP_CLAUSE_TO
;
11244 if (!strcmp ("uniform", p
))
11245 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
11246 else if (!strcmp ("untied", p
))
11247 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
11248 else if (!strcmp ("use_device", p
))
11249 result
= PRAGMA_OACC_CLAUSE_USE_DEVICE
;
11250 else if (!strcmp ("use_device_ptr", p
))
11251 result
= PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
;
11254 if (!strcmp ("vector", p
))
11255 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
11256 else if (!strcmp ("vector_length", p
))
11257 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
11260 if (!strcmp ("wait", p
))
11261 result
= PRAGMA_OACC_CLAUSE_WAIT
;
11262 else if (!strcmp ("worker", p
))
11263 result
= PRAGMA_OACC_CLAUSE_WORKER
;
11268 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
11269 c_parser_consume_token (parser
);
11274 /* Validate that a clause of the given type does not already exist. */
11277 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
11282 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11283 if (OMP_CLAUSE_CODE (c
) == code
)
11285 location_t loc
= OMP_CLAUSE_LOCATION (c
);
11286 error_at (loc
, "too many %qs clauses", name
);
11292 Parse wait clause or wait directive parameters. */
11295 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
11297 vec
<tree
, va_gc
> *args
;
11300 matching_parens parens
;
11301 if (!parens
.require_open (parser
))
11304 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
11306 if (args
->length () == 0)
11308 c_parser_error (parser
, "expected integer expression before ')'");
11309 release_tree_vector (args
);
11313 args_tree
= build_tree_list_vec (args
);
11315 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
11317 tree targ
= TREE_VALUE (t
);
11319 if (targ
!= error_mark_node
)
11321 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
11323 c_parser_error (parser
, "expression must be integral");
11324 targ
= error_mark_node
;
11328 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
11330 OMP_CLAUSE_DECL (c
) = targ
;
11331 OMP_CLAUSE_CHAIN (c
) = list
;
11337 release_tree_vector (args
);
11338 parens
.require_close (parser
);
11342 /* OpenACC 2.0, OpenMP 2.5:
11345 variable-list , identifier
11347 If KIND is nonzero, create the appropriate node and install the
11348 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
11349 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
11351 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
11352 return the list created. */
11355 c_parser_omp_variable_list (c_parser
*parser
,
11356 location_t clause_loc
,
11357 enum omp_clause_code kind
, tree list
)
11359 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
11360 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
11361 c_parser_error (parser
, "expected identifier");
11363 while (c_parser_next_token_is (parser
, CPP_NAME
)
11364 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
11366 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
11368 if (t
== NULL_TREE
)
11370 undeclared_variable (c_parser_peek_token (parser
)->location
,
11371 c_parser_peek_token (parser
)->value
);
11372 t
= error_mark_node
;
11375 c_parser_consume_token (parser
);
11377 if (t
== error_mark_node
)
11379 else if (kind
!= 0)
11383 case OMP_CLAUSE__CACHE_
:
11384 /* The OpenACC cache directive explicitly only allows "array
11385 elements or subarrays". */
11386 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
11388 c_parser_error (parser
, "expected %<[%>");
11389 t
= error_mark_node
;
11393 case OMP_CLAUSE_MAP
:
11394 case OMP_CLAUSE_FROM
:
11395 case OMP_CLAUSE_TO
:
11396 while (c_parser_next_token_is (parser
, CPP_DOT
))
11398 location_t op_loc
= c_parser_peek_token (parser
)->location
;
11399 c_parser_consume_token (parser
);
11400 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11402 c_parser_error (parser
, "expected identifier");
11403 t
= error_mark_node
;
11407 c_token
*comp_tok
= c_parser_peek_token (parser
);
11408 tree ident
= comp_tok
->value
;
11409 location_t comp_loc
= comp_tok
->location
;
11410 c_parser_consume_token (parser
);
11411 t
= build_component_ref (op_loc
, t
, ident
, comp_loc
);
11414 case OMP_CLAUSE_DEPEND
:
11415 case OMP_CLAUSE_REDUCTION
:
11416 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
11418 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
11420 c_parser_consume_token (parser
);
11421 if (!c_parser_next_token_is (parser
, CPP_COLON
))
11423 location_t expr_loc
11424 = c_parser_peek_token (parser
)->location
;
11425 c_expr expr
= c_parser_expression (parser
);
11426 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
11428 low_bound
= expr
.value
;
11430 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
11431 length
= integer_one_node
;
11434 /* Look for `:'. */
11435 if (!c_parser_require (parser
, CPP_COLON
,
11438 t
= error_mark_node
;
11441 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
11443 location_t expr_loc
11444 = c_parser_peek_token (parser
)->location
;
11445 c_expr expr
= c_parser_expression (parser
);
11446 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
11448 length
= expr
.value
;
11451 /* Look for the closing `]'. */
11452 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
11455 t
= error_mark_node
;
11459 t
= tree_cons (low_bound
, length
, t
);
11466 if (t
!= error_mark_node
)
11468 tree u
= build_omp_clause (clause_loc
, kind
);
11469 OMP_CLAUSE_DECL (u
) = t
;
11470 OMP_CLAUSE_CHAIN (u
) = list
;
11475 list
= tree_cons (t
, NULL_TREE
, list
);
11477 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
11480 c_parser_consume_token (parser
);
11486 /* Similarly, but expect leading and trailing parenthesis. This is a very
11487 common case for OpenACC and OpenMP clauses. */
11490 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
11493 /* The clauses location. */
11494 location_t loc
= c_parser_peek_token (parser
)->location
;
11496 matching_parens parens
;
11497 if (parens
.require_open (parser
))
11499 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
11500 parens
.skip_until_found_close (parser
);
11506 copy ( variable-list )
11507 copyin ( variable-list )
11508 copyout ( variable-list )
11509 create ( variable-list )
11510 delete ( variable-list )
11511 present ( variable-list )
11512 present_or_copy ( variable-list )
11513 pcopy ( variable-list )
11514 present_or_copyin ( variable-list )
11515 pcopyin ( variable-list )
11516 present_or_copyout ( variable-list )
11517 pcopyout ( variable-list )
11518 present_or_create ( variable-list )
11519 pcreate ( variable-list ) */
11522 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
11525 enum gomp_map_kind kind
;
11528 case PRAGMA_OACC_CLAUSE_COPY
:
11529 kind
= GOMP_MAP_FORCE_TOFROM
;
11531 case PRAGMA_OACC_CLAUSE_COPYIN
:
11532 kind
= GOMP_MAP_FORCE_TO
;
11534 case PRAGMA_OACC_CLAUSE_COPYOUT
:
11535 kind
= GOMP_MAP_FORCE_FROM
;
11537 case PRAGMA_OACC_CLAUSE_CREATE
:
11538 kind
= GOMP_MAP_FORCE_ALLOC
;
11540 case PRAGMA_OACC_CLAUSE_DELETE
:
11541 kind
= GOMP_MAP_DELETE
;
11543 case PRAGMA_OACC_CLAUSE_DEVICE
:
11544 kind
= GOMP_MAP_FORCE_TO
;
11546 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
11547 kind
= GOMP_MAP_DEVICE_RESIDENT
;
11549 case PRAGMA_OACC_CLAUSE_HOST
:
11550 case PRAGMA_OACC_CLAUSE_SELF
:
11551 kind
= GOMP_MAP_FORCE_FROM
;
11553 case PRAGMA_OACC_CLAUSE_LINK
:
11554 kind
= GOMP_MAP_LINK
;
11556 case PRAGMA_OACC_CLAUSE_PRESENT
:
11557 kind
= GOMP_MAP_FORCE_PRESENT
;
11559 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
11560 kind
= GOMP_MAP_TOFROM
;
11562 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
11563 kind
= GOMP_MAP_TO
;
11565 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
11566 kind
= GOMP_MAP_FROM
;
11568 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
11569 kind
= GOMP_MAP_ALLOC
;
11572 gcc_unreachable ();
11575 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
11577 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11578 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
11584 deviceptr ( variable-list ) */
11587 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
11589 location_t loc
= c_parser_peek_token (parser
)->location
;
11592 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
11593 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
11594 variable-list must only allow for pointer variables. */
11595 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11596 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
11598 tree v
= TREE_PURPOSE (t
);
11600 /* FIXME diagnostics: Ideally we should keep individual
11601 locations for all the variables in the var list to make the
11602 following errors more precise. Perhaps
11603 c_parser_omp_var_list_parens() should construct a list of
11604 locations to go along with the var list. */
11606 if (!VAR_P (v
) && TREE_CODE (v
) != PARM_DECL
)
11607 error_at (loc
, "%qD is not a variable", v
);
11608 else if (TREE_TYPE (v
) == error_mark_node
)
11610 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
11611 error_at (loc
, "%qD is not a pointer variable", v
);
11613 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
11614 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
11615 OMP_CLAUSE_DECL (u
) = v
;
11616 OMP_CLAUSE_CHAIN (u
) = list
;
11623 /* OpenACC 2.0, OpenMP 3.0:
11624 collapse ( constant-expression ) */
11627 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
11629 tree c
, num
= error_mark_node
;
11633 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
11634 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
11636 loc
= c_parser_peek_token (parser
)->location
;
11637 matching_parens parens
;
11638 if (parens
.require_open (parser
))
11640 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
11641 parens
.skip_until_found_close (parser
);
11643 if (num
== error_mark_node
)
11645 mark_exp_read (num
);
11646 num
= c_fully_fold (num
, false, NULL
);
11647 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
11648 || !tree_fits_shwi_p (num
)
11649 || (n
= tree_to_shwi (num
)) <= 0
11653 "collapse argument needs positive constant integer expression");
11656 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
11657 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
11658 OMP_CLAUSE_CHAIN (c
) = list
;
11663 copyin ( variable-list ) */
11666 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
11668 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
11672 copyprivate ( variable-list ) */
11675 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
11677 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
11681 default ( none | shared )
11684 default ( none | present ) */
11687 c_parser_omp_clause_default (c_parser
*parser
, tree list
, bool is_oacc
)
11689 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
11690 location_t loc
= c_parser_peek_token (parser
)->location
;
11693 matching_parens parens
;
11694 if (!parens
.require_open (parser
))
11696 if (c_parser_next_token_is (parser
, CPP_NAME
))
11698 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11703 if (strcmp ("none", p
) != 0)
11705 kind
= OMP_CLAUSE_DEFAULT_NONE
;
11709 if (strcmp ("present", p
) != 0 || !is_oacc
)
11711 kind
= OMP_CLAUSE_DEFAULT_PRESENT
;
11715 if (strcmp ("shared", p
) != 0 || is_oacc
)
11717 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
11724 c_parser_consume_token (parser
);
11730 c_parser_error (parser
, "expected %<none%> or %<present%>");
11732 c_parser_error (parser
, "expected %<none%> or %<shared%>");
11734 parens
.skip_until_found_close (parser
);
11736 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
11739 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
11740 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
11741 OMP_CLAUSE_CHAIN (c
) = list
;
11742 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
11748 firstprivate ( variable-list ) */
11751 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
11753 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
11757 final ( expression ) */
11760 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
11762 location_t loc
= c_parser_peek_token (parser
)->location
;
11763 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11765 tree t
= c_parser_paren_condition (parser
);
11768 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
11770 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
11771 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
11772 OMP_CLAUSE_CHAIN (c
) = list
;
11776 c_parser_error (parser
, "expected %<(%>");
11781 /* OpenACC, OpenMP 2.5:
11785 if ( directive-name-modifier : expression )
11787 directive-name-modifier:
11788 parallel | task | taskloop | target data | target | target update
11789 | target enter data | target exit data */
11792 c_parser_omp_clause_if (c_parser
*parser
, tree list
, bool is_omp
)
11794 location_t location
= c_parser_peek_token (parser
)->location
;
11795 enum tree_code if_modifier
= ERROR_MARK
;
11797 matching_parens parens
;
11798 if (!parens
.require_open (parser
))
11801 if (is_omp
&& c_parser_next_token_is (parser
, CPP_NAME
))
11803 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11805 if (strcmp (p
, "parallel") == 0)
11806 if_modifier
= OMP_PARALLEL
;
11807 else if (strcmp (p
, "task") == 0)
11808 if_modifier
= OMP_TASK
;
11809 else if (strcmp (p
, "taskloop") == 0)
11810 if_modifier
= OMP_TASKLOOP
;
11811 else if (strcmp (p
, "target") == 0)
11813 if_modifier
= OMP_TARGET
;
11814 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11816 p
= IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser
)->value
);
11817 if (strcmp ("data", p
) == 0)
11818 if_modifier
= OMP_TARGET_DATA
;
11819 else if (strcmp ("update", p
) == 0)
11820 if_modifier
= OMP_TARGET_UPDATE
;
11821 else if (strcmp ("enter", p
) == 0)
11822 if_modifier
= OMP_TARGET_ENTER_DATA
;
11823 else if (strcmp ("exit", p
) == 0)
11824 if_modifier
= OMP_TARGET_EXIT_DATA
;
11825 if (if_modifier
!= OMP_TARGET
)
11828 c_parser_consume_token (parser
);
11832 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
11833 error_at (loc
, "expected %<data%>, %<update%>, %<enter%> "
11835 if_modifier
= ERROR_MARK
;
11837 if (if_modifier
== OMP_TARGET_ENTER_DATA
11838 || if_modifier
== OMP_TARGET_EXIT_DATA
)
11840 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11842 p
= IDENTIFIER_POINTER
11843 (c_parser_peek_2nd_token (parser
)->value
);
11844 if (strcmp ("data", p
) == 0)
11848 c_parser_consume_token (parser
);
11852 = c_parser_peek_2nd_token (parser
)->location
;
11853 error_at (loc
, "expected %<data%>");
11854 if_modifier
= ERROR_MARK
;
11859 if (if_modifier
!= ERROR_MARK
)
11861 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11863 c_parser_consume_token (parser
);
11864 c_parser_consume_token (parser
);
11870 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
11871 error_at (loc
, "expected %<:%>");
11873 if_modifier
= ERROR_MARK
;
11878 tree t
= c_parser_condition (parser
), c
;
11879 parens
.skip_until_found_close (parser
);
11881 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11882 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IF
)
11884 if (if_modifier
!= ERROR_MARK
11885 && OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
11887 const char *p
= NULL
;
11888 switch (if_modifier
)
11890 case OMP_PARALLEL
: p
= "parallel"; break;
11891 case OMP_TASK
: p
= "task"; break;
11892 case OMP_TASKLOOP
: p
= "taskloop"; break;
11893 case OMP_TARGET_DATA
: p
= "target data"; break;
11894 case OMP_TARGET
: p
= "target"; break;
11895 case OMP_TARGET_UPDATE
: p
= "target update"; break;
11896 case OMP_TARGET_ENTER_DATA
: p
= "enter data"; break;
11897 case OMP_TARGET_EXIT_DATA
: p
= "exit data"; break;
11898 default: gcc_unreachable ();
11900 error_at (location
, "too many %<if%> clauses with %qs modifier",
11904 else if (OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
11907 error_at (location
, "too many %<if%> clauses");
11909 error_at (location
, "too many %<if%> clauses without modifier");
11912 else if (if_modifier
== ERROR_MARK
11913 || OMP_CLAUSE_IF_MODIFIER (c
) == ERROR_MARK
)
11915 error_at (location
, "if any %<if%> clause has modifier, then all "
11916 "%<if%> clauses have to use modifier");
11921 c
= build_omp_clause (location
, OMP_CLAUSE_IF
);
11922 OMP_CLAUSE_IF_MODIFIER (c
) = if_modifier
;
11923 OMP_CLAUSE_IF_EXPR (c
) = t
;
11924 OMP_CLAUSE_CHAIN (c
) = list
;
11929 lastprivate ( variable-list ) */
11932 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
11934 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
11941 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11945 /* FIXME: Should we allow duplicates? */
11946 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
11948 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
11949 OMP_CLAUSE_MERGEABLE
);
11950 OMP_CLAUSE_CHAIN (c
) = list
;
11959 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11962 location_t loc
= c_parser_peek_token (parser
)->location
;
11964 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
11966 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
11967 OMP_CLAUSE_CHAIN (c
) = list
;
11972 num_threads ( expression ) */
11975 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
11977 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
11978 matching_parens parens
;
11979 if (parens
.require_open (parser
))
11981 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11982 c_expr expr
= c_parser_expression (parser
);
11983 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11984 tree c
, t
= expr
.value
;
11985 t
= c_fully_fold (t
, false, NULL
);
11987 parens
.skip_until_found_close (parser
);
11989 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11991 c_parser_error (parser
, "expected integer expression");
11995 /* Attempt to statically determine when the number isn't positive. */
11996 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11997 build_int_cst (TREE_TYPE (t
), 0));
11998 protected_set_expr_location (c
, expr_loc
);
11999 if (c
== boolean_true_node
)
12001 warning_at (expr_loc
, 0,
12002 "%<num_threads%> value must be positive");
12003 t
= integer_one_node
;
12006 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
12008 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
12009 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
12010 OMP_CLAUSE_CHAIN (c
) = list
;
12018 num_tasks ( expression ) */
12021 c_parser_omp_clause_num_tasks (c_parser
*parser
, tree list
)
12023 location_t num_tasks_loc
= c_parser_peek_token (parser
)->location
;
12024 matching_parens parens
;
12025 if (parens
.require_open (parser
))
12027 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12028 c_expr expr
= c_parser_expression (parser
);
12029 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12030 tree c
, t
= expr
.value
;
12031 t
= c_fully_fold (t
, false, NULL
);
12033 parens
.skip_until_found_close (parser
);
12035 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12037 c_parser_error (parser
, "expected integer expression");
12041 /* Attempt to statically determine when the number isn't positive. */
12042 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12043 build_int_cst (TREE_TYPE (t
), 0));
12044 if (CAN_HAVE_LOCATION_P (c
))
12045 SET_EXPR_LOCATION (c
, expr_loc
);
12046 if (c
== boolean_true_node
)
12048 warning_at (expr_loc
, 0, "%<num_tasks%> value must be positive");
12049 t
= integer_one_node
;
12052 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TASKS
, "num_tasks");
12054 c
= build_omp_clause (num_tasks_loc
, OMP_CLAUSE_NUM_TASKS
);
12055 OMP_CLAUSE_NUM_TASKS_EXPR (c
) = t
;
12056 OMP_CLAUSE_CHAIN (c
) = list
;
12064 grainsize ( expression ) */
12067 c_parser_omp_clause_grainsize (c_parser
*parser
, tree list
)
12069 location_t grainsize_loc
= c_parser_peek_token (parser
)->location
;
12070 matching_parens parens
;
12071 if (parens
.require_open (parser
))
12073 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12074 c_expr expr
= c_parser_expression (parser
);
12075 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12076 tree c
, t
= expr
.value
;
12077 t
= c_fully_fold (t
, false, NULL
);
12079 parens
.skip_until_found_close (parser
);
12081 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12083 c_parser_error (parser
, "expected integer expression");
12087 /* Attempt to statically determine when the number isn't positive. */
12088 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12089 build_int_cst (TREE_TYPE (t
), 0));
12090 if (CAN_HAVE_LOCATION_P (c
))
12091 SET_EXPR_LOCATION (c
, expr_loc
);
12092 if (c
== boolean_true_node
)
12094 warning_at (expr_loc
, 0, "%<grainsize%> value must be positive");
12095 t
= integer_one_node
;
12098 check_no_duplicate_clause (list
, OMP_CLAUSE_GRAINSIZE
, "grainsize");
12100 c
= build_omp_clause (grainsize_loc
, OMP_CLAUSE_GRAINSIZE
);
12101 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
12102 OMP_CLAUSE_CHAIN (c
) = list
;
12110 priority ( expression ) */
12113 c_parser_omp_clause_priority (c_parser
*parser
, tree list
)
12115 location_t priority_loc
= c_parser_peek_token (parser
)->location
;
12116 matching_parens parens
;
12117 if (parens
.require_open (parser
))
12119 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12120 c_expr expr
= c_parser_expression (parser
);
12121 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12122 tree c
, t
= expr
.value
;
12123 t
= c_fully_fold (t
, false, NULL
);
12125 parens
.skip_until_found_close (parser
);
12127 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12129 c_parser_error (parser
, "expected integer expression");
12133 /* Attempt to statically determine when the number isn't
12135 c
= fold_build2_loc (expr_loc
, LT_EXPR
, boolean_type_node
, t
,
12136 build_int_cst (TREE_TYPE (t
), 0));
12137 if (CAN_HAVE_LOCATION_P (c
))
12138 SET_EXPR_LOCATION (c
, expr_loc
);
12139 if (c
== boolean_true_node
)
12141 warning_at (expr_loc
, 0, "%<priority%> value must be non-negative");
12142 t
= integer_one_node
;
12145 check_no_duplicate_clause (list
, OMP_CLAUSE_PRIORITY
, "priority");
12147 c
= build_omp_clause (priority_loc
, OMP_CLAUSE_PRIORITY
);
12148 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
12149 OMP_CLAUSE_CHAIN (c
) = list
;
12157 hint ( expression ) */
12160 c_parser_omp_clause_hint (c_parser
*parser
, tree list
)
12162 location_t hint_loc
= c_parser_peek_token (parser
)->location
;
12163 matching_parens parens
;
12164 if (parens
.require_open (parser
))
12166 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12167 c_expr expr
= c_parser_expression (parser
);
12168 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12169 tree c
, t
= expr
.value
;
12170 t
= c_fully_fold (t
, false, NULL
);
12172 parens
.skip_until_found_close (parser
);
12174 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12176 c_parser_error (parser
, "expected integer expression");
12180 check_no_duplicate_clause (list
, OMP_CLAUSE_HINT
, "hint");
12182 c
= build_omp_clause (hint_loc
, OMP_CLAUSE_HINT
);
12183 OMP_CLAUSE_HINT_EXPR (c
) = t
;
12184 OMP_CLAUSE_CHAIN (c
) = list
;
12192 defaultmap ( tofrom : scalar ) */
12195 c_parser_omp_clause_defaultmap (c_parser
*parser
, tree list
)
12197 location_t loc
= c_parser_peek_token (parser
)->location
;
12201 matching_parens parens
;
12202 if (!parens
.require_open (parser
))
12204 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12206 c_parser_error (parser
, "expected %<tofrom%>");
12209 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12210 if (strcmp (p
, "tofrom") != 0)
12212 c_parser_error (parser
, "expected %<tofrom%>");
12215 c_parser_consume_token (parser
);
12216 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12218 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12220 c_parser_error (parser
, "expected %<scalar%>");
12223 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12224 if (strcmp (p
, "scalar") != 0)
12226 c_parser_error (parser
, "expected %<scalar%>");
12229 c_parser_consume_token (parser
);
12230 parens
.skip_until_found_close (parser
);
12231 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULTMAP
, "defaultmap");
12232 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULTMAP
);
12233 OMP_CLAUSE_CHAIN (c
) = list
;
12237 parens
.skip_until_found_close (parser
);
12242 use_device ( variable-list )
12245 use_device_ptr ( variable-list ) */
12248 c_parser_omp_clause_use_device_ptr (c_parser
*parser
, tree list
)
12250 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_USE_DEVICE_PTR
,
12255 is_device_ptr ( variable-list ) */
12258 c_parser_omp_clause_is_device_ptr (c_parser
*parser
, tree list
)
12260 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_IS_DEVICE_PTR
, list
);
12264 num_gangs ( expression )
12265 num_workers ( expression )
12266 vector_length ( expression ) */
12269 c_parser_oacc_single_int_clause (c_parser
*parser
, omp_clause_code code
,
12272 location_t loc
= c_parser_peek_token (parser
)->location
;
12274 matching_parens parens
;
12275 if (!parens
.require_open (parser
))
12278 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12279 c_expr expr
= c_parser_expression (parser
);
12280 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12281 tree c
, t
= expr
.value
;
12282 t
= c_fully_fold (t
, false, NULL
);
12284 parens
.skip_until_found_close (parser
);
12286 if (t
== error_mark_node
)
12288 else if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12290 error_at (expr_loc
, "%qs expression must be integral",
12291 omp_clause_code_name
[code
]);
12295 /* Attempt to statically determine when the number isn't positive. */
12296 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12297 build_int_cst (TREE_TYPE (t
), 0));
12298 protected_set_expr_location (c
, expr_loc
);
12299 if (c
== boolean_true_node
)
12301 warning_at (expr_loc
, 0,
12302 "%qs value must be positive",
12303 omp_clause_code_name
[code
]);
12304 t
= integer_one_node
;
12307 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12309 c
= build_omp_clause (loc
, code
);
12310 OMP_CLAUSE_OPERAND (c
, 0) = t
;
12311 OMP_CLAUSE_CHAIN (c
) = list
;
12317 gang [( gang-arg-list )]
12318 worker [( [num:] int-expr )]
12319 vector [( [length:] int-expr )]
12321 where gang-arg is one of:
12326 and size-expr may be:
12333 c_parser_oacc_shape_clause (c_parser
*parser
, omp_clause_code kind
,
12334 const char *str
, tree list
)
12336 const char *id
= "num";
12337 tree ops
[2] = { NULL_TREE
, NULL_TREE
}, c
;
12338 location_t loc
= c_parser_peek_token (parser
)->location
;
12340 if (kind
== OMP_CLAUSE_VECTOR
)
12343 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12345 c_parser_consume_token (parser
);
12349 c_token
*next
= c_parser_peek_token (parser
);
12352 /* Gang static argument. */
12353 if (kind
== OMP_CLAUSE_GANG
12354 && c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12356 c_parser_consume_token (parser
);
12358 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12359 goto cleanup_error
;
12362 if (ops
[idx
] != NULL_TREE
)
12364 c_parser_error (parser
, "too many %<static%> arguments");
12365 goto cleanup_error
;
12368 /* Check for the '*' argument. */
12369 if (c_parser_next_token_is (parser
, CPP_MULT
)
12370 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
12371 || c_parser_peek_2nd_token (parser
)->type
12372 == CPP_CLOSE_PAREN
))
12374 c_parser_consume_token (parser
);
12375 ops
[idx
] = integer_minus_one_node
;
12377 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12379 c_parser_consume_token (parser
);
12386 /* Worker num: argument and vector length: arguments. */
12387 else if (c_parser_next_token_is (parser
, CPP_NAME
)
12388 && strcmp (id
, IDENTIFIER_POINTER (next
->value
)) == 0
12389 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12391 c_parser_consume_token (parser
); /* id */
12392 c_parser_consume_token (parser
); /* ':' */
12395 /* Now collect the actual argument. */
12396 if (ops
[idx
] != NULL_TREE
)
12398 c_parser_error (parser
, "unexpected argument");
12399 goto cleanup_error
;
12402 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12403 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
12404 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
12405 tree expr
= cexpr
.value
;
12406 if (expr
== error_mark_node
)
12407 goto cleanup_error
;
12409 expr
= c_fully_fold (expr
, false, NULL
);
12411 /* Attempt to statically determine when the number isn't a
12412 positive integer. */
12414 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
12416 c_parser_error (parser
, "expected integer expression");
12420 tree c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
12421 build_int_cst (TREE_TYPE (expr
), 0));
12422 if (c
== boolean_true_node
)
12424 warning_at (loc
, 0,
12425 "%qs value must be positive", str
);
12426 expr
= integer_one_node
;
12431 if (kind
== OMP_CLAUSE_GANG
12432 && c_parser_next_token_is (parser
, CPP_COMMA
))
12434 c_parser_consume_token (parser
);
12441 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12442 goto cleanup_error
;
12445 check_no_duplicate_clause (list
, kind
, str
);
12447 c
= build_omp_clause (loc
, kind
);
12450 OMP_CLAUSE_OPERAND (c
, 1) = ops
[1];
12452 OMP_CLAUSE_OPERAND (c
, 0) = ops
[0];
12453 OMP_CLAUSE_CHAIN (c
) = list
;
12458 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12469 c_parser_oacc_simple_clause (c_parser
*parser
, enum omp_clause_code code
,
12472 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12474 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12475 OMP_CLAUSE_CHAIN (c
) = list
;
12481 async [( int-expr )] */
12484 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
12487 location_t loc
= c_parser_peek_token (parser
)->location
;
12489 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
12491 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12493 c_parser_consume_token (parser
);
12495 t
= c_parser_expression (parser
).value
;
12496 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12497 c_parser_error (parser
, "expected integer expression");
12498 else if (t
== error_mark_node
12499 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12503 t
= c_fully_fold (t
, false, NULL
);
12505 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
12507 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
12508 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
12509 OMP_CLAUSE_CHAIN (c
) = list
;
12516 tile ( size-expr-list ) */
12519 c_parser_oacc_clause_tile (c_parser
*parser
, tree list
)
12521 tree c
, expr
= error_mark_node
;
12523 tree tile
= NULL_TREE
;
12525 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
12526 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
12528 loc
= c_parser_peek_token (parser
)->location
;
12529 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12534 if (tile
&& !c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
12537 if (c_parser_next_token_is (parser
, CPP_MULT
)
12538 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
12539 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
12541 c_parser_consume_token (parser
);
12542 expr
= integer_zero_node
;
12546 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12547 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
12548 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
12549 expr
= cexpr
.value
;
12551 if (expr
== error_mark_node
)
12553 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12558 expr
= c_fully_fold (expr
, false, NULL
);
12560 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
12561 || !tree_fits_shwi_p (expr
)
12562 || tree_to_shwi (expr
) <= 0)
12564 error_at (expr_loc
, "%<tile%> argument needs positive"
12565 " integral constant");
12566 expr
= integer_zero_node
;
12570 tile
= tree_cons (NULL_TREE
, expr
, tile
);
12572 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
));
12574 /* Consume the trailing ')'. */
12575 c_parser_consume_token (parser
);
12577 c
= build_omp_clause (loc
, OMP_CLAUSE_TILE
);
12578 tile
= nreverse (tile
);
12579 OMP_CLAUSE_TILE_LIST (c
) = tile
;
12580 OMP_CLAUSE_CHAIN (c
) = list
;
12585 wait ( int-expr-list ) */
12588 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
12590 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12592 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12593 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
12602 ordered ( constant-expression ) */
12605 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
12607 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
12609 tree c
, num
= NULL_TREE
;
12611 location_t loc
= c_parser_peek_token (parser
)->location
;
12612 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12614 matching_parens parens
;
12615 parens
.consume_open (parser
);
12616 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
12617 parens
.skip_until_found_close (parser
);
12619 if (num
== error_mark_node
)
12623 mark_exp_read (num
);
12624 num
= c_fully_fold (num
, false, NULL
);
12625 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
12626 || !tree_fits_shwi_p (num
)
12627 || (n
= tree_to_shwi (num
)) <= 0
12630 error_at (loc
, "ordered argument needs positive "
12631 "constant integer expression");
12635 c
= build_omp_clause (loc
, OMP_CLAUSE_ORDERED
);
12636 OMP_CLAUSE_ORDERED_EXPR (c
) = num
;
12637 OMP_CLAUSE_CHAIN (c
) = list
;
12642 private ( variable-list ) */
12645 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
12647 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
12651 reduction ( reduction-operator : variable-list )
12653 reduction-operator:
12654 One of: + * - & ^ | && ||
12658 reduction-operator:
12659 One of: + * - & ^ | && || max min
12663 reduction-operator:
12664 One of: + * - & ^ | && ||
12668 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
12670 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12671 matching_parens parens
;
12672 if (parens
.require_open (parser
))
12674 enum tree_code code
= ERROR_MARK
;
12675 tree reduc_id
= NULL_TREE
;
12677 switch (c_parser_peek_token (parser
)->type
)
12689 code
= BIT_AND_EXPR
;
12692 code
= BIT_XOR_EXPR
;
12695 code
= BIT_IOR_EXPR
;
12698 code
= TRUTH_ANDIF_EXPR
;
12701 code
= TRUTH_ORIF_EXPR
;
12706 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12707 if (strcmp (p
, "min") == 0)
12712 if (strcmp (p
, "max") == 0)
12717 reduc_id
= c_parser_peek_token (parser
)->value
;
12721 c_parser_error (parser
,
12722 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
12723 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
12724 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12727 c_parser_consume_token (parser
);
12728 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
12729 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12733 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12734 OMP_CLAUSE_REDUCTION
, list
);
12735 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12737 tree d
= OMP_CLAUSE_DECL (c
), type
;
12738 if (TREE_CODE (d
) != TREE_LIST
)
12739 type
= TREE_TYPE (d
);
12744 for (t
= d
; TREE_CODE (t
) == TREE_LIST
; t
= TREE_CHAIN (t
))
12746 type
= TREE_TYPE (t
);
12749 if (TREE_CODE (type
) != POINTER_TYPE
12750 && TREE_CODE (type
) != ARRAY_TYPE
)
12752 type
= TREE_TYPE (type
);
12756 while (TREE_CODE (type
) == ARRAY_TYPE
)
12757 type
= TREE_TYPE (type
);
12758 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
12759 if (code
== ERROR_MARK
12760 || !(INTEGRAL_TYPE_P (type
)
12761 || TREE_CODE (type
) == REAL_TYPE
12762 || TREE_CODE (type
) == COMPLEX_TYPE
))
12763 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
12764 = c_omp_reduction_lookup (reduc_id
,
12765 TYPE_MAIN_VARIANT (type
));
12770 parens
.skip_until_found_close (parser
);
12776 schedule ( schedule-kind )
12777 schedule ( schedule-kind , expression )
12780 static | dynamic | guided | runtime | auto
12783 schedule ( schedule-modifier : schedule-kind )
12784 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
12792 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
12795 location_t loc
= c_parser_peek_token (parser
)->location
;
12796 int modifiers
= 0, nmodifiers
= 0;
12798 matching_parens parens
;
12799 if (!parens
.require_open (parser
))
12802 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
12804 while (c_parser_next_token_is (parser
, CPP_NAME
))
12806 tree kind
= c_parser_peek_token (parser
)->value
;
12807 const char *p
= IDENTIFIER_POINTER (kind
);
12808 if (strcmp ("simd", p
) == 0)
12809 OMP_CLAUSE_SCHEDULE_SIMD (c
) = 1;
12810 else if (strcmp ("monotonic", p
) == 0)
12811 modifiers
|= OMP_CLAUSE_SCHEDULE_MONOTONIC
;
12812 else if (strcmp ("nonmonotonic", p
) == 0)
12813 modifiers
|= OMP_CLAUSE_SCHEDULE_NONMONOTONIC
;
12816 c_parser_consume_token (parser
);
12817 if (nmodifiers
++ == 0
12818 && c_parser_next_token_is (parser
, CPP_COMMA
))
12819 c_parser_consume_token (parser
);
12822 c_parser_require (parser
, CPP_COLON
, "expected %<:%>");
12827 if ((modifiers
& (OMP_CLAUSE_SCHEDULE_MONOTONIC
12828 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12829 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
12830 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12832 error_at (loc
, "both %<monotonic%> and %<nonmonotonic%> modifiers "
12837 if (c_parser_next_token_is (parser
, CPP_NAME
))
12839 tree kind
= c_parser_peek_token (parser
)->value
;
12840 const char *p
= IDENTIFIER_POINTER (kind
);
12845 if (strcmp ("dynamic", p
) != 0)
12847 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
12851 if (strcmp ("guided", p
) != 0)
12853 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
12857 if (strcmp ("runtime", p
) != 0)
12859 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
12866 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12867 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
12868 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
12869 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
12873 c_parser_consume_token (parser
);
12874 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12877 c_parser_consume_token (parser
);
12879 here
= c_parser_peek_token (parser
)->location
;
12880 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12881 expr
= convert_lvalue_to_rvalue (here
, expr
, false, true);
12883 t
= c_fully_fold (t
, false, NULL
);
12885 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
12886 error_at (here
, "schedule %<runtime%> does not take "
12887 "a %<chunk_size%> parameter");
12888 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
12890 "schedule %<auto%> does not take "
12891 "a %<chunk_size%> parameter");
12892 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
12894 /* Attempt to statically determine when the number isn't
12896 tree s
= fold_build2_loc (loc
, LE_EXPR
, boolean_type_node
, t
,
12897 build_int_cst (TREE_TYPE (t
), 0));
12898 protected_set_expr_location (s
, loc
);
12899 if (s
== boolean_true_node
)
12901 warning_at (loc
, 0,
12902 "chunk size value must be positive");
12903 t
= integer_one_node
;
12905 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
12908 c_parser_error (parser
, "expected integer expression");
12910 parens
.skip_until_found_close (parser
);
12913 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12914 "expected %<,%> or %<)%>");
12916 OMP_CLAUSE_SCHEDULE_KIND (c
)
12917 = (enum omp_clause_schedule_kind
)
12918 (OMP_CLAUSE_SCHEDULE_KIND (c
) | modifiers
);
12920 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
12921 OMP_CLAUSE_CHAIN (c
) = list
;
12925 c_parser_error (parser
, "invalid schedule kind");
12926 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12931 shared ( variable-list ) */
12934 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
12936 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
12943 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12947 /* FIXME: Should we allow duplicates? */
12948 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
12950 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12951 OMP_CLAUSE_UNTIED
);
12952 OMP_CLAUSE_CHAIN (c
) = list
;
12962 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
12963 enum omp_clause_code code
, tree list
)
12965 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12967 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12968 OMP_CLAUSE_CHAIN (c
) = list
;
12980 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
12981 enum omp_clause_code code
, tree list
)
12983 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12984 OMP_CLAUSE_CHAIN (c
) = list
;
12993 c_parser_omp_clause_nogroup (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12995 check_no_duplicate_clause (list
, OMP_CLAUSE_NOGROUP
, "nogroup");
12996 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12997 OMP_CLAUSE_NOGROUP
);
12998 OMP_CLAUSE_CHAIN (c
) = list
;
13007 c_parser_omp_clause_orderedkind (c_parser
*parser ATTRIBUTE_UNUSED
,
13008 enum omp_clause_code code
, tree list
)
13010 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
13011 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13012 OMP_CLAUSE_CHAIN (c
) = list
;
13017 num_teams ( expression ) */
13020 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
13022 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
13023 matching_parens parens
;
13024 if (parens
.require_open (parser
))
13026 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13027 c_expr expr
= c_parser_expression (parser
);
13028 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13029 tree c
, t
= expr
.value
;
13030 t
= c_fully_fold (t
, false, NULL
);
13032 parens
.skip_until_found_close (parser
);
13034 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13036 c_parser_error (parser
, "expected integer expression");
13040 /* Attempt to statically determine when the number isn't positive. */
13041 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13042 build_int_cst (TREE_TYPE (t
), 0));
13043 protected_set_expr_location (c
, expr_loc
);
13044 if (c
== boolean_true_node
)
13046 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
13047 t
= integer_one_node
;
13050 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
13052 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
13053 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
13054 OMP_CLAUSE_CHAIN (c
) = list
;
13062 thread_limit ( expression ) */
13065 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
13067 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
13068 matching_parens parens
;
13069 if (parens
.require_open (parser
))
13071 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13072 c_expr expr
= c_parser_expression (parser
);
13073 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13074 tree c
, t
= expr
.value
;
13075 t
= c_fully_fold (t
, false, NULL
);
13077 parens
.skip_until_found_close (parser
);
13079 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13081 c_parser_error (parser
, "expected integer expression");
13085 /* Attempt to statically determine when the number isn't positive. */
13086 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13087 build_int_cst (TREE_TYPE (t
), 0));
13088 protected_set_expr_location (c
, expr_loc
);
13089 if (c
== boolean_true_node
)
13091 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
13092 t
= integer_one_node
;
13095 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
13098 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
13099 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
13100 OMP_CLAUSE_CHAIN (c
) = list
;
13108 aligned ( variable-list )
13109 aligned ( variable-list : constant-expression ) */
13112 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
13114 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13117 matching_parens parens
;
13118 if (!parens
.require_open (parser
))
13121 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13122 OMP_CLAUSE_ALIGNED
, list
);
13124 if (c_parser_next_token_is (parser
, CPP_COLON
))
13126 c_parser_consume_token (parser
);
13127 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13128 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13129 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13130 tree alignment
= expr
.value
;
13131 alignment
= c_fully_fold (alignment
, false, NULL
);
13132 if (TREE_CODE (alignment
) != INTEGER_CST
13133 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
13134 || tree_int_cst_sgn (alignment
) != 1)
13136 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
13137 "be positive constant integer expression");
13138 alignment
= NULL_TREE
;
13141 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13142 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
13145 parens
.skip_until_found_close (parser
);
13150 linear ( variable-list )
13151 linear ( variable-list : expression )
13154 linear ( modifier ( variable-list ) )
13155 linear ( modifier ( variable-list ) : expression ) */
13158 c_parser_omp_clause_linear (c_parser
*parser
, tree list
)
13160 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13162 enum omp_clause_linear_kind kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
13164 matching_parens parens
;
13165 if (!parens
.require_open (parser
))
13168 if (c_parser_next_token_is (parser
, CPP_NAME
))
13170 c_token
*tok
= c_parser_peek_token (parser
);
13171 const char *p
= IDENTIFIER_POINTER (tok
->value
);
13172 if (strcmp ("val", p
) == 0)
13173 kind
= OMP_CLAUSE_LINEAR_VAL
;
13174 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
)
13175 kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
13176 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
13178 c_parser_consume_token (parser
);
13179 c_parser_consume_token (parser
);
13183 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13184 OMP_CLAUSE_LINEAR
, list
);
13186 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
13187 parens
.skip_until_found_close (parser
);
13189 if (c_parser_next_token_is (parser
, CPP_COLON
))
13191 c_parser_consume_token (parser
);
13192 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13193 c_expr expr
= c_parser_expression (parser
);
13194 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13196 step
= c_fully_fold (step
, false, NULL
);
13197 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
13199 error_at (clause_loc
, "%<linear%> clause step expression must "
13201 step
= integer_one_node
;
13206 step
= integer_one_node
;
13208 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13210 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
13211 OMP_CLAUSE_LINEAR_KIND (c
) = kind
;
13214 parens
.skip_until_found_close (parser
);
13219 safelen ( constant-expression ) */
13222 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
13224 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13227 matching_parens parens
;
13228 if (!parens
.require_open (parser
))
13231 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13232 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13233 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13235 t
= c_fully_fold (t
, false, NULL
);
13236 if (TREE_CODE (t
) != INTEGER_CST
13237 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
13238 || tree_int_cst_sgn (t
) != 1)
13240 error_at (clause_loc
, "%<safelen%> clause expression must "
13241 "be positive constant integer expression");
13245 parens
.skip_until_found_close (parser
);
13246 if (t
== NULL_TREE
|| t
== error_mark_node
)
13249 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
13251 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
13252 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
13253 OMP_CLAUSE_CHAIN (c
) = list
;
13258 simdlen ( constant-expression ) */
13261 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
13263 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13266 matching_parens parens
;
13267 if (!parens
.require_open (parser
))
13270 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13271 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13272 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13274 t
= c_fully_fold (t
, false, NULL
);
13275 if (TREE_CODE (t
) != INTEGER_CST
13276 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
13277 || tree_int_cst_sgn (t
) != 1)
13279 error_at (clause_loc
, "%<simdlen%> clause expression must "
13280 "be positive constant integer expression");
13284 parens
.skip_until_found_close (parser
);
13285 if (t
== NULL_TREE
|| t
== error_mark_node
)
13288 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
13290 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
13291 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
13292 OMP_CLAUSE_CHAIN (c
) = list
;
13298 identifier [+/- integer]
13299 vec , identifier [+/- integer]
13303 c_parser_omp_clause_depend_sink (c_parser
*parser
, location_t clause_loc
,
13307 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
13308 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13310 c_parser_error (parser
, "expected identifier");
13314 while (c_parser_next_token_is (parser
, CPP_NAME
)
13315 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
13317 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
13318 tree addend
= NULL
;
13320 if (t
== NULL_TREE
)
13322 undeclared_variable (c_parser_peek_token (parser
)->location
,
13323 c_parser_peek_token (parser
)->value
);
13324 t
= error_mark_node
;
13327 c_parser_consume_token (parser
);
13330 if (c_parser_next_token_is (parser
, CPP_MINUS
))
13332 else if (!c_parser_next_token_is (parser
, CPP_PLUS
))
13334 addend
= integer_zero_node
;
13336 goto add_to_vector
;
13338 c_parser_consume_token (parser
);
13340 if (c_parser_next_token_is_not (parser
, CPP_NUMBER
))
13342 c_parser_error (parser
, "expected integer");
13346 addend
= c_parser_peek_token (parser
)->value
;
13347 if (TREE_CODE (addend
) != INTEGER_CST
)
13349 c_parser_error (parser
, "expected integer");
13352 c_parser_consume_token (parser
);
13355 if (t
!= error_mark_node
)
13357 vec
= tree_cons (addend
, t
, vec
);
13359 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec
) = 1;
13362 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
13365 c_parser_consume_token (parser
);
13368 if (vec
== NULL_TREE
)
13371 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
13372 OMP_CLAUSE_DEPEND_KIND (u
) = OMP_CLAUSE_DEPEND_SINK
;
13373 OMP_CLAUSE_DECL (u
) = nreverse (vec
);
13374 OMP_CLAUSE_CHAIN (u
) = list
;
13379 depend ( depend-kind: variable-list )
13387 depend ( sink : vec ) */
13390 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
13392 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13393 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
13396 matching_parens parens
;
13397 if (!parens
.require_open (parser
))
13400 if (c_parser_next_token_is (parser
, CPP_NAME
))
13402 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13403 if (strcmp ("in", p
) == 0)
13404 kind
= OMP_CLAUSE_DEPEND_IN
;
13405 else if (strcmp ("inout", p
) == 0)
13406 kind
= OMP_CLAUSE_DEPEND_INOUT
;
13407 else if (strcmp ("out", p
) == 0)
13408 kind
= OMP_CLAUSE_DEPEND_OUT
;
13409 else if (strcmp ("source", p
) == 0)
13410 kind
= OMP_CLAUSE_DEPEND_SOURCE
;
13411 else if (strcmp ("sink", p
) == 0)
13412 kind
= OMP_CLAUSE_DEPEND_SINK
;
13419 c_parser_consume_token (parser
);
13421 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
13423 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
13424 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
13425 OMP_CLAUSE_DECL (c
) = NULL_TREE
;
13426 OMP_CLAUSE_CHAIN (c
) = list
;
13427 parens
.skip_until_found_close (parser
);
13431 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13434 if (kind
== OMP_CLAUSE_DEPEND_SINK
)
13435 nl
= c_parser_omp_clause_depend_sink (parser
, clause_loc
, list
);
13438 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13439 OMP_CLAUSE_DEPEND
, list
);
13441 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13442 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
13445 parens
.skip_until_found_close (parser
);
13449 c_parser_error (parser
, "invalid depend kind");
13451 parens
.skip_until_found_close (parser
);
13456 map ( map-kind: variable-list )
13457 map ( variable-list )
13460 alloc | to | from | tofrom
13464 alloc | to | from | tofrom | release | delete
13466 map ( always [,] map-kind: variable-list ) */
13469 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
13471 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13472 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
13474 enum c_id_kind always_id_kind
= C_ID_NONE
;
13475 location_t always_loc
= UNKNOWN_LOCATION
;
13476 tree always_id
= NULL_TREE
;
13479 matching_parens parens
;
13480 if (!parens
.require_open (parser
))
13483 if (c_parser_next_token_is (parser
, CPP_NAME
))
13485 c_token
*tok
= c_parser_peek_token (parser
);
13486 const char *p
= IDENTIFIER_POINTER (tok
->value
);
13487 always_id_kind
= tok
->id_kind
;
13488 always_loc
= tok
->location
;
13489 always_id
= tok
->value
;
13490 if (strcmp ("always", p
) == 0)
13492 c_token
*sectok
= c_parser_peek_2nd_token (parser
);
13493 if (sectok
->type
== CPP_COMMA
)
13495 c_parser_consume_token (parser
);
13496 c_parser_consume_token (parser
);
13499 else if (sectok
->type
== CPP_NAME
)
13501 p
= IDENTIFIER_POINTER (sectok
->value
);
13502 if (strcmp ("alloc", p
) == 0
13503 || strcmp ("to", p
) == 0
13504 || strcmp ("from", p
) == 0
13505 || strcmp ("tofrom", p
) == 0
13506 || strcmp ("release", p
) == 0
13507 || strcmp ("delete", p
) == 0)
13509 c_parser_consume_token (parser
);
13516 if (c_parser_next_token_is (parser
, CPP_NAME
)
13517 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13519 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13520 if (strcmp ("alloc", p
) == 0)
13521 kind
= GOMP_MAP_ALLOC
;
13522 else if (strcmp ("to", p
) == 0)
13523 kind
= always
? GOMP_MAP_ALWAYS_TO
: GOMP_MAP_TO
;
13524 else if (strcmp ("from", p
) == 0)
13525 kind
= always
? GOMP_MAP_ALWAYS_FROM
: GOMP_MAP_FROM
;
13526 else if (strcmp ("tofrom", p
) == 0)
13527 kind
= always
? GOMP_MAP_ALWAYS_TOFROM
: GOMP_MAP_TOFROM
;
13528 else if (strcmp ("release", p
) == 0)
13529 kind
= GOMP_MAP_RELEASE
;
13530 else if (strcmp ("delete", p
) == 0)
13531 kind
= GOMP_MAP_DELETE
;
13534 c_parser_error (parser
, "invalid map kind");
13535 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13539 c_parser_consume_token (parser
);
13540 c_parser_consume_token (parser
);
13544 if (always_id_kind
!= C_ID_ID
)
13546 c_parser_error (parser
, "expected identifier");
13547 parens
.skip_until_found_close (parser
);
13551 tree t
= lookup_name (always_id
);
13552 if (t
== NULL_TREE
)
13554 undeclared_variable (always_loc
, always_id
);
13555 t
= error_mark_node
;
13557 if (t
!= error_mark_node
)
13559 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_MAP
);
13560 OMP_CLAUSE_DECL (u
) = t
;
13561 OMP_CLAUSE_CHAIN (u
) = list
;
13562 OMP_CLAUSE_SET_MAP_KIND (u
, kind
);
13567 parens
.skip_until_found_close (parser
);
13572 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
13574 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13575 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
13577 parens
.skip_until_found_close (parser
);
13582 device ( expression ) */
13585 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
13587 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13588 matching_parens parens
;
13589 if (parens
.require_open (parser
))
13591 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13592 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13593 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13594 tree c
, t
= expr
.value
;
13595 t
= c_fully_fold (t
, false, NULL
);
13597 parens
.skip_until_found_close (parser
);
13599 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13601 c_parser_error (parser
, "expected integer expression");
13605 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
13607 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
13608 OMP_CLAUSE_DEVICE_ID (c
) = t
;
13609 OMP_CLAUSE_CHAIN (c
) = list
;
13617 dist_schedule ( static )
13618 dist_schedule ( static , expression ) */
13621 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
13623 tree c
, t
= NULL_TREE
;
13624 location_t loc
= c_parser_peek_token (parser
)->location
;
13626 matching_parens parens
;
13627 if (!parens
.require_open (parser
))
13630 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
13632 c_parser_error (parser
, "invalid dist_schedule kind");
13633 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13638 c_parser_consume_token (parser
);
13639 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13641 c_parser_consume_token (parser
);
13643 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13644 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13645 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13647 t
= c_fully_fold (t
, false, NULL
);
13648 parens
.skip_until_found_close (parser
);
13651 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13652 "expected %<,%> or %<)%>");
13654 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
13655 if (t
== error_mark_node
)
13658 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
13659 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
13660 OMP_CLAUSE_CHAIN (c
) = list
;
13665 proc_bind ( proc-bind-kind )
13668 master | close | spread */
13671 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
13673 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13674 enum omp_clause_proc_bind_kind kind
;
13677 matching_parens parens
;
13678 if (!parens
.require_open (parser
))
13681 if (c_parser_next_token_is (parser
, CPP_NAME
))
13683 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13684 if (strcmp ("master", p
) == 0)
13685 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
13686 else if (strcmp ("close", p
) == 0)
13687 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
13688 else if (strcmp ("spread", p
) == 0)
13689 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
13696 c_parser_consume_token (parser
);
13697 parens
.skip_until_found_close (parser
);
13698 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
13699 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
13700 OMP_CLAUSE_CHAIN (c
) = list
;
13704 c_parser_error (parser
, "invalid proc_bind kind");
13705 parens
.skip_until_found_close (parser
);
13710 to ( variable-list ) */
13713 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
13715 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
13719 from ( variable-list ) */
13722 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
13724 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
13728 uniform ( variable-list ) */
13731 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
13733 /* The clauses location. */
13734 location_t loc
= c_parser_peek_token (parser
)->location
;
13736 matching_parens parens
;
13737 if (parens
.require_open (parser
))
13739 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
13741 parens
.skip_until_found_close (parser
);
13746 /* Parse all OpenACC clauses. The set clauses allowed by the directive
13747 is a bitmask in MASK. Return the list of clauses found. */
13750 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
13751 const char *where
, bool finish_p
= true)
13753 tree clauses
= NULL
;
13756 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13759 pragma_omp_clause c_kind
;
13760 const char *c_name
;
13761 tree prev
= clauses
;
13763 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
13764 c_parser_consume_token (parser
);
13766 here
= c_parser_peek_token (parser
)->location
;
13767 c_kind
= c_parser_omp_clause_name (parser
);
13771 case PRAGMA_OACC_CLAUSE_ASYNC
:
13772 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
13775 case PRAGMA_OACC_CLAUSE_AUTO
:
13776 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_AUTO
,
13780 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
13781 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
13782 c_name
= "collapse";
13784 case PRAGMA_OACC_CLAUSE_COPY
:
13785 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13788 case PRAGMA_OACC_CLAUSE_COPYIN
:
13789 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13792 case PRAGMA_OACC_CLAUSE_COPYOUT
:
13793 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13794 c_name
= "copyout";
13796 case PRAGMA_OACC_CLAUSE_CREATE
:
13797 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13800 case PRAGMA_OACC_CLAUSE_DELETE
:
13801 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13804 case PRAGMA_OMP_CLAUSE_DEFAULT
:
13805 clauses
= c_parser_omp_clause_default (parser
, clauses
, true);
13806 c_name
= "default";
13808 case PRAGMA_OACC_CLAUSE_DEVICE
:
13809 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13812 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
13813 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
13814 c_name
= "deviceptr";
13816 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
13817 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13818 c_name
= "device_resident";
13820 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
13821 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13822 c_name
= "firstprivate";
13824 case PRAGMA_OACC_CLAUSE_GANG
:
13826 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_GANG
,
13829 case PRAGMA_OACC_CLAUSE_HOST
:
13830 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13833 case PRAGMA_OACC_CLAUSE_IF
:
13834 clauses
= c_parser_omp_clause_if (parser
, clauses
, false);
13837 case PRAGMA_OACC_CLAUSE_INDEPENDENT
:
13838 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_INDEPENDENT
,
13840 c_name
= "independent";
13842 case PRAGMA_OACC_CLAUSE_LINK
:
13843 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13846 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
13847 clauses
= c_parser_oacc_single_int_clause (parser
,
13848 OMP_CLAUSE_NUM_GANGS
,
13850 c_name
= "num_gangs";
13852 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
13853 clauses
= c_parser_oacc_single_int_clause (parser
,
13854 OMP_CLAUSE_NUM_WORKERS
,
13856 c_name
= "num_workers";
13858 case PRAGMA_OACC_CLAUSE_PRESENT
:
13859 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13860 c_name
= "present";
13862 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
13863 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13864 c_name
= "present_or_copy";
13866 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
13867 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13868 c_name
= "present_or_copyin";
13870 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
13871 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13872 c_name
= "present_or_copyout";
13874 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
13875 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13876 c_name
= "present_or_create";
13878 case PRAGMA_OACC_CLAUSE_PRIVATE
:
13879 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13880 c_name
= "private";
13882 case PRAGMA_OACC_CLAUSE_REDUCTION
:
13883 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13884 c_name
= "reduction";
13886 case PRAGMA_OACC_CLAUSE_SELF
:
13887 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13890 case PRAGMA_OACC_CLAUSE_SEQ
:
13891 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_SEQ
,
13895 case PRAGMA_OACC_CLAUSE_TILE
:
13896 clauses
= c_parser_oacc_clause_tile (parser
, clauses
);
13899 case PRAGMA_OACC_CLAUSE_USE_DEVICE
:
13900 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
13901 c_name
= "use_device";
13903 case PRAGMA_OACC_CLAUSE_VECTOR
:
13905 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_VECTOR
,
13908 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
13909 clauses
= c_parser_oacc_single_int_clause (parser
,
13910 OMP_CLAUSE_VECTOR_LENGTH
,
13912 c_name
= "vector_length";
13914 case PRAGMA_OACC_CLAUSE_WAIT
:
13915 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
13918 case PRAGMA_OACC_CLAUSE_WORKER
:
13920 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_WORKER
,
13924 c_parser_error (parser
, "expected %<#pragma acc%> clause");
13930 if (((mask
>> c_kind
) & 1) == 0)
13932 /* Remove the invalid clause(s) from the list to avoid
13933 confusing the rest of the compiler. */
13935 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
13940 c_parser_skip_to_pragma_eol (parser
);
13943 return c_finish_omp_clauses (clauses
, C_ORT_ACC
);
13948 /* Parse all OpenMP clauses. The set clauses allowed by the directive
13949 is a bitmask in MASK. Return the list of clauses found. */
13952 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
13953 const char *where
, bool finish_p
= true)
13955 tree clauses
= NULL
;
13958 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13961 pragma_omp_clause c_kind
;
13962 const char *c_name
;
13963 tree prev
= clauses
;
13965 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
13966 c_parser_consume_token (parser
);
13968 here
= c_parser_peek_token (parser
)->location
;
13969 c_kind
= c_parser_omp_clause_name (parser
);
13973 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
13974 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
13975 c_name
= "collapse";
13977 case PRAGMA_OMP_CLAUSE_COPYIN
:
13978 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
13981 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
13982 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
13983 c_name
= "copyprivate";
13985 case PRAGMA_OMP_CLAUSE_DEFAULT
:
13986 clauses
= c_parser_omp_clause_default (parser
, clauses
, false);
13987 c_name
= "default";
13989 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
13990 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13991 c_name
= "firstprivate";
13993 case PRAGMA_OMP_CLAUSE_FINAL
:
13994 clauses
= c_parser_omp_clause_final (parser
, clauses
);
13997 case PRAGMA_OMP_CLAUSE_GRAINSIZE
:
13998 clauses
= c_parser_omp_clause_grainsize (parser
, clauses
);
13999 c_name
= "grainsize";
14001 case PRAGMA_OMP_CLAUSE_HINT
:
14002 clauses
= c_parser_omp_clause_hint (parser
, clauses
);
14005 case PRAGMA_OMP_CLAUSE_DEFAULTMAP
:
14006 clauses
= c_parser_omp_clause_defaultmap (parser
, clauses
);
14007 c_name
= "defaultmap";
14009 case PRAGMA_OMP_CLAUSE_IF
:
14010 clauses
= c_parser_omp_clause_if (parser
, clauses
, true);
14013 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
14014 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
14015 c_name
= "lastprivate";
14017 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
14018 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
14019 c_name
= "mergeable";
14021 case PRAGMA_OMP_CLAUSE_NOWAIT
:
14022 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
14025 case PRAGMA_OMP_CLAUSE_NUM_TASKS
:
14026 clauses
= c_parser_omp_clause_num_tasks (parser
, clauses
);
14027 c_name
= "num_tasks";
14029 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
14030 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
14031 c_name
= "num_threads";
14033 case PRAGMA_OMP_CLAUSE_ORDERED
:
14034 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
14035 c_name
= "ordered";
14037 case PRAGMA_OMP_CLAUSE_PRIORITY
:
14038 clauses
= c_parser_omp_clause_priority (parser
, clauses
);
14039 c_name
= "priority";
14041 case PRAGMA_OMP_CLAUSE_PRIVATE
:
14042 clauses
= c_parser_omp_clause_private (parser
, clauses
);
14043 c_name
= "private";
14045 case PRAGMA_OMP_CLAUSE_REDUCTION
:
14046 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
14047 c_name
= "reduction";
14049 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
14050 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
14051 c_name
= "schedule";
14053 case PRAGMA_OMP_CLAUSE_SHARED
:
14054 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
14057 case PRAGMA_OMP_CLAUSE_UNTIED
:
14058 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
14061 case PRAGMA_OMP_CLAUSE_INBRANCH
:
14062 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
14064 c_name
= "inbranch";
14066 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
14067 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
14069 c_name
= "notinbranch";
14071 case PRAGMA_OMP_CLAUSE_PARALLEL
:
14073 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
14075 c_name
= "parallel";
14079 error_at (here
, "%qs must be the first clause of %qs",
14084 case PRAGMA_OMP_CLAUSE_FOR
:
14086 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
14090 goto clause_not_first
;
14092 case PRAGMA_OMP_CLAUSE_SECTIONS
:
14094 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
14096 c_name
= "sections";
14098 goto clause_not_first
;
14100 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
14102 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
14104 c_name
= "taskgroup";
14106 goto clause_not_first
;
14108 case PRAGMA_OMP_CLAUSE_LINK
:
14110 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LINK
, clauses
);
14113 case PRAGMA_OMP_CLAUSE_TO
:
14114 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINK
)) != 0)
14116 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
14119 clauses
= c_parser_omp_clause_to (parser
, clauses
);
14122 case PRAGMA_OMP_CLAUSE_FROM
:
14123 clauses
= c_parser_omp_clause_from (parser
, clauses
);
14126 case PRAGMA_OMP_CLAUSE_UNIFORM
:
14127 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
14128 c_name
= "uniform";
14130 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
14131 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
14132 c_name
= "num_teams";
14134 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
14135 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
14136 c_name
= "thread_limit";
14138 case PRAGMA_OMP_CLAUSE_ALIGNED
:
14139 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
14140 c_name
= "aligned";
14142 case PRAGMA_OMP_CLAUSE_LINEAR
:
14143 clauses
= c_parser_omp_clause_linear (parser
, clauses
);
14146 case PRAGMA_OMP_CLAUSE_DEPEND
:
14147 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
14150 case PRAGMA_OMP_CLAUSE_MAP
:
14151 clauses
= c_parser_omp_clause_map (parser
, clauses
);
14154 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
:
14155 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
14156 c_name
= "use_device_ptr";
14158 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
:
14159 clauses
= c_parser_omp_clause_is_device_ptr (parser
, clauses
);
14160 c_name
= "is_device_ptr";
14162 case PRAGMA_OMP_CLAUSE_DEVICE
:
14163 clauses
= c_parser_omp_clause_device (parser
, clauses
);
14166 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
14167 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
14168 c_name
= "dist_schedule";
14170 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
14171 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
14172 c_name
= "proc_bind";
14174 case PRAGMA_OMP_CLAUSE_SAFELEN
:
14175 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
14176 c_name
= "safelen";
14178 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
14179 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
14180 c_name
= "simdlen";
14182 case PRAGMA_OMP_CLAUSE_NOGROUP
:
14183 clauses
= c_parser_omp_clause_nogroup (parser
, clauses
);
14184 c_name
= "nogroup";
14186 case PRAGMA_OMP_CLAUSE_THREADS
:
14188 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_THREADS
,
14190 c_name
= "threads";
14192 case PRAGMA_OMP_CLAUSE_SIMD
:
14194 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_SIMD
,
14199 c_parser_error (parser
, "expected %<#pragma omp%> clause");
14205 if (((mask
>> c_kind
) & 1) == 0)
14207 /* Remove the invalid clause(s) from the list to avoid
14208 confusing the rest of the compiler. */
14210 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
14215 c_parser_skip_to_pragma_eol (parser
);
14219 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_UNIFORM
)) != 0)
14220 return c_finish_omp_clauses (clauses
, C_ORT_OMP_DECLARE_SIMD
);
14221 return c_finish_omp_clauses (clauses
, C_ORT_OMP
);
14227 /* OpenACC 2.0, OpenMP 2.5:
14231 In practice, we're also interested in adding the statement to an
14232 outer node. So it is convenient if we work around the fact that
14233 c_parser_statement calls add_stmt. */
14236 c_parser_omp_structured_block (c_parser
*parser
, bool *if_p
)
14238 tree stmt
= push_stmt_list ();
14239 c_parser_statement (parser
, if_p
);
14240 return pop_stmt_list (stmt
);
14244 # pragma acc cache (variable-list) new-line
14246 LOC is the location of the #pragma token.
14250 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
14252 tree stmt
, clauses
;
14254 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
14255 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14257 c_parser_skip_to_pragma_eol (parser
);
14259 stmt
= make_node (OACC_CACHE
);
14260 TREE_TYPE (stmt
) = void_type_node
;
14261 OACC_CACHE_CLAUSES (stmt
) = clauses
;
14262 SET_EXPR_LOCATION (stmt
, loc
);
14269 # pragma acc data oacc-data-clause[optseq] new-line
14272 LOC is the location of the #pragma token.
14275 #define OACC_DATA_CLAUSE_MASK \
14276 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14277 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14278 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14279 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14280 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14281 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14282 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14283 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14284 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14285 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14286 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
14289 c_parser_oacc_data (location_t loc
, c_parser
*parser
, bool *if_p
)
14291 tree stmt
, clauses
, block
;
14293 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
14294 "#pragma acc data");
14296 block
= c_begin_omp_parallel ();
14297 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14299 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
14305 # pragma acc declare oacc-data-clause[optseq] new-line
14308 #define OACC_DECLARE_CLAUSE_MASK \
14309 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14310 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14311 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14312 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14313 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14314 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \
14315 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \
14316 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14317 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14318 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14319 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14320 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
14323 c_parser_oacc_declare (c_parser
*parser
)
14325 location_t pragma_loc
= c_parser_peek_token (parser
)->location
;
14326 tree clauses
, stmt
, t
, decl
;
14328 bool error
= false;
14330 c_parser_consume_pragma (parser
);
14332 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DECLARE_CLAUSE_MASK
,
14333 "#pragma acc declare");
14336 error_at (pragma_loc
,
14337 "no valid clauses specified in %<#pragma acc declare%>");
14341 for (t
= clauses
; t
; t
= OMP_CLAUSE_CHAIN (t
))
14343 location_t loc
= OMP_CLAUSE_LOCATION (t
);
14344 decl
= OMP_CLAUSE_DECL (t
);
14345 if (!DECL_P (decl
))
14347 error_at (loc
, "array section in %<#pragma acc declare%>");
14352 switch (OMP_CLAUSE_MAP_KIND (t
))
14354 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
14355 case GOMP_MAP_FORCE_ALLOC
:
14356 case GOMP_MAP_FORCE_TO
:
14357 case GOMP_MAP_FORCE_DEVICEPTR
:
14358 case GOMP_MAP_DEVICE_RESIDENT
:
14361 case GOMP_MAP_LINK
:
14362 if (!global_bindings_p ()
14363 && (TREE_STATIC (decl
)
14364 || !DECL_EXTERNAL (decl
)))
14367 "%qD must be a global variable in "
14368 "%<#pragma acc declare link%>",
14376 if (global_bindings_p ())
14378 error_at (loc
, "invalid OpenACC clause at file scope");
14382 if (DECL_EXTERNAL (decl
))
14385 "invalid use of %<extern%> variable %qD "
14386 "in %<#pragma acc declare%>", decl
);
14390 else if (TREE_PUBLIC (decl
))
14393 "invalid use of %<global%> variable %qD "
14394 "in %<#pragma acc declare%>", decl
);
14401 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl
))
14402 || lookup_attribute ("omp declare target link",
14403 DECL_ATTRIBUTES (decl
)))
14405 error_at (loc
, "variable %qD used more than once with "
14406 "%<#pragma acc declare%>", decl
);
14415 if (OMP_CLAUSE_MAP_KIND (t
) == GOMP_MAP_LINK
)
14416 id
= get_identifier ("omp declare target link");
14418 id
= get_identifier ("omp declare target");
14420 DECL_ATTRIBUTES (decl
)
14421 = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (decl
));
14423 if (global_bindings_p ())
14425 symtab_node
*node
= symtab_node::get (decl
);
14428 node
->offloadable
= 1;
14429 if (ENABLE_OFFLOADING
)
14431 g
->have_offload
= true;
14432 if (is_a
<varpool_node
*> (node
))
14433 vec_safe_push (offload_vars
, decl
);
14440 if (error
|| global_bindings_p ())
14443 stmt
= make_node (OACC_DECLARE
);
14444 TREE_TYPE (stmt
) = void_type_node
;
14445 OACC_DECLARE_CLAUSES (stmt
) = clauses
;
14446 SET_EXPR_LOCATION (stmt
, pragma_loc
);
14454 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
14458 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
14461 LOC is the location of the #pragma token.
14464 #define OACC_ENTER_DATA_CLAUSE_MASK \
14465 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14466 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14467 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14468 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14469 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14470 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14471 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14473 #define OACC_EXIT_DATA_CLAUSE_MASK \
14474 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14475 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14476 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14477 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
14478 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14481 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
14483 location_t loc
= c_parser_peek_token (parser
)->location
;
14484 tree clauses
, stmt
;
14485 const char *p
= "";
14487 c_parser_consume_pragma (parser
);
14489 if (c_parser_next_token_is (parser
, CPP_NAME
))
14491 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14492 c_parser_consume_token (parser
);
14495 if (strcmp (p
, "data") != 0)
14497 error_at (loc
, "expected %<data%> after %<#pragma acc %s%>",
14498 enter
? "enter" : "exit");
14499 parser
->error
= true;
14500 c_parser_skip_to_pragma_eol (parser
);
14505 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
14506 "#pragma acc enter data");
14508 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
14509 "#pragma acc exit data");
14511 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
14513 error_at (loc
, "%<#pragma acc %s data%> has no data movement clause",
14514 enter
? "enter" : "exit");
14518 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
14519 TREE_TYPE (stmt
) = void_type_node
;
14520 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
14521 SET_EXPR_LOCATION (stmt
, loc
);
14527 # pragma acc host_data oacc-data-clause[optseq] new-line
14531 #define OACC_HOST_DATA_CLAUSE_MASK \
14532 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
14535 c_parser_oacc_host_data (location_t loc
, c_parser
*parser
, bool *if_p
)
14537 tree stmt
, clauses
, block
;
14539 clauses
= c_parser_oacc_all_clauses (parser
, OACC_HOST_DATA_CLAUSE_MASK
,
14540 "#pragma acc host_data");
14542 block
= c_begin_omp_parallel ();
14543 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14544 stmt
= c_finish_oacc_host_data (loc
, clauses
, block
);
14551 # pragma acc loop oacc-loop-clause[optseq] new-line
14554 LOC is the location of the #pragma token.
14557 #define OACC_LOOP_CLAUSE_MASK \
14558 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
14559 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14560 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14561 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14562 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14563 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14564 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
14565 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
14566 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
14567 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
14569 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
,
14570 omp_clause_mask mask
, tree
*cclauses
, bool *if_p
)
14572 bool is_parallel
= ((mask
>> PRAGMA_OACC_CLAUSE_REDUCTION
) & 1) == 1;
14574 strcat (p_name
, " loop");
14575 mask
|= OACC_LOOP_CLAUSE_MASK
;
14577 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
,
14581 clauses
= c_oacc_split_loop_clauses (clauses
, cclauses
, is_parallel
);
14583 *cclauses
= c_finish_omp_clauses (*cclauses
, C_ORT_ACC
);
14585 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14588 tree block
= c_begin_compound_stmt (true);
14589 tree stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
,
14591 block
= c_end_compound_stmt (loc
, block
, true);
14598 # pragma acc kernels oacc-kernels-clause[optseq] new-line
14603 # pragma acc parallel oacc-parallel-clause[optseq] new-line
14606 LOC is the location of the #pragma token.
14609 #define OACC_KERNELS_CLAUSE_MASK \
14610 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14611 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14612 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14613 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14614 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14615 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14616 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14617 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14618 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14619 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14620 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14621 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14622 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14623 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14624 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14625 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14626 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14628 #define OACC_PARALLEL_CLAUSE_MASK \
14629 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14630 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14631 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14632 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14633 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14634 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14635 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14636 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14637 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14638 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
14639 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14640 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14641 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14642 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14643 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14644 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14645 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14646 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14647 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14648 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14651 c_parser_oacc_kernels_parallel (location_t loc
, c_parser
*parser
,
14652 enum pragma_kind p_kind
, char *p_name
,
14655 omp_clause_mask mask
;
14656 enum tree_code code
;
14659 case PRAGMA_OACC_KERNELS
:
14660 strcat (p_name
, " kernels");
14661 mask
= OACC_KERNELS_CLAUSE_MASK
;
14662 code
= OACC_KERNELS
;
14664 case PRAGMA_OACC_PARALLEL
:
14665 strcat (p_name
, " parallel");
14666 mask
= OACC_PARALLEL_CLAUSE_MASK
;
14667 code
= OACC_PARALLEL
;
14670 gcc_unreachable ();
14673 if (c_parser_next_token_is (parser
, CPP_NAME
))
14675 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14676 if (strcmp (p
, "loop") == 0)
14678 c_parser_consume_token (parser
);
14679 tree block
= c_begin_omp_parallel ();
14681 c_parser_oacc_loop (loc
, parser
, p_name
, mask
, &clauses
, if_p
);
14682 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14686 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
);
14688 tree block
= c_begin_omp_parallel ();
14689 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14691 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14695 # pragma acc routine oacc-routine-clause[optseq] new-line
14696 function-definition
14698 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
14701 #define OACC_ROUTINE_CLAUSE_MASK \
14702 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14703 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14704 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14705 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
14707 /* Parse an OpenACC routine directive. For named directives, we apply
14708 immediately to the named function. For unnamed ones we then parse
14709 a declaration or definition, which must be for a function. */
14712 c_parser_oacc_routine (c_parser
*parser
, enum pragma_context context
)
14714 gcc_checking_assert (context
== pragma_external
);
14716 oacc_routine_data data
;
14717 data
.error_seen
= false;
14718 data
.fndecl_seen
= false;
14719 data
.clauses
= NULL_TREE
;
14720 data
.loc
= c_parser_peek_token (parser
)->location
;
14722 c_parser_consume_pragma (parser
);
14724 /* Look for optional '( name )'. */
14725 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14727 c_parser_consume_token (parser
); /* '(' */
14729 tree decl
= NULL_TREE
;
14730 c_token
*name_token
= c_parser_peek_token (parser
);
14731 location_t name_loc
= name_token
->location
;
14732 if (name_token
->type
== CPP_NAME
14733 && (name_token
->id_kind
== C_ID_ID
14734 || name_token
->id_kind
== C_ID_TYPENAME
))
14736 decl
= lookup_name (name_token
->value
);
14738 error_at (name_loc
,
14739 "%qE has not been declared", name_token
->value
);
14740 c_parser_consume_token (parser
);
14743 c_parser_error (parser
, "expected function name");
14746 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14748 c_parser_skip_to_pragma_eol (parser
, false);
14753 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
14754 "#pragma acc routine");
14756 if (TREE_CODE (decl
) != FUNCTION_DECL
)
14758 error_at (name_loc
, "%qD does not refer to a function", decl
);
14762 c_finish_oacc_routine (&data
, decl
, false);
14764 else /* No optional '( name )'. */
14767 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
14768 "#pragma acc routine");
14770 /* Emit a helpful diagnostic if there's another pragma following this
14771 one. Also don't allow a static assertion declaration, as in the
14772 following we'll just parse a *single* "declaration or function
14773 definition", and the static assertion counts an one. */
14774 if (c_parser_next_token_is (parser
, CPP_PRAGMA
)
14775 || c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
14777 error_at (data
.loc
,
14778 "%<#pragma acc routine%> not immediately followed by"
14779 " function declaration or definition");
14780 /* ..., and then just keep going. */
14784 /* We only have to consider the pragma_external case here. */
14785 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14786 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
14788 int ext
= disable_extension_diagnostics ();
14790 c_parser_consume_token (parser
);
14791 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14792 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
14793 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14794 NULL
, vNULL
, &data
);
14795 restore_extension_diagnostics (ext
);
14798 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14799 NULL
, vNULL
, &data
);
14803 /* Finalize an OpenACC routine pragma, applying it to FNDECL.
14804 IS_DEFN is true if we're applying it to the definition. */
14807 c_finish_oacc_routine (struct oacc_routine_data
*data
, tree fndecl
,
14810 /* Keep going if we're in error reporting mode. */
14811 if (data
->error_seen
14812 || fndecl
== error_mark_node
)
14815 if (data
->fndecl_seen
)
14817 error_at (data
->loc
,
14818 "%<#pragma acc routine%> not immediately followed by"
14819 " a single function declaration or definition");
14820 data
->error_seen
= true;
14823 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
14825 error_at (data
->loc
,
14826 "%<#pragma acc routine%> not immediately followed by"
14827 " function declaration or definition");
14828 data
->error_seen
= true;
14832 if (oacc_get_fn_attrib (fndecl
))
14834 error_at (data
->loc
,
14835 "%<#pragma acc routine%> already applied to %qD", fndecl
);
14836 data
->error_seen
= true;
14840 if (TREE_USED (fndecl
) || (!is_defn
&& DECL_SAVED_TREE (fndecl
)))
14842 error_at (data
->loc
,
14844 ? G_("%<#pragma acc routine%> must be applied before use")
14845 : G_("%<#pragma acc routine%> must be applied before "
14847 data
->error_seen
= true;
14851 /* Process the routine's dimension clauses. */
14852 tree dims
= oacc_build_routine_dims (data
->clauses
);
14853 oacc_replace_fn_attrib (fndecl
, dims
);
14855 /* Add an "omp declare target" attribute. */
14856 DECL_ATTRIBUTES (fndecl
)
14857 = tree_cons (get_identifier ("omp declare target"),
14858 NULL_TREE
, DECL_ATTRIBUTES (fndecl
));
14860 /* Remember that we've used this "#pragma acc routine". */
14861 data
->fndecl_seen
= true;
14865 # pragma acc update oacc-update-clause[optseq] new-line
14868 #define OACC_UPDATE_CLAUSE_MASK \
14869 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14870 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
14871 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
14872 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14873 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
14874 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14877 c_parser_oacc_update (c_parser
*parser
)
14879 location_t loc
= c_parser_peek_token (parser
)->location
;
14881 c_parser_consume_pragma (parser
);
14883 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
14884 "#pragma acc update");
14885 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
14888 "%<#pragma acc update%> must contain at least one "
14889 "%<device%> or %<host%> or %<self%> clause");
14896 tree stmt
= make_node (OACC_UPDATE
);
14897 TREE_TYPE (stmt
) = void_type_node
;
14898 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
14899 SET_EXPR_LOCATION (stmt
, loc
);
14904 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
14906 LOC is the location of the #pragma token.
14909 #define OACC_WAIT_CLAUSE_MASK \
14910 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
14913 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
14915 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
14917 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
14918 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
14920 strcpy (p_name
, " wait");
14921 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
14922 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
14929 # pragma omp atomic new-line
14933 x binop= expr | x++ | ++x | x-- | --x
14935 +, *, -, /, &, ^, |, <<, >>
14937 where x is an lvalue expression with scalar type.
14940 # pragma omp atomic new-line
14943 # pragma omp atomic read new-line
14946 # pragma omp atomic write new-line
14949 # pragma omp atomic update new-line
14952 # pragma omp atomic capture new-line
14955 # pragma omp atomic capture new-line
14963 expression-stmt | x = x binop expr
14965 v = expression-stmt
14967 { v = x; update-stmt; } | { update-stmt; v = x; }
14971 expression-stmt | x = x binop expr | x = expr binop x
14975 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
14977 where x and v are lvalue expressions with scalar type.
14979 LOC is the location of the #pragma token. */
14982 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
14984 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
14985 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
14986 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
14987 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
14988 struct c_expr expr
;
14990 bool structured_block
= false;
14991 bool swapped
= false;
14992 bool seq_cst
= false;
14995 if (c_parser_next_token_is (parser
, CPP_NAME
))
14997 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14998 if (!strcmp (p
, "seq_cst"))
15001 c_parser_consume_token (parser
);
15002 if (c_parser_next_token_is (parser
, CPP_COMMA
)
15003 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
15004 c_parser_consume_token (parser
);
15007 if (c_parser_next_token_is (parser
, CPP_NAME
))
15009 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15011 if (!strcmp (p
, "read"))
15012 code
= OMP_ATOMIC_READ
;
15013 else if (!strcmp (p
, "write"))
15015 else if (!strcmp (p
, "update"))
15017 else if (!strcmp (p
, "capture"))
15018 code
= OMP_ATOMIC_CAPTURE_NEW
;
15022 c_parser_consume_token (parser
);
15026 if (c_parser_next_token_is (parser
, CPP_COMMA
)
15027 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
15028 c_parser_consume_token (parser
);
15030 if (c_parser_next_token_is (parser
, CPP_NAME
))
15033 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15034 if (!strcmp (p
, "seq_cst"))
15037 c_parser_consume_token (parser
);
15041 c_parser_skip_to_pragma_eol (parser
);
15045 case OMP_ATOMIC_READ
:
15046 case NOP_EXPR
: /* atomic write */
15047 v
= c_parser_cast_expression (parser
, NULL
).value
;
15048 non_lvalue_p
= !lvalue_p (v
);
15049 v
= c_fully_fold (v
, false, NULL
, true);
15050 if (v
== error_mark_node
)
15053 v
= non_lvalue (v
);
15054 loc
= c_parser_peek_token (parser
)->location
;
15055 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15057 if (code
== NOP_EXPR
)
15059 lhs
= c_parser_expression (parser
).value
;
15060 lhs
= c_fully_fold (lhs
, false, NULL
);
15061 if (lhs
== error_mark_node
)
15066 lhs
= c_parser_cast_expression (parser
, NULL
).value
;
15067 non_lvalue_p
= !lvalue_p (lhs
);
15068 lhs
= c_fully_fold (lhs
, false, NULL
, true);
15069 if (lhs
== error_mark_node
)
15072 lhs
= non_lvalue (lhs
);
15074 if (code
== NOP_EXPR
)
15076 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
15084 case OMP_ATOMIC_CAPTURE_NEW
:
15085 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
15087 c_parser_consume_token (parser
);
15088 structured_block
= true;
15092 v
= c_parser_cast_expression (parser
, NULL
).value
;
15093 non_lvalue_p
= !lvalue_p (v
);
15094 v
= c_fully_fold (v
, false, NULL
, true);
15095 if (v
== error_mark_node
)
15098 v
= non_lvalue (v
);
15099 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15107 /* For structured_block case we don't know yet whether
15108 old or new x should be captured. */
15110 eloc
= c_parser_peek_token (parser
)->location
;
15111 expr
= c_parser_cast_expression (parser
, NULL
);
15113 expr
= default_function_array_conversion (eloc
, expr
);
15114 unfolded_lhs
= expr
.value
;
15115 lhs
= c_fully_fold (lhs
, false, NULL
, true);
15117 switch (TREE_CODE (lhs
))
15121 c_parser_skip_to_end_of_block_or_statement (parser
);
15122 if (structured_block
)
15124 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15125 c_parser_consume_token (parser
);
15126 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
15128 c_parser_skip_to_end_of_block_or_statement (parser
);
15129 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15130 c_parser_consume_token (parser
);
15135 case POSTINCREMENT_EXPR
:
15136 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
15137 code
= OMP_ATOMIC_CAPTURE_OLD
;
15139 case PREINCREMENT_EXPR
:
15140 lhs
= TREE_OPERAND (lhs
, 0);
15141 unfolded_lhs
= NULL_TREE
;
15142 opcode
= PLUS_EXPR
;
15143 rhs
= integer_one_node
;
15146 case POSTDECREMENT_EXPR
:
15147 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
15148 code
= OMP_ATOMIC_CAPTURE_OLD
;
15150 case PREDECREMENT_EXPR
:
15151 lhs
= TREE_OPERAND (lhs
, 0);
15152 unfolded_lhs
= NULL_TREE
;
15153 opcode
= MINUS_EXPR
;
15154 rhs
= integer_one_node
;
15157 case COMPOUND_EXPR
:
15158 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
15159 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
15160 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
15161 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
15162 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
15163 (TREE_OPERAND (lhs
, 1), 0), 0)))
15165 /* Undo effects of boolean_increment for post {in,de}crement. */
15166 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
15169 if (TREE_CODE (lhs
) == MODIFY_EXPR
15170 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
15172 /* Undo effects of boolean_increment. */
15173 if (integer_onep (TREE_OPERAND (lhs
, 1)))
15175 /* This is pre or post increment. */
15176 rhs
= TREE_OPERAND (lhs
, 1);
15177 lhs
= TREE_OPERAND (lhs
, 0);
15178 unfolded_lhs
= NULL_TREE
;
15180 if (code
== OMP_ATOMIC_CAPTURE_NEW
15181 && !structured_block
15182 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
15183 code
= OMP_ATOMIC_CAPTURE_OLD
;
15186 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
15187 && TREE_OPERAND (lhs
, 0)
15188 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
15190 /* This is pre or post decrement. */
15191 rhs
= TREE_OPERAND (lhs
, 1);
15192 lhs
= TREE_OPERAND (lhs
, 0);
15193 unfolded_lhs
= NULL_TREE
;
15195 if (code
== OMP_ATOMIC_CAPTURE_NEW
15196 && !structured_block
15197 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
15198 code
= OMP_ATOMIC_CAPTURE_OLD
;
15204 if (!lvalue_p (unfolded_lhs
))
15205 lhs
= non_lvalue (lhs
);
15206 switch (c_parser_peek_token (parser
)->type
)
15209 opcode
= MULT_EXPR
;
15212 opcode
= TRUNC_DIV_EXPR
;
15215 opcode
= PLUS_EXPR
;
15218 opcode
= MINUS_EXPR
;
15220 case CPP_LSHIFT_EQ
:
15221 opcode
= LSHIFT_EXPR
;
15223 case CPP_RSHIFT_EQ
:
15224 opcode
= RSHIFT_EXPR
;
15227 opcode
= BIT_AND_EXPR
;
15230 opcode
= BIT_IOR_EXPR
;
15233 opcode
= BIT_XOR_EXPR
;
15236 c_parser_consume_token (parser
);
15237 eloc
= c_parser_peek_token (parser
)->location
;
15238 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
15240 switch (TREE_CODE (rhs1
))
15243 case TRUNC_DIV_EXPR
:
15252 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
15254 opcode
= TREE_CODE (rhs1
);
15255 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
,
15257 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
,
15261 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
15263 opcode
= TREE_CODE (rhs1
);
15264 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
,
15266 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
,
15268 swapped
= !commutative_tree_code (opcode
);
15277 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
15279 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
15281 code
= OMP_ATOMIC_CAPTURE_OLD
;
15284 expr
= default_function_array_read_conversion (eloc
, expr
);
15285 unfolded_lhs1
= expr
.value
;
15286 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
, true);
15288 c_parser_consume_token (parser
);
15291 if (structured_block
)
15294 expr
= default_function_array_read_conversion (eloc
, expr
);
15295 rhs
= c_fully_fold (expr
.value
, false, NULL
, true);
15300 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
15303 c_parser_error (parser
,
15304 "invalid operator for %<#pragma omp atomic%>");
15308 /* Arrange to pass the location of the assignment operator to
15309 c_finish_omp_atomic. */
15310 loc
= c_parser_peek_token (parser
)->location
;
15311 c_parser_consume_token (parser
);
15312 eloc
= c_parser_peek_token (parser
)->location
;
15313 expr
= c_parser_expression (parser
);
15314 expr
= default_function_array_read_conversion (eloc
, expr
);
15316 rhs
= c_fully_fold (rhs
, false, NULL
, true);
15320 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
15322 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
15324 v
= c_parser_cast_expression (parser
, NULL
).value
;
15325 non_lvalue_p
= !lvalue_p (v
);
15326 v
= c_fully_fold (v
, false, NULL
, true);
15327 if (v
== error_mark_node
)
15330 v
= non_lvalue (v
);
15331 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15333 eloc
= c_parser_peek_token (parser
)->location
;
15334 expr
= c_parser_cast_expression (parser
, NULL
);
15336 expr
= default_function_array_read_conversion (eloc
, expr
);
15337 unfolded_lhs1
= expr
.value
;
15338 lhs1
= c_fully_fold (lhs1
, false, NULL
, true);
15339 if (lhs1
== error_mark_node
)
15341 if (!lvalue_p (unfolded_lhs1
))
15342 lhs1
= non_lvalue (lhs1
);
15344 if (structured_block
)
15346 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15347 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
15350 if (unfolded_lhs
&& unfolded_lhs1
15351 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
15353 error ("%<#pragma omp atomic capture%> uses two different "
15354 "expressions for memory");
15355 stmt
= error_mark_node
;
15358 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
15360 if (stmt
!= error_mark_node
)
15363 if (!structured_block
)
15364 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15369 # pragma omp barrier new-line
15373 c_parser_omp_barrier (c_parser
*parser
)
15375 location_t loc
= c_parser_peek_token (parser
)->location
;
15376 c_parser_consume_pragma (parser
);
15377 c_parser_skip_to_pragma_eol (parser
);
15379 c_finish_omp_barrier (loc
);
15383 # pragma omp critical [(name)] new-line
15387 # pragma omp critical [(name) [hint(expression)]] new-line
15389 LOC is the location of the #pragma itself. */
15391 #define OMP_CRITICAL_CLAUSE_MASK \
15392 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
15395 c_parser_omp_critical (location_t loc
, c_parser
*parser
, bool *if_p
)
15397 tree stmt
, name
= NULL_TREE
, clauses
= NULL_TREE
;
15399 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
15401 c_parser_consume_token (parser
);
15402 if (c_parser_next_token_is (parser
, CPP_NAME
))
15404 name
= c_parser_peek_token (parser
)->value
;
15405 c_parser_consume_token (parser
);
15406 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
15409 c_parser_error (parser
, "expected identifier");
15411 clauses
= c_parser_omp_all_clauses (parser
,
15412 OMP_CRITICAL_CLAUSE_MASK
,
15413 "#pragma omp critical");
15417 if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15418 c_parser_error (parser
, "expected %<(%> or end of line");
15419 c_parser_skip_to_pragma_eol (parser
);
15422 stmt
= c_parser_omp_structured_block (parser
, if_p
);
15423 return c_finish_omp_critical (loc
, stmt
, name
, clauses
);
15427 # pragma omp flush flush-vars[opt] new-line
15430 ( variable-list ) */
15433 c_parser_omp_flush (c_parser
*parser
)
15435 location_t loc
= c_parser_peek_token (parser
)->location
;
15436 c_parser_consume_pragma (parser
);
15437 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
15438 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
15439 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15440 c_parser_error (parser
, "expected %<(%> or end of line");
15441 c_parser_skip_to_pragma_eol (parser
);
15443 c_finish_omp_flush (loc
);
15446 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
15447 The real trick here is to determine the loop control variable early
15448 so that we can push a new decl if necessary to make it private.
15449 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
15453 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
15454 tree clauses
, tree
*cclauses
, bool *if_p
)
15456 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
15457 tree declv
, condv
, incrv
, initv
, ret
= NULL_TREE
;
15458 tree pre_body
= NULL_TREE
, this_pre_body
;
15459 tree ordered_cl
= NULL_TREE
;
15460 bool fail
= false, open_brace_parsed
= false;
15461 int i
, collapse
= 1, ordered
= 0, count
, nbraces
= 0;
15462 location_t for_loc
;
15463 bool tiling
= false;
15464 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
15466 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
15467 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
15468 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
15469 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_TILE
)
15472 collapse
= list_length (OMP_CLAUSE_TILE_LIST (cl
));
15474 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_ORDERED
15475 && OMP_CLAUSE_ORDERED_EXPR (cl
))
15478 ordered
= tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl
));
15481 if (ordered
&& ordered
< collapse
)
15483 error_at (OMP_CLAUSE_LOCATION (ordered_cl
),
15484 "%<ordered%> clause parameter is less than %<collapse%>");
15485 OMP_CLAUSE_ORDERED_EXPR (ordered_cl
)
15486 = build_int_cst (NULL_TREE
, collapse
);
15487 ordered
= collapse
;
15491 for (tree
*pc
= &clauses
; *pc
; )
15492 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_LINEAR
)
15494 error_at (OMP_CLAUSE_LOCATION (*pc
),
15495 "%<linear%> clause may not be specified together "
15496 "with %<ordered%> clause with a parameter");
15497 *pc
= OMP_CLAUSE_CHAIN (*pc
);
15500 pc
= &OMP_CLAUSE_CHAIN (*pc
);
15503 gcc_assert (tiling
|| (collapse
>= 1 && ordered
>= 0));
15504 count
= ordered
? ordered
: collapse
;
15506 declv
= make_tree_vec (count
);
15507 initv
= make_tree_vec (count
);
15508 condv
= make_tree_vec (count
);
15509 incrv
= make_tree_vec (count
);
15511 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
15513 c_parser_error (parser
, "for statement expected");
15516 for_loc
= c_parser_peek_token (parser
)->location
;
15517 c_parser_consume_token (parser
);
15519 for (i
= 0; i
< count
; i
++)
15521 int bracecount
= 0;
15523 matching_parens parens
;
15524 if (!parens
.require_open (parser
))
15527 /* Parse the initialization declaration or expression. */
15528 if (c_parser_next_tokens_start_declaration (parser
))
15531 vec_safe_push (for_block
, c_begin_compound_stmt (true));
15532 this_pre_body
= push_stmt_list ();
15533 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
15537 this_pre_body
= pop_stmt_list (this_pre_body
);
15541 pre_body
= push_stmt_list ();
15543 add_stmt (this_pre_body
);
15544 pre_body
= pop_stmt_list (pre_body
);
15547 pre_body
= this_pre_body
;
15549 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
15552 if (DECL_INITIAL (decl
) == error_mark_node
)
15553 decl
= error_mark_node
;
15556 else if (c_parser_next_token_is (parser
, CPP_NAME
)
15557 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
15559 struct c_expr decl_exp
;
15560 struct c_expr init_exp
;
15561 location_t init_loc
;
15563 decl_exp
= c_parser_postfix_expression (parser
);
15564 decl
= decl_exp
.value
;
15566 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
15568 init_loc
= c_parser_peek_token (parser
)->location
;
15569 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
15570 init_exp
= default_function_array_read_conversion (init_loc
,
15572 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
15573 NOP_EXPR
, init_loc
, init_exp
.value
,
15574 init_exp
.original_type
);
15575 init
= c_process_expr_stmt (init_loc
, init
);
15577 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15582 c_parser_error (parser
,
15583 "expected iteration declaration or initialization");
15584 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
15590 /* Parse the loop condition. */
15592 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
15594 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
15595 struct c_expr cond_expr
15596 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
15598 cond
= cond_expr
.value
;
15599 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
15600 if (COMPARISON_CLASS_P (cond
))
15602 tree op0
= TREE_OPERAND (cond
, 0), op1
= TREE_OPERAND (cond
, 1);
15603 op0
= c_fully_fold (op0
, false, NULL
);
15604 op1
= c_fully_fold (op1
, false, NULL
);
15605 TREE_OPERAND (cond
, 0) = op0
;
15606 TREE_OPERAND (cond
, 1) = op1
;
15608 switch (cond_expr
.original_code
)
15616 /* Can't be cond = error_mark_node, because we want to preserve
15617 the location until c_finish_omp_for. */
15618 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
15621 protected_set_expr_location (cond
, cond_loc
);
15623 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15625 /* Parse the increment expression. */
15627 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
15629 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
15631 incr
= c_process_expr_stmt (incr_loc
,
15632 c_parser_expression (parser
).value
);
15634 parens
.skip_until_found_close (parser
);
15636 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
15640 TREE_VEC_ELT (declv
, i
) = decl
;
15641 TREE_VEC_ELT (initv
, i
) = init
;
15642 TREE_VEC_ELT (condv
, i
) = cond
;
15643 TREE_VEC_ELT (incrv
, i
) = incr
;
15647 if (i
== count
- 1)
15650 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
15651 in between the collapsed for loops to be still considered perfectly
15652 nested. Hopefully the final version clarifies this.
15653 For now handle (multiple) {'s and empty statements. */
15656 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
15658 c_parser_consume_token (parser
);
15661 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
15663 c_parser_consume_token (parser
);
15666 else if (bracecount
15667 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15668 c_parser_consume_token (parser
);
15671 c_parser_error (parser
, "not enough perfectly nested loops");
15674 open_brace_parsed
= true;
15684 nbraces
+= bracecount
;
15690 save_break
= c_break_label
;
15691 c_break_label
= size_one_node
;
15692 save_cont
= c_cont_label
;
15693 c_cont_label
= NULL_TREE
;
15694 body
= push_stmt_list ();
15696 if (open_brace_parsed
)
15698 location_t here
= c_parser_peek_token (parser
)->location
;
15699 stmt
= c_begin_compound_stmt (true);
15700 c_parser_compound_statement_nostart (parser
);
15701 add_stmt (c_end_compound_stmt (here
, stmt
, true));
15704 add_stmt (c_parser_c99_block_statement (parser
, if_p
));
15707 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
15708 SET_EXPR_LOCATION (t
, loc
);
15712 body
= pop_stmt_list (body
);
15713 c_break_label
= save_break
;
15714 c_cont_label
= save_cont
;
15718 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15720 c_parser_consume_token (parser
);
15723 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15724 c_parser_consume_token (parser
);
15727 c_parser_error (parser
, "collapsed loops not perfectly nested");
15730 location_t here
= c_parser_peek_token (parser
)->location
;
15731 stmt
= c_begin_compound_stmt (true);
15733 c_parser_compound_statement_nostart (parser
);
15734 body
= c_end_compound_stmt (here
, stmt
, true);
15741 /* Only bother calling c_finish_omp_for if we haven't already generated
15742 an error from the initialization parsing. */
15745 stmt
= c_finish_omp_for (loc
, code
, declv
, NULL
, initv
, condv
,
15746 incrv
, body
, pre_body
);
15748 /* Check for iterators appearing in lb, b or incr expressions. */
15749 if (stmt
&& !c_omp_check_loop_iv (stmt
, declv
, NULL
))
15756 if (cclauses
!= NULL
15757 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
15760 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
15761 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
15762 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
15763 c
= &OMP_CLAUSE_CHAIN (*c
);
15766 for (i
= 0; i
< count
; i
++)
15767 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
15770 c
= &OMP_CLAUSE_CHAIN (*c
);
15771 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
15774 "iteration variable %qD should not be firstprivate",
15775 OMP_CLAUSE_DECL (*c
));
15776 *c
= OMP_CLAUSE_CHAIN (*c
);
15780 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
15782 *c
= OMP_CLAUSE_CHAIN (*c
);
15783 if (code
== OMP_SIMD
)
15785 OMP_CLAUSE_CHAIN (l
)
15786 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15787 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
15791 OMP_CLAUSE_CHAIN (l
) = clauses
;
15797 OMP_FOR_CLAUSES (stmt
) = clauses
;
15802 while (!for_block
->is_empty ())
15804 /* FIXME diagnostics: LOC below should be the actual location of
15805 this particular for block. We need to build a list of
15806 locations to go along with FOR_BLOCK. */
15807 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
15810 release_tree_vector (for_block
);
15814 /* Helper function for OpenMP parsing, split clauses and call
15815 finish_omp_clauses on each of the set of clauses afterwards. */
15818 omp_split_clauses (location_t loc
, enum tree_code code
,
15819 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
15822 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
15823 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
15825 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
], C_ORT_OMP
);
15829 #pragma omp simd simd-clause[optseq] new-line
15832 LOC is the location of the #pragma token.
15835 #define OMP_SIMD_CLAUSE_MASK \
15836 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
15837 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
15838 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15839 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
15840 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15841 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15842 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15843 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15846 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
15847 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15850 tree block
, clauses
, ret
;
15852 strcat (p_name
, " simd");
15853 mask
|= OMP_SIMD_CLAUSE_MASK
;
15855 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15858 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
15859 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
15860 tree c
= omp_find_clause (cclauses
[C_OMP_CLAUSE_SPLIT_FOR
],
15861 OMP_CLAUSE_ORDERED
);
15862 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
15864 error_at (OMP_CLAUSE_LOCATION (c
),
15865 "%<ordered%> clause with parameter may not be specified "
15866 "on %qs construct", p_name
);
15867 OMP_CLAUSE_ORDERED_EXPR (c
) = NULL_TREE
;
15871 block
= c_begin_compound_stmt (true);
15872 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
, if_p
);
15873 block
= c_end_compound_stmt (loc
, block
, true);
15880 #pragma omp for for-clause[optseq] new-line
15884 #pragma omp for simd for-simd-clause[optseq] new-line
15887 LOC is the location of the #pragma token.
15890 #define OMP_FOR_CLAUSE_MASK \
15891 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15892 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15893 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15894 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15895 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15896 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
15897 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
15898 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
15899 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15902 c_parser_omp_for (location_t loc
, c_parser
*parser
,
15903 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15906 tree block
, clauses
, ret
;
15908 strcat (p_name
, " for");
15909 mask
|= OMP_FOR_CLAUSE_MASK
;
15910 /* parallel for{, simd} disallows nowait clause, but for
15911 target {teams distribute ,}parallel for{, simd} it should be accepted. */
15912 if (cclauses
&& (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) == 0)
15913 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
15914 /* Composite distribute parallel for{, simd} disallows ordered clause. */
15915 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15916 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
15918 if (c_parser_next_token_is (parser
, CPP_NAME
))
15920 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15922 if (strcmp (p
, "simd") == 0)
15924 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15925 if (cclauses
== NULL
)
15926 cclauses
= cclauses_buf
;
15928 c_parser_consume_token (parser
);
15929 if (!flag_openmp
) /* flag_openmp_simd */
15930 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
15932 block
= c_begin_compound_stmt (true);
15933 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15934 block
= c_end_compound_stmt (loc
, block
, true);
15935 if (ret
== NULL_TREE
)
15937 ret
= make_node (OMP_FOR
);
15938 TREE_TYPE (ret
) = void_type_node
;
15939 OMP_FOR_BODY (ret
) = block
;
15940 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15941 SET_EXPR_LOCATION (ret
, loc
);
15946 if (!flag_openmp
) /* flag_openmp_simd */
15948 c_parser_skip_to_pragma_eol (parser
, false);
15952 /* Composite distribute parallel for disallows linear clause. */
15953 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15954 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINEAR
);
15956 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15959 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
15960 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15963 block
= c_begin_compound_stmt (true);
15964 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
, if_p
);
15965 block
= c_end_compound_stmt (loc
, block
, true);
15972 # pragma omp master new-line
15975 LOC is the location of the #pragma token.
15979 c_parser_omp_master (location_t loc
, c_parser
*parser
, bool *if_p
)
15981 c_parser_skip_to_pragma_eol (parser
);
15982 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
,
15987 # pragma omp ordered new-line
15991 # pragma omp ordered ordered-clauses new-line
15994 # pragma omp ordered depend-clauses new-line */
15996 #define OMP_ORDERED_CLAUSE_MASK \
15997 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
15998 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
16000 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
16001 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
16004 c_parser_omp_ordered (c_parser
*parser
, enum pragma_context context
,
16007 location_t loc
= c_parser_peek_token (parser
)->location
;
16008 c_parser_consume_pragma (parser
);
16010 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
16012 c_parser_error (parser
, "expected declaration specifiers");
16013 c_parser_skip_to_pragma_eol (parser
, false);
16017 if (c_parser_next_token_is (parser
, CPP_NAME
))
16019 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16021 if (!strcmp ("depend", p
))
16023 if (!flag_openmp
) /* flag_openmp_simd */
16025 c_parser_skip_to_pragma_eol (parser
, false);
16028 if (context
== pragma_stmt
)
16031 "%<#pragma omp ordered%> with %<depend%> clause may "
16032 "only be used in compound statements");
16033 c_parser_skip_to_pragma_eol (parser
, false);
16038 = c_parser_omp_all_clauses (parser
,
16039 OMP_ORDERED_DEPEND_CLAUSE_MASK
,
16040 "#pragma omp ordered");
16041 c_finish_omp_ordered (loc
, clauses
, NULL_TREE
);
16046 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_ORDERED_CLAUSE_MASK
,
16047 "#pragma omp ordered");
16049 if (!flag_openmp
/* flag_openmp_simd */
16050 && omp_find_clause (clauses
, OMP_CLAUSE_SIMD
) == NULL_TREE
)
16053 c_finish_omp_ordered (loc
, clauses
,
16054 c_parser_omp_structured_block (parser
, if_p
));
16061 { section-sequence }
16064 section-directive[opt] structured-block
16065 section-sequence section-directive structured-block
16067 SECTIONS_LOC is the location of the #pragma omp sections. */
16070 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
16072 tree stmt
, substmt
;
16073 bool error_suppress
= false;
16076 loc
= c_parser_peek_token (parser
)->location
;
16077 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
16079 /* Avoid skipping until the end of the block. */
16080 parser
->error
= false;
16084 stmt
= push_stmt_list ();
16086 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
16088 substmt
= c_parser_omp_structured_block (parser
, NULL
);
16089 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
16090 SET_EXPR_LOCATION (substmt
, loc
);
16091 add_stmt (substmt
);
16096 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
16098 if (c_parser_next_token_is (parser
, CPP_EOF
))
16101 loc
= c_parser_peek_token (parser
)->location
;
16102 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
16104 c_parser_consume_pragma (parser
);
16105 c_parser_skip_to_pragma_eol (parser
);
16106 error_suppress
= false;
16108 else if (!error_suppress
)
16110 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
16111 error_suppress
= true;
16114 substmt
= c_parser_omp_structured_block (parser
, NULL
);
16115 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
16116 SET_EXPR_LOCATION (substmt
, loc
);
16117 add_stmt (substmt
);
16119 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
16120 "expected %<#pragma omp section%> or %<}%>");
16122 substmt
= pop_stmt_list (stmt
);
16124 stmt
= make_node (OMP_SECTIONS
);
16125 SET_EXPR_LOCATION (stmt
, sections_loc
);
16126 TREE_TYPE (stmt
) = void_type_node
;
16127 OMP_SECTIONS_BODY (stmt
) = substmt
;
16129 return add_stmt (stmt
);
16133 # pragma omp sections sections-clause[optseq] newline
16136 LOC is the location of the #pragma token.
16139 #define OMP_SECTIONS_CLAUSE_MASK \
16140 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16141 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16142 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16143 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16144 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16147 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
16148 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
16150 tree block
, clauses
, ret
;
16152 strcat (p_name
, " sections");
16153 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
16155 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
16157 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16160 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
16161 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
16164 block
= c_begin_compound_stmt (true);
16165 ret
= c_parser_omp_sections_scope (loc
, parser
);
16167 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
16168 block
= c_end_compound_stmt (loc
, block
, true);
16175 # pragma omp parallel parallel-clause[optseq] new-line
16177 # pragma omp parallel for parallel-for-clause[optseq] new-line
16179 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
16183 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
16186 LOC is the location of the #pragma token.
16189 #define OMP_PARALLEL_CLAUSE_MASK \
16190 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16191 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16192 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16193 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
16194 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16195 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
16196 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16197 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
16198 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
16201 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
16202 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16205 tree stmt
, clauses
, block
;
16207 strcat (p_name
, " parallel");
16208 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
16209 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
16210 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) != 0
16211 && (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) == 0)
16212 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_COPYIN
);
16214 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
16216 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16217 if (cclauses
== NULL
)
16218 cclauses
= cclauses_buf
;
16220 c_parser_consume_token (parser
);
16221 if (!flag_openmp
) /* flag_openmp_simd */
16222 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
16223 block
= c_begin_omp_parallel ();
16224 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
16226 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
16228 if (ret
== NULL_TREE
)
16230 OMP_PARALLEL_COMBINED (stmt
) = 1;
16233 /* When combined with distribute, parallel has to be followed by for.
16234 #pragma omp target parallel is allowed though. */
16236 && (mask
& (OMP_CLAUSE_MASK_1
16237 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
16239 error_at (loc
, "expected %<for%> after %qs", p_name
);
16240 c_parser_skip_to_pragma_eol (parser
);
16243 else if (!flag_openmp
) /* flag_openmp_simd */
16245 c_parser_skip_to_pragma_eol (parser
, false);
16248 else if (cclauses
== NULL
&& c_parser_next_token_is (parser
, CPP_NAME
))
16250 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16251 if (strcmp (p
, "sections") == 0)
16253 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16254 if (cclauses
== NULL
)
16255 cclauses
= cclauses_buf
;
16257 c_parser_consume_token (parser
);
16258 block
= c_begin_omp_parallel ();
16259 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
16260 stmt
= c_finish_omp_parallel (loc
,
16261 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
16263 OMP_PARALLEL_COMBINED (stmt
) = 1;
16268 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16271 omp_split_clauses (loc
, OMP_PARALLEL
, mask
, clauses
, cclauses
);
16272 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
16275 block
= c_begin_omp_parallel ();
16276 c_parser_statement (parser
, if_p
);
16277 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
16283 # pragma omp single single-clause[optseq] new-line
16286 LOC is the location of the #pragma.
16289 #define OMP_SINGLE_CLAUSE_MASK \
16290 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16291 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16292 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
16293 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16296 c_parser_omp_single (location_t loc
, c_parser
*parser
, bool *if_p
)
16298 tree stmt
= make_node (OMP_SINGLE
);
16299 SET_EXPR_LOCATION (stmt
, loc
);
16300 TREE_TYPE (stmt
) = void_type_node
;
16302 OMP_SINGLE_CLAUSES (stmt
)
16303 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
16304 "#pragma omp single");
16305 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
16307 return add_stmt (stmt
);
16311 # pragma omp task task-clause[optseq] new-line
16313 LOC is the location of the #pragma.
16316 #define OMP_TASK_CLAUSE_MASK \
16317 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16318 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
16319 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
16320 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16321 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16322 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16323 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
16324 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
16325 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16326 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
16329 c_parser_omp_task (location_t loc
, c_parser
*parser
, bool *if_p
)
16331 tree clauses
, block
;
16333 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
16334 "#pragma omp task");
16336 block
= c_begin_omp_task ();
16337 c_parser_statement (parser
, if_p
);
16338 return c_finish_omp_task (loc
, clauses
, block
);
16342 # pragma omp taskwait new-line
16346 c_parser_omp_taskwait (c_parser
*parser
)
16348 location_t loc
= c_parser_peek_token (parser
)->location
;
16349 c_parser_consume_pragma (parser
);
16350 c_parser_skip_to_pragma_eol (parser
);
16352 c_finish_omp_taskwait (loc
);
16356 # pragma omp taskyield new-line
16360 c_parser_omp_taskyield (c_parser
*parser
)
16362 location_t loc
= c_parser_peek_token (parser
)->location
;
16363 c_parser_consume_pragma (parser
);
16364 c_parser_skip_to_pragma_eol (parser
);
16366 c_finish_omp_taskyield (loc
);
16370 # pragma omp taskgroup new-line
16374 c_parser_omp_taskgroup (c_parser
*parser
, bool *if_p
)
16376 location_t loc
= c_parser_peek_token (parser
)->location
;
16377 c_parser_skip_to_pragma_eol (parser
);
16378 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
,
16383 # pragma omp cancel cancel-clause[optseq] new-line
16385 LOC is the location of the #pragma.
16388 #define OMP_CANCEL_CLAUSE_MASK \
16389 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
16390 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
16391 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
16392 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
16393 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
16396 c_parser_omp_cancel (c_parser
*parser
)
16398 location_t loc
= c_parser_peek_token (parser
)->location
;
16400 c_parser_consume_pragma (parser
);
16401 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
16402 "#pragma omp cancel");
16404 c_finish_omp_cancel (loc
, clauses
);
16408 # pragma omp cancellation point cancelpt-clause[optseq] new-line
16410 LOC is the location of the #pragma.
16413 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
16414 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
16415 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
16416 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
16417 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
16420 c_parser_omp_cancellation_point (c_parser
*parser
, enum pragma_context context
)
16422 location_t loc
= c_parser_peek_token (parser
)->location
;
16424 bool point_seen
= false;
16426 c_parser_consume_pragma (parser
);
16427 if (c_parser_next_token_is (parser
, CPP_NAME
))
16429 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16430 if (strcmp (p
, "point") == 0)
16432 c_parser_consume_token (parser
);
16438 c_parser_error (parser
, "expected %<point%>");
16439 c_parser_skip_to_pragma_eol (parser
);
16443 if (context
!= pragma_compound
)
16445 if (context
== pragma_stmt
)
16447 "%<#pragma %s%> may only be used in compound statements",
16448 "omp cancellation point");
16450 c_parser_error (parser
, "expected declaration specifiers");
16451 c_parser_skip_to_pragma_eol (parser
, false);
16456 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
16457 "#pragma omp cancellation point");
16459 c_finish_omp_cancellation_point (loc
, clauses
);
16463 #pragma omp distribute distribute-clause[optseq] new-line
16466 #define OMP_DISTRIBUTE_CLAUSE_MASK \
16467 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16468 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16469 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16470 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
16471 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
16474 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
16475 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16478 tree clauses
, block
, ret
;
16480 strcat (p_name
, " distribute");
16481 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
16483 if (c_parser_next_token_is (parser
, CPP_NAME
))
16485 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16487 bool parallel
= false;
16489 if (strcmp (p
, "simd") == 0)
16492 parallel
= strcmp (p
, "parallel") == 0;
16493 if (parallel
|| simd
)
16495 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16496 if (cclauses
== NULL
)
16497 cclauses
= cclauses_buf
;
16498 c_parser_consume_token (parser
);
16499 if (!flag_openmp
) /* flag_openmp_simd */
16502 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16505 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
16508 block
= c_begin_compound_stmt (true);
16510 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16513 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
,
16515 block
= c_end_compound_stmt (loc
, block
, true);
16518 ret
= make_node (OMP_DISTRIBUTE
);
16519 TREE_TYPE (ret
) = void_type_node
;
16520 OMP_FOR_BODY (ret
) = block
;
16521 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
16522 SET_EXPR_LOCATION (ret
, loc
);
16527 if (!flag_openmp
) /* flag_openmp_simd */
16529 c_parser_skip_to_pragma_eol (parser
, false);
16533 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16536 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
16537 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
16540 block
= c_begin_compound_stmt (true);
16541 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
,
16543 block
= c_end_compound_stmt (loc
, block
, true);
16550 # pragma omp teams teams-clause[optseq] new-line
16551 structured-block */
16553 #define OMP_TEAMS_CLAUSE_MASK \
16554 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16555 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16556 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16557 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16558 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
16559 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
16560 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
16563 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
16564 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16567 tree clauses
, block
, ret
;
16569 strcat (p_name
, " teams");
16570 mask
|= OMP_TEAMS_CLAUSE_MASK
;
16572 if (c_parser_next_token_is (parser
, CPP_NAME
))
16574 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16575 if (strcmp (p
, "distribute") == 0)
16577 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16578 if (cclauses
== NULL
)
16579 cclauses
= cclauses_buf
;
16581 c_parser_consume_token (parser
);
16582 if (!flag_openmp
) /* flag_openmp_simd */
16583 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
,
16585 block
= c_begin_compound_stmt (true);
16586 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
,
16588 block
= c_end_compound_stmt (loc
, block
, true);
16591 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16592 ret
= make_node (OMP_TEAMS
);
16593 TREE_TYPE (ret
) = void_type_node
;
16594 OMP_TEAMS_CLAUSES (ret
) = clauses
;
16595 OMP_TEAMS_BODY (ret
) = block
;
16596 OMP_TEAMS_COMBINED (ret
) = 1;
16597 return add_stmt (ret
);
16600 if (!flag_openmp
) /* flag_openmp_simd */
16602 c_parser_skip_to_pragma_eol (parser
, false);
16606 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16609 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
16610 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16613 tree stmt
= make_node (OMP_TEAMS
);
16614 TREE_TYPE (stmt
) = void_type_node
;
16615 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
16616 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
16618 return add_stmt (stmt
);
16622 # pragma omp target data target-data-clause[optseq] new-line
16623 structured-block */
16625 #define OMP_TARGET_DATA_CLAUSE_MASK \
16626 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16627 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16628 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16629 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
16632 c_parser_omp_target_data (location_t loc
, c_parser
*parser
, bool *if_p
)
16635 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
16636 "#pragma omp target data");
16638 for (tree
*pc
= &clauses
; *pc
;)
16640 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16641 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16644 case GOMP_MAP_ALWAYS_TO
:
16645 case GOMP_MAP_FROM
:
16646 case GOMP_MAP_ALWAYS_FROM
:
16647 case GOMP_MAP_TOFROM
:
16648 case GOMP_MAP_ALWAYS_TOFROM
:
16649 case GOMP_MAP_ALLOC
:
16652 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16653 case GOMP_MAP_ALWAYS_POINTER
:
16657 error_at (OMP_CLAUSE_LOCATION (*pc
),
16658 "%<#pragma omp target data%> with map-type other "
16659 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16660 "on %<map%> clause");
16661 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16664 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16671 "%<#pragma omp target data%> must contain at least "
16672 "one %<map%> clause");
16676 tree stmt
= make_node (OMP_TARGET_DATA
);
16677 TREE_TYPE (stmt
) = void_type_node
;
16678 OMP_TARGET_DATA_CLAUSES (stmt
) = clauses
;
16679 keep_next_level ();
16680 tree block
= c_begin_compound_stmt (true);
16681 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
16682 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
16684 SET_EXPR_LOCATION (stmt
, loc
);
16685 return add_stmt (stmt
);
16689 # pragma omp target update target-update-clause[optseq] new-line */
16691 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
16692 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
16693 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16694 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16695 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16696 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16697 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16700 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
16701 enum pragma_context context
)
16703 if (context
== pragma_stmt
)
16705 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
16706 "omp target update");
16707 c_parser_skip_to_pragma_eol (parser
, false);
16712 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
16713 "#pragma omp target update");
16714 if (omp_find_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
16715 && omp_find_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
16718 "%<#pragma omp target update%> must contain at least one "
16719 "%<from%> or %<to%> clauses");
16723 tree stmt
= make_node (OMP_TARGET_UPDATE
);
16724 TREE_TYPE (stmt
) = void_type_node
;
16725 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
16726 SET_EXPR_LOCATION (stmt
, loc
);
16732 # pragma omp target enter data target-data-clause[optseq] new-line */
16734 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
16735 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16736 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16737 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16738 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16739 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16742 c_parser_omp_target_enter_data (location_t loc
, c_parser
*parser
,
16743 enum pragma_context context
)
16745 bool data_seen
= false;
16746 if (c_parser_next_token_is (parser
, CPP_NAME
))
16748 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16749 if (strcmp (p
, "data") == 0)
16751 c_parser_consume_token (parser
);
16757 c_parser_error (parser
, "expected %<data%>");
16758 c_parser_skip_to_pragma_eol (parser
);
16762 if (context
== pragma_stmt
)
16764 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
16765 "omp target enter data");
16766 c_parser_skip_to_pragma_eol (parser
, false);
16771 = c_parser_omp_all_clauses (parser
, OMP_TARGET_ENTER_DATA_CLAUSE_MASK
,
16772 "#pragma omp target enter data");
16774 for (tree
*pc
= &clauses
; *pc
;)
16776 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16777 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16780 case GOMP_MAP_ALWAYS_TO
:
16781 case GOMP_MAP_ALLOC
:
16784 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16785 case GOMP_MAP_ALWAYS_POINTER
:
16789 error_at (OMP_CLAUSE_LOCATION (*pc
),
16790 "%<#pragma omp target enter data%> with map-type other "
16791 "than %<to%> or %<alloc%> on %<map%> clause");
16792 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16795 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16802 "%<#pragma omp target enter data%> must contain at least "
16803 "one %<map%> clause");
16807 tree stmt
= make_node (OMP_TARGET_ENTER_DATA
);
16808 TREE_TYPE (stmt
) = void_type_node
;
16809 OMP_TARGET_ENTER_DATA_CLAUSES (stmt
) = clauses
;
16810 SET_EXPR_LOCATION (stmt
, loc
);
16816 # pragma omp target exit data target-data-clause[optseq] new-line */
16818 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
16819 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16820 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16821 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16822 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16823 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16826 c_parser_omp_target_exit_data (location_t loc
, c_parser
*parser
,
16827 enum pragma_context context
)
16829 bool data_seen
= false;
16830 if (c_parser_next_token_is (parser
, CPP_NAME
))
16832 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16833 if (strcmp (p
, "data") == 0)
16835 c_parser_consume_token (parser
);
16841 c_parser_error (parser
, "expected %<data%>");
16842 c_parser_skip_to_pragma_eol (parser
);
16846 if (context
== pragma_stmt
)
16848 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
16849 "omp target exit data");
16850 c_parser_skip_to_pragma_eol (parser
, false);
16855 = c_parser_omp_all_clauses (parser
, OMP_TARGET_EXIT_DATA_CLAUSE_MASK
,
16856 "#pragma omp target exit data");
16859 for (tree
*pc
= &clauses
; *pc
;)
16861 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16862 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16864 case GOMP_MAP_FROM
:
16865 case GOMP_MAP_ALWAYS_FROM
:
16866 case GOMP_MAP_RELEASE
:
16867 case GOMP_MAP_DELETE
:
16870 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16871 case GOMP_MAP_ALWAYS_POINTER
:
16875 error_at (OMP_CLAUSE_LOCATION (*pc
),
16876 "%<#pragma omp target exit data%> with map-type other "
16877 "than %<from%>, %<release%> or %<delete%> on %<map%>"
16879 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16882 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16889 "%<#pragma omp target exit data%> must contain at least one "
16894 tree stmt
= make_node (OMP_TARGET_EXIT_DATA
);
16895 TREE_TYPE (stmt
) = void_type_node
;
16896 OMP_TARGET_EXIT_DATA_CLAUSES (stmt
) = clauses
;
16897 SET_EXPR_LOCATION (stmt
, loc
);
16903 # pragma omp target target-clause[optseq] new-line
16904 structured-block */
16906 #define OMP_TARGET_CLAUSE_MASK \
16907 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16908 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16909 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16910 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16911 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
16912 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16913 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16914 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
16915 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
16918 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
16920 location_t loc
= c_parser_peek_token (parser
)->location
;
16921 c_parser_consume_pragma (parser
);
16922 tree
*pc
= NULL
, stmt
, block
;
16924 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
16926 c_parser_error (parser
, "expected declaration specifiers");
16927 c_parser_skip_to_pragma_eol (parser
);
16931 if (c_parser_next_token_is (parser
, CPP_NAME
))
16933 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16934 enum tree_code ccode
= ERROR_MARK
;
16936 if (strcmp (p
, "teams") == 0)
16938 else if (strcmp (p
, "parallel") == 0)
16939 ccode
= OMP_PARALLEL
;
16940 else if (strcmp (p
, "simd") == 0)
16942 if (ccode
!= ERROR_MARK
)
16944 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
16945 char p_name
[sizeof ("#pragma omp target teams distribute "
16946 "parallel for simd")];
16948 c_parser_consume_token (parser
);
16949 strcpy (p_name
, "#pragma omp target");
16950 if (!flag_openmp
) /* flag_openmp_simd */
16956 stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
16957 OMP_TARGET_CLAUSE_MASK
,
16961 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
,
16962 OMP_TARGET_CLAUSE_MASK
,
16966 stmt
= c_parser_omp_simd (loc
, parser
, p_name
,
16967 OMP_TARGET_CLAUSE_MASK
,
16971 gcc_unreachable ();
16973 return stmt
!= NULL_TREE
;
16975 keep_next_level ();
16976 tree block
= c_begin_compound_stmt (true), ret
;
16980 ret
= c_parser_omp_teams (loc
, parser
, p_name
,
16981 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16985 ret
= c_parser_omp_parallel (loc
, parser
, p_name
,
16986 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16990 ret
= c_parser_omp_simd (loc
, parser
, p_name
,
16991 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16995 gcc_unreachable ();
16997 block
= c_end_compound_stmt (loc
, block
, true);
16998 if (ret
== NULL_TREE
)
17000 if (ccode
== OMP_TEAMS
)
17002 /* For combined target teams, ensure the num_teams and
17003 thread_limit clause expressions are evaluated on the host,
17004 before entering the target construct. */
17006 for (c
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
17007 c
; c
= OMP_CLAUSE_CHAIN (c
))
17008 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
17009 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
17010 && TREE_CODE (OMP_CLAUSE_OPERAND (c
, 0)) != INTEGER_CST
)
17012 tree expr
= OMP_CLAUSE_OPERAND (c
, 0);
17013 tree tmp
= create_tmp_var_raw (TREE_TYPE (expr
));
17014 expr
= build4 (TARGET_EXPR
, TREE_TYPE (expr
), tmp
,
17015 expr
, NULL_TREE
, NULL_TREE
);
17017 OMP_CLAUSE_OPERAND (c
, 0) = expr
;
17018 tree tc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
17019 OMP_CLAUSE_FIRSTPRIVATE
);
17020 OMP_CLAUSE_DECL (tc
) = tmp
;
17021 OMP_CLAUSE_CHAIN (tc
)
17022 = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
17023 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = tc
;
17026 tree stmt
= make_node (OMP_TARGET
);
17027 TREE_TYPE (stmt
) = void_type_node
;
17028 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
17029 OMP_TARGET_BODY (stmt
) = block
;
17030 OMP_TARGET_COMBINED (stmt
) = 1;
17032 pc
= &OMP_TARGET_CLAUSES (stmt
);
17033 goto check_clauses
;
17035 else if (!flag_openmp
) /* flag_openmp_simd */
17037 c_parser_skip_to_pragma_eol (parser
, false);
17040 else if (strcmp (p
, "data") == 0)
17042 c_parser_consume_token (parser
);
17043 c_parser_omp_target_data (loc
, parser
, if_p
);
17046 else if (strcmp (p
, "enter") == 0)
17048 c_parser_consume_token (parser
);
17049 c_parser_omp_target_enter_data (loc
, parser
, context
);
17052 else if (strcmp (p
, "exit") == 0)
17054 c_parser_consume_token (parser
);
17055 c_parser_omp_target_exit_data (loc
, parser
, context
);
17058 else if (strcmp (p
, "update") == 0)
17060 c_parser_consume_token (parser
);
17061 return c_parser_omp_target_update (loc
, parser
, context
);
17064 if (!flag_openmp
) /* flag_openmp_simd */
17066 c_parser_skip_to_pragma_eol (parser
, false);
17070 stmt
= make_node (OMP_TARGET
);
17071 TREE_TYPE (stmt
) = void_type_node
;
17073 OMP_TARGET_CLAUSES (stmt
)
17074 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
17075 "#pragma omp target");
17076 pc
= &OMP_TARGET_CLAUSES (stmt
);
17077 keep_next_level ();
17078 block
= c_begin_compound_stmt (true);
17079 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
17080 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
17082 SET_EXPR_LOCATION (stmt
, loc
);
17088 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
17089 switch (OMP_CLAUSE_MAP_KIND (*pc
))
17092 case GOMP_MAP_ALWAYS_TO
:
17093 case GOMP_MAP_FROM
:
17094 case GOMP_MAP_ALWAYS_FROM
:
17095 case GOMP_MAP_TOFROM
:
17096 case GOMP_MAP_ALWAYS_TOFROM
:
17097 case GOMP_MAP_ALLOC
:
17098 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
17099 case GOMP_MAP_ALWAYS_POINTER
:
17102 error_at (OMP_CLAUSE_LOCATION (*pc
),
17103 "%<#pragma omp target%> with map-type other "
17104 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
17105 "on %<map%> clause");
17106 *pc
= OMP_CLAUSE_CHAIN (*pc
);
17109 pc
= &OMP_CLAUSE_CHAIN (*pc
);
17115 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
17117 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
17118 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
17119 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
17120 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
17121 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
17122 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
17123 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
17126 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
17128 auto_vec
<c_token
> clauses
;
17129 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17131 c_token
*token
= c_parser_peek_token (parser
);
17132 if (token
->type
== CPP_EOF
)
17134 c_parser_skip_to_pragma_eol (parser
);
17137 clauses
.safe_push (*token
);
17138 c_parser_consume_token (parser
);
17140 clauses
.safe_push (*c_parser_peek_token (parser
));
17141 c_parser_skip_to_pragma_eol (parser
);
17143 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
17145 if (c_parser_peek_token (parser
)->pragma_kind
17146 != PRAGMA_OMP_DECLARE
17147 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
17148 || strcmp (IDENTIFIER_POINTER
17149 (c_parser_peek_2nd_token (parser
)->value
),
17152 c_parser_error (parser
,
17153 "%<#pragma omp declare simd%> must be followed by "
17154 "function declaration or definition or another "
17155 "%<#pragma omp declare simd%>");
17158 c_parser_consume_pragma (parser
);
17159 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17161 c_token
*token
= c_parser_peek_token (parser
);
17162 if (token
->type
== CPP_EOF
)
17164 c_parser_skip_to_pragma_eol (parser
);
17167 clauses
.safe_push (*token
);
17168 c_parser_consume_token (parser
);
17170 clauses
.safe_push (*c_parser_peek_token (parser
));
17171 c_parser_skip_to_pragma_eol (parser
);
17174 /* Make sure nothing tries to read past the end of the tokens. */
17176 memset (&eof_token
, 0, sizeof (eof_token
));
17177 eof_token
.type
= CPP_EOF
;
17178 clauses
.safe_push (eof_token
);
17179 clauses
.safe_push (eof_token
);
17183 case pragma_external
:
17184 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17185 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
17187 int ext
= disable_extension_diagnostics ();
17189 c_parser_consume_token (parser
);
17190 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17191 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
17192 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
17194 restore_extension_diagnostics (ext
);
17197 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
17200 case pragma_struct
:
17203 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
17204 "function declaration or definition");
17206 case pragma_compound
:
17207 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17208 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
17210 int ext
= disable_extension_diagnostics ();
17212 c_parser_consume_token (parser
);
17213 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17214 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
17215 if (c_parser_next_tokens_start_declaration (parser
))
17217 c_parser_declaration_or_fndef (parser
, true, true, true, true,
17218 true, NULL
, clauses
);
17219 restore_extension_diagnostics (ext
);
17222 restore_extension_diagnostics (ext
);
17224 else if (c_parser_next_tokens_start_declaration (parser
))
17226 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
17230 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
17231 "function declaration or definition");
17234 gcc_unreachable ();
17238 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
17239 and put that into "omp declare simd" attribute. */
17242 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
17243 vec
<c_token
> clauses
)
17245 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
17246 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
17247 has already processed the tokens. */
17248 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
17250 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
17252 error ("%<#pragma omp declare simd%> not immediately followed by "
17253 "a function declaration or definition");
17254 clauses
[0].type
= CPP_EOF
;
17257 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
17259 error_at (DECL_SOURCE_LOCATION (fndecl
),
17260 "%<#pragma omp declare simd%> not immediately followed by "
17261 "a single function declaration or definition");
17262 clauses
[0].type
= CPP_EOF
;
17266 if (parms
== NULL_TREE
)
17267 parms
= DECL_ARGUMENTS (fndecl
);
17269 unsigned int tokens_avail
= parser
->tokens_avail
;
17270 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
17273 parser
->tokens
= clauses
.address ();
17274 parser
->tokens_avail
= clauses
.length ();
17276 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
17277 while (parser
->tokens_avail
> 3)
17279 c_token
*token
= c_parser_peek_token (parser
);
17280 gcc_assert (token
->type
== CPP_NAME
17281 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
17282 c_parser_consume_token (parser
);
17283 parser
->in_pragma
= true;
17285 tree c
= NULL_TREE
;
17286 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
17287 "#pragma omp declare simd");
17288 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
17289 if (c
!= NULL_TREE
)
17290 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
17291 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
17292 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
17293 DECL_ATTRIBUTES (fndecl
) = c
;
17296 parser
->tokens
= &parser
->tokens_buf
[0];
17297 parser
->tokens_avail
= tokens_avail
;
17298 if (clauses
.exists ())
17299 clauses
[0].type
= CPP_PRAGMA
;
17304 # pragma omp declare target new-line
17305 declarations and definitions
17306 # pragma omp end declare target new-line
17309 # pragma omp declare target ( extended-list ) new-line
17311 # pragma omp declare target declare-target-clauses[seq] new-line */
17313 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
17314 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
17315 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
17318 c_parser_omp_declare_target (c_parser
*parser
)
17320 location_t loc
= c_parser_peek_token (parser
)->location
;
17321 tree clauses
= NULL_TREE
;
17322 if (c_parser_next_token_is (parser
, CPP_NAME
))
17323 clauses
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_TARGET_CLAUSE_MASK
,
17324 "#pragma omp declare target");
17325 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
17327 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
17329 clauses
= c_finish_omp_clauses (clauses
, C_ORT_OMP
);
17330 c_parser_skip_to_pragma_eol (parser
);
17334 c_parser_skip_to_pragma_eol (parser
);
17335 current_omp_declare_target_attribute
++;
17338 if (current_omp_declare_target_attribute
)
17339 error_at (loc
, "%<#pragma omp declare target%> with clauses in between "
17340 "%<#pragma omp declare target%> without clauses and "
17341 "%<#pragma omp end declare target%>");
17342 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
17344 tree t
= OMP_CLAUSE_DECL (c
), id
;
17345 tree at1
= lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t
));
17346 tree at2
= lookup_attribute ("omp declare target link",
17347 DECL_ATTRIBUTES (t
));
17348 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINK
)
17350 id
= get_identifier ("omp declare target link");
17351 std::swap (at1
, at2
);
17354 id
= get_identifier ("omp declare target");
17357 error_at (OMP_CLAUSE_LOCATION (c
),
17358 "%qD specified both in declare target %<link%> and %<to%>"
17364 DECL_ATTRIBUTES (t
) = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (t
));
17365 if (TREE_CODE (t
) != FUNCTION_DECL
&& !is_global_var (t
))
17368 symtab_node
*node
= symtab_node::get (t
);
17371 node
->offloadable
= 1;
17372 if (ENABLE_OFFLOADING
)
17374 g
->have_offload
= true;
17375 if (is_a
<varpool_node
*> (node
))
17376 vec_safe_push (offload_vars
, t
);
17384 c_parser_omp_end_declare_target (c_parser
*parser
)
17386 location_t loc
= c_parser_peek_token (parser
)->location
;
17387 c_parser_consume_pragma (parser
);
17388 if (c_parser_next_token_is (parser
, CPP_NAME
)
17389 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
17392 c_parser_consume_token (parser
);
17393 if (c_parser_next_token_is (parser
, CPP_NAME
)
17394 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
17396 c_parser_consume_token (parser
);
17399 c_parser_error (parser
, "expected %<target%>");
17400 c_parser_skip_to_pragma_eol (parser
);
17406 c_parser_error (parser
, "expected %<declare%>");
17407 c_parser_skip_to_pragma_eol (parser
);
17410 c_parser_skip_to_pragma_eol (parser
);
17411 if (!current_omp_declare_target_attribute
)
17412 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
17413 "%<#pragma omp declare target%>");
17415 current_omp_declare_target_attribute
--;
17420 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17421 initializer-clause[opt] new-line
17423 initializer-clause:
17424 initializer (omp_priv = initializer)
17425 initializer (function-name (argument-list)) */
17428 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
17430 unsigned int tokens_avail
= 0, i
;
17431 vec
<tree
> types
= vNULL
;
17432 vec
<c_token
> clauses
= vNULL
;
17433 enum tree_code reduc_code
= ERROR_MARK
;
17434 tree reduc_id
= NULL_TREE
;
17436 location_t rloc
= c_parser_peek_token (parser
)->location
;
17438 if (context
== pragma_struct
|| context
== pragma_param
)
17440 error ("%<#pragma omp declare reduction%> not at file or block scope");
17444 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17447 switch (c_parser_peek_token (parser
)->type
)
17450 reduc_code
= PLUS_EXPR
;
17453 reduc_code
= MULT_EXPR
;
17456 reduc_code
= MINUS_EXPR
;
17459 reduc_code
= BIT_AND_EXPR
;
17462 reduc_code
= BIT_XOR_EXPR
;
17465 reduc_code
= BIT_IOR_EXPR
;
17468 reduc_code
= TRUTH_ANDIF_EXPR
;
17471 reduc_code
= TRUTH_ORIF_EXPR
;
17475 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17476 if (strcmp (p
, "min") == 0)
17478 reduc_code
= MIN_EXPR
;
17481 if (strcmp (p
, "max") == 0)
17483 reduc_code
= MAX_EXPR
;
17486 reduc_id
= c_parser_peek_token (parser
)->value
;
17489 c_parser_error (parser
,
17490 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
17491 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
17495 tree orig_reduc_id
, reduc_decl
;
17496 orig_reduc_id
= reduc_id
;
17497 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
17498 reduc_decl
= c_omp_reduction_decl (reduc_id
);
17499 c_parser_consume_token (parser
);
17501 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
17506 location_t loc
= c_parser_peek_token (parser
)->location
;
17507 struct c_type_name
*ctype
= c_parser_type_name (parser
);
17510 type
= groktypename (ctype
, NULL
, NULL
);
17511 if (type
== error_mark_node
)
17513 else if ((INTEGRAL_TYPE_P (type
)
17514 || TREE_CODE (type
) == REAL_TYPE
17515 || TREE_CODE (type
) == COMPLEX_TYPE
)
17516 && orig_reduc_id
== NULL_TREE
)
17517 error_at (loc
, "predeclared arithmetic type in "
17518 "%<#pragma omp declare reduction%>");
17519 else if (TREE_CODE (type
) == FUNCTION_TYPE
17520 || TREE_CODE (type
) == ARRAY_TYPE
)
17521 error_at (loc
, "function or array type in "
17522 "%<#pragma omp declare reduction%>");
17523 else if (TYPE_ATOMIC (type
))
17524 error_at (loc
, "%<_Atomic%> qualified type in "
17525 "%<#pragma omp declare reduction%>");
17526 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
17527 error_at (loc
, "const, volatile or restrict qualified type in "
17528 "%<#pragma omp declare reduction%>");
17532 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
17533 if (comptypes (TREE_PURPOSE (t
), type
))
17535 error_at (loc
, "redeclaration of %qs "
17536 "%<#pragma omp declare reduction%> for "
17538 IDENTIFIER_POINTER (reduc_id
)
17539 + sizeof ("omp declare reduction ") - 1,
17542 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
17544 error_at (ploc
, "previous %<#pragma omp declare "
17548 if (t
== NULL_TREE
)
17549 types
.safe_push (type
);
17551 if (c_parser_next_token_is (parser
, CPP_COMMA
))
17552 c_parser_consume_token (parser
);
17560 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
17561 || types
.is_empty ())
17564 clauses
.release ();
17568 c_token
*token
= c_parser_peek_token (parser
);
17569 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
17571 c_parser_consume_token (parser
);
17573 c_parser_skip_to_pragma_eol (parser
);
17577 if (types
.length () > 1)
17579 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17581 c_token
*token
= c_parser_peek_token (parser
);
17582 if (token
->type
== CPP_EOF
)
17584 clauses
.safe_push (*token
);
17585 c_parser_consume_token (parser
);
17587 clauses
.safe_push (*c_parser_peek_token (parser
));
17588 c_parser_skip_to_pragma_eol (parser
);
17590 /* Make sure nothing tries to read past the end of the tokens. */
17592 memset (&eof_token
, 0, sizeof (eof_token
));
17593 eof_token
.type
= CPP_EOF
;
17594 clauses
.safe_push (eof_token
);
17595 clauses
.safe_push (eof_token
);
17598 int errs
= errorcount
;
17599 FOR_EACH_VEC_ELT (types
, i
, type
)
17601 tokens_avail
= parser
->tokens_avail
;
17602 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
17603 if (!clauses
.is_empty ())
17605 parser
->tokens
= clauses
.address ();
17606 parser
->tokens_avail
= clauses
.length ();
17607 parser
->in_pragma
= true;
17610 bool nested
= current_function_decl
!= NULL_TREE
;
17612 c_push_function_context ();
17613 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
17614 reduc_id
, default_function_type
);
17615 current_function_decl
= fndecl
;
17616 allocate_struct_function (fndecl
, true);
17618 tree stmt
= push_stmt_list ();
17619 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
17620 warn about these. */
17621 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17622 get_identifier ("omp_out"), type
);
17623 DECL_ARTIFICIAL (omp_out
) = 1;
17624 DECL_CONTEXT (omp_out
) = fndecl
;
17625 pushdecl (omp_out
);
17626 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17627 get_identifier ("omp_in"), type
);
17628 DECL_ARTIFICIAL (omp_in
) = 1;
17629 DECL_CONTEXT (omp_in
) = fndecl
;
17631 struct c_expr combiner
= c_parser_expression (parser
);
17632 struct c_expr initializer
;
17633 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
17635 initializer
.value
= error_mark_node
;
17636 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17638 else if (c_parser_next_token_is (parser
, CPP_NAME
)
17639 && strcmp (IDENTIFIER_POINTER
17640 (c_parser_peek_token (parser
)->value
),
17641 "initializer") == 0)
17643 c_parser_consume_token (parser
);
17646 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17647 get_identifier ("omp_priv"), type
);
17648 DECL_ARTIFICIAL (omp_priv
) = 1;
17649 DECL_INITIAL (omp_priv
) = error_mark_node
;
17650 DECL_CONTEXT (omp_priv
) = fndecl
;
17651 pushdecl (omp_priv
);
17652 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17653 get_identifier ("omp_orig"), type
);
17654 DECL_ARTIFICIAL (omp_orig
) = 1;
17655 DECL_CONTEXT (omp_orig
) = fndecl
;
17656 pushdecl (omp_orig
);
17657 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17659 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
17661 c_parser_error (parser
, "expected %<omp_priv%> or "
17665 else if (strcmp (IDENTIFIER_POINTER
17666 (c_parser_peek_token (parser
)->value
),
17669 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
17670 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
17672 c_parser_error (parser
, "expected function-name %<(%>");
17676 initializer
= c_parser_postfix_expression (parser
);
17677 if (initializer
.value
17678 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
17681 tree c
= initializer
.value
;
17682 for (j
= 0; j
< call_expr_nargs (c
); j
++)
17684 tree a
= CALL_EXPR_ARG (c
, j
);
17686 if (TREE_CODE (a
) == ADDR_EXPR
17687 && TREE_OPERAND (a
, 0) == omp_priv
)
17690 if (j
== call_expr_nargs (c
))
17691 error ("one of the initializer call arguments should be "
17697 c_parser_consume_token (parser
);
17698 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
17702 tree st
= push_stmt_list ();
17703 location_t loc
= c_parser_peek_token (parser
)->location
;
17704 rich_location
richloc (line_table
, loc
);
17705 start_init (omp_priv
, NULL_TREE
, 0, &richloc
);
17706 struct c_expr init
= c_parser_initializer (parser
);
17708 finish_decl (omp_priv
, loc
, init
.value
,
17709 init
.original_type
, NULL_TREE
);
17710 pop_stmt_list (st
);
17714 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17720 c_parser_skip_to_pragma_eol (parser
);
17722 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
17723 DECL_INITIAL (reduc_decl
));
17724 DECL_INITIAL (reduc_decl
) = t
;
17725 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
17726 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
17727 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
17728 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
17729 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
17730 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
17733 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
17734 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
17735 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
17736 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
17737 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
17738 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17739 walk_tree (&DECL_INITIAL (omp_priv
),
17740 c_check_omp_declare_reduction_r
,
17741 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17745 pop_stmt_list (stmt
);
17747 if (cfun
->language
!= NULL
)
17749 ggc_free (cfun
->language
);
17750 cfun
->language
= NULL
;
17753 current_function_decl
= NULL_TREE
;
17755 c_pop_function_context ();
17757 if (!clauses
.is_empty ())
17759 parser
->tokens
= &parser
->tokens_buf
[0];
17760 parser
->tokens_avail
= tokens_avail
;
17764 if (errs
!= errorcount
)
17768 clauses
.release ();
17774 #pragma omp declare simd declare-simd-clauses[optseq] new-line
17775 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17776 initializer-clause[opt] new-line
17777 #pragma omp declare target new-line */
17780 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
17782 c_parser_consume_pragma (parser
);
17783 if (c_parser_next_token_is (parser
, CPP_NAME
))
17785 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17786 if (strcmp (p
, "simd") == 0)
17788 /* c_parser_consume_token (parser); done in
17789 c_parser_omp_declare_simd. */
17790 c_parser_omp_declare_simd (parser
, context
);
17793 if (strcmp (p
, "reduction") == 0)
17795 c_parser_consume_token (parser
);
17796 c_parser_omp_declare_reduction (parser
, context
);
17799 if (!flag_openmp
) /* flag_openmp_simd */
17801 c_parser_skip_to_pragma_eol (parser
, false);
17804 if (strcmp (p
, "target") == 0)
17806 c_parser_consume_token (parser
);
17807 c_parser_omp_declare_target (parser
);
17812 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
17814 c_parser_skip_to_pragma_eol (parser
);
17818 #pragma omp taskloop taskloop-clause[optseq] new-line
17821 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
17824 #define OMP_TASKLOOP_CLAUSE_MASK \
17825 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
17826 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17827 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17828 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
17829 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
17830 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
17831 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
17832 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
17833 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
17834 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17835 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
17836 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
17837 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
17838 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
17841 c_parser_omp_taskloop (location_t loc
, c_parser
*parser
,
17842 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17845 tree clauses
, block
, ret
;
17847 strcat (p_name
, " taskloop");
17848 mask
|= OMP_TASKLOOP_CLAUSE_MASK
;
17850 if (c_parser_next_token_is (parser
, CPP_NAME
))
17852 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17854 if (strcmp (p
, "simd") == 0)
17856 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17857 if (cclauses
== NULL
)
17858 cclauses
= cclauses_buf
;
17859 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_REDUCTION
);
17860 c_parser_consume_token (parser
);
17861 if (!flag_openmp
) /* flag_openmp_simd */
17862 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
17864 block
= c_begin_compound_stmt (true);
17865 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
17866 block
= c_end_compound_stmt (loc
, block
, true);
17869 ret
= make_node (OMP_TASKLOOP
);
17870 TREE_TYPE (ret
) = void_type_node
;
17871 OMP_FOR_BODY (ret
) = block
;
17872 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
17873 SET_EXPR_LOCATION (ret
, loc
);
17878 if (!flag_openmp
) /* flag_openmp_simd */
17880 c_parser_skip_to_pragma_eol (parser
, false);
17884 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17887 omp_split_clauses (loc
, OMP_TASKLOOP
, mask
, clauses
, cclauses
);
17888 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
17891 block
= c_begin_compound_stmt (true);
17892 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_TASKLOOP
, clauses
, NULL
, if_p
);
17893 block
= c_end_compound_stmt (loc
, block
, true);
17899 /* Main entry point to parsing most OpenMP pragmas. */
17902 c_parser_omp_construct (c_parser
*parser
, bool *if_p
)
17904 enum pragma_kind p_kind
;
17907 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
17908 omp_clause_mask
mask (0);
17910 loc
= c_parser_peek_token (parser
)->location
;
17911 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
17912 c_parser_consume_pragma (parser
);
17916 case PRAGMA_OACC_ATOMIC
:
17917 c_parser_omp_atomic (loc
, parser
);
17919 case PRAGMA_OACC_CACHE
:
17920 strcpy (p_name
, "#pragma acc");
17921 stmt
= c_parser_oacc_cache (loc
, parser
);
17923 case PRAGMA_OACC_DATA
:
17924 stmt
= c_parser_oacc_data (loc
, parser
, if_p
);
17926 case PRAGMA_OACC_HOST_DATA
:
17927 stmt
= c_parser_oacc_host_data (loc
, parser
, if_p
);
17929 case PRAGMA_OACC_KERNELS
:
17930 case PRAGMA_OACC_PARALLEL
:
17931 strcpy (p_name
, "#pragma acc");
17932 stmt
= c_parser_oacc_kernels_parallel (loc
, parser
, p_kind
, p_name
,
17935 case PRAGMA_OACC_LOOP
:
17936 strcpy (p_name
, "#pragma acc");
17937 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17939 case PRAGMA_OACC_WAIT
:
17940 strcpy (p_name
, "#pragma wait");
17941 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
17943 case PRAGMA_OMP_ATOMIC
:
17944 c_parser_omp_atomic (loc
, parser
);
17946 case PRAGMA_OMP_CRITICAL
:
17947 stmt
= c_parser_omp_critical (loc
, parser
, if_p
);
17949 case PRAGMA_OMP_DISTRIBUTE
:
17950 strcpy (p_name
, "#pragma omp");
17951 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17953 case PRAGMA_OMP_FOR
:
17954 strcpy (p_name
, "#pragma omp");
17955 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17957 case PRAGMA_OMP_MASTER
:
17958 stmt
= c_parser_omp_master (loc
, parser
, if_p
);
17960 case PRAGMA_OMP_PARALLEL
:
17961 strcpy (p_name
, "#pragma omp");
17962 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17964 case PRAGMA_OMP_SECTIONS
:
17965 strcpy (p_name
, "#pragma omp");
17966 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
17968 case PRAGMA_OMP_SIMD
:
17969 strcpy (p_name
, "#pragma omp");
17970 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17972 case PRAGMA_OMP_SINGLE
:
17973 stmt
= c_parser_omp_single (loc
, parser
, if_p
);
17975 case PRAGMA_OMP_TASK
:
17976 stmt
= c_parser_omp_task (loc
, parser
, if_p
);
17978 case PRAGMA_OMP_TASKGROUP
:
17979 stmt
= c_parser_omp_taskgroup (parser
, if_p
);
17981 case PRAGMA_OMP_TASKLOOP
:
17982 strcpy (p_name
, "#pragma omp");
17983 stmt
= c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17985 case PRAGMA_OMP_TEAMS
:
17986 strcpy (p_name
, "#pragma omp");
17987 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17990 gcc_unreachable ();
17994 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
17999 # pragma omp threadprivate (variable-list) */
18002 c_parser_omp_threadprivate (c_parser
*parser
)
18007 c_parser_consume_pragma (parser
);
18008 loc
= c_parser_peek_token (parser
)->location
;
18009 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
18011 /* Mark every variable in VARS to be assigned thread local storage. */
18012 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
18014 tree v
= TREE_PURPOSE (t
);
18016 /* FIXME diagnostics: Ideally we should keep individual
18017 locations for all the variables in the var list to make the
18018 following errors more precise. Perhaps
18019 c_parser_omp_var_list_parens() should construct a list of
18020 locations to go along with the var list. */
18022 /* If V had already been marked threadprivate, it doesn't matter
18023 whether it had been used prior to this point. */
18025 error_at (loc
, "%qD is not a variable", v
);
18026 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
18027 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
18028 else if (! is_global_var (v
))
18029 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
18030 else if (TREE_TYPE (v
) == error_mark_node
)
18032 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
18033 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
18036 if (! DECL_THREAD_LOCAL_P (v
))
18038 set_decl_tls_model (v
, decl_default_tls_model (v
));
18039 /* If rtl has been already set for this var, call
18040 make_decl_rtl once again, so that encode_section_info
18041 has a chance to look at the new decl flags. */
18042 if (DECL_RTL_SET_P (v
))
18045 C_DECL_THREADPRIVATE_P (v
) = 1;
18049 c_parser_skip_to_pragma_eol (parser
);
18052 /* Parse a transaction attribute (GCC Extension).
18054 transaction-attribute:
18058 The transactional memory language description is written for C++,
18059 and uses the C++0x attribute syntax. For compatibility, allow the
18060 bracket style for transactions in C as well. */
18063 c_parser_transaction_attributes (c_parser
*parser
)
18065 tree attr_name
, attr
= NULL
;
18067 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
18068 return c_parser_attributes (parser
);
18070 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
18072 c_parser_consume_token (parser
);
18073 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
18076 attr_name
= c_parser_attribute_any_word (parser
);
18079 c_parser_consume_token (parser
);
18080 attr
= build_tree_list (attr_name
, NULL_TREE
);
18083 c_parser_error (parser
, "expected identifier");
18085 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18087 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18091 /* Parse a __transaction_atomic or __transaction_relaxed statement
18094 transaction-statement:
18095 __transaction_atomic transaction-attribute[opt] compound-statement
18096 __transaction_relaxed compound-statement
18098 Note that the only valid attribute is: "outer".
18102 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
18104 unsigned int old_in
= parser
->in_transaction
;
18105 unsigned int this_in
= 1, new_in
;
18106 location_t loc
= c_parser_peek_token (parser
)->location
;
18109 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18110 || keyword
== RID_TRANSACTION_RELAXED
)
18111 && c_parser_next_token_is_keyword (parser
, keyword
));
18112 c_parser_consume_token (parser
);
18114 if (keyword
== RID_TRANSACTION_RELAXED
)
18115 this_in
|= TM_STMT_ATTR_RELAXED
;
18118 attrs
= c_parser_transaction_attributes (parser
);
18120 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
18123 /* Keep track if we're in the lexical scope of an outer transaction. */
18124 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
18126 parser
->in_transaction
= new_in
;
18127 stmt
= c_parser_compound_statement (parser
);
18128 parser
->in_transaction
= old_in
;
18131 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
18133 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18134 "%<__transaction_atomic%> without transactional memory support enabled"
18135 : "%<__transaction_relaxed %> "
18136 "without transactional memory support enabled"));
18141 /* Parse a __transaction_atomic or __transaction_relaxed expression
18144 transaction-expression:
18145 __transaction_atomic ( expression )
18146 __transaction_relaxed ( expression )
18149 static struct c_expr
18150 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
18153 unsigned int old_in
= parser
->in_transaction
;
18154 unsigned int this_in
= 1;
18155 location_t loc
= c_parser_peek_token (parser
)->location
;
18158 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18159 || keyword
== RID_TRANSACTION_RELAXED
)
18160 && c_parser_next_token_is_keyword (parser
, keyword
));
18161 c_parser_consume_token (parser
);
18163 if (keyword
== RID_TRANSACTION_RELAXED
)
18164 this_in
|= TM_STMT_ATTR_RELAXED
;
18167 attrs
= c_parser_transaction_attributes (parser
);
18169 this_in
|= parse_tm_stmt_attr (attrs
, 0);
18172 parser
->in_transaction
= this_in
;
18173 matching_parens parens
;
18174 if (parens
.require_open (parser
))
18176 tree expr
= c_parser_expression (parser
).value
;
18177 ret
.original_type
= TREE_TYPE (expr
);
18178 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
18179 if (this_in
& TM_STMT_ATTR_RELAXED
)
18180 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
18181 SET_EXPR_LOCATION (ret
.value
, loc
);
18182 ret
.original_code
= TRANSACTION_EXPR
;
18183 if (!parens
.require_close (parser
))
18185 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
18192 ret
.value
= error_mark_node
;
18193 ret
.original_code
= ERROR_MARK
;
18194 ret
.original_type
= NULL
;
18196 parser
->in_transaction
= old_in
;
18199 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18200 "%<__transaction_atomic%> without transactional memory support enabled"
18201 : "%<__transaction_relaxed %> "
18202 "without transactional memory support enabled"));
18204 set_c_expr_source_range (&ret
, loc
, loc
);
18209 /* Parse a __transaction_cancel statement (GCC Extension).
18211 transaction-cancel-statement:
18212 __transaction_cancel transaction-attribute[opt] ;
18214 Note that the only valid attribute is "outer".
18218 c_parser_transaction_cancel (c_parser
*parser
)
18220 location_t loc
= c_parser_peek_token (parser
)->location
;
18222 bool is_outer
= false;
18224 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
18225 c_parser_consume_token (parser
);
18227 attrs
= c_parser_transaction_attributes (parser
);
18229 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
18233 error_at (loc
, "%<__transaction_cancel%> without "
18234 "transactional memory support enabled");
18237 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
18239 error_at (loc
, "%<__transaction_cancel%> within a "
18240 "%<__transaction_relaxed%>");
18245 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
18246 && !is_tm_may_cancel_outer (current_function_decl
))
18248 error_at (loc
, "outer %<__transaction_cancel%> not "
18249 "within outer %<__transaction_atomic%>");
18250 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
18254 else if (parser
->in_transaction
== 0)
18256 error_at (loc
, "%<__transaction_cancel%> not within "
18257 "%<__transaction_atomic%>");
18261 return add_stmt (build_tm_abort_call (loc
, is_outer
));
18264 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
18267 /* Parse a single source file. */
18270 c_parse_file (void)
18272 /* Use local storage to begin. If the first token is a pragma, parse it.
18273 If it is #pragma GCC pch_preprocess, then this will load a PCH file
18274 which will cause garbage collection. */
18277 memset (&tparser
, 0, sizeof tparser
);
18278 tparser
.tokens
= &tparser
.tokens_buf
[0];
18279 the_parser
= &tparser
;
18281 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
18282 c_parser_pragma_pch_preprocess (&tparser
);
18284 the_parser
= ggc_alloc
<c_parser
> ();
18285 *the_parser
= tparser
;
18286 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
18287 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
18289 /* Initialize EH, if we've been told to do so. */
18290 if (flag_exceptions
)
18291 using_eh_for_cleanups ();
18293 c_parser_translation_unit (the_parser
);
18297 /* Parse the body of a function declaration marked with "__RTL".
18299 The RTL parser works on the level of characters read from a
18300 FILE *, whereas c_parser works at the level of tokens.
18301 Square this circle by consuming all of the tokens up to and
18302 including the closing brace, recording the start/end of the RTL
18303 fragment, and reopening the file and re-reading the relevant
18304 lines within the RTL parser.
18306 This requires the opening and closing braces of the C function
18307 to be on separate lines from the RTL they wrap.
18309 Take ownership of START_WITH_PASS, if non-NULL. */
18312 c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
)
18314 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
18316 free (start_with_pass
);
18320 location_t start_loc
= c_parser_peek_token (parser
)->location
;
18322 /* Consume all tokens, up to the closing brace, handling
18323 matching pairs of braces in the rtl dump. */
18324 int num_open_braces
= 1;
18327 switch (c_parser_peek_token (parser
)->type
)
18329 case CPP_OPEN_BRACE
:
18332 case CPP_CLOSE_BRACE
:
18333 if (--num_open_braces
== 0)
18334 goto found_closing_brace
;
18337 error_at (start_loc
, "no closing brace");
18338 free (start_with_pass
);
18343 c_parser_consume_token (parser
);
18346 found_closing_brace
:
18347 /* At the closing brace; record its location. */
18348 location_t end_loc
= c_parser_peek_token (parser
)->location
;
18350 /* Consume the closing brace. */
18351 c_parser_consume_token (parser
);
18353 /* Invoke the RTL parser. */
18354 if (!read_rtl_function_body_from_file_range (start_loc
, end_loc
))
18356 free (start_with_pass
);
18360 /* If a pass name was provided for START_WITH_PASS, run the backend
18361 accordingly now, on the cfun created above, transferring
18362 ownership of START_WITH_PASS. */
18363 if (start_with_pass
)
18364 run_rtl_passes (start_with_pass
);
18367 #include "gt-c-c-parser.h"