1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2018 Free Software Foundation, Inc.
4 Parser actions based on the old Bison parser; structure somewhat
5 influenced by and fragments based on the C++ parser.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 Make sure all relevant comments, and all relevant code from all
26 actions, brought over from old parser. Verify exact correspondence
29 Add testcases covering every input symbol in every state in old and
32 Include full syntax for GNU C, including erroneous cases accepted
33 with error messages, in syntax productions in comments.
35 Make more diagnostics in the front end generally take an explicit
36 location rather than implicitly using input_location. */
39 #define INCLUDE_UNIQUE_PTR
41 #include "coretypes.h"
46 #include "stringpool.h"
49 #include "stor-layout.h"
51 #include "trans-mem.h"
52 #include "c-family/c-pragma.h"
54 #include "c-family/c-objc.h"
56 #include "omp-general.h"
57 #include "omp-offload.h"
59 #include "gomp-constants.h"
60 #include "c-family/c-indentation.h"
61 #include "gimple-expr.h"
63 #include "gcc-rich-location.h"
65 #include "gimple-parser.h"
66 #include "read-rtl-function.h"
67 #include "run-rtl-passes.h"
69 #include "c-family/name-hint.h"
70 #include "tree-iterator.h"
72 /* We need to walk over decls with incomplete struct/union/enum types
73 after parsing the whole translation unit.
74 In finish_decl(), if the decl is static, has incomplete
75 struct/union/enum type, it is appeneded to incomplete_record_decls.
76 In c_parser_translation_unit(), we iterate over incomplete_record_decls
77 and report error if any of the decls are still incomplete. */
79 vec
<tree
> incomplete_record_decls
;
82 set_c_expr_source_range (c_expr
*expr
,
83 location_t start
, location_t finish
)
85 expr
->src_range
.m_start
= start
;
86 expr
->src_range
.m_finish
= finish
;
88 set_source_range (expr
->value
, start
, finish
);
92 set_c_expr_source_range (c_expr
*expr
,
93 source_range src_range
)
95 expr
->src_range
= src_range
;
97 set_source_range (expr
->value
, src_range
);
101 /* Initialization routine for this file. */
106 /* The only initialization required is of the reserved word
112 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
113 the c_token structure. */
114 gcc_assert (RID_MAX
<= 255);
121 mask
|= D_ASM
| D_EXT
;
125 if (!c_dialect_objc ())
126 mask
|= D_OBJC
| D_CXX_OBJC
;
128 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
129 for (i
= 0; i
< num_c_common_reswords
; i
++)
131 /* If a keyword is disabled, do not enter it into the table
132 and so create a canonical spelling that isn't a keyword. */
133 if (c_common_reswords
[i
].disable
& mask
)
136 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
138 id
= get_identifier (c_common_reswords
[i
].word
);
139 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
140 C_IS_RESERVED_WORD (id
) = 1;
145 id
= get_identifier (c_common_reswords
[i
].word
);
146 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
147 C_IS_RESERVED_WORD (id
) = 1;
148 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
151 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
153 /* We always create the symbols but they aren't always supported. */
155 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
156 id
= get_identifier (name
);
157 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
158 C_IS_RESERVED_WORD (id
) = 1;
162 /* A parser structure recording information about the state and
163 context of parsing. Includes lexer information with up to two
164 tokens of look-ahead; more are not needed for C. */
165 struct GTY(()) c_parser
{
166 /* The look-ahead tokens. */
167 c_token
* GTY((skip
)) tokens
;
168 /* Buffer for look-ahead tokens. */
169 c_token tokens_buf
[4];
170 /* How many look-ahead tokens are available (0 - 4, or
171 more if parsing from pre-lexed tokens). */
172 unsigned int tokens_avail
;
173 /* True if a syntax error is being recovered from; false otherwise.
174 c_parser_error sets this flag. It should clear this flag when
175 enough tokens have been consumed to recover from the error. */
176 BOOL_BITFIELD error
: 1;
177 /* True if we're processing a pragma, and shouldn't automatically
178 consume CPP_PRAGMA_EOL. */
179 BOOL_BITFIELD in_pragma
: 1;
180 /* True if we're parsing the outermost block of an if statement. */
181 BOOL_BITFIELD in_if_block
: 1;
182 /* True if we want to lex an untranslated string. */
183 BOOL_BITFIELD lex_untranslated_string
: 1;
185 /* Objective-C specific parser/lexer information. */
187 /* True if we are in a context where the Objective-C "PQ" keywords
188 are considered keywords. */
189 BOOL_BITFIELD objc_pq_context
: 1;
190 /* True if we are parsing a (potential) Objective-C foreach
191 statement. This is set to true after we parsed 'for (' and while
192 we wait for 'in' or ';' to decide if it's a standard C for loop or an
193 Objective-C foreach loop. */
194 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
195 /* The following flag is needed to contextualize Objective-C lexical
196 analysis. In some cases (e.g., 'int NSObject;'), it is
197 undesirable to bind an identifier to an Objective-C class, even
198 if a class with that name exists. */
199 BOOL_BITFIELD objc_need_raw_identifier
: 1;
200 /* Nonzero if we're processing a __transaction statement. The value
201 is 1 | TM_STMT_ATTR_*. */
202 unsigned int in_transaction
: 4;
203 /* True if we are in a context where the Objective-C "Property attribute"
204 keywords are valid. */
205 BOOL_BITFIELD objc_property_attr_context
: 1;
207 /* Location of the last consumed token. */
208 location_t last_token_location
;
211 /* Return a pointer to the Nth token in PARSERs tokens_buf. */
214 c_parser_tokens_buf (c_parser
*parser
, unsigned n
)
216 return &parser
->tokens_buf
[n
];
219 /* Return the error state of PARSER. */
222 c_parser_error (c_parser
*parser
)
224 return parser
->error
;
227 /* Set the error state of PARSER to ERR. */
230 c_parser_set_error (c_parser
*parser
, bool err
)
236 /* The actual parser and external interface. ??? Does this need to be
237 garbage-collected? */
239 static GTY (()) c_parser
*the_parser
;
241 /* Read in and lex a single token, storing it in *TOKEN. */
244 c_lex_one_token (c_parser
*parser
, c_token
*token
)
246 timevar_push (TV_LEX
);
248 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
,
250 (parser
->lex_untranslated_string
251 ? C_LEX_STRING_NO_TRANSLATE
: 0));
252 token
->id_kind
= C_ID_NONE
;
253 token
->keyword
= RID_MAX
;
254 token
->pragma_kind
= PRAGMA_NONE
;
262 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
263 if (c_dialect_objc ())
264 parser
->objc_need_raw_identifier
= false;
266 if (C_IS_RESERVED_WORD (token
->value
))
268 enum rid rid_code
= C_RID_CODE (token
->value
);
270 if (rid_code
== RID_CXX_COMPAT_WARN
)
272 warning_at (token
->location
,
274 "identifier %qE conflicts with C++ keyword",
277 else if (rid_code
>= RID_FIRST_ADDR_SPACE
278 && rid_code
<= RID_LAST_ADDR_SPACE
)
281 as
= (addr_space_t
) (rid_code
- RID_FIRST_ADDR_SPACE
);
282 targetm
.addr_space
.diagnose_usage (as
, token
->location
);
283 token
->id_kind
= C_ID_ADDRSPACE
;
284 token
->keyword
= rid_code
;
287 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
289 /* We found an Objective-C "pq" keyword (in, out,
290 inout, bycopy, byref, oneway). They need special
291 care because the interpretation depends on the
293 if (parser
->objc_pq_context
)
295 token
->type
= CPP_KEYWORD
;
296 token
->keyword
= rid_code
;
299 else if (parser
->objc_could_be_foreach_context
300 && rid_code
== RID_IN
)
302 /* We are in Objective-C, inside a (potential)
303 foreach context (which means after having
304 parsed 'for (', but before having parsed ';'),
305 and we found 'in'. We consider it the keyword
306 which terminates the declaration at the
307 beginning of a foreach-statement. Note that
308 this means you can't use 'in' for anything else
309 in that context; in particular, in Objective-C
310 you can't use 'in' as the name of the running
311 variable in a C for loop. We could potentially
312 try to add code here to disambiguate, but it
313 seems a reasonable limitation. */
314 token
->type
= CPP_KEYWORD
;
315 token
->keyword
= rid_code
;
318 /* Else, "pq" keywords outside of the "pq" context are
319 not keywords, and we fall through to the code for
322 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
324 /* We found an Objective-C "property attribute"
325 keyword (getter, setter, readonly, etc). These are
326 only valid in the property context. */
327 if (parser
->objc_property_attr_context
)
329 token
->type
= CPP_KEYWORD
;
330 token
->keyword
= rid_code
;
333 /* Else they are not special keywords.
336 else if (c_dialect_objc ()
337 && (OBJC_IS_AT_KEYWORD (rid_code
)
338 || OBJC_IS_CXX_KEYWORD (rid_code
)))
340 /* We found one of the Objective-C "@" keywords (defs,
341 selector, synchronized, etc) or one of the
342 Objective-C "cxx" keywords (class, private,
343 protected, public, try, catch, throw) without a
344 preceding '@' sign. Do nothing and fall through to
345 the code for normal tokens (in C++ we would still
346 consider the CXX ones keywords, but not in C). */
351 token
->type
= CPP_KEYWORD
;
352 token
->keyword
= rid_code
;
357 decl
= lookup_name (token
->value
);
360 if (TREE_CODE (decl
) == TYPE_DECL
)
362 token
->id_kind
= C_ID_TYPENAME
;
366 else if (c_dialect_objc ())
368 tree objc_interface_decl
= objc_is_class_name (token
->value
);
369 /* Objective-C class names are in the same namespace as
370 variables and typedefs, and hence are shadowed by local
372 if (objc_interface_decl
373 && (!objc_force_identifier
|| global_bindings_p ()))
375 token
->value
= objc_interface_decl
;
376 token
->id_kind
= C_ID_CLASSNAME
;
380 token
->id_kind
= C_ID_ID
;
384 /* This only happens in Objective-C; it must be a keyword. */
385 token
->type
= CPP_KEYWORD
;
386 switch (C_RID_CODE (token
->value
))
388 /* Replace 'class' with '@class', 'private' with '@private',
389 etc. This prevents confusion with the C++ keyword
390 'class', and makes the tokens consistent with other
391 Objective-C 'AT' keywords. For example '@class' is
392 reported as RID_AT_CLASS which is consistent with
393 '@synchronized', which is reported as
396 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
397 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
398 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
399 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
400 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
401 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
402 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
403 case RID_SYNCHRONIZED
: token
->keyword
= RID_AT_SYNCHRONIZED
; break;
404 default: token
->keyword
= C_RID_CODE (token
->value
);
409 case CPP_CLOSE_PAREN
:
411 /* These tokens may affect the interpretation of any identifiers
412 following, if doing Objective-C. */
413 if (c_dialect_objc ())
414 parser
->objc_need_raw_identifier
= false;
417 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
418 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
424 timevar_pop (TV_LEX
);
427 /* Return a pointer to the next token from PARSER, reading it in if
431 c_parser_peek_token (c_parser
*parser
)
433 if (parser
->tokens_avail
== 0)
435 c_lex_one_token (parser
, &parser
->tokens
[0]);
436 parser
->tokens_avail
= 1;
438 return &parser
->tokens
[0];
441 /* Return a pointer to the next-but-one token from PARSER, reading it
442 in if necessary. The next token is already read in. */
445 c_parser_peek_2nd_token (c_parser
*parser
)
447 if (parser
->tokens_avail
>= 2)
448 return &parser
->tokens
[1];
449 gcc_assert (parser
->tokens_avail
== 1);
450 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
451 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
452 c_lex_one_token (parser
, &parser
->tokens
[1]);
453 parser
->tokens_avail
= 2;
454 return &parser
->tokens
[1];
457 /* Return a pointer to the Nth token from PARSER, reading it
458 in if necessary. The N-1th token is already read in. */
461 c_parser_peek_nth_token (c_parser
*parser
, unsigned int n
)
463 /* N is 1-based, not zero-based. */
466 if (parser
->tokens_avail
>= n
)
467 return &parser
->tokens
[n
- 1];
468 gcc_assert (parser
->tokens_avail
== n
- 1);
469 c_lex_one_token (parser
, &parser
->tokens
[n
- 1]);
470 parser
->tokens_avail
= n
;
471 return &parser
->tokens
[n
- 1];
475 c_keyword_starts_typename (enum rid keyword
)
510 if (keyword
>= RID_FIRST_INT_N
511 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
512 && int_n_enabled_p
[keyword
- RID_FIRST_INT_N
])
518 /* Return true if TOKEN can start a type name,
521 c_token_starts_typename (c_token
*token
)
526 switch (token
->id_kind
)
535 gcc_assert (c_dialect_objc ());
541 return c_keyword_starts_typename (token
->keyword
);
543 if (c_dialect_objc ())
551 /* Return true if the next token from PARSER can start a type name,
552 false otherwise. LA specifies how to do lookahead in order to
553 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
556 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
558 c_token
*token
= c_parser_peek_token (parser
);
559 if (c_token_starts_typename (token
))
562 /* Try a bit harder to detect an unknown typename. */
563 if (la
!= cla_prefer_id
564 && token
->type
== CPP_NAME
565 && token
->id_kind
== C_ID_ID
567 /* Do not try too hard when we could have "object in array". */
568 && !parser
->objc_could_be_foreach_context
570 && (la
== cla_prefer_type
571 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
572 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
574 /* Only unknown identifiers. */
575 && !lookup_name (token
->value
))
581 /* Return true if TOKEN is a type qualifier, false otherwise. */
583 c_token_is_qualifier (c_token
*token
)
588 switch (token
->id_kind
)
596 switch (token
->keyword
)
614 /* Return true if the next token from PARSER is a type qualifier,
617 c_parser_next_token_is_qualifier (c_parser
*parser
)
619 c_token
*token
= c_parser_peek_token (parser
);
620 return c_token_is_qualifier (token
);
623 /* Return true if TOKEN can start declaration specifiers, false
626 c_token_starts_declspecs (c_token
*token
)
631 switch (token
->id_kind
)
640 gcc_assert (c_dialect_objc ());
646 switch (token
->keyword
)
687 if (token
->keyword
>= RID_FIRST_INT_N
688 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
689 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
694 if (c_dialect_objc ())
703 /* Return true if TOKEN can start declaration specifiers or a static
704 assertion, false otherwise. */
706 c_token_starts_declaration (c_token
*token
)
708 if (c_token_starts_declspecs (token
)
709 || token
->keyword
== RID_STATIC_ASSERT
)
715 /* Return true if the next token from PARSER can start declaration
716 specifiers, false otherwise. */
718 c_parser_next_token_starts_declspecs (c_parser
*parser
)
720 c_token
*token
= c_parser_peek_token (parser
);
722 /* In Objective-C, a classname normally starts a declspecs unless it
723 is immediately followed by a dot. In that case, it is the
724 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
725 setter/getter on the class. c_token_starts_declspecs() can't
726 differentiate between the two cases because it only checks the
727 current token, so we have a special check here. */
728 if (c_dialect_objc ()
729 && token
->type
== CPP_NAME
730 && token
->id_kind
== C_ID_CLASSNAME
731 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
734 return c_token_starts_declspecs (token
);
737 /* Return true if the next tokens from PARSER can start declaration
738 specifiers or a static assertion, false otherwise. */
740 c_parser_next_tokens_start_declaration (c_parser
*parser
)
742 c_token
*token
= c_parser_peek_token (parser
);
745 if (c_dialect_objc ()
746 && token
->type
== CPP_NAME
747 && token
->id_kind
== C_ID_CLASSNAME
748 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
751 /* Labels do not start declarations. */
752 if (token
->type
== CPP_NAME
753 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
756 if (c_token_starts_declaration (token
))
759 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
765 /* Consume the next token from PARSER. */
768 c_parser_consume_token (c_parser
*parser
)
770 gcc_assert (parser
->tokens_avail
>= 1);
771 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
772 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
773 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
774 parser
->last_token_location
= parser
->tokens
[0].location
;
775 if (parser
->tokens
!= &parser
->tokens_buf
[0])
777 else if (parser
->tokens_avail
== 2)
778 parser
->tokens
[0] = parser
->tokens
[1];
779 parser
->tokens_avail
--;
782 /* Expect the current token to be a #pragma. Consume it and remember
783 that we've begun parsing a pragma. */
786 c_parser_consume_pragma (c_parser
*parser
)
788 gcc_assert (!parser
->in_pragma
);
789 gcc_assert (parser
->tokens_avail
>= 1);
790 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
791 if (parser
->tokens
!= &parser
->tokens_buf
[0])
793 else if (parser
->tokens_avail
== 2)
794 parser
->tokens
[0] = parser
->tokens
[1];
795 parser
->tokens_avail
--;
796 parser
->in_pragma
= true;
799 /* Update the global input_location from TOKEN. */
801 c_parser_set_source_position_from_token (c_token
*token
)
803 if (token
->type
!= CPP_EOF
)
805 input_location
= token
->location
;
809 /* Helper function for c_parser_error.
810 Having peeked a token of kind TOK1_KIND that might signify
811 a conflict marker, peek successor tokens to determine
812 if we actually do have a conflict marker.
813 Specifically, we consider a run of 7 '<', '=' or '>' characters
814 at the start of a line as a conflict marker.
815 These come through the lexer as three pairs and a single,
816 e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<').
817 If it returns true, *OUT_LOC is written to with the location/range
821 c_parser_peek_conflict_marker (c_parser
*parser
, enum cpp_ttype tok1_kind
,
824 c_token
*token2
= c_parser_peek_2nd_token (parser
);
825 if (token2
->type
!= tok1_kind
)
827 c_token
*token3
= c_parser_peek_nth_token (parser
, 3);
828 if (token3
->type
!= tok1_kind
)
830 c_token
*token4
= c_parser_peek_nth_token (parser
, 4);
831 if (token4
->type
!= conflict_marker_get_final_tok_kind (tok1_kind
))
834 /* It must be at the start of the line. */
835 location_t start_loc
= c_parser_peek_token (parser
)->location
;
836 if (LOCATION_COLUMN (start_loc
) != 1)
839 /* We have a conflict marker. Construct a location of the form:
842 with start == caret, finishing at the end of the marker. */
843 location_t finish_loc
= get_finish (token4
->location
);
844 *out_loc
= make_location (start_loc
, start_loc
, finish_loc
);
849 /* Issue a diagnostic of the form
850 FILE:LINE: MESSAGE before TOKEN
851 where TOKEN is the next token in the input stream of PARSER.
852 MESSAGE (specified by the caller) is usually of the form "expected
855 Use RICHLOC as the location of the diagnostic.
857 Do not issue a diagnostic if still recovering from an error.
859 Return true iff an error was actually emitted.
861 ??? This is taken from the C++ parser, but building up messages in
862 this way is not i18n-friendly and some other approach should be
866 c_parser_error_richloc (c_parser
*parser
, const char *gmsgid
,
867 rich_location
*richloc
)
869 c_token
*token
= c_parser_peek_token (parser
);
872 parser
->error
= true;
876 /* If this is actually a conflict marker, report it as such. */
877 if (token
->type
== CPP_LSHIFT
878 || token
->type
== CPP_RSHIFT
879 || token
->type
== CPP_EQ_EQ
)
882 if (c_parser_peek_conflict_marker (parser
, token
->type
, &loc
))
884 error_at (loc
, "version control conflict marker in file");
889 c_parse_error (gmsgid
,
890 /* Because c_parse_error does not understand
891 CPP_KEYWORD, keywords are treated like
893 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
894 /* ??? The C parser does not save the cpp flags of a
895 token, we need to pass 0 here and we will not get
896 the source spelling of some tokens but rather the
897 canonical spelling. */
898 token
->value
, /*flags=*/0, richloc
);
902 /* As c_parser_error_richloc, but issue the message at the
903 location of PARSER's next token, or at input_location
904 if the next token is EOF. */
907 c_parser_error (c_parser
*parser
, const char *gmsgid
)
909 c_token
*token
= c_parser_peek_token (parser
);
910 c_parser_set_source_position_from_token (token
);
911 rich_location
richloc (line_table
, input_location
);
912 return c_parser_error_richloc (parser
, gmsgid
, &richloc
);
915 /* Some tokens naturally come in pairs e.g.'(' and ')'.
916 This class is for tracking such a matching pair of symbols.
917 In particular, it tracks the location of the first token,
918 so that if the second token is missing, we can highlight the
919 location of the first token when notifying the user about the
922 template <typename traits_t
>
926 /* token_pair's ctor. */
927 token_pair () : m_open_loc (UNKNOWN_LOCATION
) {}
929 /* If the next token is the opening symbol for this pair, consume it and
931 Otherwise, issue an error and return false.
932 In either case, record the location of the opening token. */
934 bool require_open (c_parser
*parser
)
936 c_token
*token
= c_parser_peek_token (parser
);
938 m_open_loc
= token
->location
;
940 return c_parser_require (parser
, traits_t::open_token_type
,
941 traits_t::open_gmsgid
);
944 /* Consume the next token from PARSER, recording its location as
945 that of the opening token within the pair. */
947 void consume_open (c_parser
*parser
)
949 c_token
*token
= c_parser_peek_token (parser
);
950 gcc_assert (token
->type
== traits_t::open_token_type
);
951 m_open_loc
= token
->location
;
952 c_parser_consume_token (parser
);
955 /* If the next token is the closing symbol for this pair, consume it
957 Otherwise, issue an error, highlighting the location of the
958 corresponding opening token, and return false. */
960 bool require_close (c_parser
*parser
) const
962 return c_parser_require (parser
, traits_t::close_token_type
,
963 traits_t::close_gmsgid
, m_open_loc
);
966 /* Like token_pair::require_close, except that tokens will be skipped
967 until the desired token is found. An error message is still produced
968 if the next token is not as expected. */
970 void skip_until_found_close (c_parser
*parser
) const
972 c_parser_skip_until_found (parser
, traits_t::close_token_type
,
973 traits_t::close_gmsgid
, m_open_loc
);
977 location_t m_open_loc
;
980 /* Traits for token_pair<T> for tracking matching pairs of parentheses. */
982 struct matching_paren_traits
984 static const enum cpp_ttype open_token_type
= CPP_OPEN_PAREN
;
985 static const char * const open_gmsgid
;
986 static const enum cpp_ttype close_token_type
= CPP_CLOSE_PAREN
;
987 static const char * const close_gmsgid
;
990 const char * const matching_paren_traits::open_gmsgid
= "expected %<(%>";
991 const char * const matching_paren_traits::close_gmsgid
= "expected %<)%>";
993 /* "matching_parens" is a token_pair<T> class for tracking matching
994 pairs of parentheses. */
996 typedef token_pair
<matching_paren_traits
> matching_parens
;
998 /* Traits for token_pair<T> for tracking matching pairs of braces. */
1000 struct matching_brace_traits
1002 static const enum cpp_ttype open_token_type
= CPP_OPEN_BRACE
;
1003 static const char * const open_gmsgid
;
1004 static const enum cpp_ttype close_token_type
= CPP_CLOSE_BRACE
;
1005 static const char * const close_gmsgid
;
1008 const char * const matching_brace_traits::open_gmsgid
= "expected %<{%>";
1009 const char * const matching_brace_traits::close_gmsgid
= "expected %<}%>";
1011 /* "matching_braces" is a token_pair<T> class for tracking matching
1014 typedef token_pair
<matching_brace_traits
> matching_braces
;
1016 /* Get a description of the matching symbol to TYPE e.g. "(" for
1020 get_matching_symbol (enum cpp_ttype type
)
1027 case CPP_CLOSE_PAREN
:
1029 case CPP_CLOSE_BRACE
:
1034 /* If the next token is of the indicated TYPE, consume it. Otherwise,
1035 issue the error MSGID. If MSGID is NULL then a message has already
1036 been produced and no message will be produced this time. Returns
1037 true if found, false otherwise.
1039 If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1040 within any error as the location of an "opening" token matching
1041 the close token TYPE (e.g. the location of the '(' when TYPE is
1044 If TYPE_IS_UNIQUE is true (the default) then msgid describes exactly
1045 one type (e.g. "expected %<)%>") and thus it may be reasonable to
1046 attempt to generate a fix-it hint for the problem.
1047 Otherwise msgid describes multiple token types (e.g.
1048 "expected %<;%>, %<,%> or %<)%>"), and thus we shouldn't attempt to
1049 generate a fix-it hint. */
1052 c_parser_require (c_parser
*parser
,
1053 enum cpp_ttype type
,
1055 location_t matching_location
,
1056 bool type_is_unique
)
1058 if (c_parser_next_token_is (parser
, type
))
1060 c_parser_consume_token (parser
);
1065 location_t next_token_loc
= c_parser_peek_token (parser
)->location
;
1066 gcc_rich_location
richloc (next_token_loc
);
1068 /* Potentially supply a fix-it hint, suggesting to add the
1069 missing token immediately after the *previous* token.
1070 This may move the primary location within richloc. */
1071 if (!parser
->error
&& type_is_unique
)
1072 maybe_suggest_missing_token_insertion (&richloc
, type
,
1073 parser
->last_token_location
);
1075 /* If matching_location != UNKNOWN_LOCATION, highlight it.
1076 Attempt to consolidate diagnostics by printing it as a
1077 secondary range within the main diagnostic. */
1078 bool added_matching_location
= false;
1079 if (matching_location
!= UNKNOWN_LOCATION
)
1080 added_matching_location
1081 = richloc
.add_location_if_nearby (matching_location
);
1083 if (c_parser_error_richloc (parser
, msgid
, &richloc
))
1084 /* If we weren't able to consolidate matching_location, then
1085 print it as a secondary diagnostic. */
1086 if (matching_location
!= UNKNOWN_LOCATION
&& !added_matching_location
)
1087 inform (matching_location
, "to match this %qs",
1088 get_matching_symbol (type
));
1094 /* If the next token is the indicated keyword, consume it. Otherwise,
1095 issue the error MSGID. Returns true if found, false otherwise. */
1098 c_parser_require_keyword (c_parser
*parser
,
1102 if (c_parser_next_token_is_keyword (parser
, keyword
))
1104 c_parser_consume_token (parser
);
1109 c_parser_error (parser
, msgid
);
1114 /* Like c_parser_require, except that tokens will be skipped until the
1115 desired token is found. An error message is still produced if the
1116 next token is not as expected. If MSGID is NULL then a message has
1117 already been produced and no message will be produced this
1120 If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1121 within any error as the location of an "opening" token matching
1122 the close token TYPE (e.g. the location of the '(' when TYPE is
1123 CPP_CLOSE_PAREN). */
1126 c_parser_skip_until_found (c_parser
*parser
,
1127 enum cpp_ttype type
,
1129 location_t matching_location
)
1131 unsigned nesting_depth
= 0;
1133 if (c_parser_require (parser
, type
, msgid
, matching_location
))
1136 /* Skip tokens until the desired token is found. */
1139 /* Peek at the next token. */
1140 c_token
*token
= c_parser_peek_token (parser
);
1141 /* If we've reached the token we want, consume it and stop. */
1142 if (token
->type
== type
&& !nesting_depth
)
1144 c_parser_consume_token (parser
);
1148 /* If we've run out of tokens, stop. */
1149 if (token
->type
== CPP_EOF
)
1151 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1153 if (token
->type
== CPP_OPEN_BRACE
1154 || token
->type
== CPP_OPEN_PAREN
1155 || token
->type
== CPP_OPEN_SQUARE
)
1157 else if (token
->type
== CPP_CLOSE_BRACE
1158 || token
->type
== CPP_CLOSE_PAREN
1159 || token
->type
== CPP_CLOSE_SQUARE
)
1161 if (nesting_depth
-- == 0)
1164 /* Consume this token. */
1165 c_parser_consume_token (parser
);
1167 parser
->error
= false;
1170 /* Skip tokens until the end of a parameter is found, but do not
1171 consume the comma, semicolon or closing delimiter. */
1174 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
1176 unsigned nesting_depth
= 0;
1180 c_token
*token
= c_parser_peek_token (parser
);
1181 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
1184 /* If we've run out of tokens, stop. */
1185 if (token
->type
== CPP_EOF
)
1187 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1189 if (token
->type
== CPP_OPEN_BRACE
1190 || token
->type
== CPP_OPEN_PAREN
1191 || token
->type
== CPP_OPEN_SQUARE
)
1193 else if (token
->type
== CPP_CLOSE_BRACE
1194 || token
->type
== CPP_CLOSE_PAREN
1195 || token
->type
== CPP_CLOSE_SQUARE
)
1197 if (nesting_depth
-- == 0)
1200 /* Consume this token. */
1201 c_parser_consume_token (parser
);
1203 parser
->error
= false;
1206 /* Expect to be at the end of the pragma directive and consume an
1207 end of line marker. */
1210 c_parser_skip_to_pragma_eol (c_parser
*parser
, bool error_if_not_eol
= true)
1212 gcc_assert (parser
->in_pragma
);
1213 parser
->in_pragma
= false;
1215 if (error_if_not_eol
&& c_parser_peek_token (parser
)->type
!= CPP_PRAGMA_EOL
)
1216 c_parser_error (parser
, "expected end of line");
1218 cpp_ttype token_type
;
1221 c_token
*token
= c_parser_peek_token (parser
);
1222 token_type
= token
->type
;
1223 if (token_type
== CPP_EOF
)
1225 c_parser_consume_token (parser
);
1227 while (token_type
!= CPP_PRAGMA_EOL
);
1229 parser
->error
= false;
1232 /* Skip tokens until we have consumed an entire block, or until we
1233 have consumed a non-nested ';'. */
1236 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1238 unsigned nesting_depth
= 0;
1239 bool save_error
= parser
->error
;
1245 /* Peek at the next token. */
1246 token
= c_parser_peek_token (parser
);
1248 switch (token
->type
)
1253 case CPP_PRAGMA_EOL
:
1254 if (parser
->in_pragma
)
1259 /* If the next token is a ';', we have reached the
1260 end of the statement. */
1263 /* Consume the ';'. */
1264 c_parser_consume_token (parser
);
1269 case CPP_CLOSE_BRACE
:
1270 /* If the next token is a non-nested '}', then we have
1271 reached the end of the current block. */
1272 if (nesting_depth
== 0 || --nesting_depth
== 0)
1274 c_parser_consume_token (parser
);
1279 case CPP_OPEN_BRACE
:
1280 /* If it the next token is a '{', then we are entering a new
1281 block. Consume the entire block. */
1286 /* If we see a pragma, consume the whole thing at once. We
1287 have some safeguards against consuming pragmas willy-nilly.
1288 Normally, we'd expect to be here with parser->error set,
1289 which disables these safeguards. But it's possible to get
1290 here for secondary error recovery, after parser->error has
1292 c_parser_consume_pragma (parser
);
1293 c_parser_skip_to_pragma_eol (parser
);
1294 parser
->error
= save_error
;
1301 c_parser_consume_token (parser
);
1305 parser
->error
= false;
1308 /* CPP's options (initialized by c-opts.c). */
1309 extern cpp_options
*cpp_opts
;
1311 /* Save the warning flags which are controlled by __extension__. */
1314 disable_extension_diagnostics (void)
1317 | (warn_pointer_arith
<< 1)
1318 | (warn_traditional
<< 2)
1320 | (warn_long_long
<< 4)
1321 | (warn_cxx_compat
<< 5)
1322 | (warn_overlength_strings
<< 6)
1323 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1324 play tricks to properly restore it. */
1325 | ((warn_c90_c99_compat
== 1) << 7)
1326 | ((warn_c90_c99_compat
== -1) << 8)
1327 /* Similarly for warn_c99_c11_compat. */
1328 | ((warn_c99_c11_compat
== 1) << 9)
1329 | ((warn_c99_c11_compat
== -1) << 10)
1331 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1332 warn_pointer_arith
= 0;
1333 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1335 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1336 warn_cxx_compat
= 0;
1337 warn_overlength_strings
= 0;
1338 warn_c90_c99_compat
= 0;
1339 warn_c99_c11_compat
= 0;
1343 /* Restore the warning flags which are controlled by __extension__.
1344 FLAGS is the return value from disable_extension_diagnostics. */
1347 restore_extension_diagnostics (int flags
)
1349 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1350 warn_pointer_arith
= (flags
>> 1) & 1;
1351 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1352 flag_iso
= (flags
>> 3) & 1;
1353 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1354 warn_cxx_compat
= (flags
>> 5) & 1;
1355 warn_overlength_strings
= (flags
>> 6) & 1;
1356 /* See above for why is this needed. */
1357 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1358 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1361 /* Helper data structure for parsing #pragma acc routine. */
1362 struct oacc_routine_data
{
1363 bool error_seen
; /* Set if error has been reported. */
1364 bool fndecl_seen
; /* Set if one fn decl/definition has been seen already. */
1369 static void c_parser_external_declaration (c_parser
*);
1370 static void c_parser_asm_definition (c_parser
*);
1371 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1372 bool, bool, tree
*, vec
<c_token
>,
1373 struct oacc_routine_data
* = NULL
,
1375 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1376 static void c_parser_static_assert_declaration (c_parser
*);
1377 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1378 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1379 static tree
c_parser_struct_declaration (c_parser
*);
1380 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1381 static tree
c_parser_alignas_specifier (c_parser
*);
1382 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1384 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1386 struct c_declarator
*);
1387 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1388 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1390 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1391 static tree
c_parser_simple_asm_expr (c_parser
*);
1392 static tree
c_parser_attributes (c_parser
*);
1393 static struct c_expr
c_parser_initializer (c_parser
*);
1394 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool,
1396 static void c_parser_initelt (c_parser
*, struct obstack
*);
1397 static void c_parser_initval (c_parser
*, struct c_expr
*,
1399 static tree
c_parser_compound_statement (c_parser
*);
1400 static void c_parser_compound_statement_nostart (c_parser
*);
1401 static void c_parser_label (c_parser
*);
1402 static void c_parser_statement (c_parser
*, bool *, location_t
* = NULL
);
1403 static void c_parser_statement_after_labels (c_parser
*, bool *,
1404 vec
<tree
> * = NULL
);
1405 static tree
c_parser_c99_block_statement (c_parser
*, bool *,
1406 location_t
* = NULL
);
1407 static void c_parser_if_statement (c_parser
*, bool *, vec
<tree
> *);
1408 static void c_parser_switch_statement (c_parser
*, bool *);
1409 static void c_parser_while_statement (c_parser
*, bool, unsigned short, bool *);
1410 static void c_parser_do_statement (c_parser
*, bool, unsigned short);
1411 static void c_parser_for_statement (c_parser
*, bool, unsigned short, bool *);
1412 static tree
c_parser_asm_statement (c_parser
*);
1413 static tree
c_parser_asm_operands (c_parser
*);
1414 static tree
c_parser_asm_goto_operands (c_parser
*);
1415 static tree
c_parser_asm_clobbers (c_parser
*);
1416 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1418 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1419 struct c_expr
*, tree
);
1420 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1422 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1423 static struct c_expr
c_parser_unary_expression (c_parser
*);
1424 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1425 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1426 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1427 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1428 struct c_type_name
*,
1430 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1433 static tree
c_parser_transaction (c_parser
*, enum rid
);
1434 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1435 static tree
c_parser_transaction_cancel (c_parser
*);
1436 static struct c_expr
c_parser_expression (c_parser
*);
1437 static struct c_expr
c_parser_expression_conv (c_parser
*);
1438 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1439 vec
<tree
, va_gc
> **, location_t
*,
1440 tree
*, vec
<location_t
> *,
1441 unsigned int * = NULL
);
1442 static void c_parser_oacc_declare (c_parser
*);
1443 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1444 static void c_parser_oacc_update (c_parser
*);
1445 static void c_parser_omp_construct (c_parser
*, bool *);
1446 static void c_parser_omp_threadprivate (c_parser
*);
1447 static void c_parser_omp_barrier (c_parser
*);
1448 static void c_parser_omp_flush (c_parser
*);
1449 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1450 tree
, tree
*, bool *);
1451 static void c_parser_omp_taskwait (c_parser
*);
1452 static void c_parser_omp_taskyield (c_parser
*);
1453 static void c_parser_omp_cancel (c_parser
*);
1455 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1456 pragma_stmt
, pragma_compound
};
1457 static bool c_parser_pragma (c_parser
*, enum pragma_context
, bool *);
1458 static void c_parser_omp_cancellation_point (c_parser
*, enum pragma_context
);
1459 static bool c_parser_omp_target (c_parser
*, enum pragma_context
, bool *);
1460 static void c_parser_omp_end_declare_target (c_parser
*);
1461 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1462 static bool c_parser_omp_ordered (c_parser
*, enum pragma_context
, bool *);
1463 static void c_parser_oacc_routine (c_parser
*, enum pragma_context
);
1465 /* These Objective-C parser functions are only ever called when
1466 compiling Objective-C. */
1467 static void c_parser_objc_class_definition (c_parser
*, tree
);
1468 static void c_parser_objc_class_instance_variables (c_parser
*);
1469 static void c_parser_objc_class_declaration (c_parser
*);
1470 static void c_parser_objc_alias_declaration (c_parser
*);
1471 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1472 static bool c_parser_objc_method_type (c_parser
*);
1473 static void c_parser_objc_method_definition (c_parser
*);
1474 static void c_parser_objc_methodprotolist (c_parser
*);
1475 static void c_parser_objc_methodproto (c_parser
*);
1476 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1477 static tree
c_parser_objc_type_name (c_parser
*);
1478 static tree
c_parser_objc_protocol_refs (c_parser
*);
1479 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1480 static void c_parser_objc_synchronized_statement (c_parser
*);
1481 static tree
c_parser_objc_selector (c_parser
*);
1482 static tree
c_parser_objc_selector_arg (c_parser
*);
1483 static tree
c_parser_objc_receiver (c_parser
*);
1484 static tree
c_parser_objc_message_args (c_parser
*);
1485 static tree
c_parser_objc_keywordexpr (c_parser
*);
1486 static void c_parser_objc_at_property_declaration (c_parser
*);
1487 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1488 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1489 static bool c_parser_objc_diagnose_bad_element_prefix
1490 (c_parser
*, struct c_declspecs
*);
1492 static void c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
);
1494 /* Parse a translation unit (C90 6.7, C99 6.9, C11 6.9).
1497 external-declarations
1499 external-declarations:
1500 external-declaration
1501 external-declarations external-declaration
1510 c_parser_translation_unit (c_parser
*parser
)
1512 if (c_parser_next_token_is (parser
, CPP_EOF
))
1514 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1515 "ISO C forbids an empty translation unit");
1519 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1520 mark_valid_location_for_stdc_pragma (false);
1524 c_parser_external_declaration (parser
);
1525 obstack_free (&parser_obstack
, obstack_position
);
1527 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1532 FOR_EACH_VEC_ELT (incomplete_record_decls
, i
, decl
)
1533 if (DECL_SIZE (decl
) == NULL_TREE
&& TREE_TYPE (decl
) != error_mark_node
)
1534 error ("storage size of %q+D isn%'t known", decl
);
1537 /* Parse an external declaration (C90 6.7, C99 6.9, C11 6.9).
1539 external-declaration:
1545 external-declaration:
1548 __extension__ external-declaration
1552 external-declaration:
1553 objc-class-definition
1554 objc-class-declaration
1555 objc-alias-declaration
1556 objc-protocol-definition
1557 objc-method-definition
1562 c_parser_external_declaration (c_parser
*parser
)
1565 switch (c_parser_peek_token (parser
)->type
)
1568 switch (c_parser_peek_token (parser
)->keyword
)
1571 ext
= disable_extension_diagnostics ();
1572 c_parser_consume_token (parser
);
1573 c_parser_external_declaration (parser
);
1574 restore_extension_diagnostics (ext
);
1577 c_parser_asm_definition (parser
);
1579 case RID_AT_INTERFACE
:
1580 case RID_AT_IMPLEMENTATION
:
1581 gcc_assert (c_dialect_objc ());
1582 c_parser_objc_class_definition (parser
, NULL_TREE
);
1585 gcc_assert (c_dialect_objc ());
1586 c_parser_objc_class_declaration (parser
);
1589 gcc_assert (c_dialect_objc ());
1590 c_parser_objc_alias_declaration (parser
);
1592 case RID_AT_PROTOCOL
:
1593 gcc_assert (c_dialect_objc ());
1594 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1596 case RID_AT_PROPERTY
:
1597 gcc_assert (c_dialect_objc ());
1598 c_parser_objc_at_property_declaration (parser
);
1600 case RID_AT_SYNTHESIZE
:
1601 gcc_assert (c_dialect_objc ());
1602 c_parser_objc_at_synthesize_declaration (parser
);
1604 case RID_AT_DYNAMIC
:
1605 gcc_assert (c_dialect_objc ());
1606 c_parser_objc_at_dynamic_declaration (parser
);
1609 gcc_assert (c_dialect_objc ());
1610 c_parser_consume_token (parser
);
1611 objc_finish_implementation ();
1618 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1619 "ISO C does not allow extra %<;%> outside of a function");
1620 c_parser_consume_token (parser
);
1623 mark_valid_location_for_stdc_pragma (true);
1624 c_parser_pragma (parser
, pragma_external
, NULL
);
1625 mark_valid_location_for_stdc_pragma (false);
1629 if (c_dialect_objc ())
1631 c_parser_objc_method_definition (parser
);
1634 /* Else fall through, and yield a syntax error trying to parse
1635 as a declaration or function definition. */
1639 /* A declaration or a function definition (or, in Objective-C,
1640 an @interface or @protocol with prefix attributes). We can
1641 only tell which after parsing the declaration specifiers, if
1642 any, and the first declarator. */
1643 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1649 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1650 static void c_finish_oacc_routine (struct oacc_routine_data
*, tree
, bool);
1652 /* Build and add a DEBUG_BEGIN_STMT statement with location LOC. */
1655 add_debug_begin_stmt (location_t loc
)
1657 /* Don't add DEBUG_BEGIN_STMTs outside of functions, see PR84721. */
1658 if (!MAY_HAVE_DEBUG_MARKER_STMTS
|| !building_stmt_list_p ())
1661 tree stmt
= build0 (DEBUG_BEGIN_STMT
, void_type_node
);
1662 SET_EXPR_LOCATION (stmt
, loc
);
1666 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1667 6.7, 6.9.1, C11 6.7, 6.9.1). If FNDEF_OK is true, a function definition
1668 is accepted; otherwise (old-style parameter declarations) only other
1669 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1670 assertion is accepted; otherwise (old-style parameter declarations)
1671 it is not. If NESTED is true, we are inside a function or parsing
1672 old-style parameter declarations; any functions encountered are
1673 nested functions and declaration specifiers are required; otherwise
1674 we are at top level and functions are normal functions and
1675 declaration specifiers may be optional. If EMPTY_OK is true, empty
1676 declarations are OK (subject to all other constraints); otherwise
1677 (old-style parameter declarations) they are diagnosed. If
1678 START_ATTR_OK is true, the declaration specifiers may start with
1679 attributes; otherwise they may not.
1680 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1681 declaration when parsing an Objective-C foreach statement.
1682 FALLTHRU_ATTR_P is used to signal whether this function parsed
1683 "__attribute__((fallthrough));".
1686 declaration-specifiers init-declarator-list[opt] ;
1687 static_assert-declaration
1689 function-definition:
1690 declaration-specifiers[opt] declarator declaration-list[opt]
1695 declaration-list declaration
1697 init-declarator-list:
1699 init-declarator-list , init-declarator
1702 declarator simple-asm-expr[opt] attributes[opt]
1703 declarator simple-asm-expr[opt] attributes[opt] = initializer
1707 nested-function-definition:
1708 declaration-specifiers declarator declaration-list[opt]
1714 attributes objc-class-definition
1715 attributes objc-category-definition
1716 attributes objc-protocol-definition
1718 The simple-asm-expr and attributes are GNU extensions.
1720 This function does not handle __extension__; that is handled in its
1721 callers. ??? Following the old parser, __extension__ may start
1722 external declarations, declarations in functions and declarations
1723 at the start of "for" loops, but not old-style parameter
1726 C99 requires declaration specifiers in a function definition; the
1727 absence is diagnosed through the diagnosis of implicit int. In GNU
1728 C we also allow but diagnose declarations without declaration
1729 specifiers, but only at top level (elsewhere they conflict with
1732 In Objective-C, declarations of the looping variable in a foreach
1733 statement are exceptionally terminated by 'in' (for example, 'for
1734 (NSObject *object in array) { ... }').
1739 threadprivate-directive
1743 gimple-function-definition:
1744 declaration-specifiers[opt] __GIMPLE (gimple-or-rtl-pass-list) declarator
1745 declaration-list[opt] compound-statement
1747 rtl-function-definition:
1748 declaration-specifiers[opt] __RTL (gimple-or-rtl-pass-list) declarator
1749 declaration-list[opt] compound-statement */
1752 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1753 bool static_assert_ok
, bool empty_ok
,
1754 bool nested
, bool start_attr_ok
,
1755 tree
*objc_foreach_object_declaration
,
1756 vec
<c_token
> omp_declare_simd_clauses
,
1757 struct oacc_routine_data
*oacc_routine_data
,
1758 bool *fallthru_attr_p
)
1760 struct c_declspecs
*specs
;
1762 tree all_prefix_attrs
;
1763 bool diagnosed_no_specs
= false;
1764 location_t here
= c_parser_peek_token (parser
)->location
;
1766 add_debug_begin_stmt (c_parser_peek_token (parser
)->location
);
1768 if (static_assert_ok
1769 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1771 c_parser_static_assert_declaration (parser
);
1774 specs
= build_null_declspecs ();
1776 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1777 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1778 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1779 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1780 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1781 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1783 tree name
= c_parser_peek_token (parser
)->value
;
1785 /* Issue a warning about NAME being an unknown type name, perhaps
1786 with some kind of hint.
1787 If the user forgot a "struct" etc, suggest inserting
1788 it. Otherwise, attempt to look for misspellings. */
1789 gcc_rich_location
richloc (here
);
1790 if (tag_exists_p (RECORD_TYPE
, name
))
1792 /* This is not C++ with its implicit typedef. */
1793 richloc
.add_fixit_insert_before ("struct ");
1795 "unknown type name %qE;"
1796 " use %<struct%> keyword to refer to the type",
1799 else if (tag_exists_p (UNION_TYPE
, name
))
1801 richloc
.add_fixit_insert_before ("union ");
1803 "unknown type name %qE;"
1804 " use %<union%> keyword to refer to the type",
1807 else if (tag_exists_p (ENUMERAL_TYPE
, name
))
1809 richloc
.add_fixit_insert_before ("enum ");
1811 "unknown type name %qE;"
1812 " use %<enum%> keyword to refer to the type",
1817 auto_diagnostic_group d
;
1818 name_hint hint
= lookup_name_fuzzy (name
, FUZZY_LOOKUP_TYPENAME
,
1822 richloc
.add_fixit_replace (hint
.suggestion ());
1824 "unknown type name %qE; did you mean %qs?",
1825 name
, hint
.suggestion ());
1828 error_at (here
, "unknown type name %qE", name
);
1831 /* Parse declspecs normally to get a correct pointer type, but avoid
1832 a further "fails to be a type name" error. Refuse nested functions
1833 since it is not how the user likely wants us to recover. */
1834 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1835 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1836 c_parser_peek_token (parser
)->value
= error_mark_node
;
1840 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1841 true, true, cla_nonabstract_decl
);
1844 c_parser_skip_to_end_of_block_or_statement (parser
);
1847 if (nested
&& !specs
->declspecs_seen_p
)
1849 c_parser_error (parser
, "expected declaration specifiers");
1850 c_parser_skip_to_end_of_block_or_statement (parser
);
1854 finish_declspecs (specs
);
1855 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1856 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1859 error_at (here
, "%<__auto_type%> in empty declaration");
1860 else if (specs
->typespec_kind
== ctsk_none
1861 && attribute_fallthrough_p (specs
->attrs
))
1863 if (fallthru_attr_p
!= NULL
)
1864 *fallthru_attr_p
= true;
1865 tree fn
= build_call_expr_internal_loc (here
, IFN_FALLTHROUGH
,
1873 shadow_tag_warned (specs
, 1);
1874 pedwarn (here
, 0, "empty declaration");
1876 c_parser_consume_token (parser
);
1877 if (oacc_routine_data
)
1878 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1882 /* Provide better error recovery. Note that a type name here is usually
1883 better diagnosed as a redeclaration. */
1885 && specs
->typespec_kind
== ctsk_tagdef
1886 && c_parser_next_token_starts_declspecs (parser
)
1887 && !c_parser_next_token_is (parser
, CPP_NAME
))
1889 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1890 parser
->error
= false;
1891 shadow_tag_warned (specs
, 1);
1894 else if (c_dialect_objc () && !auto_type_p
)
1896 /* Prefix attributes are an error on method decls. */
1897 switch (c_parser_peek_token (parser
)->type
)
1901 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1905 warning_at (c_parser_peek_token (parser
)->location
,
1907 "prefix attributes are ignored for methods");
1908 specs
->attrs
= NULL_TREE
;
1911 c_parser_objc_method_definition (parser
);
1913 c_parser_objc_methodproto (parser
);
1919 /* This is where we parse 'attributes @interface ...',
1920 'attributes @implementation ...', 'attributes @protocol ...'
1921 (where attributes could be, for example, __attribute__
1924 switch (c_parser_peek_token (parser
)->keyword
)
1926 case RID_AT_INTERFACE
:
1928 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1930 c_parser_objc_class_definition (parser
, specs
->attrs
);
1934 case RID_AT_IMPLEMENTATION
:
1936 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1940 warning_at (c_parser_peek_token (parser
)->location
,
1942 "prefix attributes are ignored for implementations");
1943 specs
->attrs
= NULL_TREE
;
1945 c_parser_objc_class_definition (parser
, NULL_TREE
);
1949 case RID_AT_PROTOCOL
:
1951 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1953 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1960 case RID_AT_PROPERTY
:
1963 c_parser_error (parser
, "unexpected attribute");
1964 specs
->attrs
= NULL
;
1971 else if (attribute_fallthrough_p (specs
->attrs
))
1972 warning_at (here
, OPT_Wattributes
,
1973 "%<fallthrough%> attribute not followed by %<;%>");
1975 pending_xref_error ();
1976 prefix_attrs
= specs
->attrs
;
1977 all_prefix_attrs
= prefix_attrs
;
1978 specs
->attrs
= NULL_TREE
;
1981 struct c_declarator
*declarator
;
1984 tree fnbody
= NULL_TREE
;
1985 /* Declaring either one or more declarators (in which case we
1986 should diagnose if there were no declaration specifiers) or a
1987 function definition (in which case the diagnostic for
1988 implicit int suffices). */
1989 declarator
= c_parser_declarator (parser
,
1990 specs
->typespec_kind
!= ctsk_none
,
1991 C_DTR_NORMAL
, &dummy
);
1992 if (declarator
== NULL
)
1994 if (omp_declare_simd_clauses
.exists ())
1995 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1996 omp_declare_simd_clauses
);
1997 if (oacc_routine_data
)
1998 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1999 c_parser_skip_to_end_of_block_or_statement (parser
);
2002 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
2005 "%<__auto_type%> requires a plain identifier"
2007 c_parser_skip_to_end_of_block_or_statement (parser
);
2010 if (c_parser_next_token_is (parser
, CPP_EQ
)
2011 || c_parser_next_token_is (parser
, CPP_COMMA
)
2012 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2013 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
2014 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
2015 || c_parser_next_token_is_keyword (parser
, RID_IN
))
2017 tree asm_name
= NULL_TREE
;
2018 tree postfix_attrs
= NULL_TREE
;
2019 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
2021 diagnosed_no_specs
= true;
2022 pedwarn (here
, 0, "data definition has no type or storage class");
2024 /* Having seen a data definition, there cannot now be a
2025 function definition. */
2027 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
2028 asm_name
= c_parser_simple_asm_expr (parser
);
2029 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2031 postfix_attrs
= c_parser_attributes (parser
);
2032 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2034 /* This means there is an attribute specifier after
2035 the declarator in a function definition. Provide
2036 some more information for the user. */
2037 error_at (here
, "attributes should be specified before the "
2038 "declarator in a function definition");
2039 c_parser_skip_to_end_of_block_or_statement (parser
);
2043 if (c_parser_next_token_is (parser
, CPP_EQ
))
2047 location_t init_loc
;
2048 c_parser_consume_token (parser
);
2051 init_loc
= c_parser_peek_token (parser
)->location
;
2052 rich_location
richloc (line_table
, init_loc
);
2053 start_init (NULL_TREE
, asm_name
, global_bindings_p (), &richloc
);
2054 /* A parameter is initialized, which is invalid. Don't
2055 attempt to instrument the initializer. */
2056 int flag_sanitize_save
= flag_sanitize
;
2057 if (nested
&& !empty_ok
)
2059 init
= c_parser_expr_no_commas (parser
, NULL
);
2060 flag_sanitize
= flag_sanitize_save
;
2061 if (TREE_CODE (init
.value
) == COMPONENT_REF
2062 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
2064 "%<__auto_type%> used with a bit-field"
2066 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
2067 tree init_type
= TREE_TYPE (init
.value
);
2068 /* As with typeof, remove all qualifiers from atomic types. */
2069 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
2071 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
2072 bool vm_type
= variably_modified_type_p (init_type
,
2075 init
.value
= save_expr (init
.value
);
2077 specs
->typespec_kind
= ctsk_typeof
;
2078 specs
->locations
[cdw_typedef
] = init_loc
;
2079 specs
->typedef_p
= true;
2080 specs
->type
= init_type
;
2083 bool maybe_const
= true;
2084 tree type_expr
= c_fully_fold (init
.value
, false,
2086 specs
->expr_const_operands
&= maybe_const
;
2088 specs
->expr
= build2 (COMPOUND_EXPR
,
2089 TREE_TYPE (type_expr
),
2090 specs
->expr
, type_expr
);
2092 specs
->expr
= type_expr
;
2094 d
= start_decl (declarator
, specs
, true,
2095 chainon (postfix_attrs
, all_prefix_attrs
));
2097 d
= error_mark_node
;
2098 if (omp_declare_simd_clauses
.exists ())
2099 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
2100 omp_declare_simd_clauses
);
2104 /* The declaration of the variable is in effect while
2105 its initializer is parsed. */
2106 d
= start_decl (declarator
, specs
, true,
2107 chainon (postfix_attrs
, all_prefix_attrs
));
2109 d
= error_mark_node
;
2110 if (omp_declare_simd_clauses
.exists ())
2111 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
2112 omp_declare_simd_clauses
);
2113 init_loc
= c_parser_peek_token (parser
)->location
;
2114 rich_location
richloc (line_table
, init_loc
);
2115 start_init (d
, asm_name
, global_bindings_p (), &richloc
);
2116 /* A parameter is initialized, which is invalid. Don't
2117 attempt to instrument the initializer. */
2118 int flag_sanitize_save
= flag_sanitize
;
2119 if (TREE_CODE (d
) == PARM_DECL
)
2121 init
= c_parser_initializer (parser
);
2122 flag_sanitize
= flag_sanitize_save
;
2125 if (oacc_routine_data
)
2126 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2127 if (d
!= error_mark_node
)
2129 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
2130 finish_decl (d
, init_loc
, init
.value
,
2131 init
.original_type
, asm_name
);
2139 "%<__auto_type%> requires an initialized "
2140 "data declaration");
2141 c_parser_skip_to_end_of_block_or_statement (parser
);
2144 tree d
= start_decl (declarator
, specs
, false,
2145 chainon (postfix_attrs
,
2147 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
2148 if (declarator
->kind
== cdk_function
)
2149 if (DECL_ARGUMENTS (d
) == NULL_TREE
)
2150 DECL_ARGUMENTS (d
) = declarator
->u
.arg_info
->parms
;
2151 if (omp_declare_simd_clauses
.exists ())
2153 tree parms
= NULL_TREE
;
2154 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
2156 struct c_declarator
*ce
= declarator
;
2158 if (ce
->kind
== cdk_function
)
2160 parms
= ce
->u
.arg_info
->parms
;
2164 ce
= ce
->declarator
;
2167 temp_store_parm_decls (d
, parms
);
2168 c_finish_omp_declare_simd (parser
, d
, parms
,
2169 omp_declare_simd_clauses
);
2171 temp_pop_parm_decls ();
2173 if (oacc_routine_data
)
2174 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2176 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
2177 NULL_TREE
, asm_name
);
2179 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2182 *objc_foreach_object_declaration
= d
;
2184 *objc_foreach_object_declaration
= error_mark_node
;
2187 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2192 "%<__auto_type%> may only be used with"
2193 " a single declarator");
2194 c_parser_skip_to_end_of_block_or_statement (parser
);
2197 c_parser_consume_token (parser
);
2198 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2199 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2202 all_prefix_attrs
= prefix_attrs
;
2205 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2207 c_parser_consume_token (parser
);
2210 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2212 /* This can only happen in Objective-C: we found the
2213 'in' that terminates the declaration inside an
2214 Objective-C foreach statement. Do not consume the
2215 token, so that the caller can use it to determine
2216 that this indeed is a foreach context. */
2221 c_parser_error (parser
, "expected %<,%> or %<;%>");
2222 c_parser_skip_to_end_of_block_or_statement (parser
);
2226 else if (auto_type_p
)
2229 "%<__auto_type%> requires an initialized data declaration");
2230 c_parser_skip_to_end_of_block_or_statement (parser
);
2235 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
2236 "%<asm%> or %<__attribute__%>");
2237 c_parser_skip_to_end_of_block_or_statement (parser
);
2240 /* Function definition (nested or otherwise). */
2243 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
2244 c_push_function_context ();
2246 if (!start_function (specs
, declarator
, all_prefix_attrs
))
2248 /* At this point we've consumed:
2249 declaration-specifiers declarator
2250 and the next token isn't CPP_EQ, CPP_COMMA, CPP_SEMICOLON,
2251 RID_ASM, RID_ATTRIBUTE, or RID_IN,
2253 declaration-specifiers declarator
2254 aren't grokkable as a function definition, so we have
2256 gcc_assert (!c_parser_next_token_is (parser
, CPP_SEMICOLON
));
2257 if (c_parser_next_token_starts_declspecs (parser
))
2260 declaration-specifiers declarator decl-specs
2261 then assume we have a missing semicolon, which would
2263 declaration-specifiers declarator decl-specs
2266 <~~~~~~~~~ declaration ~~~~~~~~~~>
2267 Use c_parser_require to get an error with a fix-it hint. */
2268 c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>");
2269 parser
->error
= false;
2273 /* This can appear in many cases looking nothing like a
2274 function definition, so we don't give a more specific
2275 error suggesting there was one. */
2276 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2277 "or %<__attribute__%>");
2280 c_pop_function_context ();
2284 if (DECL_DECLARED_INLINE_P (current_function_decl
))
2285 tv
= TV_PARSE_INLINE
;
2288 auto_timevar
at (g_timer
, tv
);
2290 /* Parse old-style parameter declarations. ??? Attributes are
2291 not allowed to start declaration specifiers here because of a
2292 syntax conflict between a function declaration with attribute
2293 suffix and a function definition with an attribute prefix on
2294 first old-style parameter declaration. Following the old
2295 parser, they are not accepted on subsequent old-style
2296 parameter declarations either. However, there is no
2297 ambiguity after the first declaration, nor indeed on the
2298 first as long as we don't allow postfix attributes after a
2299 declarator with a nonempty identifier list in a definition;
2300 and postfix attributes have never been accepted here in
2301 function definitions either. */
2302 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
2303 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
2304 c_parser_declaration_or_fndef (parser
, false, false, false,
2305 true, false, NULL
, vNULL
);
2306 store_parm_decls ();
2307 if (omp_declare_simd_clauses
.exists ())
2308 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
2309 omp_declare_simd_clauses
);
2310 if (oacc_routine_data
)
2311 c_finish_oacc_routine (oacc_routine_data
, current_function_decl
, true);
2312 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
2313 = c_parser_peek_token (parser
)->location
;
2315 /* If the definition was marked with __GIMPLE then parse the
2316 function body as GIMPLE. */
2317 if (specs
->gimple_p
)
2319 cfun
->pass_startwith
= specs
->gimple_or_rtl_pass
;
2320 bool saved
= in_late_binary_op
;
2321 in_late_binary_op
= true;
2322 c_parser_parse_gimple_body (parser
);
2323 in_late_binary_op
= saved
;
2325 /* Similarly, if it was marked with __RTL, use the RTL parser now,
2326 consuming the function body. */
2327 else if (specs
->rtl_p
)
2329 c_parser_parse_rtl_body (parser
, specs
->gimple_or_rtl_pass
);
2331 /* Normally, store_parm_decls sets next_is_function_body,
2332 anticipating a function body. We need a push_scope/pop_scope
2333 pair to flush out this state, or subsequent function parsing
2342 fnbody
= c_parser_compound_statement (parser
);
2343 tree fndecl
= current_function_decl
;
2346 tree decl
= current_function_decl
;
2347 /* Mark nested functions as needing static-chain initially.
2348 lower_nested_functions will recompute it but the
2349 DECL_STATIC_CHAIN flag is also used before that happens,
2350 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2351 DECL_STATIC_CHAIN (decl
) = 1;
2354 c_pop_function_context ();
2355 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
2363 /* Get rid of the empty stmt list for GIMPLE. */
2364 if (specs
->gimple_p
)
2365 DECL_SAVED_TREE (fndecl
) = NULL_TREE
;
2371 /* Parse an asm-definition (asm() outside a function body). This is a
2379 c_parser_asm_definition (c_parser
*parser
)
2381 tree asm_str
= c_parser_simple_asm_expr (parser
);
2383 symtab
->finalize_toplevel_asm (asm_str
);
2384 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2387 /* Parse a static assertion (C11 6.7.10).
2389 static_assert-declaration:
2390 static_assert-declaration-no-semi ;
2394 c_parser_static_assert_declaration (c_parser
*parser
)
2396 c_parser_static_assert_declaration_no_semi (parser
);
2398 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2399 c_parser_skip_to_end_of_block_or_statement (parser
);
2402 /* Parse a static assertion (C11 6.7.10), without the trailing
2405 static_assert-declaration-no-semi:
2406 _Static_assert ( constant-expression , string-literal )
2410 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2412 location_t assert_loc
, value_loc
;
2416 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2417 assert_loc
= c_parser_peek_token (parser
)->location
;
2419 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2420 "ISO C99 does not support %<_Static_assert%>");
2422 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2423 "ISO C90 does not support %<_Static_assert%>");
2424 c_parser_consume_token (parser
);
2425 matching_parens parens
;
2426 if (!parens
.require_open (parser
))
2428 location_t value_tok_loc
= c_parser_peek_token (parser
)->location
;
2429 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2430 value_loc
= EXPR_LOC_OR_LOC (value
, value_tok_loc
);
2431 parser
->lex_untranslated_string
= true;
2432 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2434 parser
->lex_untranslated_string
= false;
2437 switch (c_parser_peek_token (parser
)->type
)
2443 case CPP_UTF8STRING
:
2444 string
= c_parser_peek_token (parser
)->value
;
2445 c_parser_consume_token (parser
);
2446 parser
->lex_untranslated_string
= false;
2449 c_parser_error (parser
, "expected string literal");
2450 parser
->lex_untranslated_string
= false;
2453 parens
.require_close (parser
);
2455 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2457 error_at (value_loc
, "expression in static assertion is not an integer");
2460 if (TREE_CODE (value
) != INTEGER_CST
)
2462 value
= c_fully_fold (value
, false, NULL
);
2463 /* Strip no-op conversions. */
2464 STRIP_TYPE_NOPS (value
);
2465 if (TREE_CODE (value
) == INTEGER_CST
)
2466 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2467 "is not an integer constant expression");
2469 if (TREE_CODE (value
) != INTEGER_CST
)
2471 error_at (value_loc
, "expression in static assertion is not constant");
2474 constant_expression_warning (value
);
2475 if (integer_zerop (value
))
2476 error_at (assert_loc
, "static assertion failed: %E", string
);
2479 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2480 6.7, C11 6.7), adding them to SPECS (which may already include some).
2481 Storage class specifiers are accepted iff SCSPEC_OK; type
2482 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2483 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2484 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2486 declaration-specifiers:
2487 storage-class-specifier declaration-specifiers[opt]
2488 type-specifier declaration-specifiers[opt]
2489 type-qualifier declaration-specifiers[opt]
2490 function-specifier declaration-specifiers[opt]
2491 alignment-specifier declaration-specifiers[opt]
2493 Function specifiers (inline) are from C99, and are currently
2494 handled as storage class specifiers, as is __thread. Alignment
2495 specifiers are from C11.
2497 C90 6.5.1, C99 6.7.1, C11 6.7.1:
2498 storage-class-specifier:
2506 (_Thread_local is new in C11.)
2508 C99 6.7.4, C11 6.7.4:
2513 (_Noreturn is new in C11.)
2515 C90 6.5.2, C99 6.7.2, C11 6.7.2:
2528 [_Imaginary removed in C99 TC2]
2529 struct-or-union-specifier
2532 atomic-type-specifier
2534 (_Bool and _Complex are new in C99.)
2535 (atomic-type-specifier is new in C11.)
2537 C90 6.5.3, C99 6.7.3, C11 6.7.3:
2543 address-space-qualifier
2546 (restrict is new in C99.)
2547 (_Atomic is new in C11.)
2551 declaration-specifiers:
2552 attributes declaration-specifiers[opt]
2558 identifier recognized by the target
2560 storage-class-specifier:
2574 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2575 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2577 atomic-type-specifier
2578 _Atomic ( type-name )
2583 class-name objc-protocol-refs[opt]
2584 typedef-name objc-protocol-refs
2589 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2590 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2591 bool alignspec_ok
, bool auto_type_ok
,
2592 enum c_lookahead_kind la
)
2594 bool attrs_ok
= start_attr_ok
;
2595 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2598 gcc_assert (la
== cla_prefer_id
);
2600 while (c_parser_next_token_is (parser
, CPP_NAME
)
2601 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2602 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2604 struct c_typespec t
;
2607 location_t loc
= c_parser_peek_token (parser
)->location
;
2609 /* If we cannot accept a type, exit if the next token must start
2610 one. Also, if we already have seen a tagged definition,
2611 a typename would be an error anyway and likely the user
2612 has simply forgotten a semicolon, so we exit. */
2613 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2614 && c_parser_next_tokens_start_typename (parser
, la
)
2615 && !c_parser_next_token_is_qualifier (parser
)
2616 && !c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
))
2619 if (c_parser_next_token_is (parser
, CPP_NAME
))
2621 c_token
*name_token
= c_parser_peek_token (parser
);
2622 tree value
= name_token
->value
;
2623 c_id_kind kind
= name_token
->id_kind
;
2625 if (kind
== C_ID_ADDRSPACE
)
2628 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2629 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2630 c_parser_consume_token (parser
);
2635 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2637 /* If we cannot accept a type, and the next token must start one,
2638 exit. Do the same if we already have seen a tagged definition,
2639 since it would be an error anyway and likely the user has simply
2640 forgotten a semicolon. */
2641 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2644 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2645 a C_ID_CLASSNAME. */
2646 c_parser_consume_token (parser
);
2649 if (kind
== C_ID_ID
)
2651 error_at (loc
, "unknown type name %qE", value
);
2652 t
.kind
= ctsk_typedef
;
2653 t
.spec
= error_mark_node
;
2655 else if (kind
== C_ID_TYPENAME
2656 && (!c_dialect_objc ()
2657 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2659 t
.kind
= ctsk_typedef
;
2660 /* For a typedef name, record the meaning, not the name.
2661 In case of 'foo foo, bar;'. */
2662 t
.spec
= lookup_name (value
);
2666 tree proto
= NULL_TREE
;
2667 gcc_assert (c_dialect_objc ());
2669 if (c_parser_next_token_is (parser
, CPP_LESS
))
2670 proto
= c_parser_objc_protocol_refs (parser
);
2671 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2674 t
.expr_const_operands
= true;
2675 declspecs_add_type (name_token
->location
, specs
, t
);
2678 if (c_parser_next_token_is (parser
, CPP_LESS
))
2680 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2681 nisse@lysator.liu.se. */
2683 gcc_assert (c_dialect_objc ());
2684 if (!typespec_ok
|| seen_type
)
2686 proto
= c_parser_objc_protocol_refs (parser
);
2688 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2690 t
.expr_const_operands
= true;
2691 declspecs_add_type (loc
, specs
, t
);
2694 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2695 switch (c_parser_peek_token (parser
)->keyword
)
2708 /* TODO: Distinguish between function specifiers (inline, noreturn)
2709 and storage class specifiers, either here or in
2710 declspecs_add_scspec. */
2711 declspecs_add_scspec (loc
, specs
,
2712 c_parser_peek_token (parser
)->value
);
2713 c_parser_consume_token (parser
);
2745 if (c_dialect_objc ())
2746 parser
->objc_need_raw_identifier
= true;
2747 t
.kind
= ctsk_resword
;
2748 t
.spec
= c_parser_peek_token (parser
)->value
;
2750 t
.expr_const_operands
= true;
2751 declspecs_add_type (loc
, specs
, t
);
2752 c_parser_consume_token (parser
);
2759 t
= c_parser_enum_specifier (parser
);
2760 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2761 declspecs_add_type (loc
, specs
, t
);
2769 t
= c_parser_struct_or_union_specifier (parser
);
2770 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2771 declspecs_add_type (loc
, specs
, t
);
2774 /* ??? The old parser rejected typeof after other type
2775 specifiers, but is a syntax error the best way of
2777 if (!typespec_ok
|| seen_type
)
2781 t
= c_parser_typeof_specifier (parser
);
2782 declspecs_add_type (loc
, specs
, t
);
2785 /* C parser handling of Objective-C constructs needs
2786 checking for correct lvalue-to-rvalue conversions, and
2787 the code in build_modify_expr handling various
2788 Objective-C cases, and that in build_unary_op handling
2789 Objective-C cases for increment / decrement, also needs
2790 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2791 and objc_types_are_equivalent may also need updates. */
2792 if (c_dialect_objc ())
2793 sorry ("%<_Atomic%> in Objective-C");
2795 pedwarn_c99 (loc
, OPT_Wpedantic
,
2796 "ISO C99 does not support the %<_Atomic%> qualifier");
2798 pedwarn_c99 (loc
, OPT_Wpedantic
,
2799 "ISO C90 does not support the %<_Atomic%> qualifier");
2802 value
= c_parser_peek_token (parser
)->value
;
2803 c_parser_consume_token (parser
);
2804 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2806 /* _Atomic ( type-name ). */
2808 c_parser_consume_token (parser
);
2809 struct c_type_name
*type
= c_parser_type_name (parser
);
2810 t
.kind
= ctsk_typeof
;
2811 t
.spec
= error_mark_node
;
2813 t
.expr_const_operands
= true;
2815 t
.spec
= groktypename (type
, &t
.expr
,
2816 &t
.expr_const_operands
);
2817 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2819 if (t
.spec
!= error_mark_node
)
2821 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2822 error_at (loc
, "%<_Atomic%>-qualified array type");
2823 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2824 error_at (loc
, "%<_Atomic%>-qualified function type");
2825 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2826 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2828 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2830 declspecs_add_type (loc
, specs
, t
);
2833 declspecs_add_qual (loc
, specs
, value
);
2839 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2840 c_parser_consume_token (parser
);
2845 attrs
= c_parser_attributes (parser
);
2846 declspecs_add_attrs (loc
, specs
, attrs
);
2851 align
= c_parser_alignas_specifier (parser
);
2852 declspecs_add_alignas (loc
, specs
, align
);
2856 error_at (loc
, "%<__GIMPLE%> only valid with -fgimple");
2857 c_parser_consume_token (parser
);
2858 specs
->gimple_p
= true;
2859 specs
->locations
[cdw_gimple
] = loc
;
2860 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2863 c_parser_consume_token (parser
);
2864 specs
->rtl_p
= true;
2865 specs
->locations
[cdw_rtl
] = loc
;
2866 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2875 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2, C11 6.7.2.2).
2878 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2879 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2880 enum attributes[opt] identifier
2882 The form with trailing comma is new in C99. The forms with
2883 attributes are GNU extensions. In GNU C, we accept any expression
2884 without commas in the syntax (assignment expressions, not just
2885 conditional expressions); assignment expressions will be diagnosed
2890 enumerator-list , enumerator
2893 enumeration-constant
2894 enumeration-constant = constant-expression
2899 enumeration-constant attributes[opt]
2900 enumeration-constant attributes[opt] = constant-expression
2904 static struct c_typespec
2905 c_parser_enum_specifier (c_parser
*parser
)
2907 struct c_typespec ret
;
2909 tree ident
= NULL_TREE
;
2910 location_t enum_loc
;
2911 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2912 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2913 c_parser_consume_token (parser
);
2914 attrs
= c_parser_attributes (parser
);
2915 enum_loc
= c_parser_peek_token (parser
)->location
;
2916 /* Set the location in case we create a decl now. */
2917 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2918 if (c_parser_next_token_is (parser
, CPP_NAME
))
2920 ident
= c_parser_peek_token (parser
)->value
;
2921 ident_loc
= c_parser_peek_token (parser
)->location
;
2922 enum_loc
= ident_loc
;
2923 c_parser_consume_token (parser
);
2925 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2927 /* Parse an enum definition. */
2928 struct c_enum_contents the_enum
;
2931 /* We chain the enumerators in reverse order, then put them in
2932 forward order at the end. */
2934 timevar_push (TV_PARSE_ENUM
);
2935 type
= start_enum (enum_loc
, &the_enum
, ident
);
2937 c_parser_consume_token (parser
);
2945 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2946 location_t decl_loc
, value_loc
;
2947 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2949 /* Give a nicer error for "enum {}". */
2950 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2953 error_at (c_parser_peek_token (parser
)->location
,
2954 "empty enum is invalid");
2955 parser
->error
= true;
2958 c_parser_error (parser
, "expected identifier");
2959 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2960 values
= error_mark_node
;
2963 token
= c_parser_peek_token (parser
);
2964 enum_id
= token
->value
;
2965 /* Set the location in case we create a decl now. */
2966 c_parser_set_source_position_from_token (token
);
2967 decl_loc
= value_loc
= token
->location
;
2968 c_parser_consume_token (parser
);
2969 /* Parse any specified attributes. */
2970 tree enum_attrs
= c_parser_attributes (parser
);
2971 if (c_parser_next_token_is (parser
, CPP_EQ
))
2973 c_parser_consume_token (parser
);
2974 value_loc
= c_parser_peek_token (parser
)->location
;
2975 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2978 enum_value
= NULL_TREE
;
2979 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2980 &the_enum
, enum_id
, enum_value
);
2982 decl_attributes (&TREE_PURPOSE (enum_decl
), enum_attrs
, 0);
2983 TREE_CHAIN (enum_decl
) = values
;
2986 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2988 comma_loc
= c_parser_peek_token (parser
)->location
;
2990 c_parser_consume_token (parser
);
2992 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2995 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2996 "comma at end of enumerator list");
2997 c_parser_consume_token (parser
);
3002 c_parser_error (parser
, "expected %<,%> or %<}%>");
3003 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
3004 values
= error_mark_node
;
3008 postfix_attrs
= c_parser_attributes (parser
);
3009 ret
.spec
= finish_enum (type
, nreverse (values
),
3010 chainon (attrs
, postfix_attrs
));
3011 ret
.kind
= ctsk_tagdef
;
3012 ret
.expr
= NULL_TREE
;
3013 ret
.expr_const_operands
= true;
3014 timevar_pop (TV_PARSE_ENUM
);
3019 c_parser_error (parser
, "expected %<{%>");
3020 ret
.spec
= error_mark_node
;
3021 ret
.kind
= ctsk_tagref
;
3022 ret
.expr
= NULL_TREE
;
3023 ret
.expr_const_operands
= true;
3026 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
3027 /* In ISO C, enumerated types can be referred to only if already
3029 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
3032 pedwarn (enum_loc
, OPT_Wpedantic
,
3033 "ISO C forbids forward references to %<enum%> types");
3038 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1).
3040 struct-or-union-specifier:
3041 struct-or-union attributes[opt] identifier[opt]
3042 { struct-contents } attributes[opt]
3043 struct-or-union attributes[opt] identifier
3046 struct-declaration-list
3048 struct-declaration-list:
3049 struct-declaration ;
3050 struct-declaration-list struct-declaration ;
3057 struct-declaration-list struct-declaration
3059 struct-declaration-list:
3060 struct-declaration-list ;
3063 (Note that in the syntax here, unlike that in ISO C, the semicolons
3064 are included here rather than in struct-declaration, in order to
3065 describe the syntax with extra semicolons and missing semicolon at
3070 struct-declaration-list:
3071 @defs ( class-name )
3073 (Note this does not include a trailing semicolon, but can be
3074 followed by further declarations, and gets a pedwarn-if-pedantic
3075 when followed by a semicolon.) */
3077 static struct c_typespec
3078 c_parser_struct_or_union_specifier (c_parser
*parser
)
3080 struct c_typespec ret
;
3082 tree ident
= NULL_TREE
;
3083 location_t struct_loc
;
3084 location_t ident_loc
= UNKNOWN_LOCATION
;
3085 enum tree_code code
;
3086 switch (c_parser_peek_token (parser
)->keyword
)
3097 struct_loc
= c_parser_peek_token (parser
)->location
;
3098 c_parser_consume_token (parser
);
3099 attrs
= c_parser_attributes (parser
);
3101 /* Set the location in case we create a decl now. */
3102 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
3104 if (c_parser_next_token_is (parser
, CPP_NAME
))
3106 ident
= c_parser_peek_token (parser
)->value
;
3107 ident_loc
= c_parser_peek_token (parser
)->location
;
3108 struct_loc
= ident_loc
;
3109 c_parser_consume_token (parser
);
3111 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3113 /* Parse a struct or union definition. Start the scope of the
3114 tag before parsing components. */
3115 struct c_struct_parse_info
*struct_info
;
3116 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
3118 /* We chain the components in reverse order, then put them in
3119 forward order at the end. Each struct-declaration may
3120 declare multiple components (comma-separated), so we must use
3121 chainon to join them, although when parsing each
3122 struct-declaration we can use TREE_CHAIN directly.
3124 The theory behind all this is that there will be more
3125 semicolon separated fields than comma separated fields, and
3126 so we'll be minimizing the number of node traversals required
3129 timevar_push (TV_PARSE_STRUCT
);
3130 contents
= NULL_TREE
;
3131 c_parser_consume_token (parser
);
3132 /* Handle the Objective-C @defs construct,
3133 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
3134 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
3137 gcc_assert (c_dialect_objc ());
3138 c_parser_consume_token (parser
);
3139 matching_parens parens
;
3140 if (!parens
.require_open (parser
))
3142 if (c_parser_next_token_is (parser
, CPP_NAME
)
3143 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
3145 name
= c_parser_peek_token (parser
)->value
;
3146 c_parser_consume_token (parser
);
3150 c_parser_error (parser
, "expected class name");
3151 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3154 parens
.skip_until_found_close (parser
);
3155 contents
= nreverse (objc_get_class_ivars (name
));
3158 /* Parse the struct-declarations and semicolons. Problems with
3159 semicolons are diagnosed here; empty structures are diagnosed
3164 /* Parse any stray semicolon. */
3165 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3167 location_t semicolon_loc
3168 = c_parser_peek_token (parser
)->location
;
3169 gcc_rich_location
richloc (semicolon_loc
);
3170 richloc
.add_fixit_remove ();
3171 pedwarn (&richloc
, OPT_Wpedantic
,
3172 "extra semicolon in struct or union specified");
3173 c_parser_consume_token (parser
);
3176 /* Stop if at the end of the struct or union contents. */
3177 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3179 c_parser_consume_token (parser
);
3182 /* Accept #pragmas at struct scope. */
3183 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3185 c_parser_pragma (parser
, pragma_struct
, NULL
);
3188 /* Parse some comma-separated declarations, but not the
3189 trailing semicolon if any. */
3190 decls
= c_parser_struct_declaration (parser
);
3191 contents
= chainon (decls
, contents
);
3192 /* If no semicolon follows, either we have a parse error or
3193 are at the end of the struct or union and should
3195 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3196 c_parser_consume_token (parser
);
3199 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3200 pedwarn (c_parser_peek_token (parser
)->location
, 0,
3201 "no semicolon at end of struct or union");
3202 else if (parser
->error
3203 || !c_parser_next_token_starts_declspecs (parser
))
3205 c_parser_error (parser
, "expected %<;%>");
3206 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
3210 /* If we come here, we have already emitted an error
3211 for an expected `;', identifier or `(', and we also
3212 recovered already. Go on with the next field. */
3215 postfix_attrs
= c_parser_attributes (parser
);
3216 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
3217 chainon (attrs
, postfix_attrs
), struct_info
);
3218 ret
.kind
= ctsk_tagdef
;
3219 ret
.expr
= NULL_TREE
;
3220 ret
.expr_const_operands
= true;
3221 timevar_pop (TV_PARSE_STRUCT
);
3226 c_parser_error (parser
, "expected %<{%>");
3227 ret
.spec
= error_mark_node
;
3228 ret
.kind
= ctsk_tagref
;
3229 ret
.expr
= NULL_TREE
;
3230 ret
.expr_const_operands
= true;
3233 ret
= parser_xref_tag (ident_loc
, code
, ident
);
3237 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1),
3238 *without* the trailing semicolon.
3241 specifier-qualifier-list struct-declarator-list
3242 static_assert-declaration-no-semi
3244 specifier-qualifier-list:
3245 type-specifier specifier-qualifier-list[opt]
3246 type-qualifier specifier-qualifier-list[opt]
3247 alignment-specifier specifier-qualifier-list[opt]
3248 attributes specifier-qualifier-list[opt]
3250 struct-declarator-list:
3252 struct-declarator-list , attributes[opt] struct-declarator
3255 declarator attributes[opt]
3256 declarator[opt] : constant-expression attributes[opt]
3261 __extension__ struct-declaration
3262 specifier-qualifier-list
3264 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
3265 of attributes where shown is a GNU extension. In GNU C, we accept
3266 any expression without commas in the syntax (assignment
3267 expressions, not just conditional expressions); assignment
3268 expressions will be diagnosed as non-constant. */
3271 c_parser_struct_declaration (c_parser
*parser
)
3273 struct c_declspecs
*specs
;
3275 tree all_prefix_attrs
;
3277 location_t decl_loc
;
3278 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3282 ext
= disable_extension_diagnostics ();
3283 c_parser_consume_token (parser
);
3284 decl
= c_parser_struct_declaration (parser
);
3285 restore_extension_diagnostics (ext
);
3288 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
3290 c_parser_static_assert_declaration_no_semi (parser
);
3293 specs
= build_null_declspecs ();
3294 decl_loc
= c_parser_peek_token (parser
)->location
;
3295 /* Strictly by the standard, we shouldn't allow _Alignas here,
3296 but it appears to have been intended to allow it there, so
3297 we're keeping it as it is until WG14 reaches a conclusion
3299 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
3300 c_parser_declspecs (parser
, specs
, false, true, true,
3301 true, false, cla_nonabstract_decl
);
3304 if (!specs
->declspecs_seen_p
)
3306 c_parser_error (parser
, "expected specifier-qualifier-list");
3309 finish_declspecs (specs
);
3310 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3311 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3314 if (specs
->typespec_kind
== ctsk_none
)
3316 pedwarn (decl_loc
, OPT_Wpedantic
,
3317 "ISO C forbids member declarations with no members");
3318 shadow_tag_warned (specs
, pedantic
);
3323 /* Support for unnamed structs or unions as members of
3324 structs or unions (which is [a] useful and [b] supports
3328 ret
= grokfield (c_parser_peek_token (parser
)->location
,
3329 build_id_declarator (NULL_TREE
), specs
,
3332 decl_attributes (&ret
, attrs
, 0);
3337 /* Provide better error recovery. Note that a type name here is valid,
3338 and will be treated as a field name. */
3339 if (specs
->typespec_kind
== ctsk_tagdef
3340 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
3341 && c_parser_next_token_starts_declspecs (parser
)
3342 && !c_parser_next_token_is (parser
, CPP_NAME
))
3344 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
3345 parser
->error
= false;
3349 pending_xref_error ();
3350 prefix_attrs
= specs
->attrs
;
3351 all_prefix_attrs
= prefix_attrs
;
3352 specs
->attrs
= NULL_TREE
;
3356 /* Declaring one or more declarators or un-named bit-fields. */
3357 struct c_declarator
*declarator
;
3359 if (c_parser_next_token_is (parser
, CPP_COLON
))
3360 declarator
= build_id_declarator (NULL_TREE
);
3362 declarator
= c_parser_declarator (parser
,
3363 specs
->typespec_kind
!= ctsk_none
,
3364 C_DTR_NORMAL
, &dummy
);
3365 if (declarator
== NULL
)
3367 c_parser_skip_to_end_of_block_or_statement (parser
);
3370 if (c_parser_next_token_is (parser
, CPP_COLON
)
3371 || c_parser_next_token_is (parser
, CPP_COMMA
)
3372 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3373 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
3374 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3376 tree postfix_attrs
= NULL_TREE
;
3377 tree width
= NULL_TREE
;
3379 if (c_parser_next_token_is (parser
, CPP_COLON
))
3381 c_parser_consume_token (parser
);
3382 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
3384 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3385 postfix_attrs
= c_parser_attributes (parser
);
3386 d
= grokfield (c_parser_peek_token (parser
)->location
,
3387 declarator
, specs
, width
, &all_prefix_attrs
);
3388 decl_attributes (&d
, chainon (postfix_attrs
,
3389 all_prefix_attrs
), 0);
3390 DECL_CHAIN (d
) = decls
;
3392 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3393 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
3396 all_prefix_attrs
= prefix_attrs
;
3397 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3398 c_parser_consume_token (parser
);
3399 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3400 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3402 /* Semicolon consumed in caller. */
3407 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3413 c_parser_error (parser
,
3414 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3415 "%<__attribute__%>");
3422 /* Parse a typeof specifier (a GNU extension).
3425 typeof ( expression )
3426 typeof ( type-name )
3429 static struct c_typespec
3430 c_parser_typeof_specifier (c_parser
*parser
)
3432 struct c_typespec ret
;
3433 ret
.kind
= ctsk_typeof
;
3434 ret
.spec
= error_mark_node
;
3435 ret
.expr
= NULL_TREE
;
3436 ret
.expr_const_operands
= true;
3437 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3438 c_parser_consume_token (parser
);
3439 c_inhibit_evaluation_warnings
++;
3441 matching_parens parens
;
3442 if (!parens
.require_open (parser
))
3444 c_inhibit_evaluation_warnings
--;
3448 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3450 struct c_type_name
*type
= c_parser_type_name (parser
);
3451 c_inhibit_evaluation_warnings
--;
3455 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3456 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3462 location_t here
= c_parser_peek_token (parser
)->location
;
3463 struct c_expr expr
= c_parser_expression (parser
);
3464 c_inhibit_evaluation_warnings
--;
3466 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3467 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3468 error_at (here
, "%<typeof%> applied to a bit-field");
3469 mark_exp_read (expr
.value
);
3470 ret
.spec
= TREE_TYPE (expr
.value
);
3471 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3472 /* This is returned with the type so that when the type is
3473 evaluated, this can be evaluated. */
3475 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3476 pop_maybe_used (was_vm
);
3477 /* For use in macros such as those in <stdatomic.h>, remove all
3478 qualifiers from atomic types. (const can be an issue for more macros
3479 using typeof than just the <stdatomic.h> ones.) */
3480 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3481 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3483 parens
.skip_until_found_close (parser
);
3487 /* Parse an alignment-specifier.
3491 alignment-specifier:
3492 _Alignas ( type-name )
3493 _Alignas ( constant-expression )
3497 c_parser_alignas_specifier (c_parser
* parser
)
3499 tree ret
= error_mark_node
;
3500 location_t loc
= c_parser_peek_token (parser
)->location
;
3501 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3502 c_parser_consume_token (parser
);
3504 pedwarn_c99 (loc
, OPT_Wpedantic
,
3505 "ISO C99 does not support %<_Alignas%>");
3507 pedwarn_c99 (loc
, OPT_Wpedantic
,
3508 "ISO C90 does not support %<_Alignas%>");
3509 matching_parens parens
;
3510 if (!parens
.require_open (parser
))
3512 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3514 struct c_type_name
*type
= c_parser_type_name (parser
);
3516 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3520 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3521 parens
.skip_until_found_close (parser
);
3525 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3526 6.5.5, C99 6.7.5, 6.7.6, C11 6.7.6, 6.7.7). If TYPE_SEEN_P then
3527 a typedef name may be redeclared; otherwise it may not. KIND
3528 indicates which kind of declarator is wanted. Returns a valid
3529 declarator except in the case of a syntax error in which case NULL is
3530 returned. *SEEN_ID is set to true if an identifier being declared is
3531 seen; this is used to diagnose bad forms of abstract array declarators
3532 and to determine whether an identifier list is syntactically permitted.
3535 pointer[opt] direct-declarator
3539 ( attributes[opt] declarator )
3540 direct-declarator array-declarator
3541 direct-declarator ( parameter-type-list )
3542 direct-declarator ( identifier-list[opt] )
3545 * type-qualifier-list[opt]
3546 * type-qualifier-list[opt] pointer
3548 type-qualifier-list:
3551 type-qualifier-list type-qualifier
3552 type-qualifier-list attributes
3555 [ type-qualifier-list[opt] assignment-expression[opt] ]
3556 [ static type-qualifier-list[opt] assignment-expression ]
3557 [ type-qualifier-list static assignment-expression ]
3558 [ type-qualifier-list[opt] * ]
3560 parameter-type-list:
3562 parameter-list , ...
3565 parameter-declaration
3566 parameter-list , parameter-declaration
3568 parameter-declaration:
3569 declaration-specifiers declarator attributes[opt]
3570 declaration-specifiers abstract-declarator[opt] attributes[opt]
3574 identifier-list , identifier
3576 abstract-declarator:
3578 pointer[opt] direct-abstract-declarator
3580 direct-abstract-declarator:
3581 ( attributes[opt] abstract-declarator )
3582 direct-abstract-declarator[opt] array-declarator
3583 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3588 direct-declarator ( parameter-forward-declarations
3589 parameter-type-list[opt] )
3591 direct-abstract-declarator:
3592 direct-abstract-declarator[opt] ( parameter-forward-declarations
3593 parameter-type-list[opt] )
3595 parameter-forward-declarations:
3597 parameter-forward-declarations parameter-list ;
3599 The uses of attributes shown above are GNU extensions.
3601 Some forms of array declarator are not included in C99 in the
3602 syntax for abstract declarators; these are disallowed elsewhere.
3603 This may be a defect (DR#289).
3605 This function also accepts an omitted abstract declarator as being
3606 an abstract declarator, although not part of the formal syntax. */
3608 struct c_declarator
*
3609 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3612 /* Parse any initial pointer part. */
3613 if (c_parser_next_token_is (parser
, CPP_MULT
))
3615 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3616 struct c_declarator
*inner
;
3617 c_parser_consume_token (parser
);
3618 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3619 false, false, cla_prefer_id
);
3620 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3624 return make_pointer_declarator (quals_attrs
, inner
);
3626 /* Now we have a direct declarator, direct abstract declarator or
3627 nothing (which counts as a direct abstract declarator here). */
3628 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3631 /* Parse a direct declarator or direct abstract declarator; arguments
3632 as c_parser_declarator. */
3634 static struct c_declarator
*
3635 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3638 /* The direct declarator must start with an identifier (possibly
3639 omitted) or a parenthesized declarator (possibly abstract). In
3640 an ordinary declarator, initial parentheses must start a
3641 parenthesized declarator. In an abstract declarator or parameter
3642 declarator, they could start a parenthesized declarator or a
3643 parameter list. To tell which, the open parenthesis and any
3644 following attributes must be read. If a declaration specifier
3645 follows, then it is a parameter list; if the specifier is a
3646 typedef name, there might be an ambiguity about redeclaring it,
3647 which is resolved in the direction of treating it as a typedef
3648 name. If a close parenthesis follows, it is also an empty
3649 parameter list, as the syntax does not permit empty abstract
3650 declarators. Otherwise, it is a parenthesized declarator (in
3651 which case the analysis may be repeated inside it, recursively).
3653 ??? There is an ambiguity in a parameter declaration "int
3654 (__attribute__((foo)) x)", where x is not a typedef name: it
3655 could be an abstract declarator for a function, or declare x with
3656 parentheses. The proper resolution of this ambiguity needs
3657 documenting. At present we follow an accident of the old
3658 parser's implementation, whereby the first parameter must have
3659 some declaration specifiers other than just attributes. Thus as
3660 a parameter declaration it is treated as a parenthesized
3661 parameter named x, and as an abstract declarator it is
3664 ??? Also following the old parser, attributes inside an empty
3665 parameter list are ignored, making it a list not yielding a
3666 prototype, rather than giving an error or making it have one
3667 parameter with implicit type int.
3669 ??? Also following the old parser, typedef names may be
3670 redeclared in declarators, but not Objective-C class names. */
3672 if (kind
!= C_DTR_ABSTRACT
3673 && c_parser_next_token_is (parser
, CPP_NAME
)
3675 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3676 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3677 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3679 struct c_declarator
*inner
3680 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3682 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3683 c_parser_consume_token (parser
);
3684 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3687 if (kind
!= C_DTR_NORMAL
3688 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3690 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3691 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3692 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3695 /* Either we are at the end of an abstract declarator, or we have
3698 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3701 struct c_declarator
*inner
;
3702 c_parser_consume_token (parser
);
3703 attrs
= c_parser_attributes (parser
);
3704 if (kind
!= C_DTR_NORMAL
3705 && (c_parser_next_token_starts_declspecs (parser
)
3706 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3708 struct c_arg_info
*args
3709 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3716 = build_function_declarator (args
,
3717 build_id_declarator (NULL_TREE
));
3718 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3722 /* A parenthesized declarator. */
3723 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3724 if (inner
!= NULL
&& attrs
!= NULL
)
3725 inner
= build_attrs_declarator (attrs
, inner
);
3726 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3728 c_parser_consume_token (parser
);
3732 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3736 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3743 if (kind
== C_DTR_NORMAL
)
3745 c_parser_error (parser
, "expected identifier or %<(%>");
3749 return build_id_declarator (NULL_TREE
);
3753 /* Parse part of a direct declarator or direct abstract declarator,
3754 given that some (in INNER) has already been parsed; ID_PRESENT is
3755 true if an identifier is present, false for an abstract
3758 static struct c_declarator
*
3759 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3760 struct c_declarator
*inner
)
3762 /* Parse a sequence of array declarators and parameter lists. */
3763 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3765 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3766 struct c_declarator
*declarator
;
3767 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3770 struct c_expr dimen
;
3771 dimen
.value
= NULL_TREE
;
3772 dimen
.original_code
= ERROR_MARK
;
3773 dimen
.original_type
= NULL_TREE
;
3774 c_parser_consume_token (parser
);
3775 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3776 false, false, cla_prefer_id
);
3777 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3779 c_parser_consume_token (parser
);
3780 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3781 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3782 false, false, cla_prefer_id
);
3783 if (!quals_attrs
->declspecs_seen_p
)
3785 /* If "static" is present, there must be an array dimension.
3786 Otherwise, there may be a dimension, "*", or no
3791 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3795 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3797 dimen
.value
= NULL_TREE
;
3800 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3802 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3804 dimen
.value
= NULL_TREE
;
3806 c_parser_consume_token (parser
);
3811 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3817 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3820 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3821 c_parser_consume_token (parser
);
3824 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3829 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3830 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3831 static_seen
, star_seen
);
3832 if (declarator
== NULL
)
3834 inner
= set_array_declarator_inner (declarator
, inner
);
3835 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3837 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3840 struct c_arg_info
*args
;
3841 c_parser_consume_token (parser
);
3842 attrs
= c_parser_attributes (parser
);
3843 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3848 inner
= build_function_declarator (args
, inner
);
3849 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3855 /* Parse a parameter list or identifier list, including the closing
3856 parenthesis but not the opening one. ATTRS are the attributes at
3857 the start of the list. ID_LIST_OK is true if an identifier list is
3858 acceptable; such a list must not have attributes at the start. */
3860 static struct c_arg_info
*
3861 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3864 declare_parm_level ();
3865 /* If the list starts with an identifier, it is an identifier list.
3866 Otherwise, it is either a prototype list or an empty list. */
3869 && c_parser_next_token_is (parser
, CPP_NAME
)
3870 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3872 /* Look ahead to detect typos in type names. */
3873 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3874 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3875 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3876 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
3877 && c_parser_peek_2nd_token (parser
)->type
!= CPP_KEYWORD
)
3879 tree list
= NULL_TREE
, *nextp
= &list
;
3880 while (c_parser_next_token_is (parser
, CPP_NAME
)
3881 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3883 *nextp
= build_tree_list (NULL_TREE
,
3884 c_parser_peek_token (parser
)->value
);
3885 nextp
= & TREE_CHAIN (*nextp
);
3886 c_parser_consume_token (parser
);
3887 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3889 c_parser_consume_token (parser
);
3890 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3892 c_parser_error (parser
, "expected identifier");
3896 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3898 struct c_arg_info
*ret
= build_arg_info ();
3900 c_parser_consume_token (parser
);
3906 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3914 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3921 /* Parse a parameter list (possibly empty), including the closing
3922 parenthesis but not the opening one. ATTRS are the attributes at
3923 the start of the list. EXPR is NULL or an expression that needs to
3924 be evaluated for the side effects of array size expressions in the
3927 static struct c_arg_info
*
3928 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3930 bool bad_parm
= false;
3932 /* ??? Following the old parser, forward parameter declarations may
3933 use abstract declarators, and if no real parameter declarations
3934 follow the forward declarations then this is not diagnosed. Also
3935 note as above that attributes are ignored as the only contents of
3936 the parentheses, or as the only contents after forward
3938 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3940 struct c_arg_info
*ret
= build_arg_info ();
3941 c_parser_consume_token (parser
);
3944 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3946 struct c_arg_info
*ret
= build_arg_info ();
3948 if (flag_allow_parameterless_variadic_functions
)
3950 /* F (...) is allowed. */
3951 ret
->types
= NULL_TREE
;
3955 /* Suppress -Wold-style-definition for this case. */
3956 ret
->types
= error_mark_node
;
3957 error_at (c_parser_peek_token (parser
)->location
,
3958 "ISO C requires a named argument before %<...%>");
3960 c_parser_consume_token (parser
);
3961 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3963 c_parser_consume_token (parser
);
3968 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3973 /* Nonempty list of parameters, either terminated with semicolon
3974 (forward declarations; recurse) or with close parenthesis (normal
3975 function) or with ", ... )" (variadic function). */
3978 /* Parse a parameter. */
3979 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3984 push_parm_decl (parm
, &expr
);
3985 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3988 c_parser_consume_token (parser
);
3989 mark_forward_parm_decls ();
3990 new_attrs
= c_parser_attributes (parser
);
3991 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3993 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3995 c_parser_consume_token (parser
);
3999 return get_parm_info (false, expr
);
4001 if (!c_parser_require (parser
, CPP_COMMA
,
4002 "expected %<;%>, %<,%> or %<)%>",
4003 UNKNOWN_LOCATION
, false))
4005 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4008 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4010 c_parser_consume_token (parser
);
4011 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4013 c_parser_consume_token (parser
);
4017 return get_parm_info (true, expr
);
4021 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4029 /* Parse a parameter declaration. ATTRS are the attributes at the
4030 start of the declaration if it is the first parameter. */
4032 static struct c_parm
*
4033 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
4035 struct c_declspecs
*specs
;
4036 struct c_declarator
*declarator
;
4038 tree postfix_attrs
= NULL_TREE
;
4041 /* Accept #pragmas between parameter declarations. */
4042 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4043 c_parser_pragma (parser
, pragma_param
, NULL
);
4045 if (!c_parser_next_token_starts_declspecs (parser
))
4047 c_token
*token
= c_parser_peek_token (parser
);
4050 c_parser_set_source_position_from_token (token
);
4051 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
4053 auto_diagnostic_group d
;
4054 name_hint hint
= lookup_name_fuzzy (token
->value
,
4055 FUZZY_LOOKUP_TYPENAME
,
4059 gcc_rich_location
richloc (token
->location
);
4060 richloc
.add_fixit_replace (hint
.suggestion ());
4062 "unknown type name %qE; did you mean %qs?",
4063 token
->value
, hint
.suggestion ());
4066 error_at (token
->location
, "unknown type name %qE", token
->value
);
4067 parser
->error
= true;
4069 /* ??? In some Objective-C cases '...' isn't applicable so there
4070 should be a different message. */
4072 c_parser_error (parser
,
4073 "expected declaration specifiers or %<...%>");
4074 c_parser_skip_to_end_of_parameter (parser
);
4078 location_t start_loc
= c_parser_peek_token (parser
)->location
;
4080 specs
= build_null_declspecs ();
4083 declspecs_add_attrs (input_location
, specs
, attrs
);
4086 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
4087 cla_nonabstract_decl
);
4088 finish_declspecs (specs
);
4089 pending_xref_error ();
4090 prefix_attrs
= specs
->attrs
;
4091 specs
->attrs
= NULL_TREE
;
4092 declarator
= c_parser_declarator (parser
,
4093 specs
->typespec_kind
!= ctsk_none
,
4094 C_DTR_PARM
, &dummy
);
4095 if (declarator
== NULL
)
4097 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4100 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4101 postfix_attrs
= c_parser_attributes (parser
);
4103 /* Generate a location for the parameter, ranging from the start of the
4104 initial token to the end of the final token.
4106 If we have a identifier, then use it for the caret location, e.g.
4108 extern int callee (int one, int (*two)(int, int), float three);
4109 ~~~~~~^~~~~~~~~~~~~~
4111 otherwise, reuse the start location for the caret location e.g.:
4113 extern int callee (int one, int (*)(int, int), float three);
4116 location_t end_loc
= parser
->last_token_location
;
4118 /* Find any cdk_id declarator; determine if we have an identifier. */
4119 c_declarator
*id_declarator
= declarator
;
4120 while (id_declarator
&& id_declarator
->kind
!= cdk_id
)
4121 id_declarator
= id_declarator
->declarator
;
4122 location_t caret_loc
= (id_declarator
->u
.id
4123 ? id_declarator
->id_loc
4125 location_t param_loc
= make_location (caret_loc
, start_loc
, end_loc
);
4127 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
4128 declarator
, param_loc
);
4131 /* Parse a string literal in an asm expression. It should not be
4132 translated, and wide string literals are an error although
4133 permitted by the syntax. This is a GNU extension.
4138 ??? At present, following the old parser, the caller needs to have
4139 set lex_untranslated_string to 1. It would be better to follow the
4140 C++ parser rather than using this kludge. */
4143 c_parser_asm_string_literal (c_parser
*parser
)
4146 int save_flag
= warn_overlength_strings
;
4147 warn_overlength_strings
= 0;
4148 if (c_parser_next_token_is (parser
, CPP_STRING
))
4150 str
= c_parser_peek_token (parser
)->value
;
4151 c_parser_consume_token (parser
);
4153 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
4155 error_at (c_parser_peek_token (parser
)->location
,
4156 "wide string literal in %<asm%>");
4157 str
= build_string (1, "");
4158 c_parser_consume_token (parser
);
4162 c_parser_error (parser
, "expected string literal");
4165 warn_overlength_strings
= save_flag
;
4169 /* Parse a simple asm expression. This is used in restricted
4170 contexts, where a full expression with inputs and outputs does not
4171 make sense. This is a GNU extension.
4174 asm ( asm-string-literal )
4178 c_parser_simple_asm_expr (c_parser
*parser
)
4181 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4182 /* ??? Follow the C++ parser rather than using the
4183 lex_untranslated_string kludge. */
4184 parser
->lex_untranslated_string
= true;
4185 c_parser_consume_token (parser
);
4186 matching_parens parens
;
4187 if (!parens
.require_open (parser
))
4189 parser
->lex_untranslated_string
= false;
4192 str
= c_parser_asm_string_literal (parser
);
4193 parser
->lex_untranslated_string
= false;
4194 if (!parens
.require_close (parser
))
4196 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4203 c_parser_attribute_any_word (c_parser
*parser
)
4205 tree attr_name
= NULL_TREE
;
4207 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
4209 /* ??? See comment above about what keywords are accepted here. */
4211 switch (c_parser_peek_token (parser
)->keyword
)
4242 case RID_TRANSACTION_ATOMIC
:
4243 case RID_TRANSACTION_CANCEL
:
4259 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
4260 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
4262 else if (c_parser_next_token_is (parser
, CPP_NAME
))
4263 attr_name
= c_parser_peek_token (parser
)->value
;
4268 /* Parse (possibly empty) attributes. This is a GNU extension.
4272 attributes attribute
4275 __attribute__ ( ( attribute-list ) )
4279 attribute_list , attrib
4284 any-word ( identifier )
4285 any-word ( identifier , nonempty-expr-list )
4286 any-word ( expr-list )
4288 where the "identifier" must not be declared as a type, and
4289 "any-word" may be any identifier (including one declared as a
4290 type), a reserved word storage class specifier, type specifier or
4291 type qualifier. ??? This still leaves out most reserved keywords
4292 (following the old parser), shouldn't we include them, and why not
4293 allow identifiers declared as types to start the arguments? */
4296 c_parser_attributes (c_parser
*parser
)
4298 tree attrs
= NULL_TREE
;
4299 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4301 /* ??? Follow the C++ parser rather than using the
4302 lex_untranslated_string kludge. */
4303 parser
->lex_untranslated_string
= true;
4304 /* Consume the `__attribute__' keyword. */
4305 c_parser_consume_token (parser
);
4306 /* Look for the two `(' tokens. */
4307 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4309 parser
->lex_untranslated_string
= false;
4312 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4314 parser
->lex_untranslated_string
= false;
4315 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4318 /* Parse the attribute list. */
4319 while (c_parser_next_token_is (parser
, CPP_COMMA
)
4320 || c_parser_next_token_is (parser
, CPP_NAME
)
4321 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
4323 tree attr
, attr_name
, attr_args
;
4324 vec
<tree
, va_gc
> *expr_list
;
4325 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4327 c_parser_consume_token (parser
);
4331 attr_name
= c_parser_attribute_any_word (parser
);
4332 if (attr_name
== NULL
)
4334 attr_name
= canonicalize_attr_name (attr_name
);
4335 c_parser_consume_token (parser
);
4336 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
4338 attr
= build_tree_list (attr_name
, NULL_TREE
);
4339 /* Add this attribute to the list. */
4340 attrs
= chainon (attrs
, attr
);
4341 /* If the next token isn't a comma, we're done. */
4342 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4346 c_parser_consume_token (parser
);
4347 /* Parse the attribute contents. If they start with an
4348 identifier which is followed by a comma or close
4349 parenthesis, then the arguments start with that
4350 identifier; otherwise they are an expression list.
4351 In objective-c the identifier may be a classname. */
4352 if (c_parser_next_token_is (parser
, CPP_NAME
)
4353 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4354 || (c_dialect_objc ()
4355 && c_parser_peek_token (parser
)->id_kind
4357 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4358 || (c_parser_peek_2nd_token (parser
)->type
4359 == CPP_CLOSE_PAREN
))
4360 && (attribute_takes_identifier_p (attr_name
)
4361 || (c_dialect_objc ()
4362 && c_parser_peek_token (parser
)->id_kind
4363 == C_ID_CLASSNAME
)))
4365 tree arg1
= c_parser_peek_token (parser
)->value
;
4366 c_parser_consume_token (parser
);
4367 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4368 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4372 c_parser_consume_token (parser
);
4373 expr_list
= c_parser_expr_list (parser
, false, true,
4374 NULL
, NULL
, NULL
, NULL
);
4375 tree_list
= build_tree_list_vec (expr_list
);
4376 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4377 release_tree_vector (expr_list
);
4382 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4383 attr_args
= NULL_TREE
;
4386 expr_list
= c_parser_expr_list (parser
, false, true,
4387 NULL
, NULL
, NULL
, NULL
);
4388 attr_args
= build_tree_list_vec (expr_list
);
4389 release_tree_vector (expr_list
);
4393 attr
= build_tree_list (attr_name
, attr_args
);
4394 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4395 c_parser_consume_token (parser
);
4398 parser
->lex_untranslated_string
= false;
4399 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4403 /* Add this attribute to the list. */
4404 attrs
= chainon (attrs
, attr
);
4405 /* If the next token isn't a comma, we're done. */
4406 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4409 /* Look for the two `)' tokens. */
4410 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4411 c_parser_consume_token (parser
);
4414 parser
->lex_untranslated_string
= false;
4415 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4419 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4420 c_parser_consume_token (parser
);
4423 parser
->lex_untranslated_string
= false;
4424 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4428 parser
->lex_untranslated_string
= false;
4434 /* Parse a type name (C90 6.5.5, C99 6.7.6, C11 6.7.7). ALIGNAS_OK
4435 says whether alignment specifiers are OK (only in cases that might
4436 be the type name of a compound literal).
4439 specifier-qualifier-list abstract-declarator[opt]
4442 struct c_type_name
*
4443 c_parser_type_name (c_parser
*parser
, bool alignas_ok
)
4445 struct c_declspecs
*specs
= build_null_declspecs ();
4446 struct c_declarator
*declarator
;
4447 struct c_type_name
*ret
;
4449 c_parser_declspecs (parser
, specs
, false, true, true, alignas_ok
, false,
4451 if (!specs
->declspecs_seen_p
)
4453 c_parser_error (parser
, "expected specifier-qualifier-list");
4456 if (specs
->type
!= error_mark_node
)
4458 pending_xref_error ();
4459 finish_declspecs (specs
);
4461 declarator
= c_parser_declarator (parser
,
4462 specs
->typespec_kind
!= ctsk_none
,
4463 C_DTR_ABSTRACT
, &dummy
);
4464 if (declarator
== NULL
)
4466 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4468 ret
->declarator
= declarator
;
4472 /* Parse an initializer (C90 6.5.7, C99 6.7.8, C11 6.7.9).
4475 assignment-expression
4476 { initializer-list }
4477 { initializer-list , }
4480 designation[opt] initializer
4481 initializer-list , designation[opt] initializer
4488 designator-list designator
4495 [ constant-expression ]
4507 [ constant-expression ... constant-expression ]
4509 Any expression without commas is accepted in the syntax for the
4510 constant-expressions, with non-constant expressions rejected later.
4512 This function is only used for top-level initializers; for nested
4513 ones, see c_parser_initval. */
4515 static struct c_expr
4516 c_parser_initializer (c_parser
*parser
)
4518 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4519 return c_parser_braced_init (parser
, NULL_TREE
, false, NULL
);
4523 location_t loc
= c_parser_peek_token (parser
)->location
;
4524 ret
= c_parser_expr_no_commas (parser
, NULL
);
4525 if (TREE_CODE (ret
.value
) != STRING_CST
4526 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4527 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4532 /* The location of the last comma within the current initializer list,
4533 or UNKNOWN_LOCATION if not within one. */
4535 location_t last_init_list_comma
;
4537 /* Parse a braced initializer list. TYPE is the type specified for a
4538 compound literal, and NULL_TREE for other initializers and for
4539 nested braced lists. NESTED_P is true for nested braced lists,
4540 false for the list of a compound literal or the list that is the
4541 top-level initializer in a declaration. */
4543 static struct c_expr
4544 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
,
4545 struct obstack
*outer_obstack
)
4548 struct obstack braced_init_obstack
;
4549 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4550 gcc_obstack_init (&braced_init_obstack
);
4551 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4552 matching_braces braces
;
4553 braces
.consume_open (parser
);
4556 finish_implicit_inits (brace_loc
, outer_obstack
);
4557 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4560 really_start_incremental_init (type
);
4561 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4563 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4567 /* Parse a non-empty initializer list, possibly with a trailing
4571 c_parser_initelt (parser
, &braced_init_obstack
);
4574 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4576 last_init_list_comma
= c_parser_peek_token (parser
)->location
;
4577 c_parser_consume_token (parser
);
4581 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4585 c_token
*next_tok
= c_parser_peek_token (parser
);
4586 if (next_tok
->type
!= CPP_CLOSE_BRACE
)
4589 ret
.original_code
= ERROR_MARK
;
4590 ret
.original_type
= NULL
;
4591 braces
.skip_until_found_close (parser
);
4592 pop_init_level (brace_loc
, 0, &braced_init_obstack
, last_init_list_comma
);
4593 obstack_free (&braced_init_obstack
, NULL
);
4596 location_t close_loc
= next_tok
->location
;
4597 c_parser_consume_token (parser
);
4598 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
, close_loc
);
4599 obstack_free (&braced_init_obstack
, NULL
);
4600 set_c_expr_source_range (&ret
, brace_loc
, close_loc
);
4604 /* Parse a nested initializer, including designators. */
4607 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4609 /* Parse any designator or designator list. A single array
4610 designator may have the subsequent "=" omitted in GNU C, but a
4611 longer list or a structure member designator may not. */
4612 if (c_parser_next_token_is (parser
, CPP_NAME
)
4613 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4615 /* Old-style structure member designator. */
4616 set_init_label (c_parser_peek_token (parser
)->location
,
4617 c_parser_peek_token (parser
)->value
,
4618 c_parser_peek_token (parser
)->location
,
4619 braced_init_obstack
);
4620 /* Use the colon as the error location. */
4621 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4622 "obsolete use of designated initializer with %<:%>");
4623 c_parser_consume_token (parser
);
4624 c_parser_consume_token (parser
);
4628 /* des_seen is 0 if there have been no designators, 1 if there
4629 has been a single array designator and 2 otherwise. */
4631 /* Location of a designator. */
4632 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4633 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4634 || c_parser_next_token_is (parser
, CPP_DOT
))
4636 int des_prev
= des_seen
;
4638 des_loc
= c_parser_peek_token (parser
)->location
;
4641 if (c_parser_next_token_is (parser
, CPP_DOT
))
4644 c_parser_consume_token (parser
);
4645 if (c_parser_next_token_is (parser
, CPP_NAME
))
4647 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4648 c_parser_peek_token (parser
)->location
,
4649 braced_init_obstack
);
4650 c_parser_consume_token (parser
);
4656 init
.original_code
= ERROR_MARK
;
4657 init
.original_type
= NULL
;
4658 c_parser_error (parser
, "expected identifier");
4659 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4660 process_init_element (input_location
, init
, false,
4661 braced_init_obstack
);
4668 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4669 location_t array_index_loc
= UNKNOWN_LOCATION
;
4670 /* ??? Following the old parser, [ objc-receiver
4671 objc-message-args ] is accepted as an initializer,
4672 being distinguished from a designator by what follows
4673 the first assignment expression inside the square
4674 brackets, but after a first array designator a
4675 subsequent square bracket is for Objective-C taken to
4676 start an expression, using the obsolete form of
4677 designated initializer without '=', rather than
4678 possibly being a second level of designation: in LALR
4679 terms, the '[' is shifted rather than reducing
4680 designator to designator-list. */
4681 if (des_prev
== 1 && c_dialect_objc ())
4683 des_seen
= des_prev
;
4686 if (des_prev
== 0 && c_dialect_objc ())
4688 /* This might be an array designator or an
4689 Objective-C message expression. If the former,
4690 continue parsing here; if the latter, parse the
4691 remainder of the initializer given the starting
4692 primary-expression. ??? It might make sense to
4693 distinguish when des_prev == 1 as well; see
4694 previous comment. */
4696 struct c_expr mexpr
;
4697 c_parser_consume_token (parser
);
4698 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4699 && ((c_parser_peek_token (parser
)->id_kind
4701 || (c_parser_peek_token (parser
)->id_kind
4702 == C_ID_CLASSNAME
)))
4704 /* Type name receiver. */
4705 tree id
= c_parser_peek_token (parser
)->value
;
4706 c_parser_consume_token (parser
);
4707 rec
= objc_get_class_reference (id
);
4708 goto parse_message_args
;
4710 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4711 mark_exp_read (first
);
4712 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4713 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4714 goto array_desig_after_first
;
4715 /* Expression receiver. So far only one part
4716 without commas has been parsed; there might be
4717 more of the expression. */
4719 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4722 location_t comma_loc
, exp_loc
;
4723 comma_loc
= c_parser_peek_token (parser
)->location
;
4724 c_parser_consume_token (parser
);
4725 exp_loc
= c_parser_peek_token (parser
)->location
;
4726 next
= c_parser_expr_no_commas (parser
, NULL
);
4727 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4729 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4732 /* Now parse the objc-message-args. */
4733 args
= c_parser_objc_message_args (parser
);
4734 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4737 = objc_build_message_expr (rec
, args
);
4738 mexpr
.original_code
= ERROR_MARK
;
4739 mexpr
.original_type
= NULL
;
4740 /* Now parse and process the remainder of the
4741 initializer, starting with this message
4742 expression as a primary-expression. */
4743 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4746 c_parser_consume_token (parser
);
4747 array_index_loc
= c_parser_peek_token (parser
)->location
;
4748 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4749 mark_exp_read (first
);
4750 array_desig_after_first
:
4751 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4753 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4754 c_parser_consume_token (parser
);
4755 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4756 mark_exp_read (second
);
4760 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4762 c_parser_consume_token (parser
);
4763 set_init_index (array_index_loc
, first
, second
,
4764 braced_init_obstack
);
4766 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4767 "ISO C forbids specifying range of elements to initialize");
4770 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4776 if (c_parser_next_token_is (parser
, CPP_EQ
))
4778 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4779 "ISO C90 forbids specifying subobject "
4781 c_parser_consume_token (parser
);
4786 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4787 "obsolete use of designated initializer without %<=%>");
4792 init
.original_code
= ERROR_MARK
;
4793 init
.original_type
= NULL
;
4794 c_parser_error (parser
, "expected %<=%>");
4795 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4796 process_init_element (input_location
, init
, false,
4797 braced_init_obstack
);
4803 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4806 /* Parse a nested initializer; as c_parser_initializer but parses
4807 initializers within braced lists, after any designators have been
4808 applied. If AFTER is not NULL then it is an Objective-C message
4809 expression which is the primary-expression starting the
4813 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4814 struct obstack
* braced_init_obstack
)
4817 gcc_assert (!after
|| c_dialect_objc ());
4818 location_t loc
= c_parser_peek_token (parser
)->location
;
4820 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4821 init
= c_parser_braced_init (parser
, NULL_TREE
, true,
4822 braced_init_obstack
);
4825 init
= c_parser_expr_no_commas (parser
, after
);
4826 if (init
.value
!= NULL_TREE
4827 && TREE_CODE (init
.value
) != STRING_CST
4828 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4829 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4831 process_init_element (loc
, init
, false, braced_init_obstack
);
4834 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4835 C99 6.8.2, C11 6.8.2).
4838 { block-item-list[opt] }
4839 { label-declarations block-item-list }
4843 block-item-list block-item
4855 { label-declarations block-item-list }
4858 __extension__ nested-declaration
4859 nested-function-definition
4863 label-declarations label-declaration
4866 __label__ identifier-list ;
4868 Allowing the mixing of declarations and code is new in C99. The
4869 GNU syntax also permits (not shown above) labels at the end of
4870 compound statements, which yield an error. We don't allow labels
4871 on declarations; this might seem like a natural extension, but
4872 there would be a conflict between attributes on the label and
4873 prefix attributes on the declaration. ??? The syntax follows the
4874 old parser in requiring something after label declarations.
4875 Although they are erroneous if the labels declared aren't defined,
4876 is it useful for the syntax to be this way?
4897 cancellation-point-directive */
4900 c_parser_compound_statement (c_parser
*parser
)
4903 location_t brace_loc
;
4904 brace_loc
= c_parser_peek_token (parser
)->location
;
4905 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4907 /* Ensure a scope is entered and left anyway to avoid confusion
4908 if we have just prepared to enter a function body. */
4909 stmt
= c_begin_compound_stmt (true);
4910 c_end_compound_stmt (brace_loc
, stmt
, true);
4911 return error_mark_node
;
4913 stmt
= c_begin_compound_stmt (true);
4914 c_parser_compound_statement_nostart (parser
);
4916 return c_end_compound_stmt (brace_loc
, stmt
, true);
4919 /* Parse a compound statement except for the opening brace. This is
4920 used for parsing both compound statements and statement expressions
4921 (which follow different paths to handling the opening). */
4924 c_parser_compound_statement_nostart (c_parser
*parser
)
4926 bool last_stmt
= false;
4927 bool last_label
= false;
4928 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4929 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4930 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4932 add_debug_begin_stmt (c_parser_peek_token (parser
)->location
);
4933 c_parser_consume_token (parser
);
4936 mark_valid_location_for_stdc_pragma (true);
4937 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4939 /* Read zero or more forward-declarations for labels that nested
4940 functions can jump to. */
4941 mark_valid_location_for_stdc_pragma (false);
4942 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4944 label_loc
= c_parser_peek_token (parser
)->location
;
4945 c_parser_consume_token (parser
);
4946 /* Any identifiers, including those declared as type names,
4951 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4953 c_parser_error (parser
, "expected identifier");
4957 = declare_label (c_parser_peek_token (parser
)->value
);
4958 C_DECLARED_LABEL_FLAG (label
) = 1;
4959 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4960 c_parser_consume_token (parser
);
4961 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4962 c_parser_consume_token (parser
);
4966 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4968 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4970 /* We must now have at least one statement, label or declaration. */
4971 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4973 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4974 c_parser_error (parser
, "expected declaration or statement");
4975 c_parser_consume_token (parser
);
4978 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4980 location_t loc
= c_parser_peek_token (parser
)->location
;
4981 loc
= expansion_point_location_if_in_system_header (loc
);
4982 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4983 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4984 || (c_parser_next_token_is (parser
, CPP_NAME
)
4985 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4987 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4988 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4990 label_loc
= c_parser_peek_token (parser
)->location
;
4993 mark_valid_location_for_stdc_pragma (false);
4994 c_parser_label (parser
);
4996 else if (!last_label
4997 && c_parser_next_tokens_start_declaration (parser
))
5000 mark_valid_location_for_stdc_pragma (false);
5001 bool fallthru_attr_p
= false;
5002 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5003 true, NULL
, vNULL
, NULL
,
5005 if (last_stmt
&& !fallthru_attr_p
)
5006 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
5007 "ISO C90 forbids mixed declarations and code");
5008 last_stmt
= fallthru_attr_p
;
5010 else if (!last_label
5011 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5013 /* __extension__ can start a declaration, but is also an
5014 unary operator that can start an expression. Consume all
5015 but the last of a possible series of __extension__ to
5017 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5018 && (c_parser_peek_2nd_token (parser
)->keyword
5020 c_parser_consume_token (parser
);
5021 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5024 ext
= disable_extension_diagnostics ();
5025 c_parser_consume_token (parser
);
5027 mark_valid_location_for_stdc_pragma (false);
5028 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5030 /* Following the old parser, __extension__ does not
5031 disable this diagnostic. */
5032 restore_extension_diagnostics (ext
);
5034 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
5035 "ISO C90 forbids mixed declarations and code");
5041 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
5043 /* External pragmas, and some omp pragmas, are not associated
5044 with regular c code, and so are not to be considered statements
5045 syntactically. This ensures that the user doesn't put them
5046 places that would turn into syntax errors if the directive
5048 if (c_parser_pragma (parser
,
5049 last_label
? pragma_stmt
: pragma_compound
,
5051 last_label
= false, last_stmt
= true;
5053 else if (c_parser_next_token_is (parser
, CPP_EOF
))
5055 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5056 c_parser_error (parser
, "expected declaration or statement");
5059 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5061 if (parser
->in_if_block
)
5063 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5064 error_at (loc
, "expected %<}%> before %<else%>");
5069 error_at (loc
, "%<else%> without a previous %<if%>");
5070 c_parser_consume_token (parser
);
5079 mark_valid_location_for_stdc_pragma (false);
5080 c_parser_statement_after_labels (parser
, NULL
);
5083 parser
->error
= false;
5086 error_at (label_loc
, "label at end of compound statement");
5087 c_parser_consume_token (parser
);
5088 /* Restore the value we started with. */
5089 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5092 /* Parse all consecutive labels. */
5095 c_parser_all_labels (c_parser
*parser
)
5097 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5098 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5099 || (c_parser_next_token_is (parser
, CPP_NAME
)
5100 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5101 c_parser_label (parser
);
5104 /* Parse a label (C90 6.6.1, C99 6.8.1, C11 6.8.1).
5107 identifier : attributes[opt]
5108 case constant-expression :
5114 case constant-expression ... constant-expression :
5116 The use of attributes on labels is a GNU extension. The syntax in
5117 GNU C accepts any expressions without commas, non-constant
5118 expressions being rejected later. */
5121 c_parser_label (c_parser
*parser
)
5123 location_t loc1
= c_parser_peek_token (parser
)->location
;
5124 tree label
= NULL_TREE
;
5126 /* Remember whether this case or a user-defined label is allowed to fall
5128 bool fallthrough_p
= c_parser_peek_token (parser
)->flags
& PREV_FALLTHROUGH
;
5130 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
5133 c_parser_consume_token (parser
);
5134 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
5135 if (c_parser_next_token_is (parser
, CPP_COLON
))
5137 c_parser_consume_token (parser
);
5138 label
= do_case (loc1
, exp1
, NULL_TREE
);
5140 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
5142 c_parser_consume_token (parser
);
5143 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
5144 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5145 label
= do_case (loc1
, exp1
, exp2
);
5148 c_parser_error (parser
, "expected %<:%> or %<...%>");
5150 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
5152 c_parser_consume_token (parser
);
5153 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5154 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
5158 tree name
= c_parser_peek_token (parser
)->value
;
5161 location_t loc2
= c_parser_peek_token (parser
)->location
;
5162 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
5163 c_parser_consume_token (parser
);
5164 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
5165 c_parser_consume_token (parser
);
5166 attrs
= c_parser_attributes (parser
);
5167 tlab
= define_label (loc2
, name
);
5170 decl_attributes (&tlab
, attrs
, 0);
5171 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
5176 if (TREE_CODE (label
) == LABEL_EXPR
)
5177 FALLTHROUGH_LABEL_P (LABEL_EXPR_LABEL (label
)) = fallthrough_p
;
5179 FALLTHROUGH_LABEL_P (CASE_LABEL (label
)) = fallthrough_p
;
5181 /* Allow '__attribute__((fallthrough));'. */
5182 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
5184 location_t loc
= c_parser_peek_token (parser
)->location
;
5185 tree attrs
= c_parser_attributes (parser
);
5186 if (attribute_fallthrough_p (attrs
))
5188 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5190 tree fn
= build_call_expr_internal_loc (loc
,
5196 warning_at (loc
, OPT_Wattributes
, "%<fallthrough%> attribute "
5197 "not followed by %<;%>");
5199 else if (attrs
!= NULL_TREE
)
5200 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5201 " can be applied to a null statement");
5203 if (c_parser_next_tokens_start_declaration (parser
))
5205 error_at (c_parser_peek_token (parser
)->location
,
5206 "a label can only be part of a statement and "
5207 "a declaration is not a statement");
5208 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
5209 /*static_assert_ok*/ true,
5210 /*empty_ok*/ true, /*nested*/ true,
5211 /*start_attr_ok*/ true, NULL
,
5217 /* Parse a statement (C90 6.6, C99 6.8, C11 6.8).
5222 expression-statement
5230 expression-statement:
5233 selection-statement:
5237 iteration-statement:
5246 return expression[opt] ;
5256 expression-statement:
5262 objc-throw-statement
5263 objc-try-catch-statement
5264 objc-synchronized-statement
5266 objc-throw-statement:
5282 parallel-directive structured-block
5285 kernels-directive structured-block
5288 data-directive structured-block
5291 loop-directive structured-block
5305 parallel-for-construct
5306 parallel-for-simd-construct
5307 parallel-sections-construct
5314 parallel-directive structured-block
5317 for-directive iteration-statement
5320 simd-directive iteration-statements
5323 for-simd-directive iteration-statements
5326 sections-directive section-scope
5329 single-directive structured-block
5331 parallel-for-construct:
5332 parallel-for-directive iteration-statement
5334 parallel-for-simd-construct:
5335 parallel-for-simd-directive iteration-statement
5337 parallel-sections-construct:
5338 parallel-sections-directive section-scope
5341 master-directive structured-block
5344 critical-directive structured-block
5347 atomic-directive expression-statement
5350 ordered-directive structured-block
5352 Transactional Memory:
5355 transaction-statement
5356 transaction-cancel-statement
5358 IF_P is used to track whether there's a (possibly labeled) if statement
5359 which is not enclosed in braces and has an else clause. This is used to
5360 implement -Wparentheses. */
5363 c_parser_statement (c_parser
*parser
, bool *if_p
, location_t
*loc_after_labels
)
5365 c_parser_all_labels (parser
);
5366 if (loc_after_labels
)
5367 *loc_after_labels
= c_parser_peek_token (parser
)->location
;
5368 c_parser_statement_after_labels (parser
, if_p
, NULL
);
5371 /* Parse a statement, other than a labeled statement. CHAIN is a vector
5372 of if-else-if conditions.
5374 IF_P is used to track whether there's a (possibly labeled) if statement
5375 which is not enclosed in braces and has an else clause. This is used to
5376 implement -Wparentheses. */
5379 c_parser_statement_after_labels (c_parser
*parser
, bool *if_p
,
5382 location_t loc
= c_parser_peek_token (parser
)->location
;
5383 tree stmt
= NULL_TREE
;
5384 bool in_if_block
= parser
->in_if_block
;
5385 parser
->in_if_block
= false;
5389 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_BRACE
)
5390 add_debug_begin_stmt (loc
);
5392 switch (c_parser_peek_token (parser
)->type
)
5394 case CPP_OPEN_BRACE
:
5395 add_stmt (c_parser_compound_statement (parser
));
5398 switch (c_parser_peek_token (parser
)->keyword
)
5401 c_parser_if_statement (parser
, if_p
, chain
);
5404 c_parser_switch_statement (parser
, if_p
);
5407 c_parser_while_statement (parser
, false, 0, if_p
);
5410 c_parser_do_statement (parser
, 0, false);
5413 c_parser_for_statement (parser
, false, 0, if_p
);
5416 c_parser_consume_token (parser
);
5417 if (c_parser_next_token_is (parser
, CPP_NAME
))
5419 stmt
= c_finish_goto_label (loc
,
5420 c_parser_peek_token (parser
)->value
);
5421 c_parser_consume_token (parser
);
5423 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5427 c_parser_consume_token (parser
);
5428 val
= c_parser_expression (parser
);
5429 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5430 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5433 c_parser_error (parser
, "expected identifier or %<*%>");
5434 goto expect_semicolon
;
5436 c_parser_consume_token (parser
);
5437 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5438 goto expect_semicolon
;
5440 c_parser_consume_token (parser
);
5441 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5442 goto expect_semicolon
;
5444 c_parser_consume_token (parser
);
5445 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5447 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5448 c_parser_consume_token (parser
);
5452 location_t xloc
= c_parser_peek_token (parser
)->location
;
5453 struct c_expr expr
= c_parser_expression_conv (parser
);
5454 mark_exp_read (expr
.value
);
5455 stmt
= c_finish_return (EXPR_LOC_OR_LOC (expr
.value
, xloc
),
5456 expr
.value
, expr
.original_type
);
5457 goto expect_semicolon
;
5461 stmt
= c_parser_asm_statement (parser
);
5463 case RID_TRANSACTION_ATOMIC
:
5464 case RID_TRANSACTION_RELAXED
:
5465 stmt
= c_parser_transaction (parser
,
5466 c_parser_peek_token (parser
)->keyword
);
5468 case RID_TRANSACTION_CANCEL
:
5469 stmt
= c_parser_transaction_cancel (parser
);
5470 goto expect_semicolon
;
5472 gcc_assert (c_dialect_objc ());
5473 c_parser_consume_token (parser
);
5474 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5476 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5477 c_parser_consume_token (parser
);
5481 struct c_expr expr
= c_parser_expression (parser
);
5482 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5483 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5484 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5485 goto expect_semicolon
;
5489 gcc_assert (c_dialect_objc ());
5490 c_parser_objc_try_catch_finally_statement (parser
);
5492 case RID_AT_SYNCHRONIZED
:
5493 gcc_assert (c_dialect_objc ());
5494 c_parser_objc_synchronized_statement (parser
);
5498 /* Allow '__attribute__((fallthrough));'. */
5499 tree attrs
= c_parser_attributes (parser
);
5500 if (attribute_fallthrough_p (attrs
))
5502 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5504 tree fn
= build_call_expr_internal_loc (loc
,
5509 c_parser_consume_token (parser
);
5512 warning_at (loc
, OPT_Wattributes
,
5513 "%<fallthrough%> attribute not followed "
5516 else if (attrs
!= NULL_TREE
)
5517 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5518 " can be applied to a null statement");
5526 c_parser_consume_token (parser
);
5528 case CPP_CLOSE_PAREN
:
5529 case CPP_CLOSE_SQUARE
:
5530 /* Avoid infinite loop in error recovery:
5531 c_parser_skip_until_found stops at a closing nesting
5532 delimiter without consuming it, but here we need to consume
5533 it to proceed further. */
5534 c_parser_error (parser
, "expected statement");
5535 c_parser_consume_token (parser
);
5538 c_parser_pragma (parser
, pragma_stmt
, if_p
);
5542 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5544 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5547 /* Two cases cannot and do not have line numbers associated: If stmt
5548 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5549 cannot hold line numbers. But that's OK because the statement
5550 will either be changed to a MODIFY_EXPR during gimplification of
5551 the statement expr, or discarded. If stmt was compound, but
5552 without new variables, we will have skipped the creation of a
5553 BIND and will have a bare STATEMENT_LIST. But that's OK because
5554 (recursively) all of the component statements should already have
5555 line numbers assigned. ??? Can we discard no-op statements
5557 if (EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5558 protected_set_expr_location (stmt
, loc
);
5560 parser
->in_if_block
= in_if_block
;
5563 /* Parse the condition from an if, do, while or for statements. */
5566 c_parser_condition (c_parser
*parser
)
5568 location_t loc
= c_parser_peek_token (parser
)->location
;
5570 cond
= c_parser_expression_conv (parser
).value
;
5571 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5572 cond
= c_fully_fold (cond
, false, NULL
);
5573 if (warn_sequence_point
)
5574 verify_sequence_points (cond
);
5578 /* Parse a parenthesized condition from an if, do or while statement.
5584 c_parser_paren_condition (c_parser
*parser
)
5587 matching_parens parens
;
5588 if (!parens
.require_open (parser
))
5589 return error_mark_node
;
5590 cond
= c_parser_condition (parser
);
5591 parens
.skip_until_found_close (parser
);
5595 /* Parse a statement which is a block in C99.
5597 IF_P is used to track whether there's a (possibly labeled) if statement
5598 which is not enclosed in braces and has an else clause. This is used to
5599 implement -Wparentheses. */
5602 c_parser_c99_block_statement (c_parser
*parser
, bool *if_p
,
5603 location_t
*loc_after_labels
)
5605 tree block
= c_begin_compound_stmt (flag_isoc99
);
5606 location_t loc
= c_parser_peek_token (parser
)->location
;
5607 c_parser_statement (parser
, if_p
, loc_after_labels
);
5608 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5611 /* Parse the body of an if statement. This is just parsing a
5612 statement but (a) it is a block in C99, (b) we track whether the
5613 body is an if statement for the sake of -Wparentheses warnings, (c)
5614 we handle an empty body specially for the sake of -Wempty-body
5615 warnings, and (d) we call parser_compound_statement directly
5616 because c_parser_statement_after_labels resets
5617 parser->in_if_block.
5619 IF_P is used to track whether there's a (possibly labeled) if statement
5620 which is not enclosed in braces and has an else clause. This is used to
5621 implement -Wparentheses. */
5624 c_parser_if_body (c_parser
*parser
, bool *if_p
,
5625 const token_indent_info
&if_tinfo
)
5627 tree block
= c_begin_compound_stmt (flag_isoc99
);
5628 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5629 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
5630 token_indent_info body_tinfo
5631 = get_token_indent_info (c_parser_peek_token (parser
));
5633 c_parser_all_labels (parser
);
5634 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5636 location_t loc
= c_parser_peek_token (parser
)->location
;
5637 add_stmt (build_empty_stmt (loc
));
5638 c_parser_consume_token (parser
);
5639 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5640 warning_at (loc
, OPT_Wempty_body
,
5641 "suggest braces around empty body in an %<if%> statement");
5643 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5644 add_stmt (c_parser_compound_statement (parser
));
5647 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5648 c_parser_statement_after_labels (parser
, if_p
);
5651 token_indent_info next_tinfo
5652 = get_token_indent_info (c_parser_peek_token (parser
));
5653 warn_for_misleading_indentation (if_tinfo
, body_tinfo
, next_tinfo
);
5654 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5655 && next_tinfo
.type
!= CPP_SEMICOLON
)
5656 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5657 if_tinfo
.location
, RID_IF
);
5659 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5662 /* Parse the else body of an if statement. This is just parsing a
5663 statement but (a) it is a block in C99, (b) we handle an empty body
5664 specially for the sake of -Wempty-body warnings. CHAIN is a vector
5665 of if-else-if conditions. */
5668 c_parser_else_body (c_parser
*parser
, const token_indent_info
&else_tinfo
,
5671 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5672 tree block
= c_begin_compound_stmt (flag_isoc99
);
5673 token_indent_info body_tinfo
5674 = get_token_indent_info (c_parser_peek_token (parser
));
5675 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
5677 c_parser_all_labels (parser
);
5678 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5680 location_t loc
= c_parser_peek_token (parser
)->location
;
5683 "suggest braces around empty body in an %<else%> statement");
5684 add_stmt (build_empty_stmt (loc
));
5685 c_parser_consume_token (parser
);
5689 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5690 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5691 c_parser_statement_after_labels (parser
, NULL
, chain
);
5694 token_indent_info next_tinfo
5695 = get_token_indent_info (c_parser_peek_token (parser
));
5696 warn_for_misleading_indentation (else_tinfo
, body_tinfo
, next_tinfo
);
5697 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5698 && next_tinfo
.type
!= CPP_SEMICOLON
)
5699 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5700 else_tinfo
.location
, RID_ELSE
);
5702 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5705 /* We might need to reclassify any previously-lexed identifier, e.g.
5706 when we've left a for loop with an if-statement without else in the
5707 body - we might have used a wrong scope for the token. See PR67784. */
5710 c_parser_maybe_reclassify_token (c_parser
*parser
)
5712 if (c_parser_next_token_is (parser
, CPP_NAME
))
5714 c_token
*token
= c_parser_peek_token (parser
);
5716 if (token
->id_kind
!= C_ID_CLASSNAME
)
5718 tree decl
= lookup_name (token
->value
);
5720 token
->id_kind
= C_ID_ID
;
5723 if (TREE_CODE (decl
) == TYPE_DECL
)
5724 token
->id_kind
= C_ID_TYPENAME
;
5726 else if (c_dialect_objc ())
5728 tree objc_interface_decl
= objc_is_class_name (token
->value
);
5729 /* Objective-C class names are in the same namespace as
5730 variables and typedefs, and hence are shadowed by local
5732 if (objc_interface_decl
)
5734 token
->value
= objc_interface_decl
;
5735 token
->id_kind
= C_ID_CLASSNAME
;
5742 /* Parse an if statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5745 if ( expression ) statement
5746 if ( expression ) statement else statement
5748 CHAIN is a vector of if-else-if conditions.
5749 IF_P is used to track whether there's a (possibly labeled) if statement
5750 which is not enclosed in braces and has an else clause. This is used to
5751 implement -Wparentheses. */
5754 c_parser_if_statement (c_parser
*parser
, bool *if_p
, vec
<tree
> *chain
)
5759 bool nested_if
= false;
5760 tree first_body
, second_body
;
5763 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5764 token_indent_info if_tinfo
5765 = get_token_indent_info (c_parser_peek_token (parser
));
5766 c_parser_consume_token (parser
);
5767 block
= c_begin_compound_stmt (flag_isoc99
);
5768 loc
= c_parser_peek_token (parser
)->location
;
5769 cond
= c_parser_paren_condition (parser
);
5770 in_if_block
= parser
->in_if_block
;
5771 parser
->in_if_block
= true;
5772 first_body
= c_parser_if_body (parser
, &nested_if
, if_tinfo
);
5773 parser
->in_if_block
= in_if_block
;
5775 if (warn_duplicated_cond
)
5776 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond
), cond
, &chain
);
5778 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5780 token_indent_info else_tinfo
5781 = get_token_indent_info (c_parser_peek_token (parser
));
5782 c_parser_consume_token (parser
);
5783 if (warn_duplicated_cond
)
5785 if (c_parser_next_token_is_keyword (parser
, RID_IF
)
5788 /* We've got "if (COND) else if (COND2)". Start the
5789 condition chain and add COND as the first element. */
5790 chain
= new vec
<tree
> ();
5791 if (!CONSTANT_CLASS_P (cond
) && !TREE_SIDE_EFFECTS (cond
))
5792 chain
->safe_push (cond
);
5794 else if (!c_parser_next_token_is_keyword (parser
, RID_IF
))
5796 /* This is if-else without subsequent if. Zap the condition
5797 chain; we would have already warned at this point. */
5802 second_body
= c_parser_else_body (parser
, else_tinfo
, chain
);
5803 /* Set IF_P to true to indicate that this if statement has an
5804 else clause. This may trigger the Wparentheses warning
5805 below when we get back up to the parent if statement. */
5811 second_body
= NULL_TREE
;
5813 /* Diagnose an ambiguous else if if-then-else is nested inside
5816 warning_at (loc
, OPT_Wdangling_else
,
5817 "suggest explicit braces to avoid ambiguous %<else%>");
5819 if (warn_duplicated_cond
)
5821 /* This if statement does not have an else clause. We don't
5822 need the condition chain anymore. */
5827 c_finish_if_stmt (loc
, cond
, first_body
, second_body
);
5828 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5830 c_parser_maybe_reclassify_token (parser
);
5833 /* Parse a switch statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5836 switch (expression) statement
5840 c_parser_switch_statement (c_parser
*parser
, bool *if_p
)
5843 tree block
, expr
, body
, save_break
;
5844 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5845 location_t switch_cond_loc
;
5846 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5847 c_parser_consume_token (parser
);
5848 block
= c_begin_compound_stmt (flag_isoc99
);
5849 bool explicit_cast_p
= false;
5850 matching_parens parens
;
5851 if (parens
.require_open (parser
))
5853 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5854 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5855 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5856 explicit_cast_p
= true;
5857 ce
= c_parser_expression (parser
);
5858 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5860 /* ??? expr has no valid location? */
5861 parens
.skip_until_found_close (parser
);
5865 switch_cond_loc
= UNKNOWN_LOCATION
;
5866 expr
= error_mark_node
;
5867 ce
.original_type
= error_mark_node
;
5869 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5870 save_break
= c_break_label
;
5871 c_break_label
= NULL_TREE
;
5872 location_t loc_after_labels
;
5873 bool open_brace_p
= c_parser_peek_token (parser
)->type
== CPP_OPEN_BRACE
;
5874 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
5875 location_t next_loc
= c_parser_peek_token (parser
)->location
;
5876 if (!open_brace_p
&& c_parser_peek_token (parser
)->type
!= CPP_SEMICOLON
)
5877 warn_for_multistatement_macros (loc_after_labels
, next_loc
, switch_loc
,
5881 location_t here
= c_parser_peek_token (parser
)->location
;
5882 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5883 SET_EXPR_LOCATION (t
, here
);
5884 SWITCH_BREAK_LABEL_P (c_break_label
) = 1;
5885 append_to_statement_list_force (t
, &body
);
5887 c_finish_case (body
, ce
.original_type
);
5888 c_break_label
= save_break
;
5889 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5890 c_parser_maybe_reclassify_token (parser
);
5893 /* Parse a while statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5896 while (expression) statement
5898 IF_P is used to track whether there's a (possibly labeled) if statement
5899 which is not enclosed in braces and has an else clause. This is used to
5900 implement -Wparentheses. */
5903 c_parser_while_statement (c_parser
*parser
, bool ivdep
, unsigned short unroll
,
5906 tree block
, cond
, body
, save_break
, save_cont
;
5908 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5909 token_indent_info while_tinfo
5910 = get_token_indent_info (c_parser_peek_token (parser
));
5911 c_parser_consume_token (parser
);
5912 block
= c_begin_compound_stmt (flag_isoc99
);
5913 loc
= c_parser_peek_token (parser
)->location
;
5914 cond
= c_parser_paren_condition (parser
);
5915 if (ivdep
&& cond
!= error_mark_node
)
5916 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5917 build_int_cst (integer_type_node
,
5918 annot_expr_ivdep_kind
),
5920 if (unroll
&& cond
!= error_mark_node
)
5921 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5922 build_int_cst (integer_type_node
,
5923 annot_expr_unroll_kind
),
5924 build_int_cst (integer_type_node
, unroll
));
5925 save_break
= c_break_label
;
5926 c_break_label
= NULL_TREE
;
5927 save_cont
= c_cont_label
;
5928 c_cont_label
= NULL_TREE
;
5930 token_indent_info body_tinfo
5931 = get_token_indent_info (c_parser_peek_token (parser
));
5933 location_t loc_after_labels
;
5934 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
5935 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
5936 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5937 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5938 c_parser_maybe_reclassify_token (parser
);
5940 token_indent_info next_tinfo
5941 = get_token_indent_info (c_parser_peek_token (parser
));
5942 warn_for_misleading_indentation (while_tinfo
, body_tinfo
, next_tinfo
);
5944 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
5945 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
5946 while_tinfo
.location
, RID_WHILE
);
5948 c_break_label
= save_break
;
5949 c_cont_label
= save_cont
;
5952 /* Parse a do statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5955 do statement while ( expression ) ;
5959 c_parser_do_statement (c_parser
*parser
, bool ivdep
, unsigned short unroll
)
5961 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5963 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5964 c_parser_consume_token (parser
);
5965 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5966 warning_at (c_parser_peek_token (parser
)->location
,
5968 "suggest braces around empty body in %<do%> statement");
5969 block
= c_begin_compound_stmt (flag_isoc99
);
5970 loc
= c_parser_peek_token (parser
)->location
;
5971 save_break
= c_break_label
;
5972 c_break_label
= NULL_TREE
;
5973 save_cont
= c_cont_label
;
5974 c_cont_label
= NULL_TREE
;
5975 body
= c_parser_c99_block_statement (parser
, NULL
);
5976 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5977 new_break
= c_break_label
;
5978 c_break_label
= save_break
;
5979 new_cont
= c_cont_label
;
5980 c_cont_label
= save_cont
;
5981 cond
= c_parser_paren_condition (parser
);
5982 if (ivdep
&& cond
!= error_mark_node
)
5983 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5984 build_int_cst (integer_type_node
,
5985 annot_expr_ivdep_kind
),
5987 if (unroll
&& cond
!= error_mark_node
)
5988 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5989 build_int_cst (integer_type_node
,
5990 annot_expr_unroll_kind
),
5991 build_int_cst (integer_type_node
, unroll
));
5992 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5993 c_parser_skip_to_end_of_block_or_statement (parser
);
5994 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5995 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5998 /* Parse a for statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
6001 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
6002 for ( nested-declaration expression[opt] ; expression[opt] ) statement
6004 The form with a declaration is new in C99.
6006 ??? In accordance with the old parser, the declaration may be a
6007 nested function, which is then rejected in check_for_loop_decls,
6008 but does it make any sense for this to be included in the grammar?
6009 Note in particular that the nested function does not include a
6010 trailing ';', whereas the "declaration" production includes one.
6011 Also, can we reject bad declarations earlier and cheaper than
6012 check_for_loop_decls?
6014 In Objective-C, there are two additional variants:
6017 for ( expression in expresssion ) statement
6018 for ( declaration in expression ) statement
6020 This is inconsistent with C, because the second variant is allowed
6021 even if c99 is not enabled.
6023 The rest of the comment documents these Objective-C foreach-statement.
6025 Here is the canonical example of the first variant:
6026 for (object in array) { do something with object }
6027 we call the first expression ("object") the "object_expression" and
6028 the second expression ("array") the "collection_expression".
6029 object_expression must be an lvalue of type "id" (a generic Objective-C
6030 object) because the loop works by assigning to object_expression the
6031 various objects from the collection_expression. collection_expression
6032 must evaluate to something of type "id" which responds to the method
6033 countByEnumeratingWithState:objects:count:.
6035 The canonical example of the second variant is:
6036 for (id object in array) { do something with object }
6037 which is completely equivalent to
6040 for (object in array) { do something with object }
6042 Note that initizializing 'object' in some way (eg, "for ((object =
6043 xxx) in array) { do something with object }") is possibly
6044 technically valid, but completely pointless as 'object' will be
6045 assigned to something else as soon as the loop starts. We should
6046 most likely reject it (TODO).
6048 The beginning of the Objective-C foreach-statement looks exactly
6049 like the beginning of the for-statement, and we can tell it is a
6050 foreach-statement only because the initial declaration or
6051 expression is terminated by 'in' instead of ';'.
6053 IF_P is used to track whether there's a (possibly labeled) if statement
6054 which is not enclosed in braces and has an else clause. This is used to
6055 implement -Wparentheses. */
6058 c_parser_for_statement (c_parser
*parser
, bool ivdep
, unsigned short unroll
,
6061 tree block
, cond
, incr
, save_break
, save_cont
, body
;
6062 /* The following are only used when parsing an ObjC foreach statement. */
6063 tree object_expression
;
6064 /* Silence the bogus uninitialized warning. */
6065 tree collection_expression
= NULL
;
6066 location_t loc
= c_parser_peek_token (parser
)->location
;
6067 location_t for_loc
= c_parser_peek_token (parser
)->location
;
6068 bool is_foreach_statement
= false;
6069 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
6070 token_indent_info for_tinfo
6071 = get_token_indent_info (c_parser_peek_token (parser
));
6072 c_parser_consume_token (parser
);
6073 /* Open a compound statement in Objective-C as well, just in case this is
6074 as foreach expression. */
6075 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
6076 cond
= error_mark_node
;
6077 incr
= error_mark_node
;
6078 matching_parens parens
;
6079 if (parens
.require_open (parser
))
6081 /* Parse the initialization declaration or expression. */
6082 object_expression
= error_mark_node
;
6083 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
6084 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6086 parser
->objc_could_be_foreach_context
= false;
6087 c_parser_consume_token (parser
);
6088 c_finish_expr_stmt (loc
, NULL_TREE
);
6090 else if (c_parser_next_tokens_start_declaration (parser
))
6092 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
6093 &object_expression
, vNULL
);
6094 parser
->objc_could_be_foreach_context
= false;
6096 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6098 c_parser_consume_token (parser
);
6099 is_foreach_statement
= true;
6100 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6101 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
6104 check_for_loop_decls (for_loc
, flag_isoc99
);
6106 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
6108 /* __extension__ can start a declaration, but is also an
6109 unary operator that can start an expression. Consume all
6110 but the last of a possible series of __extension__ to
6112 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
6113 && (c_parser_peek_2nd_token (parser
)->keyword
6115 c_parser_consume_token (parser
);
6116 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
6119 ext
= disable_extension_diagnostics ();
6120 c_parser_consume_token (parser
);
6121 c_parser_declaration_or_fndef (parser
, true, true, true, true,
6122 true, &object_expression
, vNULL
);
6123 parser
->objc_could_be_foreach_context
= false;
6125 restore_extension_diagnostics (ext
);
6126 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6128 c_parser_consume_token (parser
);
6129 is_foreach_statement
= true;
6130 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6131 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
6134 check_for_loop_decls (for_loc
, flag_isoc99
);
6144 tree init_expression
;
6145 ce
= c_parser_expression (parser
);
6146 init_expression
= ce
.value
;
6147 parser
->objc_could_be_foreach_context
= false;
6148 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6150 c_parser_consume_token (parser
);
6151 is_foreach_statement
= true;
6152 if (! lvalue_p (init_expression
))
6153 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
6154 object_expression
= c_fully_fold (init_expression
, false, NULL
);
6158 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6159 init_expression
= ce
.value
;
6160 c_finish_expr_stmt (loc
, init_expression
);
6161 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6165 /* Parse the loop condition. In the case of a foreach
6166 statement, there is no loop condition. */
6167 gcc_assert (!parser
->objc_could_be_foreach_context
);
6168 if (!is_foreach_statement
)
6170 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6174 c_parser_error (parser
, "missing loop condition in loop with "
6175 "%<GCC ivdep%> pragma");
6176 cond
= error_mark_node
;
6180 c_parser_error (parser
, "missing loop condition in loop with "
6181 "%<GCC unroll%> pragma");
6182 cond
= error_mark_node
;
6186 c_parser_consume_token (parser
);
6192 cond
= c_parser_condition (parser
);
6193 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
6196 if (ivdep
&& cond
!= error_mark_node
)
6197 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6198 build_int_cst (integer_type_node
,
6199 annot_expr_ivdep_kind
),
6201 if (unroll
&& cond
!= error_mark_node
)
6202 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6203 build_int_cst (integer_type_node
,
6204 annot_expr_unroll_kind
),
6205 build_int_cst (integer_type_node
, unroll
));
6207 /* Parse the increment expression (the third expression in a
6208 for-statement). In the case of a foreach-statement, this is
6209 the expression that follows the 'in'. */
6210 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6212 if (is_foreach_statement
)
6214 c_parser_error (parser
, "missing collection in fast enumeration");
6215 collection_expression
= error_mark_node
;
6218 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
6222 if (is_foreach_statement
)
6223 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
6227 struct c_expr ce
= c_parser_expression (parser
);
6228 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6229 incr
= c_process_expr_stmt (loc
, ce
.value
);
6232 parens
.skip_until_found_close (parser
);
6234 save_break
= c_break_label
;
6235 c_break_label
= NULL_TREE
;
6236 save_cont
= c_cont_label
;
6237 c_cont_label
= NULL_TREE
;
6239 token_indent_info body_tinfo
6240 = get_token_indent_info (c_parser_peek_token (parser
));
6242 location_t loc_after_labels
;
6243 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
6244 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
6246 if (is_foreach_statement
)
6247 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
6249 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
6250 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
6251 c_parser_maybe_reclassify_token (parser
);
6253 token_indent_info next_tinfo
6254 = get_token_indent_info (c_parser_peek_token (parser
));
6255 warn_for_misleading_indentation (for_tinfo
, body_tinfo
, next_tinfo
);
6257 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
6258 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
6259 for_tinfo
.location
, RID_FOR
);
6261 c_break_label
= save_break
;
6262 c_cont_label
= save_cont
;
6265 /* Parse an asm statement, a GNU extension. This is a full-blown asm
6266 statement with inputs, outputs, clobbers, and volatile tag
6270 asm type-qualifier[opt] ( asm-argument ) ;
6271 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
6275 asm-string-literal : asm-operands[opt]
6276 asm-string-literal : asm-operands[opt] : asm-operands[opt]
6277 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
6280 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
6283 Qualifiers other than volatile are accepted in the syntax but
6287 c_parser_asm_statement (c_parser
*parser
)
6289 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
6290 bool simple
, is_goto
;
6291 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
6292 int section
, nsections
;
6294 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
6295 c_parser_consume_token (parser
);
6296 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
6298 quals
= c_parser_peek_token (parser
)->value
;
6299 c_parser_consume_token (parser
);
6301 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
6302 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
6304 warning_at (c_parser_peek_token (parser
)->location
,
6306 "%E qualifier ignored on asm",
6307 c_parser_peek_token (parser
)->value
);
6309 c_parser_consume_token (parser
);
6315 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
6317 c_parser_consume_token (parser
);
6321 /* ??? Follow the C++ parser rather than using the
6322 lex_untranslated_string kludge. */
6323 parser
->lex_untranslated_string
= true;
6326 matching_parens parens
;
6327 if (!parens
.require_open (parser
))
6330 str
= c_parser_asm_string_literal (parser
);
6331 if (str
== NULL_TREE
)
6332 goto error_close_paren
;
6335 outputs
= NULL_TREE
;
6337 clobbers
= NULL_TREE
;
6340 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6343 /* Parse each colon-delimited section of operands. */
6344 nsections
= 3 + is_goto
;
6345 for (section
= 0; section
< nsections
; ++section
)
6347 if (!c_parser_require (parser
, CPP_COLON
,
6349 ? G_("expected %<:%>")
6350 : G_("expected %<:%> or %<)%>"),
6351 UNKNOWN_LOCATION
, is_goto
))
6352 goto error_close_paren
;
6354 /* Once past any colon, we're no longer a simple asm. */
6357 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
6358 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6363 /* For asm goto, we don't allow output operands, but reserve
6364 the slot for a future extension that does allow them. */
6366 outputs
= c_parser_asm_operands (parser
);
6369 inputs
= c_parser_asm_operands (parser
);
6372 clobbers
= c_parser_asm_clobbers (parser
);
6375 labels
= c_parser_asm_goto_operands (parser
);
6381 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6386 if (!parens
.require_close (parser
))
6388 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6392 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6393 c_parser_skip_to_end_of_block_or_statement (parser
);
6395 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
6396 clobbers
, labels
, simple
));
6399 parser
->lex_untranslated_string
= false;
6403 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6407 /* Parse asm operands, a GNU extension.
6411 asm-operands , asm-operand
6414 asm-string-literal ( expression )
6415 [ identifier ] asm-string-literal ( expression )
6419 c_parser_asm_operands (c_parser
*parser
)
6421 tree list
= NULL_TREE
;
6426 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
6428 c_parser_consume_token (parser
);
6429 if (c_parser_next_token_is (parser
, CPP_NAME
))
6431 tree id
= c_parser_peek_token (parser
)->value
;
6432 c_parser_consume_token (parser
);
6433 name
= build_string (IDENTIFIER_LENGTH (id
),
6434 IDENTIFIER_POINTER (id
));
6438 c_parser_error (parser
, "expected identifier");
6439 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
6442 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6447 str
= c_parser_asm_string_literal (parser
);
6448 if (str
== NULL_TREE
)
6450 parser
->lex_untranslated_string
= false;
6451 matching_parens parens
;
6452 if (!parens
.require_open (parser
))
6454 parser
->lex_untranslated_string
= true;
6457 expr
= c_parser_expression (parser
);
6458 mark_exp_read (expr
.value
);
6459 parser
->lex_untranslated_string
= true;
6460 if (!parens
.require_close (parser
))
6462 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6465 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
6467 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6468 c_parser_consume_token (parser
);
6475 /* Parse asm clobbers, a GNU extension.
6479 asm-clobbers , asm-string-literal
6483 c_parser_asm_clobbers (c_parser
*parser
)
6485 tree list
= NULL_TREE
;
6488 tree str
= c_parser_asm_string_literal (parser
);
6490 list
= tree_cons (NULL_TREE
, str
, list
);
6493 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6494 c_parser_consume_token (parser
);
6501 /* Parse asm goto labels, a GNU extension.
6505 asm-goto-operands , identifier
6509 c_parser_asm_goto_operands (c_parser
*parser
)
6511 tree list
= NULL_TREE
;
6516 if (c_parser_next_token_is (parser
, CPP_NAME
))
6518 c_token
*tok
= c_parser_peek_token (parser
);
6520 label
= lookup_label_for_goto (tok
->location
, name
);
6521 c_parser_consume_token (parser
);
6522 TREE_USED (label
) = 1;
6526 c_parser_error (parser
, "expected identifier");
6530 name
= build_string (IDENTIFIER_LENGTH (name
),
6531 IDENTIFIER_POINTER (name
));
6532 list
= tree_cons (name
, label
, list
);
6533 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6534 c_parser_consume_token (parser
);
6536 return nreverse (list
);
6540 /* Parse an expression other than a compound expression; that is, an
6541 assignment expression (C90 6.3.16, C99 6.5.16, C11 6.5.16). If
6542 AFTER is not NULL then it is an Objective-C message expression which
6543 is the primary-expression starting the expression as an initializer.
6545 assignment-expression:
6546 conditional-expression
6547 unary-expression assignment-operator assignment-expression
6549 assignment-operator: one of
6550 = *= /= %= += -= <<= >>= &= ^= |=
6552 In GNU C we accept any conditional expression on the LHS and
6553 diagnose the invalid lvalue rather than producing a syntax
6556 static struct c_expr
6557 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
6558 tree omp_atomic_lhs
)
6560 struct c_expr lhs
, rhs
, ret
;
6561 enum tree_code code
;
6562 location_t op_location
, exp_location
;
6563 gcc_assert (!after
|| c_dialect_objc ());
6564 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
6565 op_location
= c_parser_peek_token (parser
)->location
;
6566 switch (c_parser_peek_token (parser
)->type
)
6575 code
= TRUNC_DIV_EXPR
;
6578 code
= TRUNC_MOD_EXPR
;
6593 code
= BIT_AND_EXPR
;
6596 code
= BIT_XOR_EXPR
;
6599 code
= BIT_IOR_EXPR
;
6604 c_parser_consume_token (parser
);
6605 exp_location
= c_parser_peek_token (parser
)->location
;
6606 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6607 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6609 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6610 code
, exp_location
, rhs
.value
,
6612 set_c_expr_source_range (&ret
, lhs
.get_start (), rhs
.get_finish ());
6613 if (code
== NOP_EXPR
)
6614 ret
.original_code
= MODIFY_EXPR
;
6617 TREE_NO_WARNING (ret
.value
) = 1;
6618 ret
.original_code
= ERROR_MARK
;
6620 ret
.original_type
= NULL
;
6624 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15, C11 6.5.15). If
6625 AFTER is not NULL then it is an Objective-C message expression which is
6626 the primary-expression starting the expression as an initializer.
6628 conditional-expression:
6629 logical-OR-expression
6630 logical-OR-expression ? expression : conditional-expression
6634 conditional-expression:
6635 logical-OR-expression ? : conditional-expression
6638 static struct c_expr
6639 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6640 tree omp_atomic_lhs
)
6642 struct c_expr cond
, exp1
, exp2
, ret
;
6643 location_t start
, cond_loc
, colon_loc
;
6645 gcc_assert (!after
|| c_dialect_objc ());
6647 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6649 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6651 if (cond
.value
!= error_mark_node
)
6652 start
= cond
.get_start ();
6654 start
= UNKNOWN_LOCATION
;
6655 cond_loc
= c_parser_peek_token (parser
)->location
;
6656 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6657 c_parser_consume_token (parser
);
6658 if (c_parser_next_token_is (parser
, CPP_COLON
))
6660 tree eptype
= NULL_TREE
;
6662 location_t middle_loc
= c_parser_peek_token (parser
)->location
;
6663 pedwarn (middle_loc
, OPT_Wpedantic
,
6664 "ISO C forbids omitting the middle term of a ?: expression");
6665 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6667 eptype
= TREE_TYPE (cond
.value
);
6668 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6670 tree e
= cond
.value
;
6671 while (TREE_CODE (e
) == COMPOUND_EXPR
)
6672 e
= TREE_OPERAND (e
, 1);
6673 warn_for_omitted_condop (middle_loc
, e
);
6674 /* Make sure first operand is calculated only once. */
6675 exp1
.value
= save_expr (default_conversion (cond
.value
));
6677 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6678 exp1
.original_type
= NULL
;
6679 exp1
.src_range
= cond
.src_range
;
6680 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6681 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6686 = c_objc_common_truthvalue_conversion
6687 (cond_loc
, default_conversion (cond
.value
));
6688 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6689 exp1
= c_parser_expression_conv (parser
);
6690 mark_exp_read (exp1
.value
);
6691 c_inhibit_evaluation_warnings
+=
6692 ((cond
.value
== truthvalue_true_node
)
6693 - (cond
.value
== truthvalue_false_node
));
6696 colon_loc
= c_parser_peek_token (parser
)->location
;
6697 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6699 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6701 ret
.original_code
= ERROR_MARK
;
6702 ret
.original_type
= NULL
;
6706 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6707 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6708 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6710 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6711 location_t loc1
= make_location (exp1
.get_start (), exp1
.src_range
);
6712 location_t loc2
= make_location (exp2
.get_start (), exp2
.src_range
);
6713 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6714 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6715 exp1
.value
, exp1
.original_type
, loc1
,
6716 exp2
.value
, exp2
.original_type
, loc2
);
6717 ret
.original_code
= ERROR_MARK
;
6718 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6719 ret
.original_type
= NULL
;
6724 /* If both sides are enum type, the default conversion will have
6725 made the type of the result be an integer type. We want to
6726 remember the enum types we started with. */
6727 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6728 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6729 ret
.original_type
= ((t1
!= error_mark_node
6730 && t2
!= error_mark_node
6731 && (TYPE_MAIN_VARIANT (t1
)
6732 == TYPE_MAIN_VARIANT (t2
)))
6736 set_c_expr_source_range (&ret
, start
, exp2
.get_finish ());
6740 /* Parse a binary expression; that is, a logical-OR-expression (C90
6741 6.3.5-6.3.14, C99 6.5.5-6.5.14, C11 6.5.5-6.5.14). If AFTER is not
6742 NULL then it is an Objective-C message expression which is the
6743 primary-expression starting the expression as an initializer.
6745 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6746 when it should be the unfolded lhs. In a valid OpenMP source,
6747 one of the operands of the toplevel binary expression must be equal
6748 to it. In that case, just return a build2 created binary operation
6749 rather than result of parser_build_binary_op.
6751 multiplicative-expression:
6753 multiplicative-expression * cast-expression
6754 multiplicative-expression / cast-expression
6755 multiplicative-expression % cast-expression
6757 additive-expression:
6758 multiplicative-expression
6759 additive-expression + multiplicative-expression
6760 additive-expression - multiplicative-expression
6764 shift-expression << additive-expression
6765 shift-expression >> additive-expression
6767 relational-expression:
6769 relational-expression < shift-expression
6770 relational-expression > shift-expression
6771 relational-expression <= shift-expression
6772 relational-expression >= shift-expression
6774 equality-expression:
6775 relational-expression
6776 equality-expression == relational-expression
6777 equality-expression != relational-expression
6781 AND-expression & equality-expression
6783 exclusive-OR-expression:
6785 exclusive-OR-expression ^ AND-expression
6787 inclusive-OR-expression:
6788 exclusive-OR-expression
6789 inclusive-OR-expression | exclusive-OR-expression
6791 logical-AND-expression:
6792 inclusive-OR-expression
6793 logical-AND-expression && inclusive-OR-expression
6795 logical-OR-expression:
6796 logical-AND-expression
6797 logical-OR-expression || logical-AND-expression
6800 static struct c_expr
6801 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6802 tree omp_atomic_lhs
)
6804 /* A binary expression is parsed using operator-precedence parsing,
6805 with the operands being cast expressions. All the binary
6806 operators are left-associative. Thus a binary expression is of
6809 E0 op1 E1 op2 E2 ...
6811 which we represent on a stack. On the stack, the precedence
6812 levels are strictly increasing. When a new operator is
6813 encountered of higher precedence than that at the top of the
6814 stack, it is pushed; its LHS is the top expression, and its RHS
6815 is everything parsed until it is popped. When a new operator is
6816 encountered with precedence less than or equal to that at the top
6817 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6818 by the result of the operation until the operator at the top of
6819 the stack has lower precedence than the new operator or there is
6820 only one element on the stack; then the top expression is the LHS
6821 of the new operator. In the case of logical AND and OR
6822 expressions, we also need to adjust c_inhibit_evaluation_warnings
6823 as appropriate when the operators are pushed and popped. */
6826 /* The expression at this stack level. */
6828 /* The precedence of the operator on its left, PREC_NONE at the
6829 bottom of the stack. */
6830 enum c_parser_prec prec
;
6831 /* The operation on its left. */
6833 /* The source location of this operation. */
6835 /* The sizeof argument if expr.original_code == SIZEOF_EXPR. */
6839 /* Location of the binary operator. */
6840 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6843 switch (stack[sp].op) \
6845 case TRUTH_ANDIF_EXPR: \
6846 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6847 == truthvalue_false_node); \
6849 case TRUTH_ORIF_EXPR: \
6850 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6851 == truthvalue_true_node); \
6853 case TRUNC_DIV_EXPR: \
6854 if (stack[sp - 1].expr.original_code == SIZEOF_EXPR \
6855 && stack[sp].expr.original_code == SIZEOF_EXPR) \
6857 tree type0 = stack[sp - 1].sizeof_arg; \
6858 tree type1 = stack[sp].sizeof_arg; \
6859 tree first_arg = type0; \
6860 if (!TYPE_P (type0)) \
6861 type0 = TREE_TYPE (type0); \
6862 if (!TYPE_P (type1)) \
6863 type1 = TREE_TYPE (type1); \
6864 if (POINTER_TYPE_P (type0) \
6865 && comptypes (TREE_TYPE (type0), type1) \
6866 && !(TREE_CODE (first_arg) == PARM_DECL \
6867 && C_ARRAY_PARAMETER (first_arg) \
6868 && warn_sizeof_array_argument)) \
6870 auto_diagnostic_group d; \
6871 if (warning_at (stack[sp].loc, OPT_Wsizeof_pointer_div, \
6872 "division %<sizeof (%T) / sizeof (%T)%> " \
6873 "does not compute the number of array " \
6876 if (DECL_P (first_arg)) \
6877 inform (DECL_SOURCE_LOCATION (first_arg), \
6878 "first %<sizeof%> operand was declared here"); \
6885 stack[sp - 1].expr \
6886 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6887 stack[sp - 1].expr, true, true); \
6889 = convert_lvalue_to_rvalue (stack[sp].loc, \
6890 stack[sp].expr, true, true); \
6891 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6892 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6893 && ((1 << stack[sp].prec) \
6894 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6895 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6896 && stack[sp].op != TRUNC_MOD_EXPR \
6897 && stack[0].expr.value != error_mark_node \
6898 && stack[1].expr.value != error_mark_node \
6899 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6900 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6901 stack[0].expr.value \
6902 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6903 stack[0].expr.value, stack[1].expr.value); \
6905 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6907 stack[sp - 1].expr, \
6911 gcc_assert (!after
|| c_dialect_objc ());
6912 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6913 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6914 stack
[0].prec
= PREC_NONE
;
6915 stack
[0].sizeof_arg
= c_last_sizeof_arg
;
6919 enum c_parser_prec oprec
;
6920 enum tree_code ocode
;
6921 source_range src_range
;
6924 switch (c_parser_peek_token (parser
)->type
)
6932 ocode
= TRUNC_DIV_EXPR
;
6936 ocode
= TRUNC_MOD_EXPR
;
6948 ocode
= LSHIFT_EXPR
;
6952 ocode
= RSHIFT_EXPR
;
6966 case CPP_GREATER_EQ
:
6979 oprec
= PREC_BITAND
;
6980 ocode
= BIT_AND_EXPR
;
6983 oprec
= PREC_BITXOR
;
6984 ocode
= BIT_XOR_EXPR
;
6988 ocode
= BIT_IOR_EXPR
;
6991 oprec
= PREC_LOGAND
;
6992 ocode
= TRUTH_ANDIF_EXPR
;
6996 ocode
= TRUTH_ORIF_EXPR
;
6999 /* Not a binary operator, so end of the binary
7003 binary_loc
= c_parser_peek_token (parser
)->location
;
7004 while (oprec
<= stack
[sp
].prec
)
7006 c_parser_consume_token (parser
);
7009 case TRUTH_ANDIF_EXPR
:
7010 src_range
= stack
[sp
].expr
.src_range
;
7012 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
7013 stack
[sp
].expr
, true, true);
7014 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
7015 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
7016 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
7017 == truthvalue_false_node
);
7018 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
7020 case TRUTH_ORIF_EXPR
:
7021 src_range
= stack
[sp
].expr
.src_range
;
7023 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
7024 stack
[sp
].expr
, true, true);
7025 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
7026 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
7027 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
7028 == truthvalue_true_node
);
7029 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
7035 stack
[sp
].loc
= binary_loc
;
7036 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
7037 stack
[sp
].prec
= oprec
;
7038 stack
[sp
].op
= ocode
;
7039 stack
[sp
].sizeof_arg
= c_last_sizeof_arg
;
7044 return stack
[0].expr
;
7048 /* Parse a cast expression (C90 6.3.4, C99 6.5.4, C11 6.5.4). If AFTER
7049 is not NULL then it is an Objective-C message expression which is the
7050 primary-expression starting the expression as an initializer.
7054 ( type-name ) unary-expression
7057 static struct c_expr
7058 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
7060 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
7061 gcc_assert (!after
|| c_dialect_objc ());
7063 return c_parser_postfix_expression_after_primary (parser
,
7065 /* If the expression begins with a parenthesized type name, it may
7066 be either a cast or a compound literal; we need to see whether
7067 the next character is '{' to tell the difference. If not, it is
7068 an unary expression. Full detection of unknown typenames here
7069 would require a 3-token lookahead. */
7070 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7071 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7073 struct c_type_name
*type_name
;
7076 matching_parens parens
;
7077 parens
.consume_open (parser
);
7078 type_name
= c_parser_type_name (parser
, true);
7079 parens
.skip_until_found_close (parser
);
7080 if (type_name
== NULL
)
7083 ret
.original_code
= ERROR_MARK
;
7084 ret
.original_type
= NULL
;
7088 /* Save casted types in the function's used types hash table. */
7089 used_types_insert (type_name
->specs
->type
);
7091 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7092 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
7094 if (type_name
->specs
->alignas_p
)
7095 error_at (type_name
->specs
->locations
[cdw_alignas
],
7096 "alignment specified for type name in cast");
7098 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7099 expr
= c_parser_cast_expression (parser
, NULL
);
7100 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
7102 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
7103 if (ret
.value
&& expr
.value
)
7104 set_c_expr_source_range (&ret
, cast_loc
, expr
.get_finish ());
7105 ret
.original_code
= ERROR_MARK
;
7106 ret
.original_type
= NULL
;
7110 return c_parser_unary_expression (parser
);
7113 /* Parse an unary expression (C90 6.3.3, C99 6.5.3, C11 6.5.3).
7119 unary-operator cast-expression
7120 sizeof unary-expression
7121 sizeof ( type-name )
7123 unary-operator: one of
7129 __alignof__ unary-expression
7130 __alignof__ ( type-name )
7133 (C11 permits _Alignof with type names only.)
7135 unary-operator: one of
7136 __extension__ __real__ __imag__
7138 Transactional Memory:
7141 transaction-expression
7143 In addition, the GNU syntax treats ++ and -- as unary operators, so
7144 they may be applied to cast expressions with errors for non-lvalues
7147 static struct c_expr
7148 c_parser_unary_expression (c_parser
*parser
)
7151 struct c_expr ret
, op
;
7152 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7155 ret
.original_code
= ERROR_MARK
;
7156 ret
.original_type
= NULL
;
7157 switch (c_parser_peek_token (parser
)->type
)
7160 c_parser_consume_token (parser
);
7161 exp_loc
= c_parser_peek_token (parser
)->location
;
7162 op
= c_parser_cast_expression (parser
, NULL
);
7164 op
= default_function_array_read_conversion (exp_loc
, op
);
7165 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
7166 case CPP_MINUS_MINUS
:
7167 c_parser_consume_token (parser
);
7168 exp_loc
= c_parser_peek_token (parser
)->location
;
7169 op
= c_parser_cast_expression (parser
, NULL
);
7171 op
= default_function_array_read_conversion (exp_loc
, op
);
7172 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
7174 c_parser_consume_token (parser
);
7175 op
= c_parser_cast_expression (parser
, NULL
);
7176 mark_exp_read (op
.value
);
7177 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
7180 c_parser_consume_token (parser
);
7181 exp_loc
= c_parser_peek_token (parser
)->location
;
7182 op
= c_parser_cast_expression (parser
, NULL
);
7183 finish
= op
.get_finish ();
7184 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7185 location_t combined_loc
= make_location (op_loc
, op_loc
, finish
);
7186 ret
.value
= build_indirect_ref (combined_loc
, op
.value
, RO_UNARY_STAR
);
7187 ret
.src_range
.m_start
= op_loc
;
7188 ret
.src_range
.m_finish
= finish
;
7192 if (!c_dialect_objc () && !in_system_header_at (input_location
))
7195 "traditional C rejects the unary plus operator");
7196 c_parser_consume_token (parser
);
7197 exp_loc
= c_parser_peek_token (parser
)->location
;
7198 op
= c_parser_cast_expression (parser
, NULL
);
7199 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7200 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
7202 c_parser_consume_token (parser
);
7203 exp_loc
= c_parser_peek_token (parser
)->location
;
7204 op
= c_parser_cast_expression (parser
, NULL
);
7205 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7206 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
7208 c_parser_consume_token (parser
);
7209 exp_loc
= c_parser_peek_token (parser
)->location
;
7210 op
= c_parser_cast_expression (parser
, NULL
);
7211 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7212 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
7214 c_parser_consume_token (parser
);
7215 exp_loc
= c_parser_peek_token (parser
)->location
;
7216 op
= c_parser_cast_expression (parser
, NULL
);
7217 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7218 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
7220 /* Refer to the address of a label as a pointer. */
7221 c_parser_consume_token (parser
);
7222 if (c_parser_next_token_is (parser
, CPP_NAME
))
7224 ret
.value
= finish_label_address_expr
7225 (c_parser_peek_token (parser
)->value
, op_loc
);
7226 set_c_expr_source_range (&ret
, op_loc
,
7227 c_parser_peek_token (parser
)->get_finish ());
7228 c_parser_consume_token (parser
);
7232 c_parser_error (parser
, "expected identifier");
7237 switch (c_parser_peek_token (parser
)->keyword
)
7240 return c_parser_sizeof_expression (parser
);
7242 return c_parser_alignof_expression (parser
);
7244 c_parser_consume_token (parser
);
7245 ext
= disable_extension_diagnostics ();
7246 ret
= c_parser_cast_expression (parser
, NULL
);
7247 restore_extension_diagnostics (ext
);
7250 c_parser_consume_token (parser
);
7251 exp_loc
= c_parser_peek_token (parser
)->location
;
7252 op
= c_parser_cast_expression (parser
, NULL
);
7253 op
= default_function_array_conversion (exp_loc
, op
);
7254 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
7256 c_parser_consume_token (parser
);
7257 exp_loc
= c_parser_peek_token (parser
)->location
;
7258 op
= c_parser_cast_expression (parser
, NULL
);
7259 op
= default_function_array_conversion (exp_loc
, op
);
7260 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
7261 case RID_TRANSACTION_ATOMIC
:
7262 case RID_TRANSACTION_RELAXED
:
7263 return c_parser_transaction_expression (parser
,
7264 c_parser_peek_token (parser
)->keyword
);
7266 return c_parser_postfix_expression (parser
);
7269 return c_parser_postfix_expression (parser
);
7273 /* Parse a sizeof expression. */
7275 static struct c_expr
7276 c_parser_sizeof_expression (c_parser
*parser
)
7279 struct c_expr result
;
7280 location_t expr_loc
;
7281 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
7284 location_t finish
= UNKNOWN_LOCATION
;
7286 start
= c_parser_peek_token (parser
)->location
;
7288 c_parser_consume_token (parser
);
7289 c_inhibit_evaluation_warnings
++;
7291 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7292 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7294 /* Either sizeof ( type-name ) or sizeof unary-expression
7295 starting with a compound literal. */
7296 struct c_type_name
*type_name
;
7297 matching_parens parens
;
7298 parens
.consume_open (parser
);
7299 expr_loc
= c_parser_peek_token (parser
)->location
;
7300 type_name
= c_parser_type_name (parser
, true);
7301 parens
.skip_until_found_close (parser
);
7302 finish
= parser
->tokens_buf
[0].location
;
7303 if (type_name
== NULL
)
7306 c_inhibit_evaluation_warnings
--;
7309 ret
.original_code
= ERROR_MARK
;
7310 ret
.original_type
= NULL
;
7313 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7315 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7318 finish
= expr
.get_finish ();
7321 /* sizeof ( type-name ). */
7322 if (type_name
->specs
->alignas_p
)
7323 error_at (type_name
->specs
->locations
[cdw_alignas
],
7324 "alignment specified for type name in %<sizeof%>");
7325 c_inhibit_evaluation_warnings
--;
7327 result
= c_expr_sizeof_type (expr_loc
, type_name
);
7331 expr_loc
= c_parser_peek_token (parser
)->location
;
7332 expr
= c_parser_unary_expression (parser
);
7333 finish
= expr
.get_finish ();
7335 c_inhibit_evaluation_warnings
--;
7337 mark_exp_read (expr
.value
);
7338 if (TREE_CODE (expr
.value
) == COMPONENT_REF
7339 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
7340 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
7341 result
= c_expr_sizeof_expr (expr_loc
, expr
);
7343 if (finish
!= UNKNOWN_LOCATION
)
7344 set_c_expr_source_range (&result
, start
, finish
);
7348 /* Parse an alignof expression. */
7350 static struct c_expr
7351 c_parser_alignof_expression (c_parser
*parser
)
7354 location_t start_loc
= c_parser_peek_token (parser
)->location
;
7356 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
7357 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
7358 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
7360 /* A diagnostic is not required for the use of this identifier in
7361 the implementation namespace; only diagnose it for the C11
7362 spelling because of existing code using the other spellings. */
7366 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
7369 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
7372 c_parser_consume_token (parser
);
7373 c_inhibit_evaluation_warnings
++;
7375 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7376 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7378 /* Either __alignof__ ( type-name ) or __alignof__
7379 unary-expression starting with a compound literal. */
7381 struct c_type_name
*type_name
;
7383 matching_parens parens
;
7384 parens
.consume_open (parser
);
7385 loc
= c_parser_peek_token (parser
)->location
;
7386 type_name
= c_parser_type_name (parser
, true);
7387 end_loc
= c_parser_peek_token (parser
)->location
;
7388 parens
.skip_until_found_close (parser
);
7389 if (type_name
== NULL
)
7392 c_inhibit_evaluation_warnings
--;
7395 ret
.original_code
= ERROR_MARK
;
7396 ret
.original_type
= NULL
;
7399 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7401 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7406 /* alignof ( type-name ). */
7407 if (type_name
->specs
->alignas_p
)
7408 error_at (type_name
->specs
->locations
[cdw_alignas
],
7409 "alignment specified for type name in %qE",
7411 c_inhibit_evaluation_warnings
--;
7413 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
7415 false, is_c11_alignof
, 1);
7416 ret
.original_code
= ERROR_MARK
;
7417 ret
.original_type
= NULL
;
7418 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7424 expr
= c_parser_unary_expression (parser
);
7425 end_loc
= expr
.src_range
.m_finish
;
7427 mark_exp_read (expr
.value
);
7428 c_inhibit_evaluation_warnings
--;
7432 OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
7434 ret
.value
= c_alignof_expr (start_loc
, expr
.value
);
7435 ret
.original_code
= ERROR_MARK
;
7436 ret
.original_type
= NULL
;
7437 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7442 /* Helper function to read arguments of builtins which are interfaces
7443 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
7444 others. The name of the builtin is passed using BNAME parameter.
7445 Function returns true if there were no errors while parsing and
7446 stores the arguments in CEXPR_LIST. If it returns true,
7447 *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
7450 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
7451 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
7453 location_t
*out_close_paren_loc
)
7455 location_t loc
= c_parser_peek_token (parser
)->location
;
7456 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7458 bool saved_force_folding_builtin_constant_p
;
7460 *ret_cexpr_list
= NULL
;
7461 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
7463 error_at (loc
, "cannot take address of %qs", bname
);
7467 c_parser_consume_token (parser
);
7469 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7471 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7472 c_parser_consume_token (parser
);
7476 saved_force_folding_builtin_constant_p
7477 = force_folding_builtin_constant_p
;
7478 force_folding_builtin_constant_p
|= choose_expr_p
;
7479 expr
= c_parser_expr_no_commas (parser
, NULL
);
7480 force_folding_builtin_constant_p
7481 = saved_force_folding_builtin_constant_p
;
7482 vec_alloc (cexpr_list
, 1);
7483 vec_safe_push (cexpr_list
, expr
);
7484 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7486 c_parser_consume_token (parser
);
7487 expr
= c_parser_expr_no_commas (parser
, NULL
);
7488 vec_safe_push (cexpr_list
, expr
);
7491 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7492 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7495 *ret_cexpr_list
= cexpr_list
;
7499 /* This represents a single generic-association. */
7501 struct c_generic_association
7503 /* The location of the starting token of the type. */
7504 location_t type_location
;
7505 /* The association's type, or NULL_TREE for 'default'. */
7507 /* The association's expression. */
7508 struct c_expr expression
;
7511 /* Parse a generic-selection. (C11 6.5.1.1).
7514 _Generic ( assignment-expression , generic-assoc-list )
7518 generic-assoc-list , generic-association
7520 generic-association:
7521 type-name : assignment-expression
7522 default : assignment-expression
7525 static struct c_expr
7526 c_parser_generic_selection (c_parser
*parser
)
7528 struct c_expr selector
, error_expr
;
7530 struct c_generic_association matched_assoc
;
7531 bool match_found
= false;
7532 location_t generic_loc
, selector_loc
;
7534 error_expr
.original_code
= ERROR_MARK
;
7535 error_expr
.original_type
= NULL
;
7536 error_expr
.set_error ();
7537 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
7538 matched_assoc
.type
= NULL_TREE
;
7539 matched_assoc
.expression
= error_expr
;
7541 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
7542 generic_loc
= c_parser_peek_token (parser
)->location
;
7543 c_parser_consume_token (parser
);
7545 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7546 "ISO C99 does not support %<_Generic%>");
7548 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7549 "ISO C90 does not support %<_Generic%>");
7551 matching_parens parens
;
7552 if (!parens
.require_open (parser
))
7555 c_inhibit_evaluation_warnings
++;
7556 selector_loc
= c_parser_peek_token (parser
)->location
;
7557 selector
= c_parser_expr_no_commas (parser
, NULL
);
7558 selector
= default_function_array_conversion (selector_loc
, selector
);
7559 c_inhibit_evaluation_warnings
--;
7561 if (selector
.value
== error_mark_node
)
7563 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7566 selector_type
= TREE_TYPE (selector
.value
);
7567 /* In ISO C terms, rvalues (including the controlling expression of
7568 _Generic) do not have qualified types. */
7569 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
7570 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
7571 /* In ISO C terms, _Noreturn is not part of the type of expressions
7572 such as &abort, but in GCC it is represented internally as a type
7574 if (FUNCTION_POINTER_TYPE_P (selector_type
)
7575 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
7577 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
7579 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7581 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7585 auto_vec
<c_generic_association
> associations
;
7588 struct c_generic_association assoc
, *iter
;
7590 c_token
*token
= c_parser_peek_token (parser
);
7592 assoc
.type_location
= token
->location
;
7593 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
7595 c_parser_consume_token (parser
);
7596 assoc
.type
= NULL_TREE
;
7600 struct c_type_name
*type_name
;
7602 type_name
= c_parser_type_name (parser
);
7603 if (type_name
== NULL
)
7605 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7608 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
7609 if (assoc
.type
== error_mark_node
)
7611 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7615 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
7616 error_at (assoc
.type_location
,
7617 "%<_Generic%> association has function type");
7618 else if (!COMPLETE_TYPE_P (assoc
.type
))
7619 error_at (assoc
.type_location
,
7620 "%<_Generic%> association has incomplete type");
7622 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
7623 error_at (assoc
.type_location
,
7624 "%<_Generic%> association has "
7625 "variable length type");
7628 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7630 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7634 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
7635 if (assoc
.expression
.value
== error_mark_node
)
7637 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7641 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
7643 if (assoc
.type
== NULL_TREE
)
7645 if (iter
->type
== NULL_TREE
)
7647 error_at (assoc
.type_location
,
7648 "duplicate %<default%> case in %<_Generic%>");
7649 inform (iter
->type_location
, "original %<default%> is here");
7652 else if (iter
->type
!= NULL_TREE
)
7654 if (comptypes (assoc
.type
, iter
->type
))
7656 error_at (assoc
.type_location
,
7657 "%<_Generic%> specifies two compatible types");
7658 inform (iter
->type_location
, "compatible type is here");
7663 if (assoc
.type
== NULL_TREE
)
7667 matched_assoc
= assoc
;
7671 else if (comptypes (assoc
.type
, selector_type
))
7673 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7675 matched_assoc
= assoc
;
7680 error_at (assoc
.type_location
,
7681 "%<_Generic%> selector matches multiple associations");
7682 inform (matched_assoc
.type_location
,
7683 "other match is here");
7687 associations
.safe_push (assoc
);
7689 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7691 c_parser_consume_token (parser
);
7694 if (!parens
.require_close (parser
))
7696 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7702 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7703 "compatible with any association",
7708 return matched_assoc
.expression
;
7711 /* Check the validity of a function pointer argument *EXPR (argument
7712 position POS) to __builtin_tgmath. Return the number of function
7713 arguments if possibly valid; return 0 having reported an error if
7717 check_tgmath_function (c_expr
*expr
, unsigned int pos
)
7719 tree type
= TREE_TYPE (expr
->value
);
7720 if (!FUNCTION_POINTER_TYPE_P (type
))
7722 error_at (expr
->get_location (),
7723 "argument %u of %<__builtin_tgmath%> is not a function pointer",
7727 type
= TREE_TYPE (type
);
7728 if (!prototype_p (type
))
7730 error_at (expr
->get_location (),
7731 "argument %u of %<__builtin_tgmath%> is unprototyped", pos
);
7734 if (stdarg_p (type
))
7736 error_at (expr
->get_location (),
7737 "argument %u of %<__builtin_tgmath%> has variable arguments",
7741 unsigned int nargs
= 0;
7742 function_args_iterator iter
;
7744 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
7746 if (t
== void_type_node
)
7752 error_at (expr
->get_location (),
7753 "argument %u of %<__builtin_tgmath%> has no arguments", pos
);
7759 /* Ways in which a parameter or return value of a type-generic macro
7760 may vary between the different functions the macro may call. */
7761 enum tgmath_parm_kind
7763 tgmath_fixed
, tgmath_real
, tgmath_complex
7766 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2,
7767 C11 6.5.1-6.5.2). Compound literals aren't handled here; callers have to
7768 call c_parser_postfix_expression_after_paren_type on encountering them.
7772 postfix-expression [ expression ]
7773 postfix-expression ( argument-expression-list[opt] )
7774 postfix-expression . identifier
7775 postfix-expression -> identifier
7776 postfix-expression ++
7777 postfix-expression --
7778 ( type-name ) { initializer-list }
7779 ( type-name ) { initializer-list , }
7781 argument-expression-list:
7783 argument-expression-list , argument-expression
7796 (treated as a keyword in GNU C)
7799 ( compound-statement )
7800 __builtin_va_arg ( assignment-expression , type-name )
7801 __builtin_offsetof ( type-name , offsetof-member-designator )
7802 __builtin_choose_expr ( assignment-expression ,
7803 assignment-expression ,
7804 assignment-expression )
7805 __builtin_types_compatible_p ( type-name , type-name )
7806 __builtin_tgmath ( expr-list )
7807 __builtin_complex ( assignment-expression , assignment-expression )
7808 __builtin_shuffle ( assignment-expression , assignment-expression )
7809 __builtin_shuffle ( assignment-expression ,
7810 assignment-expression ,
7811 assignment-expression, )
7813 offsetof-member-designator:
7815 offsetof-member-designator . identifier
7816 offsetof-member-designator [ expression ]
7821 [ objc-receiver objc-message-args ]
7822 @selector ( objc-selector-arg )
7823 @protocol ( identifier )
7824 @encode ( type-name )
7826 Classname . identifier
7829 static struct c_expr
7830 c_parser_postfix_expression (c_parser
*parser
)
7832 struct c_expr expr
, e1
;
7833 struct c_type_name
*t1
, *t2
;
7834 location_t loc
= c_parser_peek_token (parser
)->location
;
7835 source_range tok_range
= c_parser_peek_token (parser
)->get_range ();
7836 expr
.original_code
= ERROR_MARK
;
7837 expr
.original_type
= NULL
;
7838 switch (c_parser_peek_token (parser
)->type
)
7841 expr
.value
= c_parser_peek_token (parser
)->value
;
7842 set_c_expr_source_range (&expr
, tok_range
);
7843 loc
= c_parser_peek_token (parser
)->location
;
7844 c_parser_consume_token (parser
);
7845 if (TREE_CODE (expr
.value
) == FIXED_CST
7846 && !targetm
.fixed_point_supported_p ())
7848 error_at (loc
, "fixed-point types not supported for this target");
7856 expr
.value
= c_parser_peek_token (parser
)->value
;
7857 /* For the purpose of warning when a pointer is compared with
7858 a zero character constant. */
7859 expr
.original_type
= char_type_node
;
7860 set_c_expr_source_range (&expr
, tok_range
);
7861 c_parser_consume_token (parser
);
7867 case CPP_UTF8STRING
:
7868 expr
.value
= c_parser_peek_token (parser
)->value
;
7869 set_c_expr_source_range (&expr
, tok_range
);
7870 expr
.original_code
= STRING_CST
;
7871 c_parser_consume_token (parser
);
7873 case CPP_OBJC_STRING
:
7874 gcc_assert (c_dialect_objc ());
7876 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7877 set_c_expr_source_range (&expr
, tok_range
);
7878 c_parser_consume_token (parser
);
7881 switch (c_parser_peek_token (parser
)->id_kind
)
7885 tree id
= c_parser_peek_token (parser
)->value
;
7886 c_parser_consume_token (parser
);
7887 expr
.value
= build_external_ref (loc
, id
,
7888 (c_parser_peek_token (parser
)->type
7890 &expr
.original_type
);
7891 set_c_expr_source_range (&expr
, tok_range
);
7894 case C_ID_CLASSNAME
:
7896 /* Here we parse the Objective-C 2.0 Class.name dot
7898 tree class_name
= c_parser_peek_token (parser
)->value
;
7900 c_parser_consume_token (parser
);
7901 gcc_assert (c_dialect_objc ());
7902 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7907 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7909 c_parser_error (parser
, "expected identifier");
7913 c_token
*component_tok
= c_parser_peek_token (parser
);
7914 component
= component_tok
->value
;
7915 location_t end_loc
= component_tok
->get_finish ();
7916 c_parser_consume_token (parser
);
7917 expr
.value
= objc_build_class_component_ref (class_name
,
7919 set_c_expr_source_range (&expr
, loc
, end_loc
);
7923 c_parser_error (parser
, "expected expression");
7928 case CPP_OPEN_PAREN
:
7929 /* A parenthesized expression, statement expression or compound
7931 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7933 /* A statement expression. */
7935 location_t brace_loc
;
7936 c_parser_consume_token (parser
);
7937 brace_loc
= c_parser_peek_token (parser
)->location
;
7938 c_parser_consume_token (parser
);
7939 /* If we've not yet started the current function's statement list,
7940 or we're in the parameter scope of an old-style function
7941 declaration, statement expressions are not allowed. */
7942 if (!building_stmt_list_p () || old_style_parameter_scope ())
7944 error_at (loc
, "braced-group within expression allowed "
7945 "only inside a function");
7946 parser
->error
= true;
7947 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7948 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7952 stmt
= c_begin_stmt_expr ();
7953 c_parser_compound_statement_nostart (parser
);
7954 location_t close_loc
= c_parser_peek_token (parser
)->location
;
7955 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7957 pedwarn (loc
, OPT_Wpedantic
,
7958 "ISO C forbids braced-groups within expressions");
7959 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7960 set_c_expr_source_range (&expr
, loc
, close_loc
);
7961 mark_exp_read (expr
.value
);
7965 /* A parenthesized expression. */
7966 location_t loc_open_paren
= c_parser_peek_token (parser
)->location
;
7967 c_parser_consume_token (parser
);
7968 expr
= c_parser_expression (parser
);
7969 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7970 TREE_NO_WARNING (expr
.value
) = 1;
7971 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
7972 && expr
.original_code
!= SIZEOF_EXPR
)
7973 expr
.original_code
= ERROR_MARK
;
7974 /* Don't change EXPR.ORIGINAL_TYPE. */
7975 location_t loc_close_paren
= c_parser_peek_token (parser
)->location
;
7976 set_c_expr_source_range (&expr
, loc_open_paren
, loc_close_paren
);
7977 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7978 "expected %<)%>", loc_open_paren
);
7982 switch (c_parser_peek_token (parser
)->keyword
)
7984 case RID_FUNCTION_NAME
:
7985 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7986 "%<__FUNCTION__%> predefined identifier");
7987 expr
.value
= fname_decl (loc
,
7988 c_parser_peek_token (parser
)->keyword
,
7989 c_parser_peek_token (parser
)->value
);
7990 set_c_expr_source_range (&expr
, loc
, loc
);
7991 c_parser_consume_token (parser
);
7993 case RID_PRETTY_FUNCTION_NAME
:
7994 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7995 "%<__PRETTY_FUNCTION__%> predefined identifier");
7996 expr
.value
= fname_decl (loc
,
7997 c_parser_peek_token (parser
)->keyword
,
7998 c_parser_peek_token (parser
)->value
);
7999 set_c_expr_source_range (&expr
, loc
, loc
);
8000 c_parser_consume_token (parser
);
8002 case RID_C99_FUNCTION_NAME
:
8003 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
8004 "%<__func__%> predefined identifier");
8005 expr
.value
= fname_decl (loc
,
8006 c_parser_peek_token (parser
)->keyword
,
8007 c_parser_peek_token (parser
)->value
);
8008 set_c_expr_source_range (&expr
, loc
, loc
);
8009 c_parser_consume_token (parser
);
8013 location_t start_loc
= loc
;
8014 c_parser_consume_token (parser
);
8015 matching_parens parens
;
8016 if (!parens
.require_open (parser
))
8021 e1
= c_parser_expr_no_commas (parser
, NULL
);
8022 mark_exp_read (e1
.value
);
8023 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
8024 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8026 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8030 loc
= c_parser_peek_token (parser
)->location
;
8031 t1
= c_parser_type_name (parser
);
8032 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
8033 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8041 tree type_expr
= NULL_TREE
;
8042 expr
.value
= c_build_va_arg (start_loc
, e1
.value
, loc
,
8043 groktypename (t1
, &type_expr
, NULL
));
8046 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
8047 TREE_TYPE (expr
.value
), type_expr
,
8049 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
8051 set_c_expr_source_range (&expr
, start_loc
, end_loc
);
8057 c_parser_consume_token (parser
);
8058 matching_parens parens
;
8059 if (!parens
.require_open (parser
))
8064 t1
= c_parser_type_name (parser
);
8066 parser
->error
= true;
8067 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8068 gcc_assert (parser
->error
);
8071 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8075 tree type
= groktypename (t1
, NULL
, NULL
);
8077 if (type
== error_mark_node
)
8078 offsetof_ref
= error_mark_node
;
8081 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
8082 SET_EXPR_LOCATION (offsetof_ref
, loc
);
8084 /* Parse the second argument to __builtin_offsetof. We
8085 must have one identifier, and beyond that we want to
8086 accept sub structure and sub array references. */
8087 if (c_parser_next_token_is (parser
, CPP_NAME
))
8089 c_token
*comp_tok
= c_parser_peek_token (parser
);
8090 offsetof_ref
= build_component_ref
8091 (loc
, offsetof_ref
, comp_tok
->value
, comp_tok
->location
);
8092 c_parser_consume_token (parser
);
8093 while (c_parser_next_token_is (parser
, CPP_DOT
)
8094 || c_parser_next_token_is (parser
,
8096 || c_parser_next_token_is (parser
,
8099 if (c_parser_next_token_is (parser
, CPP_DEREF
))
8101 loc
= c_parser_peek_token (parser
)->location
;
8102 offsetof_ref
= build_array_ref (loc
,
8107 else if (c_parser_next_token_is (parser
, CPP_DOT
))
8110 c_parser_consume_token (parser
);
8111 if (c_parser_next_token_is_not (parser
,
8114 c_parser_error (parser
, "expected identifier");
8117 c_token
*comp_tok
= c_parser_peek_token (parser
);
8118 offsetof_ref
= build_component_ref
8119 (loc
, offsetof_ref
, comp_tok
->value
,
8120 comp_tok
->location
);
8121 c_parser_consume_token (parser
);
8127 loc
= c_parser_peek_token (parser
)->location
;
8128 c_parser_consume_token (parser
);
8129 ce
= c_parser_expression (parser
);
8130 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8132 idx
= c_fully_fold (idx
, false, NULL
);
8133 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8135 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
8140 c_parser_error (parser
, "expected identifier");
8141 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
8142 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8144 expr
.value
= fold_offsetof (offsetof_ref
);
8145 set_c_expr_source_range (&expr
, loc
, end_loc
);
8148 case RID_CHOOSE_EXPR
:
8150 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8151 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
8153 location_t close_paren_loc
;
8155 c_parser_consume_token (parser
);
8156 if (!c_parser_get_builtin_args (parser
,
8157 "__builtin_choose_expr",
8165 if (vec_safe_length (cexpr_list
) != 3)
8167 error_at (loc
, "wrong number of arguments to "
8168 "%<__builtin_choose_expr%>");
8173 e1_p
= &(*cexpr_list
)[0];
8174 e2_p
= &(*cexpr_list
)[1];
8175 e3_p
= &(*cexpr_list
)[2];
8178 mark_exp_read (e2_p
->value
);
8179 mark_exp_read (e3_p
->value
);
8180 if (TREE_CODE (c
) != INTEGER_CST
8181 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
8183 "first argument to %<__builtin_choose_expr%> not"
8185 constant_expression_warning (c
);
8186 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
8187 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8190 case RID_TYPES_COMPATIBLE_P
:
8192 c_parser_consume_token (parser
);
8193 matching_parens parens
;
8194 if (!parens
.require_open (parser
))
8199 t1
= c_parser_type_name (parser
);
8205 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8207 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8211 t2
= c_parser_type_name (parser
);
8217 location_t close_paren_loc
= c_parser_peek_token (parser
)->location
;
8218 parens
.skip_until_found_close (parser
);
8220 e1
= groktypename (t1
, NULL
, NULL
);
8221 e2
= groktypename (t2
, NULL
, NULL
);
8222 if (e1
== error_mark_node
|| e2
== error_mark_node
)
8228 e1
= TYPE_MAIN_VARIANT (e1
);
8229 e2
= TYPE_MAIN_VARIANT (e2
);
8232 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
8233 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8236 case RID_BUILTIN_TGMATH
:
8238 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8239 location_t close_paren_loc
;
8241 c_parser_consume_token (parser
);
8242 if (!c_parser_get_builtin_args (parser
,
8251 if (vec_safe_length (cexpr_list
) < 3)
8253 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8260 FOR_EACH_VEC_ELT (*cexpr_list
, i
, p
)
8261 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8262 unsigned int nargs
= check_tgmath_function (&(*cexpr_list
)[0], 1);
8268 if (vec_safe_length (cexpr_list
) < nargs
)
8270 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8274 unsigned int num_functions
= vec_safe_length (cexpr_list
) - nargs
;
8275 if (num_functions
< 2)
8277 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8282 /* The first NUM_FUNCTIONS expressions are the function
8283 pointers. The remaining NARGS expressions are the
8284 arguments that are to be passed to one of those
8285 functions, chosen following <tgmath.h> rules. */
8286 for (unsigned int j
= 1; j
< num_functions
; j
++)
8288 unsigned int this_nargs
8289 = check_tgmath_function (&(*cexpr_list
)[j
], j
+ 1);
8290 if (this_nargs
== 0)
8295 if (this_nargs
!= nargs
)
8297 error_at ((*cexpr_list
)[j
].get_location (),
8298 "argument %u of %<__builtin_tgmath%> has "
8299 "wrong number of arguments", j
+ 1);
8305 /* The functions all have the same number of arguments.
8306 Determine whether arguments and return types vary in
8307 ways permitted for <tgmath.h> functions. */
8308 /* The first entry in each of these vectors is for the
8309 return type, subsequent entries for parameter
8311 auto_vec
<enum tgmath_parm_kind
> parm_kind (nargs
+ 1);
8312 auto_vec
<tree
> parm_first (nargs
+ 1);
8313 auto_vec
<bool> parm_complex (nargs
+ 1);
8314 auto_vec
<bool> parm_varies (nargs
+ 1);
8315 tree first_type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[0].value
));
8316 tree first_ret
= TYPE_MAIN_VARIANT (TREE_TYPE (first_type
));
8317 parm_first
.quick_push (first_ret
);
8318 parm_complex
.quick_push (TREE_CODE (first_ret
) == COMPLEX_TYPE
);
8319 parm_varies
.quick_push (false);
8320 function_args_iterator iter
;
8322 unsigned int argpos
;
8323 FOREACH_FUNCTION_ARGS (first_type
, t
, iter
)
8325 if (t
== void_type_node
)
8327 parm_first
.quick_push (TYPE_MAIN_VARIANT (t
));
8328 parm_complex
.quick_push (TREE_CODE (t
) == COMPLEX_TYPE
);
8329 parm_varies
.quick_push (false);
8331 for (unsigned int j
= 1; j
< num_functions
; j
++)
8333 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8334 tree ret
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
8335 if (ret
!= parm_first
[0])
8337 parm_varies
[0] = true;
8338 if (!SCALAR_FLOAT_TYPE_P (parm_first
[0])
8339 && !COMPLEX_FLOAT_TYPE_P (parm_first
[0]))
8341 error_at ((*cexpr_list
)[0].get_location (),
8342 "invalid type-generic return type for "
8343 "argument %u of %<__builtin_tgmath%>",
8348 if (!SCALAR_FLOAT_TYPE_P (ret
)
8349 && !COMPLEX_FLOAT_TYPE_P (ret
))
8351 error_at ((*cexpr_list
)[j
].get_location (),
8352 "invalid type-generic return type for "
8353 "argument %u of %<__builtin_tgmath%>",
8359 if (TREE_CODE (ret
) == COMPLEX_TYPE
)
8360 parm_complex
[0] = true;
8362 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8364 if (t
== void_type_node
)
8366 t
= TYPE_MAIN_VARIANT (t
);
8367 if (t
!= parm_first
[argpos
])
8369 parm_varies
[argpos
] = true;
8370 if (!SCALAR_FLOAT_TYPE_P (parm_first
[argpos
])
8371 && !COMPLEX_FLOAT_TYPE_P (parm_first
[argpos
]))
8373 error_at ((*cexpr_list
)[0].get_location (),
8374 "invalid type-generic type for "
8375 "argument %u of argument %u of "
8376 "%<__builtin_tgmath%>", argpos
, 1);
8380 if (!SCALAR_FLOAT_TYPE_P (t
)
8381 && !COMPLEX_FLOAT_TYPE_P (t
))
8383 error_at ((*cexpr_list
)[j
].get_location (),
8384 "invalid type-generic type for "
8385 "argument %u of argument %u of "
8386 "%<__builtin_tgmath%>", argpos
, j
+ 1);
8391 if (TREE_CODE (t
) == COMPLEX_TYPE
)
8392 parm_complex
[argpos
] = true;
8396 enum tgmath_parm_kind max_variation
= tgmath_fixed
;
8397 for (unsigned int j
= 0; j
<= nargs
; j
++)
8399 enum tgmath_parm_kind this_kind
;
8402 if (parm_complex
[j
])
8403 max_variation
= this_kind
= tgmath_complex
;
8406 this_kind
= tgmath_real
;
8407 if (max_variation
!= tgmath_complex
)
8408 max_variation
= tgmath_real
;
8412 this_kind
= tgmath_fixed
;
8413 parm_kind
.quick_push (this_kind
);
8415 if (max_variation
== tgmath_fixed
)
8417 error_at (loc
, "function arguments of %<__builtin_tgmath%> "
8418 "all have the same type");
8423 /* Identify a parameter (not the return type) that varies,
8424 including with complex types if any variation includes
8425 complex types; there must be at least one such
8427 unsigned int tgarg
= 0;
8428 for (unsigned int j
= 1; j
<= nargs
; j
++)
8429 if (parm_kind
[j
] == max_variation
)
8436 error_at (loc
, "function arguments of %<__builtin_tgmath%> "
8437 "lack type-generic parameter");
8442 /* Determine the type of the relevant parameter for each
8444 auto_vec
<tree
> tg_type (num_functions
);
8445 for (unsigned int j
= 0; j
< num_functions
; j
++)
8447 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8449 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8451 if (argpos
== tgarg
)
8453 tg_type
.quick_push (TYPE_MAIN_VARIANT (t
));
8460 /* Verify that the corresponding types are different for
8461 all the listed functions. Also determine whether all
8462 the types are complex, whether all the types are
8463 standard or binary, and whether all the types are
8465 bool all_complex
= true;
8466 bool all_binary
= true;
8467 bool all_decimal
= true;
8468 hash_set
<tree
> tg_types
;
8469 FOR_EACH_VEC_ELT (tg_type
, i
, t
)
8471 if (TREE_CODE (t
) == COMPLEX_TYPE
)
8472 all_decimal
= false;
8475 all_complex
= false;
8476 if (DECIMAL_FLOAT_TYPE_P (t
))
8479 all_decimal
= false;
8481 if (tg_types
.add (t
))
8483 error_at ((*cexpr_list
)[i
].get_location (),
8484 "duplicate type-generic parameter type for "
8485 "function argument %u of %<__builtin_tgmath%>",
8492 /* Verify that other parameters and the return type whose
8493 types vary have their types varying in the correct
8495 for (unsigned int j
= 0; j
< num_functions
; j
++)
8497 tree exp_type
= tg_type
[j
];
8498 tree exp_real_type
= exp_type
;
8499 if (TREE_CODE (exp_type
) == COMPLEX_TYPE
)
8500 exp_real_type
= TREE_TYPE (exp_type
);
8501 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8502 tree ret
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
8503 if ((parm_kind
[0] == tgmath_complex
&& ret
!= exp_type
)
8504 || (parm_kind
[0] == tgmath_real
&& ret
!= exp_real_type
))
8506 error_at ((*cexpr_list
)[j
].get_location (),
8507 "bad return type for function argument %u "
8508 "of %<__builtin_tgmath%>", j
+ 1);
8513 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8515 if (t
== void_type_node
)
8517 t
= TYPE_MAIN_VARIANT (t
);
8518 if ((parm_kind
[argpos
] == tgmath_complex
8520 || (parm_kind
[argpos
] == tgmath_real
8521 && t
!= exp_real_type
))
8523 error_at ((*cexpr_list
)[j
].get_location (),
8524 "bad type for argument %u of "
8525 "function argument %u of "
8526 "%<__builtin_tgmath%>", argpos
, j
+ 1);
8534 /* The functions listed are a valid set of functions for a
8535 <tgmath.h> macro to select between. Identify the
8536 matching function, if any. First, the argument types
8537 must be combined following <tgmath.h> rules. Integer
8538 types are treated as _Decimal64 if any type-generic
8539 argument is decimal, or if the only alternatives for
8540 type-generic arguments are of decimal types, and are
8541 otherwise treated as double (or _Complex double for
8542 complex integer types, or _Float64 or _Complex _Float64
8543 if all the return types are the same _FloatN or
8544 _FloatNx type). After that adjustment, types are
8545 combined following the usual arithmetic conversions.
8546 If the function only accepts complex arguments, a
8547 complex type is produced. */
8548 bool arg_complex
= all_complex
;
8549 bool arg_binary
= all_binary
;
8550 bool arg_int_decimal
= all_decimal
;
8551 for (unsigned int j
= 1; j
<= nargs
; j
++)
8553 if (parm_kind
[j
] == tgmath_fixed
)
8555 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
- 1];
8556 tree type
= TREE_TYPE (ce
->value
);
8557 if (!INTEGRAL_TYPE_P (type
)
8558 && !SCALAR_FLOAT_TYPE_P (type
)
8559 && TREE_CODE (type
) != COMPLEX_TYPE
)
8561 error_at (ce
->get_location (),
8562 "invalid type of argument %u of type-generic "
8567 if (DECIMAL_FLOAT_TYPE_P (type
))
8569 arg_int_decimal
= true;
8572 error_at (ce
->get_location (),
8573 "decimal floating-point argument %u to "
8574 "complex-only type-generic function", j
);
8578 else if (all_binary
)
8580 error_at (ce
->get_location (),
8581 "decimal floating-point argument %u to "
8582 "binary-only type-generic function", j
);
8586 else if (arg_complex
)
8588 error_at (ce
->get_location (),
8589 "both complex and decimal floating-point "
8590 "arguments to type-generic function");
8594 else if (arg_binary
)
8596 error_at (ce
->get_location (),
8597 "both binary and decimal floating-point "
8598 "arguments to type-generic function");
8603 else if (TREE_CODE (type
) == COMPLEX_TYPE
)
8606 if (COMPLEX_FLOAT_TYPE_P (type
))
8610 error_at (ce
->get_location (),
8611 "complex argument %u to "
8612 "decimal-only type-generic function", j
);
8616 else if (arg_int_decimal
)
8618 error_at (ce
->get_location (),
8619 "both complex and decimal floating-point "
8620 "arguments to type-generic function");
8625 else if (SCALAR_FLOAT_TYPE_P (type
))
8630 error_at (ce
->get_location (),
8631 "binary argument %u to "
8632 "decimal-only type-generic function", j
);
8636 else if (arg_int_decimal
)
8638 error_at (ce
->get_location (),
8639 "both binary and decimal floating-point "
8640 "arguments to type-generic function");
8646 /* For a macro rounding its result to a narrower type, map
8647 integer types to _Float64 not double if the return type
8648 is a _FloatN or _FloatNx type. */
8649 bool arg_int_float64
= false;
8650 if (parm_kind
[0] == tgmath_fixed
8651 && SCALAR_FLOAT_TYPE_P (parm_first
[0])
8652 && float64_type_node
!= NULL_TREE
)
8653 for (unsigned int j
= 0; j
< NUM_FLOATN_NX_TYPES
; j
++)
8654 if (parm_first
[0] == FLOATN_TYPE_NODE (j
))
8656 arg_int_float64
= true;
8659 tree arg_real
= NULL_TREE
;
8660 for (unsigned int j
= 1; j
<= nargs
; j
++)
8662 if (parm_kind
[j
] == tgmath_fixed
)
8664 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
- 1];
8665 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (ce
->value
));
8666 if (TREE_CODE (type
) == COMPLEX_TYPE
)
8667 type
= TREE_TYPE (type
);
8668 if (INTEGRAL_TYPE_P (type
))
8669 type
= (arg_int_decimal
8670 ? dfloat64_type_node
8673 : double_type_node
);
8674 if (arg_real
== NULL_TREE
)
8677 arg_real
= common_type (arg_real
, type
);
8678 if (arg_real
== error_mark_node
)
8684 tree arg_type
= (arg_complex
8685 ? build_complex_type (arg_real
)
8688 /* Look for a function to call with type-generic parameter
8690 c_expr_t
*fn
= NULL
;
8691 for (unsigned int j
= 0; j
< num_functions
; j
++)
8693 if (tg_type
[j
] == arg_type
)
8695 fn
= &(*cexpr_list
)[j
];
8700 && parm_kind
[0] == tgmath_fixed
8701 && SCALAR_FLOAT_TYPE_P (parm_first
[0]))
8703 /* Presume this is a macro that rounds its result to a
8704 narrower type, and look for the first function with
8705 at least the range and precision of the argument
8707 for (unsigned int j
= 0; j
< num_functions
; j
++)
8710 != (TREE_CODE (tg_type
[j
]) == COMPLEX_TYPE
))
8712 tree real_tg_type
= (arg_complex
8713 ? TREE_TYPE (tg_type
[j
])
8715 if (DECIMAL_FLOAT_TYPE_P (arg_real
)
8716 != DECIMAL_FLOAT_TYPE_P (real_tg_type
))
8718 scalar_float_mode arg_mode
8719 = SCALAR_FLOAT_TYPE_MODE (arg_real
);
8720 scalar_float_mode tg_mode
8721 = SCALAR_FLOAT_TYPE_MODE (real_tg_type
);
8722 const real_format
*arg_fmt
= REAL_MODE_FORMAT (arg_mode
);
8723 const real_format
*tg_fmt
= REAL_MODE_FORMAT (tg_mode
);
8724 if (arg_fmt
->b
== tg_fmt
->b
8725 && arg_fmt
->p
<= tg_fmt
->p
8726 && arg_fmt
->emax
<= tg_fmt
->emax
8727 && (arg_fmt
->emin
- arg_fmt
->p
8728 >= tg_fmt
->emin
- tg_fmt
->p
))
8730 fn
= &(*cexpr_list
)[j
];
8737 error_at (loc
, "no matching function for type-generic call");
8742 /* Construct a call to FN. */
8743 vec
<tree
, va_gc
> *args
;
8744 vec_alloc (args
, nargs
);
8745 vec
<tree
, va_gc
> *origtypes
;
8746 vec_alloc (origtypes
, nargs
);
8747 auto_vec
<location_t
> arg_loc (nargs
);
8748 for (unsigned int j
= 0; j
< nargs
; j
++)
8750 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
];
8751 args
->quick_push (ce
->value
);
8752 arg_loc
.quick_push (ce
->get_location ());
8753 origtypes
->quick_push (ce
->original_type
);
8755 expr
.value
= c_build_function_call_vec (loc
, arg_loc
, fn
->value
,
8757 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8760 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
8762 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8765 location_t close_paren_loc
;
8767 c_parser_consume_token (parser
);
8768 if (!c_parser_get_builtin_args (parser
,
8769 "__builtin_call_with_static_chain",
8776 if (vec_safe_length (cexpr_list
) != 2)
8778 error_at (loc
, "wrong number of arguments to "
8779 "%<__builtin_call_with_static_chain%>");
8784 expr
= (*cexpr_list
)[0];
8785 e2_p
= &(*cexpr_list
)[1];
8786 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
8787 chain_value
= e2_p
->value
;
8788 mark_exp_read (chain_value
);
8790 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
8791 error_at (loc
, "first argument to "
8792 "%<__builtin_call_with_static_chain%> "
8793 "must be a call expression");
8794 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
8795 error_at (loc
, "second argument to "
8796 "%<__builtin_call_with_static_chain%> "
8797 "must be a pointer type");
8799 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
8800 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8803 case RID_BUILTIN_COMPLEX
:
8805 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8806 c_expr_t
*e1_p
, *e2_p
;
8807 location_t close_paren_loc
;
8809 c_parser_consume_token (parser
);
8810 if (!c_parser_get_builtin_args (parser
,
8811 "__builtin_complex",
8819 if (vec_safe_length (cexpr_list
) != 2)
8821 error_at (loc
, "wrong number of arguments to "
8822 "%<__builtin_complex%>");
8827 e1_p
= &(*cexpr_list
)[0];
8828 e2_p
= &(*cexpr_list
)[1];
8830 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
8831 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
8832 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
8833 TREE_OPERAND (e1_p
->value
, 0));
8834 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
8835 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
8836 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
8837 TREE_OPERAND (e2_p
->value
, 0));
8838 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8839 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8840 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
8841 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
8843 error_at (loc
, "%<__builtin_complex%> operand "
8844 "not of real binary floating-point type");
8848 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
8849 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
8852 "%<__builtin_complex%> operands of different types");
8856 pedwarn_c90 (loc
, OPT_Wpedantic
,
8857 "ISO C90 does not support complex types");
8858 expr
.value
= build2_loc (loc
, COMPLEX_EXPR
,
8861 (TREE_TYPE (e1_p
->value
))),
8862 e1_p
->value
, e2_p
->value
);
8863 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8866 case RID_BUILTIN_SHUFFLE
:
8868 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8871 location_t close_paren_loc
;
8873 c_parser_consume_token (parser
);
8874 if (!c_parser_get_builtin_args (parser
,
8875 "__builtin_shuffle",
8883 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
8884 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8886 if (vec_safe_length (cexpr_list
) == 2)
8888 c_build_vec_perm_expr
8889 (loc
, (*cexpr_list
)[0].value
,
8890 NULL_TREE
, (*cexpr_list
)[1].value
);
8892 else if (vec_safe_length (cexpr_list
) == 3)
8894 c_build_vec_perm_expr
8895 (loc
, (*cexpr_list
)[0].value
,
8896 (*cexpr_list
)[1].value
,
8897 (*cexpr_list
)[2].value
);
8900 error_at (loc
, "wrong number of arguments to "
8901 "%<__builtin_shuffle%>");
8904 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8907 case RID_AT_SELECTOR
:
8909 gcc_assert (c_dialect_objc ());
8910 c_parser_consume_token (parser
);
8911 matching_parens parens
;
8912 if (!parens
.require_open (parser
))
8917 tree sel
= c_parser_objc_selector_arg (parser
);
8918 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8919 parens
.skip_until_found_close (parser
);
8920 expr
.value
= objc_build_selector_expr (loc
, sel
);
8921 set_c_expr_source_range (&expr
, loc
, close_loc
);
8924 case RID_AT_PROTOCOL
:
8926 gcc_assert (c_dialect_objc ());
8927 c_parser_consume_token (parser
);
8928 matching_parens parens
;
8929 if (!parens
.require_open (parser
))
8934 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8936 c_parser_error (parser
, "expected identifier");
8937 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8941 tree id
= c_parser_peek_token (parser
)->value
;
8942 c_parser_consume_token (parser
);
8943 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8944 parens
.skip_until_found_close (parser
);
8945 expr
.value
= objc_build_protocol_expr (id
);
8946 set_c_expr_source_range (&expr
, loc
, close_loc
);
8951 /* Extension to support C-structures in the archiver. */
8952 gcc_assert (c_dialect_objc ());
8953 c_parser_consume_token (parser
);
8954 matching_parens parens
;
8955 if (!parens
.require_open (parser
))
8960 t1
= c_parser_type_name (parser
);
8964 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8967 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8968 parens
.skip_until_found_close (parser
);
8969 tree type
= groktypename (t1
, NULL
, NULL
);
8970 expr
.value
= objc_build_encode_expr (type
);
8971 set_c_expr_source_range (&expr
, loc
, close_loc
);
8975 expr
= c_parser_generic_selection (parser
);
8978 c_parser_error (parser
, "expected expression");
8983 case CPP_OPEN_SQUARE
:
8984 if (c_dialect_objc ())
8986 tree receiver
, args
;
8987 c_parser_consume_token (parser
);
8988 receiver
= c_parser_objc_receiver (parser
);
8989 args
= c_parser_objc_message_args (parser
);
8990 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8991 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8993 expr
.value
= objc_build_message_expr (receiver
, args
);
8994 set_c_expr_source_range (&expr
, loc
, close_loc
);
8997 /* Else fall through to report error. */
9000 c_parser_error (parser
, "expected expression");
9005 return c_parser_postfix_expression_after_primary
9006 (parser
, EXPR_LOC_OR_LOC (expr
.value
, loc
), expr
);
9009 /* Parse a postfix expression after a parenthesized type name: the
9010 brace-enclosed initializer of a compound literal, possibly followed
9011 by some postfix operators. This is separate because it is not
9012 possible to tell until after the type name whether a cast
9013 expression has a cast or a compound literal, or whether the operand
9014 of sizeof is a parenthesized type name or starts with a compound
9015 literal. TYPE_LOC is the location where TYPE_NAME starts--the
9016 location of the first token after the parentheses around the type
9019 static struct c_expr
9020 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
9021 struct c_type_name
*type_name
,
9022 location_t type_loc
)
9028 location_t start_loc
;
9029 tree type_expr
= NULL_TREE
;
9030 bool type_expr_const
= true;
9031 check_compound_literal_type (type_loc
, type_name
);
9032 rich_location
richloc (line_table
, type_loc
);
9033 start_init (NULL_TREE
, NULL
, 0, &richloc
);
9034 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
9035 start_loc
= c_parser_peek_token (parser
)->location
;
9036 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
9038 error_at (type_loc
, "compound literal has variable size");
9039 type
= error_mark_node
;
9041 init
= c_parser_braced_init (parser
, type
, false, NULL
);
9043 maybe_warn_string_init (type_loc
, type
, init
);
9045 if (type
!= error_mark_node
9046 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
9047 && current_function_decl
)
9049 error ("compound literal qualified by address-space qualifier");
9050 type
= error_mark_node
;
9053 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
9054 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
9055 ? CONSTRUCTOR_NON_CONST (init
.value
)
9056 : init
.original_code
== C_MAYBE_CONST_EXPR
);
9057 non_const
|= !type_expr_const
;
9058 unsigned int alignas_align
= 0;
9059 if (type
!= error_mark_node
9060 && type_name
->specs
->align_log
!= -1)
9062 alignas_align
= 1U << type_name
->specs
->align_log
;
9063 if (alignas_align
< min_align_of_type (type
))
9065 error_at (type_name
->specs
->locations
[cdw_alignas
],
9066 "%<_Alignas%> specifiers cannot reduce "
9067 "alignment of compound literal");
9071 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
,
9073 set_c_expr_source_range (&expr
, init
.src_range
);
9074 expr
.original_code
= ERROR_MARK
;
9075 expr
.original_type
= NULL
;
9076 if (type
!= error_mark_node
9077 && expr
.value
!= error_mark_node
9080 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
9082 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
9083 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
9087 gcc_assert (!non_const
);
9088 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
9089 type_expr
, expr
.value
);
9092 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
9095 /* Callback function for sizeof_pointer_memaccess_warning to compare
9099 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
9101 return comptypes (type1
, type2
) == 1;
9104 /* Warn for patterns where abs-like function appears to be used incorrectly,
9105 gracefully ignore any non-abs-like function. The warning location should
9106 be LOC. FNDECL is the declaration of called function, it must be a
9107 BUILT_IN_NORMAL function. ARG is the first and only argument of the
9111 warn_for_abs (location_t loc
, tree fndecl
, tree arg
)
9113 tree atype
= TREE_TYPE (arg
);
9115 /* Casts from pointers (and thus arrays and fndecls) will generate
9116 -Wint-conversion warnings. Most other wrong types hopefully lead to type
9117 mismatch errors. TODO: Think about what to do with FIXED_POINT_TYPE_P
9118 types and possibly other exotic types. */
9119 if (!INTEGRAL_TYPE_P (atype
)
9120 && !SCALAR_FLOAT_TYPE_P (atype
)
9121 && TREE_CODE (atype
) != COMPLEX_TYPE
)
9124 enum built_in_function fcode
= DECL_FUNCTION_CODE (fndecl
);
9130 case BUILT_IN_LLABS
:
9131 case BUILT_IN_IMAXABS
:
9132 if (!INTEGRAL_TYPE_P (atype
))
9134 if (SCALAR_FLOAT_TYPE_P (atype
))
9135 warning_at (loc
, OPT_Wabsolute_value
,
9136 "using integer absolute value function %qD when "
9137 "argument is of floating point type %qT",
9139 else if (TREE_CODE (atype
) == COMPLEX_TYPE
)
9140 warning_at (loc
, OPT_Wabsolute_value
,
9141 "using integer absolute value function %qD when "
9142 "argument is of complex type %qT", fndecl
, atype
);
9147 if (TYPE_UNSIGNED (atype
))
9148 warning_at (loc
, OPT_Wabsolute_value
,
9149 "taking the absolute value of unsigned type %qT "
9150 "has no effect", atype
);
9153 CASE_FLT_FN (BUILT_IN_FABS
):
9154 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FABS
):
9155 if (!SCALAR_FLOAT_TYPE_P (atype
)
9156 || DECIMAL_FLOAT_MODE_P (TYPE_MODE (atype
)))
9158 if (INTEGRAL_TYPE_P (atype
))
9159 warning_at (loc
, OPT_Wabsolute_value
,
9160 "using floating point absolute value function %qD "
9161 "when argument is of integer type %qT", fndecl
, atype
);
9162 else if (DECIMAL_FLOAT_TYPE_P (atype
))
9163 warning_at (loc
, OPT_Wabsolute_value
,
9164 "using floating point absolute value function %qD "
9165 "when argument is of decimal floating point type %qT",
9167 else if (TREE_CODE (atype
) == COMPLEX_TYPE
)
9168 warning_at (loc
, OPT_Wabsolute_value
,
9169 "using floating point absolute value function %qD when "
9170 "argument is of complex type %qT", fndecl
, atype
);
9177 CASE_FLT_FN (BUILT_IN_CABS
):
9178 if (TREE_CODE (atype
) != COMPLEX_TYPE
)
9180 if (INTEGRAL_TYPE_P (atype
))
9181 warning_at (loc
, OPT_Wabsolute_value
,
9182 "using complex absolute value function %qD when "
9183 "argument is of integer type %qT", fndecl
, atype
);
9184 else if (SCALAR_FLOAT_TYPE_P (atype
))
9185 warning_at (loc
, OPT_Wabsolute_value
,
9186 "using complex absolute value function %qD when "
9187 "argument is of floating point type %qT",
9196 case BUILT_IN_FABSD32
:
9197 case BUILT_IN_FABSD64
:
9198 case BUILT_IN_FABSD128
:
9199 if (!DECIMAL_FLOAT_TYPE_P (atype
))
9201 if (INTEGRAL_TYPE_P (atype
))
9202 warning_at (loc
, OPT_Wabsolute_value
,
9203 "using decimal floating point absolute value "
9204 "function %qD when argument is of integer type %qT",
9206 else if (SCALAR_FLOAT_TYPE_P (atype
))
9207 warning_at (loc
, OPT_Wabsolute_value
,
9208 "using decimal floating point absolute value "
9209 "function %qD when argument is of floating point "
9210 "type %qT", fndecl
, atype
);
9211 else if (TREE_CODE (atype
) == COMPLEX_TYPE
)
9212 warning_at (loc
, OPT_Wabsolute_value
,
9213 "using decimal floating point absolute value "
9214 "function %qD when argument is of complex type %qT",
9226 if (!TYPE_ARG_TYPES (TREE_TYPE (fndecl
)))
9229 tree ftype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)));
9230 if (TREE_CODE (atype
) == COMPLEX_TYPE
)
9232 gcc_assert (TREE_CODE (ftype
) == COMPLEX_TYPE
);
9233 atype
= TREE_TYPE (atype
);
9234 ftype
= TREE_TYPE (ftype
);
9237 if (TYPE_PRECISION (ftype
) < TYPE_PRECISION (atype
))
9238 warning_at (loc
, OPT_Wabsolute_value
,
9239 "absolute value function %qD given an argument of type %qT "
9240 "but has parameter of type %qT which may cause truncation "
9241 "of value", fndecl
, atype
, ftype
);
9245 /* Parse a postfix expression after the initial primary or compound
9246 literal; that is, parse a series of postfix operators.
9248 EXPR_LOC is the location of the primary expression. */
9250 static struct c_expr
9251 c_parser_postfix_expression_after_primary (c_parser
*parser
,
9252 location_t expr_loc
,
9255 struct c_expr orig_expr
;
9257 location_t sizeof_arg_loc
[3], comp_loc
;
9259 unsigned int literal_zero_mask
;
9261 vec
<tree
, va_gc
> *exprlist
;
9262 vec
<tree
, va_gc
> *origtypes
= NULL
;
9263 vec
<location_t
> arg_loc
= vNULL
;
9269 location_t op_loc
= c_parser_peek_token (parser
)->location
;
9270 switch (c_parser_peek_token (parser
)->type
)
9272 case CPP_OPEN_SQUARE
:
9273 /* Array reference. */
9274 c_parser_consume_token (parser
);
9275 idx
= c_parser_expression (parser
).value
;
9276 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
9278 start
= expr
.get_start ();
9279 finish
= parser
->tokens_buf
[0].location
;
9280 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
9281 set_c_expr_source_range (&expr
, start
, finish
);
9282 expr
.original_code
= ERROR_MARK
;
9283 expr
.original_type
= NULL
;
9285 case CPP_OPEN_PAREN
:
9286 /* Function call. */
9287 c_parser_consume_token (parser
);
9288 for (i
= 0; i
< 3; i
++)
9290 sizeof_arg
[i
] = NULL_TREE
;
9291 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
9293 literal_zero_mask
= 0;
9294 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9297 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
9298 sizeof_arg_loc
, sizeof_arg
,
9299 &arg_loc
, &literal_zero_mask
);
9300 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9303 mark_exp_read (expr
.value
);
9304 if (warn_sizeof_pointer_memaccess
)
9305 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
9306 expr
.value
, exprlist
,
9308 sizeof_ptr_memacc_comptypes
);
9309 if (TREE_CODE (expr
.value
) == FUNCTION_DECL
)
9311 if (fndecl_built_in_p (expr
.value
, BUILT_IN_MEMSET
)
9312 && vec_safe_length (exprlist
) == 3)
9314 tree arg0
= (*exprlist
)[0];
9315 tree arg2
= (*exprlist
)[2];
9316 warn_for_memset (expr_loc
, arg0
, arg2
, literal_zero_mask
);
9318 if (warn_absolute_value
9319 && fndecl_built_in_p (expr
.value
, BUILT_IN_NORMAL
)
9320 && vec_safe_length (exprlist
) == 1)
9321 warn_for_abs (expr_loc
, expr
.value
, (*exprlist
)[0]);
9324 start
= expr
.get_start ();
9325 finish
= parser
->tokens_buf
[0].get_finish ();
9327 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
9328 exprlist
, origtypes
);
9329 set_c_expr_source_range (&expr
, start
, finish
);
9331 expr
.original_code
= ERROR_MARK
;
9332 if (TREE_CODE (expr
.value
) == INTEGER_CST
9333 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
9334 && fndecl_built_in_p (orig_expr
.value
, BUILT_IN_CONSTANT_P
))
9335 expr
.original_code
= C_MAYBE_CONST_EXPR
;
9336 expr
.original_type
= NULL
;
9339 release_tree_vector (exprlist
);
9340 release_tree_vector (origtypes
);
9345 /* Structure element reference. */
9346 c_parser_consume_token (parser
);
9347 expr
= default_function_array_conversion (expr_loc
, expr
);
9348 if (c_parser_next_token_is (parser
, CPP_NAME
))
9350 c_token
*comp_tok
= c_parser_peek_token (parser
);
9351 ident
= comp_tok
->value
;
9352 comp_loc
= comp_tok
->location
;
9356 c_parser_error (parser
, "expected identifier");
9358 expr
.original_code
= ERROR_MARK
;
9359 expr
.original_type
= NULL
;
9362 start
= expr
.get_start ();
9363 finish
= c_parser_peek_token (parser
)->get_finish ();
9364 c_parser_consume_token (parser
);
9365 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
,
9367 set_c_expr_source_range (&expr
, start
, finish
);
9368 expr
.original_code
= ERROR_MARK
;
9369 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
9370 expr
.original_type
= NULL
;
9373 /* Remember the original type of a bitfield. */
9374 tree field
= TREE_OPERAND (expr
.value
, 1);
9375 if (TREE_CODE (field
) != FIELD_DECL
)
9376 expr
.original_type
= NULL
;
9378 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
9382 /* Structure element reference. */
9383 c_parser_consume_token (parser
);
9384 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
9385 if (c_parser_next_token_is (parser
, CPP_NAME
))
9387 c_token
*comp_tok
= c_parser_peek_token (parser
);
9388 ident
= comp_tok
->value
;
9389 comp_loc
= comp_tok
->location
;
9393 c_parser_error (parser
, "expected identifier");
9395 expr
.original_code
= ERROR_MARK
;
9396 expr
.original_type
= NULL
;
9399 start
= expr
.get_start ();
9400 finish
= c_parser_peek_token (parser
)->get_finish ();
9401 c_parser_consume_token (parser
);
9402 expr
.value
= build_component_ref (op_loc
,
9403 build_indirect_ref (op_loc
,
9407 set_c_expr_source_range (&expr
, start
, finish
);
9408 expr
.original_code
= ERROR_MARK
;
9409 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
9410 expr
.original_type
= NULL
;
9413 /* Remember the original type of a bitfield. */
9414 tree field
= TREE_OPERAND (expr
.value
, 1);
9415 if (TREE_CODE (field
) != FIELD_DECL
)
9416 expr
.original_type
= NULL
;
9418 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
9422 /* Postincrement. */
9423 start
= expr
.get_start ();
9424 finish
= c_parser_peek_token (parser
)->get_finish ();
9425 c_parser_consume_token (parser
);
9426 expr
= default_function_array_read_conversion (expr_loc
, expr
);
9427 expr
.value
= build_unary_op (op_loc
, POSTINCREMENT_EXPR
,
9429 set_c_expr_source_range (&expr
, start
, finish
);
9430 expr
.original_code
= ERROR_MARK
;
9431 expr
.original_type
= NULL
;
9433 case CPP_MINUS_MINUS
:
9434 /* Postdecrement. */
9435 start
= expr
.get_start ();
9436 finish
= c_parser_peek_token (parser
)->get_finish ();
9437 c_parser_consume_token (parser
);
9438 expr
= default_function_array_read_conversion (expr_loc
, expr
);
9439 expr
.value
= build_unary_op (op_loc
, POSTDECREMENT_EXPR
,
9441 set_c_expr_source_range (&expr
, start
, finish
);
9442 expr
.original_code
= ERROR_MARK
;
9443 expr
.original_type
= NULL
;
9451 /* Parse an expression (C90 6.3.17, C99 6.5.17, C11 6.5.17).
9454 assignment-expression
9455 expression , assignment-expression
9458 static struct c_expr
9459 c_parser_expression (c_parser
*parser
)
9461 location_t tloc
= c_parser_peek_token (parser
)->location
;
9463 expr
= c_parser_expr_no_commas (parser
, NULL
);
9464 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9465 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
9466 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9470 location_t loc
= c_parser_peek_token (parser
)->location
;
9471 location_t expr_loc
;
9472 c_parser_consume_token (parser
);
9473 expr_loc
= c_parser_peek_token (parser
)->location
;
9474 lhsval
= expr
.value
;
9475 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
9476 lhsval
= TREE_OPERAND (lhsval
, 1);
9477 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
9478 mark_exp_read (lhsval
);
9479 next
= c_parser_expr_no_commas (parser
, NULL
);
9480 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
9481 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
9482 expr
.original_code
= COMPOUND_EXPR
;
9483 expr
.original_type
= next
.original_type
;
9488 /* Parse an expression and convert functions or arrays to pointers and
9489 lvalues to rvalues. */
9491 static struct c_expr
9492 c_parser_expression_conv (c_parser
*parser
)
9495 location_t loc
= c_parser_peek_token (parser
)->location
;
9496 expr
= c_parser_expression (parser
);
9497 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
9501 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
9502 argument is a literal zero alone and if so, set it in literal_zero_mask. */
9505 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
9508 if (idx
>= HOST_BITS_PER_INT
)
9511 c_token
*tok
= c_parser_peek_token (parser
);
9519 /* If a parameter is literal zero alone, remember it
9520 for -Wmemset-transposed-args warning. */
9521 if (integer_zerop (tok
->value
)
9522 && !TREE_OVERFLOW (tok
->value
)
9523 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9524 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
9525 *literal_zero_mask
|= 1U << idx
;
9531 /* Parse a non-empty list of expressions. If CONVERT_P, convert
9532 functions and arrays to pointers and lvalues to rvalues. If
9533 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
9534 locations of function arguments into this vector.
9537 assignment-expression
9538 nonempty-expr-list , assignment-expression
9541 static vec
<tree
, va_gc
> *
9542 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
9543 vec
<tree
, va_gc
> **p_orig_types
,
9544 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
9545 vec
<location_t
> *locations
,
9546 unsigned int *literal_zero_mask
)
9548 vec
<tree
, va_gc
> *ret
;
9549 vec
<tree
, va_gc
> *orig_types
;
9551 unsigned int idx
= 0;
9553 ret
= make_tree_vector ();
9554 if (p_orig_types
== NULL
)
9557 orig_types
= make_tree_vector ();
9559 if (literal_zero_mask
)
9560 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
9561 expr
= c_parser_expr_no_commas (parser
, NULL
);
9563 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true, true);
9565 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
9566 ret
->quick_push (expr
.value
);
9568 orig_types
->quick_push (expr
.original_type
);
9570 locations
->safe_push (expr
.get_location ());
9571 if (sizeof_arg
!= NULL
9572 && expr
.original_code
== SIZEOF_EXPR
)
9574 sizeof_arg
[0] = c_last_sizeof_arg
;
9575 sizeof_arg_loc
[0] = c_last_sizeof_loc
;
9577 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9579 c_parser_consume_token (parser
);
9580 if (literal_zero_mask
)
9581 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
9582 expr
= c_parser_expr_no_commas (parser
, NULL
);
9584 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true,
9587 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
9588 vec_safe_push (ret
, expr
.value
);
9590 vec_safe_push (orig_types
, expr
.original_type
);
9592 locations
->safe_push (expr
.get_location ());
9594 && sizeof_arg
!= NULL
9595 && expr
.original_code
== SIZEOF_EXPR
)
9597 sizeof_arg
[idx
] = c_last_sizeof_arg
;
9598 sizeof_arg_loc
[idx
] = c_last_sizeof_loc
;
9602 *p_orig_types
= orig_types
;
9606 /* Parse Objective-C-specific constructs. */
9608 /* Parse an objc-class-definition.
9610 objc-class-definition:
9611 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
9612 objc-class-instance-variables[opt] objc-methodprotolist @end
9613 @implementation identifier objc-superclass[opt]
9614 objc-class-instance-variables[opt]
9615 @interface identifier ( identifier ) objc-protocol-refs[opt]
9616 objc-methodprotolist @end
9617 @interface identifier ( ) objc-protocol-refs[opt]
9618 objc-methodprotolist @end
9619 @implementation identifier ( identifier )
9624 "@interface identifier (" must start "@interface identifier (
9625 identifier ) ...": objc-methodprotolist in the first production may
9626 not start with a parenthesized identifier as a declarator of a data
9627 definition with no declaration specifiers if the objc-superclass,
9628 objc-protocol-refs and objc-class-instance-variables are omitted. */
9631 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
9636 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
9638 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
9643 c_parser_consume_token (parser
);
9644 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9646 c_parser_error (parser
, "expected identifier");
9649 id1
= c_parser_peek_token (parser
)->value
;
9650 c_parser_consume_token (parser
);
9651 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9653 /* We have a category or class extension. */
9655 tree proto
= NULL_TREE
;
9656 matching_parens parens
;
9657 parens
.consume_open (parser
);
9658 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9660 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9662 /* We have a class extension. */
9667 c_parser_error (parser
, "expected identifier or %<)%>");
9668 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
9674 id2
= c_parser_peek_token (parser
)->value
;
9675 c_parser_consume_token (parser
);
9677 parens
.skip_until_found_close (parser
);
9680 objc_start_category_implementation (id1
, id2
);
9683 if (c_parser_next_token_is (parser
, CPP_LESS
))
9684 proto
= c_parser_objc_protocol_refs (parser
);
9685 objc_start_category_interface (id1
, id2
, proto
, attributes
);
9686 c_parser_objc_methodprotolist (parser
);
9687 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9688 objc_finish_interface ();
9691 if (c_parser_next_token_is (parser
, CPP_COLON
))
9693 c_parser_consume_token (parser
);
9694 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9696 c_parser_error (parser
, "expected identifier");
9699 superclass
= c_parser_peek_token (parser
)->value
;
9700 c_parser_consume_token (parser
);
9703 superclass
= NULL_TREE
;
9706 tree proto
= NULL_TREE
;
9707 if (c_parser_next_token_is (parser
, CPP_LESS
))
9708 proto
= c_parser_objc_protocol_refs (parser
);
9709 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
9712 objc_start_class_implementation (id1
, superclass
);
9713 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9714 c_parser_objc_class_instance_variables (parser
);
9717 objc_continue_interface ();
9718 c_parser_objc_methodprotolist (parser
);
9719 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9720 objc_finish_interface ();
9724 objc_continue_implementation ();
9729 /* Parse objc-class-instance-variables.
9731 objc-class-instance-variables:
9732 { objc-instance-variable-decl-list[opt] }
9734 objc-instance-variable-decl-list:
9735 objc-visibility-spec
9736 objc-instance-variable-decl ;
9738 objc-instance-variable-decl-list objc-visibility-spec
9739 objc-instance-variable-decl-list objc-instance-variable-decl ;
9740 objc-instance-variable-decl-list ;
9742 objc-visibility-spec:
9747 objc-instance-variable-decl:
9752 c_parser_objc_class_instance_variables (c_parser
*parser
)
9754 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
9755 c_parser_consume_token (parser
);
9756 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
9759 /* Parse any stray semicolon. */
9760 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9762 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9764 c_parser_consume_token (parser
);
9767 /* Stop if at the end of the instance variables. */
9768 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9770 c_parser_consume_token (parser
);
9773 /* Parse any objc-visibility-spec. */
9774 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
9776 c_parser_consume_token (parser
);
9777 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
9780 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
9782 c_parser_consume_token (parser
);
9783 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
9786 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
9788 c_parser_consume_token (parser
);
9789 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
9792 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
9794 c_parser_consume_token (parser
);
9795 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
9798 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
9800 c_parser_pragma (parser
, pragma_external
, NULL
);
9804 /* Parse some comma-separated declarations. */
9805 decls
= c_parser_struct_declaration (parser
);
9808 /* There is a syntax error. We want to skip the offending
9809 tokens up to the next ';' (included) or '}'
9812 /* First, skip manually a ')' or ']'. This is because they
9813 reduce the nesting level, so c_parser_skip_until_found()
9814 wouldn't be able to skip past them. */
9815 c_token
*token
= c_parser_peek_token (parser
);
9816 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
9817 c_parser_consume_token (parser
);
9819 /* Then, do the standard skipping. */
9820 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9822 /* We hopefully recovered. Start normal parsing again. */
9823 parser
->error
= false;
9828 /* Comma-separated instance variables are chained together
9829 in reverse order; add them one by one. */
9830 tree ivar
= nreverse (decls
);
9831 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
9832 objc_add_instance_variable (copy_node (ivar
));
9834 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9838 /* Parse an objc-class-declaration.
9840 objc-class-declaration:
9841 @class identifier-list ;
9845 c_parser_objc_class_declaration (c_parser
*parser
)
9847 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
9848 c_parser_consume_token (parser
);
9849 /* Any identifiers, including those declared as type names, are OK
9854 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9856 c_parser_error (parser
, "expected identifier");
9857 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9858 parser
->error
= false;
9861 id
= c_parser_peek_token (parser
)->value
;
9862 objc_declare_class (id
);
9863 c_parser_consume_token (parser
);
9864 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9865 c_parser_consume_token (parser
);
9869 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9872 /* Parse an objc-alias-declaration.
9874 objc-alias-declaration:
9875 @compatibility_alias identifier identifier ;
9879 c_parser_objc_alias_declaration (c_parser
*parser
)
9882 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
9883 c_parser_consume_token (parser
);
9884 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9886 c_parser_error (parser
, "expected identifier");
9887 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9890 id1
= c_parser_peek_token (parser
)->value
;
9891 c_parser_consume_token (parser
);
9892 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9894 c_parser_error (parser
, "expected identifier");
9895 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9898 id2
= c_parser_peek_token (parser
)->value
;
9899 c_parser_consume_token (parser
);
9900 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9901 objc_declare_alias (id1
, id2
);
9904 /* Parse an objc-protocol-definition.
9906 objc-protocol-definition:
9907 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
9908 @protocol identifier-list ;
9910 "@protocol identifier ;" should be resolved as "@protocol
9911 identifier-list ;": objc-methodprotolist may not start with a
9912 semicolon in the first alternative if objc-protocol-refs are
9916 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
9918 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
9920 c_parser_consume_token (parser
);
9921 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9923 c_parser_error (parser
, "expected identifier");
9926 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9927 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
9929 /* Any identifiers, including those declared as type names, are
9934 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9936 c_parser_error (parser
, "expected identifier");
9939 id
= c_parser_peek_token (parser
)->value
;
9940 objc_declare_protocol (id
, attributes
);
9941 c_parser_consume_token (parser
);
9942 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9943 c_parser_consume_token (parser
);
9947 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9951 tree id
= c_parser_peek_token (parser
)->value
;
9952 tree proto
= NULL_TREE
;
9953 c_parser_consume_token (parser
);
9954 if (c_parser_next_token_is (parser
, CPP_LESS
))
9955 proto
= c_parser_objc_protocol_refs (parser
);
9956 parser
->objc_pq_context
= true;
9957 objc_start_protocol (id
, proto
, attributes
);
9958 c_parser_objc_methodprotolist (parser
);
9959 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9960 parser
->objc_pq_context
= false;
9961 objc_finish_interface ();
9965 /* Parse an objc-method-type.
9971 Return true if it is a class method (+) and false if it is
9972 an instance method (-).
9975 c_parser_objc_method_type (c_parser
*parser
)
9977 switch (c_parser_peek_token (parser
)->type
)
9980 c_parser_consume_token (parser
);
9983 c_parser_consume_token (parser
);
9990 /* Parse an objc-method-definition.
9992 objc-method-definition:
9993 objc-method-type objc-method-decl ;[opt] compound-statement
9997 c_parser_objc_method_definition (c_parser
*parser
)
9999 bool is_class_method
= c_parser_objc_method_type (parser
);
10000 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
10001 parser
->objc_pq_context
= true;
10002 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
10004 if (decl
== error_mark_node
)
10005 return; /* Bail here. */
10007 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10009 c_parser_consume_token (parser
);
10010 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
10011 "extra semicolon in method definition specified");
10014 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10016 c_parser_error (parser
, "expected %<{%>");
10020 parser
->objc_pq_context
= false;
10021 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
10023 add_stmt (c_parser_compound_statement (parser
));
10024 objc_finish_method_definition (current_function_decl
);
10028 /* This code is executed when we find a method definition
10029 outside of an @implementation context (or invalid for other
10030 reasons). Parse the method (to keep going) but do not emit
10033 c_parser_compound_statement (parser
);
10037 /* Parse an objc-methodprotolist.
10039 objc-methodprotolist:
10041 objc-methodprotolist objc-methodproto
10042 objc-methodprotolist declaration
10043 objc-methodprotolist ;
10047 The declaration is a data definition, which may be missing
10048 declaration specifiers under the same rules and diagnostics as
10049 other data definitions outside functions, and the stray semicolon
10050 is diagnosed the same way as a stray semicolon outside a
10054 c_parser_objc_methodprotolist (c_parser
*parser
)
10058 /* The list is terminated by @end. */
10059 switch (c_parser_peek_token (parser
)->type
)
10061 case CPP_SEMICOLON
:
10062 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
10063 "ISO C does not allow extra %<;%> outside of a function");
10064 c_parser_consume_token (parser
);
10068 c_parser_objc_methodproto (parser
);
10071 c_parser_pragma (parser
, pragma_external
, NULL
);
10076 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
10078 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
10079 c_parser_objc_at_property_declaration (parser
);
10080 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
10082 objc_set_method_opt (true);
10083 c_parser_consume_token (parser
);
10085 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
10087 objc_set_method_opt (false);
10088 c_parser_consume_token (parser
);
10091 c_parser_declaration_or_fndef (parser
, false, false, true,
10092 false, true, NULL
, vNULL
);
10098 /* Parse an objc-methodproto.
10101 objc-method-type objc-method-decl ;
10105 c_parser_objc_methodproto (c_parser
*parser
)
10107 bool is_class_method
= c_parser_objc_method_type (parser
);
10108 tree decl
, attributes
= NULL_TREE
;
10110 /* Remember protocol qualifiers in prototypes. */
10111 parser
->objc_pq_context
= true;
10112 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
10114 /* Forget protocol qualifiers now. */
10115 parser
->objc_pq_context
= false;
10117 /* Do not allow the presence of attributes to hide an erroneous
10118 method implementation in the interface section. */
10119 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
10121 c_parser_error (parser
, "expected %<;%>");
10125 if (decl
!= error_mark_node
)
10126 objc_add_method_declaration (is_class_method
, decl
, attributes
);
10128 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10131 /* If we are at a position that method attributes may be present, check that
10132 there are not any parsed already (a syntax error) and then collect any
10133 specified at the current location. Finally, if new attributes were present,
10134 check that the next token is legal ( ';' for decls and '{' for defs). */
10137 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
10142 c_parser_error (parser
,
10143 "method attributes must be specified at the end only");
10144 *attributes
= NULL_TREE
;
10148 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
10149 *attributes
= c_parser_attributes (parser
);
10151 /* If there were no attributes here, just report any earlier error. */
10152 if (*attributes
== NULL_TREE
|| bad
)
10155 /* If the attributes are followed by a ; or {, then just report any earlier
10157 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
10158 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
10161 /* We've got attributes, but not at the end. */
10162 c_parser_error (parser
,
10163 "expected %<;%> or %<{%> after method attribute definition");
10167 /* Parse an objc-method-decl.
10170 ( objc-type-name ) objc-selector
10172 ( objc-type-name ) objc-keyword-selector objc-optparmlist
10173 objc-keyword-selector objc-optparmlist
10176 objc-keyword-selector:
10178 objc-keyword-selector objc-keyword-decl
10181 objc-selector : ( objc-type-name ) identifier
10182 objc-selector : identifier
10183 : ( objc-type-name ) identifier
10187 objc-optparms objc-optellipsis
10191 objc-opt-parms , parameter-declaration
10199 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
10200 tree
*attributes
, tree
*expr
)
10202 tree type
= NULL_TREE
;
10204 tree parms
= NULL_TREE
;
10205 bool ellipsis
= false;
10206 bool attr_err
= false;
10208 *attributes
= NULL_TREE
;
10209 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10211 matching_parens parens
;
10212 parens
.consume_open (parser
);
10213 type
= c_parser_objc_type_name (parser
);
10214 parens
.skip_until_found_close (parser
);
10216 sel
= c_parser_objc_selector (parser
);
10217 /* If there is no selector, or a colon follows, we have an
10218 objc-keyword-selector. If there is a selector, and a colon does
10219 not follow, that selector ends the objc-method-decl. */
10220 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
10223 tree list
= NULL_TREE
;
10226 tree atype
= NULL_TREE
, id
, keyworddecl
;
10227 tree param_attr
= NULL_TREE
;
10228 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10230 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10232 c_parser_consume_token (parser
);
10233 atype
= c_parser_objc_type_name (parser
);
10234 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10237 /* New ObjC allows attributes on method parameters. */
10238 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
10239 param_attr
= c_parser_attributes (parser
);
10240 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10242 c_parser_error (parser
, "expected identifier");
10243 return error_mark_node
;
10245 id
= c_parser_peek_token (parser
)->value
;
10246 c_parser_consume_token (parser
);
10247 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
10248 list
= chainon (list
, keyworddecl
);
10249 tsel
= c_parser_objc_selector (parser
);
10250 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10254 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
10256 /* Parse the optional parameter list. Optional Objective-C
10257 method parameters follow the C syntax, and may include '...'
10258 to denote a variable number of arguments. */
10259 parms
= make_node (TREE_LIST
);
10260 while (c_parser_next_token_is (parser
, CPP_COMMA
))
10262 struct c_parm
*parm
;
10263 c_parser_consume_token (parser
);
10264 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
10267 c_parser_consume_token (parser
);
10268 attr_err
|= c_parser_objc_maybe_method_attributes
10269 (parser
, attributes
) ;
10272 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
10275 parms
= chainon (parms
,
10276 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
10281 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
10285 c_parser_error (parser
, "objective-c method declaration is expected");
10286 return error_mark_node
;
10290 return error_mark_node
;
10292 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
10295 /* Parse an objc-type-name.
10298 objc-type-qualifiers[opt] type-name
10299 objc-type-qualifiers[opt]
10301 objc-type-qualifiers:
10302 objc-type-qualifier
10303 objc-type-qualifiers objc-type-qualifier
10305 objc-type-qualifier: one of
10306 in out inout bycopy byref oneway
10310 c_parser_objc_type_name (c_parser
*parser
)
10312 tree quals
= NULL_TREE
;
10313 struct c_type_name
*type_name
= NULL
;
10314 tree type
= NULL_TREE
;
10317 c_token
*token
= c_parser_peek_token (parser
);
10318 if (token
->type
== CPP_KEYWORD
10319 && (token
->keyword
== RID_IN
10320 || token
->keyword
== RID_OUT
10321 || token
->keyword
== RID_INOUT
10322 || token
->keyword
== RID_BYCOPY
10323 || token
->keyword
== RID_BYREF
10324 || token
->keyword
== RID_ONEWAY
))
10326 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
10327 c_parser_consume_token (parser
);
10332 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
10333 type_name
= c_parser_type_name (parser
);
10335 type
= groktypename (type_name
, NULL
, NULL
);
10337 /* If the type is unknown, and error has already been produced and
10338 we need to recover from the error. In that case, use NULL_TREE
10339 for the type, as if no type had been specified; this will use the
10340 default type ('id') which is good for error recovery. */
10341 if (type
== error_mark_node
)
10344 return build_tree_list (quals
, type
);
10347 /* Parse objc-protocol-refs.
10349 objc-protocol-refs:
10350 < identifier-list >
10354 c_parser_objc_protocol_refs (c_parser
*parser
)
10356 tree list
= NULL_TREE
;
10357 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
10358 c_parser_consume_token (parser
);
10359 /* Any identifiers, including those declared as type names, are OK
10364 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10366 c_parser_error (parser
, "expected identifier");
10369 id
= c_parser_peek_token (parser
)->value
;
10370 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
10371 c_parser_consume_token (parser
);
10372 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10373 c_parser_consume_token (parser
);
10377 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
10381 /* Parse an objc-try-catch-finally-statement.
10383 objc-try-catch-finally-statement:
10384 @try compound-statement objc-catch-list[opt]
10385 @try compound-statement objc-catch-list[opt] @finally compound-statement
10388 @catch ( objc-catch-parameter-declaration ) compound-statement
10389 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
10391 objc-catch-parameter-declaration:
10392 parameter-declaration
10395 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
10397 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
10398 for C++. Keep them in sync. */
10401 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
10403 location_t location
;
10406 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
10407 c_parser_consume_token (parser
);
10408 location
= c_parser_peek_token (parser
)->location
;
10409 objc_maybe_warn_exceptions (location
);
10410 stmt
= c_parser_compound_statement (parser
);
10411 objc_begin_try_stmt (location
, stmt
);
10413 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
10415 struct c_parm
*parm
;
10416 tree parameter_declaration
= error_mark_node
;
10417 bool seen_open_paren
= false;
10419 c_parser_consume_token (parser
);
10420 matching_parens parens
;
10421 if (!parens
.require_open (parser
))
10422 seen_open_paren
= true;
10423 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
10425 /* We have "@catch (...)" (where the '...' are literally
10426 what is in the code). Skip the '...'.
10427 parameter_declaration is set to NULL_TREE, and
10428 objc_being_catch_clauses() knows that that means
10430 c_parser_consume_token (parser
);
10431 parameter_declaration
= NULL_TREE
;
10435 /* We have "@catch (NSException *exception)" or something
10436 like that. Parse the parameter declaration. */
10437 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
10439 parameter_declaration
= error_mark_node
;
10441 parameter_declaration
= grokparm (parm
, NULL
);
10443 if (seen_open_paren
)
10444 parens
.require_close (parser
);
10447 /* If there was no open parenthesis, we are recovering from
10448 an error, and we are trying to figure out what mistake
10449 the user has made. */
10451 /* If there is an immediate closing parenthesis, the user
10452 probably forgot the opening one (ie, they typed "@catch
10453 NSException *e)". Parse the closing parenthesis and keep
10455 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
10456 c_parser_consume_token (parser
);
10458 /* If these is no immediate closing parenthesis, the user
10459 probably doesn't know that parenthesis are required at
10460 all (ie, they typed "@catch NSException *e"). So, just
10461 forget about the closing parenthesis and keep going. */
10463 objc_begin_catch_clause (parameter_declaration
);
10464 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
10465 c_parser_compound_statement_nostart (parser
);
10466 objc_finish_catch_clause ();
10468 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
10470 c_parser_consume_token (parser
);
10471 location
= c_parser_peek_token (parser
)->location
;
10472 stmt
= c_parser_compound_statement (parser
);
10473 objc_build_finally_clause (location
, stmt
);
10475 objc_finish_try_stmt ();
10478 /* Parse an objc-synchronized-statement.
10480 objc-synchronized-statement:
10481 @synchronized ( expression ) compound-statement
10485 c_parser_objc_synchronized_statement (c_parser
*parser
)
10489 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
10490 c_parser_consume_token (parser
);
10491 loc
= c_parser_peek_token (parser
)->location
;
10492 objc_maybe_warn_exceptions (loc
);
10493 matching_parens parens
;
10494 if (parens
.require_open (parser
))
10496 struct c_expr ce
= c_parser_expression (parser
);
10497 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
10499 expr
= c_fully_fold (expr
, false, NULL
);
10500 parens
.skip_until_found_close (parser
);
10503 expr
= error_mark_node
;
10504 stmt
= c_parser_compound_statement (parser
);
10505 objc_build_synchronized (loc
, expr
, stmt
);
10508 /* Parse an objc-selector; return NULL_TREE without an error if the
10509 next token is not an objc-selector.
10514 enum struct union if else while do for switch case default
10515 break continue return goto asm sizeof typeof __alignof
10516 unsigned long const short volatile signed restrict _Complex
10517 in out inout bycopy byref oneway int char float double void _Bool
10520 ??? Why this selection of keywords but not, for example, storage
10521 class specifiers? */
10524 c_parser_objc_selector (c_parser
*parser
)
10526 c_token
*token
= c_parser_peek_token (parser
);
10527 tree value
= token
->value
;
10528 if (token
->type
== CPP_NAME
)
10530 c_parser_consume_token (parser
);
10533 if (token
->type
!= CPP_KEYWORD
)
10535 switch (token
->keyword
)
10574 CASE_RID_FLOATN_NX
:
10578 case RID_AUTO_TYPE
:
10583 c_parser_consume_token (parser
);
10590 /* Parse an objc-selector-arg.
10594 objc-keywordname-list
10596 objc-keywordname-list:
10598 objc-keywordname-list objc-keywordname
10606 c_parser_objc_selector_arg (c_parser
*parser
)
10608 tree sel
= c_parser_objc_selector (parser
);
10609 tree list
= NULL_TREE
;
10610 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10614 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10616 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
10617 sel
= c_parser_objc_selector (parser
);
10618 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10624 /* Parse an objc-receiver.
10633 c_parser_objc_receiver (c_parser
*parser
)
10635 location_t loc
= c_parser_peek_token (parser
)->location
;
10637 if (c_parser_peek_token (parser
)->type
== CPP_NAME
10638 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
10639 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
10641 tree id
= c_parser_peek_token (parser
)->value
;
10642 c_parser_consume_token (parser
);
10643 return objc_get_class_reference (id
);
10645 struct c_expr ce
= c_parser_expression (parser
);
10646 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
10647 return c_fully_fold (ce
.value
, false, NULL
);
10650 /* Parse objc-message-args.
10654 objc-keywordarg-list
10656 objc-keywordarg-list:
10658 objc-keywordarg-list objc-keywordarg
10661 objc-selector : objc-keywordexpr
10666 c_parser_objc_message_args (c_parser
*parser
)
10668 tree sel
= c_parser_objc_selector (parser
);
10669 tree list
= NULL_TREE
;
10670 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10675 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10676 return error_mark_node
;
10677 keywordexpr
= c_parser_objc_keywordexpr (parser
);
10678 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
10679 sel
= c_parser_objc_selector (parser
);
10680 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10686 /* Parse an objc-keywordexpr.
10693 c_parser_objc_keywordexpr (c_parser
*parser
)
10696 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
10697 NULL
, NULL
, NULL
, NULL
);
10698 if (vec_safe_length (expr_list
) == 1)
10700 /* Just return the expression, remove a level of
10702 ret
= (*expr_list
)[0];
10706 /* We have a comma expression, we will collapse later. */
10707 ret
= build_tree_list_vec (expr_list
);
10709 release_tree_vector (expr_list
);
10713 /* A check, needed in several places, that ObjC interface, implementation or
10714 method definitions are not prefixed by incorrect items. */
10716 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
10717 struct c_declspecs
*specs
)
10719 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
10720 || specs
->typespec_kind
!= ctsk_none
)
10722 c_parser_error (parser
,
10723 "no type or storage class may be specified here,");
10724 c_parser_skip_to_end_of_block_or_statement (parser
);
10730 /* Parse an Objective-C @property declaration. The syntax is:
10732 objc-property-declaration:
10733 '@property' objc-property-attributes[opt] struct-declaration ;
10735 objc-property-attributes:
10736 '(' objc-property-attribute-list ')'
10738 objc-property-attribute-list:
10739 objc-property-attribute
10740 objc-property-attribute-list, objc-property-attribute
10742 objc-property-attribute
10743 'getter' = identifier
10744 'setter' = identifier
10753 @property NSString *name;
10754 @property (readonly) id object;
10755 @property (retain, nonatomic, getter=getTheName) id name;
10756 @property int a, b, c;
10758 PS: This function is identical to cp_parser_objc_at_propery_declaration
10759 for C++. Keep them in sync. */
10761 c_parser_objc_at_property_declaration (c_parser
*parser
)
10763 /* The following variables hold the attributes of the properties as
10764 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
10765 seen. When we see an attribute, we set them to 'true' (if they
10766 are boolean properties) or to the identifier (if they have an
10767 argument, ie, for getter and setter). Note that here we only
10768 parse the list of attributes, check the syntax and accumulate the
10769 attributes that we find. objc_add_property_declaration() will
10770 then process the information. */
10771 bool property_assign
= false;
10772 bool property_copy
= false;
10773 tree property_getter_ident
= NULL_TREE
;
10774 bool property_nonatomic
= false;
10775 bool property_readonly
= false;
10776 bool property_readwrite
= false;
10777 bool property_retain
= false;
10778 tree property_setter_ident
= NULL_TREE
;
10780 /* 'properties' is the list of properties that we read. Usually a
10781 single one, but maybe more (eg, in "@property int a, b, c;" there
10786 loc
= c_parser_peek_token (parser
)->location
;
10787 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
10789 c_parser_consume_token (parser
); /* Eat '@property'. */
10791 /* Parse the optional attribute list... */
10792 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10794 matching_parens parens
;
10797 parens
.consume_open (parser
);
10799 /* Property attribute keywords are valid now. */
10800 parser
->objc_property_attr_context
= true;
10804 bool syntax_error
= false;
10805 c_token
*token
= c_parser_peek_token (parser
);
10808 if (token
->type
!= CPP_KEYWORD
)
10810 if (token
->type
== CPP_CLOSE_PAREN
)
10811 c_parser_error (parser
, "expected identifier");
10814 c_parser_consume_token (parser
);
10815 c_parser_error (parser
, "unknown property attribute");
10819 keyword
= token
->keyword
;
10820 c_parser_consume_token (parser
);
10823 case RID_ASSIGN
: property_assign
= true; break;
10824 case RID_COPY
: property_copy
= true; break;
10825 case RID_NONATOMIC
: property_nonatomic
= true; break;
10826 case RID_READONLY
: property_readonly
= true; break;
10827 case RID_READWRITE
: property_readwrite
= true; break;
10828 case RID_RETAIN
: property_retain
= true; break;
10832 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
10834 if (keyword
== RID_GETTER
)
10835 c_parser_error (parser
,
10836 "missing %<=%> (after %<getter%> attribute)");
10838 c_parser_error (parser
,
10839 "missing %<=%> (after %<setter%> attribute)");
10840 syntax_error
= true;
10843 c_parser_consume_token (parser
); /* eat the = */
10844 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10846 c_parser_error (parser
, "expected identifier");
10847 syntax_error
= true;
10850 if (keyword
== RID_SETTER
)
10852 if (property_setter_ident
!= NULL_TREE
)
10853 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
10855 property_setter_ident
= c_parser_peek_token (parser
)->value
;
10856 c_parser_consume_token (parser
);
10857 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
10858 c_parser_error (parser
, "setter name must terminate with %<:%>");
10860 c_parser_consume_token (parser
);
10864 if (property_getter_ident
!= NULL_TREE
)
10865 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
10867 property_getter_ident
= c_parser_peek_token (parser
)->value
;
10868 c_parser_consume_token (parser
);
10872 c_parser_error (parser
, "unknown property attribute");
10873 syntax_error
= true;
10880 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10881 c_parser_consume_token (parser
);
10885 parser
->objc_property_attr_context
= false;
10886 parens
.skip_until_found_close (parser
);
10888 /* ... and the property declaration(s). */
10889 properties
= c_parser_struct_declaration (parser
);
10891 if (properties
== error_mark_node
)
10893 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10894 parser
->error
= false;
10898 if (properties
== NULL_TREE
)
10899 c_parser_error (parser
, "expected identifier");
10902 /* Comma-separated properties are chained together in
10903 reverse order; add them one by one. */
10904 properties
= nreverse (properties
);
10906 for (; properties
; properties
= TREE_CHAIN (properties
))
10907 objc_add_property_declaration (loc
, copy_node (properties
),
10908 property_readonly
, property_readwrite
,
10909 property_assign
, property_retain
,
10910 property_copy
, property_nonatomic
,
10911 property_getter_ident
, property_setter_ident
);
10914 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10915 parser
->error
= false;
10918 /* Parse an Objective-C @synthesize declaration. The syntax is:
10920 objc-synthesize-declaration:
10921 @synthesize objc-synthesize-identifier-list ;
10923 objc-synthesize-identifier-list:
10924 objc-synthesize-identifier
10925 objc-synthesize-identifier-list, objc-synthesize-identifier
10927 objc-synthesize-identifier
10929 identifier = identifier
10932 @synthesize MyProperty;
10933 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
10935 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
10936 for C++. Keep them in sync.
10939 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
10941 tree list
= NULL_TREE
;
10943 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
10944 loc
= c_parser_peek_token (parser
)->location
;
10946 c_parser_consume_token (parser
);
10949 tree property
, ivar
;
10950 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10952 c_parser_error (parser
, "expected identifier");
10953 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10954 /* Once we find the semicolon, we can resume normal parsing.
10955 We have to reset parser->error manually because
10956 c_parser_skip_until_found() won't reset it for us if the
10957 next token is precisely a semicolon. */
10958 parser
->error
= false;
10961 property
= c_parser_peek_token (parser
)->value
;
10962 c_parser_consume_token (parser
);
10963 if (c_parser_next_token_is (parser
, CPP_EQ
))
10965 c_parser_consume_token (parser
);
10966 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10968 c_parser_error (parser
, "expected identifier");
10969 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10970 parser
->error
= false;
10973 ivar
= c_parser_peek_token (parser
)->value
;
10974 c_parser_consume_token (parser
);
10978 list
= chainon (list
, build_tree_list (ivar
, property
));
10979 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10980 c_parser_consume_token (parser
);
10984 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10985 objc_add_synthesize_declaration (loc
, list
);
10988 /* Parse an Objective-C @dynamic declaration. The syntax is:
10990 objc-dynamic-declaration:
10991 @dynamic identifier-list ;
10994 @dynamic MyProperty;
10995 @dynamic MyProperty, AnotherProperty;
10997 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
10998 for C++. Keep them in sync.
11001 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
11003 tree list
= NULL_TREE
;
11005 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
11006 loc
= c_parser_peek_token (parser
)->location
;
11008 c_parser_consume_token (parser
);
11012 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
11014 c_parser_error (parser
, "expected identifier");
11015 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
11016 parser
->error
= false;
11019 property
= c_parser_peek_token (parser
)->value
;
11020 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
11021 c_parser_consume_token (parser
);
11022 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11023 c_parser_consume_token (parser
);
11027 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
11028 objc_add_dynamic_declaration (loc
, list
);
11032 /* Parse a pragma GCC ivdep. */
11035 c_parse_pragma_ivdep (c_parser
*parser
)
11037 c_parser_consume_pragma (parser
);
11038 c_parser_skip_to_pragma_eol (parser
);
11042 /* Parse a pragma GCC unroll. */
11044 static unsigned short
11045 c_parser_pragma_unroll (c_parser
*parser
)
11047 unsigned short unroll
;
11048 c_parser_consume_pragma (parser
);
11049 location_t location
= c_parser_peek_token (parser
)->location
;
11050 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
11051 mark_exp_read (expr
);
11052 expr
= c_fully_fold (expr
, false, NULL
);
11053 HOST_WIDE_INT lunroll
= 0;
11054 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
11055 || TREE_CODE (expr
) != INTEGER_CST
11056 || (lunroll
= tree_to_shwi (expr
)) < 0
11057 || lunroll
>= USHRT_MAX
)
11059 error_at (location
, "%<#pragma GCC unroll%> requires an"
11060 " assignment-expression that evaluates to a non-negative"
11061 " integral constant less than %u", USHRT_MAX
);
11066 unroll
= (unsigned short)lunroll
;
11071 c_parser_skip_to_pragma_eol (parser
);
11075 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
11076 should be considered, statements. ALLOW_STMT is true if we're within
11077 the context of a function and such pragmas are to be allowed. Returns
11078 true if we actually parsed such a pragma. */
11081 c_parser_pragma (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
11084 const char *construct
= NULL
;
11086 id
= c_parser_peek_token (parser
)->pragma_kind
;
11087 gcc_assert (id
!= PRAGMA_NONE
);
11091 case PRAGMA_OACC_DECLARE
:
11092 c_parser_oacc_declare (parser
);
11095 case PRAGMA_OACC_ENTER_DATA
:
11096 if (context
!= pragma_compound
)
11098 construct
= "acc enter data";
11100 if (context
== pragma_stmt
)
11102 error_at (c_parser_peek_token (parser
)->location
,
11103 "%<#pragma %s%> may only be used in compound "
11104 "statements", construct
);
11105 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11110 c_parser_oacc_enter_exit_data (parser
, true);
11113 case PRAGMA_OACC_EXIT_DATA
:
11114 if (context
!= pragma_compound
)
11116 construct
= "acc exit data";
11119 c_parser_oacc_enter_exit_data (parser
, false);
11122 case PRAGMA_OACC_ROUTINE
:
11123 if (context
!= pragma_external
)
11125 error_at (c_parser_peek_token (parser
)->location
,
11126 "%<#pragma acc routine%> must be at file scope");
11127 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11130 c_parser_oacc_routine (parser
, context
);
11133 case PRAGMA_OACC_UPDATE
:
11134 if (context
!= pragma_compound
)
11136 construct
= "acc update";
11139 c_parser_oacc_update (parser
);
11142 case PRAGMA_OMP_BARRIER
:
11143 if (context
!= pragma_compound
)
11145 construct
= "omp barrier";
11148 c_parser_omp_barrier (parser
);
11151 case PRAGMA_OMP_FLUSH
:
11152 if (context
!= pragma_compound
)
11154 construct
= "omp flush";
11157 c_parser_omp_flush (parser
);
11160 case PRAGMA_OMP_TASKWAIT
:
11161 if (context
!= pragma_compound
)
11163 construct
= "omp taskwait";
11166 c_parser_omp_taskwait (parser
);
11169 case PRAGMA_OMP_TASKYIELD
:
11170 if (context
!= pragma_compound
)
11172 construct
= "omp taskyield";
11175 c_parser_omp_taskyield (parser
);
11178 case PRAGMA_OMP_CANCEL
:
11179 if (context
!= pragma_compound
)
11181 construct
= "omp cancel";
11184 c_parser_omp_cancel (parser
);
11187 case PRAGMA_OMP_CANCELLATION_POINT
:
11188 c_parser_omp_cancellation_point (parser
, context
);
11191 case PRAGMA_OMP_THREADPRIVATE
:
11192 c_parser_omp_threadprivate (parser
);
11195 case PRAGMA_OMP_TARGET
:
11196 return c_parser_omp_target (parser
, context
, if_p
);
11198 case PRAGMA_OMP_END_DECLARE_TARGET
:
11199 c_parser_omp_end_declare_target (parser
);
11202 case PRAGMA_OMP_SECTION
:
11203 error_at (c_parser_peek_token (parser
)->location
,
11204 "%<#pragma omp section%> may only be used in "
11205 "%<#pragma omp sections%> construct");
11206 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11209 case PRAGMA_OMP_DECLARE
:
11210 c_parser_omp_declare (parser
, context
);
11213 case PRAGMA_OMP_ORDERED
:
11214 return c_parser_omp_ordered (parser
, context
, if_p
);
11218 const bool ivdep
= c_parse_pragma_ivdep (parser
);
11219 unsigned short unroll
;
11220 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_UNROLL
)
11221 unroll
= c_parser_pragma_unroll (parser
);
11224 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
11225 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
11226 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
11228 c_parser_error (parser
, "for, while or do statement expected");
11231 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11232 c_parser_for_statement (parser
, ivdep
, unroll
, if_p
);
11233 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
11234 c_parser_while_statement (parser
, ivdep
, unroll
, if_p
);
11236 c_parser_do_statement (parser
, ivdep
, unroll
);
11240 case PRAGMA_UNROLL
:
11242 unsigned short unroll
= c_parser_pragma_unroll (parser
);
11244 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_IVDEP
)
11245 ivdep
= c_parse_pragma_ivdep (parser
);
11248 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
11249 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
11250 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
11252 c_parser_error (parser
, "for, while or do statement expected");
11255 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11256 c_parser_for_statement (parser
, ivdep
, unroll
, if_p
);
11257 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
11258 c_parser_while_statement (parser
, ivdep
, unroll
, if_p
);
11260 c_parser_do_statement (parser
, ivdep
, unroll
);
11264 case PRAGMA_GCC_PCH_PREPROCESS
:
11265 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
11266 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11269 case PRAGMA_OACC_WAIT
:
11270 if (context
!= pragma_compound
)
11272 construct
= "acc wait";
11275 /* FALL THROUGH. */
11278 if (id
< PRAGMA_FIRST_EXTERNAL
)
11280 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
11283 c_parser_error (parser
, "expected declaration specifiers");
11284 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11287 c_parser_omp_construct (parser
, if_p
);
11293 c_parser_consume_pragma (parser
);
11294 c_invoke_pragma_handler (id
);
11296 /* Skip to EOL, but suppress any error message. Those will have been
11297 generated by the handler routine through calling error, as opposed
11298 to calling c_parser_error. */
11299 parser
->error
= true;
11300 c_parser_skip_to_pragma_eol (parser
);
11305 /* The interface the pragma parsers have to the lexer. */
11308 pragma_lex (tree
*value
, location_t
*loc
)
11310 c_token
*tok
= c_parser_peek_token (the_parser
);
11311 enum cpp_ttype ret
= tok
->type
;
11313 *value
= tok
->value
;
11315 *loc
= tok
->location
;
11317 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
11321 if (ret
== CPP_KEYWORD
)
11323 c_parser_consume_token (the_parser
);
11330 c_parser_pragma_pch_preprocess (c_parser
*parser
)
11334 c_parser_consume_pragma (parser
);
11335 if (c_parser_next_token_is (parser
, CPP_STRING
))
11337 name
= c_parser_peek_token (parser
)->value
;
11338 c_parser_consume_token (parser
);
11341 c_parser_error (parser
, "expected string literal");
11342 c_parser_skip_to_pragma_eol (parser
);
11345 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
11348 /* OpenACC and OpenMP parsing routines. */
11350 /* Returns name of the next clause.
11351 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
11352 the token is not consumed. Otherwise appropriate pragma_omp_clause is
11353 returned and the token is consumed. */
11355 static pragma_omp_clause
11356 c_parser_omp_clause_name (c_parser
*parser
)
11358 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
11360 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
11361 result
= PRAGMA_OACC_CLAUSE_AUTO
;
11362 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
11363 result
= PRAGMA_OMP_CLAUSE_IF
;
11364 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
11365 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
11366 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11367 result
= PRAGMA_OMP_CLAUSE_FOR
;
11368 else if (c_parser_next_token_is (parser
, CPP_NAME
))
11370 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11375 if (!strcmp ("aligned", p
))
11376 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
11377 else if (!strcmp ("async", p
))
11378 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
11381 if (!strcmp ("collapse", p
))
11382 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
11383 else if (!strcmp ("copy", p
))
11384 result
= PRAGMA_OACC_CLAUSE_COPY
;
11385 else if (!strcmp ("copyin", p
))
11386 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
11387 else if (!strcmp ("copyout", p
))
11388 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
11389 else if (!strcmp ("copyprivate", p
))
11390 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
11391 else if (!strcmp ("create", p
))
11392 result
= PRAGMA_OACC_CLAUSE_CREATE
;
11395 if (!strcmp ("defaultmap", p
))
11396 result
= PRAGMA_OMP_CLAUSE_DEFAULTMAP
;
11397 else if (!strcmp ("delete", p
))
11398 result
= PRAGMA_OACC_CLAUSE_DELETE
;
11399 else if (!strcmp ("depend", p
))
11400 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
11401 else if (!strcmp ("device", p
))
11402 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
11403 else if (!strcmp ("deviceptr", p
))
11404 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
11405 else if (!strcmp ("device_resident", p
))
11406 result
= PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
;
11407 else if (!strcmp ("dist_schedule", p
))
11408 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
11411 if (!strcmp ("final", p
))
11412 result
= PRAGMA_OMP_CLAUSE_FINAL
;
11413 else if (!strcmp ("finalize", p
))
11414 result
= PRAGMA_OACC_CLAUSE_FINALIZE
;
11415 else if (!strcmp ("firstprivate", p
))
11416 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
11417 else if (!strcmp ("from", p
))
11418 result
= PRAGMA_OMP_CLAUSE_FROM
;
11421 if (!strcmp ("gang", p
))
11422 result
= PRAGMA_OACC_CLAUSE_GANG
;
11423 else if (!strcmp ("grainsize", p
))
11424 result
= PRAGMA_OMP_CLAUSE_GRAINSIZE
;
11427 if (!strcmp ("hint", p
))
11428 result
= PRAGMA_OMP_CLAUSE_HINT
;
11429 else if (!strcmp ("host", p
))
11430 result
= PRAGMA_OACC_CLAUSE_HOST
;
11433 if (!strcmp ("if_present", p
))
11434 result
= PRAGMA_OACC_CLAUSE_IF_PRESENT
;
11435 else if (!strcmp ("inbranch", p
))
11436 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
11437 else if (!strcmp ("independent", p
))
11438 result
= PRAGMA_OACC_CLAUSE_INDEPENDENT
;
11439 else if (!strcmp ("is_device_ptr", p
))
11440 result
= PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
;
11443 if (!strcmp ("lastprivate", p
))
11444 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
11445 else if (!strcmp ("linear", p
))
11446 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
11447 else if (!strcmp ("link", p
))
11448 result
= PRAGMA_OMP_CLAUSE_LINK
;
11451 if (!strcmp ("map", p
))
11452 result
= PRAGMA_OMP_CLAUSE_MAP
;
11453 else if (!strcmp ("mergeable", p
))
11454 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
11457 if (!strcmp ("nogroup", p
))
11458 result
= PRAGMA_OMP_CLAUSE_NOGROUP
;
11459 else if (!strcmp ("notinbranch", p
))
11460 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
11461 else if (!strcmp ("nowait", p
))
11462 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
11463 else if (!strcmp ("num_gangs", p
))
11464 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
11465 else if (!strcmp ("num_tasks", p
))
11466 result
= PRAGMA_OMP_CLAUSE_NUM_TASKS
;
11467 else if (!strcmp ("num_teams", p
))
11468 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
11469 else if (!strcmp ("num_threads", p
))
11470 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
11471 else if (!strcmp ("num_workers", p
))
11472 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
11475 if (!strcmp ("ordered", p
))
11476 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
11479 if (!strcmp ("parallel", p
))
11480 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
11481 else if (!strcmp ("present", p
))
11482 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
11483 /* As of OpenACC 2.5, these are now aliases of the non-present_or
11485 else if (!strcmp ("present_or_copy", p
)
11486 || !strcmp ("pcopy", p
))
11487 result
= PRAGMA_OACC_CLAUSE_COPY
;
11488 else if (!strcmp ("present_or_copyin", p
)
11489 || !strcmp ("pcopyin", p
))
11490 result
= PRAGMA_OACC_CLAUSE_COPYIN
;
11491 else if (!strcmp ("present_or_copyout", p
)
11492 || !strcmp ("pcopyout", p
))
11493 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
11494 else if (!strcmp ("present_or_create", p
)
11495 || !strcmp ("pcreate", p
))
11496 result
= PRAGMA_OACC_CLAUSE_CREATE
;
11497 else if (!strcmp ("priority", p
))
11498 result
= PRAGMA_OMP_CLAUSE_PRIORITY
;
11499 else if (!strcmp ("private", p
))
11500 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
11501 else if (!strcmp ("proc_bind", p
))
11502 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
11505 if (!strcmp ("reduction", p
))
11506 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
11509 if (!strcmp ("safelen", p
))
11510 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
11511 else if (!strcmp ("schedule", p
))
11512 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
11513 else if (!strcmp ("sections", p
))
11514 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
11515 else if (!strcmp ("self", p
)) /* "self" is a synonym for "host". */
11516 result
= PRAGMA_OACC_CLAUSE_HOST
;
11517 else if (!strcmp ("seq", p
))
11518 result
= PRAGMA_OACC_CLAUSE_SEQ
;
11519 else if (!strcmp ("shared", p
))
11520 result
= PRAGMA_OMP_CLAUSE_SHARED
;
11521 else if (!strcmp ("simd", p
))
11522 result
= PRAGMA_OMP_CLAUSE_SIMD
;
11523 else if (!strcmp ("simdlen", p
))
11524 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
11527 if (!strcmp ("taskgroup", p
))
11528 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
11529 else if (!strcmp ("thread_limit", p
))
11530 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
11531 else if (!strcmp ("threads", p
))
11532 result
= PRAGMA_OMP_CLAUSE_THREADS
;
11533 else if (!strcmp ("tile", p
))
11534 result
= PRAGMA_OACC_CLAUSE_TILE
;
11535 else if (!strcmp ("to", p
))
11536 result
= PRAGMA_OMP_CLAUSE_TO
;
11539 if (!strcmp ("uniform", p
))
11540 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
11541 else if (!strcmp ("untied", p
))
11542 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
11543 else if (!strcmp ("use_device", p
))
11544 result
= PRAGMA_OACC_CLAUSE_USE_DEVICE
;
11545 else if (!strcmp ("use_device_ptr", p
))
11546 result
= PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
;
11549 if (!strcmp ("vector", p
))
11550 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
11551 else if (!strcmp ("vector_length", p
))
11552 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
11555 if (!strcmp ("wait", p
))
11556 result
= PRAGMA_OACC_CLAUSE_WAIT
;
11557 else if (!strcmp ("worker", p
))
11558 result
= PRAGMA_OACC_CLAUSE_WORKER
;
11563 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
11564 c_parser_consume_token (parser
);
11569 /* Validate that a clause of the given type does not already exist. */
11572 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
11577 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11578 if (OMP_CLAUSE_CODE (c
) == code
)
11580 location_t loc
= OMP_CLAUSE_LOCATION (c
);
11581 error_at (loc
, "too many %qs clauses", name
);
11587 Parse wait clause or wait directive parameters. */
11590 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
11592 vec
<tree
, va_gc
> *args
;
11595 matching_parens parens
;
11596 if (!parens
.require_open (parser
))
11599 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
11601 if (args
->length () == 0)
11603 c_parser_error (parser
, "expected integer expression before ')'");
11604 release_tree_vector (args
);
11608 args_tree
= build_tree_list_vec (args
);
11610 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
11612 tree targ
= TREE_VALUE (t
);
11614 if (targ
!= error_mark_node
)
11616 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
11618 c_parser_error (parser
, "expression must be integral");
11619 targ
= error_mark_node
;
11623 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
11625 OMP_CLAUSE_DECL (c
) = targ
;
11626 OMP_CLAUSE_CHAIN (c
) = list
;
11632 release_tree_vector (args
);
11633 parens
.require_close (parser
);
11637 /* OpenACC 2.0, OpenMP 2.5:
11640 variable-list , identifier
11642 If KIND is nonzero, create the appropriate node and install the
11643 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
11644 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
11646 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
11647 return the list created. */
11650 c_parser_omp_variable_list (c_parser
*parser
,
11651 location_t clause_loc
,
11652 enum omp_clause_code kind
, tree list
)
11654 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
11655 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
11656 c_parser_error (parser
, "expected identifier");
11658 while (c_parser_next_token_is (parser
, CPP_NAME
)
11659 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
11661 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
11663 if (t
== NULL_TREE
)
11665 undeclared_variable (c_parser_peek_token (parser
)->location
,
11666 c_parser_peek_token (parser
)->value
);
11667 t
= error_mark_node
;
11670 c_parser_consume_token (parser
);
11672 if (t
== error_mark_node
)
11674 else if (kind
!= 0)
11678 case OMP_CLAUSE__CACHE_
:
11679 /* The OpenACC cache directive explicitly only allows "array
11680 elements or subarrays". */
11681 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
11683 c_parser_error (parser
, "expected %<[%>");
11684 t
= error_mark_node
;
11688 case OMP_CLAUSE_MAP
:
11689 case OMP_CLAUSE_FROM
:
11690 case OMP_CLAUSE_TO
:
11691 while (c_parser_next_token_is (parser
, CPP_DOT
))
11693 location_t op_loc
= c_parser_peek_token (parser
)->location
;
11694 c_parser_consume_token (parser
);
11695 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11697 c_parser_error (parser
, "expected identifier");
11698 t
= error_mark_node
;
11702 c_token
*comp_tok
= c_parser_peek_token (parser
);
11703 tree ident
= comp_tok
->value
;
11704 location_t comp_loc
= comp_tok
->location
;
11705 c_parser_consume_token (parser
);
11706 t
= build_component_ref (op_loc
, t
, ident
, comp_loc
);
11709 case OMP_CLAUSE_DEPEND
:
11710 case OMP_CLAUSE_REDUCTION
:
11711 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
11713 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
11715 c_parser_consume_token (parser
);
11716 if (!c_parser_next_token_is (parser
, CPP_COLON
))
11718 location_t expr_loc
11719 = c_parser_peek_token (parser
)->location
;
11720 c_expr expr
= c_parser_expression (parser
);
11721 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
11723 low_bound
= expr
.value
;
11725 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
11726 length
= integer_one_node
;
11729 /* Look for `:'. */
11730 if (!c_parser_require (parser
, CPP_COLON
,
11733 t
= error_mark_node
;
11736 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
11738 location_t expr_loc
11739 = c_parser_peek_token (parser
)->location
;
11740 c_expr expr
= c_parser_expression (parser
);
11741 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
11743 length
= expr
.value
;
11746 /* Look for the closing `]'. */
11747 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
11750 t
= error_mark_node
;
11754 t
= tree_cons (low_bound
, length
, t
);
11761 if (t
!= error_mark_node
)
11763 tree u
= build_omp_clause (clause_loc
, kind
);
11764 OMP_CLAUSE_DECL (u
) = t
;
11765 OMP_CLAUSE_CHAIN (u
) = list
;
11770 list
= tree_cons (t
, NULL_TREE
, list
);
11772 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
11775 c_parser_consume_token (parser
);
11781 /* Similarly, but expect leading and trailing parenthesis. This is a very
11782 common case for OpenACC and OpenMP clauses. */
11785 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
11788 /* The clauses location. */
11789 location_t loc
= c_parser_peek_token (parser
)->location
;
11791 matching_parens parens
;
11792 if (parens
.require_open (parser
))
11794 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
11795 parens
.skip_until_found_close (parser
);
11801 copy ( variable-list )
11802 copyin ( variable-list )
11803 copyout ( variable-list )
11804 create ( variable-list )
11805 delete ( variable-list )
11806 present ( variable-list ) */
11809 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
11812 enum gomp_map_kind kind
;
11815 case PRAGMA_OACC_CLAUSE_COPY
:
11816 kind
= GOMP_MAP_TOFROM
;
11818 case PRAGMA_OACC_CLAUSE_COPYIN
:
11819 kind
= GOMP_MAP_TO
;
11821 case PRAGMA_OACC_CLAUSE_COPYOUT
:
11822 kind
= GOMP_MAP_FROM
;
11824 case PRAGMA_OACC_CLAUSE_CREATE
:
11825 kind
= GOMP_MAP_ALLOC
;
11827 case PRAGMA_OACC_CLAUSE_DELETE
:
11828 kind
= GOMP_MAP_RELEASE
;
11830 case PRAGMA_OACC_CLAUSE_DEVICE
:
11831 kind
= GOMP_MAP_FORCE_TO
;
11833 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
11834 kind
= GOMP_MAP_DEVICE_RESIDENT
;
11836 case PRAGMA_OACC_CLAUSE_HOST
:
11837 kind
= GOMP_MAP_FORCE_FROM
;
11839 case PRAGMA_OACC_CLAUSE_LINK
:
11840 kind
= GOMP_MAP_LINK
;
11842 case PRAGMA_OACC_CLAUSE_PRESENT
:
11843 kind
= GOMP_MAP_FORCE_PRESENT
;
11846 gcc_unreachable ();
11849 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
11851 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11852 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
11858 deviceptr ( variable-list ) */
11861 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
11863 location_t loc
= c_parser_peek_token (parser
)->location
;
11866 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
11867 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
11868 variable-list must only allow for pointer variables. */
11869 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11870 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
11872 tree v
= TREE_PURPOSE (t
);
11874 /* FIXME diagnostics: Ideally we should keep individual
11875 locations for all the variables in the var list to make the
11876 following errors more precise. Perhaps
11877 c_parser_omp_var_list_parens() should construct a list of
11878 locations to go along with the var list. */
11880 if (!VAR_P (v
) && TREE_CODE (v
) != PARM_DECL
)
11881 error_at (loc
, "%qD is not a variable", v
);
11882 else if (TREE_TYPE (v
) == error_mark_node
)
11884 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
11885 error_at (loc
, "%qD is not a pointer variable", v
);
11887 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
11888 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
11889 OMP_CLAUSE_DECL (u
) = v
;
11890 OMP_CLAUSE_CHAIN (u
) = list
;
11897 /* OpenACC 2.0, OpenMP 3.0:
11898 collapse ( constant-expression ) */
11901 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
11903 tree c
, num
= error_mark_node
;
11907 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
11908 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
11910 loc
= c_parser_peek_token (parser
)->location
;
11911 matching_parens parens
;
11912 if (parens
.require_open (parser
))
11914 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
11915 parens
.skip_until_found_close (parser
);
11917 if (num
== error_mark_node
)
11919 mark_exp_read (num
);
11920 num
= c_fully_fold (num
, false, NULL
);
11921 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
11922 || !tree_fits_shwi_p (num
)
11923 || (n
= tree_to_shwi (num
)) <= 0
11927 "collapse argument needs positive constant integer expression");
11930 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
11931 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
11932 OMP_CLAUSE_CHAIN (c
) = list
;
11937 copyin ( variable-list ) */
11940 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
11942 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
11946 copyprivate ( variable-list ) */
11949 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
11951 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
11955 default ( none | shared )
11958 default ( none | present ) */
11961 c_parser_omp_clause_default (c_parser
*parser
, tree list
, bool is_oacc
)
11963 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
11964 location_t loc
= c_parser_peek_token (parser
)->location
;
11967 matching_parens parens
;
11968 if (!parens
.require_open (parser
))
11970 if (c_parser_next_token_is (parser
, CPP_NAME
))
11972 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11977 if (strcmp ("none", p
) != 0)
11979 kind
= OMP_CLAUSE_DEFAULT_NONE
;
11983 if (strcmp ("present", p
) != 0 || !is_oacc
)
11985 kind
= OMP_CLAUSE_DEFAULT_PRESENT
;
11989 if (strcmp ("shared", p
) != 0 || is_oacc
)
11991 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
11998 c_parser_consume_token (parser
);
12004 c_parser_error (parser
, "expected %<none%> or %<present%>");
12006 c_parser_error (parser
, "expected %<none%> or %<shared%>");
12008 parens
.skip_until_found_close (parser
);
12010 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
12013 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
12014 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
12015 OMP_CLAUSE_CHAIN (c
) = list
;
12016 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
12022 firstprivate ( variable-list ) */
12025 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
12027 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
12031 final ( expression ) */
12034 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
12036 location_t loc
= c_parser_peek_token (parser
)->location
;
12037 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12039 tree t
= c_parser_paren_condition (parser
);
12042 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
12044 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
12045 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
12046 OMP_CLAUSE_CHAIN (c
) = list
;
12050 c_parser_error (parser
, "expected %<(%>");
12055 /* OpenACC, OpenMP 2.5:
12059 if ( directive-name-modifier : expression )
12061 directive-name-modifier:
12062 parallel | task | taskloop | target data | target | target update
12063 | target enter data | target exit data */
12066 c_parser_omp_clause_if (c_parser
*parser
, tree list
, bool is_omp
)
12068 location_t location
= c_parser_peek_token (parser
)->location
;
12069 enum tree_code if_modifier
= ERROR_MARK
;
12071 matching_parens parens
;
12072 if (!parens
.require_open (parser
))
12075 if (is_omp
&& c_parser_next_token_is (parser
, CPP_NAME
))
12077 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12079 if (strcmp (p
, "parallel") == 0)
12080 if_modifier
= OMP_PARALLEL
;
12081 else if (strcmp (p
, "task") == 0)
12082 if_modifier
= OMP_TASK
;
12083 else if (strcmp (p
, "taskloop") == 0)
12084 if_modifier
= OMP_TASKLOOP
;
12085 else if (strcmp (p
, "target") == 0)
12087 if_modifier
= OMP_TARGET
;
12088 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12090 p
= IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser
)->value
);
12091 if (strcmp ("data", p
) == 0)
12092 if_modifier
= OMP_TARGET_DATA
;
12093 else if (strcmp ("update", p
) == 0)
12094 if_modifier
= OMP_TARGET_UPDATE
;
12095 else if (strcmp ("enter", p
) == 0)
12096 if_modifier
= OMP_TARGET_ENTER_DATA
;
12097 else if (strcmp ("exit", p
) == 0)
12098 if_modifier
= OMP_TARGET_EXIT_DATA
;
12099 if (if_modifier
!= OMP_TARGET
)
12102 c_parser_consume_token (parser
);
12106 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
12107 error_at (loc
, "expected %<data%>, %<update%>, %<enter%> "
12109 if_modifier
= ERROR_MARK
;
12111 if (if_modifier
== OMP_TARGET_ENTER_DATA
12112 || if_modifier
== OMP_TARGET_EXIT_DATA
)
12114 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
12116 p
= IDENTIFIER_POINTER
12117 (c_parser_peek_2nd_token (parser
)->value
);
12118 if (strcmp ("data", p
) == 0)
12122 c_parser_consume_token (parser
);
12126 = c_parser_peek_2nd_token (parser
)->location
;
12127 error_at (loc
, "expected %<data%>");
12128 if_modifier
= ERROR_MARK
;
12133 if (if_modifier
!= ERROR_MARK
)
12135 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12137 c_parser_consume_token (parser
);
12138 c_parser_consume_token (parser
);
12144 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
12145 error_at (loc
, "expected %<:%>");
12147 if_modifier
= ERROR_MARK
;
12152 tree t
= c_parser_condition (parser
), c
;
12153 parens
.skip_until_found_close (parser
);
12155 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
12156 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IF
)
12158 if (if_modifier
!= ERROR_MARK
12159 && OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
12161 const char *p
= NULL
;
12162 switch (if_modifier
)
12164 case OMP_PARALLEL
: p
= "parallel"; break;
12165 case OMP_TASK
: p
= "task"; break;
12166 case OMP_TASKLOOP
: p
= "taskloop"; break;
12167 case OMP_TARGET_DATA
: p
= "target data"; break;
12168 case OMP_TARGET
: p
= "target"; break;
12169 case OMP_TARGET_UPDATE
: p
= "target update"; break;
12170 case OMP_TARGET_ENTER_DATA
: p
= "enter data"; break;
12171 case OMP_TARGET_EXIT_DATA
: p
= "exit data"; break;
12172 default: gcc_unreachable ();
12174 error_at (location
, "too many %<if%> clauses with %qs modifier",
12178 else if (OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
12181 error_at (location
, "too many %<if%> clauses");
12183 error_at (location
, "too many %<if%> clauses without modifier");
12186 else if (if_modifier
== ERROR_MARK
12187 || OMP_CLAUSE_IF_MODIFIER (c
) == ERROR_MARK
)
12189 error_at (location
, "if any %<if%> clause has modifier, then all "
12190 "%<if%> clauses have to use modifier");
12195 c
= build_omp_clause (location
, OMP_CLAUSE_IF
);
12196 OMP_CLAUSE_IF_MODIFIER (c
) = if_modifier
;
12197 OMP_CLAUSE_IF_EXPR (c
) = t
;
12198 OMP_CLAUSE_CHAIN (c
) = list
;
12203 lastprivate ( variable-list ) */
12206 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
12208 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
12215 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12219 /* FIXME: Should we allow duplicates? */
12220 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
12222 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12223 OMP_CLAUSE_MERGEABLE
);
12224 OMP_CLAUSE_CHAIN (c
) = list
;
12233 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12236 location_t loc
= c_parser_peek_token (parser
)->location
;
12238 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
12240 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
12241 OMP_CLAUSE_CHAIN (c
) = list
;
12246 num_threads ( expression ) */
12249 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
12251 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
12252 matching_parens parens
;
12253 if (parens
.require_open (parser
))
12255 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12256 c_expr expr
= c_parser_expression (parser
);
12257 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12258 tree c
, t
= expr
.value
;
12259 t
= c_fully_fold (t
, false, NULL
);
12261 parens
.skip_until_found_close (parser
);
12263 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12265 c_parser_error (parser
, "expected integer expression");
12269 /* Attempt to statically determine when the number isn't positive. */
12270 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12271 build_int_cst (TREE_TYPE (t
), 0));
12272 protected_set_expr_location (c
, expr_loc
);
12273 if (c
== boolean_true_node
)
12275 warning_at (expr_loc
, 0,
12276 "%<num_threads%> value must be positive");
12277 t
= integer_one_node
;
12280 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
12282 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
12283 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
12284 OMP_CLAUSE_CHAIN (c
) = list
;
12292 num_tasks ( expression ) */
12295 c_parser_omp_clause_num_tasks (c_parser
*parser
, tree list
)
12297 location_t num_tasks_loc
= c_parser_peek_token (parser
)->location
;
12298 matching_parens parens
;
12299 if (parens
.require_open (parser
))
12301 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12302 c_expr expr
= c_parser_expression (parser
);
12303 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12304 tree c
, t
= expr
.value
;
12305 t
= c_fully_fold (t
, false, NULL
);
12307 parens
.skip_until_found_close (parser
);
12309 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12311 c_parser_error (parser
, "expected integer expression");
12315 /* Attempt to statically determine when the number isn't positive. */
12316 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12317 build_int_cst (TREE_TYPE (t
), 0));
12318 if (CAN_HAVE_LOCATION_P (c
))
12319 SET_EXPR_LOCATION (c
, expr_loc
);
12320 if (c
== boolean_true_node
)
12322 warning_at (expr_loc
, 0, "%<num_tasks%> value must be positive");
12323 t
= integer_one_node
;
12326 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TASKS
, "num_tasks");
12328 c
= build_omp_clause (num_tasks_loc
, OMP_CLAUSE_NUM_TASKS
);
12329 OMP_CLAUSE_NUM_TASKS_EXPR (c
) = t
;
12330 OMP_CLAUSE_CHAIN (c
) = list
;
12338 grainsize ( expression ) */
12341 c_parser_omp_clause_grainsize (c_parser
*parser
, tree list
)
12343 location_t grainsize_loc
= c_parser_peek_token (parser
)->location
;
12344 matching_parens parens
;
12345 if (parens
.require_open (parser
))
12347 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12348 c_expr expr
= c_parser_expression (parser
);
12349 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12350 tree c
, t
= expr
.value
;
12351 t
= c_fully_fold (t
, false, NULL
);
12353 parens
.skip_until_found_close (parser
);
12355 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12357 c_parser_error (parser
, "expected integer expression");
12361 /* Attempt to statically determine when the number isn't positive. */
12362 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12363 build_int_cst (TREE_TYPE (t
), 0));
12364 if (CAN_HAVE_LOCATION_P (c
))
12365 SET_EXPR_LOCATION (c
, expr_loc
);
12366 if (c
== boolean_true_node
)
12368 warning_at (expr_loc
, 0, "%<grainsize%> value must be positive");
12369 t
= integer_one_node
;
12372 check_no_duplicate_clause (list
, OMP_CLAUSE_GRAINSIZE
, "grainsize");
12374 c
= build_omp_clause (grainsize_loc
, OMP_CLAUSE_GRAINSIZE
);
12375 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
12376 OMP_CLAUSE_CHAIN (c
) = list
;
12384 priority ( expression ) */
12387 c_parser_omp_clause_priority (c_parser
*parser
, tree list
)
12389 location_t priority_loc
= c_parser_peek_token (parser
)->location
;
12390 matching_parens parens
;
12391 if (parens
.require_open (parser
))
12393 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12394 c_expr expr
= c_parser_expression (parser
);
12395 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12396 tree c
, t
= expr
.value
;
12397 t
= c_fully_fold (t
, false, NULL
);
12399 parens
.skip_until_found_close (parser
);
12401 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12403 c_parser_error (parser
, "expected integer expression");
12407 /* Attempt to statically determine when the number isn't
12409 c
= fold_build2_loc (expr_loc
, LT_EXPR
, boolean_type_node
, t
,
12410 build_int_cst (TREE_TYPE (t
), 0));
12411 if (CAN_HAVE_LOCATION_P (c
))
12412 SET_EXPR_LOCATION (c
, expr_loc
);
12413 if (c
== boolean_true_node
)
12415 warning_at (expr_loc
, 0, "%<priority%> value must be non-negative");
12416 t
= integer_one_node
;
12419 check_no_duplicate_clause (list
, OMP_CLAUSE_PRIORITY
, "priority");
12421 c
= build_omp_clause (priority_loc
, OMP_CLAUSE_PRIORITY
);
12422 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
12423 OMP_CLAUSE_CHAIN (c
) = list
;
12431 hint ( expression ) */
12434 c_parser_omp_clause_hint (c_parser
*parser
, tree list
)
12436 location_t hint_loc
= c_parser_peek_token (parser
)->location
;
12437 matching_parens parens
;
12438 if (parens
.require_open (parser
))
12440 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12441 c_expr expr
= c_parser_expression (parser
);
12442 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12443 tree c
, t
= expr
.value
;
12444 t
= c_fully_fold (t
, false, NULL
);
12446 parens
.skip_until_found_close (parser
);
12448 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12450 c_parser_error (parser
, "expected integer expression");
12454 check_no_duplicate_clause (list
, OMP_CLAUSE_HINT
, "hint");
12456 c
= build_omp_clause (hint_loc
, OMP_CLAUSE_HINT
);
12457 OMP_CLAUSE_HINT_EXPR (c
) = t
;
12458 OMP_CLAUSE_CHAIN (c
) = list
;
12466 defaultmap ( tofrom : scalar ) */
12469 c_parser_omp_clause_defaultmap (c_parser
*parser
, tree list
)
12471 location_t loc
= c_parser_peek_token (parser
)->location
;
12475 matching_parens parens
;
12476 if (!parens
.require_open (parser
))
12478 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12480 c_parser_error (parser
, "expected %<tofrom%>");
12483 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12484 if (strcmp (p
, "tofrom") != 0)
12486 c_parser_error (parser
, "expected %<tofrom%>");
12489 c_parser_consume_token (parser
);
12490 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12492 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12494 c_parser_error (parser
, "expected %<scalar%>");
12497 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12498 if (strcmp (p
, "scalar") != 0)
12500 c_parser_error (parser
, "expected %<scalar%>");
12503 c_parser_consume_token (parser
);
12504 parens
.skip_until_found_close (parser
);
12505 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULTMAP
, "defaultmap");
12506 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULTMAP
);
12507 OMP_CLAUSE_CHAIN (c
) = list
;
12511 parens
.skip_until_found_close (parser
);
12516 use_device ( variable-list )
12519 use_device_ptr ( variable-list ) */
12522 c_parser_omp_clause_use_device_ptr (c_parser
*parser
, tree list
)
12524 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_USE_DEVICE_PTR
,
12529 is_device_ptr ( variable-list ) */
12532 c_parser_omp_clause_is_device_ptr (c_parser
*parser
, tree list
)
12534 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_IS_DEVICE_PTR
, list
);
12538 num_gangs ( expression )
12539 num_workers ( expression )
12540 vector_length ( expression ) */
12543 c_parser_oacc_single_int_clause (c_parser
*parser
, omp_clause_code code
,
12546 location_t loc
= c_parser_peek_token (parser
)->location
;
12548 matching_parens parens
;
12549 if (!parens
.require_open (parser
))
12552 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12553 c_expr expr
= c_parser_expression (parser
);
12554 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12555 tree c
, t
= expr
.value
;
12556 t
= c_fully_fold (t
, false, NULL
);
12558 parens
.skip_until_found_close (parser
);
12560 if (t
== error_mark_node
)
12562 else if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12564 error_at (expr_loc
, "%qs expression must be integral",
12565 omp_clause_code_name
[code
]);
12569 /* Attempt to statically determine when the number isn't positive. */
12570 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12571 build_int_cst (TREE_TYPE (t
), 0));
12572 protected_set_expr_location (c
, expr_loc
);
12573 if (c
== boolean_true_node
)
12575 warning_at (expr_loc
, 0,
12576 "%qs value must be positive",
12577 omp_clause_code_name
[code
]);
12578 t
= integer_one_node
;
12581 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12583 c
= build_omp_clause (loc
, code
);
12584 OMP_CLAUSE_OPERAND (c
, 0) = t
;
12585 OMP_CLAUSE_CHAIN (c
) = list
;
12591 gang [( gang-arg-list )]
12592 worker [( [num:] int-expr )]
12593 vector [( [length:] int-expr )]
12595 where gang-arg is one of:
12600 and size-expr may be:
12607 c_parser_oacc_shape_clause (c_parser
*parser
, omp_clause_code kind
,
12608 const char *str
, tree list
)
12610 const char *id
= "num";
12611 tree ops
[2] = { NULL_TREE
, NULL_TREE
}, c
;
12612 location_t loc
= c_parser_peek_token (parser
)->location
;
12614 if (kind
== OMP_CLAUSE_VECTOR
)
12617 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12619 c_parser_consume_token (parser
);
12623 c_token
*next
= c_parser_peek_token (parser
);
12626 /* Gang static argument. */
12627 if (kind
== OMP_CLAUSE_GANG
12628 && c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12630 c_parser_consume_token (parser
);
12632 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12633 goto cleanup_error
;
12636 if (ops
[idx
] != NULL_TREE
)
12638 c_parser_error (parser
, "too many %<static%> arguments");
12639 goto cleanup_error
;
12642 /* Check for the '*' argument. */
12643 if (c_parser_next_token_is (parser
, CPP_MULT
)
12644 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
12645 || c_parser_peek_2nd_token (parser
)->type
12646 == CPP_CLOSE_PAREN
))
12648 c_parser_consume_token (parser
);
12649 ops
[idx
] = integer_minus_one_node
;
12651 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12653 c_parser_consume_token (parser
);
12660 /* Worker num: argument and vector length: arguments. */
12661 else if (c_parser_next_token_is (parser
, CPP_NAME
)
12662 && strcmp (id
, IDENTIFIER_POINTER (next
->value
)) == 0
12663 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12665 c_parser_consume_token (parser
); /* id */
12666 c_parser_consume_token (parser
); /* ':' */
12669 /* Now collect the actual argument. */
12670 if (ops
[idx
] != NULL_TREE
)
12672 c_parser_error (parser
, "unexpected argument");
12673 goto cleanup_error
;
12676 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12677 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
12678 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
12679 tree expr
= cexpr
.value
;
12680 if (expr
== error_mark_node
)
12681 goto cleanup_error
;
12683 expr
= c_fully_fold (expr
, false, NULL
);
12685 /* Attempt to statically determine when the number isn't a
12686 positive integer. */
12688 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
12690 c_parser_error (parser
, "expected integer expression");
12694 tree c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
12695 build_int_cst (TREE_TYPE (expr
), 0));
12696 if (c
== boolean_true_node
)
12698 warning_at (loc
, 0,
12699 "%qs value must be positive", str
);
12700 expr
= integer_one_node
;
12705 if (kind
== OMP_CLAUSE_GANG
12706 && c_parser_next_token_is (parser
, CPP_COMMA
))
12708 c_parser_consume_token (parser
);
12715 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12716 goto cleanup_error
;
12719 check_no_duplicate_clause (list
, kind
, str
);
12721 c
= build_omp_clause (loc
, kind
);
12724 OMP_CLAUSE_OPERAND (c
, 1) = ops
[1];
12726 OMP_CLAUSE_OPERAND (c
, 0) = ops
[0];
12727 OMP_CLAUSE_CHAIN (c
) = list
;
12732 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12744 c_parser_oacc_simple_clause (c_parser
*parser
, enum omp_clause_code code
,
12747 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12749 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12750 OMP_CLAUSE_CHAIN (c
) = list
;
12756 async [( int-expr )] */
12759 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
12762 location_t loc
= c_parser_peek_token (parser
)->location
;
12764 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
12766 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12768 c_parser_consume_token (parser
);
12770 t
= c_parser_expression (parser
).value
;
12771 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12772 c_parser_error (parser
, "expected integer expression");
12773 else if (t
== error_mark_node
12774 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12778 t
= c_fully_fold (t
, false, NULL
);
12780 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
12782 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
12783 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
12784 OMP_CLAUSE_CHAIN (c
) = list
;
12791 tile ( size-expr-list ) */
12794 c_parser_oacc_clause_tile (c_parser
*parser
, tree list
)
12796 tree c
, expr
= error_mark_node
;
12798 tree tile
= NULL_TREE
;
12800 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
12801 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
12803 loc
= c_parser_peek_token (parser
)->location
;
12804 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12809 if (tile
&& !c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
12812 if (c_parser_next_token_is (parser
, CPP_MULT
)
12813 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
12814 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
12816 c_parser_consume_token (parser
);
12817 expr
= integer_zero_node
;
12821 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12822 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
12823 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
12824 expr
= cexpr
.value
;
12826 if (expr
== error_mark_node
)
12828 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12833 expr
= c_fully_fold (expr
, false, NULL
);
12835 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
12836 || !tree_fits_shwi_p (expr
)
12837 || tree_to_shwi (expr
) <= 0)
12839 error_at (expr_loc
, "%<tile%> argument needs positive"
12840 " integral constant");
12841 expr
= integer_zero_node
;
12845 tile
= tree_cons (NULL_TREE
, expr
, tile
);
12847 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
));
12849 /* Consume the trailing ')'. */
12850 c_parser_consume_token (parser
);
12852 c
= build_omp_clause (loc
, OMP_CLAUSE_TILE
);
12853 tile
= nreverse (tile
);
12854 OMP_CLAUSE_TILE_LIST (c
) = tile
;
12855 OMP_CLAUSE_CHAIN (c
) = list
;
12860 wait ( int-expr-list ) */
12863 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
12865 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12867 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12868 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
12877 ordered ( constant-expression ) */
12880 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
12882 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
12884 tree c
, num
= NULL_TREE
;
12886 location_t loc
= c_parser_peek_token (parser
)->location
;
12887 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12889 matching_parens parens
;
12890 parens
.consume_open (parser
);
12891 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
12892 parens
.skip_until_found_close (parser
);
12894 if (num
== error_mark_node
)
12898 mark_exp_read (num
);
12899 num
= c_fully_fold (num
, false, NULL
);
12900 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
12901 || !tree_fits_shwi_p (num
)
12902 || (n
= tree_to_shwi (num
)) <= 0
12905 error_at (loc
, "ordered argument needs positive "
12906 "constant integer expression");
12910 c
= build_omp_clause (loc
, OMP_CLAUSE_ORDERED
);
12911 OMP_CLAUSE_ORDERED_EXPR (c
) = num
;
12912 OMP_CLAUSE_CHAIN (c
) = list
;
12917 private ( variable-list ) */
12920 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
12922 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
12926 reduction ( reduction-operator : variable-list )
12928 reduction-operator:
12929 One of: + * - & ^ | && ||
12933 reduction-operator:
12934 One of: + * - & ^ | && || max min
12938 reduction-operator:
12939 One of: + * - & ^ | && ||
12943 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
12945 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12946 matching_parens parens
;
12947 if (parens
.require_open (parser
))
12949 enum tree_code code
= ERROR_MARK
;
12950 tree reduc_id
= NULL_TREE
;
12952 switch (c_parser_peek_token (parser
)->type
)
12964 code
= BIT_AND_EXPR
;
12967 code
= BIT_XOR_EXPR
;
12970 code
= BIT_IOR_EXPR
;
12973 code
= TRUTH_ANDIF_EXPR
;
12976 code
= TRUTH_ORIF_EXPR
;
12981 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12982 if (strcmp (p
, "min") == 0)
12987 if (strcmp (p
, "max") == 0)
12992 reduc_id
= c_parser_peek_token (parser
)->value
;
12996 c_parser_error (parser
,
12997 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
12998 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
12999 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
13002 c_parser_consume_token (parser
);
13003 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
13004 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13008 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13009 OMP_CLAUSE_REDUCTION
, list
);
13010 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13012 tree d
= OMP_CLAUSE_DECL (c
), type
;
13013 if (TREE_CODE (d
) != TREE_LIST
)
13014 type
= TREE_TYPE (d
);
13019 for (t
= d
; TREE_CODE (t
) == TREE_LIST
; t
= TREE_CHAIN (t
))
13021 type
= TREE_TYPE (t
);
13024 if (TREE_CODE (type
) != POINTER_TYPE
13025 && TREE_CODE (type
) != ARRAY_TYPE
)
13027 type
= TREE_TYPE (type
);
13031 while (TREE_CODE (type
) == ARRAY_TYPE
)
13032 type
= TREE_TYPE (type
);
13033 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
13034 if (code
== ERROR_MARK
13035 || !(INTEGRAL_TYPE_P (type
)
13036 || TREE_CODE (type
) == REAL_TYPE
13037 || TREE_CODE (type
) == COMPLEX_TYPE
))
13038 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
13039 = c_omp_reduction_lookup (reduc_id
,
13040 TYPE_MAIN_VARIANT (type
));
13045 parens
.skip_until_found_close (parser
);
13051 schedule ( schedule-kind )
13052 schedule ( schedule-kind , expression )
13055 static | dynamic | guided | runtime | auto
13058 schedule ( schedule-modifier : schedule-kind )
13059 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
13067 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
13070 location_t loc
= c_parser_peek_token (parser
)->location
;
13071 int modifiers
= 0, nmodifiers
= 0;
13073 matching_parens parens
;
13074 if (!parens
.require_open (parser
))
13077 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
13079 while (c_parser_next_token_is (parser
, CPP_NAME
))
13081 tree kind
= c_parser_peek_token (parser
)->value
;
13082 const char *p
= IDENTIFIER_POINTER (kind
);
13083 if (strcmp ("simd", p
) == 0)
13084 OMP_CLAUSE_SCHEDULE_SIMD (c
) = 1;
13085 else if (strcmp ("monotonic", p
) == 0)
13086 modifiers
|= OMP_CLAUSE_SCHEDULE_MONOTONIC
;
13087 else if (strcmp ("nonmonotonic", p
) == 0)
13088 modifiers
|= OMP_CLAUSE_SCHEDULE_NONMONOTONIC
;
13091 c_parser_consume_token (parser
);
13092 if (nmodifiers
++ == 0
13093 && c_parser_next_token_is (parser
, CPP_COMMA
))
13094 c_parser_consume_token (parser
);
13097 c_parser_require (parser
, CPP_COLON
, "expected %<:%>");
13102 if ((modifiers
& (OMP_CLAUSE_SCHEDULE_MONOTONIC
13103 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
13104 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
13105 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
13107 error_at (loc
, "both %<monotonic%> and %<nonmonotonic%> modifiers "
13112 if (c_parser_next_token_is (parser
, CPP_NAME
))
13114 tree kind
= c_parser_peek_token (parser
)->value
;
13115 const char *p
= IDENTIFIER_POINTER (kind
);
13120 if (strcmp ("dynamic", p
) != 0)
13122 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
13126 if (strcmp ("guided", p
) != 0)
13128 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
13132 if (strcmp ("runtime", p
) != 0)
13134 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
13141 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
13142 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
13143 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
13144 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
13148 c_parser_consume_token (parser
);
13149 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13152 c_parser_consume_token (parser
);
13154 here
= c_parser_peek_token (parser
)->location
;
13155 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13156 expr
= convert_lvalue_to_rvalue (here
, expr
, false, true);
13158 t
= c_fully_fold (t
, false, NULL
);
13160 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
13161 error_at (here
, "schedule %<runtime%> does not take "
13162 "a %<chunk_size%> parameter");
13163 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
13165 "schedule %<auto%> does not take "
13166 "a %<chunk_size%> parameter");
13167 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
13169 /* Attempt to statically determine when the number isn't
13171 tree s
= fold_build2_loc (loc
, LE_EXPR
, boolean_type_node
, t
,
13172 build_int_cst (TREE_TYPE (t
), 0));
13173 protected_set_expr_location (s
, loc
);
13174 if (s
== boolean_true_node
)
13176 warning_at (loc
, 0,
13177 "chunk size value must be positive");
13178 t
= integer_one_node
;
13180 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
13183 c_parser_error (parser
, "expected integer expression");
13185 parens
.skip_until_found_close (parser
);
13188 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13189 "expected %<,%> or %<)%>");
13191 OMP_CLAUSE_SCHEDULE_KIND (c
)
13192 = (enum omp_clause_schedule_kind
)
13193 (OMP_CLAUSE_SCHEDULE_KIND (c
) | modifiers
);
13195 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
13196 OMP_CLAUSE_CHAIN (c
) = list
;
13200 c_parser_error (parser
, "invalid schedule kind");
13201 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
13206 shared ( variable-list ) */
13209 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
13211 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
13218 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
13222 /* FIXME: Should we allow duplicates? */
13223 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
13225 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
13226 OMP_CLAUSE_UNTIED
);
13227 OMP_CLAUSE_CHAIN (c
) = list
;
13237 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
13238 enum omp_clause_code code
, tree list
)
13240 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
13242 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13243 OMP_CLAUSE_CHAIN (c
) = list
;
13255 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
13256 enum omp_clause_code code
, tree list
)
13258 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13259 OMP_CLAUSE_CHAIN (c
) = list
;
13268 c_parser_omp_clause_nogroup (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
13270 check_no_duplicate_clause (list
, OMP_CLAUSE_NOGROUP
, "nogroup");
13271 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
13272 OMP_CLAUSE_NOGROUP
);
13273 OMP_CLAUSE_CHAIN (c
) = list
;
13282 c_parser_omp_clause_orderedkind (c_parser
*parser ATTRIBUTE_UNUSED
,
13283 enum omp_clause_code code
, tree list
)
13285 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
13286 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13287 OMP_CLAUSE_CHAIN (c
) = list
;
13292 num_teams ( expression ) */
13295 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
13297 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
13298 matching_parens parens
;
13299 if (parens
.require_open (parser
))
13301 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13302 c_expr expr
= c_parser_expression (parser
);
13303 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13304 tree c
, t
= expr
.value
;
13305 t
= c_fully_fold (t
, false, NULL
);
13307 parens
.skip_until_found_close (parser
);
13309 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13311 c_parser_error (parser
, "expected integer expression");
13315 /* Attempt to statically determine when the number isn't positive. */
13316 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13317 build_int_cst (TREE_TYPE (t
), 0));
13318 protected_set_expr_location (c
, expr_loc
);
13319 if (c
== boolean_true_node
)
13321 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
13322 t
= integer_one_node
;
13325 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
13327 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
13328 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
13329 OMP_CLAUSE_CHAIN (c
) = list
;
13337 thread_limit ( expression ) */
13340 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
13342 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
13343 matching_parens parens
;
13344 if (parens
.require_open (parser
))
13346 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13347 c_expr expr
= c_parser_expression (parser
);
13348 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13349 tree c
, t
= expr
.value
;
13350 t
= c_fully_fold (t
, false, NULL
);
13352 parens
.skip_until_found_close (parser
);
13354 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13356 c_parser_error (parser
, "expected integer expression");
13360 /* Attempt to statically determine when the number isn't positive. */
13361 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13362 build_int_cst (TREE_TYPE (t
), 0));
13363 protected_set_expr_location (c
, expr_loc
);
13364 if (c
== boolean_true_node
)
13366 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
13367 t
= integer_one_node
;
13370 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
13373 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
13374 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
13375 OMP_CLAUSE_CHAIN (c
) = list
;
13383 aligned ( variable-list )
13384 aligned ( variable-list : constant-expression ) */
13387 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
13389 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13392 matching_parens parens
;
13393 if (!parens
.require_open (parser
))
13396 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13397 OMP_CLAUSE_ALIGNED
, list
);
13399 if (c_parser_next_token_is (parser
, CPP_COLON
))
13401 c_parser_consume_token (parser
);
13402 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13403 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13404 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13405 tree alignment
= expr
.value
;
13406 alignment
= c_fully_fold (alignment
, false, NULL
);
13407 if (TREE_CODE (alignment
) != INTEGER_CST
13408 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
13409 || tree_int_cst_sgn (alignment
) != 1)
13411 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
13412 "be positive constant integer expression");
13413 alignment
= NULL_TREE
;
13416 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13417 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
13420 parens
.skip_until_found_close (parser
);
13425 linear ( variable-list )
13426 linear ( variable-list : expression )
13429 linear ( modifier ( variable-list ) )
13430 linear ( modifier ( variable-list ) : expression ) */
13433 c_parser_omp_clause_linear (c_parser
*parser
, tree list
)
13435 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13437 enum omp_clause_linear_kind kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
13439 matching_parens parens
;
13440 if (!parens
.require_open (parser
))
13443 if (c_parser_next_token_is (parser
, CPP_NAME
))
13445 c_token
*tok
= c_parser_peek_token (parser
);
13446 const char *p
= IDENTIFIER_POINTER (tok
->value
);
13447 if (strcmp ("val", p
) == 0)
13448 kind
= OMP_CLAUSE_LINEAR_VAL
;
13449 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
)
13450 kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
13451 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
13453 c_parser_consume_token (parser
);
13454 c_parser_consume_token (parser
);
13458 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13459 OMP_CLAUSE_LINEAR
, list
);
13461 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
13462 parens
.skip_until_found_close (parser
);
13464 if (c_parser_next_token_is (parser
, CPP_COLON
))
13466 c_parser_consume_token (parser
);
13467 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13468 c_expr expr
= c_parser_expression (parser
);
13469 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13471 step
= c_fully_fold (step
, false, NULL
);
13472 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
13474 error_at (clause_loc
, "%<linear%> clause step expression must "
13476 step
= integer_one_node
;
13481 step
= integer_one_node
;
13483 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13485 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
13486 OMP_CLAUSE_LINEAR_KIND (c
) = kind
;
13489 parens
.skip_until_found_close (parser
);
13494 safelen ( constant-expression ) */
13497 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
13499 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13502 matching_parens parens
;
13503 if (!parens
.require_open (parser
))
13506 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13507 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13508 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13510 t
= c_fully_fold (t
, false, NULL
);
13511 if (TREE_CODE (t
) != INTEGER_CST
13512 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
13513 || tree_int_cst_sgn (t
) != 1)
13515 error_at (clause_loc
, "%<safelen%> clause expression must "
13516 "be positive constant integer expression");
13520 parens
.skip_until_found_close (parser
);
13521 if (t
== NULL_TREE
|| t
== error_mark_node
)
13524 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
13526 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
13527 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
13528 OMP_CLAUSE_CHAIN (c
) = list
;
13533 simdlen ( constant-expression ) */
13536 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
13538 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13541 matching_parens parens
;
13542 if (!parens
.require_open (parser
))
13545 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13546 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13547 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13549 t
= c_fully_fold (t
, false, NULL
);
13550 if (TREE_CODE (t
) != INTEGER_CST
13551 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
13552 || tree_int_cst_sgn (t
) != 1)
13554 error_at (clause_loc
, "%<simdlen%> clause expression must "
13555 "be positive constant integer expression");
13559 parens
.skip_until_found_close (parser
);
13560 if (t
== NULL_TREE
|| t
== error_mark_node
)
13563 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
13565 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
13566 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
13567 OMP_CLAUSE_CHAIN (c
) = list
;
13573 identifier [+/- integer]
13574 vec , identifier [+/- integer]
13578 c_parser_omp_clause_depend_sink (c_parser
*parser
, location_t clause_loc
,
13582 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
13583 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13585 c_parser_error (parser
, "expected identifier");
13589 while (c_parser_next_token_is (parser
, CPP_NAME
)
13590 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
13592 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
13593 tree addend
= NULL
;
13595 if (t
== NULL_TREE
)
13597 undeclared_variable (c_parser_peek_token (parser
)->location
,
13598 c_parser_peek_token (parser
)->value
);
13599 t
= error_mark_node
;
13602 c_parser_consume_token (parser
);
13605 if (c_parser_next_token_is (parser
, CPP_MINUS
))
13607 else if (!c_parser_next_token_is (parser
, CPP_PLUS
))
13609 addend
= integer_zero_node
;
13611 goto add_to_vector
;
13613 c_parser_consume_token (parser
);
13615 if (c_parser_next_token_is_not (parser
, CPP_NUMBER
))
13617 c_parser_error (parser
, "expected integer");
13621 addend
= c_parser_peek_token (parser
)->value
;
13622 if (TREE_CODE (addend
) != INTEGER_CST
)
13624 c_parser_error (parser
, "expected integer");
13627 c_parser_consume_token (parser
);
13630 if (t
!= error_mark_node
)
13632 vec
= tree_cons (addend
, t
, vec
);
13634 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec
) = 1;
13637 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
13640 c_parser_consume_token (parser
);
13643 if (vec
== NULL_TREE
)
13646 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
13647 OMP_CLAUSE_DEPEND_KIND (u
) = OMP_CLAUSE_DEPEND_SINK
;
13648 OMP_CLAUSE_DECL (u
) = nreverse (vec
);
13649 OMP_CLAUSE_CHAIN (u
) = list
;
13654 depend ( depend-kind: variable-list )
13662 depend ( sink : vec ) */
13665 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
13667 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13668 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
13671 matching_parens parens
;
13672 if (!parens
.require_open (parser
))
13675 if (c_parser_next_token_is (parser
, CPP_NAME
))
13677 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13678 if (strcmp ("in", p
) == 0)
13679 kind
= OMP_CLAUSE_DEPEND_IN
;
13680 else if (strcmp ("inout", p
) == 0)
13681 kind
= OMP_CLAUSE_DEPEND_INOUT
;
13682 else if (strcmp ("out", p
) == 0)
13683 kind
= OMP_CLAUSE_DEPEND_OUT
;
13684 else if (strcmp ("source", p
) == 0)
13685 kind
= OMP_CLAUSE_DEPEND_SOURCE
;
13686 else if (strcmp ("sink", p
) == 0)
13687 kind
= OMP_CLAUSE_DEPEND_SINK
;
13694 c_parser_consume_token (parser
);
13696 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
13698 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
13699 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
13700 OMP_CLAUSE_DECL (c
) = NULL_TREE
;
13701 OMP_CLAUSE_CHAIN (c
) = list
;
13702 parens
.skip_until_found_close (parser
);
13706 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13709 if (kind
== OMP_CLAUSE_DEPEND_SINK
)
13710 nl
= c_parser_omp_clause_depend_sink (parser
, clause_loc
, list
);
13713 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13714 OMP_CLAUSE_DEPEND
, list
);
13716 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13717 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
13720 parens
.skip_until_found_close (parser
);
13724 c_parser_error (parser
, "invalid depend kind");
13726 parens
.skip_until_found_close (parser
);
13731 map ( map-kind: variable-list )
13732 map ( variable-list )
13735 alloc | to | from | tofrom
13739 alloc | to | from | tofrom | release | delete
13741 map ( always [,] map-kind: variable-list ) */
13744 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
13746 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13747 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
13749 enum c_id_kind always_id_kind
= C_ID_NONE
;
13750 location_t always_loc
= UNKNOWN_LOCATION
;
13751 tree always_id
= NULL_TREE
;
13754 matching_parens parens
;
13755 if (!parens
.require_open (parser
))
13758 if (c_parser_next_token_is (parser
, CPP_NAME
))
13760 c_token
*tok
= c_parser_peek_token (parser
);
13761 const char *p
= IDENTIFIER_POINTER (tok
->value
);
13762 always_id_kind
= tok
->id_kind
;
13763 always_loc
= tok
->location
;
13764 always_id
= tok
->value
;
13765 if (strcmp ("always", p
) == 0)
13767 c_token
*sectok
= c_parser_peek_2nd_token (parser
);
13768 if (sectok
->type
== CPP_COMMA
)
13770 c_parser_consume_token (parser
);
13771 c_parser_consume_token (parser
);
13774 else if (sectok
->type
== CPP_NAME
)
13776 p
= IDENTIFIER_POINTER (sectok
->value
);
13777 if (strcmp ("alloc", p
) == 0
13778 || strcmp ("to", p
) == 0
13779 || strcmp ("from", p
) == 0
13780 || strcmp ("tofrom", p
) == 0
13781 || strcmp ("release", p
) == 0
13782 || strcmp ("delete", p
) == 0)
13784 c_parser_consume_token (parser
);
13791 if (c_parser_next_token_is (parser
, CPP_NAME
)
13792 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13794 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13795 if (strcmp ("alloc", p
) == 0)
13796 kind
= GOMP_MAP_ALLOC
;
13797 else if (strcmp ("to", p
) == 0)
13798 kind
= always
? GOMP_MAP_ALWAYS_TO
: GOMP_MAP_TO
;
13799 else if (strcmp ("from", p
) == 0)
13800 kind
= always
? GOMP_MAP_ALWAYS_FROM
: GOMP_MAP_FROM
;
13801 else if (strcmp ("tofrom", p
) == 0)
13802 kind
= always
? GOMP_MAP_ALWAYS_TOFROM
: GOMP_MAP_TOFROM
;
13803 else if (strcmp ("release", p
) == 0)
13804 kind
= GOMP_MAP_RELEASE
;
13805 else if (strcmp ("delete", p
) == 0)
13806 kind
= GOMP_MAP_DELETE
;
13809 c_parser_error (parser
, "invalid map kind");
13810 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13814 c_parser_consume_token (parser
);
13815 c_parser_consume_token (parser
);
13819 if (always_id_kind
!= C_ID_ID
)
13821 c_parser_error (parser
, "expected identifier");
13822 parens
.skip_until_found_close (parser
);
13826 tree t
= lookup_name (always_id
);
13827 if (t
== NULL_TREE
)
13829 undeclared_variable (always_loc
, always_id
);
13830 t
= error_mark_node
;
13832 if (t
!= error_mark_node
)
13834 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_MAP
);
13835 OMP_CLAUSE_DECL (u
) = t
;
13836 OMP_CLAUSE_CHAIN (u
) = list
;
13837 OMP_CLAUSE_SET_MAP_KIND (u
, kind
);
13842 parens
.skip_until_found_close (parser
);
13847 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
13849 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13850 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
13852 parens
.skip_until_found_close (parser
);
13857 device ( expression ) */
13860 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
13862 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13863 matching_parens parens
;
13864 if (parens
.require_open (parser
))
13866 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13867 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13868 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13869 tree c
, t
= expr
.value
;
13870 t
= c_fully_fold (t
, false, NULL
);
13872 parens
.skip_until_found_close (parser
);
13874 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13876 c_parser_error (parser
, "expected integer expression");
13880 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
13882 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
13883 OMP_CLAUSE_DEVICE_ID (c
) = t
;
13884 OMP_CLAUSE_CHAIN (c
) = list
;
13892 dist_schedule ( static )
13893 dist_schedule ( static , expression ) */
13896 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
13898 tree c
, t
= NULL_TREE
;
13899 location_t loc
= c_parser_peek_token (parser
)->location
;
13901 matching_parens parens
;
13902 if (!parens
.require_open (parser
))
13905 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
13907 c_parser_error (parser
, "invalid dist_schedule kind");
13908 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13913 c_parser_consume_token (parser
);
13914 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13916 c_parser_consume_token (parser
);
13918 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13919 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13920 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13922 t
= c_fully_fold (t
, false, NULL
);
13923 parens
.skip_until_found_close (parser
);
13926 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13927 "expected %<,%> or %<)%>");
13929 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
13930 if (t
== error_mark_node
)
13933 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
13934 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
13935 OMP_CLAUSE_CHAIN (c
) = list
;
13940 proc_bind ( proc-bind-kind )
13943 master | close | spread */
13946 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
13948 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13949 enum omp_clause_proc_bind_kind kind
;
13952 matching_parens parens
;
13953 if (!parens
.require_open (parser
))
13956 if (c_parser_next_token_is (parser
, CPP_NAME
))
13958 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13959 if (strcmp ("master", p
) == 0)
13960 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
13961 else if (strcmp ("close", p
) == 0)
13962 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
13963 else if (strcmp ("spread", p
) == 0)
13964 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
13971 c_parser_consume_token (parser
);
13972 parens
.skip_until_found_close (parser
);
13973 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
13974 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
13975 OMP_CLAUSE_CHAIN (c
) = list
;
13979 c_parser_error (parser
, "invalid proc_bind kind");
13980 parens
.skip_until_found_close (parser
);
13985 to ( variable-list ) */
13988 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
13990 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
13994 from ( variable-list ) */
13997 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
13999 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
14003 uniform ( variable-list ) */
14006 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
14008 /* The clauses location. */
14009 location_t loc
= c_parser_peek_token (parser
)->location
;
14011 matching_parens parens
;
14012 if (parens
.require_open (parser
))
14014 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
14016 parens
.skip_until_found_close (parser
);
14021 /* Parse all OpenACC clauses. The set clauses allowed by the directive
14022 is a bitmask in MASK. Return the list of clauses found. */
14025 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
14026 const char *where
, bool finish_p
= true)
14028 tree clauses
= NULL
;
14031 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14034 pragma_omp_clause c_kind
;
14035 const char *c_name
;
14036 tree prev
= clauses
;
14038 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
14039 c_parser_consume_token (parser
);
14041 here
= c_parser_peek_token (parser
)->location
;
14042 c_kind
= c_parser_omp_clause_name (parser
);
14046 case PRAGMA_OACC_CLAUSE_ASYNC
:
14047 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
14050 case PRAGMA_OACC_CLAUSE_AUTO
:
14051 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_AUTO
,
14055 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
14056 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
14057 c_name
= "collapse";
14059 case PRAGMA_OACC_CLAUSE_COPY
:
14060 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14063 case PRAGMA_OACC_CLAUSE_COPYIN
:
14064 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14067 case PRAGMA_OACC_CLAUSE_COPYOUT
:
14068 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14069 c_name
= "copyout";
14071 case PRAGMA_OACC_CLAUSE_CREATE
:
14072 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14075 case PRAGMA_OACC_CLAUSE_DELETE
:
14076 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14079 case PRAGMA_OMP_CLAUSE_DEFAULT
:
14080 clauses
= c_parser_omp_clause_default (parser
, clauses
, true);
14081 c_name
= "default";
14083 case PRAGMA_OACC_CLAUSE_DEVICE
:
14084 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14087 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
14088 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
14089 c_name
= "deviceptr";
14091 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
14092 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14093 c_name
= "device_resident";
14095 case PRAGMA_OACC_CLAUSE_FINALIZE
:
14096 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_FINALIZE
,
14098 c_name
= "finalize";
14100 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
14101 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
14102 c_name
= "firstprivate";
14104 case PRAGMA_OACC_CLAUSE_GANG
:
14106 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_GANG
,
14109 case PRAGMA_OACC_CLAUSE_HOST
:
14110 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14113 case PRAGMA_OACC_CLAUSE_IF
:
14114 clauses
= c_parser_omp_clause_if (parser
, clauses
, false);
14117 case PRAGMA_OACC_CLAUSE_IF_PRESENT
:
14118 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_IF_PRESENT
,
14120 c_name
= "if_present";
14122 case PRAGMA_OACC_CLAUSE_INDEPENDENT
:
14123 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_INDEPENDENT
,
14125 c_name
= "independent";
14127 case PRAGMA_OACC_CLAUSE_LINK
:
14128 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14131 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
14132 clauses
= c_parser_oacc_single_int_clause (parser
,
14133 OMP_CLAUSE_NUM_GANGS
,
14135 c_name
= "num_gangs";
14137 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
14138 clauses
= c_parser_oacc_single_int_clause (parser
,
14139 OMP_CLAUSE_NUM_WORKERS
,
14141 c_name
= "num_workers";
14143 case PRAGMA_OACC_CLAUSE_PRESENT
:
14144 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14145 c_name
= "present";
14147 case PRAGMA_OACC_CLAUSE_PRIVATE
:
14148 clauses
= c_parser_omp_clause_private (parser
, clauses
);
14149 c_name
= "private";
14151 case PRAGMA_OACC_CLAUSE_REDUCTION
:
14152 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
14153 c_name
= "reduction";
14155 case PRAGMA_OACC_CLAUSE_SEQ
:
14156 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_SEQ
,
14160 case PRAGMA_OACC_CLAUSE_TILE
:
14161 clauses
= c_parser_oacc_clause_tile (parser
, clauses
);
14164 case PRAGMA_OACC_CLAUSE_USE_DEVICE
:
14165 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
14166 c_name
= "use_device";
14168 case PRAGMA_OACC_CLAUSE_VECTOR
:
14170 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_VECTOR
,
14173 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
14174 clauses
= c_parser_oacc_single_int_clause (parser
,
14175 OMP_CLAUSE_VECTOR_LENGTH
,
14177 c_name
= "vector_length";
14179 case PRAGMA_OACC_CLAUSE_WAIT
:
14180 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
14183 case PRAGMA_OACC_CLAUSE_WORKER
:
14185 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_WORKER
,
14189 c_parser_error (parser
, "expected %<#pragma acc%> clause");
14195 if (((mask
>> c_kind
) & 1) == 0)
14197 /* Remove the invalid clause(s) from the list to avoid
14198 confusing the rest of the compiler. */
14200 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
14205 c_parser_skip_to_pragma_eol (parser
);
14208 return c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14213 /* Parse all OpenMP clauses. The set clauses allowed by the directive
14214 is a bitmask in MASK. Return the list of clauses found. */
14217 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
14218 const char *where
, bool finish_p
= true)
14220 tree clauses
= NULL
;
14223 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14226 pragma_omp_clause c_kind
;
14227 const char *c_name
;
14228 tree prev
= clauses
;
14230 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
14231 c_parser_consume_token (parser
);
14233 here
= c_parser_peek_token (parser
)->location
;
14234 c_kind
= c_parser_omp_clause_name (parser
);
14238 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
14239 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
14240 c_name
= "collapse";
14242 case PRAGMA_OMP_CLAUSE_COPYIN
:
14243 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
14246 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
14247 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
14248 c_name
= "copyprivate";
14250 case PRAGMA_OMP_CLAUSE_DEFAULT
:
14251 clauses
= c_parser_omp_clause_default (parser
, clauses
, false);
14252 c_name
= "default";
14254 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
14255 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
14256 c_name
= "firstprivate";
14258 case PRAGMA_OMP_CLAUSE_FINAL
:
14259 clauses
= c_parser_omp_clause_final (parser
, clauses
);
14262 case PRAGMA_OMP_CLAUSE_GRAINSIZE
:
14263 clauses
= c_parser_omp_clause_grainsize (parser
, clauses
);
14264 c_name
= "grainsize";
14266 case PRAGMA_OMP_CLAUSE_HINT
:
14267 clauses
= c_parser_omp_clause_hint (parser
, clauses
);
14270 case PRAGMA_OMP_CLAUSE_DEFAULTMAP
:
14271 clauses
= c_parser_omp_clause_defaultmap (parser
, clauses
);
14272 c_name
= "defaultmap";
14274 case PRAGMA_OMP_CLAUSE_IF
:
14275 clauses
= c_parser_omp_clause_if (parser
, clauses
, true);
14278 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
14279 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
14280 c_name
= "lastprivate";
14282 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
14283 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
14284 c_name
= "mergeable";
14286 case PRAGMA_OMP_CLAUSE_NOWAIT
:
14287 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
14290 case PRAGMA_OMP_CLAUSE_NUM_TASKS
:
14291 clauses
= c_parser_omp_clause_num_tasks (parser
, clauses
);
14292 c_name
= "num_tasks";
14294 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
14295 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
14296 c_name
= "num_threads";
14298 case PRAGMA_OMP_CLAUSE_ORDERED
:
14299 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
14300 c_name
= "ordered";
14302 case PRAGMA_OMP_CLAUSE_PRIORITY
:
14303 clauses
= c_parser_omp_clause_priority (parser
, clauses
);
14304 c_name
= "priority";
14306 case PRAGMA_OMP_CLAUSE_PRIVATE
:
14307 clauses
= c_parser_omp_clause_private (parser
, clauses
);
14308 c_name
= "private";
14310 case PRAGMA_OMP_CLAUSE_REDUCTION
:
14311 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
14312 c_name
= "reduction";
14314 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
14315 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
14316 c_name
= "schedule";
14318 case PRAGMA_OMP_CLAUSE_SHARED
:
14319 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
14322 case PRAGMA_OMP_CLAUSE_UNTIED
:
14323 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
14326 case PRAGMA_OMP_CLAUSE_INBRANCH
:
14327 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
14329 c_name
= "inbranch";
14331 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
14332 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
14334 c_name
= "notinbranch";
14336 case PRAGMA_OMP_CLAUSE_PARALLEL
:
14338 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
14340 c_name
= "parallel";
14344 error_at (here
, "%qs must be the first clause of %qs",
14349 case PRAGMA_OMP_CLAUSE_FOR
:
14351 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
14355 goto clause_not_first
;
14357 case PRAGMA_OMP_CLAUSE_SECTIONS
:
14359 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
14361 c_name
= "sections";
14363 goto clause_not_first
;
14365 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
14367 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
14369 c_name
= "taskgroup";
14371 goto clause_not_first
;
14373 case PRAGMA_OMP_CLAUSE_LINK
:
14375 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LINK
, clauses
);
14378 case PRAGMA_OMP_CLAUSE_TO
:
14379 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINK
)) != 0)
14381 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
14384 clauses
= c_parser_omp_clause_to (parser
, clauses
);
14387 case PRAGMA_OMP_CLAUSE_FROM
:
14388 clauses
= c_parser_omp_clause_from (parser
, clauses
);
14391 case PRAGMA_OMP_CLAUSE_UNIFORM
:
14392 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
14393 c_name
= "uniform";
14395 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
14396 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
14397 c_name
= "num_teams";
14399 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
14400 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
14401 c_name
= "thread_limit";
14403 case PRAGMA_OMP_CLAUSE_ALIGNED
:
14404 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
14405 c_name
= "aligned";
14407 case PRAGMA_OMP_CLAUSE_LINEAR
:
14408 clauses
= c_parser_omp_clause_linear (parser
, clauses
);
14411 case PRAGMA_OMP_CLAUSE_DEPEND
:
14412 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
14415 case PRAGMA_OMP_CLAUSE_MAP
:
14416 clauses
= c_parser_omp_clause_map (parser
, clauses
);
14419 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
:
14420 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
14421 c_name
= "use_device_ptr";
14423 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
:
14424 clauses
= c_parser_omp_clause_is_device_ptr (parser
, clauses
);
14425 c_name
= "is_device_ptr";
14427 case PRAGMA_OMP_CLAUSE_DEVICE
:
14428 clauses
= c_parser_omp_clause_device (parser
, clauses
);
14431 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
14432 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
14433 c_name
= "dist_schedule";
14435 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
14436 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
14437 c_name
= "proc_bind";
14439 case PRAGMA_OMP_CLAUSE_SAFELEN
:
14440 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
14441 c_name
= "safelen";
14443 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
14444 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
14445 c_name
= "simdlen";
14447 case PRAGMA_OMP_CLAUSE_NOGROUP
:
14448 clauses
= c_parser_omp_clause_nogroup (parser
, clauses
);
14449 c_name
= "nogroup";
14451 case PRAGMA_OMP_CLAUSE_THREADS
:
14453 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_THREADS
,
14455 c_name
= "threads";
14457 case PRAGMA_OMP_CLAUSE_SIMD
:
14459 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_SIMD
,
14464 c_parser_error (parser
, "expected %<#pragma omp%> clause");
14470 if (((mask
>> c_kind
) & 1) == 0)
14472 /* Remove the invalid clause(s) from the list to avoid
14473 confusing the rest of the compiler. */
14475 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
14480 c_parser_skip_to_pragma_eol (parser
);
14484 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_UNIFORM
)) != 0)
14485 return c_finish_omp_clauses (clauses
, C_ORT_OMP_DECLARE_SIMD
);
14486 return c_finish_omp_clauses (clauses
, C_ORT_OMP
);
14492 /* OpenACC 2.0, OpenMP 2.5:
14496 In practice, we're also interested in adding the statement to an
14497 outer node. So it is convenient if we work around the fact that
14498 c_parser_statement calls add_stmt. */
14501 c_parser_omp_structured_block (c_parser
*parser
, bool *if_p
)
14503 tree stmt
= push_stmt_list ();
14504 c_parser_statement (parser
, if_p
);
14505 return pop_stmt_list (stmt
);
14509 # pragma acc cache (variable-list) new-line
14511 LOC is the location of the #pragma token.
14515 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
14517 tree stmt
, clauses
;
14519 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
14520 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14522 c_parser_skip_to_pragma_eol (parser
);
14524 stmt
= make_node (OACC_CACHE
);
14525 TREE_TYPE (stmt
) = void_type_node
;
14526 OACC_CACHE_CLAUSES (stmt
) = clauses
;
14527 SET_EXPR_LOCATION (stmt
, loc
);
14534 # pragma acc data oacc-data-clause[optseq] new-line
14537 LOC is the location of the #pragma token.
14540 #define OACC_DATA_CLAUSE_MASK \
14541 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14542 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14543 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14544 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14545 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14546 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14547 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT))
14550 c_parser_oacc_data (location_t loc
, c_parser
*parser
, bool *if_p
)
14552 tree stmt
, clauses
, block
;
14554 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
14555 "#pragma acc data");
14557 block
= c_begin_omp_parallel ();
14558 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14560 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
14566 # pragma acc declare oacc-data-clause[optseq] new-line
14569 #define OACC_DECLARE_CLAUSE_MASK \
14570 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14571 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14572 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14573 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14574 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14575 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \
14576 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \
14577 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT))
14580 c_parser_oacc_declare (c_parser
*parser
)
14582 location_t pragma_loc
= c_parser_peek_token (parser
)->location
;
14583 tree clauses
, stmt
, t
, decl
;
14585 bool error
= false;
14587 c_parser_consume_pragma (parser
);
14589 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DECLARE_CLAUSE_MASK
,
14590 "#pragma acc declare");
14593 error_at (pragma_loc
,
14594 "no valid clauses specified in %<#pragma acc declare%>");
14598 for (t
= clauses
; t
; t
= OMP_CLAUSE_CHAIN (t
))
14600 location_t loc
= OMP_CLAUSE_LOCATION (t
);
14601 decl
= OMP_CLAUSE_DECL (t
);
14602 if (!DECL_P (decl
))
14604 error_at (loc
, "array section in %<#pragma acc declare%>");
14609 switch (OMP_CLAUSE_MAP_KIND (t
))
14611 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
14612 case GOMP_MAP_ALLOC
:
14614 case GOMP_MAP_FORCE_DEVICEPTR
:
14615 case GOMP_MAP_DEVICE_RESIDENT
:
14618 case GOMP_MAP_LINK
:
14619 if (!global_bindings_p ()
14620 && (TREE_STATIC (decl
)
14621 || !DECL_EXTERNAL (decl
)))
14624 "%qD must be a global variable in "
14625 "%<#pragma acc declare link%>",
14633 if (global_bindings_p ())
14635 error_at (loc
, "invalid OpenACC clause at file scope");
14639 if (DECL_EXTERNAL (decl
))
14642 "invalid use of %<extern%> variable %qD "
14643 "in %<#pragma acc declare%>", decl
);
14647 else if (TREE_PUBLIC (decl
))
14650 "invalid use of %<global%> variable %qD "
14651 "in %<#pragma acc declare%>", decl
);
14658 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl
))
14659 || lookup_attribute ("omp declare target link",
14660 DECL_ATTRIBUTES (decl
)))
14662 error_at (loc
, "variable %qD used more than once with "
14663 "%<#pragma acc declare%>", decl
);
14672 if (OMP_CLAUSE_MAP_KIND (t
) == GOMP_MAP_LINK
)
14673 id
= get_identifier ("omp declare target link");
14675 id
= get_identifier ("omp declare target");
14677 DECL_ATTRIBUTES (decl
)
14678 = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (decl
));
14680 if (global_bindings_p ())
14682 symtab_node
*node
= symtab_node::get (decl
);
14685 node
->offloadable
= 1;
14686 if (ENABLE_OFFLOADING
)
14688 g
->have_offload
= true;
14689 if (is_a
<varpool_node
*> (node
))
14690 vec_safe_push (offload_vars
, decl
);
14697 if (error
|| global_bindings_p ())
14700 stmt
= make_node (OACC_DECLARE
);
14701 TREE_TYPE (stmt
) = void_type_node
;
14702 OACC_DECLARE_CLAUSES (stmt
) = clauses
;
14703 SET_EXPR_LOCATION (stmt
, pragma_loc
);
14711 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
14715 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
14718 LOC is the location of the #pragma token.
14721 #define OACC_ENTER_DATA_CLAUSE_MASK \
14722 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14723 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14724 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14725 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14726 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14728 #define OACC_EXIT_DATA_CLAUSE_MASK \
14729 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14730 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14731 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14732 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
14733 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FINALIZE) \
14734 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14737 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
14739 location_t loc
= c_parser_peek_token (parser
)->location
;
14740 tree clauses
, stmt
;
14741 const char *p
= "";
14743 c_parser_consume_pragma (parser
);
14745 if (c_parser_next_token_is (parser
, CPP_NAME
))
14747 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14748 c_parser_consume_token (parser
);
14751 if (strcmp (p
, "data") != 0)
14753 error_at (loc
, "expected %<data%> after %<#pragma acc %s%>",
14754 enter
? "enter" : "exit");
14755 parser
->error
= true;
14756 c_parser_skip_to_pragma_eol (parser
);
14761 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
14762 "#pragma acc enter data");
14764 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
14765 "#pragma acc exit data");
14767 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
14769 error_at (loc
, "%<#pragma acc %s data%> has no data movement clause",
14770 enter
? "enter" : "exit");
14774 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
14775 TREE_TYPE (stmt
) = void_type_node
;
14776 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
14777 SET_EXPR_LOCATION (stmt
, loc
);
14783 # pragma acc host_data oacc-data-clause[optseq] new-line
14787 #define OACC_HOST_DATA_CLAUSE_MASK \
14788 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
14791 c_parser_oacc_host_data (location_t loc
, c_parser
*parser
, bool *if_p
)
14793 tree stmt
, clauses
, block
;
14795 clauses
= c_parser_oacc_all_clauses (parser
, OACC_HOST_DATA_CLAUSE_MASK
,
14796 "#pragma acc host_data");
14798 block
= c_begin_omp_parallel ();
14799 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14800 stmt
= c_finish_oacc_host_data (loc
, clauses
, block
);
14807 # pragma acc loop oacc-loop-clause[optseq] new-line
14810 LOC is the location of the #pragma token.
14813 #define OACC_LOOP_CLAUSE_MASK \
14814 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
14815 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14816 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14817 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14818 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14819 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14820 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
14821 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
14822 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
14823 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
14825 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
,
14826 omp_clause_mask mask
, tree
*cclauses
, bool *if_p
)
14828 bool is_parallel
= ((mask
>> PRAGMA_OACC_CLAUSE_REDUCTION
) & 1) == 1;
14830 strcat (p_name
, " loop");
14831 mask
|= OACC_LOOP_CLAUSE_MASK
;
14833 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
,
14837 clauses
= c_oacc_split_loop_clauses (clauses
, cclauses
, is_parallel
);
14839 *cclauses
= c_finish_omp_clauses (*cclauses
, C_ORT_ACC
);
14841 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14844 tree block
= c_begin_compound_stmt (true);
14845 tree stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
,
14847 block
= c_end_compound_stmt (loc
, block
, true);
14854 # pragma acc kernels oacc-kernels-clause[optseq] new-line
14859 # pragma acc parallel oacc-parallel-clause[optseq] new-line
14862 LOC is the location of the #pragma token.
14865 #define OACC_KERNELS_CLAUSE_MASK \
14866 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14867 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14868 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14869 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14870 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14871 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14872 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14873 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14874 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14875 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14876 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14877 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14878 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14880 #define OACC_PARALLEL_CLAUSE_MASK \
14881 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14882 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14883 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14884 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14885 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14886 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14887 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14888 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14889 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14890 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
14891 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14892 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14893 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14894 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14895 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14896 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14899 c_parser_oacc_kernels_parallel (location_t loc
, c_parser
*parser
,
14900 enum pragma_kind p_kind
, char *p_name
,
14903 omp_clause_mask mask
;
14904 enum tree_code code
;
14907 case PRAGMA_OACC_KERNELS
:
14908 strcat (p_name
, " kernels");
14909 mask
= OACC_KERNELS_CLAUSE_MASK
;
14910 code
= OACC_KERNELS
;
14912 case PRAGMA_OACC_PARALLEL
:
14913 strcat (p_name
, " parallel");
14914 mask
= OACC_PARALLEL_CLAUSE_MASK
;
14915 code
= OACC_PARALLEL
;
14918 gcc_unreachable ();
14921 if (c_parser_next_token_is (parser
, CPP_NAME
))
14923 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14924 if (strcmp (p
, "loop") == 0)
14926 c_parser_consume_token (parser
);
14927 tree block
= c_begin_omp_parallel ();
14929 c_parser_oacc_loop (loc
, parser
, p_name
, mask
, &clauses
, if_p
);
14930 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14934 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
);
14936 tree block
= c_begin_omp_parallel ();
14937 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14939 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14943 # pragma acc routine oacc-routine-clause[optseq] new-line
14944 function-definition
14946 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
14949 #define OACC_ROUTINE_CLAUSE_MASK \
14950 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14951 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14952 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14953 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
14955 /* Parse an OpenACC routine directive. For named directives, we apply
14956 immediately to the named function. For unnamed ones we then parse
14957 a declaration or definition, which must be for a function. */
14960 c_parser_oacc_routine (c_parser
*parser
, enum pragma_context context
)
14962 gcc_checking_assert (context
== pragma_external
);
14964 oacc_routine_data data
;
14965 data
.error_seen
= false;
14966 data
.fndecl_seen
= false;
14967 data
.clauses
= NULL_TREE
;
14968 data
.loc
= c_parser_peek_token (parser
)->location
;
14970 c_parser_consume_pragma (parser
);
14972 /* Look for optional '( name )'. */
14973 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14975 c_parser_consume_token (parser
); /* '(' */
14977 tree decl
= NULL_TREE
;
14978 c_token
*name_token
= c_parser_peek_token (parser
);
14979 location_t name_loc
= name_token
->location
;
14980 if (name_token
->type
== CPP_NAME
14981 && (name_token
->id_kind
== C_ID_ID
14982 || name_token
->id_kind
== C_ID_TYPENAME
))
14984 decl
= lookup_name (name_token
->value
);
14986 error_at (name_loc
,
14987 "%qE has not been declared", name_token
->value
);
14988 c_parser_consume_token (parser
);
14991 c_parser_error (parser
, "expected function name");
14994 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14996 c_parser_skip_to_pragma_eol (parser
, false);
15001 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
15002 "#pragma acc routine");
15004 if (TREE_CODE (decl
) != FUNCTION_DECL
)
15006 error_at (name_loc
, "%qD does not refer to a function", decl
);
15010 c_finish_oacc_routine (&data
, decl
, false);
15012 else /* No optional '( name )'. */
15015 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
15016 "#pragma acc routine");
15018 /* Emit a helpful diagnostic if there's another pragma following this
15019 one. Also don't allow a static assertion declaration, as in the
15020 following we'll just parse a *single* "declaration or function
15021 definition", and the static assertion counts an one. */
15022 if (c_parser_next_token_is (parser
, CPP_PRAGMA
)
15023 || c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
15025 error_at (data
.loc
,
15026 "%<#pragma acc routine%> not immediately followed by"
15027 " function declaration or definition");
15028 /* ..., and then just keep going. */
15032 /* We only have to consider the pragma_external case here. */
15033 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
15034 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
15036 int ext
= disable_extension_diagnostics ();
15038 c_parser_consume_token (parser
);
15039 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
15040 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
15041 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
15042 NULL
, vNULL
, &data
);
15043 restore_extension_diagnostics (ext
);
15046 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
15047 NULL
, vNULL
, &data
);
15051 /* Finalize an OpenACC routine pragma, applying it to FNDECL.
15052 IS_DEFN is true if we're applying it to the definition. */
15055 c_finish_oacc_routine (struct oacc_routine_data
*data
, tree fndecl
,
15058 /* Keep going if we're in error reporting mode. */
15059 if (data
->error_seen
15060 || fndecl
== error_mark_node
)
15063 if (data
->fndecl_seen
)
15065 error_at (data
->loc
,
15066 "%<#pragma acc routine%> not immediately followed by"
15067 " a single function declaration or definition");
15068 data
->error_seen
= true;
15071 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
15073 error_at (data
->loc
,
15074 "%<#pragma acc routine%> not immediately followed by"
15075 " function declaration or definition");
15076 data
->error_seen
= true;
15080 if (oacc_get_fn_attrib (fndecl
))
15082 error_at (data
->loc
,
15083 "%<#pragma acc routine%> already applied to %qD", fndecl
);
15084 data
->error_seen
= true;
15088 if (TREE_USED (fndecl
) || (!is_defn
&& DECL_SAVED_TREE (fndecl
)))
15090 error_at (data
->loc
,
15092 ? G_("%<#pragma acc routine%> must be applied before use")
15093 : G_("%<#pragma acc routine%> must be applied before "
15095 data
->error_seen
= true;
15099 /* Process the routine's dimension clauses. */
15100 tree dims
= oacc_build_routine_dims (data
->clauses
);
15101 oacc_replace_fn_attrib (fndecl
, dims
);
15103 /* Add an "omp declare target" attribute. */
15104 DECL_ATTRIBUTES (fndecl
)
15105 = tree_cons (get_identifier ("omp declare target"),
15106 NULL_TREE
, DECL_ATTRIBUTES (fndecl
));
15108 /* Remember that we've used this "#pragma acc routine". */
15109 data
->fndecl_seen
= true;
15113 # pragma acc update oacc-update-clause[optseq] new-line
15116 #define OACC_UPDATE_CLAUSE_MASK \
15117 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
15118 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
15119 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
15120 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
15121 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF_PRESENT) \
15122 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
15125 c_parser_oacc_update (c_parser
*parser
)
15127 location_t loc
= c_parser_peek_token (parser
)->location
;
15129 c_parser_consume_pragma (parser
);
15131 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
15132 "#pragma acc update");
15133 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
15136 "%<#pragma acc update%> must contain at least one "
15137 "%<device%> or %<host%> or %<self%> clause");
15144 tree stmt
= make_node (OACC_UPDATE
);
15145 TREE_TYPE (stmt
) = void_type_node
;
15146 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
15147 SET_EXPR_LOCATION (stmt
, loc
);
15152 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
15154 LOC is the location of the #pragma token.
15157 #define OACC_WAIT_CLAUSE_MASK \
15158 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
15161 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
15163 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
15165 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
15166 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
15168 strcpy (p_name
, " wait");
15169 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
15170 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
15177 # pragma omp atomic new-line
15181 x binop= expr | x++ | ++x | x-- | --x
15183 +, *, -, /, &, ^, |, <<, >>
15185 where x is an lvalue expression with scalar type.
15188 # pragma omp atomic new-line
15191 # pragma omp atomic read new-line
15194 # pragma omp atomic write new-line
15197 # pragma omp atomic update new-line
15200 # pragma omp atomic capture new-line
15203 # pragma omp atomic capture new-line
15211 expression-stmt | x = x binop expr
15213 v = expression-stmt
15215 { v = x; update-stmt; } | { update-stmt; v = x; }
15219 expression-stmt | x = x binop expr | x = expr binop x
15223 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
15225 where x and v are lvalue expressions with scalar type.
15227 LOC is the location of the #pragma token. */
15230 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
15232 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
15233 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
15234 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
15235 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
15236 struct c_expr expr
;
15238 bool structured_block
= false;
15239 bool swapped
= false;
15240 bool seq_cst
= false;
15243 if (c_parser_next_token_is (parser
, CPP_NAME
))
15245 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15246 if (!strcmp (p
, "seq_cst"))
15249 c_parser_consume_token (parser
);
15250 if (c_parser_next_token_is (parser
, CPP_COMMA
)
15251 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
15252 c_parser_consume_token (parser
);
15255 if (c_parser_next_token_is (parser
, CPP_NAME
))
15257 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15259 if (!strcmp (p
, "read"))
15260 code
= OMP_ATOMIC_READ
;
15261 else if (!strcmp (p
, "write"))
15263 else if (!strcmp (p
, "update"))
15265 else if (!strcmp (p
, "capture"))
15266 code
= OMP_ATOMIC_CAPTURE_NEW
;
15270 c_parser_consume_token (parser
);
15274 if (c_parser_next_token_is (parser
, CPP_COMMA
)
15275 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
15276 c_parser_consume_token (parser
);
15278 if (c_parser_next_token_is (parser
, CPP_NAME
))
15281 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15282 if (!strcmp (p
, "seq_cst"))
15285 c_parser_consume_token (parser
);
15289 c_parser_skip_to_pragma_eol (parser
);
15293 case OMP_ATOMIC_READ
:
15294 case NOP_EXPR
: /* atomic write */
15295 v
= c_parser_cast_expression (parser
, NULL
).value
;
15296 non_lvalue_p
= !lvalue_p (v
);
15297 v
= c_fully_fold (v
, false, NULL
, true);
15298 if (v
== error_mark_node
)
15301 v
= non_lvalue (v
);
15302 loc
= c_parser_peek_token (parser
)->location
;
15303 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15305 if (code
== NOP_EXPR
)
15307 lhs
= c_parser_expression (parser
).value
;
15308 lhs
= c_fully_fold (lhs
, false, NULL
);
15309 if (lhs
== error_mark_node
)
15314 lhs
= c_parser_cast_expression (parser
, NULL
).value
;
15315 non_lvalue_p
= !lvalue_p (lhs
);
15316 lhs
= c_fully_fold (lhs
, false, NULL
, true);
15317 if (lhs
== error_mark_node
)
15320 lhs
= non_lvalue (lhs
);
15322 if (code
== NOP_EXPR
)
15324 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
15332 case OMP_ATOMIC_CAPTURE_NEW
:
15333 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
15335 c_parser_consume_token (parser
);
15336 structured_block
= true;
15340 v
= c_parser_cast_expression (parser
, NULL
).value
;
15341 non_lvalue_p
= !lvalue_p (v
);
15342 v
= c_fully_fold (v
, false, NULL
, true);
15343 if (v
== error_mark_node
)
15346 v
= non_lvalue (v
);
15347 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15355 /* For structured_block case we don't know yet whether
15356 old or new x should be captured. */
15358 eloc
= c_parser_peek_token (parser
)->location
;
15359 expr
= c_parser_cast_expression (parser
, NULL
);
15361 expr
= default_function_array_conversion (eloc
, expr
);
15362 unfolded_lhs
= expr
.value
;
15363 lhs
= c_fully_fold (lhs
, false, NULL
, true);
15365 switch (TREE_CODE (lhs
))
15369 c_parser_skip_to_end_of_block_or_statement (parser
);
15370 if (structured_block
)
15372 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15373 c_parser_consume_token (parser
);
15374 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
15376 c_parser_skip_to_end_of_block_or_statement (parser
);
15377 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15378 c_parser_consume_token (parser
);
15383 case POSTINCREMENT_EXPR
:
15384 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
15385 code
= OMP_ATOMIC_CAPTURE_OLD
;
15387 case PREINCREMENT_EXPR
:
15388 lhs
= TREE_OPERAND (lhs
, 0);
15389 unfolded_lhs
= NULL_TREE
;
15390 opcode
= PLUS_EXPR
;
15391 rhs
= integer_one_node
;
15394 case POSTDECREMENT_EXPR
:
15395 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
15396 code
= OMP_ATOMIC_CAPTURE_OLD
;
15398 case PREDECREMENT_EXPR
:
15399 lhs
= TREE_OPERAND (lhs
, 0);
15400 unfolded_lhs
= NULL_TREE
;
15401 opcode
= MINUS_EXPR
;
15402 rhs
= integer_one_node
;
15405 case COMPOUND_EXPR
:
15406 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
15407 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
15408 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
15409 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
15410 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
15411 (TREE_OPERAND (lhs
, 1), 0), 0)))
15413 /* Undo effects of boolean_increment for post {in,de}crement. */
15414 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
15417 if (TREE_CODE (lhs
) == MODIFY_EXPR
15418 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
15420 /* Undo effects of boolean_increment. */
15421 if (integer_onep (TREE_OPERAND (lhs
, 1)))
15423 /* This is pre or post increment. */
15424 rhs
= TREE_OPERAND (lhs
, 1);
15425 lhs
= TREE_OPERAND (lhs
, 0);
15426 unfolded_lhs
= NULL_TREE
;
15428 if (code
== OMP_ATOMIC_CAPTURE_NEW
15429 && !structured_block
15430 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
15431 code
= OMP_ATOMIC_CAPTURE_OLD
;
15434 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
15435 && TREE_OPERAND (lhs
, 0)
15436 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
15438 /* This is pre or post decrement. */
15439 rhs
= TREE_OPERAND (lhs
, 1);
15440 lhs
= TREE_OPERAND (lhs
, 0);
15441 unfolded_lhs
= NULL_TREE
;
15443 if (code
== OMP_ATOMIC_CAPTURE_NEW
15444 && !structured_block
15445 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
15446 code
= OMP_ATOMIC_CAPTURE_OLD
;
15452 if (!lvalue_p (unfolded_lhs
))
15453 lhs
= non_lvalue (lhs
);
15454 switch (c_parser_peek_token (parser
)->type
)
15457 opcode
= MULT_EXPR
;
15460 opcode
= TRUNC_DIV_EXPR
;
15463 opcode
= PLUS_EXPR
;
15466 opcode
= MINUS_EXPR
;
15468 case CPP_LSHIFT_EQ
:
15469 opcode
= LSHIFT_EXPR
;
15471 case CPP_RSHIFT_EQ
:
15472 opcode
= RSHIFT_EXPR
;
15475 opcode
= BIT_AND_EXPR
;
15478 opcode
= BIT_IOR_EXPR
;
15481 opcode
= BIT_XOR_EXPR
;
15484 c_parser_consume_token (parser
);
15485 eloc
= c_parser_peek_token (parser
)->location
;
15486 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
15488 switch (TREE_CODE (rhs1
))
15491 case TRUNC_DIV_EXPR
:
15500 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
15502 opcode
= TREE_CODE (rhs1
);
15503 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
,
15505 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
,
15509 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
15511 opcode
= TREE_CODE (rhs1
);
15512 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
,
15514 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
,
15516 swapped
= !commutative_tree_code (opcode
);
15525 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
15527 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
15529 code
= OMP_ATOMIC_CAPTURE_OLD
;
15532 expr
= default_function_array_read_conversion (eloc
, expr
);
15533 unfolded_lhs1
= expr
.value
;
15534 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
, true);
15536 c_parser_consume_token (parser
);
15539 if (structured_block
)
15542 expr
= default_function_array_read_conversion (eloc
, expr
);
15543 rhs
= c_fully_fold (expr
.value
, false, NULL
, true);
15548 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
15551 c_parser_error (parser
,
15552 "invalid operator for %<#pragma omp atomic%>");
15556 /* Arrange to pass the location of the assignment operator to
15557 c_finish_omp_atomic. */
15558 loc
= c_parser_peek_token (parser
)->location
;
15559 c_parser_consume_token (parser
);
15560 eloc
= c_parser_peek_token (parser
)->location
;
15561 expr
= c_parser_expression (parser
);
15562 expr
= default_function_array_read_conversion (eloc
, expr
);
15564 rhs
= c_fully_fold (rhs
, false, NULL
, true);
15568 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
15570 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
15572 v
= c_parser_cast_expression (parser
, NULL
).value
;
15573 non_lvalue_p
= !lvalue_p (v
);
15574 v
= c_fully_fold (v
, false, NULL
, true);
15575 if (v
== error_mark_node
)
15578 v
= non_lvalue (v
);
15579 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15581 eloc
= c_parser_peek_token (parser
)->location
;
15582 expr
= c_parser_cast_expression (parser
, NULL
);
15584 expr
= default_function_array_read_conversion (eloc
, expr
);
15585 unfolded_lhs1
= expr
.value
;
15586 lhs1
= c_fully_fold (lhs1
, false, NULL
, true);
15587 if (lhs1
== error_mark_node
)
15589 if (!lvalue_p (unfolded_lhs1
))
15590 lhs1
= non_lvalue (lhs1
);
15592 if (structured_block
)
15594 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15595 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
15598 if (unfolded_lhs
&& unfolded_lhs1
15599 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
15601 error ("%<#pragma omp atomic capture%> uses two different "
15602 "expressions for memory");
15603 stmt
= error_mark_node
;
15606 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
15608 if (stmt
!= error_mark_node
)
15611 if (!structured_block
)
15612 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15617 # pragma omp barrier new-line
15621 c_parser_omp_barrier (c_parser
*parser
)
15623 location_t loc
= c_parser_peek_token (parser
)->location
;
15624 c_parser_consume_pragma (parser
);
15625 c_parser_skip_to_pragma_eol (parser
);
15627 c_finish_omp_barrier (loc
);
15631 # pragma omp critical [(name)] new-line
15635 # pragma omp critical [(name) [hint(expression)]] new-line
15637 LOC is the location of the #pragma itself. */
15639 #define OMP_CRITICAL_CLAUSE_MASK \
15640 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
15643 c_parser_omp_critical (location_t loc
, c_parser
*parser
, bool *if_p
)
15645 tree stmt
, name
= NULL_TREE
, clauses
= NULL_TREE
;
15647 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
15649 c_parser_consume_token (parser
);
15650 if (c_parser_next_token_is (parser
, CPP_NAME
))
15652 name
= c_parser_peek_token (parser
)->value
;
15653 c_parser_consume_token (parser
);
15654 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
15657 c_parser_error (parser
, "expected identifier");
15659 clauses
= c_parser_omp_all_clauses (parser
,
15660 OMP_CRITICAL_CLAUSE_MASK
,
15661 "#pragma omp critical");
15665 if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15666 c_parser_error (parser
, "expected %<(%> or end of line");
15667 c_parser_skip_to_pragma_eol (parser
);
15670 stmt
= c_parser_omp_structured_block (parser
, if_p
);
15671 return c_finish_omp_critical (loc
, stmt
, name
, clauses
);
15675 # pragma omp flush flush-vars[opt] new-line
15678 ( variable-list ) */
15681 c_parser_omp_flush (c_parser
*parser
)
15683 location_t loc
= c_parser_peek_token (parser
)->location
;
15684 c_parser_consume_pragma (parser
);
15685 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
15686 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
15687 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15688 c_parser_error (parser
, "expected %<(%> or end of line");
15689 c_parser_skip_to_pragma_eol (parser
);
15691 c_finish_omp_flush (loc
);
15694 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
15695 The real trick here is to determine the loop control variable early
15696 so that we can push a new decl if necessary to make it private.
15697 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
15701 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
15702 tree clauses
, tree
*cclauses
, bool *if_p
)
15704 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
15705 tree declv
, condv
, incrv
, initv
, ret
= NULL_TREE
;
15706 tree pre_body
= NULL_TREE
, this_pre_body
;
15707 tree ordered_cl
= NULL_TREE
;
15708 bool fail
= false, open_brace_parsed
= false;
15709 int i
, collapse
= 1, ordered
= 0, count
, nbraces
= 0;
15710 location_t for_loc
;
15711 bool tiling
= false;
15712 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
15714 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
15715 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
15716 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
15717 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_TILE
)
15720 collapse
= list_length (OMP_CLAUSE_TILE_LIST (cl
));
15722 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_ORDERED
15723 && OMP_CLAUSE_ORDERED_EXPR (cl
))
15726 ordered
= tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl
));
15729 if (ordered
&& ordered
< collapse
)
15731 error_at (OMP_CLAUSE_LOCATION (ordered_cl
),
15732 "%<ordered%> clause parameter is less than %<collapse%>");
15733 OMP_CLAUSE_ORDERED_EXPR (ordered_cl
)
15734 = build_int_cst (NULL_TREE
, collapse
);
15735 ordered
= collapse
;
15739 for (tree
*pc
= &clauses
; *pc
; )
15740 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_LINEAR
)
15742 error_at (OMP_CLAUSE_LOCATION (*pc
),
15743 "%<linear%> clause may not be specified together "
15744 "with %<ordered%> clause with a parameter");
15745 *pc
= OMP_CLAUSE_CHAIN (*pc
);
15748 pc
= &OMP_CLAUSE_CHAIN (*pc
);
15751 gcc_assert (tiling
|| (collapse
>= 1 && ordered
>= 0));
15752 count
= ordered
? ordered
: collapse
;
15754 declv
= make_tree_vec (count
);
15755 initv
= make_tree_vec (count
);
15756 condv
= make_tree_vec (count
);
15757 incrv
= make_tree_vec (count
);
15759 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
15761 c_parser_error (parser
, "for statement expected");
15764 for_loc
= c_parser_peek_token (parser
)->location
;
15765 c_parser_consume_token (parser
);
15767 for (i
= 0; i
< count
; i
++)
15769 int bracecount
= 0;
15771 matching_parens parens
;
15772 if (!parens
.require_open (parser
))
15775 /* Parse the initialization declaration or expression. */
15776 if (c_parser_next_tokens_start_declaration (parser
))
15779 vec_safe_push (for_block
, c_begin_compound_stmt (true));
15780 this_pre_body
= push_stmt_list ();
15781 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
15785 this_pre_body
= pop_stmt_list (this_pre_body
);
15789 pre_body
= push_stmt_list ();
15791 add_stmt (this_pre_body
);
15792 pre_body
= pop_stmt_list (pre_body
);
15795 pre_body
= this_pre_body
;
15797 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
15800 if (DECL_INITIAL (decl
) == error_mark_node
)
15801 decl
= error_mark_node
;
15804 else if (c_parser_next_token_is (parser
, CPP_NAME
)
15805 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
15807 struct c_expr decl_exp
;
15808 struct c_expr init_exp
;
15809 location_t init_loc
;
15811 decl_exp
= c_parser_postfix_expression (parser
);
15812 decl
= decl_exp
.value
;
15814 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
15816 init_loc
= c_parser_peek_token (parser
)->location
;
15817 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
15818 init_exp
= default_function_array_read_conversion (init_loc
,
15820 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
15821 NOP_EXPR
, init_loc
, init_exp
.value
,
15822 init_exp
.original_type
);
15823 init
= c_process_expr_stmt (init_loc
, init
);
15825 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15830 c_parser_error (parser
,
15831 "expected iteration declaration or initialization");
15832 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
15838 /* Parse the loop condition. */
15840 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
15842 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
15843 struct c_expr cond_expr
15844 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
15846 cond
= cond_expr
.value
;
15847 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
15848 if (COMPARISON_CLASS_P (cond
))
15850 tree op0
= TREE_OPERAND (cond
, 0), op1
= TREE_OPERAND (cond
, 1);
15851 op0
= c_fully_fold (op0
, false, NULL
);
15852 op1
= c_fully_fold (op1
, false, NULL
);
15853 TREE_OPERAND (cond
, 0) = op0
;
15854 TREE_OPERAND (cond
, 1) = op1
;
15856 switch (cond_expr
.original_code
)
15864 /* Can't be cond = error_mark_node, because we want to preserve
15865 the location until c_finish_omp_for. */
15866 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
15869 protected_set_expr_location (cond
, cond_loc
);
15871 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15873 /* Parse the increment expression. */
15875 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
15877 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
15879 incr
= c_process_expr_stmt (incr_loc
,
15880 c_parser_expression (parser
).value
);
15882 parens
.skip_until_found_close (parser
);
15884 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
15888 TREE_VEC_ELT (declv
, i
) = decl
;
15889 TREE_VEC_ELT (initv
, i
) = init
;
15890 TREE_VEC_ELT (condv
, i
) = cond
;
15891 TREE_VEC_ELT (incrv
, i
) = incr
;
15895 if (i
== count
- 1)
15898 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
15899 in between the collapsed for loops to be still considered perfectly
15900 nested. Hopefully the final version clarifies this.
15901 For now handle (multiple) {'s and empty statements. */
15904 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
15906 c_parser_consume_token (parser
);
15909 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
15911 c_parser_consume_token (parser
);
15914 else if (bracecount
15915 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15916 c_parser_consume_token (parser
);
15919 c_parser_error (parser
, "not enough perfectly nested loops");
15922 open_brace_parsed
= true;
15932 nbraces
+= bracecount
;
15938 save_break
= c_break_label
;
15939 c_break_label
= size_one_node
;
15940 save_cont
= c_cont_label
;
15941 c_cont_label
= NULL_TREE
;
15942 body
= push_stmt_list ();
15944 if (open_brace_parsed
)
15946 location_t here
= c_parser_peek_token (parser
)->location
;
15947 stmt
= c_begin_compound_stmt (true);
15948 c_parser_compound_statement_nostart (parser
);
15949 add_stmt (c_end_compound_stmt (here
, stmt
, true));
15952 add_stmt (c_parser_c99_block_statement (parser
, if_p
));
15955 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
15956 SET_EXPR_LOCATION (t
, loc
);
15960 body
= pop_stmt_list (body
);
15961 c_break_label
= save_break
;
15962 c_cont_label
= save_cont
;
15966 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15968 c_parser_consume_token (parser
);
15971 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15972 c_parser_consume_token (parser
);
15975 c_parser_error (parser
, "collapsed loops not perfectly nested");
15978 location_t here
= c_parser_peek_token (parser
)->location
;
15979 stmt
= c_begin_compound_stmt (true);
15981 c_parser_compound_statement_nostart (parser
);
15982 body
= c_end_compound_stmt (here
, stmt
, true);
15989 /* Only bother calling c_finish_omp_for if we haven't already generated
15990 an error from the initialization parsing. */
15993 stmt
= c_finish_omp_for (loc
, code
, declv
, NULL
, initv
, condv
,
15994 incrv
, body
, pre_body
);
15996 /* Check for iterators appearing in lb, b or incr expressions. */
15997 if (stmt
&& !c_omp_check_loop_iv (stmt
, declv
, NULL
))
16004 if (cclauses
!= NULL
16005 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
16008 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
16009 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
16010 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
16011 c
= &OMP_CLAUSE_CHAIN (*c
);
16014 for (i
= 0; i
< count
; i
++)
16015 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
16018 c
= &OMP_CLAUSE_CHAIN (*c
);
16019 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
16022 "iteration variable %qD should not be firstprivate",
16023 OMP_CLAUSE_DECL (*c
));
16024 *c
= OMP_CLAUSE_CHAIN (*c
);
16028 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
16030 *c
= OMP_CLAUSE_CHAIN (*c
);
16031 if (code
== OMP_SIMD
)
16033 OMP_CLAUSE_CHAIN (l
)
16034 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
16035 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
16039 OMP_CLAUSE_CHAIN (l
) = clauses
;
16045 OMP_FOR_CLAUSES (stmt
) = clauses
;
16050 while (!for_block
->is_empty ())
16052 /* FIXME diagnostics: LOC below should be the actual location of
16053 this particular for block. We need to build a list of
16054 locations to go along with FOR_BLOCK. */
16055 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
16058 release_tree_vector (for_block
);
16062 /* Helper function for OpenMP parsing, split clauses and call
16063 finish_omp_clauses on each of the set of clauses afterwards. */
16066 omp_split_clauses (location_t loc
, enum tree_code code
,
16067 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
16070 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
16071 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
16073 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
], C_ORT_OMP
);
16077 #pragma omp simd simd-clause[optseq] new-line
16080 LOC is the location of the #pragma token.
16083 #define OMP_SIMD_CLAUSE_MASK \
16084 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
16085 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
16086 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
16087 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
16088 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16089 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16090 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16091 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
16094 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
16095 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16098 tree block
, clauses
, ret
;
16100 strcat (p_name
, " simd");
16101 mask
|= OMP_SIMD_CLAUSE_MASK
;
16103 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16106 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
16107 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
16108 tree c
= omp_find_clause (cclauses
[C_OMP_CLAUSE_SPLIT_FOR
],
16109 OMP_CLAUSE_ORDERED
);
16110 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
16112 error_at (OMP_CLAUSE_LOCATION (c
),
16113 "%<ordered%> clause with parameter may not be specified "
16114 "on %qs construct", p_name
);
16115 OMP_CLAUSE_ORDERED_EXPR (c
) = NULL_TREE
;
16119 block
= c_begin_compound_stmt (true);
16120 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
, if_p
);
16121 block
= c_end_compound_stmt (loc
, block
, true);
16128 #pragma omp for for-clause[optseq] new-line
16132 #pragma omp for simd for-simd-clause[optseq] new-line
16135 LOC is the location of the #pragma token.
16138 #define OMP_FOR_CLAUSE_MASK \
16139 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16140 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16141 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16142 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
16143 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16144 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
16145 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
16146 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
16147 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16150 c_parser_omp_for (location_t loc
, c_parser
*parser
,
16151 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16154 tree block
, clauses
, ret
;
16156 strcat (p_name
, " for");
16157 mask
|= OMP_FOR_CLAUSE_MASK
;
16158 /* parallel for{, simd} disallows nowait clause, but for
16159 target {teams distribute ,}parallel for{, simd} it should be accepted. */
16160 if (cclauses
&& (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) == 0)
16161 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
16162 /* Composite distribute parallel for{, simd} disallows ordered clause. */
16163 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
16164 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
16166 if (c_parser_next_token_is (parser
, CPP_NAME
))
16168 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16170 if (strcmp (p
, "simd") == 0)
16172 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16173 if (cclauses
== NULL
)
16174 cclauses
= cclauses_buf
;
16176 c_parser_consume_token (parser
);
16177 if (!flag_openmp
) /* flag_openmp_simd */
16178 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16180 block
= c_begin_compound_stmt (true);
16181 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
16182 block
= c_end_compound_stmt (loc
, block
, true);
16183 if (ret
== NULL_TREE
)
16185 ret
= make_node (OMP_FOR
);
16186 TREE_TYPE (ret
) = void_type_node
;
16187 OMP_FOR_BODY (ret
) = block
;
16188 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
16189 SET_EXPR_LOCATION (ret
, loc
);
16194 if (!flag_openmp
) /* flag_openmp_simd */
16196 c_parser_skip_to_pragma_eol (parser
, false);
16200 /* Composite distribute parallel for disallows linear clause. */
16201 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
16202 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINEAR
);
16204 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16207 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
16208 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
16211 block
= c_begin_compound_stmt (true);
16212 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
, if_p
);
16213 block
= c_end_compound_stmt (loc
, block
, true);
16220 # pragma omp master new-line
16223 LOC is the location of the #pragma token.
16227 c_parser_omp_master (location_t loc
, c_parser
*parser
, bool *if_p
)
16229 c_parser_skip_to_pragma_eol (parser
);
16230 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
,
16235 # pragma omp ordered new-line
16239 # pragma omp ordered ordered-clauses new-line
16242 # pragma omp ordered depend-clauses new-line */
16244 #define OMP_ORDERED_CLAUSE_MASK \
16245 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
16246 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
16248 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
16249 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
16252 c_parser_omp_ordered (c_parser
*parser
, enum pragma_context context
,
16255 location_t loc
= c_parser_peek_token (parser
)->location
;
16256 c_parser_consume_pragma (parser
);
16258 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
16260 c_parser_error (parser
, "expected declaration specifiers");
16261 c_parser_skip_to_pragma_eol (parser
, false);
16265 if (c_parser_next_token_is (parser
, CPP_NAME
))
16267 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16269 if (!strcmp ("depend", p
))
16271 if (!flag_openmp
) /* flag_openmp_simd */
16273 c_parser_skip_to_pragma_eol (parser
, false);
16276 if (context
== pragma_stmt
)
16279 "%<#pragma omp ordered%> with %<depend%> clause may "
16280 "only be used in compound statements");
16281 c_parser_skip_to_pragma_eol (parser
, false);
16286 = c_parser_omp_all_clauses (parser
,
16287 OMP_ORDERED_DEPEND_CLAUSE_MASK
,
16288 "#pragma omp ordered");
16289 c_finish_omp_ordered (loc
, clauses
, NULL_TREE
);
16294 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_ORDERED_CLAUSE_MASK
,
16295 "#pragma omp ordered");
16297 if (!flag_openmp
/* flag_openmp_simd */
16298 && omp_find_clause (clauses
, OMP_CLAUSE_SIMD
) == NULL_TREE
)
16301 c_finish_omp_ordered (loc
, clauses
,
16302 c_parser_omp_structured_block (parser
, if_p
));
16309 { section-sequence }
16312 section-directive[opt] structured-block
16313 section-sequence section-directive structured-block
16315 SECTIONS_LOC is the location of the #pragma omp sections. */
16318 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
16320 tree stmt
, substmt
;
16321 bool error_suppress
= false;
16324 loc
= c_parser_peek_token (parser
)->location
;
16325 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
16327 /* Avoid skipping until the end of the block. */
16328 parser
->error
= false;
16332 stmt
= push_stmt_list ();
16334 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
16336 substmt
= c_parser_omp_structured_block (parser
, NULL
);
16337 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
16338 SET_EXPR_LOCATION (substmt
, loc
);
16339 add_stmt (substmt
);
16344 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
16346 if (c_parser_next_token_is (parser
, CPP_EOF
))
16349 loc
= c_parser_peek_token (parser
)->location
;
16350 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
16352 c_parser_consume_pragma (parser
);
16353 c_parser_skip_to_pragma_eol (parser
);
16354 error_suppress
= false;
16356 else if (!error_suppress
)
16358 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
16359 error_suppress
= true;
16362 substmt
= c_parser_omp_structured_block (parser
, NULL
);
16363 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
16364 SET_EXPR_LOCATION (substmt
, loc
);
16365 add_stmt (substmt
);
16367 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
16368 "expected %<#pragma omp section%> or %<}%>");
16370 substmt
= pop_stmt_list (stmt
);
16372 stmt
= make_node (OMP_SECTIONS
);
16373 SET_EXPR_LOCATION (stmt
, sections_loc
);
16374 TREE_TYPE (stmt
) = void_type_node
;
16375 OMP_SECTIONS_BODY (stmt
) = substmt
;
16377 return add_stmt (stmt
);
16381 # pragma omp sections sections-clause[optseq] newline
16384 LOC is the location of the #pragma token.
16387 #define OMP_SECTIONS_CLAUSE_MASK \
16388 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16389 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16390 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16391 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16392 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16395 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
16396 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
16398 tree block
, clauses
, ret
;
16400 strcat (p_name
, " sections");
16401 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
16403 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
16405 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16408 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
16409 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
16412 block
= c_begin_compound_stmt (true);
16413 ret
= c_parser_omp_sections_scope (loc
, parser
);
16415 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
16416 block
= c_end_compound_stmt (loc
, block
, true);
16423 # pragma omp parallel parallel-clause[optseq] new-line
16425 # pragma omp parallel for parallel-for-clause[optseq] new-line
16427 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
16431 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
16434 LOC is the location of the #pragma token.
16437 #define OMP_PARALLEL_CLAUSE_MASK \
16438 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16439 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16440 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16441 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
16442 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16443 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
16444 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16445 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
16446 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
16449 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
16450 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16453 tree stmt
, clauses
, block
;
16455 strcat (p_name
, " parallel");
16456 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
16457 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
16458 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) != 0
16459 && (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) == 0)
16460 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_COPYIN
);
16462 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
16464 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16465 if (cclauses
== NULL
)
16466 cclauses
= cclauses_buf
;
16468 c_parser_consume_token (parser
);
16469 if (!flag_openmp
) /* flag_openmp_simd */
16470 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
16471 block
= c_begin_omp_parallel ();
16472 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
16474 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
16476 if (ret
== NULL_TREE
)
16478 OMP_PARALLEL_COMBINED (stmt
) = 1;
16481 /* When combined with distribute, parallel has to be followed by for.
16482 #pragma omp target parallel is allowed though. */
16484 && (mask
& (OMP_CLAUSE_MASK_1
16485 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
16487 error_at (loc
, "expected %<for%> after %qs", p_name
);
16488 c_parser_skip_to_pragma_eol (parser
);
16491 else if (!flag_openmp
) /* flag_openmp_simd */
16493 c_parser_skip_to_pragma_eol (parser
, false);
16496 else if (cclauses
== NULL
&& c_parser_next_token_is (parser
, CPP_NAME
))
16498 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16499 if (strcmp (p
, "sections") == 0)
16501 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16502 if (cclauses
== NULL
)
16503 cclauses
= cclauses_buf
;
16505 c_parser_consume_token (parser
);
16506 block
= c_begin_omp_parallel ();
16507 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
16508 stmt
= c_finish_omp_parallel (loc
,
16509 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
16511 OMP_PARALLEL_COMBINED (stmt
) = 1;
16516 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16519 omp_split_clauses (loc
, OMP_PARALLEL
, mask
, clauses
, cclauses
);
16520 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
16523 block
= c_begin_omp_parallel ();
16524 c_parser_statement (parser
, if_p
);
16525 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
16531 # pragma omp single single-clause[optseq] new-line
16534 LOC is the location of the #pragma.
16537 #define OMP_SINGLE_CLAUSE_MASK \
16538 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16539 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16540 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
16541 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16544 c_parser_omp_single (location_t loc
, c_parser
*parser
, bool *if_p
)
16546 tree stmt
= make_node (OMP_SINGLE
);
16547 SET_EXPR_LOCATION (stmt
, loc
);
16548 TREE_TYPE (stmt
) = void_type_node
;
16550 OMP_SINGLE_CLAUSES (stmt
)
16551 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
16552 "#pragma omp single");
16553 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
16555 return add_stmt (stmt
);
16559 # pragma omp task task-clause[optseq] new-line
16561 LOC is the location of the #pragma.
16564 #define OMP_TASK_CLAUSE_MASK \
16565 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16566 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
16567 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
16568 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16569 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16570 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16571 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
16572 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
16573 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16574 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
16577 c_parser_omp_task (location_t loc
, c_parser
*parser
, bool *if_p
)
16579 tree clauses
, block
;
16581 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
16582 "#pragma omp task");
16584 block
= c_begin_omp_task ();
16585 c_parser_statement (parser
, if_p
);
16586 return c_finish_omp_task (loc
, clauses
, block
);
16590 # pragma omp taskwait new-line
16594 c_parser_omp_taskwait (c_parser
*parser
)
16596 location_t loc
= c_parser_peek_token (parser
)->location
;
16597 c_parser_consume_pragma (parser
);
16598 c_parser_skip_to_pragma_eol (parser
);
16600 c_finish_omp_taskwait (loc
);
16604 # pragma omp taskyield new-line
16608 c_parser_omp_taskyield (c_parser
*parser
)
16610 location_t loc
= c_parser_peek_token (parser
)->location
;
16611 c_parser_consume_pragma (parser
);
16612 c_parser_skip_to_pragma_eol (parser
);
16614 c_finish_omp_taskyield (loc
);
16618 # pragma omp taskgroup new-line
16622 c_parser_omp_taskgroup (c_parser
*parser
, bool *if_p
)
16624 location_t loc
= c_parser_peek_token (parser
)->location
;
16625 c_parser_skip_to_pragma_eol (parser
);
16626 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
,
16631 # pragma omp cancel cancel-clause[optseq] new-line
16633 LOC is the location of the #pragma.
16636 #define OMP_CANCEL_CLAUSE_MASK \
16637 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
16638 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
16639 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
16640 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
16641 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
16644 c_parser_omp_cancel (c_parser
*parser
)
16646 location_t loc
= c_parser_peek_token (parser
)->location
;
16648 c_parser_consume_pragma (parser
);
16649 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
16650 "#pragma omp cancel");
16652 c_finish_omp_cancel (loc
, clauses
);
16656 # pragma omp cancellation point cancelpt-clause[optseq] new-line
16658 LOC is the location of the #pragma.
16661 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
16662 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
16663 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
16664 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
16665 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
16668 c_parser_omp_cancellation_point (c_parser
*parser
, enum pragma_context context
)
16670 location_t loc
= c_parser_peek_token (parser
)->location
;
16672 bool point_seen
= false;
16674 c_parser_consume_pragma (parser
);
16675 if (c_parser_next_token_is (parser
, CPP_NAME
))
16677 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16678 if (strcmp (p
, "point") == 0)
16680 c_parser_consume_token (parser
);
16686 c_parser_error (parser
, "expected %<point%>");
16687 c_parser_skip_to_pragma_eol (parser
);
16691 if (context
!= pragma_compound
)
16693 if (context
== pragma_stmt
)
16695 "%<#pragma %s%> may only be used in compound statements",
16696 "omp cancellation point");
16698 c_parser_error (parser
, "expected declaration specifiers");
16699 c_parser_skip_to_pragma_eol (parser
, false);
16704 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
16705 "#pragma omp cancellation point");
16707 c_finish_omp_cancellation_point (loc
, clauses
);
16711 #pragma omp distribute distribute-clause[optseq] new-line
16714 #define OMP_DISTRIBUTE_CLAUSE_MASK \
16715 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16716 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16717 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16718 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
16719 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
16722 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
16723 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16726 tree clauses
, block
, ret
;
16728 strcat (p_name
, " distribute");
16729 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
16731 if (c_parser_next_token_is (parser
, CPP_NAME
))
16733 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16735 bool parallel
= false;
16737 if (strcmp (p
, "simd") == 0)
16740 parallel
= strcmp (p
, "parallel") == 0;
16741 if (parallel
|| simd
)
16743 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16744 if (cclauses
== NULL
)
16745 cclauses
= cclauses_buf
;
16746 c_parser_consume_token (parser
);
16747 if (!flag_openmp
) /* flag_openmp_simd */
16750 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16753 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
16756 block
= c_begin_compound_stmt (true);
16758 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16761 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
,
16763 block
= c_end_compound_stmt (loc
, block
, true);
16766 ret
= make_node (OMP_DISTRIBUTE
);
16767 TREE_TYPE (ret
) = void_type_node
;
16768 OMP_FOR_BODY (ret
) = block
;
16769 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
16770 SET_EXPR_LOCATION (ret
, loc
);
16775 if (!flag_openmp
) /* flag_openmp_simd */
16777 c_parser_skip_to_pragma_eol (parser
, false);
16781 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16784 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
16785 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
16788 block
= c_begin_compound_stmt (true);
16789 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
,
16791 block
= c_end_compound_stmt (loc
, block
, true);
16798 # pragma omp teams teams-clause[optseq] new-line
16799 structured-block */
16801 #define OMP_TEAMS_CLAUSE_MASK \
16802 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16803 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16804 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16805 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16806 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
16807 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
16808 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
16811 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
16812 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16815 tree clauses
, block
, ret
;
16817 strcat (p_name
, " teams");
16818 mask
|= OMP_TEAMS_CLAUSE_MASK
;
16820 if (c_parser_next_token_is (parser
, CPP_NAME
))
16822 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16823 if (strcmp (p
, "distribute") == 0)
16825 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16826 if (cclauses
== NULL
)
16827 cclauses
= cclauses_buf
;
16829 c_parser_consume_token (parser
);
16830 if (!flag_openmp
) /* flag_openmp_simd */
16831 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
,
16833 block
= c_begin_compound_stmt (true);
16834 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
,
16836 block
= c_end_compound_stmt (loc
, block
, true);
16839 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16840 ret
= make_node (OMP_TEAMS
);
16841 TREE_TYPE (ret
) = void_type_node
;
16842 OMP_TEAMS_CLAUSES (ret
) = clauses
;
16843 OMP_TEAMS_BODY (ret
) = block
;
16844 OMP_TEAMS_COMBINED (ret
) = 1;
16845 return add_stmt (ret
);
16848 if (!flag_openmp
) /* flag_openmp_simd */
16850 c_parser_skip_to_pragma_eol (parser
, false);
16854 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16857 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
16858 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16861 tree stmt
= make_node (OMP_TEAMS
);
16862 TREE_TYPE (stmt
) = void_type_node
;
16863 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
16864 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
16866 return add_stmt (stmt
);
16870 # pragma omp target data target-data-clause[optseq] new-line
16871 structured-block */
16873 #define OMP_TARGET_DATA_CLAUSE_MASK \
16874 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16875 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16876 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16877 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
16880 c_parser_omp_target_data (location_t loc
, c_parser
*parser
, bool *if_p
)
16883 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
16884 "#pragma omp target data");
16886 for (tree
*pc
= &clauses
; *pc
;)
16888 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16889 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16892 case GOMP_MAP_ALWAYS_TO
:
16893 case GOMP_MAP_FROM
:
16894 case GOMP_MAP_ALWAYS_FROM
:
16895 case GOMP_MAP_TOFROM
:
16896 case GOMP_MAP_ALWAYS_TOFROM
:
16897 case GOMP_MAP_ALLOC
:
16900 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16901 case GOMP_MAP_ALWAYS_POINTER
:
16905 error_at (OMP_CLAUSE_LOCATION (*pc
),
16906 "%<#pragma omp target data%> with map-type other "
16907 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16908 "on %<map%> clause");
16909 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16912 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16919 "%<#pragma omp target data%> must contain at least "
16920 "one %<map%> clause");
16924 tree stmt
= make_node (OMP_TARGET_DATA
);
16925 TREE_TYPE (stmt
) = void_type_node
;
16926 OMP_TARGET_DATA_CLAUSES (stmt
) = clauses
;
16927 keep_next_level ();
16928 tree block
= c_begin_compound_stmt (true);
16929 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
16930 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
16932 SET_EXPR_LOCATION (stmt
, loc
);
16933 return add_stmt (stmt
);
16937 # pragma omp target update target-update-clause[optseq] new-line */
16939 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
16940 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
16941 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16942 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16943 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16944 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16945 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16948 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
16949 enum pragma_context context
)
16951 if (context
== pragma_stmt
)
16953 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
16954 "omp target update");
16955 c_parser_skip_to_pragma_eol (parser
, false);
16960 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
16961 "#pragma omp target update");
16962 if (omp_find_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
16963 && omp_find_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
16966 "%<#pragma omp target update%> must contain at least one "
16967 "%<from%> or %<to%> clauses");
16971 tree stmt
= make_node (OMP_TARGET_UPDATE
);
16972 TREE_TYPE (stmt
) = void_type_node
;
16973 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
16974 SET_EXPR_LOCATION (stmt
, loc
);
16980 # pragma omp target enter data target-data-clause[optseq] new-line */
16982 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
16983 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16984 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16985 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16986 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16987 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16990 c_parser_omp_target_enter_data (location_t loc
, c_parser
*parser
,
16991 enum pragma_context context
)
16993 bool data_seen
= false;
16994 if (c_parser_next_token_is (parser
, CPP_NAME
))
16996 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16997 if (strcmp (p
, "data") == 0)
16999 c_parser_consume_token (parser
);
17005 c_parser_error (parser
, "expected %<data%>");
17006 c_parser_skip_to_pragma_eol (parser
);
17010 if (context
== pragma_stmt
)
17012 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
17013 "omp target enter data");
17014 c_parser_skip_to_pragma_eol (parser
, false);
17019 = c_parser_omp_all_clauses (parser
, OMP_TARGET_ENTER_DATA_CLAUSE_MASK
,
17020 "#pragma omp target enter data");
17022 for (tree
*pc
= &clauses
; *pc
;)
17024 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
17025 switch (OMP_CLAUSE_MAP_KIND (*pc
))
17028 case GOMP_MAP_ALWAYS_TO
:
17029 case GOMP_MAP_ALLOC
:
17032 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
17033 case GOMP_MAP_ALWAYS_POINTER
:
17037 error_at (OMP_CLAUSE_LOCATION (*pc
),
17038 "%<#pragma omp target enter data%> with map-type other "
17039 "than %<to%> or %<alloc%> on %<map%> clause");
17040 *pc
= OMP_CLAUSE_CHAIN (*pc
);
17043 pc
= &OMP_CLAUSE_CHAIN (*pc
);
17050 "%<#pragma omp target enter data%> must contain at least "
17051 "one %<map%> clause");
17055 tree stmt
= make_node (OMP_TARGET_ENTER_DATA
);
17056 TREE_TYPE (stmt
) = void_type_node
;
17057 OMP_TARGET_ENTER_DATA_CLAUSES (stmt
) = clauses
;
17058 SET_EXPR_LOCATION (stmt
, loc
);
17064 # pragma omp target exit data target-data-clause[optseq] new-line */
17066 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
17067 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
17068 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
17069 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17070 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
17071 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
17074 c_parser_omp_target_exit_data (location_t loc
, c_parser
*parser
,
17075 enum pragma_context context
)
17077 bool data_seen
= false;
17078 if (c_parser_next_token_is (parser
, CPP_NAME
))
17080 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17081 if (strcmp (p
, "data") == 0)
17083 c_parser_consume_token (parser
);
17089 c_parser_error (parser
, "expected %<data%>");
17090 c_parser_skip_to_pragma_eol (parser
);
17094 if (context
== pragma_stmt
)
17096 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
17097 "omp target exit data");
17098 c_parser_skip_to_pragma_eol (parser
, false);
17103 = c_parser_omp_all_clauses (parser
, OMP_TARGET_EXIT_DATA_CLAUSE_MASK
,
17104 "#pragma omp target exit data");
17107 for (tree
*pc
= &clauses
; *pc
;)
17109 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
17110 switch (OMP_CLAUSE_MAP_KIND (*pc
))
17112 case GOMP_MAP_FROM
:
17113 case GOMP_MAP_ALWAYS_FROM
:
17114 case GOMP_MAP_RELEASE
:
17115 case GOMP_MAP_DELETE
:
17118 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
17119 case GOMP_MAP_ALWAYS_POINTER
:
17123 error_at (OMP_CLAUSE_LOCATION (*pc
),
17124 "%<#pragma omp target exit data%> with map-type other "
17125 "than %<from%>, %<release%> or %<delete%> on %<map%>"
17127 *pc
= OMP_CLAUSE_CHAIN (*pc
);
17130 pc
= &OMP_CLAUSE_CHAIN (*pc
);
17137 "%<#pragma omp target exit data%> must contain at least one "
17142 tree stmt
= make_node (OMP_TARGET_EXIT_DATA
);
17143 TREE_TYPE (stmt
) = void_type_node
;
17144 OMP_TARGET_EXIT_DATA_CLAUSES (stmt
) = clauses
;
17145 SET_EXPR_LOCATION (stmt
, loc
);
17151 # pragma omp target target-clause[optseq] new-line
17152 structured-block */
17154 #define OMP_TARGET_CLAUSE_MASK \
17155 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
17156 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
17157 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17158 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
17159 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
17160 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17161 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17162 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
17163 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
17166 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
17168 location_t loc
= c_parser_peek_token (parser
)->location
;
17169 c_parser_consume_pragma (parser
);
17170 tree
*pc
= NULL
, stmt
, block
;
17172 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
17174 c_parser_error (parser
, "expected declaration specifiers");
17175 c_parser_skip_to_pragma_eol (parser
);
17179 if (c_parser_next_token_is (parser
, CPP_NAME
))
17181 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17182 enum tree_code ccode
= ERROR_MARK
;
17184 if (strcmp (p
, "teams") == 0)
17186 else if (strcmp (p
, "parallel") == 0)
17187 ccode
= OMP_PARALLEL
;
17188 else if (strcmp (p
, "simd") == 0)
17190 if (ccode
!= ERROR_MARK
)
17192 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
17193 char p_name
[sizeof ("#pragma omp target teams distribute "
17194 "parallel for simd")];
17196 c_parser_consume_token (parser
);
17197 strcpy (p_name
, "#pragma omp target");
17198 if (!flag_openmp
) /* flag_openmp_simd */
17204 stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
17205 OMP_TARGET_CLAUSE_MASK
,
17209 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
,
17210 OMP_TARGET_CLAUSE_MASK
,
17214 stmt
= c_parser_omp_simd (loc
, parser
, p_name
,
17215 OMP_TARGET_CLAUSE_MASK
,
17219 gcc_unreachable ();
17221 return stmt
!= NULL_TREE
;
17223 keep_next_level ();
17224 tree block
= c_begin_compound_stmt (true), ret
;
17228 ret
= c_parser_omp_teams (loc
, parser
, p_name
,
17229 OMP_TARGET_CLAUSE_MASK
, cclauses
,
17233 ret
= c_parser_omp_parallel (loc
, parser
, p_name
,
17234 OMP_TARGET_CLAUSE_MASK
, cclauses
,
17238 ret
= c_parser_omp_simd (loc
, parser
, p_name
,
17239 OMP_TARGET_CLAUSE_MASK
, cclauses
,
17243 gcc_unreachable ();
17245 block
= c_end_compound_stmt (loc
, block
, true);
17246 if (ret
== NULL_TREE
)
17248 if (ccode
== OMP_TEAMS
)
17250 /* For combined target teams, ensure the num_teams and
17251 thread_limit clause expressions are evaluated on the host,
17252 before entering the target construct. */
17254 for (c
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
17255 c
; c
= OMP_CLAUSE_CHAIN (c
))
17256 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
17257 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
17258 && TREE_CODE (OMP_CLAUSE_OPERAND (c
, 0)) != INTEGER_CST
)
17260 tree expr
= OMP_CLAUSE_OPERAND (c
, 0);
17261 tree tmp
= create_tmp_var_raw (TREE_TYPE (expr
));
17262 expr
= build4 (TARGET_EXPR
, TREE_TYPE (expr
), tmp
,
17263 expr
, NULL_TREE
, NULL_TREE
);
17265 OMP_CLAUSE_OPERAND (c
, 0) = expr
;
17266 tree tc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
17267 OMP_CLAUSE_FIRSTPRIVATE
);
17268 OMP_CLAUSE_DECL (tc
) = tmp
;
17269 OMP_CLAUSE_CHAIN (tc
)
17270 = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
17271 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = tc
;
17274 tree stmt
= make_node (OMP_TARGET
);
17275 TREE_TYPE (stmt
) = void_type_node
;
17276 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
17277 OMP_TARGET_BODY (stmt
) = block
;
17278 OMP_TARGET_COMBINED (stmt
) = 1;
17280 pc
= &OMP_TARGET_CLAUSES (stmt
);
17281 goto check_clauses
;
17283 else if (!flag_openmp
) /* flag_openmp_simd */
17285 c_parser_skip_to_pragma_eol (parser
, false);
17288 else if (strcmp (p
, "data") == 0)
17290 c_parser_consume_token (parser
);
17291 c_parser_omp_target_data (loc
, parser
, if_p
);
17294 else if (strcmp (p
, "enter") == 0)
17296 c_parser_consume_token (parser
);
17297 c_parser_omp_target_enter_data (loc
, parser
, context
);
17300 else if (strcmp (p
, "exit") == 0)
17302 c_parser_consume_token (parser
);
17303 c_parser_omp_target_exit_data (loc
, parser
, context
);
17306 else if (strcmp (p
, "update") == 0)
17308 c_parser_consume_token (parser
);
17309 return c_parser_omp_target_update (loc
, parser
, context
);
17312 if (!flag_openmp
) /* flag_openmp_simd */
17314 c_parser_skip_to_pragma_eol (parser
, false);
17318 stmt
= make_node (OMP_TARGET
);
17319 TREE_TYPE (stmt
) = void_type_node
;
17321 OMP_TARGET_CLAUSES (stmt
)
17322 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
17323 "#pragma omp target");
17324 pc
= &OMP_TARGET_CLAUSES (stmt
);
17325 keep_next_level ();
17326 block
= c_begin_compound_stmt (true);
17327 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
17328 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
17330 SET_EXPR_LOCATION (stmt
, loc
);
17336 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
17337 switch (OMP_CLAUSE_MAP_KIND (*pc
))
17340 case GOMP_MAP_ALWAYS_TO
:
17341 case GOMP_MAP_FROM
:
17342 case GOMP_MAP_ALWAYS_FROM
:
17343 case GOMP_MAP_TOFROM
:
17344 case GOMP_MAP_ALWAYS_TOFROM
:
17345 case GOMP_MAP_ALLOC
:
17346 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
17347 case GOMP_MAP_ALWAYS_POINTER
:
17350 error_at (OMP_CLAUSE_LOCATION (*pc
),
17351 "%<#pragma omp target%> with map-type other "
17352 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
17353 "on %<map%> clause");
17354 *pc
= OMP_CLAUSE_CHAIN (*pc
);
17357 pc
= &OMP_CLAUSE_CHAIN (*pc
);
17363 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
17365 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
17366 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
17367 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
17368 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
17369 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
17370 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
17371 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
17374 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
17376 auto_vec
<c_token
> clauses
;
17377 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17379 c_token
*token
= c_parser_peek_token (parser
);
17380 if (token
->type
== CPP_EOF
)
17382 c_parser_skip_to_pragma_eol (parser
);
17385 clauses
.safe_push (*token
);
17386 c_parser_consume_token (parser
);
17388 clauses
.safe_push (*c_parser_peek_token (parser
));
17389 c_parser_skip_to_pragma_eol (parser
);
17391 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
17393 if (c_parser_peek_token (parser
)->pragma_kind
17394 != PRAGMA_OMP_DECLARE
17395 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
17396 || strcmp (IDENTIFIER_POINTER
17397 (c_parser_peek_2nd_token (parser
)->value
),
17400 c_parser_error (parser
,
17401 "%<#pragma omp declare simd%> must be followed by "
17402 "function declaration or definition or another "
17403 "%<#pragma omp declare simd%>");
17406 c_parser_consume_pragma (parser
);
17407 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17409 c_token
*token
= c_parser_peek_token (parser
);
17410 if (token
->type
== CPP_EOF
)
17412 c_parser_skip_to_pragma_eol (parser
);
17415 clauses
.safe_push (*token
);
17416 c_parser_consume_token (parser
);
17418 clauses
.safe_push (*c_parser_peek_token (parser
));
17419 c_parser_skip_to_pragma_eol (parser
);
17422 /* Make sure nothing tries to read past the end of the tokens. */
17424 memset (&eof_token
, 0, sizeof (eof_token
));
17425 eof_token
.type
= CPP_EOF
;
17426 clauses
.safe_push (eof_token
);
17427 clauses
.safe_push (eof_token
);
17431 case pragma_external
:
17432 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17433 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
17435 int ext
= disable_extension_diagnostics ();
17437 c_parser_consume_token (parser
);
17438 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17439 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
17440 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
17442 restore_extension_diagnostics (ext
);
17445 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
17448 case pragma_struct
:
17451 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
17452 "function declaration or definition");
17454 case pragma_compound
:
17455 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17456 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
17458 int ext
= disable_extension_diagnostics ();
17460 c_parser_consume_token (parser
);
17461 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17462 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
17463 if (c_parser_next_tokens_start_declaration (parser
))
17465 c_parser_declaration_or_fndef (parser
, true, true, true, true,
17466 true, NULL
, clauses
);
17467 restore_extension_diagnostics (ext
);
17470 restore_extension_diagnostics (ext
);
17472 else if (c_parser_next_tokens_start_declaration (parser
))
17474 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
17478 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
17479 "function declaration or definition");
17482 gcc_unreachable ();
17486 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
17487 and put that into "omp declare simd" attribute. */
17490 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
17491 vec
<c_token
> clauses
)
17493 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
17494 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
17495 has already processed the tokens. */
17496 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
17498 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
17500 error ("%<#pragma omp declare simd%> not immediately followed by "
17501 "a function declaration or definition");
17502 clauses
[0].type
= CPP_EOF
;
17505 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
17507 error_at (DECL_SOURCE_LOCATION (fndecl
),
17508 "%<#pragma omp declare simd%> not immediately followed by "
17509 "a single function declaration or definition");
17510 clauses
[0].type
= CPP_EOF
;
17514 if (parms
== NULL_TREE
)
17515 parms
= DECL_ARGUMENTS (fndecl
);
17517 unsigned int tokens_avail
= parser
->tokens_avail
;
17518 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
17521 parser
->tokens
= clauses
.address ();
17522 parser
->tokens_avail
= clauses
.length ();
17524 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
17525 while (parser
->tokens_avail
> 3)
17527 c_token
*token
= c_parser_peek_token (parser
);
17528 gcc_assert (token
->type
== CPP_NAME
17529 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
17530 c_parser_consume_token (parser
);
17531 parser
->in_pragma
= true;
17533 tree c
= NULL_TREE
;
17534 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
17535 "#pragma omp declare simd");
17536 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
17537 if (c
!= NULL_TREE
)
17538 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
17539 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
17540 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
17541 DECL_ATTRIBUTES (fndecl
) = c
;
17544 parser
->tokens
= &parser
->tokens_buf
[0];
17545 parser
->tokens_avail
= tokens_avail
;
17546 if (clauses
.exists ())
17547 clauses
[0].type
= CPP_PRAGMA
;
17552 # pragma omp declare target new-line
17553 declarations and definitions
17554 # pragma omp end declare target new-line
17557 # pragma omp declare target ( extended-list ) new-line
17559 # pragma omp declare target declare-target-clauses[seq] new-line */
17561 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
17562 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
17563 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
17566 c_parser_omp_declare_target (c_parser
*parser
)
17568 location_t loc
= c_parser_peek_token (parser
)->location
;
17569 tree clauses
= NULL_TREE
;
17570 if (c_parser_next_token_is (parser
, CPP_NAME
))
17571 clauses
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_TARGET_CLAUSE_MASK
,
17572 "#pragma omp declare target");
17573 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
17575 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
17577 clauses
= c_finish_omp_clauses (clauses
, C_ORT_OMP
);
17578 c_parser_skip_to_pragma_eol (parser
);
17582 c_parser_skip_to_pragma_eol (parser
);
17583 current_omp_declare_target_attribute
++;
17586 if (current_omp_declare_target_attribute
)
17587 error_at (loc
, "%<#pragma omp declare target%> with clauses in between "
17588 "%<#pragma omp declare target%> without clauses and "
17589 "%<#pragma omp end declare target%>");
17590 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
17592 tree t
= OMP_CLAUSE_DECL (c
), id
;
17593 tree at1
= lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t
));
17594 tree at2
= lookup_attribute ("omp declare target link",
17595 DECL_ATTRIBUTES (t
));
17596 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINK
)
17598 id
= get_identifier ("omp declare target link");
17599 std::swap (at1
, at2
);
17602 id
= get_identifier ("omp declare target");
17605 error_at (OMP_CLAUSE_LOCATION (c
),
17606 "%qD specified both in declare target %<link%> and %<to%>"
17612 DECL_ATTRIBUTES (t
) = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (t
));
17613 if (TREE_CODE (t
) != FUNCTION_DECL
&& !is_global_var (t
))
17616 symtab_node
*node
= symtab_node::get (t
);
17619 node
->offloadable
= 1;
17620 if (ENABLE_OFFLOADING
)
17622 g
->have_offload
= true;
17623 if (is_a
<varpool_node
*> (node
))
17624 vec_safe_push (offload_vars
, t
);
17632 c_parser_omp_end_declare_target (c_parser
*parser
)
17634 location_t loc
= c_parser_peek_token (parser
)->location
;
17635 c_parser_consume_pragma (parser
);
17636 if (c_parser_next_token_is (parser
, CPP_NAME
)
17637 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
17640 c_parser_consume_token (parser
);
17641 if (c_parser_next_token_is (parser
, CPP_NAME
)
17642 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
17644 c_parser_consume_token (parser
);
17647 c_parser_error (parser
, "expected %<target%>");
17648 c_parser_skip_to_pragma_eol (parser
);
17654 c_parser_error (parser
, "expected %<declare%>");
17655 c_parser_skip_to_pragma_eol (parser
);
17658 c_parser_skip_to_pragma_eol (parser
);
17659 if (!current_omp_declare_target_attribute
)
17660 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
17661 "%<#pragma omp declare target%>");
17663 current_omp_declare_target_attribute
--;
17668 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17669 initializer-clause[opt] new-line
17671 initializer-clause:
17672 initializer (omp_priv = initializer)
17673 initializer (function-name (argument-list)) */
17676 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
17678 unsigned int tokens_avail
= 0, i
;
17679 vec
<tree
> types
= vNULL
;
17680 vec
<c_token
> clauses
= vNULL
;
17681 enum tree_code reduc_code
= ERROR_MARK
;
17682 tree reduc_id
= NULL_TREE
;
17684 location_t rloc
= c_parser_peek_token (parser
)->location
;
17686 if (context
== pragma_struct
|| context
== pragma_param
)
17688 error ("%<#pragma omp declare reduction%> not at file or block scope");
17692 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17695 switch (c_parser_peek_token (parser
)->type
)
17698 reduc_code
= PLUS_EXPR
;
17701 reduc_code
= MULT_EXPR
;
17704 reduc_code
= MINUS_EXPR
;
17707 reduc_code
= BIT_AND_EXPR
;
17710 reduc_code
= BIT_XOR_EXPR
;
17713 reduc_code
= BIT_IOR_EXPR
;
17716 reduc_code
= TRUTH_ANDIF_EXPR
;
17719 reduc_code
= TRUTH_ORIF_EXPR
;
17723 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17724 if (strcmp (p
, "min") == 0)
17726 reduc_code
= MIN_EXPR
;
17729 if (strcmp (p
, "max") == 0)
17731 reduc_code
= MAX_EXPR
;
17734 reduc_id
= c_parser_peek_token (parser
)->value
;
17737 c_parser_error (parser
,
17738 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
17739 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
17743 tree orig_reduc_id
, reduc_decl
;
17744 orig_reduc_id
= reduc_id
;
17745 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
17746 reduc_decl
= c_omp_reduction_decl (reduc_id
);
17747 c_parser_consume_token (parser
);
17749 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
17754 location_t loc
= c_parser_peek_token (parser
)->location
;
17755 struct c_type_name
*ctype
= c_parser_type_name (parser
);
17758 type
= groktypename (ctype
, NULL
, NULL
);
17759 if (type
== error_mark_node
)
17761 else if ((INTEGRAL_TYPE_P (type
)
17762 || TREE_CODE (type
) == REAL_TYPE
17763 || TREE_CODE (type
) == COMPLEX_TYPE
)
17764 && orig_reduc_id
== NULL_TREE
)
17765 error_at (loc
, "predeclared arithmetic type in "
17766 "%<#pragma omp declare reduction%>");
17767 else if (TREE_CODE (type
) == FUNCTION_TYPE
17768 || TREE_CODE (type
) == ARRAY_TYPE
)
17769 error_at (loc
, "function or array type in "
17770 "%<#pragma omp declare reduction%>");
17771 else if (TYPE_ATOMIC (type
))
17772 error_at (loc
, "%<_Atomic%> qualified type in "
17773 "%<#pragma omp declare reduction%>");
17774 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
17775 error_at (loc
, "const, volatile or restrict qualified type in "
17776 "%<#pragma omp declare reduction%>");
17780 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
17781 if (comptypes (TREE_PURPOSE (t
), type
))
17783 error_at (loc
, "redeclaration of %qs "
17784 "%<#pragma omp declare reduction%> for "
17786 IDENTIFIER_POINTER (reduc_id
)
17787 + sizeof ("omp declare reduction ") - 1,
17790 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
17792 error_at (ploc
, "previous %<#pragma omp declare "
17796 if (t
== NULL_TREE
)
17797 types
.safe_push (type
);
17799 if (c_parser_next_token_is (parser
, CPP_COMMA
))
17800 c_parser_consume_token (parser
);
17808 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
17809 || types
.is_empty ())
17812 clauses
.release ();
17816 c_token
*token
= c_parser_peek_token (parser
);
17817 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
17819 c_parser_consume_token (parser
);
17821 c_parser_skip_to_pragma_eol (parser
);
17825 if (types
.length () > 1)
17827 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17829 c_token
*token
= c_parser_peek_token (parser
);
17830 if (token
->type
== CPP_EOF
)
17832 clauses
.safe_push (*token
);
17833 c_parser_consume_token (parser
);
17835 clauses
.safe_push (*c_parser_peek_token (parser
));
17836 c_parser_skip_to_pragma_eol (parser
);
17838 /* Make sure nothing tries to read past the end of the tokens. */
17840 memset (&eof_token
, 0, sizeof (eof_token
));
17841 eof_token
.type
= CPP_EOF
;
17842 clauses
.safe_push (eof_token
);
17843 clauses
.safe_push (eof_token
);
17846 int errs
= errorcount
;
17847 FOR_EACH_VEC_ELT (types
, i
, type
)
17849 tokens_avail
= parser
->tokens_avail
;
17850 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
17851 if (!clauses
.is_empty ())
17853 parser
->tokens
= clauses
.address ();
17854 parser
->tokens_avail
= clauses
.length ();
17855 parser
->in_pragma
= true;
17858 bool nested
= current_function_decl
!= NULL_TREE
;
17860 c_push_function_context ();
17861 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
17862 reduc_id
, default_function_type
);
17863 current_function_decl
= fndecl
;
17864 allocate_struct_function (fndecl
, true);
17866 tree stmt
= push_stmt_list ();
17867 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
17868 warn about these. */
17869 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17870 get_identifier ("omp_out"), type
);
17871 DECL_ARTIFICIAL (omp_out
) = 1;
17872 DECL_CONTEXT (omp_out
) = fndecl
;
17873 pushdecl (omp_out
);
17874 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17875 get_identifier ("omp_in"), type
);
17876 DECL_ARTIFICIAL (omp_in
) = 1;
17877 DECL_CONTEXT (omp_in
) = fndecl
;
17879 struct c_expr combiner
= c_parser_expression (parser
);
17880 struct c_expr initializer
;
17881 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
17883 initializer
.set_error ();
17884 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17886 else if (c_parser_next_token_is (parser
, CPP_NAME
)
17887 && strcmp (IDENTIFIER_POINTER
17888 (c_parser_peek_token (parser
)->value
),
17889 "initializer") == 0)
17891 c_parser_consume_token (parser
);
17894 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17895 get_identifier ("omp_priv"), type
);
17896 DECL_ARTIFICIAL (omp_priv
) = 1;
17897 DECL_INITIAL (omp_priv
) = error_mark_node
;
17898 DECL_CONTEXT (omp_priv
) = fndecl
;
17899 pushdecl (omp_priv
);
17900 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17901 get_identifier ("omp_orig"), type
);
17902 DECL_ARTIFICIAL (omp_orig
) = 1;
17903 DECL_CONTEXT (omp_orig
) = fndecl
;
17904 pushdecl (omp_orig
);
17905 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17907 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
17909 c_parser_error (parser
, "expected %<omp_priv%> or "
17913 else if (strcmp (IDENTIFIER_POINTER
17914 (c_parser_peek_token (parser
)->value
),
17917 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
17918 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
17920 c_parser_error (parser
, "expected function-name %<(%>");
17924 initializer
= c_parser_postfix_expression (parser
);
17925 if (initializer
.value
17926 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
17929 tree c
= initializer
.value
;
17930 for (j
= 0; j
< call_expr_nargs (c
); j
++)
17932 tree a
= CALL_EXPR_ARG (c
, j
);
17934 if (TREE_CODE (a
) == ADDR_EXPR
17935 && TREE_OPERAND (a
, 0) == omp_priv
)
17938 if (j
== call_expr_nargs (c
))
17939 error ("one of the initializer call arguments should be "
17945 c_parser_consume_token (parser
);
17946 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
17950 tree st
= push_stmt_list ();
17951 location_t loc
= c_parser_peek_token (parser
)->location
;
17952 rich_location
richloc (line_table
, loc
);
17953 start_init (omp_priv
, NULL_TREE
, 0, &richloc
);
17954 struct c_expr init
= c_parser_initializer (parser
);
17956 finish_decl (omp_priv
, loc
, init
.value
,
17957 init
.original_type
, NULL_TREE
);
17958 pop_stmt_list (st
);
17962 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17968 c_parser_skip_to_pragma_eol (parser
);
17970 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
17971 DECL_INITIAL (reduc_decl
));
17972 DECL_INITIAL (reduc_decl
) = t
;
17973 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
17974 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
17975 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
17976 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
17977 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
17978 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
17981 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
17982 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
17983 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
17984 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
17985 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
17986 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17987 walk_tree (&DECL_INITIAL (omp_priv
),
17988 c_check_omp_declare_reduction_r
,
17989 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17993 pop_stmt_list (stmt
);
17995 if (cfun
->language
!= NULL
)
17997 ggc_free (cfun
->language
);
17998 cfun
->language
= NULL
;
18001 current_function_decl
= NULL_TREE
;
18003 c_pop_function_context ();
18005 if (!clauses
.is_empty ())
18007 parser
->tokens
= &parser
->tokens_buf
[0];
18008 parser
->tokens_avail
= tokens_avail
;
18012 if (errs
!= errorcount
)
18016 clauses
.release ();
18022 #pragma omp declare simd declare-simd-clauses[optseq] new-line
18023 #pragma omp declare reduction (reduction-id : typename-list : expression) \
18024 initializer-clause[opt] new-line
18025 #pragma omp declare target new-line */
18028 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
18030 c_parser_consume_pragma (parser
);
18031 if (c_parser_next_token_is (parser
, CPP_NAME
))
18033 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
18034 if (strcmp (p
, "simd") == 0)
18036 /* c_parser_consume_token (parser); done in
18037 c_parser_omp_declare_simd. */
18038 c_parser_omp_declare_simd (parser
, context
);
18041 if (strcmp (p
, "reduction") == 0)
18043 c_parser_consume_token (parser
);
18044 c_parser_omp_declare_reduction (parser
, context
);
18047 if (!flag_openmp
) /* flag_openmp_simd */
18049 c_parser_skip_to_pragma_eol (parser
, false);
18052 if (strcmp (p
, "target") == 0)
18054 c_parser_consume_token (parser
);
18055 c_parser_omp_declare_target (parser
);
18060 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
18062 c_parser_skip_to_pragma_eol (parser
);
18066 #pragma omp taskloop taskloop-clause[optseq] new-line
18069 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
18072 #define OMP_TASKLOOP_CLAUSE_MASK \
18073 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
18074 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
18075 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
18076 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
18077 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
18078 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
18079 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
18080 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
18081 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
18082 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
18083 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
18084 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
18085 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
18086 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
18089 c_parser_omp_taskloop (location_t loc
, c_parser
*parser
,
18090 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
18093 tree clauses
, block
, ret
;
18095 strcat (p_name
, " taskloop");
18096 mask
|= OMP_TASKLOOP_CLAUSE_MASK
;
18098 if (c_parser_next_token_is (parser
, CPP_NAME
))
18100 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
18102 if (strcmp (p
, "simd") == 0)
18104 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
18105 if (cclauses
== NULL
)
18106 cclauses
= cclauses_buf
;
18107 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_REDUCTION
);
18108 c_parser_consume_token (parser
);
18109 if (!flag_openmp
) /* flag_openmp_simd */
18110 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
18112 block
= c_begin_compound_stmt (true);
18113 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
18114 block
= c_end_compound_stmt (loc
, block
, true);
18117 ret
= make_node (OMP_TASKLOOP
);
18118 TREE_TYPE (ret
) = void_type_node
;
18119 OMP_FOR_BODY (ret
) = block
;
18120 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
18121 SET_EXPR_LOCATION (ret
, loc
);
18126 if (!flag_openmp
) /* flag_openmp_simd */
18128 c_parser_skip_to_pragma_eol (parser
, false);
18132 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
18135 omp_split_clauses (loc
, OMP_TASKLOOP
, mask
, clauses
, cclauses
);
18136 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
18139 block
= c_begin_compound_stmt (true);
18140 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_TASKLOOP
, clauses
, NULL
, if_p
);
18141 block
= c_end_compound_stmt (loc
, block
, true);
18147 /* Main entry point to parsing most OpenMP pragmas. */
18150 c_parser_omp_construct (c_parser
*parser
, bool *if_p
)
18152 enum pragma_kind p_kind
;
18155 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
18156 omp_clause_mask
mask (0);
18158 loc
= c_parser_peek_token (parser
)->location
;
18159 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
18160 c_parser_consume_pragma (parser
);
18164 case PRAGMA_OACC_ATOMIC
:
18165 c_parser_omp_atomic (loc
, parser
);
18167 case PRAGMA_OACC_CACHE
:
18168 strcpy (p_name
, "#pragma acc");
18169 stmt
= c_parser_oacc_cache (loc
, parser
);
18171 case PRAGMA_OACC_DATA
:
18172 stmt
= c_parser_oacc_data (loc
, parser
, if_p
);
18174 case PRAGMA_OACC_HOST_DATA
:
18175 stmt
= c_parser_oacc_host_data (loc
, parser
, if_p
);
18177 case PRAGMA_OACC_KERNELS
:
18178 case PRAGMA_OACC_PARALLEL
:
18179 strcpy (p_name
, "#pragma acc");
18180 stmt
= c_parser_oacc_kernels_parallel (loc
, parser
, p_kind
, p_name
,
18183 case PRAGMA_OACC_LOOP
:
18184 strcpy (p_name
, "#pragma acc");
18185 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18187 case PRAGMA_OACC_WAIT
:
18188 strcpy (p_name
, "#pragma wait");
18189 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
18191 case PRAGMA_OMP_ATOMIC
:
18192 c_parser_omp_atomic (loc
, parser
);
18194 case PRAGMA_OMP_CRITICAL
:
18195 stmt
= c_parser_omp_critical (loc
, parser
, if_p
);
18197 case PRAGMA_OMP_DISTRIBUTE
:
18198 strcpy (p_name
, "#pragma omp");
18199 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18201 case PRAGMA_OMP_FOR
:
18202 strcpy (p_name
, "#pragma omp");
18203 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18205 case PRAGMA_OMP_MASTER
:
18206 stmt
= c_parser_omp_master (loc
, parser
, if_p
);
18208 case PRAGMA_OMP_PARALLEL
:
18209 strcpy (p_name
, "#pragma omp");
18210 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18212 case PRAGMA_OMP_SECTIONS
:
18213 strcpy (p_name
, "#pragma omp");
18214 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
18216 case PRAGMA_OMP_SIMD
:
18217 strcpy (p_name
, "#pragma omp");
18218 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18220 case PRAGMA_OMP_SINGLE
:
18221 stmt
= c_parser_omp_single (loc
, parser
, if_p
);
18223 case PRAGMA_OMP_TASK
:
18224 stmt
= c_parser_omp_task (loc
, parser
, if_p
);
18226 case PRAGMA_OMP_TASKGROUP
:
18227 stmt
= c_parser_omp_taskgroup (parser
, if_p
);
18229 case PRAGMA_OMP_TASKLOOP
:
18230 strcpy (p_name
, "#pragma omp");
18231 stmt
= c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18233 case PRAGMA_OMP_TEAMS
:
18234 strcpy (p_name
, "#pragma omp");
18235 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18238 gcc_unreachable ();
18242 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
18247 # pragma omp threadprivate (variable-list) */
18250 c_parser_omp_threadprivate (c_parser
*parser
)
18255 c_parser_consume_pragma (parser
);
18256 loc
= c_parser_peek_token (parser
)->location
;
18257 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
18259 /* Mark every variable in VARS to be assigned thread local storage. */
18260 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
18262 tree v
= TREE_PURPOSE (t
);
18264 /* FIXME diagnostics: Ideally we should keep individual
18265 locations for all the variables in the var list to make the
18266 following errors more precise. Perhaps
18267 c_parser_omp_var_list_parens() should construct a list of
18268 locations to go along with the var list. */
18270 /* If V had already been marked threadprivate, it doesn't matter
18271 whether it had been used prior to this point. */
18273 error_at (loc
, "%qD is not a variable", v
);
18274 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
18275 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
18276 else if (! is_global_var (v
))
18277 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
18278 else if (TREE_TYPE (v
) == error_mark_node
)
18280 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
18281 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
18284 if (! DECL_THREAD_LOCAL_P (v
))
18286 set_decl_tls_model (v
, decl_default_tls_model (v
));
18287 /* If rtl has been already set for this var, call
18288 make_decl_rtl once again, so that encode_section_info
18289 has a chance to look at the new decl flags. */
18290 if (DECL_RTL_SET_P (v
))
18293 C_DECL_THREADPRIVATE_P (v
) = 1;
18297 c_parser_skip_to_pragma_eol (parser
);
18300 /* Parse a transaction attribute (GCC Extension).
18302 transaction-attribute:
18306 The transactional memory language description is written for C++,
18307 and uses the C++0x attribute syntax. For compatibility, allow the
18308 bracket style for transactions in C as well. */
18311 c_parser_transaction_attributes (c_parser
*parser
)
18313 tree attr_name
, attr
= NULL
;
18315 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
18316 return c_parser_attributes (parser
);
18318 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
18320 c_parser_consume_token (parser
);
18321 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
18324 attr_name
= c_parser_attribute_any_word (parser
);
18327 c_parser_consume_token (parser
);
18328 attr
= build_tree_list (attr_name
, NULL_TREE
);
18331 c_parser_error (parser
, "expected identifier");
18333 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18335 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18339 /* Parse a __transaction_atomic or __transaction_relaxed statement
18342 transaction-statement:
18343 __transaction_atomic transaction-attribute[opt] compound-statement
18344 __transaction_relaxed compound-statement
18346 Note that the only valid attribute is: "outer".
18350 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
18352 unsigned int old_in
= parser
->in_transaction
;
18353 unsigned int this_in
= 1, new_in
;
18354 location_t loc
= c_parser_peek_token (parser
)->location
;
18357 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18358 || keyword
== RID_TRANSACTION_RELAXED
)
18359 && c_parser_next_token_is_keyword (parser
, keyword
));
18360 c_parser_consume_token (parser
);
18362 if (keyword
== RID_TRANSACTION_RELAXED
)
18363 this_in
|= TM_STMT_ATTR_RELAXED
;
18366 attrs
= c_parser_transaction_attributes (parser
);
18368 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
18371 /* Keep track if we're in the lexical scope of an outer transaction. */
18372 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
18374 parser
->in_transaction
= new_in
;
18375 stmt
= c_parser_compound_statement (parser
);
18376 parser
->in_transaction
= old_in
;
18379 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
18381 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18382 "%<__transaction_atomic%> without transactional memory support enabled"
18383 : "%<__transaction_relaxed %> "
18384 "without transactional memory support enabled"));
18389 /* Parse a __transaction_atomic or __transaction_relaxed expression
18392 transaction-expression:
18393 __transaction_atomic ( expression )
18394 __transaction_relaxed ( expression )
18397 static struct c_expr
18398 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
18401 unsigned int old_in
= parser
->in_transaction
;
18402 unsigned int this_in
= 1;
18403 location_t loc
= c_parser_peek_token (parser
)->location
;
18406 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18407 || keyword
== RID_TRANSACTION_RELAXED
)
18408 && c_parser_next_token_is_keyword (parser
, keyword
));
18409 c_parser_consume_token (parser
);
18411 if (keyword
== RID_TRANSACTION_RELAXED
)
18412 this_in
|= TM_STMT_ATTR_RELAXED
;
18415 attrs
= c_parser_transaction_attributes (parser
);
18417 this_in
|= parse_tm_stmt_attr (attrs
, 0);
18420 parser
->in_transaction
= this_in
;
18421 matching_parens parens
;
18422 if (parens
.require_open (parser
))
18424 tree expr
= c_parser_expression (parser
).value
;
18425 ret
.original_type
= TREE_TYPE (expr
);
18426 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
18427 if (this_in
& TM_STMT_ATTR_RELAXED
)
18428 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
18429 SET_EXPR_LOCATION (ret
.value
, loc
);
18430 ret
.original_code
= TRANSACTION_EXPR
;
18431 if (!parens
.require_close (parser
))
18433 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
18441 ret
.original_code
= ERROR_MARK
;
18442 ret
.original_type
= NULL
;
18444 parser
->in_transaction
= old_in
;
18447 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18448 "%<__transaction_atomic%> without transactional memory support enabled"
18449 : "%<__transaction_relaxed %> "
18450 "without transactional memory support enabled"));
18452 set_c_expr_source_range (&ret
, loc
, loc
);
18457 /* Parse a __transaction_cancel statement (GCC Extension).
18459 transaction-cancel-statement:
18460 __transaction_cancel transaction-attribute[opt] ;
18462 Note that the only valid attribute is "outer".
18466 c_parser_transaction_cancel (c_parser
*parser
)
18468 location_t loc
= c_parser_peek_token (parser
)->location
;
18470 bool is_outer
= false;
18472 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
18473 c_parser_consume_token (parser
);
18475 attrs
= c_parser_transaction_attributes (parser
);
18477 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
18481 error_at (loc
, "%<__transaction_cancel%> without "
18482 "transactional memory support enabled");
18485 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
18487 error_at (loc
, "%<__transaction_cancel%> within a "
18488 "%<__transaction_relaxed%>");
18493 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
18494 && !is_tm_may_cancel_outer (current_function_decl
))
18496 error_at (loc
, "outer %<__transaction_cancel%> not "
18497 "within outer %<__transaction_atomic%>");
18498 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
18502 else if (parser
->in_transaction
== 0)
18504 error_at (loc
, "%<__transaction_cancel%> not within "
18505 "%<__transaction_atomic%>");
18509 return add_stmt (build_tm_abort_call (loc
, is_outer
));
18512 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
18515 /* Parse a single source file. */
18518 c_parse_file (void)
18520 /* Use local storage to begin. If the first token is a pragma, parse it.
18521 If it is #pragma GCC pch_preprocess, then this will load a PCH file
18522 which will cause garbage collection. */
18525 memset (&tparser
, 0, sizeof tparser
);
18526 tparser
.tokens
= &tparser
.tokens_buf
[0];
18527 the_parser
= &tparser
;
18529 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
18530 c_parser_pragma_pch_preprocess (&tparser
);
18532 the_parser
= ggc_alloc
<c_parser
> ();
18533 *the_parser
= tparser
;
18534 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
18535 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
18537 /* Initialize EH, if we've been told to do so. */
18538 if (flag_exceptions
)
18539 using_eh_for_cleanups ();
18541 c_parser_translation_unit (the_parser
);
18545 /* Parse the body of a function declaration marked with "__RTL".
18547 The RTL parser works on the level of characters read from a
18548 FILE *, whereas c_parser works at the level of tokens.
18549 Square this circle by consuming all of the tokens up to and
18550 including the closing brace, recording the start/end of the RTL
18551 fragment, and reopening the file and re-reading the relevant
18552 lines within the RTL parser.
18554 This requires the opening and closing braces of the C function
18555 to be on separate lines from the RTL they wrap.
18557 Take ownership of START_WITH_PASS, if non-NULL. */
18560 c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
)
18562 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
18564 free (start_with_pass
);
18568 location_t start_loc
= c_parser_peek_token (parser
)->location
;
18570 /* Consume all tokens, up to the closing brace, handling
18571 matching pairs of braces in the rtl dump. */
18572 int num_open_braces
= 1;
18575 switch (c_parser_peek_token (parser
)->type
)
18577 case CPP_OPEN_BRACE
:
18580 case CPP_CLOSE_BRACE
:
18581 if (--num_open_braces
== 0)
18582 goto found_closing_brace
;
18585 error_at (start_loc
, "no closing brace");
18586 free (start_with_pass
);
18591 c_parser_consume_token (parser
);
18594 found_closing_brace
:
18595 /* At the closing brace; record its location. */
18596 location_t end_loc
= c_parser_peek_token (parser
)->location
;
18598 /* Consume the closing brace. */
18599 c_parser_consume_token (parser
);
18601 /* Invoke the RTL parser. */
18602 if (!read_rtl_function_body_from_file_range (start_loc
, end_loc
))
18604 free (start_with_pass
);
18608 /* If a pass name was provided for START_WITH_PASS, run the backend
18609 accordingly now, on the cfun created above, transferring
18610 ownership of START_WITH_PASS. */
18611 if (start_with_pass
)
18612 run_rtl_passes (start_with_pass
);
18615 #include "gt-c-c-parser.h"