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 if (!MAY_HAVE_DEBUG_MARKER_STMTS
)
1660 tree stmt
= build0 (DEBUG_BEGIN_STMT
, void_type_node
);
1661 SET_EXPR_LOCATION (stmt
, loc
);
1665 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1666 6.7, 6.9.1, C11 6.7, 6.9.1). If FNDEF_OK is true, a function definition
1667 is accepted; otherwise (old-style parameter declarations) only other
1668 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1669 assertion is accepted; otherwise (old-style parameter declarations)
1670 it is not. If NESTED is true, we are inside a function or parsing
1671 old-style parameter declarations; any functions encountered are
1672 nested functions and declaration specifiers are required; otherwise
1673 we are at top level and functions are normal functions and
1674 declaration specifiers may be optional. If EMPTY_OK is true, empty
1675 declarations are OK (subject to all other constraints); otherwise
1676 (old-style parameter declarations) they are diagnosed. If
1677 START_ATTR_OK is true, the declaration specifiers may start with
1678 attributes; otherwise they may not.
1679 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1680 declaration when parsing an Objective-C foreach statement.
1681 FALLTHRU_ATTR_P is used to signal whether this function parsed
1682 "__attribute__((fallthrough));".
1685 declaration-specifiers init-declarator-list[opt] ;
1686 static_assert-declaration
1688 function-definition:
1689 declaration-specifiers[opt] declarator declaration-list[opt]
1694 declaration-list declaration
1696 init-declarator-list:
1698 init-declarator-list , init-declarator
1701 declarator simple-asm-expr[opt] attributes[opt]
1702 declarator simple-asm-expr[opt] attributes[opt] = initializer
1706 nested-function-definition:
1707 declaration-specifiers declarator declaration-list[opt]
1713 attributes objc-class-definition
1714 attributes objc-category-definition
1715 attributes objc-protocol-definition
1717 The simple-asm-expr and attributes are GNU extensions.
1719 This function does not handle __extension__; that is handled in its
1720 callers. ??? Following the old parser, __extension__ may start
1721 external declarations, declarations in functions and declarations
1722 at the start of "for" loops, but not old-style parameter
1725 C99 requires declaration specifiers in a function definition; the
1726 absence is diagnosed through the diagnosis of implicit int. In GNU
1727 C we also allow but diagnose declarations without declaration
1728 specifiers, but only at top level (elsewhere they conflict with
1731 In Objective-C, declarations of the looping variable in a foreach
1732 statement are exceptionally terminated by 'in' (for example, 'for
1733 (NSObject *object in array) { ... }').
1738 threadprivate-directive
1742 gimple-function-definition:
1743 declaration-specifiers[opt] __GIMPLE (gimple-or-rtl-pass-list) declarator
1744 declaration-list[opt] compound-statement
1746 rtl-function-definition:
1747 declaration-specifiers[opt] __RTL (gimple-or-rtl-pass-list) declarator
1748 declaration-list[opt] compound-statement */
1751 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1752 bool static_assert_ok
, bool empty_ok
,
1753 bool nested
, bool start_attr_ok
,
1754 tree
*objc_foreach_object_declaration
,
1755 vec
<c_token
> omp_declare_simd_clauses
,
1756 struct oacc_routine_data
*oacc_routine_data
,
1757 bool *fallthru_attr_p
)
1759 struct c_declspecs
*specs
;
1761 tree all_prefix_attrs
;
1762 bool diagnosed_no_specs
= false;
1763 location_t here
= c_parser_peek_token (parser
)->location
;
1765 add_debug_begin_stmt (c_parser_peek_token (parser
)->location
);
1767 if (static_assert_ok
1768 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1770 c_parser_static_assert_declaration (parser
);
1773 specs
= build_null_declspecs ();
1775 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1776 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1777 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1778 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1779 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1780 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1782 tree name
= c_parser_peek_token (parser
)->value
;
1784 /* Issue a warning about NAME being an unknown type name, perhaps
1785 with some kind of hint.
1786 If the user forgot a "struct" etc, suggest inserting
1787 it. Otherwise, attempt to look for misspellings. */
1788 gcc_rich_location
richloc (here
);
1789 if (tag_exists_p (RECORD_TYPE
, name
))
1791 /* This is not C++ with its implicit typedef. */
1792 richloc
.add_fixit_insert_before ("struct ");
1794 "unknown type name %qE;"
1795 " use %<struct%> keyword to refer to the type",
1798 else if (tag_exists_p (UNION_TYPE
, name
))
1800 richloc
.add_fixit_insert_before ("union ");
1802 "unknown type name %qE;"
1803 " use %<union%> keyword to refer to the type",
1806 else if (tag_exists_p (ENUMERAL_TYPE
, name
))
1808 richloc
.add_fixit_insert_before ("enum ");
1810 "unknown type name %qE;"
1811 " use %<enum%> keyword to refer to the type",
1816 name_hint hint
= lookup_name_fuzzy (name
, FUZZY_LOOKUP_TYPENAME
,
1820 richloc
.add_fixit_replace (hint
.suggestion ());
1822 "unknown type name %qE; did you mean %qs?",
1823 name
, hint
.suggestion ());
1826 error_at (here
, "unknown type name %qE", name
);
1829 /* Parse declspecs normally to get a correct pointer type, but avoid
1830 a further "fails to be a type name" error. Refuse nested functions
1831 since it is not how the user likely wants us to recover. */
1832 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1833 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1834 c_parser_peek_token (parser
)->value
= error_mark_node
;
1838 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1839 true, true, cla_nonabstract_decl
);
1842 c_parser_skip_to_end_of_block_or_statement (parser
);
1845 if (nested
&& !specs
->declspecs_seen_p
)
1847 c_parser_error (parser
, "expected declaration specifiers");
1848 c_parser_skip_to_end_of_block_or_statement (parser
);
1852 finish_declspecs (specs
);
1853 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1854 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1857 error_at (here
, "%<__auto_type%> in empty declaration");
1858 else if (specs
->typespec_kind
== ctsk_none
1859 && attribute_fallthrough_p (specs
->attrs
))
1861 if (fallthru_attr_p
!= NULL
)
1862 *fallthru_attr_p
= true;
1863 tree fn
= build_call_expr_internal_loc (here
, IFN_FALLTHROUGH
,
1871 shadow_tag_warned (specs
, 1);
1872 pedwarn (here
, 0, "empty declaration");
1874 c_parser_consume_token (parser
);
1875 if (oacc_routine_data
)
1876 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1880 /* Provide better error recovery. Note that a type name here is usually
1881 better diagnosed as a redeclaration. */
1883 && specs
->typespec_kind
== ctsk_tagdef
1884 && c_parser_next_token_starts_declspecs (parser
)
1885 && !c_parser_next_token_is (parser
, CPP_NAME
))
1887 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1888 parser
->error
= false;
1889 shadow_tag_warned (specs
, 1);
1892 else if (c_dialect_objc () && !auto_type_p
)
1894 /* Prefix attributes are an error on method decls. */
1895 switch (c_parser_peek_token (parser
)->type
)
1899 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1903 warning_at (c_parser_peek_token (parser
)->location
,
1905 "prefix attributes are ignored for methods");
1906 specs
->attrs
= NULL_TREE
;
1909 c_parser_objc_method_definition (parser
);
1911 c_parser_objc_methodproto (parser
);
1917 /* This is where we parse 'attributes @interface ...',
1918 'attributes @implementation ...', 'attributes @protocol ...'
1919 (where attributes could be, for example, __attribute__
1922 switch (c_parser_peek_token (parser
)->keyword
)
1924 case RID_AT_INTERFACE
:
1926 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1928 c_parser_objc_class_definition (parser
, specs
->attrs
);
1932 case RID_AT_IMPLEMENTATION
:
1934 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1938 warning_at (c_parser_peek_token (parser
)->location
,
1940 "prefix attributes are ignored for implementations");
1941 specs
->attrs
= NULL_TREE
;
1943 c_parser_objc_class_definition (parser
, NULL_TREE
);
1947 case RID_AT_PROTOCOL
:
1949 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1951 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1958 case RID_AT_PROPERTY
:
1961 c_parser_error (parser
, "unexpected attribute");
1962 specs
->attrs
= NULL
;
1969 else if (attribute_fallthrough_p (specs
->attrs
))
1970 warning_at (here
, OPT_Wattributes
,
1971 "%<fallthrough%> attribute not followed by %<;%>");
1973 pending_xref_error ();
1974 prefix_attrs
= specs
->attrs
;
1975 all_prefix_attrs
= prefix_attrs
;
1976 specs
->attrs
= NULL_TREE
;
1979 struct c_declarator
*declarator
;
1982 tree fnbody
= NULL_TREE
;
1983 /* Declaring either one or more declarators (in which case we
1984 should diagnose if there were no declaration specifiers) or a
1985 function definition (in which case the diagnostic for
1986 implicit int suffices). */
1987 declarator
= c_parser_declarator (parser
,
1988 specs
->typespec_kind
!= ctsk_none
,
1989 C_DTR_NORMAL
, &dummy
);
1990 if (declarator
== NULL
)
1992 if (omp_declare_simd_clauses
.exists ())
1993 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1994 omp_declare_simd_clauses
);
1995 if (oacc_routine_data
)
1996 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1997 c_parser_skip_to_end_of_block_or_statement (parser
);
2000 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
2003 "%<__auto_type%> requires a plain identifier"
2005 c_parser_skip_to_end_of_block_or_statement (parser
);
2008 if (c_parser_next_token_is (parser
, CPP_EQ
)
2009 || c_parser_next_token_is (parser
, CPP_COMMA
)
2010 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
2011 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
2012 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
2013 || c_parser_next_token_is_keyword (parser
, RID_IN
))
2015 tree asm_name
= NULL_TREE
;
2016 tree postfix_attrs
= NULL_TREE
;
2017 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
2019 diagnosed_no_specs
= true;
2020 pedwarn (here
, 0, "data definition has no type or storage class");
2022 /* Having seen a data definition, there cannot now be a
2023 function definition. */
2025 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
2026 asm_name
= c_parser_simple_asm_expr (parser
);
2027 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2029 postfix_attrs
= c_parser_attributes (parser
);
2030 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2032 /* This means there is an attribute specifier after
2033 the declarator in a function definition. Provide
2034 some more information for the user. */
2035 error_at (here
, "attributes should be specified before the "
2036 "declarator in a function definition");
2037 c_parser_skip_to_end_of_block_or_statement (parser
);
2041 if (c_parser_next_token_is (parser
, CPP_EQ
))
2045 location_t init_loc
;
2046 c_parser_consume_token (parser
);
2049 init_loc
= c_parser_peek_token (parser
)->location
;
2050 rich_location
richloc (line_table
, init_loc
);
2051 start_init (NULL_TREE
, asm_name
, global_bindings_p (), &richloc
);
2052 /* A parameter is initialized, which is invalid. Don't
2053 attempt to instrument the initializer. */
2054 int flag_sanitize_save
= flag_sanitize
;
2055 if (nested
&& !empty_ok
)
2057 init
= c_parser_expr_no_commas (parser
, NULL
);
2058 flag_sanitize
= flag_sanitize_save
;
2059 if (TREE_CODE (init
.value
) == COMPONENT_REF
2060 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
2062 "%<__auto_type%> used with a bit-field"
2064 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
2065 tree init_type
= TREE_TYPE (init
.value
);
2066 /* As with typeof, remove all qualifiers from atomic types. */
2067 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
2069 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
2070 bool vm_type
= variably_modified_type_p (init_type
,
2073 init
.value
= save_expr (init
.value
);
2075 specs
->typespec_kind
= ctsk_typeof
;
2076 specs
->locations
[cdw_typedef
] = init_loc
;
2077 specs
->typedef_p
= true;
2078 specs
->type
= init_type
;
2081 bool maybe_const
= true;
2082 tree type_expr
= c_fully_fold (init
.value
, false,
2084 specs
->expr_const_operands
&= maybe_const
;
2086 specs
->expr
= build2 (COMPOUND_EXPR
,
2087 TREE_TYPE (type_expr
),
2088 specs
->expr
, type_expr
);
2090 specs
->expr
= type_expr
;
2092 d
= start_decl (declarator
, specs
, true,
2093 chainon (postfix_attrs
, all_prefix_attrs
));
2095 d
= error_mark_node
;
2096 if (omp_declare_simd_clauses
.exists ())
2097 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
2098 omp_declare_simd_clauses
);
2102 /* The declaration of the variable is in effect while
2103 its initializer is parsed. */
2104 d
= start_decl (declarator
, specs
, true,
2105 chainon (postfix_attrs
, all_prefix_attrs
));
2107 d
= error_mark_node
;
2108 if (omp_declare_simd_clauses
.exists ())
2109 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
2110 omp_declare_simd_clauses
);
2111 init_loc
= c_parser_peek_token (parser
)->location
;
2112 rich_location
richloc (line_table
, init_loc
);
2113 start_init (d
, asm_name
, global_bindings_p (), &richloc
);
2114 /* A parameter is initialized, which is invalid. Don't
2115 attempt to instrument the initializer. */
2116 int flag_sanitize_save
= flag_sanitize
;
2117 if (TREE_CODE (d
) == PARM_DECL
)
2119 init
= c_parser_initializer (parser
);
2120 flag_sanitize
= flag_sanitize_save
;
2123 if (oacc_routine_data
)
2124 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2125 if (d
!= error_mark_node
)
2127 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
2128 finish_decl (d
, init_loc
, init
.value
,
2129 init
.original_type
, asm_name
);
2137 "%<__auto_type%> requires an initialized "
2138 "data declaration");
2139 c_parser_skip_to_end_of_block_or_statement (parser
);
2142 tree d
= start_decl (declarator
, specs
, false,
2143 chainon (postfix_attrs
,
2145 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
2146 if (declarator
->kind
== cdk_function
)
2147 if (DECL_ARGUMENTS (d
) == NULL_TREE
)
2148 DECL_ARGUMENTS (d
) = declarator
->u
.arg_info
->parms
;
2149 if (omp_declare_simd_clauses
.exists ())
2151 tree parms
= NULL_TREE
;
2152 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
2154 struct c_declarator
*ce
= declarator
;
2156 if (ce
->kind
== cdk_function
)
2158 parms
= ce
->u
.arg_info
->parms
;
2162 ce
= ce
->declarator
;
2165 temp_store_parm_decls (d
, parms
);
2166 c_finish_omp_declare_simd (parser
, d
, parms
,
2167 omp_declare_simd_clauses
);
2169 temp_pop_parm_decls ();
2171 if (oacc_routine_data
)
2172 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2174 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
2175 NULL_TREE
, asm_name
);
2177 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2180 *objc_foreach_object_declaration
= d
;
2182 *objc_foreach_object_declaration
= error_mark_node
;
2185 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2190 "%<__auto_type%> may only be used with"
2191 " a single declarator");
2192 c_parser_skip_to_end_of_block_or_statement (parser
);
2195 c_parser_consume_token (parser
);
2196 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2197 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2200 all_prefix_attrs
= prefix_attrs
;
2203 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2205 c_parser_consume_token (parser
);
2208 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2210 /* This can only happen in Objective-C: we found the
2211 'in' that terminates the declaration inside an
2212 Objective-C foreach statement. Do not consume the
2213 token, so that the caller can use it to determine
2214 that this indeed is a foreach context. */
2219 c_parser_error (parser
, "expected %<,%> or %<;%>");
2220 c_parser_skip_to_end_of_block_or_statement (parser
);
2224 else if (auto_type_p
)
2227 "%<__auto_type%> requires an initialized data declaration");
2228 c_parser_skip_to_end_of_block_or_statement (parser
);
2233 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
2234 "%<asm%> or %<__attribute__%>");
2235 c_parser_skip_to_end_of_block_or_statement (parser
);
2238 /* Function definition (nested or otherwise). */
2241 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
2242 c_push_function_context ();
2244 if (!start_function (specs
, declarator
, all_prefix_attrs
))
2246 /* At this point we've consumed:
2247 declaration-specifiers declarator
2248 and the next token isn't CPP_EQ, CPP_COMMA, CPP_SEMICOLON,
2249 RID_ASM, RID_ATTRIBUTE, or RID_IN,
2251 declaration-specifiers declarator
2252 aren't grokkable as a function definition, so we have
2254 gcc_assert (!c_parser_next_token_is (parser
, CPP_SEMICOLON
));
2255 if (c_parser_next_token_starts_declspecs (parser
))
2258 declaration-specifiers declarator decl-specs
2259 then assume we have a missing semicolon, which would
2261 declaration-specifiers declarator decl-specs
2264 <~~~~~~~~~ declaration ~~~~~~~~~~>
2265 Use c_parser_require to get an error with a fix-it hint. */
2266 c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>");
2267 parser
->error
= false;
2271 /* This can appear in many cases looking nothing like a
2272 function definition, so we don't give a more specific
2273 error suggesting there was one. */
2274 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2275 "or %<__attribute__%>");
2278 c_pop_function_context ();
2282 if (DECL_DECLARED_INLINE_P (current_function_decl
))
2283 tv
= TV_PARSE_INLINE
;
2286 auto_timevar
at (g_timer
, tv
);
2288 /* Parse old-style parameter declarations. ??? Attributes are
2289 not allowed to start declaration specifiers here because of a
2290 syntax conflict between a function declaration with attribute
2291 suffix and a function definition with an attribute prefix on
2292 first old-style parameter declaration. Following the old
2293 parser, they are not accepted on subsequent old-style
2294 parameter declarations either. However, there is no
2295 ambiguity after the first declaration, nor indeed on the
2296 first as long as we don't allow postfix attributes after a
2297 declarator with a nonempty identifier list in a definition;
2298 and postfix attributes have never been accepted here in
2299 function definitions either. */
2300 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
2301 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
2302 c_parser_declaration_or_fndef (parser
, false, false, false,
2303 true, false, NULL
, vNULL
);
2304 store_parm_decls ();
2305 if (omp_declare_simd_clauses
.exists ())
2306 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
2307 omp_declare_simd_clauses
);
2308 if (oacc_routine_data
)
2309 c_finish_oacc_routine (oacc_routine_data
, current_function_decl
, true);
2310 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
2311 = c_parser_peek_token (parser
)->location
;
2313 /* If the definition was marked with __GIMPLE then parse the
2314 function body as GIMPLE. */
2315 if (specs
->gimple_p
)
2317 cfun
->pass_startwith
= specs
->gimple_or_rtl_pass
;
2318 bool saved
= in_late_binary_op
;
2319 in_late_binary_op
= true;
2320 c_parser_parse_gimple_body (parser
);
2321 in_late_binary_op
= saved
;
2323 /* Similarly, if it was marked with __RTL, use the RTL parser now,
2324 consuming the function body. */
2325 else if (specs
->rtl_p
)
2327 c_parser_parse_rtl_body (parser
, specs
->gimple_or_rtl_pass
);
2329 /* Normally, store_parm_decls sets next_is_function_body,
2330 anticipating a function body. We need a push_scope/pop_scope
2331 pair to flush out this state, or subsequent function parsing
2340 fnbody
= c_parser_compound_statement (parser
);
2341 tree fndecl
= current_function_decl
;
2344 tree decl
= current_function_decl
;
2345 /* Mark nested functions as needing static-chain initially.
2346 lower_nested_functions will recompute it but the
2347 DECL_STATIC_CHAIN flag is also used before that happens,
2348 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2349 DECL_STATIC_CHAIN (decl
) = 1;
2352 c_pop_function_context ();
2353 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
2361 /* Get rid of the empty stmt list for GIMPLE. */
2362 if (specs
->gimple_p
)
2363 DECL_SAVED_TREE (fndecl
) = NULL_TREE
;
2369 /* Parse an asm-definition (asm() outside a function body). This is a
2377 c_parser_asm_definition (c_parser
*parser
)
2379 tree asm_str
= c_parser_simple_asm_expr (parser
);
2381 symtab
->finalize_toplevel_asm (asm_str
);
2382 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2385 /* Parse a static assertion (C11 6.7.10).
2387 static_assert-declaration:
2388 static_assert-declaration-no-semi ;
2392 c_parser_static_assert_declaration (c_parser
*parser
)
2394 c_parser_static_assert_declaration_no_semi (parser
);
2396 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2397 c_parser_skip_to_end_of_block_or_statement (parser
);
2400 /* Parse a static assertion (C11 6.7.10), without the trailing
2403 static_assert-declaration-no-semi:
2404 _Static_assert ( constant-expression , string-literal )
2408 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2410 location_t assert_loc
, value_loc
;
2414 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2415 assert_loc
= c_parser_peek_token (parser
)->location
;
2417 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2418 "ISO C99 does not support %<_Static_assert%>");
2420 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2421 "ISO C90 does not support %<_Static_assert%>");
2422 c_parser_consume_token (parser
);
2423 matching_parens parens
;
2424 if (!parens
.require_open (parser
))
2426 location_t value_tok_loc
= c_parser_peek_token (parser
)->location
;
2427 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2428 value_loc
= EXPR_LOC_OR_LOC (value
, value_tok_loc
);
2429 parser
->lex_untranslated_string
= true;
2430 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2432 parser
->lex_untranslated_string
= false;
2435 switch (c_parser_peek_token (parser
)->type
)
2441 case CPP_UTF8STRING
:
2442 string
= c_parser_peek_token (parser
)->value
;
2443 c_parser_consume_token (parser
);
2444 parser
->lex_untranslated_string
= false;
2447 c_parser_error (parser
, "expected string literal");
2448 parser
->lex_untranslated_string
= false;
2451 parens
.require_close (parser
);
2453 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2455 error_at (value_loc
, "expression in static assertion is not an integer");
2458 if (TREE_CODE (value
) != INTEGER_CST
)
2460 value
= c_fully_fold (value
, false, NULL
);
2461 /* Strip no-op conversions. */
2462 STRIP_TYPE_NOPS (value
);
2463 if (TREE_CODE (value
) == INTEGER_CST
)
2464 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2465 "is not an integer constant expression");
2467 if (TREE_CODE (value
) != INTEGER_CST
)
2469 error_at (value_loc
, "expression in static assertion is not constant");
2472 constant_expression_warning (value
);
2473 if (integer_zerop (value
))
2474 error_at (assert_loc
, "static assertion failed: %E", string
);
2477 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2478 6.7, C11 6.7), adding them to SPECS (which may already include some).
2479 Storage class specifiers are accepted iff SCSPEC_OK; type
2480 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2481 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2482 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2484 declaration-specifiers:
2485 storage-class-specifier declaration-specifiers[opt]
2486 type-specifier declaration-specifiers[opt]
2487 type-qualifier declaration-specifiers[opt]
2488 function-specifier declaration-specifiers[opt]
2489 alignment-specifier declaration-specifiers[opt]
2491 Function specifiers (inline) are from C99, and are currently
2492 handled as storage class specifiers, as is __thread. Alignment
2493 specifiers are from C11.
2495 C90 6.5.1, C99 6.7.1, C11 6.7.1:
2496 storage-class-specifier:
2504 (_Thread_local is new in C11.)
2506 C99 6.7.4, C11 6.7.4:
2511 (_Noreturn is new in C11.)
2513 C90 6.5.2, C99 6.7.2, C11 6.7.2:
2526 [_Imaginary removed in C99 TC2]
2527 struct-or-union-specifier
2530 atomic-type-specifier
2532 (_Bool and _Complex are new in C99.)
2533 (atomic-type-specifier is new in C11.)
2535 C90 6.5.3, C99 6.7.3, C11 6.7.3:
2541 address-space-qualifier
2544 (restrict is new in C99.)
2545 (_Atomic is new in C11.)
2549 declaration-specifiers:
2550 attributes declaration-specifiers[opt]
2556 identifier recognized by the target
2558 storage-class-specifier:
2572 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2573 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2575 atomic-type-specifier
2576 _Atomic ( type-name )
2581 class-name objc-protocol-refs[opt]
2582 typedef-name objc-protocol-refs
2587 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2588 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2589 bool alignspec_ok
, bool auto_type_ok
,
2590 enum c_lookahead_kind la
)
2592 bool attrs_ok
= start_attr_ok
;
2593 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2596 gcc_assert (la
== cla_prefer_id
);
2598 while (c_parser_next_token_is (parser
, CPP_NAME
)
2599 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2600 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2602 struct c_typespec t
;
2605 location_t loc
= c_parser_peek_token (parser
)->location
;
2607 /* If we cannot accept a type, exit if the next token must start
2608 one. Also, if we already have seen a tagged definition,
2609 a typename would be an error anyway and likely the user
2610 has simply forgotten a semicolon, so we exit. */
2611 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2612 && c_parser_next_tokens_start_typename (parser
, la
)
2613 && !c_parser_next_token_is_qualifier (parser
)
2614 && !c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
))
2617 if (c_parser_next_token_is (parser
, CPP_NAME
))
2619 c_token
*name_token
= c_parser_peek_token (parser
);
2620 tree value
= name_token
->value
;
2621 c_id_kind kind
= name_token
->id_kind
;
2623 if (kind
== C_ID_ADDRSPACE
)
2626 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2627 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2628 c_parser_consume_token (parser
);
2633 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2635 /* If we cannot accept a type, and the next token must start one,
2636 exit. Do the same if we already have seen a tagged definition,
2637 since it would be an error anyway and likely the user has simply
2638 forgotten a semicolon. */
2639 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2642 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2643 a C_ID_CLASSNAME. */
2644 c_parser_consume_token (parser
);
2647 if (kind
== C_ID_ID
)
2649 error_at (loc
, "unknown type name %qE", value
);
2650 t
.kind
= ctsk_typedef
;
2651 t
.spec
= error_mark_node
;
2653 else if (kind
== C_ID_TYPENAME
2654 && (!c_dialect_objc ()
2655 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2657 t
.kind
= ctsk_typedef
;
2658 /* For a typedef name, record the meaning, not the name.
2659 In case of 'foo foo, bar;'. */
2660 t
.spec
= lookup_name (value
);
2664 tree proto
= NULL_TREE
;
2665 gcc_assert (c_dialect_objc ());
2667 if (c_parser_next_token_is (parser
, CPP_LESS
))
2668 proto
= c_parser_objc_protocol_refs (parser
);
2669 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2672 t
.expr_const_operands
= true;
2673 declspecs_add_type (name_token
->location
, specs
, t
);
2676 if (c_parser_next_token_is (parser
, CPP_LESS
))
2678 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2679 nisse@lysator.liu.se. */
2681 gcc_assert (c_dialect_objc ());
2682 if (!typespec_ok
|| seen_type
)
2684 proto
= c_parser_objc_protocol_refs (parser
);
2686 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2688 t
.expr_const_operands
= true;
2689 declspecs_add_type (loc
, specs
, t
);
2692 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2693 switch (c_parser_peek_token (parser
)->keyword
)
2706 /* TODO: Distinguish between function specifiers (inline, noreturn)
2707 and storage class specifiers, either here or in
2708 declspecs_add_scspec. */
2709 declspecs_add_scspec (loc
, specs
,
2710 c_parser_peek_token (parser
)->value
);
2711 c_parser_consume_token (parser
);
2743 if (c_dialect_objc ())
2744 parser
->objc_need_raw_identifier
= true;
2745 t
.kind
= ctsk_resword
;
2746 t
.spec
= c_parser_peek_token (parser
)->value
;
2748 t
.expr_const_operands
= true;
2749 declspecs_add_type (loc
, specs
, t
);
2750 c_parser_consume_token (parser
);
2757 t
= c_parser_enum_specifier (parser
);
2758 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2759 declspecs_add_type (loc
, specs
, t
);
2767 t
= c_parser_struct_or_union_specifier (parser
);
2768 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2769 declspecs_add_type (loc
, specs
, t
);
2772 /* ??? The old parser rejected typeof after other type
2773 specifiers, but is a syntax error the best way of
2775 if (!typespec_ok
|| seen_type
)
2779 t
= c_parser_typeof_specifier (parser
);
2780 declspecs_add_type (loc
, specs
, t
);
2783 /* C parser handling of Objective-C constructs needs
2784 checking for correct lvalue-to-rvalue conversions, and
2785 the code in build_modify_expr handling various
2786 Objective-C cases, and that in build_unary_op handling
2787 Objective-C cases for increment / decrement, also needs
2788 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2789 and objc_types_are_equivalent may also need updates. */
2790 if (c_dialect_objc ())
2791 sorry ("%<_Atomic%> in Objective-C");
2793 pedwarn_c99 (loc
, OPT_Wpedantic
,
2794 "ISO C99 does not support the %<_Atomic%> qualifier");
2796 pedwarn_c99 (loc
, OPT_Wpedantic
,
2797 "ISO C90 does not support the %<_Atomic%> qualifier");
2800 value
= c_parser_peek_token (parser
)->value
;
2801 c_parser_consume_token (parser
);
2802 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2804 /* _Atomic ( type-name ). */
2806 c_parser_consume_token (parser
);
2807 struct c_type_name
*type
= c_parser_type_name (parser
);
2808 t
.kind
= ctsk_typeof
;
2809 t
.spec
= error_mark_node
;
2811 t
.expr_const_operands
= true;
2813 t
.spec
= groktypename (type
, &t
.expr
,
2814 &t
.expr_const_operands
);
2815 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2817 if (t
.spec
!= error_mark_node
)
2819 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2820 error_at (loc
, "%<_Atomic%>-qualified array type");
2821 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2822 error_at (loc
, "%<_Atomic%>-qualified function type");
2823 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2824 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2826 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2828 declspecs_add_type (loc
, specs
, t
);
2831 declspecs_add_qual (loc
, specs
, value
);
2837 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2838 c_parser_consume_token (parser
);
2843 attrs
= c_parser_attributes (parser
);
2844 declspecs_add_attrs (loc
, specs
, attrs
);
2849 align
= c_parser_alignas_specifier (parser
);
2850 declspecs_add_alignas (loc
, specs
, align
);
2854 error_at (loc
, "%<__GIMPLE%> only valid with -fgimple");
2855 c_parser_consume_token (parser
);
2856 specs
->gimple_p
= true;
2857 specs
->locations
[cdw_gimple
] = loc
;
2858 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2861 c_parser_consume_token (parser
);
2862 specs
->rtl_p
= true;
2863 specs
->locations
[cdw_rtl
] = loc
;
2864 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2873 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2, C11 6.7.2.2).
2876 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2877 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2878 enum attributes[opt] identifier
2880 The form with trailing comma is new in C99. The forms with
2881 attributes are GNU extensions. In GNU C, we accept any expression
2882 without commas in the syntax (assignment expressions, not just
2883 conditional expressions); assignment expressions will be diagnosed
2888 enumerator-list , enumerator
2891 enumeration-constant
2892 enumeration-constant = constant-expression
2897 enumeration-constant attributes[opt]
2898 enumeration-constant attributes[opt] = constant-expression
2902 static struct c_typespec
2903 c_parser_enum_specifier (c_parser
*parser
)
2905 struct c_typespec ret
;
2907 tree ident
= NULL_TREE
;
2908 location_t enum_loc
;
2909 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2910 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2911 c_parser_consume_token (parser
);
2912 attrs
= c_parser_attributes (parser
);
2913 enum_loc
= c_parser_peek_token (parser
)->location
;
2914 /* Set the location in case we create a decl now. */
2915 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2916 if (c_parser_next_token_is (parser
, CPP_NAME
))
2918 ident
= c_parser_peek_token (parser
)->value
;
2919 ident_loc
= c_parser_peek_token (parser
)->location
;
2920 enum_loc
= ident_loc
;
2921 c_parser_consume_token (parser
);
2923 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2925 /* Parse an enum definition. */
2926 struct c_enum_contents the_enum
;
2929 /* We chain the enumerators in reverse order, then put them in
2930 forward order at the end. */
2932 timevar_push (TV_PARSE_ENUM
);
2933 type
= start_enum (enum_loc
, &the_enum
, ident
);
2935 c_parser_consume_token (parser
);
2943 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2944 location_t decl_loc
, value_loc
;
2945 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2947 /* Give a nicer error for "enum {}". */
2948 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2951 error_at (c_parser_peek_token (parser
)->location
,
2952 "empty enum is invalid");
2953 parser
->error
= true;
2956 c_parser_error (parser
, "expected identifier");
2957 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2958 values
= error_mark_node
;
2961 token
= c_parser_peek_token (parser
);
2962 enum_id
= token
->value
;
2963 /* Set the location in case we create a decl now. */
2964 c_parser_set_source_position_from_token (token
);
2965 decl_loc
= value_loc
= token
->location
;
2966 c_parser_consume_token (parser
);
2967 /* Parse any specified attributes. */
2968 tree enum_attrs
= c_parser_attributes (parser
);
2969 if (c_parser_next_token_is (parser
, CPP_EQ
))
2971 c_parser_consume_token (parser
);
2972 value_loc
= c_parser_peek_token (parser
)->location
;
2973 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2976 enum_value
= NULL_TREE
;
2977 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2978 &the_enum
, enum_id
, enum_value
);
2980 decl_attributes (&TREE_PURPOSE (enum_decl
), enum_attrs
, 0);
2981 TREE_CHAIN (enum_decl
) = values
;
2984 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2986 comma_loc
= c_parser_peek_token (parser
)->location
;
2988 c_parser_consume_token (parser
);
2990 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2993 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2994 "comma at end of enumerator list");
2995 c_parser_consume_token (parser
);
3000 c_parser_error (parser
, "expected %<,%> or %<}%>");
3001 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
3002 values
= error_mark_node
;
3006 postfix_attrs
= c_parser_attributes (parser
);
3007 ret
.spec
= finish_enum (type
, nreverse (values
),
3008 chainon (attrs
, postfix_attrs
));
3009 ret
.kind
= ctsk_tagdef
;
3010 ret
.expr
= NULL_TREE
;
3011 ret
.expr_const_operands
= true;
3012 timevar_pop (TV_PARSE_ENUM
);
3017 c_parser_error (parser
, "expected %<{%>");
3018 ret
.spec
= error_mark_node
;
3019 ret
.kind
= ctsk_tagref
;
3020 ret
.expr
= NULL_TREE
;
3021 ret
.expr_const_operands
= true;
3024 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
3025 /* In ISO C, enumerated types can be referred to only if already
3027 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
3030 pedwarn (enum_loc
, OPT_Wpedantic
,
3031 "ISO C forbids forward references to %<enum%> types");
3036 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1).
3038 struct-or-union-specifier:
3039 struct-or-union attributes[opt] identifier[opt]
3040 { struct-contents } attributes[opt]
3041 struct-or-union attributes[opt] identifier
3044 struct-declaration-list
3046 struct-declaration-list:
3047 struct-declaration ;
3048 struct-declaration-list struct-declaration ;
3055 struct-declaration-list struct-declaration
3057 struct-declaration-list:
3058 struct-declaration-list ;
3061 (Note that in the syntax here, unlike that in ISO C, the semicolons
3062 are included here rather than in struct-declaration, in order to
3063 describe the syntax with extra semicolons and missing semicolon at
3068 struct-declaration-list:
3069 @defs ( class-name )
3071 (Note this does not include a trailing semicolon, but can be
3072 followed by further declarations, and gets a pedwarn-if-pedantic
3073 when followed by a semicolon.) */
3075 static struct c_typespec
3076 c_parser_struct_or_union_specifier (c_parser
*parser
)
3078 struct c_typespec ret
;
3080 tree ident
= NULL_TREE
;
3081 location_t struct_loc
;
3082 location_t ident_loc
= UNKNOWN_LOCATION
;
3083 enum tree_code code
;
3084 switch (c_parser_peek_token (parser
)->keyword
)
3095 struct_loc
= c_parser_peek_token (parser
)->location
;
3096 c_parser_consume_token (parser
);
3097 attrs
= c_parser_attributes (parser
);
3099 /* Set the location in case we create a decl now. */
3100 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
3102 if (c_parser_next_token_is (parser
, CPP_NAME
))
3104 ident
= c_parser_peek_token (parser
)->value
;
3105 ident_loc
= c_parser_peek_token (parser
)->location
;
3106 struct_loc
= ident_loc
;
3107 c_parser_consume_token (parser
);
3109 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3111 /* Parse a struct or union definition. Start the scope of the
3112 tag before parsing components. */
3113 struct c_struct_parse_info
*struct_info
;
3114 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
3116 /* We chain the components in reverse order, then put them in
3117 forward order at the end. Each struct-declaration may
3118 declare multiple components (comma-separated), so we must use
3119 chainon to join them, although when parsing each
3120 struct-declaration we can use TREE_CHAIN directly.
3122 The theory behind all this is that there will be more
3123 semicolon separated fields than comma separated fields, and
3124 so we'll be minimizing the number of node traversals required
3127 timevar_push (TV_PARSE_STRUCT
);
3128 contents
= NULL_TREE
;
3129 c_parser_consume_token (parser
);
3130 /* Handle the Objective-C @defs construct,
3131 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
3132 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
3135 gcc_assert (c_dialect_objc ());
3136 c_parser_consume_token (parser
);
3137 matching_parens parens
;
3138 if (!parens
.require_open (parser
))
3140 if (c_parser_next_token_is (parser
, CPP_NAME
)
3141 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
3143 name
= c_parser_peek_token (parser
)->value
;
3144 c_parser_consume_token (parser
);
3148 c_parser_error (parser
, "expected class name");
3149 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3152 parens
.skip_until_found_close (parser
);
3153 contents
= nreverse (objc_get_class_ivars (name
));
3156 /* Parse the struct-declarations and semicolons. Problems with
3157 semicolons are diagnosed here; empty structures are diagnosed
3162 /* Parse any stray semicolon. */
3163 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3165 location_t semicolon_loc
3166 = c_parser_peek_token (parser
)->location
;
3167 gcc_rich_location
richloc (semicolon_loc
);
3168 richloc
.add_fixit_remove ();
3169 pedwarn (&richloc
, OPT_Wpedantic
,
3170 "extra semicolon in struct or union specified");
3171 c_parser_consume_token (parser
);
3174 /* Stop if at the end of the struct or union contents. */
3175 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3177 c_parser_consume_token (parser
);
3180 /* Accept #pragmas at struct scope. */
3181 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3183 c_parser_pragma (parser
, pragma_struct
, NULL
);
3186 /* Parse some comma-separated declarations, but not the
3187 trailing semicolon if any. */
3188 decls
= c_parser_struct_declaration (parser
);
3189 contents
= chainon (decls
, contents
);
3190 /* If no semicolon follows, either we have a parse error or
3191 are at the end of the struct or union and should
3193 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3194 c_parser_consume_token (parser
);
3197 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3198 pedwarn (c_parser_peek_token (parser
)->location
, 0,
3199 "no semicolon at end of struct or union");
3200 else if (parser
->error
3201 || !c_parser_next_token_starts_declspecs (parser
))
3203 c_parser_error (parser
, "expected %<;%>");
3204 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
3208 /* If we come here, we have already emitted an error
3209 for an expected `;', identifier or `(', and we also
3210 recovered already. Go on with the next field. */
3213 postfix_attrs
= c_parser_attributes (parser
);
3214 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
3215 chainon (attrs
, postfix_attrs
), struct_info
);
3216 ret
.kind
= ctsk_tagdef
;
3217 ret
.expr
= NULL_TREE
;
3218 ret
.expr_const_operands
= true;
3219 timevar_pop (TV_PARSE_STRUCT
);
3224 c_parser_error (parser
, "expected %<{%>");
3225 ret
.spec
= error_mark_node
;
3226 ret
.kind
= ctsk_tagref
;
3227 ret
.expr
= NULL_TREE
;
3228 ret
.expr_const_operands
= true;
3231 ret
= parser_xref_tag (ident_loc
, code
, ident
);
3235 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1),
3236 *without* the trailing semicolon.
3239 specifier-qualifier-list struct-declarator-list
3240 static_assert-declaration-no-semi
3242 specifier-qualifier-list:
3243 type-specifier specifier-qualifier-list[opt]
3244 type-qualifier specifier-qualifier-list[opt]
3245 alignment-specifier specifier-qualifier-list[opt]
3246 attributes specifier-qualifier-list[opt]
3248 struct-declarator-list:
3250 struct-declarator-list , attributes[opt] struct-declarator
3253 declarator attributes[opt]
3254 declarator[opt] : constant-expression attributes[opt]
3259 __extension__ struct-declaration
3260 specifier-qualifier-list
3262 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
3263 of attributes where shown is a GNU extension. In GNU C, we accept
3264 any expression without commas in the syntax (assignment
3265 expressions, not just conditional expressions); assignment
3266 expressions will be diagnosed as non-constant. */
3269 c_parser_struct_declaration (c_parser
*parser
)
3271 struct c_declspecs
*specs
;
3273 tree all_prefix_attrs
;
3275 location_t decl_loc
;
3276 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3280 ext
= disable_extension_diagnostics ();
3281 c_parser_consume_token (parser
);
3282 decl
= c_parser_struct_declaration (parser
);
3283 restore_extension_diagnostics (ext
);
3286 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
3288 c_parser_static_assert_declaration_no_semi (parser
);
3291 specs
= build_null_declspecs ();
3292 decl_loc
= c_parser_peek_token (parser
)->location
;
3293 /* Strictly by the standard, we shouldn't allow _Alignas here,
3294 but it appears to have been intended to allow it there, so
3295 we're keeping it as it is until WG14 reaches a conclusion
3297 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
3298 c_parser_declspecs (parser
, specs
, false, true, true,
3299 true, false, cla_nonabstract_decl
);
3302 if (!specs
->declspecs_seen_p
)
3304 c_parser_error (parser
, "expected specifier-qualifier-list");
3307 finish_declspecs (specs
);
3308 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3309 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3312 if (specs
->typespec_kind
== ctsk_none
)
3314 pedwarn (decl_loc
, OPT_Wpedantic
,
3315 "ISO C forbids member declarations with no members");
3316 shadow_tag_warned (specs
, pedantic
);
3321 /* Support for unnamed structs or unions as members of
3322 structs or unions (which is [a] useful and [b] supports
3326 ret
= grokfield (c_parser_peek_token (parser
)->location
,
3327 build_id_declarator (NULL_TREE
), specs
,
3330 decl_attributes (&ret
, attrs
, 0);
3335 /* Provide better error recovery. Note that a type name here is valid,
3336 and will be treated as a field name. */
3337 if (specs
->typespec_kind
== ctsk_tagdef
3338 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
3339 && c_parser_next_token_starts_declspecs (parser
)
3340 && !c_parser_next_token_is (parser
, CPP_NAME
))
3342 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
3343 parser
->error
= false;
3347 pending_xref_error ();
3348 prefix_attrs
= specs
->attrs
;
3349 all_prefix_attrs
= prefix_attrs
;
3350 specs
->attrs
= NULL_TREE
;
3354 /* Declaring one or more declarators or un-named bit-fields. */
3355 struct c_declarator
*declarator
;
3357 if (c_parser_next_token_is (parser
, CPP_COLON
))
3358 declarator
= build_id_declarator (NULL_TREE
);
3360 declarator
= c_parser_declarator (parser
,
3361 specs
->typespec_kind
!= ctsk_none
,
3362 C_DTR_NORMAL
, &dummy
);
3363 if (declarator
== NULL
)
3365 c_parser_skip_to_end_of_block_or_statement (parser
);
3368 if (c_parser_next_token_is (parser
, CPP_COLON
)
3369 || c_parser_next_token_is (parser
, CPP_COMMA
)
3370 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3371 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
3372 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3374 tree postfix_attrs
= NULL_TREE
;
3375 tree width
= NULL_TREE
;
3377 if (c_parser_next_token_is (parser
, CPP_COLON
))
3379 c_parser_consume_token (parser
);
3380 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
3382 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3383 postfix_attrs
= c_parser_attributes (parser
);
3384 d
= grokfield (c_parser_peek_token (parser
)->location
,
3385 declarator
, specs
, width
, &all_prefix_attrs
);
3386 decl_attributes (&d
, chainon (postfix_attrs
,
3387 all_prefix_attrs
), 0);
3388 DECL_CHAIN (d
) = decls
;
3390 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3391 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
3394 all_prefix_attrs
= prefix_attrs
;
3395 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3396 c_parser_consume_token (parser
);
3397 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3398 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3400 /* Semicolon consumed in caller. */
3405 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3411 c_parser_error (parser
,
3412 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3413 "%<__attribute__%>");
3420 /* Parse a typeof specifier (a GNU extension).
3423 typeof ( expression )
3424 typeof ( type-name )
3427 static struct c_typespec
3428 c_parser_typeof_specifier (c_parser
*parser
)
3430 struct c_typespec ret
;
3431 ret
.kind
= ctsk_typeof
;
3432 ret
.spec
= error_mark_node
;
3433 ret
.expr
= NULL_TREE
;
3434 ret
.expr_const_operands
= true;
3435 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3436 c_parser_consume_token (parser
);
3437 c_inhibit_evaluation_warnings
++;
3439 matching_parens parens
;
3440 if (!parens
.require_open (parser
))
3442 c_inhibit_evaluation_warnings
--;
3446 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3448 struct c_type_name
*type
= c_parser_type_name (parser
);
3449 c_inhibit_evaluation_warnings
--;
3453 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3454 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3460 location_t here
= c_parser_peek_token (parser
)->location
;
3461 struct c_expr expr
= c_parser_expression (parser
);
3462 c_inhibit_evaluation_warnings
--;
3464 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3465 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3466 error_at (here
, "%<typeof%> applied to a bit-field");
3467 mark_exp_read (expr
.value
);
3468 ret
.spec
= TREE_TYPE (expr
.value
);
3469 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3470 /* This is returned with the type so that when the type is
3471 evaluated, this can be evaluated. */
3473 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3474 pop_maybe_used (was_vm
);
3475 /* For use in macros such as those in <stdatomic.h>, remove all
3476 qualifiers from atomic types. (const can be an issue for more macros
3477 using typeof than just the <stdatomic.h> ones.) */
3478 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3479 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3481 parens
.skip_until_found_close (parser
);
3485 /* Parse an alignment-specifier.
3489 alignment-specifier:
3490 _Alignas ( type-name )
3491 _Alignas ( constant-expression )
3495 c_parser_alignas_specifier (c_parser
* parser
)
3497 tree ret
= error_mark_node
;
3498 location_t loc
= c_parser_peek_token (parser
)->location
;
3499 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3500 c_parser_consume_token (parser
);
3502 pedwarn_c99 (loc
, OPT_Wpedantic
,
3503 "ISO C99 does not support %<_Alignas%>");
3505 pedwarn_c99 (loc
, OPT_Wpedantic
,
3506 "ISO C90 does not support %<_Alignas%>");
3507 matching_parens parens
;
3508 if (!parens
.require_open (parser
))
3510 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3512 struct c_type_name
*type
= c_parser_type_name (parser
);
3514 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3518 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3519 parens
.skip_until_found_close (parser
);
3523 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3524 6.5.5, C99 6.7.5, 6.7.6, C11 6.7.6, 6.7.7). If TYPE_SEEN_P then
3525 a typedef name may be redeclared; otherwise it may not. KIND
3526 indicates which kind of declarator is wanted. Returns a valid
3527 declarator except in the case of a syntax error in which case NULL is
3528 returned. *SEEN_ID is set to true if an identifier being declared is
3529 seen; this is used to diagnose bad forms of abstract array declarators
3530 and to determine whether an identifier list is syntactically permitted.
3533 pointer[opt] direct-declarator
3537 ( attributes[opt] declarator )
3538 direct-declarator array-declarator
3539 direct-declarator ( parameter-type-list )
3540 direct-declarator ( identifier-list[opt] )
3543 * type-qualifier-list[opt]
3544 * type-qualifier-list[opt] pointer
3546 type-qualifier-list:
3549 type-qualifier-list type-qualifier
3550 type-qualifier-list attributes
3553 [ type-qualifier-list[opt] assignment-expression[opt] ]
3554 [ static type-qualifier-list[opt] assignment-expression ]
3555 [ type-qualifier-list static assignment-expression ]
3556 [ type-qualifier-list[opt] * ]
3558 parameter-type-list:
3560 parameter-list , ...
3563 parameter-declaration
3564 parameter-list , parameter-declaration
3566 parameter-declaration:
3567 declaration-specifiers declarator attributes[opt]
3568 declaration-specifiers abstract-declarator[opt] attributes[opt]
3572 identifier-list , identifier
3574 abstract-declarator:
3576 pointer[opt] direct-abstract-declarator
3578 direct-abstract-declarator:
3579 ( attributes[opt] abstract-declarator )
3580 direct-abstract-declarator[opt] array-declarator
3581 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3586 direct-declarator ( parameter-forward-declarations
3587 parameter-type-list[opt] )
3589 direct-abstract-declarator:
3590 direct-abstract-declarator[opt] ( parameter-forward-declarations
3591 parameter-type-list[opt] )
3593 parameter-forward-declarations:
3595 parameter-forward-declarations parameter-list ;
3597 The uses of attributes shown above are GNU extensions.
3599 Some forms of array declarator are not included in C99 in the
3600 syntax for abstract declarators; these are disallowed elsewhere.
3601 This may be a defect (DR#289).
3603 This function also accepts an omitted abstract declarator as being
3604 an abstract declarator, although not part of the formal syntax. */
3606 struct c_declarator
*
3607 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3610 /* Parse any initial pointer part. */
3611 if (c_parser_next_token_is (parser
, CPP_MULT
))
3613 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3614 struct c_declarator
*inner
;
3615 c_parser_consume_token (parser
);
3616 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3617 false, false, cla_prefer_id
);
3618 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3622 return make_pointer_declarator (quals_attrs
, inner
);
3624 /* Now we have a direct declarator, direct abstract declarator or
3625 nothing (which counts as a direct abstract declarator here). */
3626 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3629 /* Parse a direct declarator or direct abstract declarator; arguments
3630 as c_parser_declarator. */
3632 static struct c_declarator
*
3633 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3636 /* The direct declarator must start with an identifier (possibly
3637 omitted) or a parenthesized declarator (possibly abstract). In
3638 an ordinary declarator, initial parentheses must start a
3639 parenthesized declarator. In an abstract declarator or parameter
3640 declarator, they could start a parenthesized declarator or a
3641 parameter list. To tell which, the open parenthesis and any
3642 following attributes must be read. If a declaration specifier
3643 follows, then it is a parameter list; if the specifier is a
3644 typedef name, there might be an ambiguity about redeclaring it,
3645 which is resolved in the direction of treating it as a typedef
3646 name. If a close parenthesis follows, it is also an empty
3647 parameter list, as the syntax does not permit empty abstract
3648 declarators. Otherwise, it is a parenthesized declarator (in
3649 which case the analysis may be repeated inside it, recursively).
3651 ??? There is an ambiguity in a parameter declaration "int
3652 (__attribute__((foo)) x)", where x is not a typedef name: it
3653 could be an abstract declarator for a function, or declare x with
3654 parentheses. The proper resolution of this ambiguity needs
3655 documenting. At present we follow an accident of the old
3656 parser's implementation, whereby the first parameter must have
3657 some declaration specifiers other than just attributes. Thus as
3658 a parameter declaration it is treated as a parenthesized
3659 parameter named x, and as an abstract declarator it is
3662 ??? Also following the old parser, attributes inside an empty
3663 parameter list are ignored, making it a list not yielding a
3664 prototype, rather than giving an error or making it have one
3665 parameter with implicit type int.
3667 ??? Also following the old parser, typedef names may be
3668 redeclared in declarators, but not Objective-C class names. */
3670 if (kind
!= C_DTR_ABSTRACT
3671 && c_parser_next_token_is (parser
, CPP_NAME
)
3673 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3674 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3675 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3677 struct c_declarator
*inner
3678 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3680 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3681 c_parser_consume_token (parser
);
3682 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3685 if (kind
!= C_DTR_NORMAL
3686 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3688 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3689 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3690 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3693 /* Either we are at the end of an abstract declarator, or we have
3696 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3699 struct c_declarator
*inner
;
3700 c_parser_consume_token (parser
);
3701 attrs
= c_parser_attributes (parser
);
3702 if (kind
!= C_DTR_NORMAL
3703 && (c_parser_next_token_starts_declspecs (parser
)
3704 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3706 struct c_arg_info
*args
3707 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3714 = build_function_declarator (args
,
3715 build_id_declarator (NULL_TREE
));
3716 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3720 /* A parenthesized declarator. */
3721 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3722 if (inner
!= NULL
&& attrs
!= NULL
)
3723 inner
= build_attrs_declarator (attrs
, inner
);
3724 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3726 c_parser_consume_token (parser
);
3730 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3734 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3741 if (kind
== C_DTR_NORMAL
)
3743 c_parser_error (parser
, "expected identifier or %<(%>");
3747 return build_id_declarator (NULL_TREE
);
3751 /* Parse part of a direct declarator or direct abstract declarator,
3752 given that some (in INNER) has already been parsed; ID_PRESENT is
3753 true if an identifier is present, false for an abstract
3756 static struct c_declarator
*
3757 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3758 struct c_declarator
*inner
)
3760 /* Parse a sequence of array declarators and parameter lists. */
3761 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3763 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3764 struct c_declarator
*declarator
;
3765 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3768 struct c_expr dimen
;
3769 dimen
.value
= NULL_TREE
;
3770 dimen
.original_code
= ERROR_MARK
;
3771 dimen
.original_type
= NULL_TREE
;
3772 c_parser_consume_token (parser
);
3773 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3774 false, false, cla_prefer_id
);
3775 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3777 c_parser_consume_token (parser
);
3778 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3779 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3780 false, false, cla_prefer_id
);
3781 if (!quals_attrs
->declspecs_seen_p
)
3783 /* If "static" is present, there must be an array dimension.
3784 Otherwise, there may be a dimension, "*", or no
3789 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3793 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3795 dimen
.value
= NULL_TREE
;
3798 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3800 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3802 dimen
.value
= NULL_TREE
;
3804 c_parser_consume_token (parser
);
3809 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3815 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3818 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3819 c_parser_consume_token (parser
);
3822 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3827 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3828 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3829 static_seen
, star_seen
);
3830 if (declarator
== NULL
)
3832 inner
= set_array_declarator_inner (declarator
, inner
);
3833 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3835 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3838 struct c_arg_info
*args
;
3839 c_parser_consume_token (parser
);
3840 attrs
= c_parser_attributes (parser
);
3841 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3846 inner
= build_function_declarator (args
, inner
);
3847 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3853 /* Parse a parameter list or identifier list, including the closing
3854 parenthesis but not the opening one. ATTRS are the attributes at
3855 the start of the list. ID_LIST_OK is true if an identifier list is
3856 acceptable; such a list must not have attributes at the start. */
3858 static struct c_arg_info
*
3859 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3862 declare_parm_level ();
3863 /* If the list starts with an identifier, it is an identifier list.
3864 Otherwise, it is either a prototype list or an empty list. */
3867 && c_parser_next_token_is (parser
, CPP_NAME
)
3868 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3870 /* Look ahead to detect typos in type names. */
3871 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3872 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3873 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3874 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
3875 && c_parser_peek_2nd_token (parser
)->type
!= CPP_KEYWORD
)
3877 tree list
= NULL_TREE
, *nextp
= &list
;
3878 while (c_parser_next_token_is (parser
, CPP_NAME
)
3879 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3881 *nextp
= build_tree_list (NULL_TREE
,
3882 c_parser_peek_token (parser
)->value
);
3883 nextp
= & TREE_CHAIN (*nextp
);
3884 c_parser_consume_token (parser
);
3885 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3887 c_parser_consume_token (parser
);
3888 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3890 c_parser_error (parser
, "expected identifier");
3894 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3896 struct c_arg_info
*ret
= build_arg_info ();
3898 c_parser_consume_token (parser
);
3904 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3912 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3919 /* Parse a parameter list (possibly empty), including the closing
3920 parenthesis but not the opening one. ATTRS are the attributes at
3921 the start of the list. EXPR is NULL or an expression that needs to
3922 be evaluated for the side effects of array size expressions in the
3925 static struct c_arg_info
*
3926 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3928 bool bad_parm
= false;
3930 /* ??? Following the old parser, forward parameter declarations may
3931 use abstract declarators, and if no real parameter declarations
3932 follow the forward declarations then this is not diagnosed. Also
3933 note as above that attributes are ignored as the only contents of
3934 the parentheses, or as the only contents after forward
3936 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3938 struct c_arg_info
*ret
= build_arg_info ();
3939 c_parser_consume_token (parser
);
3942 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3944 struct c_arg_info
*ret
= build_arg_info ();
3946 if (flag_allow_parameterless_variadic_functions
)
3948 /* F (...) is allowed. */
3949 ret
->types
= NULL_TREE
;
3953 /* Suppress -Wold-style-definition for this case. */
3954 ret
->types
= error_mark_node
;
3955 error_at (c_parser_peek_token (parser
)->location
,
3956 "ISO C requires a named argument before %<...%>");
3958 c_parser_consume_token (parser
);
3959 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3961 c_parser_consume_token (parser
);
3966 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3971 /* Nonempty list of parameters, either terminated with semicolon
3972 (forward declarations; recurse) or with close parenthesis (normal
3973 function) or with ", ... )" (variadic function). */
3976 /* Parse a parameter. */
3977 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3982 push_parm_decl (parm
, &expr
);
3983 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3986 c_parser_consume_token (parser
);
3987 mark_forward_parm_decls ();
3988 new_attrs
= c_parser_attributes (parser
);
3989 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3991 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3993 c_parser_consume_token (parser
);
3997 return get_parm_info (false, expr
);
3999 if (!c_parser_require (parser
, CPP_COMMA
,
4000 "expected %<;%>, %<,%> or %<)%>",
4001 UNKNOWN_LOCATION
, false))
4003 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4006 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4008 c_parser_consume_token (parser
);
4009 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4011 c_parser_consume_token (parser
);
4015 return get_parm_info (true, expr
);
4019 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4027 /* Parse a parameter declaration. ATTRS are the attributes at the
4028 start of the declaration if it is the first parameter. */
4030 static struct c_parm
*
4031 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
4033 struct c_declspecs
*specs
;
4034 struct c_declarator
*declarator
;
4036 tree postfix_attrs
= NULL_TREE
;
4039 /* Accept #pragmas between parameter declarations. */
4040 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4041 c_parser_pragma (parser
, pragma_param
, NULL
);
4043 if (!c_parser_next_token_starts_declspecs (parser
))
4045 c_token
*token
= c_parser_peek_token (parser
);
4048 c_parser_set_source_position_from_token (token
);
4049 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
4051 name_hint hint
= lookup_name_fuzzy (token
->value
,
4052 FUZZY_LOOKUP_TYPENAME
,
4056 gcc_rich_location
richloc (token
->location
);
4057 richloc
.add_fixit_replace (hint
.suggestion ());
4059 "unknown type name %qE; did you mean %qs?",
4060 token
->value
, hint
.suggestion ());
4063 error_at (token
->location
, "unknown type name %qE", token
->value
);
4064 parser
->error
= true;
4066 /* ??? In some Objective-C cases '...' isn't applicable so there
4067 should be a different message. */
4069 c_parser_error (parser
,
4070 "expected declaration specifiers or %<...%>");
4071 c_parser_skip_to_end_of_parameter (parser
);
4075 location_t start_loc
= c_parser_peek_token (parser
)->location
;
4077 specs
= build_null_declspecs ();
4080 declspecs_add_attrs (input_location
, specs
, attrs
);
4083 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
4084 cla_nonabstract_decl
);
4085 finish_declspecs (specs
);
4086 pending_xref_error ();
4087 prefix_attrs
= specs
->attrs
;
4088 specs
->attrs
= NULL_TREE
;
4089 declarator
= c_parser_declarator (parser
,
4090 specs
->typespec_kind
!= ctsk_none
,
4091 C_DTR_PARM
, &dummy
);
4092 if (declarator
== NULL
)
4094 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4097 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4098 postfix_attrs
= c_parser_attributes (parser
);
4100 /* Generate a location for the parameter, ranging from the start of the
4101 initial token to the end of the final token.
4103 If we have a identifier, then use it for the caret location, e.g.
4105 extern int callee (int one, int (*two)(int, int), float three);
4106 ~~~~~~^~~~~~~~~~~~~~
4108 otherwise, reuse the start location for the caret location e.g.:
4110 extern int callee (int one, int (*)(int, int), float three);
4113 location_t end_loc
= parser
->last_token_location
;
4115 /* Find any cdk_id declarator; determine if we have an identifier. */
4116 c_declarator
*id_declarator
= declarator
;
4117 while (id_declarator
&& id_declarator
->kind
!= cdk_id
)
4118 id_declarator
= id_declarator
->declarator
;
4119 location_t caret_loc
= (id_declarator
->u
.id
4120 ? id_declarator
->id_loc
4122 location_t param_loc
= make_location (caret_loc
, start_loc
, end_loc
);
4124 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
4125 declarator
, param_loc
);
4128 /* Parse a string literal in an asm expression. It should not be
4129 translated, and wide string literals are an error although
4130 permitted by the syntax. This is a GNU extension.
4135 ??? At present, following the old parser, the caller needs to have
4136 set lex_untranslated_string to 1. It would be better to follow the
4137 C++ parser rather than using this kludge. */
4140 c_parser_asm_string_literal (c_parser
*parser
)
4143 int save_flag
= warn_overlength_strings
;
4144 warn_overlength_strings
= 0;
4145 if (c_parser_next_token_is (parser
, CPP_STRING
))
4147 str
= c_parser_peek_token (parser
)->value
;
4148 c_parser_consume_token (parser
);
4150 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
4152 error_at (c_parser_peek_token (parser
)->location
,
4153 "wide string literal in %<asm%>");
4154 str
= build_string (1, "");
4155 c_parser_consume_token (parser
);
4159 c_parser_error (parser
, "expected string literal");
4162 warn_overlength_strings
= save_flag
;
4166 /* Parse a simple asm expression. This is used in restricted
4167 contexts, where a full expression with inputs and outputs does not
4168 make sense. This is a GNU extension.
4171 asm ( asm-string-literal )
4175 c_parser_simple_asm_expr (c_parser
*parser
)
4178 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4179 /* ??? Follow the C++ parser rather than using the
4180 lex_untranslated_string kludge. */
4181 parser
->lex_untranslated_string
= true;
4182 c_parser_consume_token (parser
);
4183 matching_parens parens
;
4184 if (!parens
.require_open (parser
))
4186 parser
->lex_untranslated_string
= false;
4189 str
= c_parser_asm_string_literal (parser
);
4190 parser
->lex_untranslated_string
= false;
4191 if (!parens
.require_close (parser
))
4193 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4200 c_parser_attribute_any_word (c_parser
*parser
)
4202 tree attr_name
= NULL_TREE
;
4204 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
4206 /* ??? See comment above about what keywords are accepted here. */
4208 switch (c_parser_peek_token (parser
)->keyword
)
4239 case RID_TRANSACTION_ATOMIC
:
4240 case RID_TRANSACTION_CANCEL
:
4256 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
4257 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
4259 else if (c_parser_next_token_is (parser
, CPP_NAME
))
4260 attr_name
= c_parser_peek_token (parser
)->value
;
4265 /* Parse (possibly empty) attributes. This is a GNU extension.
4269 attributes attribute
4272 __attribute__ ( ( attribute-list ) )
4276 attribute_list , attrib
4281 any-word ( identifier )
4282 any-word ( identifier , nonempty-expr-list )
4283 any-word ( expr-list )
4285 where the "identifier" must not be declared as a type, and
4286 "any-word" may be any identifier (including one declared as a
4287 type), a reserved word storage class specifier, type specifier or
4288 type qualifier. ??? This still leaves out most reserved keywords
4289 (following the old parser), shouldn't we include them, and why not
4290 allow identifiers declared as types to start the arguments? */
4293 c_parser_attributes (c_parser
*parser
)
4295 tree attrs
= NULL_TREE
;
4296 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4298 /* ??? Follow the C++ parser rather than using the
4299 lex_untranslated_string kludge. */
4300 parser
->lex_untranslated_string
= true;
4301 /* Consume the `__attribute__' keyword. */
4302 c_parser_consume_token (parser
);
4303 /* Look for the two `(' tokens. */
4304 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4306 parser
->lex_untranslated_string
= false;
4309 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4311 parser
->lex_untranslated_string
= false;
4312 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4315 /* Parse the attribute list. */
4316 while (c_parser_next_token_is (parser
, CPP_COMMA
)
4317 || c_parser_next_token_is (parser
, CPP_NAME
)
4318 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
4320 tree attr
, attr_name
, attr_args
;
4321 vec
<tree
, va_gc
> *expr_list
;
4322 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4324 c_parser_consume_token (parser
);
4328 attr_name
= c_parser_attribute_any_word (parser
);
4329 if (attr_name
== NULL
)
4331 attr_name
= canonicalize_attr_name (attr_name
);
4332 c_parser_consume_token (parser
);
4333 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
4335 attr
= build_tree_list (attr_name
, NULL_TREE
);
4336 /* Add this attribute to the list. */
4337 attrs
= chainon (attrs
, attr
);
4338 /* If the next token isn't a comma, we're done. */
4339 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4343 c_parser_consume_token (parser
);
4344 /* Parse the attribute contents. If they start with an
4345 identifier which is followed by a comma or close
4346 parenthesis, then the arguments start with that
4347 identifier; otherwise they are an expression list.
4348 In objective-c the identifier may be a classname. */
4349 if (c_parser_next_token_is (parser
, CPP_NAME
)
4350 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4351 || (c_dialect_objc ()
4352 && c_parser_peek_token (parser
)->id_kind
4354 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4355 || (c_parser_peek_2nd_token (parser
)->type
4356 == CPP_CLOSE_PAREN
))
4357 && (attribute_takes_identifier_p (attr_name
)
4358 || (c_dialect_objc ()
4359 && c_parser_peek_token (parser
)->id_kind
4360 == C_ID_CLASSNAME
)))
4362 tree arg1
= c_parser_peek_token (parser
)->value
;
4363 c_parser_consume_token (parser
);
4364 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4365 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4369 c_parser_consume_token (parser
);
4370 expr_list
= c_parser_expr_list (parser
, false, true,
4371 NULL
, NULL
, NULL
, NULL
);
4372 tree_list
= build_tree_list_vec (expr_list
);
4373 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4374 release_tree_vector (expr_list
);
4379 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4380 attr_args
= NULL_TREE
;
4383 expr_list
= c_parser_expr_list (parser
, false, true,
4384 NULL
, NULL
, NULL
, NULL
);
4385 attr_args
= build_tree_list_vec (expr_list
);
4386 release_tree_vector (expr_list
);
4390 attr
= build_tree_list (attr_name
, attr_args
);
4391 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4392 c_parser_consume_token (parser
);
4395 parser
->lex_untranslated_string
= false;
4396 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4400 /* Add this attribute to the list. */
4401 attrs
= chainon (attrs
, attr
);
4402 /* If the next token isn't a comma, we're done. */
4403 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4406 /* Look for the two `)' tokens. */
4407 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4408 c_parser_consume_token (parser
);
4411 parser
->lex_untranslated_string
= false;
4412 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4416 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4417 c_parser_consume_token (parser
);
4420 parser
->lex_untranslated_string
= false;
4421 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4425 parser
->lex_untranslated_string
= false;
4431 /* Parse a type name (C90 6.5.5, C99 6.7.6, C11 6.7.7). ALIGNAS_OK
4432 says whether alignment specifiers are OK (only in cases that might
4433 be the type name of a compound literal).
4436 specifier-qualifier-list abstract-declarator[opt]
4439 struct c_type_name
*
4440 c_parser_type_name (c_parser
*parser
, bool alignas_ok
)
4442 struct c_declspecs
*specs
= build_null_declspecs ();
4443 struct c_declarator
*declarator
;
4444 struct c_type_name
*ret
;
4446 c_parser_declspecs (parser
, specs
, false, true, true, alignas_ok
, false,
4448 if (!specs
->declspecs_seen_p
)
4450 c_parser_error (parser
, "expected specifier-qualifier-list");
4453 if (specs
->type
!= error_mark_node
)
4455 pending_xref_error ();
4456 finish_declspecs (specs
);
4458 declarator
= c_parser_declarator (parser
,
4459 specs
->typespec_kind
!= ctsk_none
,
4460 C_DTR_ABSTRACT
, &dummy
);
4461 if (declarator
== NULL
)
4463 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4465 ret
->declarator
= declarator
;
4469 /* Parse an initializer (C90 6.5.7, C99 6.7.8, C11 6.7.9).
4472 assignment-expression
4473 { initializer-list }
4474 { initializer-list , }
4477 designation[opt] initializer
4478 initializer-list , designation[opt] initializer
4485 designator-list designator
4492 [ constant-expression ]
4504 [ constant-expression ... constant-expression ]
4506 Any expression without commas is accepted in the syntax for the
4507 constant-expressions, with non-constant expressions rejected later.
4509 This function is only used for top-level initializers; for nested
4510 ones, see c_parser_initval. */
4512 static struct c_expr
4513 c_parser_initializer (c_parser
*parser
)
4515 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4516 return c_parser_braced_init (parser
, NULL_TREE
, false, NULL
);
4520 location_t loc
= c_parser_peek_token (parser
)->location
;
4521 ret
= c_parser_expr_no_commas (parser
, NULL
);
4522 if (TREE_CODE (ret
.value
) != STRING_CST
4523 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4524 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4529 /* The location of the last comma within the current initializer list,
4530 or UNKNOWN_LOCATION if not within one. */
4532 location_t last_init_list_comma
;
4534 /* Parse a braced initializer list. TYPE is the type specified for a
4535 compound literal, and NULL_TREE for other initializers and for
4536 nested braced lists. NESTED_P is true for nested braced lists,
4537 false for the list of a compound literal or the list that is the
4538 top-level initializer in a declaration. */
4540 static struct c_expr
4541 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
,
4542 struct obstack
*outer_obstack
)
4545 struct obstack braced_init_obstack
;
4546 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4547 gcc_obstack_init (&braced_init_obstack
);
4548 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4549 matching_braces braces
;
4550 braces
.consume_open (parser
);
4553 finish_implicit_inits (brace_loc
, outer_obstack
);
4554 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4557 really_start_incremental_init (type
);
4558 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4560 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4564 /* Parse a non-empty initializer list, possibly with a trailing
4568 c_parser_initelt (parser
, &braced_init_obstack
);
4571 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4573 last_init_list_comma
= c_parser_peek_token (parser
)->location
;
4574 c_parser_consume_token (parser
);
4578 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4582 c_token
*next_tok
= c_parser_peek_token (parser
);
4583 if (next_tok
->type
!= CPP_CLOSE_BRACE
)
4586 ret
.original_code
= ERROR_MARK
;
4587 ret
.original_type
= NULL
;
4588 braces
.skip_until_found_close (parser
);
4589 pop_init_level (brace_loc
, 0, &braced_init_obstack
, last_init_list_comma
);
4590 obstack_free (&braced_init_obstack
, NULL
);
4593 location_t close_loc
= next_tok
->location
;
4594 c_parser_consume_token (parser
);
4595 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
, close_loc
);
4596 obstack_free (&braced_init_obstack
, NULL
);
4597 set_c_expr_source_range (&ret
, brace_loc
, close_loc
);
4601 /* Parse a nested initializer, including designators. */
4604 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4606 /* Parse any designator or designator list. A single array
4607 designator may have the subsequent "=" omitted in GNU C, but a
4608 longer list or a structure member designator may not. */
4609 if (c_parser_next_token_is (parser
, CPP_NAME
)
4610 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4612 /* Old-style structure member designator. */
4613 set_init_label (c_parser_peek_token (parser
)->location
,
4614 c_parser_peek_token (parser
)->value
,
4615 c_parser_peek_token (parser
)->location
,
4616 braced_init_obstack
);
4617 /* Use the colon as the error location. */
4618 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4619 "obsolete use of designated initializer with %<:%>");
4620 c_parser_consume_token (parser
);
4621 c_parser_consume_token (parser
);
4625 /* des_seen is 0 if there have been no designators, 1 if there
4626 has been a single array designator and 2 otherwise. */
4628 /* Location of a designator. */
4629 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4630 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4631 || c_parser_next_token_is (parser
, CPP_DOT
))
4633 int des_prev
= des_seen
;
4635 des_loc
= c_parser_peek_token (parser
)->location
;
4638 if (c_parser_next_token_is (parser
, CPP_DOT
))
4641 c_parser_consume_token (parser
);
4642 if (c_parser_next_token_is (parser
, CPP_NAME
))
4644 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4645 c_parser_peek_token (parser
)->location
,
4646 braced_init_obstack
);
4647 c_parser_consume_token (parser
);
4653 init
.original_code
= ERROR_MARK
;
4654 init
.original_type
= NULL
;
4655 c_parser_error (parser
, "expected identifier");
4656 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4657 process_init_element (input_location
, init
, false,
4658 braced_init_obstack
);
4665 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4666 location_t array_index_loc
= UNKNOWN_LOCATION
;
4667 /* ??? Following the old parser, [ objc-receiver
4668 objc-message-args ] is accepted as an initializer,
4669 being distinguished from a designator by what follows
4670 the first assignment expression inside the square
4671 brackets, but after a first array designator a
4672 subsequent square bracket is for Objective-C taken to
4673 start an expression, using the obsolete form of
4674 designated initializer without '=', rather than
4675 possibly being a second level of designation: in LALR
4676 terms, the '[' is shifted rather than reducing
4677 designator to designator-list. */
4678 if (des_prev
== 1 && c_dialect_objc ())
4680 des_seen
= des_prev
;
4683 if (des_prev
== 0 && c_dialect_objc ())
4685 /* This might be an array designator or an
4686 Objective-C message expression. If the former,
4687 continue parsing here; if the latter, parse the
4688 remainder of the initializer given the starting
4689 primary-expression. ??? It might make sense to
4690 distinguish when des_prev == 1 as well; see
4691 previous comment. */
4693 struct c_expr mexpr
;
4694 c_parser_consume_token (parser
);
4695 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4696 && ((c_parser_peek_token (parser
)->id_kind
4698 || (c_parser_peek_token (parser
)->id_kind
4699 == C_ID_CLASSNAME
)))
4701 /* Type name receiver. */
4702 tree id
= c_parser_peek_token (parser
)->value
;
4703 c_parser_consume_token (parser
);
4704 rec
= objc_get_class_reference (id
);
4705 goto parse_message_args
;
4707 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4708 mark_exp_read (first
);
4709 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4710 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4711 goto array_desig_after_first
;
4712 /* Expression receiver. So far only one part
4713 without commas has been parsed; there might be
4714 more of the expression. */
4716 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4719 location_t comma_loc
, exp_loc
;
4720 comma_loc
= c_parser_peek_token (parser
)->location
;
4721 c_parser_consume_token (parser
);
4722 exp_loc
= c_parser_peek_token (parser
)->location
;
4723 next
= c_parser_expr_no_commas (parser
, NULL
);
4724 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4726 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4729 /* Now parse the objc-message-args. */
4730 args
= c_parser_objc_message_args (parser
);
4731 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4734 = objc_build_message_expr (rec
, args
);
4735 mexpr
.original_code
= ERROR_MARK
;
4736 mexpr
.original_type
= NULL
;
4737 /* Now parse and process the remainder of the
4738 initializer, starting with this message
4739 expression as a primary-expression. */
4740 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4743 c_parser_consume_token (parser
);
4744 array_index_loc
= c_parser_peek_token (parser
)->location
;
4745 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4746 mark_exp_read (first
);
4747 array_desig_after_first
:
4748 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4750 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4751 c_parser_consume_token (parser
);
4752 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4753 mark_exp_read (second
);
4757 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4759 c_parser_consume_token (parser
);
4760 set_init_index (array_index_loc
, first
, second
,
4761 braced_init_obstack
);
4763 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4764 "ISO C forbids specifying range of elements to initialize");
4767 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4773 if (c_parser_next_token_is (parser
, CPP_EQ
))
4775 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4776 "ISO C90 forbids specifying subobject "
4778 c_parser_consume_token (parser
);
4783 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4784 "obsolete use of designated initializer without %<=%>");
4789 init
.original_code
= ERROR_MARK
;
4790 init
.original_type
= NULL
;
4791 c_parser_error (parser
, "expected %<=%>");
4792 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4793 process_init_element (input_location
, init
, false,
4794 braced_init_obstack
);
4800 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4803 /* Parse a nested initializer; as c_parser_initializer but parses
4804 initializers within braced lists, after any designators have been
4805 applied. If AFTER is not NULL then it is an Objective-C message
4806 expression which is the primary-expression starting the
4810 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4811 struct obstack
* braced_init_obstack
)
4814 gcc_assert (!after
|| c_dialect_objc ());
4815 location_t loc
= c_parser_peek_token (parser
)->location
;
4817 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4818 init
= c_parser_braced_init (parser
, NULL_TREE
, true,
4819 braced_init_obstack
);
4822 init
= c_parser_expr_no_commas (parser
, after
);
4823 if (init
.value
!= NULL_TREE
4824 && TREE_CODE (init
.value
) != STRING_CST
4825 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4826 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4828 process_init_element (loc
, init
, false, braced_init_obstack
);
4831 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4832 C99 6.8.2, C11 6.8.2).
4835 { block-item-list[opt] }
4836 { label-declarations block-item-list }
4840 block-item-list block-item
4852 { label-declarations block-item-list }
4855 __extension__ nested-declaration
4856 nested-function-definition
4860 label-declarations label-declaration
4863 __label__ identifier-list ;
4865 Allowing the mixing of declarations and code is new in C99. The
4866 GNU syntax also permits (not shown above) labels at the end of
4867 compound statements, which yield an error. We don't allow labels
4868 on declarations; this might seem like a natural extension, but
4869 there would be a conflict between attributes on the label and
4870 prefix attributes on the declaration. ??? The syntax follows the
4871 old parser in requiring something after label declarations.
4872 Although they are erroneous if the labels declared aren't defined,
4873 is it useful for the syntax to be this way?
4894 cancellation-point-directive */
4897 c_parser_compound_statement (c_parser
*parser
)
4900 location_t brace_loc
;
4901 brace_loc
= c_parser_peek_token (parser
)->location
;
4902 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4904 /* Ensure a scope is entered and left anyway to avoid confusion
4905 if we have just prepared to enter a function body. */
4906 stmt
= c_begin_compound_stmt (true);
4907 c_end_compound_stmt (brace_loc
, stmt
, true);
4908 return error_mark_node
;
4910 stmt
= c_begin_compound_stmt (true);
4911 c_parser_compound_statement_nostart (parser
);
4913 return c_end_compound_stmt (brace_loc
, stmt
, true);
4916 /* Parse a compound statement except for the opening brace. This is
4917 used for parsing both compound statements and statement expressions
4918 (which follow different paths to handling the opening). */
4921 c_parser_compound_statement_nostart (c_parser
*parser
)
4923 bool last_stmt
= false;
4924 bool last_label
= false;
4925 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4926 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4927 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4929 add_debug_begin_stmt (c_parser_peek_token (parser
)->location
);
4930 c_parser_consume_token (parser
);
4933 mark_valid_location_for_stdc_pragma (true);
4934 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4936 /* Read zero or more forward-declarations for labels that nested
4937 functions can jump to. */
4938 mark_valid_location_for_stdc_pragma (false);
4939 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4941 label_loc
= c_parser_peek_token (parser
)->location
;
4942 c_parser_consume_token (parser
);
4943 /* Any identifiers, including those declared as type names,
4948 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4950 c_parser_error (parser
, "expected identifier");
4954 = declare_label (c_parser_peek_token (parser
)->value
);
4955 C_DECLARED_LABEL_FLAG (label
) = 1;
4956 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4957 c_parser_consume_token (parser
);
4958 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4959 c_parser_consume_token (parser
);
4963 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4965 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4967 /* We must now have at least one statement, label or declaration. */
4968 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4970 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4971 c_parser_error (parser
, "expected declaration or statement");
4972 c_parser_consume_token (parser
);
4975 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4977 location_t loc
= c_parser_peek_token (parser
)->location
;
4978 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4979 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4980 || (c_parser_next_token_is (parser
, CPP_NAME
)
4981 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4983 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4984 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4986 label_loc
= c_parser_peek_token (parser
)->location
;
4989 mark_valid_location_for_stdc_pragma (false);
4990 c_parser_label (parser
);
4992 else if (!last_label
4993 && c_parser_next_tokens_start_declaration (parser
))
4996 mark_valid_location_for_stdc_pragma (false);
4997 bool fallthru_attr_p
= false;
4998 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4999 true, NULL
, vNULL
, NULL
,
5001 if (last_stmt
&& !fallthru_attr_p
)
5002 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
5003 "ISO C90 forbids mixed declarations and code");
5004 last_stmt
= fallthru_attr_p
;
5006 else if (!last_label
5007 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5009 /* __extension__ can start a declaration, but is also an
5010 unary operator that can start an expression. Consume all
5011 but the last of a possible series of __extension__ to
5013 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5014 && (c_parser_peek_2nd_token (parser
)->keyword
5016 c_parser_consume_token (parser
);
5017 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5020 ext
= disable_extension_diagnostics ();
5021 c_parser_consume_token (parser
);
5023 mark_valid_location_for_stdc_pragma (false);
5024 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5026 /* Following the old parser, __extension__ does not
5027 disable this diagnostic. */
5028 restore_extension_diagnostics (ext
);
5030 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
5031 "ISO C90 forbids mixed declarations and code");
5037 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
5039 /* External pragmas, and some omp pragmas, are not associated
5040 with regular c code, and so are not to be considered statements
5041 syntactically. This ensures that the user doesn't put them
5042 places that would turn into syntax errors if the directive
5044 if (c_parser_pragma (parser
,
5045 last_label
? pragma_stmt
: pragma_compound
,
5047 last_label
= false, last_stmt
= true;
5049 else if (c_parser_next_token_is (parser
, CPP_EOF
))
5051 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5052 c_parser_error (parser
, "expected declaration or statement");
5055 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5057 if (parser
->in_if_block
)
5059 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5060 error_at (loc
, "expected %<}%> before %<else%>");
5065 error_at (loc
, "%<else%> without a previous %<if%>");
5066 c_parser_consume_token (parser
);
5075 mark_valid_location_for_stdc_pragma (false);
5076 c_parser_statement_after_labels (parser
, NULL
);
5079 parser
->error
= false;
5082 error_at (label_loc
, "label at end of compound statement");
5083 c_parser_consume_token (parser
);
5084 /* Restore the value we started with. */
5085 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5088 /* Parse all consecutive labels. */
5091 c_parser_all_labels (c_parser
*parser
)
5093 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5094 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5095 || (c_parser_next_token_is (parser
, CPP_NAME
)
5096 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5097 c_parser_label (parser
);
5100 /* Parse a label (C90 6.6.1, C99 6.8.1, C11 6.8.1).
5103 identifier : attributes[opt]
5104 case constant-expression :
5110 case constant-expression ... constant-expression :
5112 The use of attributes on labels is a GNU extension. The syntax in
5113 GNU C accepts any expressions without commas, non-constant
5114 expressions being rejected later. */
5117 c_parser_label (c_parser
*parser
)
5119 location_t loc1
= c_parser_peek_token (parser
)->location
;
5120 tree label
= NULL_TREE
;
5122 /* Remember whether this case or a user-defined label is allowed to fall
5124 bool fallthrough_p
= c_parser_peek_token (parser
)->flags
& PREV_FALLTHROUGH
;
5126 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
5129 c_parser_consume_token (parser
);
5130 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
5131 if (c_parser_next_token_is (parser
, CPP_COLON
))
5133 c_parser_consume_token (parser
);
5134 label
= do_case (loc1
, exp1
, NULL_TREE
);
5136 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
5138 c_parser_consume_token (parser
);
5139 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
5140 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5141 label
= do_case (loc1
, exp1
, exp2
);
5144 c_parser_error (parser
, "expected %<:%> or %<...%>");
5146 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
5148 c_parser_consume_token (parser
);
5149 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5150 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
5154 tree name
= c_parser_peek_token (parser
)->value
;
5157 location_t loc2
= c_parser_peek_token (parser
)->location
;
5158 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
5159 c_parser_consume_token (parser
);
5160 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
5161 c_parser_consume_token (parser
);
5162 attrs
= c_parser_attributes (parser
);
5163 tlab
= define_label (loc2
, name
);
5166 decl_attributes (&tlab
, attrs
, 0);
5167 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
5172 if (TREE_CODE (label
) == LABEL_EXPR
)
5173 FALLTHROUGH_LABEL_P (LABEL_EXPR_LABEL (label
)) = fallthrough_p
;
5175 FALLTHROUGH_LABEL_P (CASE_LABEL (label
)) = fallthrough_p
;
5177 /* Allow '__attribute__((fallthrough));'. */
5178 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
5180 location_t loc
= c_parser_peek_token (parser
)->location
;
5181 tree attrs
= c_parser_attributes (parser
);
5182 if (attribute_fallthrough_p (attrs
))
5184 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5186 tree fn
= build_call_expr_internal_loc (loc
,
5192 warning_at (loc
, OPT_Wattributes
, "%<fallthrough%> attribute "
5193 "not followed by %<;%>");
5195 else if (attrs
!= NULL_TREE
)
5196 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5197 " can be applied to a null statement");
5199 if (c_parser_next_tokens_start_declaration (parser
))
5201 error_at (c_parser_peek_token (parser
)->location
,
5202 "a label can only be part of a statement and "
5203 "a declaration is not a statement");
5204 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
5205 /*static_assert_ok*/ true,
5206 /*empty_ok*/ true, /*nested*/ true,
5207 /*start_attr_ok*/ true, NULL
,
5213 /* Parse a statement (C90 6.6, C99 6.8, C11 6.8).
5218 expression-statement
5226 expression-statement:
5229 selection-statement:
5233 iteration-statement:
5242 return expression[opt] ;
5252 expression-statement:
5258 objc-throw-statement
5259 objc-try-catch-statement
5260 objc-synchronized-statement
5262 objc-throw-statement:
5278 parallel-directive structured-block
5281 kernels-directive structured-block
5284 data-directive structured-block
5287 loop-directive structured-block
5301 parallel-for-construct
5302 parallel-for-simd-construct
5303 parallel-sections-construct
5310 parallel-directive structured-block
5313 for-directive iteration-statement
5316 simd-directive iteration-statements
5319 for-simd-directive iteration-statements
5322 sections-directive section-scope
5325 single-directive structured-block
5327 parallel-for-construct:
5328 parallel-for-directive iteration-statement
5330 parallel-for-simd-construct:
5331 parallel-for-simd-directive iteration-statement
5333 parallel-sections-construct:
5334 parallel-sections-directive section-scope
5337 master-directive structured-block
5340 critical-directive structured-block
5343 atomic-directive expression-statement
5346 ordered-directive structured-block
5348 Transactional Memory:
5351 transaction-statement
5352 transaction-cancel-statement
5354 IF_P is used to track whether there's a (possibly labeled) if statement
5355 which is not enclosed in braces and has an else clause. This is used to
5356 implement -Wparentheses. */
5359 c_parser_statement (c_parser
*parser
, bool *if_p
, location_t
*loc_after_labels
)
5361 c_parser_all_labels (parser
);
5362 if (loc_after_labels
)
5363 *loc_after_labels
= c_parser_peek_token (parser
)->location
;
5364 c_parser_statement_after_labels (parser
, if_p
, NULL
);
5367 /* Parse a statement, other than a labeled statement. CHAIN is a vector
5368 of if-else-if conditions.
5370 IF_P is used to track whether there's a (possibly labeled) if statement
5371 which is not enclosed in braces and has an else clause. This is used to
5372 implement -Wparentheses. */
5375 c_parser_statement_after_labels (c_parser
*parser
, bool *if_p
,
5378 location_t loc
= c_parser_peek_token (parser
)->location
;
5379 tree stmt
= NULL_TREE
;
5380 bool in_if_block
= parser
->in_if_block
;
5381 parser
->in_if_block
= false;
5385 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_BRACE
)
5386 add_debug_begin_stmt (loc
);
5388 switch (c_parser_peek_token (parser
)->type
)
5390 case CPP_OPEN_BRACE
:
5391 add_stmt (c_parser_compound_statement (parser
));
5394 switch (c_parser_peek_token (parser
)->keyword
)
5397 c_parser_if_statement (parser
, if_p
, chain
);
5400 c_parser_switch_statement (parser
, if_p
);
5403 c_parser_while_statement (parser
, false, 0, if_p
);
5406 c_parser_do_statement (parser
, 0, false);
5409 c_parser_for_statement (parser
, false, 0, if_p
);
5412 c_parser_consume_token (parser
);
5413 if (c_parser_next_token_is (parser
, CPP_NAME
))
5415 stmt
= c_finish_goto_label (loc
,
5416 c_parser_peek_token (parser
)->value
);
5417 c_parser_consume_token (parser
);
5419 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5423 c_parser_consume_token (parser
);
5424 val
= c_parser_expression (parser
);
5425 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5426 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5429 c_parser_error (parser
, "expected identifier or %<*%>");
5430 goto expect_semicolon
;
5432 c_parser_consume_token (parser
);
5433 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5434 goto expect_semicolon
;
5436 c_parser_consume_token (parser
);
5437 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5438 goto expect_semicolon
;
5440 c_parser_consume_token (parser
);
5441 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5443 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5444 c_parser_consume_token (parser
);
5448 location_t xloc
= c_parser_peek_token (parser
)->location
;
5449 struct c_expr expr
= c_parser_expression_conv (parser
);
5450 mark_exp_read (expr
.value
);
5451 stmt
= c_finish_return (EXPR_LOC_OR_LOC (expr
.value
, xloc
),
5452 expr
.value
, expr
.original_type
);
5453 goto expect_semicolon
;
5457 stmt
= c_parser_asm_statement (parser
);
5459 case RID_TRANSACTION_ATOMIC
:
5460 case RID_TRANSACTION_RELAXED
:
5461 stmt
= c_parser_transaction (parser
,
5462 c_parser_peek_token (parser
)->keyword
);
5464 case RID_TRANSACTION_CANCEL
:
5465 stmt
= c_parser_transaction_cancel (parser
);
5466 goto expect_semicolon
;
5468 gcc_assert (c_dialect_objc ());
5469 c_parser_consume_token (parser
);
5470 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5472 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5473 c_parser_consume_token (parser
);
5477 struct c_expr expr
= c_parser_expression (parser
);
5478 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5479 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5480 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5481 goto expect_semicolon
;
5485 gcc_assert (c_dialect_objc ());
5486 c_parser_objc_try_catch_finally_statement (parser
);
5488 case RID_AT_SYNCHRONIZED
:
5489 gcc_assert (c_dialect_objc ());
5490 c_parser_objc_synchronized_statement (parser
);
5494 /* Allow '__attribute__((fallthrough));'. */
5495 tree attrs
= c_parser_attributes (parser
);
5496 if (attribute_fallthrough_p (attrs
))
5498 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5500 tree fn
= build_call_expr_internal_loc (loc
,
5505 c_parser_consume_token (parser
);
5508 warning_at (loc
, OPT_Wattributes
,
5509 "%<fallthrough%> attribute not followed "
5512 else if (attrs
!= NULL_TREE
)
5513 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5514 " can be applied to a null statement");
5522 c_parser_consume_token (parser
);
5524 case CPP_CLOSE_PAREN
:
5525 case CPP_CLOSE_SQUARE
:
5526 /* Avoid infinite loop in error recovery:
5527 c_parser_skip_until_found stops at a closing nesting
5528 delimiter without consuming it, but here we need to consume
5529 it to proceed further. */
5530 c_parser_error (parser
, "expected statement");
5531 c_parser_consume_token (parser
);
5534 c_parser_pragma (parser
, pragma_stmt
, if_p
);
5538 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5540 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5543 /* Two cases cannot and do not have line numbers associated: If stmt
5544 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5545 cannot hold line numbers. But that's OK because the statement
5546 will either be changed to a MODIFY_EXPR during gimplification of
5547 the statement expr, or discarded. If stmt was compound, but
5548 without new variables, we will have skipped the creation of a
5549 BIND and will have a bare STATEMENT_LIST. But that's OK because
5550 (recursively) all of the component statements should already have
5551 line numbers assigned. ??? Can we discard no-op statements
5553 if (EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5554 protected_set_expr_location (stmt
, loc
);
5556 parser
->in_if_block
= in_if_block
;
5559 /* Parse the condition from an if, do, while or for statements. */
5562 c_parser_condition (c_parser
*parser
)
5564 location_t loc
= c_parser_peek_token (parser
)->location
;
5566 cond
= c_parser_expression_conv (parser
).value
;
5567 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5568 cond
= c_fully_fold (cond
, false, NULL
);
5569 if (warn_sequence_point
)
5570 verify_sequence_points (cond
);
5574 /* Parse a parenthesized condition from an if, do or while statement.
5580 c_parser_paren_condition (c_parser
*parser
)
5583 matching_parens parens
;
5584 if (!parens
.require_open (parser
))
5585 return error_mark_node
;
5586 cond
= c_parser_condition (parser
);
5587 parens
.skip_until_found_close (parser
);
5591 /* Parse a statement which is a block in C99.
5593 IF_P is used to track whether there's a (possibly labeled) if statement
5594 which is not enclosed in braces and has an else clause. This is used to
5595 implement -Wparentheses. */
5598 c_parser_c99_block_statement (c_parser
*parser
, bool *if_p
,
5599 location_t
*loc_after_labels
)
5601 tree block
= c_begin_compound_stmt (flag_isoc99
);
5602 location_t loc
= c_parser_peek_token (parser
)->location
;
5603 c_parser_statement (parser
, if_p
, loc_after_labels
);
5604 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5607 /* Parse the body of an if statement. This is just parsing a
5608 statement but (a) it is a block in C99, (b) we track whether the
5609 body is an if statement for the sake of -Wparentheses warnings, (c)
5610 we handle an empty body specially for the sake of -Wempty-body
5611 warnings, and (d) we call parser_compound_statement directly
5612 because c_parser_statement_after_labels resets
5613 parser->in_if_block.
5615 IF_P is used to track whether there's a (possibly labeled) if statement
5616 which is not enclosed in braces and has an else clause. This is used to
5617 implement -Wparentheses. */
5620 c_parser_if_body (c_parser
*parser
, bool *if_p
,
5621 const token_indent_info
&if_tinfo
)
5623 tree block
= c_begin_compound_stmt (flag_isoc99
);
5624 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5625 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
5626 token_indent_info body_tinfo
5627 = get_token_indent_info (c_parser_peek_token (parser
));
5629 c_parser_all_labels (parser
);
5630 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5632 location_t loc
= c_parser_peek_token (parser
)->location
;
5633 add_stmt (build_empty_stmt (loc
));
5634 c_parser_consume_token (parser
);
5635 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5636 warning_at (loc
, OPT_Wempty_body
,
5637 "suggest braces around empty body in an %<if%> statement");
5639 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5640 add_stmt (c_parser_compound_statement (parser
));
5643 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5644 c_parser_statement_after_labels (parser
, if_p
);
5647 token_indent_info next_tinfo
5648 = get_token_indent_info (c_parser_peek_token (parser
));
5649 warn_for_misleading_indentation (if_tinfo
, body_tinfo
, next_tinfo
);
5650 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5651 && next_tinfo
.type
!= CPP_SEMICOLON
)
5652 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5653 if_tinfo
.location
, RID_IF
);
5655 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5658 /* Parse the else body of an if statement. This is just parsing a
5659 statement but (a) it is a block in C99, (b) we handle an empty body
5660 specially for the sake of -Wempty-body warnings. CHAIN is a vector
5661 of if-else-if conditions. */
5664 c_parser_else_body (c_parser
*parser
, const token_indent_info
&else_tinfo
,
5667 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5668 tree block
= c_begin_compound_stmt (flag_isoc99
);
5669 token_indent_info body_tinfo
5670 = get_token_indent_info (c_parser_peek_token (parser
));
5671 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
5673 c_parser_all_labels (parser
);
5674 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5676 location_t loc
= c_parser_peek_token (parser
)->location
;
5679 "suggest braces around empty body in an %<else%> statement");
5680 add_stmt (build_empty_stmt (loc
));
5681 c_parser_consume_token (parser
);
5685 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5686 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5687 c_parser_statement_after_labels (parser
, NULL
, chain
);
5690 token_indent_info next_tinfo
5691 = get_token_indent_info (c_parser_peek_token (parser
));
5692 warn_for_misleading_indentation (else_tinfo
, body_tinfo
, next_tinfo
);
5693 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5694 && next_tinfo
.type
!= CPP_SEMICOLON
)
5695 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5696 else_tinfo
.location
, RID_ELSE
);
5698 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5701 /* We might need to reclassify any previously-lexed identifier, e.g.
5702 when we've left a for loop with an if-statement without else in the
5703 body - we might have used a wrong scope for the token. See PR67784. */
5706 c_parser_maybe_reclassify_token (c_parser
*parser
)
5708 if (c_parser_next_token_is (parser
, CPP_NAME
))
5710 c_token
*token
= c_parser_peek_token (parser
);
5712 if (token
->id_kind
!= C_ID_CLASSNAME
)
5714 tree decl
= lookup_name (token
->value
);
5716 token
->id_kind
= C_ID_ID
;
5719 if (TREE_CODE (decl
) == TYPE_DECL
)
5720 token
->id_kind
= C_ID_TYPENAME
;
5722 else if (c_dialect_objc ())
5724 tree objc_interface_decl
= objc_is_class_name (token
->value
);
5725 /* Objective-C class names are in the same namespace as
5726 variables and typedefs, and hence are shadowed by local
5728 if (objc_interface_decl
)
5730 token
->value
= objc_interface_decl
;
5731 token
->id_kind
= C_ID_CLASSNAME
;
5738 /* Parse an if statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5741 if ( expression ) statement
5742 if ( expression ) statement else statement
5744 CHAIN is a vector of if-else-if conditions.
5745 IF_P is used to track whether there's a (possibly labeled) if statement
5746 which is not enclosed in braces and has an else clause. This is used to
5747 implement -Wparentheses. */
5750 c_parser_if_statement (c_parser
*parser
, bool *if_p
, vec
<tree
> *chain
)
5755 bool nested_if
= false;
5756 tree first_body
, second_body
;
5759 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5760 token_indent_info if_tinfo
5761 = get_token_indent_info (c_parser_peek_token (parser
));
5762 c_parser_consume_token (parser
);
5763 block
= c_begin_compound_stmt (flag_isoc99
);
5764 loc
= c_parser_peek_token (parser
)->location
;
5765 cond
= c_parser_paren_condition (parser
);
5766 in_if_block
= parser
->in_if_block
;
5767 parser
->in_if_block
= true;
5768 first_body
= c_parser_if_body (parser
, &nested_if
, if_tinfo
);
5769 parser
->in_if_block
= in_if_block
;
5771 if (warn_duplicated_cond
)
5772 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond
), cond
, &chain
);
5774 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5776 token_indent_info else_tinfo
5777 = get_token_indent_info (c_parser_peek_token (parser
));
5778 c_parser_consume_token (parser
);
5779 if (warn_duplicated_cond
)
5781 if (c_parser_next_token_is_keyword (parser
, RID_IF
)
5784 /* We've got "if (COND) else if (COND2)". Start the
5785 condition chain and add COND as the first element. */
5786 chain
= new vec
<tree
> ();
5787 if (!CONSTANT_CLASS_P (cond
) && !TREE_SIDE_EFFECTS (cond
))
5788 chain
->safe_push (cond
);
5790 else if (!c_parser_next_token_is_keyword (parser
, RID_IF
))
5792 /* This is if-else without subsequent if. Zap the condition
5793 chain; we would have already warned at this point. */
5798 second_body
= c_parser_else_body (parser
, else_tinfo
, chain
);
5799 /* Set IF_P to true to indicate that this if statement has an
5800 else clause. This may trigger the Wparentheses warning
5801 below when we get back up to the parent if statement. */
5807 second_body
= NULL_TREE
;
5809 /* Diagnose an ambiguous else if if-then-else is nested inside
5812 warning_at (loc
, OPT_Wdangling_else
,
5813 "suggest explicit braces to avoid ambiguous %<else%>");
5815 if (warn_duplicated_cond
)
5817 /* This if statement does not have an else clause. We don't
5818 need the condition chain anymore. */
5823 c_finish_if_stmt (loc
, cond
, first_body
, second_body
);
5824 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5826 c_parser_maybe_reclassify_token (parser
);
5829 /* Parse a switch statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5832 switch (expression) statement
5836 c_parser_switch_statement (c_parser
*parser
, bool *if_p
)
5839 tree block
, expr
, body
, save_break
;
5840 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5841 location_t switch_cond_loc
;
5842 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5843 c_parser_consume_token (parser
);
5844 block
= c_begin_compound_stmt (flag_isoc99
);
5845 bool explicit_cast_p
= false;
5846 matching_parens parens
;
5847 if (parens
.require_open (parser
))
5849 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5850 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5851 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5852 explicit_cast_p
= true;
5853 ce
= c_parser_expression (parser
);
5854 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5856 /* ??? expr has no valid location? */
5857 parens
.skip_until_found_close (parser
);
5861 switch_cond_loc
= UNKNOWN_LOCATION
;
5862 expr
= error_mark_node
;
5863 ce
.original_type
= error_mark_node
;
5865 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5866 save_break
= c_break_label
;
5867 c_break_label
= NULL_TREE
;
5868 location_t loc_after_labels
;
5869 bool open_brace_p
= c_parser_peek_token (parser
)->type
== CPP_OPEN_BRACE
;
5870 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
5871 location_t next_loc
= c_parser_peek_token (parser
)->location
;
5872 if (!open_brace_p
&& c_parser_peek_token (parser
)->type
!= CPP_SEMICOLON
)
5873 warn_for_multistatement_macros (loc_after_labels
, next_loc
, switch_loc
,
5877 location_t here
= c_parser_peek_token (parser
)->location
;
5878 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5879 SET_EXPR_LOCATION (t
, here
);
5880 SWITCH_BREAK_LABEL_P (c_break_label
) = 1;
5881 append_to_statement_list_force (t
, &body
);
5883 c_finish_case (body
, ce
.original_type
);
5884 c_break_label
= save_break
;
5885 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5886 c_parser_maybe_reclassify_token (parser
);
5889 /* Parse a while statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5892 while (expression) statement
5894 IF_P is used to track whether there's a (possibly labeled) if statement
5895 which is not enclosed in braces and has an else clause. This is used to
5896 implement -Wparentheses. */
5899 c_parser_while_statement (c_parser
*parser
, bool ivdep
, unsigned short unroll
,
5902 tree block
, cond
, body
, save_break
, save_cont
;
5904 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5905 token_indent_info while_tinfo
5906 = get_token_indent_info (c_parser_peek_token (parser
));
5907 c_parser_consume_token (parser
);
5908 block
= c_begin_compound_stmt (flag_isoc99
);
5909 loc
= c_parser_peek_token (parser
)->location
;
5910 cond
= c_parser_paren_condition (parser
);
5911 if (ivdep
&& cond
!= error_mark_node
)
5912 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5913 build_int_cst (integer_type_node
,
5914 annot_expr_ivdep_kind
),
5916 if (unroll
&& cond
!= error_mark_node
)
5917 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5918 build_int_cst (integer_type_node
,
5919 annot_expr_unroll_kind
),
5920 build_int_cst (integer_type_node
, unroll
));
5921 save_break
= c_break_label
;
5922 c_break_label
= NULL_TREE
;
5923 save_cont
= c_cont_label
;
5924 c_cont_label
= NULL_TREE
;
5926 token_indent_info body_tinfo
5927 = get_token_indent_info (c_parser_peek_token (parser
));
5929 location_t loc_after_labels
;
5930 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
5931 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
5932 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5933 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5934 c_parser_maybe_reclassify_token (parser
);
5936 token_indent_info next_tinfo
5937 = get_token_indent_info (c_parser_peek_token (parser
));
5938 warn_for_misleading_indentation (while_tinfo
, body_tinfo
, next_tinfo
);
5940 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
5941 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
5942 while_tinfo
.location
, RID_WHILE
);
5944 c_break_label
= save_break
;
5945 c_cont_label
= save_cont
;
5948 /* Parse a do statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5951 do statement while ( expression ) ;
5955 c_parser_do_statement (c_parser
*parser
, bool ivdep
, unsigned short unroll
)
5957 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5959 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5960 c_parser_consume_token (parser
);
5961 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5962 warning_at (c_parser_peek_token (parser
)->location
,
5964 "suggest braces around empty body in %<do%> statement");
5965 block
= c_begin_compound_stmt (flag_isoc99
);
5966 loc
= c_parser_peek_token (parser
)->location
;
5967 save_break
= c_break_label
;
5968 c_break_label
= NULL_TREE
;
5969 save_cont
= c_cont_label
;
5970 c_cont_label
= NULL_TREE
;
5971 body
= c_parser_c99_block_statement (parser
, NULL
);
5972 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5973 new_break
= c_break_label
;
5974 c_break_label
= save_break
;
5975 new_cont
= c_cont_label
;
5976 c_cont_label
= save_cont
;
5977 cond
= c_parser_paren_condition (parser
);
5978 if (ivdep
&& cond
!= error_mark_node
)
5979 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5980 build_int_cst (integer_type_node
,
5981 annot_expr_ivdep_kind
),
5983 if (unroll
&& cond
!= error_mark_node
)
5984 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5985 build_int_cst (integer_type_node
,
5986 annot_expr_unroll_kind
),
5987 build_int_cst (integer_type_node
, unroll
));
5988 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5989 c_parser_skip_to_end_of_block_or_statement (parser
);
5990 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5991 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5994 /* Parse a for statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5997 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5998 for ( nested-declaration expression[opt] ; expression[opt] ) statement
6000 The form with a declaration is new in C99.
6002 ??? In accordance with the old parser, the declaration may be a
6003 nested function, which is then rejected in check_for_loop_decls,
6004 but does it make any sense for this to be included in the grammar?
6005 Note in particular that the nested function does not include a
6006 trailing ';', whereas the "declaration" production includes one.
6007 Also, can we reject bad declarations earlier and cheaper than
6008 check_for_loop_decls?
6010 In Objective-C, there are two additional variants:
6013 for ( expression in expresssion ) statement
6014 for ( declaration in expression ) statement
6016 This is inconsistent with C, because the second variant is allowed
6017 even if c99 is not enabled.
6019 The rest of the comment documents these Objective-C foreach-statement.
6021 Here is the canonical example of the first variant:
6022 for (object in array) { do something with object }
6023 we call the first expression ("object") the "object_expression" and
6024 the second expression ("array") the "collection_expression".
6025 object_expression must be an lvalue of type "id" (a generic Objective-C
6026 object) because the loop works by assigning to object_expression the
6027 various objects from the collection_expression. collection_expression
6028 must evaluate to something of type "id" which responds to the method
6029 countByEnumeratingWithState:objects:count:.
6031 The canonical example of the second variant is:
6032 for (id object in array) { do something with object }
6033 which is completely equivalent to
6036 for (object in array) { do something with object }
6038 Note that initizializing 'object' in some way (eg, "for ((object =
6039 xxx) in array) { do something with object }") is possibly
6040 technically valid, but completely pointless as 'object' will be
6041 assigned to something else as soon as the loop starts. We should
6042 most likely reject it (TODO).
6044 The beginning of the Objective-C foreach-statement looks exactly
6045 like the beginning of the for-statement, and we can tell it is a
6046 foreach-statement only because the initial declaration or
6047 expression is terminated by 'in' instead of ';'.
6049 IF_P is used to track whether there's a (possibly labeled) if statement
6050 which is not enclosed in braces and has an else clause. This is used to
6051 implement -Wparentheses. */
6054 c_parser_for_statement (c_parser
*parser
, bool ivdep
, unsigned short unroll
,
6057 tree block
, cond
, incr
, save_break
, save_cont
, body
;
6058 /* The following are only used when parsing an ObjC foreach statement. */
6059 tree object_expression
;
6060 /* Silence the bogus uninitialized warning. */
6061 tree collection_expression
= NULL
;
6062 location_t loc
= c_parser_peek_token (parser
)->location
;
6063 location_t for_loc
= c_parser_peek_token (parser
)->location
;
6064 bool is_foreach_statement
= false;
6065 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
6066 token_indent_info for_tinfo
6067 = get_token_indent_info (c_parser_peek_token (parser
));
6068 c_parser_consume_token (parser
);
6069 /* Open a compound statement in Objective-C as well, just in case this is
6070 as foreach expression. */
6071 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
6072 cond
= error_mark_node
;
6073 incr
= error_mark_node
;
6074 matching_parens parens
;
6075 if (parens
.require_open (parser
))
6077 /* Parse the initialization declaration or expression. */
6078 object_expression
= error_mark_node
;
6079 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
6080 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6082 parser
->objc_could_be_foreach_context
= false;
6083 c_parser_consume_token (parser
);
6084 c_finish_expr_stmt (loc
, NULL_TREE
);
6086 else if (c_parser_next_tokens_start_declaration (parser
))
6088 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
6089 &object_expression
, vNULL
);
6090 parser
->objc_could_be_foreach_context
= false;
6092 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6094 c_parser_consume_token (parser
);
6095 is_foreach_statement
= true;
6096 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6097 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
6100 check_for_loop_decls (for_loc
, flag_isoc99
);
6102 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
6104 /* __extension__ can start a declaration, but is also an
6105 unary operator that can start an expression. Consume all
6106 but the last of a possible series of __extension__ to
6108 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
6109 && (c_parser_peek_2nd_token (parser
)->keyword
6111 c_parser_consume_token (parser
);
6112 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
6115 ext
= disable_extension_diagnostics ();
6116 c_parser_consume_token (parser
);
6117 c_parser_declaration_or_fndef (parser
, true, true, true, true,
6118 true, &object_expression
, vNULL
);
6119 parser
->objc_could_be_foreach_context
= false;
6121 restore_extension_diagnostics (ext
);
6122 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6124 c_parser_consume_token (parser
);
6125 is_foreach_statement
= true;
6126 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6127 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
6130 check_for_loop_decls (for_loc
, flag_isoc99
);
6140 tree init_expression
;
6141 ce
= c_parser_expression (parser
);
6142 init_expression
= ce
.value
;
6143 parser
->objc_could_be_foreach_context
= false;
6144 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6146 c_parser_consume_token (parser
);
6147 is_foreach_statement
= true;
6148 if (! lvalue_p (init_expression
))
6149 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
6150 object_expression
= c_fully_fold (init_expression
, false, NULL
);
6154 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6155 init_expression
= ce
.value
;
6156 c_finish_expr_stmt (loc
, init_expression
);
6157 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6161 /* Parse the loop condition. In the case of a foreach
6162 statement, there is no loop condition. */
6163 gcc_assert (!parser
->objc_could_be_foreach_context
);
6164 if (!is_foreach_statement
)
6166 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6170 c_parser_error (parser
, "missing loop condition in loop with "
6171 "%<GCC ivdep%> pragma");
6172 cond
= error_mark_node
;
6176 c_parser_error (parser
, "missing loop condition in loop with "
6177 "%<GCC unroll%> pragma");
6178 cond
= error_mark_node
;
6182 c_parser_consume_token (parser
);
6188 cond
= c_parser_condition (parser
);
6189 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
6192 if (ivdep
&& cond
!= error_mark_node
)
6193 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6194 build_int_cst (integer_type_node
,
6195 annot_expr_ivdep_kind
),
6197 if (unroll
&& cond
!= error_mark_node
)
6198 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6199 build_int_cst (integer_type_node
,
6200 annot_expr_unroll_kind
),
6201 build_int_cst (integer_type_node
, unroll
));
6203 /* Parse the increment expression (the third expression in a
6204 for-statement). In the case of a foreach-statement, this is
6205 the expression that follows the 'in'. */
6206 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6208 if (is_foreach_statement
)
6210 c_parser_error (parser
, "missing collection in fast enumeration");
6211 collection_expression
= error_mark_node
;
6214 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
6218 if (is_foreach_statement
)
6219 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
6223 struct c_expr ce
= c_parser_expression (parser
);
6224 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6225 incr
= c_process_expr_stmt (loc
, ce
.value
);
6228 parens
.skip_until_found_close (parser
);
6230 save_break
= c_break_label
;
6231 c_break_label
= NULL_TREE
;
6232 save_cont
= c_cont_label
;
6233 c_cont_label
= NULL_TREE
;
6235 token_indent_info body_tinfo
6236 = get_token_indent_info (c_parser_peek_token (parser
));
6238 location_t loc_after_labels
;
6239 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
6240 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
6242 if (is_foreach_statement
)
6243 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
6245 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
6246 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
6247 c_parser_maybe_reclassify_token (parser
);
6249 token_indent_info next_tinfo
6250 = get_token_indent_info (c_parser_peek_token (parser
));
6251 warn_for_misleading_indentation (for_tinfo
, body_tinfo
, next_tinfo
);
6253 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
6254 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
6255 for_tinfo
.location
, RID_FOR
);
6257 c_break_label
= save_break
;
6258 c_cont_label
= save_cont
;
6261 /* Parse an asm statement, a GNU extension. This is a full-blown asm
6262 statement with inputs, outputs, clobbers, and volatile tag
6266 asm type-qualifier[opt] ( asm-argument ) ;
6267 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
6271 asm-string-literal : asm-operands[opt]
6272 asm-string-literal : asm-operands[opt] : asm-operands[opt]
6273 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
6276 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
6279 Qualifiers other than volatile are accepted in the syntax but
6283 c_parser_asm_statement (c_parser
*parser
)
6285 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
6286 bool simple
, is_goto
;
6287 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
6288 int section
, nsections
;
6290 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
6291 c_parser_consume_token (parser
);
6292 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
6294 quals
= c_parser_peek_token (parser
)->value
;
6295 c_parser_consume_token (parser
);
6297 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
6298 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
6300 warning_at (c_parser_peek_token (parser
)->location
,
6302 "%E qualifier ignored on asm",
6303 c_parser_peek_token (parser
)->value
);
6305 c_parser_consume_token (parser
);
6311 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
6313 c_parser_consume_token (parser
);
6317 /* ??? Follow the C++ parser rather than using the
6318 lex_untranslated_string kludge. */
6319 parser
->lex_untranslated_string
= true;
6322 matching_parens parens
;
6323 if (!parens
.require_open (parser
))
6326 str
= c_parser_asm_string_literal (parser
);
6327 if (str
== NULL_TREE
)
6328 goto error_close_paren
;
6331 outputs
= NULL_TREE
;
6333 clobbers
= NULL_TREE
;
6336 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6339 /* Parse each colon-delimited section of operands. */
6340 nsections
= 3 + is_goto
;
6341 for (section
= 0; section
< nsections
; ++section
)
6343 if (!c_parser_require (parser
, CPP_COLON
,
6345 ? G_("expected %<:%>")
6346 : G_("expected %<:%> or %<)%>"),
6347 UNKNOWN_LOCATION
, is_goto
))
6348 goto error_close_paren
;
6350 /* Once past any colon, we're no longer a simple asm. */
6353 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
6354 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6359 /* For asm goto, we don't allow output operands, but reserve
6360 the slot for a future extension that does allow them. */
6362 outputs
= c_parser_asm_operands (parser
);
6365 inputs
= c_parser_asm_operands (parser
);
6368 clobbers
= c_parser_asm_clobbers (parser
);
6371 labels
= c_parser_asm_goto_operands (parser
);
6377 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6382 if (!parens
.require_close (parser
))
6384 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6388 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6389 c_parser_skip_to_end_of_block_or_statement (parser
);
6391 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
6392 clobbers
, labels
, simple
));
6395 parser
->lex_untranslated_string
= false;
6399 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6403 /* Parse asm operands, a GNU extension.
6407 asm-operands , asm-operand
6410 asm-string-literal ( expression )
6411 [ identifier ] asm-string-literal ( expression )
6415 c_parser_asm_operands (c_parser
*parser
)
6417 tree list
= NULL_TREE
;
6422 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
6424 c_parser_consume_token (parser
);
6425 if (c_parser_next_token_is (parser
, CPP_NAME
))
6427 tree id
= c_parser_peek_token (parser
)->value
;
6428 c_parser_consume_token (parser
);
6429 name
= build_string (IDENTIFIER_LENGTH (id
),
6430 IDENTIFIER_POINTER (id
));
6434 c_parser_error (parser
, "expected identifier");
6435 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
6438 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6443 str
= c_parser_asm_string_literal (parser
);
6444 if (str
== NULL_TREE
)
6446 parser
->lex_untranslated_string
= false;
6447 matching_parens parens
;
6448 if (!parens
.require_open (parser
))
6450 parser
->lex_untranslated_string
= true;
6453 expr
= c_parser_expression (parser
);
6454 mark_exp_read (expr
.value
);
6455 parser
->lex_untranslated_string
= true;
6456 if (!parens
.require_close (parser
))
6458 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6461 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
6463 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6464 c_parser_consume_token (parser
);
6471 /* Parse asm clobbers, a GNU extension.
6475 asm-clobbers , asm-string-literal
6479 c_parser_asm_clobbers (c_parser
*parser
)
6481 tree list
= NULL_TREE
;
6484 tree str
= c_parser_asm_string_literal (parser
);
6486 list
= tree_cons (NULL_TREE
, str
, list
);
6489 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6490 c_parser_consume_token (parser
);
6497 /* Parse asm goto labels, a GNU extension.
6501 asm-goto-operands , identifier
6505 c_parser_asm_goto_operands (c_parser
*parser
)
6507 tree list
= NULL_TREE
;
6512 if (c_parser_next_token_is (parser
, CPP_NAME
))
6514 c_token
*tok
= c_parser_peek_token (parser
);
6516 label
= lookup_label_for_goto (tok
->location
, name
);
6517 c_parser_consume_token (parser
);
6518 TREE_USED (label
) = 1;
6522 c_parser_error (parser
, "expected identifier");
6526 name
= build_string (IDENTIFIER_LENGTH (name
),
6527 IDENTIFIER_POINTER (name
));
6528 list
= tree_cons (name
, label
, list
);
6529 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6530 c_parser_consume_token (parser
);
6532 return nreverse (list
);
6536 /* Parse an expression other than a compound expression; that is, an
6537 assignment expression (C90 6.3.16, C99 6.5.16, C11 6.5.16). If
6538 AFTER is not NULL then it is an Objective-C message expression which
6539 is the primary-expression starting the expression as an initializer.
6541 assignment-expression:
6542 conditional-expression
6543 unary-expression assignment-operator assignment-expression
6545 assignment-operator: one of
6546 = *= /= %= += -= <<= >>= &= ^= |=
6548 In GNU C we accept any conditional expression on the LHS and
6549 diagnose the invalid lvalue rather than producing a syntax
6552 static struct c_expr
6553 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
6554 tree omp_atomic_lhs
)
6556 struct c_expr lhs
, rhs
, ret
;
6557 enum tree_code code
;
6558 location_t op_location
, exp_location
;
6559 gcc_assert (!after
|| c_dialect_objc ());
6560 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
6561 op_location
= c_parser_peek_token (parser
)->location
;
6562 switch (c_parser_peek_token (parser
)->type
)
6571 code
= TRUNC_DIV_EXPR
;
6574 code
= TRUNC_MOD_EXPR
;
6589 code
= BIT_AND_EXPR
;
6592 code
= BIT_XOR_EXPR
;
6595 code
= BIT_IOR_EXPR
;
6600 c_parser_consume_token (parser
);
6601 exp_location
= c_parser_peek_token (parser
)->location
;
6602 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6603 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6605 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6606 code
, exp_location
, rhs
.value
,
6608 set_c_expr_source_range (&ret
, lhs
.get_start (), rhs
.get_finish ());
6609 if (code
== NOP_EXPR
)
6610 ret
.original_code
= MODIFY_EXPR
;
6613 TREE_NO_WARNING (ret
.value
) = 1;
6614 ret
.original_code
= ERROR_MARK
;
6616 ret
.original_type
= NULL
;
6620 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15, C11 6.5.15). If
6621 AFTER is not NULL then it is an Objective-C message expression which is
6622 the primary-expression starting the expression as an initializer.
6624 conditional-expression:
6625 logical-OR-expression
6626 logical-OR-expression ? expression : conditional-expression
6630 conditional-expression:
6631 logical-OR-expression ? : conditional-expression
6634 static struct c_expr
6635 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6636 tree omp_atomic_lhs
)
6638 struct c_expr cond
, exp1
, exp2
, ret
;
6639 location_t start
, cond_loc
, colon_loc
;
6641 gcc_assert (!after
|| c_dialect_objc ());
6643 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6645 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6647 if (cond
.value
!= error_mark_node
)
6648 start
= cond
.get_start ();
6650 start
= UNKNOWN_LOCATION
;
6651 cond_loc
= c_parser_peek_token (parser
)->location
;
6652 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6653 c_parser_consume_token (parser
);
6654 if (c_parser_next_token_is (parser
, CPP_COLON
))
6656 tree eptype
= NULL_TREE
;
6658 location_t middle_loc
= c_parser_peek_token (parser
)->location
;
6659 pedwarn (middle_loc
, OPT_Wpedantic
,
6660 "ISO C forbids omitting the middle term of a ?: expression");
6661 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6663 eptype
= TREE_TYPE (cond
.value
);
6664 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6666 tree e
= cond
.value
;
6667 while (TREE_CODE (e
) == COMPOUND_EXPR
)
6668 e
= TREE_OPERAND (e
, 1);
6669 warn_for_omitted_condop (middle_loc
, e
);
6670 /* Make sure first operand is calculated only once. */
6671 exp1
.value
= save_expr (default_conversion (cond
.value
));
6673 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6674 exp1
.original_type
= NULL
;
6675 exp1
.src_range
= cond
.src_range
;
6676 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6677 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6682 = c_objc_common_truthvalue_conversion
6683 (cond_loc
, default_conversion (cond
.value
));
6684 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6685 exp1
= c_parser_expression_conv (parser
);
6686 mark_exp_read (exp1
.value
);
6687 c_inhibit_evaluation_warnings
+=
6688 ((cond
.value
== truthvalue_true_node
)
6689 - (cond
.value
== truthvalue_false_node
));
6692 colon_loc
= c_parser_peek_token (parser
)->location
;
6693 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6695 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6697 ret
.original_code
= ERROR_MARK
;
6698 ret
.original_type
= NULL
;
6702 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6703 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6704 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6706 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6707 location_t loc1
= make_location (exp1
.get_start (), exp1
.src_range
);
6708 location_t loc2
= make_location (exp2
.get_start (), exp2
.src_range
);
6709 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6710 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6711 exp1
.value
, exp1
.original_type
, loc1
,
6712 exp2
.value
, exp2
.original_type
, loc2
);
6713 ret
.original_code
= ERROR_MARK
;
6714 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6715 ret
.original_type
= NULL
;
6720 /* If both sides are enum type, the default conversion will have
6721 made the type of the result be an integer type. We want to
6722 remember the enum types we started with. */
6723 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6724 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6725 ret
.original_type
= ((t1
!= error_mark_node
6726 && t2
!= error_mark_node
6727 && (TYPE_MAIN_VARIANT (t1
)
6728 == TYPE_MAIN_VARIANT (t2
)))
6732 set_c_expr_source_range (&ret
, start
, exp2
.get_finish ());
6736 /* Parse a binary expression; that is, a logical-OR-expression (C90
6737 6.3.5-6.3.14, C99 6.5.5-6.5.14, C11 6.5.5-6.5.14). If AFTER is not
6738 NULL then it is an Objective-C message expression which is the
6739 primary-expression starting the expression as an initializer.
6741 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6742 when it should be the unfolded lhs. In a valid OpenMP source,
6743 one of the operands of the toplevel binary expression must be equal
6744 to it. In that case, just return a build2 created binary operation
6745 rather than result of parser_build_binary_op.
6747 multiplicative-expression:
6749 multiplicative-expression * cast-expression
6750 multiplicative-expression / cast-expression
6751 multiplicative-expression % cast-expression
6753 additive-expression:
6754 multiplicative-expression
6755 additive-expression + multiplicative-expression
6756 additive-expression - multiplicative-expression
6760 shift-expression << additive-expression
6761 shift-expression >> additive-expression
6763 relational-expression:
6765 relational-expression < shift-expression
6766 relational-expression > shift-expression
6767 relational-expression <= shift-expression
6768 relational-expression >= shift-expression
6770 equality-expression:
6771 relational-expression
6772 equality-expression == relational-expression
6773 equality-expression != relational-expression
6777 AND-expression & equality-expression
6779 exclusive-OR-expression:
6781 exclusive-OR-expression ^ AND-expression
6783 inclusive-OR-expression:
6784 exclusive-OR-expression
6785 inclusive-OR-expression | exclusive-OR-expression
6787 logical-AND-expression:
6788 inclusive-OR-expression
6789 logical-AND-expression && inclusive-OR-expression
6791 logical-OR-expression:
6792 logical-AND-expression
6793 logical-OR-expression || logical-AND-expression
6796 static struct c_expr
6797 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6798 tree omp_atomic_lhs
)
6800 /* A binary expression is parsed using operator-precedence parsing,
6801 with the operands being cast expressions. All the binary
6802 operators are left-associative. Thus a binary expression is of
6805 E0 op1 E1 op2 E2 ...
6807 which we represent on a stack. On the stack, the precedence
6808 levels are strictly increasing. When a new operator is
6809 encountered of higher precedence than that at the top of the
6810 stack, it is pushed; its LHS is the top expression, and its RHS
6811 is everything parsed until it is popped. When a new operator is
6812 encountered with precedence less than or equal to that at the top
6813 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6814 by the result of the operation until the operator at the top of
6815 the stack has lower precedence than the new operator or there is
6816 only one element on the stack; then the top expression is the LHS
6817 of the new operator. In the case of logical AND and OR
6818 expressions, we also need to adjust c_inhibit_evaluation_warnings
6819 as appropriate when the operators are pushed and popped. */
6822 /* The expression at this stack level. */
6824 /* The precedence of the operator on its left, PREC_NONE at the
6825 bottom of the stack. */
6826 enum c_parser_prec prec
;
6827 /* The operation on its left. */
6829 /* The source location of this operation. */
6831 /* The sizeof argument if expr.original_code == SIZEOF_EXPR. */
6835 /* Location of the binary operator. */
6836 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6839 switch (stack[sp].op) \
6841 case TRUTH_ANDIF_EXPR: \
6842 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6843 == truthvalue_false_node); \
6845 case TRUTH_ORIF_EXPR: \
6846 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6847 == truthvalue_true_node); \
6849 case TRUNC_DIV_EXPR: \
6850 if (stack[sp - 1].expr.original_code == SIZEOF_EXPR \
6851 && stack[sp].expr.original_code == SIZEOF_EXPR) \
6853 tree type0 = stack[sp - 1].sizeof_arg; \
6854 tree type1 = stack[sp].sizeof_arg; \
6855 tree first_arg = type0; \
6856 if (!TYPE_P (type0)) \
6857 type0 = TREE_TYPE (type0); \
6858 if (!TYPE_P (type1)) \
6859 type1 = TREE_TYPE (type1); \
6860 if (POINTER_TYPE_P (type0) \
6861 && comptypes (TREE_TYPE (type0), type1) \
6862 && !(TREE_CODE (first_arg) == PARM_DECL \
6863 && C_ARRAY_PARAMETER (first_arg) \
6864 && warn_sizeof_array_argument)) \
6865 if (warning_at (stack[sp].loc, OPT_Wsizeof_pointer_div, \
6866 "division %<sizeof (%T) / sizeof (%T)%> does " \
6867 "not compute the number of array elements", \
6869 if (DECL_P (first_arg)) \
6870 inform (DECL_SOURCE_LOCATION (first_arg), \
6871 "first %<sizeof%> operand was declared here"); \
6877 stack[sp - 1].expr \
6878 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6879 stack[sp - 1].expr, true, true); \
6881 = convert_lvalue_to_rvalue (stack[sp].loc, \
6882 stack[sp].expr, true, true); \
6883 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6884 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6885 && ((1 << stack[sp].prec) \
6886 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6887 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6888 && stack[sp].op != TRUNC_MOD_EXPR \
6889 && stack[0].expr.value != error_mark_node \
6890 && stack[1].expr.value != error_mark_node \
6891 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6892 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6893 stack[0].expr.value \
6894 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6895 stack[0].expr.value, stack[1].expr.value); \
6897 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6899 stack[sp - 1].expr, \
6903 gcc_assert (!after
|| c_dialect_objc ());
6904 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6905 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6906 stack
[0].prec
= PREC_NONE
;
6907 stack
[0].sizeof_arg
= c_last_sizeof_arg
;
6911 enum c_parser_prec oprec
;
6912 enum tree_code ocode
;
6913 source_range src_range
;
6916 switch (c_parser_peek_token (parser
)->type
)
6924 ocode
= TRUNC_DIV_EXPR
;
6928 ocode
= TRUNC_MOD_EXPR
;
6940 ocode
= LSHIFT_EXPR
;
6944 ocode
= RSHIFT_EXPR
;
6958 case CPP_GREATER_EQ
:
6971 oprec
= PREC_BITAND
;
6972 ocode
= BIT_AND_EXPR
;
6975 oprec
= PREC_BITXOR
;
6976 ocode
= BIT_XOR_EXPR
;
6980 ocode
= BIT_IOR_EXPR
;
6983 oprec
= PREC_LOGAND
;
6984 ocode
= TRUTH_ANDIF_EXPR
;
6988 ocode
= TRUTH_ORIF_EXPR
;
6991 /* Not a binary operator, so end of the binary
6995 binary_loc
= c_parser_peek_token (parser
)->location
;
6996 while (oprec
<= stack
[sp
].prec
)
6998 c_parser_consume_token (parser
);
7001 case TRUTH_ANDIF_EXPR
:
7002 src_range
= stack
[sp
].expr
.src_range
;
7004 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
7005 stack
[sp
].expr
, true, true);
7006 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
7007 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
7008 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
7009 == truthvalue_false_node
);
7010 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
7012 case TRUTH_ORIF_EXPR
:
7013 src_range
= stack
[sp
].expr
.src_range
;
7015 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
7016 stack
[sp
].expr
, true, true);
7017 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
7018 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
7019 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
7020 == truthvalue_true_node
);
7021 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
7027 stack
[sp
].loc
= binary_loc
;
7028 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
7029 stack
[sp
].prec
= oprec
;
7030 stack
[sp
].op
= ocode
;
7031 stack
[sp
].sizeof_arg
= c_last_sizeof_arg
;
7036 return stack
[0].expr
;
7040 /* Parse a cast expression (C90 6.3.4, C99 6.5.4, C11 6.5.4). If AFTER
7041 is not NULL then it is an Objective-C message expression which is the
7042 primary-expression starting the expression as an initializer.
7046 ( type-name ) unary-expression
7049 static struct c_expr
7050 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
7052 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
7053 gcc_assert (!after
|| c_dialect_objc ());
7055 return c_parser_postfix_expression_after_primary (parser
,
7057 /* If the expression begins with a parenthesized type name, it may
7058 be either a cast or a compound literal; we need to see whether
7059 the next character is '{' to tell the difference. If not, it is
7060 an unary expression. Full detection of unknown typenames here
7061 would require a 3-token lookahead. */
7062 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7063 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7065 struct c_type_name
*type_name
;
7068 matching_parens parens
;
7069 parens
.consume_open (parser
);
7070 type_name
= c_parser_type_name (parser
, true);
7071 parens
.skip_until_found_close (parser
);
7072 if (type_name
== NULL
)
7075 ret
.original_code
= ERROR_MARK
;
7076 ret
.original_type
= NULL
;
7080 /* Save casted types in the function's used types hash table. */
7081 used_types_insert (type_name
->specs
->type
);
7083 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7084 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
7086 if (type_name
->specs
->alignas_p
)
7087 error_at (type_name
->specs
->locations
[cdw_alignas
],
7088 "alignment specified for type name in cast");
7090 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7091 expr
= c_parser_cast_expression (parser
, NULL
);
7092 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
7094 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
7095 if (ret
.value
&& expr
.value
)
7096 set_c_expr_source_range (&ret
, cast_loc
, expr
.get_finish ());
7097 ret
.original_code
= ERROR_MARK
;
7098 ret
.original_type
= NULL
;
7102 return c_parser_unary_expression (parser
);
7105 /* Parse an unary expression (C90 6.3.3, C99 6.5.3, C11 6.5.3).
7111 unary-operator cast-expression
7112 sizeof unary-expression
7113 sizeof ( type-name )
7115 unary-operator: one of
7121 __alignof__ unary-expression
7122 __alignof__ ( type-name )
7125 (C11 permits _Alignof with type names only.)
7127 unary-operator: one of
7128 __extension__ __real__ __imag__
7130 Transactional Memory:
7133 transaction-expression
7135 In addition, the GNU syntax treats ++ and -- as unary operators, so
7136 they may be applied to cast expressions with errors for non-lvalues
7139 static struct c_expr
7140 c_parser_unary_expression (c_parser
*parser
)
7143 struct c_expr ret
, op
;
7144 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7147 ret
.original_code
= ERROR_MARK
;
7148 ret
.original_type
= NULL
;
7149 switch (c_parser_peek_token (parser
)->type
)
7152 c_parser_consume_token (parser
);
7153 exp_loc
= c_parser_peek_token (parser
)->location
;
7154 op
= c_parser_cast_expression (parser
, NULL
);
7156 op
= default_function_array_read_conversion (exp_loc
, op
);
7157 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
7158 case CPP_MINUS_MINUS
:
7159 c_parser_consume_token (parser
);
7160 exp_loc
= c_parser_peek_token (parser
)->location
;
7161 op
= c_parser_cast_expression (parser
, NULL
);
7163 op
= default_function_array_read_conversion (exp_loc
, op
);
7164 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
7166 c_parser_consume_token (parser
);
7167 op
= c_parser_cast_expression (parser
, NULL
);
7168 mark_exp_read (op
.value
);
7169 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
7172 c_parser_consume_token (parser
);
7173 exp_loc
= c_parser_peek_token (parser
)->location
;
7174 op
= c_parser_cast_expression (parser
, NULL
);
7175 finish
= op
.get_finish ();
7176 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7177 location_t combined_loc
= make_location (op_loc
, op_loc
, finish
);
7178 ret
.value
= build_indirect_ref (combined_loc
, op
.value
, RO_UNARY_STAR
);
7179 ret
.src_range
.m_start
= op_loc
;
7180 ret
.src_range
.m_finish
= finish
;
7184 if (!c_dialect_objc () && !in_system_header_at (input_location
))
7187 "traditional C rejects the unary plus operator");
7188 c_parser_consume_token (parser
);
7189 exp_loc
= c_parser_peek_token (parser
)->location
;
7190 op
= c_parser_cast_expression (parser
, NULL
);
7191 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7192 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
7194 c_parser_consume_token (parser
);
7195 exp_loc
= c_parser_peek_token (parser
)->location
;
7196 op
= c_parser_cast_expression (parser
, NULL
);
7197 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7198 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
7200 c_parser_consume_token (parser
);
7201 exp_loc
= c_parser_peek_token (parser
)->location
;
7202 op
= c_parser_cast_expression (parser
, NULL
);
7203 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7204 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
7206 c_parser_consume_token (parser
);
7207 exp_loc
= c_parser_peek_token (parser
)->location
;
7208 op
= c_parser_cast_expression (parser
, NULL
);
7209 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7210 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
7212 /* Refer to the address of a label as a pointer. */
7213 c_parser_consume_token (parser
);
7214 if (c_parser_next_token_is (parser
, CPP_NAME
))
7216 ret
.value
= finish_label_address_expr
7217 (c_parser_peek_token (parser
)->value
, op_loc
);
7218 set_c_expr_source_range (&ret
, op_loc
,
7219 c_parser_peek_token (parser
)->get_finish ());
7220 c_parser_consume_token (parser
);
7224 c_parser_error (parser
, "expected identifier");
7229 switch (c_parser_peek_token (parser
)->keyword
)
7232 return c_parser_sizeof_expression (parser
);
7234 return c_parser_alignof_expression (parser
);
7236 c_parser_consume_token (parser
);
7237 ext
= disable_extension_diagnostics ();
7238 ret
= c_parser_cast_expression (parser
, NULL
);
7239 restore_extension_diagnostics (ext
);
7242 c_parser_consume_token (parser
);
7243 exp_loc
= c_parser_peek_token (parser
)->location
;
7244 op
= c_parser_cast_expression (parser
, NULL
);
7245 op
= default_function_array_conversion (exp_loc
, op
);
7246 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
7248 c_parser_consume_token (parser
);
7249 exp_loc
= c_parser_peek_token (parser
)->location
;
7250 op
= c_parser_cast_expression (parser
, NULL
);
7251 op
= default_function_array_conversion (exp_loc
, op
);
7252 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
7253 case RID_TRANSACTION_ATOMIC
:
7254 case RID_TRANSACTION_RELAXED
:
7255 return c_parser_transaction_expression (parser
,
7256 c_parser_peek_token (parser
)->keyword
);
7258 return c_parser_postfix_expression (parser
);
7261 return c_parser_postfix_expression (parser
);
7265 /* Parse a sizeof expression. */
7267 static struct c_expr
7268 c_parser_sizeof_expression (c_parser
*parser
)
7271 struct c_expr result
;
7272 location_t expr_loc
;
7273 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
7276 location_t finish
= UNKNOWN_LOCATION
;
7278 start
= c_parser_peek_token (parser
)->location
;
7280 c_parser_consume_token (parser
);
7281 c_inhibit_evaluation_warnings
++;
7283 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7284 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7286 /* Either sizeof ( type-name ) or sizeof unary-expression
7287 starting with a compound literal. */
7288 struct c_type_name
*type_name
;
7289 matching_parens parens
;
7290 parens
.consume_open (parser
);
7291 expr_loc
= c_parser_peek_token (parser
)->location
;
7292 type_name
= c_parser_type_name (parser
, true);
7293 parens
.skip_until_found_close (parser
);
7294 finish
= parser
->tokens_buf
[0].location
;
7295 if (type_name
== NULL
)
7298 c_inhibit_evaluation_warnings
--;
7301 ret
.original_code
= ERROR_MARK
;
7302 ret
.original_type
= NULL
;
7305 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7307 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7310 finish
= expr
.get_finish ();
7313 /* sizeof ( type-name ). */
7314 if (type_name
->specs
->alignas_p
)
7315 error_at (type_name
->specs
->locations
[cdw_alignas
],
7316 "alignment specified for type name in %<sizeof%>");
7317 c_inhibit_evaluation_warnings
--;
7319 result
= c_expr_sizeof_type (expr_loc
, type_name
);
7323 expr_loc
= c_parser_peek_token (parser
)->location
;
7324 expr
= c_parser_unary_expression (parser
);
7325 finish
= expr
.get_finish ();
7327 c_inhibit_evaluation_warnings
--;
7329 mark_exp_read (expr
.value
);
7330 if (TREE_CODE (expr
.value
) == COMPONENT_REF
7331 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
7332 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
7333 result
= c_expr_sizeof_expr (expr_loc
, expr
);
7335 if (finish
!= UNKNOWN_LOCATION
)
7336 set_c_expr_source_range (&result
, start
, finish
);
7340 /* Parse an alignof expression. */
7342 static struct c_expr
7343 c_parser_alignof_expression (c_parser
*parser
)
7346 location_t start_loc
= c_parser_peek_token (parser
)->location
;
7348 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
7349 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
7350 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
7352 /* A diagnostic is not required for the use of this identifier in
7353 the implementation namespace; only diagnose it for the C11
7354 spelling because of existing code using the other spellings. */
7358 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
7361 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
7364 c_parser_consume_token (parser
);
7365 c_inhibit_evaluation_warnings
++;
7367 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7368 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7370 /* Either __alignof__ ( type-name ) or __alignof__
7371 unary-expression starting with a compound literal. */
7373 struct c_type_name
*type_name
;
7375 matching_parens parens
;
7376 parens
.consume_open (parser
);
7377 loc
= c_parser_peek_token (parser
)->location
;
7378 type_name
= c_parser_type_name (parser
, true);
7379 end_loc
= c_parser_peek_token (parser
)->location
;
7380 parens
.skip_until_found_close (parser
);
7381 if (type_name
== NULL
)
7384 c_inhibit_evaluation_warnings
--;
7387 ret
.original_code
= ERROR_MARK
;
7388 ret
.original_type
= NULL
;
7391 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7393 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7398 /* alignof ( type-name ). */
7399 if (type_name
->specs
->alignas_p
)
7400 error_at (type_name
->specs
->locations
[cdw_alignas
],
7401 "alignment specified for type name in %qE",
7403 c_inhibit_evaluation_warnings
--;
7405 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
7407 false, is_c11_alignof
, 1);
7408 ret
.original_code
= ERROR_MARK
;
7409 ret
.original_type
= NULL
;
7410 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7416 expr
= c_parser_unary_expression (parser
);
7417 end_loc
= expr
.src_range
.m_finish
;
7419 mark_exp_read (expr
.value
);
7420 c_inhibit_evaluation_warnings
--;
7424 OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
7426 ret
.value
= c_alignof_expr (start_loc
, expr
.value
);
7427 ret
.original_code
= ERROR_MARK
;
7428 ret
.original_type
= NULL
;
7429 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7434 /* Helper function to read arguments of builtins which are interfaces
7435 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
7436 others. The name of the builtin is passed using BNAME parameter.
7437 Function returns true if there were no errors while parsing and
7438 stores the arguments in CEXPR_LIST. If it returns true,
7439 *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
7442 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
7443 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
7445 location_t
*out_close_paren_loc
)
7447 location_t loc
= c_parser_peek_token (parser
)->location
;
7448 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7450 bool saved_force_folding_builtin_constant_p
;
7452 *ret_cexpr_list
= NULL
;
7453 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
7455 error_at (loc
, "cannot take address of %qs", bname
);
7459 c_parser_consume_token (parser
);
7461 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7463 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7464 c_parser_consume_token (parser
);
7468 saved_force_folding_builtin_constant_p
7469 = force_folding_builtin_constant_p
;
7470 force_folding_builtin_constant_p
|= choose_expr_p
;
7471 expr
= c_parser_expr_no_commas (parser
, NULL
);
7472 force_folding_builtin_constant_p
7473 = saved_force_folding_builtin_constant_p
;
7474 vec_alloc (cexpr_list
, 1);
7475 vec_safe_push (cexpr_list
, expr
);
7476 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7478 c_parser_consume_token (parser
);
7479 expr
= c_parser_expr_no_commas (parser
, NULL
);
7480 vec_safe_push (cexpr_list
, expr
);
7483 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7484 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7487 *ret_cexpr_list
= cexpr_list
;
7491 /* This represents a single generic-association. */
7493 struct c_generic_association
7495 /* The location of the starting token of the type. */
7496 location_t type_location
;
7497 /* The association's type, or NULL_TREE for 'default'. */
7499 /* The association's expression. */
7500 struct c_expr expression
;
7503 /* Parse a generic-selection. (C11 6.5.1.1).
7506 _Generic ( assignment-expression , generic-assoc-list )
7510 generic-assoc-list , generic-association
7512 generic-association:
7513 type-name : assignment-expression
7514 default : assignment-expression
7517 static struct c_expr
7518 c_parser_generic_selection (c_parser
*parser
)
7520 struct c_expr selector
, error_expr
;
7522 struct c_generic_association matched_assoc
;
7523 bool match_found
= false;
7524 location_t generic_loc
, selector_loc
;
7526 error_expr
.original_code
= ERROR_MARK
;
7527 error_expr
.original_type
= NULL
;
7528 error_expr
.set_error ();
7529 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
7530 matched_assoc
.type
= NULL_TREE
;
7531 matched_assoc
.expression
= error_expr
;
7533 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
7534 generic_loc
= c_parser_peek_token (parser
)->location
;
7535 c_parser_consume_token (parser
);
7537 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7538 "ISO C99 does not support %<_Generic%>");
7540 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7541 "ISO C90 does not support %<_Generic%>");
7543 matching_parens parens
;
7544 if (!parens
.require_open (parser
))
7547 c_inhibit_evaluation_warnings
++;
7548 selector_loc
= c_parser_peek_token (parser
)->location
;
7549 selector
= c_parser_expr_no_commas (parser
, NULL
);
7550 selector
= default_function_array_conversion (selector_loc
, selector
);
7551 c_inhibit_evaluation_warnings
--;
7553 if (selector
.value
== error_mark_node
)
7555 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7558 selector_type
= TREE_TYPE (selector
.value
);
7559 /* In ISO C terms, rvalues (including the controlling expression of
7560 _Generic) do not have qualified types. */
7561 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
7562 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
7563 /* In ISO C terms, _Noreturn is not part of the type of expressions
7564 such as &abort, but in GCC it is represented internally as a type
7566 if (FUNCTION_POINTER_TYPE_P (selector_type
)
7567 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
7569 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
7571 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7573 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7577 auto_vec
<c_generic_association
> associations
;
7580 struct c_generic_association assoc
, *iter
;
7582 c_token
*token
= c_parser_peek_token (parser
);
7584 assoc
.type_location
= token
->location
;
7585 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
7587 c_parser_consume_token (parser
);
7588 assoc
.type
= NULL_TREE
;
7592 struct c_type_name
*type_name
;
7594 type_name
= c_parser_type_name (parser
);
7595 if (type_name
== NULL
)
7597 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7600 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
7601 if (assoc
.type
== error_mark_node
)
7603 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7607 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
7608 error_at (assoc
.type_location
,
7609 "%<_Generic%> association has function type");
7610 else if (!COMPLETE_TYPE_P (assoc
.type
))
7611 error_at (assoc
.type_location
,
7612 "%<_Generic%> association has incomplete type");
7614 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
7615 error_at (assoc
.type_location
,
7616 "%<_Generic%> association has "
7617 "variable length type");
7620 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7622 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7626 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
7627 if (assoc
.expression
.value
== error_mark_node
)
7629 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7633 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
7635 if (assoc
.type
== NULL_TREE
)
7637 if (iter
->type
== NULL_TREE
)
7639 error_at (assoc
.type_location
,
7640 "duplicate %<default%> case in %<_Generic%>");
7641 inform (iter
->type_location
, "original %<default%> is here");
7644 else if (iter
->type
!= NULL_TREE
)
7646 if (comptypes (assoc
.type
, iter
->type
))
7648 error_at (assoc
.type_location
,
7649 "%<_Generic%> specifies two compatible types");
7650 inform (iter
->type_location
, "compatible type is here");
7655 if (assoc
.type
== NULL_TREE
)
7659 matched_assoc
= assoc
;
7663 else if (comptypes (assoc
.type
, selector_type
))
7665 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7667 matched_assoc
= assoc
;
7672 error_at (assoc
.type_location
,
7673 "%<_Generic%> selector matches multiple associations");
7674 inform (matched_assoc
.type_location
,
7675 "other match is here");
7679 associations
.safe_push (assoc
);
7681 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7683 c_parser_consume_token (parser
);
7686 if (!parens
.require_close (parser
))
7688 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7694 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7695 "compatible with any association",
7700 return matched_assoc
.expression
;
7703 /* Check the validity of a function pointer argument *EXPR (argument
7704 position POS) to __builtin_tgmath. Return the number of function
7705 arguments if possibly valid; return 0 having reported an error if
7709 check_tgmath_function (c_expr
*expr
, unsigned int pos
)
7711 tree type
= TREE_TYPE (expr
->value
);
7712 if (!FUNCTION_POINTER_TYPE_P (type
))
7714 error_at (expr
->get_location (),
7715 "argument %u of %<__builtin_tgmath%> is not a function pointer",
7719 type
= TREE_TYPE (type
);
7720 if (!prototype_p (type
))
7722 error_at (expr
->get_location (),
7723 "argument %u of %<__builtin_tgmath%> is unprototyped", pos
);
7726 if (stdarg_p (type
))
7728 error_at (expr
->get_location (),
7729 "argument %u of %<__builtin_tgmath%> has variable arguments",
7733 unsigned int nargs
= 0;
7734 function_args_iterator iter
;
7736 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
7738 if (t
== void_type_node
)
7744 error_at (expr
->get_location (),
7745 "argument %u of %<__builtin_tgmath%> has no arguments", pos
);
7751 /* Ways in which a parameter or return value of a type-generic macro
7752 may vary between the different functions the macro may call. */
7753 enum tgmath_parm_kind
7755 tgmath_fixed
, tgmath_real
, tgmath_complex
7758 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2,
7759 C11 6.5.1-6.5.2). Compound literals aren't handled here; callers have to
7760 call c_parser_postfix_expression_after_paren_type on encountering them.
7764 postfix-expression [ expression ]
7765 postfix-expression ( argument-expression-list[opt] )
7766 postfix-expression . identifier
7767 postfix-expression -> identifier
7768 postfix-expression ++
7769 postfix-expression --
7770 ( type-name ) { initializer-list }
7771 ( type-name ) { initializer-list , }
7773 argument-expression-list:
7775 argument-expression-list , argument-expression
7788 (treated as a keyword in GNU C)
7791 ( compound-statement )
7792 __builtin_va_arg ( assignment-expression , type-name )
7793 __builtin_offsetof ( type-name , offsetof-member-designator )
7794 __builtin_choose_expr ( assignment-expression ,
7795 assignment-expression ,
7796 assignment-expression )
7797 __builtin_types_compatible_p ( type-name , type-name )
7798 __builtin_tgmath ( expr-list )
7799 __builtin_complex ( assignment-expression , assignment-expression )
7800 __builtin_shuffle ( assignment-expression , assignment-expression )
7801 __builtin_shuffle ( assignment-expression ,
7802 assignment-expression ,
7803 assignment-expression, )
7805 offsetof-member-designator:
7807 offsetof-member-designator . identifier
7808 offsetof-member-designator [ expression ]
7813 [ objc-receiver objc-message-args ]
7814 @selector ( objc-selector-arg )
7815 @protocol ( identifier )
7816 @encode ( type-name )
7818 Classname . identifier
7821 static struct c_expr
7822 c_parser_postfix_expression (c_parser
*parser
)
7824 struct c_expr expr
, e1
;
7825 struct c_type_name
*t1
, *t2
;
7826 location_t loc
= c_parser_peek_token (parser
)->location
;
7827 source_range tok_range
= c_parser_peek_token (parser
)->get_range ();
7828 expr
.original_code
= ERROR_MARK
;
7829 expr
.original_type
= NULL
;
7830 switch (c_parser_peek_token (parser
)->type
)
7833 expr
.value
= c_parser_peek_token (parser
)->value
;
7834 set_c_expr_source_range (&expr
, tok_range
);
7835 loc
= c_parser_peek_token (parser
)->location
;
7836 c_parser_consume_token (parser
);
7837 if (TREE_CODE (expr
.value
) == FIXED_CST
7838 && !targetm
.fixed_point_supported_p ())
7840 error_at (loc
, "fixed-point types not supported for this target");
7848 expr
.value
= c_parser_peek_token (parser
)->value
;
7849 /* For the purpose of warning when a pointer is compared with
7850 a zero character constant. */
7851 expr
.original_type
= char_type_node
;
7852 set_c_expr_source_range (&expr
, tok_range
);
7853 c_parser_consume_token (parser
);
7859 case CPP_UTF8STRING
:
7860 expr
.value
= c_parser_peek_token (parser
)->value
;
7861 set_c_expr_source_range (&expr
, tok_range
);
7862 expr
.original_code
= STRING_CST
;
7863 c_parser_consume_token (parser
);
7865 case CPP_OBJC_STRING
:
7866 gcc_assert (c_dialect_objc ());
7868 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7869 set_c_expr_source_range (&expr
, tok_range
);
7870 c_parser_consume_token (parser
);
7873 switch (c_parser_peek_token (parser
)->id_kind
)
7877 tree id
= c_parser_peek_token (parser
)->value
;
7878 c_parser_consume_token (parser
);
7879 expr
.value
= build_external_ref (loc
, id
,
7880 (c_parser_peek_token (parser
)->type
7882 &expr
.original_type
);
7883 set_c_expr_source_range (&expr
, tok_range
);
7886 case C_ID_CLASSNAME
:
7888 /* Here we parse the Objective-C 2.0 Class.name dot
7890 tree class_name
= c_parser_peek_token (parser
)->value
;
7892 c_parser_consume_token (parser
);
7893 gcc_assert (c_dialect_objc ());
7894 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7899 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7901 c_parser_error (parser
, "expected identifier");
7905 c_token
*component_tok
= c_parser_peek_token (parser
);
7906 component
= component_tok
->value
;
7907 location_t end_loc
= component_tok
->get_finish ();
7908 c_parser_consume_token (parser
);
7909 expr
.value
= objc_build_class_component_ref (class_name
,
7911 set_c_expr_source_range (&expr
, loc
, end_loc
);
7915 c_parser_error (parser
, "expected expression");
7920 case CPP_OPEN_PAREN
:
7921 /* A parenthesized expression, statement expression or compound
7923 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7925 /* A statement expression. */
7927 location_t brace_loc
;
7928 c_parser_consume_token (parser
);
7929 brace_loc
= c_parser_peek_token (parser
)->location
;
7930 c_parser_consume_token (parser
);
7931 if (!building_stmt_list_p ())
7933 error_at (loc
, "braced-group within expression allowed "
7934 "only inside a function");
7935 parser
->error
= true;
7936 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7937 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7941 stmt
= c_begin_stmt_expr ();
7942 c_parser_compound_statement_nostart (parser
);
7943 location_t close_loc
= c_parser_peek_token (parser
)->location
;
7944 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7946 pedwarn (loc
, OPT_Wpedantic
,
7947 "ISO C forbids braced-groups within expressions");
7948 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7949 set_c_expr_source_range (&expr
, loc
, close_loc
);
7950 mark_exp_read (expr
.value
);
7954 /* A parenthesized expression. */
7955 location_t loc_open_paren
= c_parser_peek_token (parser
)->location
;
7956 c_parser_consume_token (parser
);
7957 expr
= c_parser_expression (parser
);
7958 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7959 TREE_NO_WARNING (expr
.value
) = 1;
7960 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
7961 && expr
.original_code
!= SIZEOF_EXPR
)
7962 expr
.original_code
= ERROR_MARK
;
7963 /* Don't change EXPR.ORIGINAL_TYPE. */
7964 location_t loc_close_paren
= c_parser_peek_token (parser
)->location
;
7965 set_c_expr_source_range (&expr
, loc_open_paren
, loc_close_paren
);
7966 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7967 "expected %<)%>", loc_open_paren
);
7971 switch (c_parser_peek_token (parser
)->keyword
)
7973 case RID_FUNCTION_NAME
:
7974 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7975 "%<__FUNCTION__%> predefined identifier");
7976 expr
.value
= fname_decl (loc
,
7977 c_parser_peek_token (parser
)->keyword
,
7978 c_parser_peek_token (parser
)->value
);
7979 set_c_expr_source_range (&expr
, loc
, loc
);
7980 c_parser_consume_token (parser
);
7982 case RID_PRETTY_FUNCTION_NAME
:
7983 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7984 "%<__PRETTY_FUNCTION__%> predefined identifier");
7985 expr
.value
= fname_decl (loc
,
7986 c_parser_peek_token (parser
)->keyword
,
7987 c_parser_peek_token (parser
)->value
);
7988 set_c_expr_source_range (&expr
, loc
, loc
);
7989 c_parser_consume_token (parser
);
7991 case RID_C99_FUNCTION_NAME
:
7992 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7993 "%<__func__%> predefined identifier");
7994 expr
.value
= fname_decl (loc
,
7995 c_parser_peek_token (parser
)->keyword
,
7996 c_parser_peek_token (parser
)->value
);
7997 set_c_expr_source_range (&expr
, loc
, loc
);
7998 c_parser_consume_token (parser
);
8002 location_t start_loc
= loc
;
8003 c_parser_consume_token (parser
);
8004 matching_parens parens
;
8005 if (!parens
.require_open (parser
))
8010 e1
= c_parser_expr_no_commas (parser
, NULL
);
8011 mark_exp_read (e1
.value
);
8012 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
8013 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8015 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8019 loc
= c_parser_peek_token (parser
)->location
;
8020 t1
= c_parser_type_name (parser
);
8021 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
8022 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8030 tree type_expr
= NULL_TREE
;
8031 expr
.value
= c_build_va_arg (start_loc
, e1
.value
, loc
,
8032 groktypename (t1
, &type_expr
, NULL
));
8035 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
8036 TREE_TYPE (expr
.value
), type_expr
,
8038 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
8040 set_c_expr_source_range (&expr
, start_loc
, end_loc
);
8046 c_parser_consume_token (parser
);
8047 matching_parens parens
;
8048 if (!parens
.require_open (parser
))
8053 t1
= c_parser_type_name (parser
);
8055 parser
->error
= true;
8056 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8057 gcc_assert (parser
->error
);
8060 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8064 tree type
= groktypename (t1
, NULL
, NULL
);
8066 if (type
== error_mark_node
)
8067 offsetof_ref
= error_mark_node
;
8070 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
8071 SET_EXPR_LOCATION (offsetof_ref
, loc
);
8073 /* Parse the second argument to __builtin_offsetof. We
8074 must have one identifier, and beyond that we want to
8075 accept sub structure and sub array references. */
8076 if (c_parser_next_token_is (parser
, CPP_NAME
))
8078 c_token
*comp_tok
= c_parser_peek_token (parser
);
8079 offsetof_ref
= build_component_ref
8080 (loc
, offsetof_ref
, comp_tok
->value
, comp_tok
->location
);
8081 c_parser_consume_token (parser
);
8082 while (c_parser_next_token_is (parser
, CPP_DOT
)
8083 || c_parser_next_token_is (parser
,
8085 || c_parser_next_token_is (parser
,
8088 if (c_parser_next_token_is (parser
, CPP_DEREF
))
8090 loc
= c_parser_peek_token (parser
)->location
;
8091 offsetof_ref
= build_array_ref (loc
,
8096 else if (c_parser_next_token_is (parser
, CPP_DOT
))
8099 c_parser_consume_token (parser
);
8100 if (c_parser_next_token_is_not (parser
,
8103 c_parser_error (parser
, "expected identifier");
8106 c_token
*comp_tok
= c_parser_peek_token (parser
);
8107 offsetof_ref
= build_component_ref
8108 (loc
, offsetof_ref
, comp_tok
->value
,
8109 comp_tok
->location
);
8110 c_parser_consume_token (parser
);
8116 loc
= c_parser_peek_token (parser
)->location
;
8117 c_parser_consume_token (parser
);
8118 ce
= c_parser_expression (parser
);
8119 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8121 idx
= c_fully_fold (idx
, false, NULL
);
8122 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8124 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
8129 c_parser_error (parser
, "expected identifier");
8130 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
8131 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8133 expr
.value
= fold_offsetof (offsetof_ref
);
8134 set_c_expr_source_range (&expr
, loc
, end_loc
);
8137 case RID_CHOOSE_EXPR
:
8139 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8140 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
8142 location_t close_paren_loc
;
8144 c_parser_consume_token (parser
);
8145 if (!c_parser_get_builtin_args (parser
,
8146 "__builtin_choose_expr",
8154 if (vec_safe_length (cexpr_list
) != 3)
8156 error_at (loc
, "wrong number of arguments to "
8157 "%<__builtin_choose_expr%>");
8162 e1_p
= &(*cexpr_list
)[0];
8163 e2_p
= &(*cexpr_list
)[1];
8164 e3_p
= &(*cexpr_list
)[2];
8167 mark_exp_read (e2_p
->value
);
8168 mark_exp_read (e3_p
->value
);
8169 if (TREE_CODE (c
) != INTEGER_CST
8170 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
8172 "first argument to %<__builtin_choose_expr%> not"
8174 constant_expression_warning (c
);
8175 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
8176 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8179 case RID_TYPES_COMPATIBLE_P
:
8181 c_parser_consume_token (parser
);
8182 matching_parens parens
;
8183 if (!parens
.require_open (parser
))
8188 t1
= c_parser_type_name (parser
);
8194 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8196 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8200 t2
= c_parser_type_name (parser
);
8206 location_t close_paren_loc
= c_parser_peek_token (parser
)->location
;
8207 parens
.skip_until_found_close (parser
);
8209 e1
= groktypename (t1
, NULL
, NULL
);
8210 e2
= groktypename (t2
, NULL
, NULL
);
8211 if (e1
== error_mark_node
|| e2
== error_mark_node
)
8217 e1
= TYPE_MAIN_VARIANT (e1
);
8218 e2
= TYPE_MAIN_VARIANT (e2
);
8221 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
8222 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8225 case RID_BUILTIN_TGMATH
:
8227 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8228 location_t close_paren_loc
;
8230 c_parser_consume_token (parser
);
8231 if (!c_parser_get_builtin_args (parser
,
8240 if (vec_safe_length (cexpr_list
) < 3)
8242 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8249 FOR_EACH_VEC_ELT (*cexpr_list
, i
, p
)
8250 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8251 unsigned int nargs
= check_tgmath_function (&(*cexpr_list
)[0], 1);
8257 if (vec_safe_length (cexpr_list
) < nargs
)
8259 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8263 unsigned int num_functions
= vec_safe_length (cexpr_list
) - nargs
;
8264 if (num_functions
< 2)
8266 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8271 /* The first NUM_FUNCTIONS expressions are the function
8272 pointers. The remaining NARGS expressions are the
8273 arguments that are to be passed to one of those
8274 functions, chosen following <tgmath.h> rules. */
8275 for (unsigned int j
= 1; j
< num_functions
; j
++)
8277 unsigned int this_nargs
8278 = check_tgmath_function (&(*cexpr_list
)[j
], j
+ 1);
8279 if (this_nargs
== 0)
8284 if (this_nargs
!= nargs
)
8286 error_at ((*cexpr_list
)[j
].get_location (),
8287 "argument %u of %<__builtin_tgmath%> has "
8288 "wrong number of arguments", j
+ 1);
8294 /* The functions all have the same number of arguments.
8295 Determine whether arguments and return types vary in
8296 ways permitted for <tgmath.h> functions. */
8297 /* The first entry in each of these vectors is for the
8298 return type, subsequent entries for parameter
8300 auto_vec
<enum tgmath_parm_kind
> parm_kind (nargs
+ 1);
8301 auto_vec
<tree
> parm_first (nargs
+ 1);
8302 auto_vec
<bool> parm_complex (nargs
+ 1);
8303 auto_vec
<bool> parm_varies (nargs
+ 1);
8304 tree first_type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[0].value
));
8305 tree first_ret
= TYPE_MAIN_VARIANT (TREE_TYPE (first_type
));
8306 parm_first
.quick_push (first_ret
);
8307 parm_complex
.quick_push (TREE_CODE (first_ret
) == COMPLEX_TYPE
);
8308 parm_varies
.quick_push (false);
8309 function_args_iterator iter
;
8311 unsigned int argpos
;
8312 FOREACH_FUNCTION_ARGS (first_type
, t
, iter
)
8314 if (t
== void_type_node
)
8316 parm_first
.quick_push (TYPE_MAIN_VARIANT (t
));
8317 parm_complex
.quick_push (TREE_CODE (t
) == COMPLEX_TYPE
);
8318 parm_varies
.quick_push (false);
8320 for (unsigned int j
= 1; j
< num_functions
; j
++)
8322 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8323 tree ret
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
8324 if (ret
!= parm_first
[0])
8326 parm_varies
[0] = true;
8327 if (!SCALAR_FLOAT_TYPE_P (parm_first
[0])
8328 && !COMPLEX_FLOAT_TYPE_P (parm_first
[0]))
8330 error_at ((*cexpr_list
)[0].get_location (),
8331 "invalid type-generic return type for "
8332 "argument %u of %<__builtin_tgmath%>",
8337 if (!SCALAR_FLOAT_TYPE_P (ret
)
8338 && !COMPLEX_FLOAT_TYPE_P (ret
))
8340 error_at ((*cexpr_list
)[j
].get_location (),
8341 "invalid type-generic return type for "
8342 "argument %u of %<__builtin_tgmath%>",
8348 if (TREE_CODE (ret
) == COMPLEX_TYPE
)
8349 parm_complex
[0] = true;
8351 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8353 if (t
== void_type_node
)
8355 t
= TYPE_MAIN_VARIANT (t
);
8356 if (t
!= parm_first
[argpos
])
8358 parm_varies
[argpos
] = true;
8359 if (!SCALAR_FLOAT_TYPE_P (parm_first
[argpos
])
8360 && !COMPLEX_FLOAT_TYPE_P (parm_first
[argpos
]))
8362 error_at ((*cexpr_list
)[0].get_location (),
8363 "invalid type-generic type for "
8364 "argument %u of argument %u of "
8365 "%<__builtin_tgmath%>", argpos
, 1);
8369 if (!SCALAR_FLOAT_TYPE_P (t
)
8370 && !COMPLEX_FLOAT_TYPE_P (t
))
8372 error_at ((*cexpr_list
)[j
].get_location (),
8373 "invalid type-generic type for "
8374 "argument %u of argument %u of "
8375 "%<__builtin_tgmath%>", argpos
, j
+ 1);
8380 if (TREE_CODE (t
) == COMPLEX_TYPE
)
8381 parm_complex
[argpos
] = true;
8385 enum tgmath_parm_kind max_variation
= tgmath_fixed
;
8386 for (unsigned int j
= 0; j
<= nargs
; j
++)
8388 enum tgmath_parm_kind this_kind
;
8391 if (parm_complex
[j
])
8392 max_variation
= this_kind
= tgmath_complex
;
8395 this_kind
= tgmath_real
;
8396 if (max_variation
!= tgmath_complex
)
8397 max_variation
= tgmath_real
;
8401 this_kind
= tgmath_fixed
;
8402 parm_kind
.quick_push (this_kind
);
8404 if (max_variation
== tgmath_fixed
)
8406 error_at (loc
, "function arguments of %<__builtin_tgmath%> "
8407 "all have the same type");
8412 /* Identify a parameter (not the return type) that varies,
8413 including with complex types if any variation includes
8414 complex types; there must be at least one such
8416 unsigned int tgarg
= 0;
8417 for (unsigned int j
= 1; j
<= nargs
; j
++)
8418 if (parm_kind
[j
] == max_variation
)
8425 error_at (loc
, "function arguments of %<__builtin_tgmath%> "
8426 "lack type-generic parameter");
8431 /* Determine the type of the relevant parameter for each
8433 auto_vec
<tree
> tg_type (num_functions
);
8434 for (unsigned int j
= 0; j
< num_functions
; j
++)
8436 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8438 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8440 if (argpos
== tgarg
)
8442 tg_type
.quick_push (TYPE_MAIN_VARIANT (t
));
8449 /* Verify that the corresponding types are different for
8450 all the listed functions. Also determine whether all
8451 the types are complex, whether all the types are
8452 standard or binary, and whether all the types are
8454 bool all_complex
= true;
8455 bool all_binary
= true;
8456 bool all_decimal
= true;
8457 hash_set
<tree
> tg_types
;
8458 FOR_EACH_VEC_ELT (tg_type
, i
, t
)
8460 if (TREE_CODE (t
) == COMPLEX_TYPE
)
8461 all_decimal
= false;
8464 all_complex
= false;
8465 if (DECIMAL_FLOAT_TYPE_P (t
))
8468 all_decimal
= false;
8470 if (tg_types
.add (t
))
8472 error_at ((*cexpr_list
)[i
].get_location (),
8473 "duplicate type-generic parameter type for "
8474 "function argument %u of %<__builtin_tgmath%>",
8481 /* Verify that other parameters and the return type whose
8482 types vary have their types varying in the correct
8484 for (unsigned int j
= 0; j
< num_functions
; j
++)
8486 tree exp_type
= tg_type
[j
];
8487 tree exp_real_type
= exp_type
;
8488 if (TREE_CODE (exp_type
) == COMPLEX_TYPE
)
8489 exp_real_type
= TREE_TYPE (exp_type
);
8490 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8491 tree ret
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
8492 if ((parm_kind
[0] == tgmath_complex
&& ret
!= exp_type
)
8493 || (parm_kind
[0] == tgmath_real
&& ret
!= exp_real_type
))
8495 error_at ((*cexpr_list
)[j
].get_location (),
8496 "bad return type for function argument %u "
8497 "of %<__builtin_tgmath%>", j
+ 1);
8502 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8504 if (t
== void_type_node
)
8506 t
= TYPE_MAIN_VARIANT (t
);
8507 if ((parm_kind
[argpos
] == tgmath_complex
8509 || (parm_kind
[argpos
] == tgmath_real
8510 && t
!= exp_real_type
))
8512 error_at ((*cexpr_list
)[j
].get_location (),
8513 "bad type for argument %u of "
8514 "function argument %u of "
8515 "%<__builtin_tgmath%>", argpos
, j
+ 1);
8523 /* The functions listed are a valid set of functions for a
8524 <tgmath.h> macro to select between. Identify the
8525 matching function, if any. First, the argument types
8526 must be combined following <tgmath.h> rules. Integer
8527 types are treated as _Decimal64 if any type-generic
8528 argument is decimal, or if the only alternatives for
8529 type-generic arguments are of decimal types, and are
8530 otherwise treated as double (or _Complex double for
8531 complex integer types). After that adjustment, types
8532 are combined following the usual arithmetic
8533 conversions. If the function only accepts complex
8534 arguments, a complex type is produced. */
8535 bool arg_complex
= all_complex
;
8536 bool arg_binary
= all_binary
;
8537 bool arg_int_decimal
= all_decimal
;
8538 for (unsigned int j
= 1; j
<= nargs
; j
++)
8540 if (parm_kind
[j
] == tgmath_fixed
)
8542 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
- 1];
8543 tree type
= TREE_TYPE (ce
->value
);
8544 if (!INTEGRAL_TYPE_P (type
)
8545 && !SCALAR_FLOAT_TYPE_P (type
)
8546 && TREE_CODE (type
) != COMPLEX_TYPE
)
8548 error_at (ce
->get_location (),
8549 "invalid type of argument %u of type-generic "
8554 if (DECIMAL_FLOAT_TYPE_P (type
))
8556 arg_int_decimal
= true;
8559 error_at (ce
->get_location (),
8560 "decimal floating-point argument %u to "
8561 "complex-only type-generic function", j
);
8565 else if (all_binary
)
8567 error_at (ce
->get_location (),
8568 "decimal floating-point argument %u to "
8569 "binary-only type-generic function", j
);
8573 else if (arg_complex
)
8575 error_at (ce
->get_location (),
8576 "both complex and decimal floating-point "
8577 "arguments to type-generic function");
8581 else if (arg_binary
)
8583 error_at (ce
->get_location (),
8584 "both binary and decimal floating-point "
8585 "arguments to type-generic function");
8590 else if (TREE_CODE (type
) == COMPLEX_TYPE
)
8593 if (COMPLEX_FLOAT_TYPE_P (type
))
8597 error_at (ce
->get_location (),
8598 "complex argument %u to "
8599 "decimal-only type-generic function", j
);
8603 else if (arg_int_decimal
)
8605 error_at (ce
->get_location (),
8606 "both complex and decimal floating-point "
8607 "arguments to type-generic function");
8612 else if (SCALAR_FLOAT_TYPE_P (type
))
8617 error_at (ce
->get_location (),
8618 "binary argument %u to "
8619 "decimal-only type-generic function", j
);
8623 else if (arg_int_decimal
)
8625 error_at (ce
->get_location (),
8626 "both binary and decimal floating-point "
8627 "arguments to type-generic function");
8633 tree arg_real
= NULL_TREE
;
8634 for (unsigned int j
= 1; j
<= nargs
; j
++)
8636 if (parm_kind
[j
] == tgmath_fixed
)
8638 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
- 1];
8639 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (ce
->value
));
8640 if (TREE_CODE (type
) == COMPLEX_TYPE
)
8641 type
= TREE_TYPE (type
);
8642 if (INTEGRAL_TYPE_P (type
))
8643 type
= (arg_int_decimal
8644 ? dfloat64_type_node
8645 : double_type_node
);
8646 if (arg_real
== NULL_TREE
)
8649 arg_real
= common_type (arg_real
, type
);
8650 if (arg_real
== error_mark_node
)
8656 tree arg_type
= (arg_complex
8657 ? build_complex_type (arg_real
)
8660 /* Look for a function to call with type-generic parameter
8662 c_expr_t
*fn
= NULL
;
8663 for (unsigned int j
= 0; j
< num_functions
; j
++)
8665 if (tg_type
[j
] == arg_type
)
8667 fn
= &(*cexpr_list
)[j
];
8672 && parm_kind
[0] == tgmath_fixed
8673 && SCALAR_FLOAT_TYPE_P (parm_first
[0]))
8675 /* Presume this is a macro that rounds its result to a
8676 narrower type, and look for the first function with
8677 at least the range and precision of the argument
8679 for (unsigned int j
= 0; j
< num_functions
; j
++)
8682 != (TREE_CODE (tg_type
[j
]) == COMPLEX_TYPE
))
8684 tree real_tg_type
= (arg_complex
8685 ? TREE_TYPE (tg_type
[j
])
8687 if (DECIMAL_FLOAT_TYPE_P (arg_real
)
8688 != DECIMAL_FLOAT_TYPE_P (real_tg_type
))
8690 scalar_float_mode arg_mode
8691 = SCALAR_FLOAT_TYPE_MODE (arg_real
);
8692 scalar_float_mode tg_mode
8693 = SCALAR_FLOAT_TYPE_MODE (real_tg_type
);
8694 const real_format
*arg_fmt
= REAL_MODE_FORMAT (arg_mode
);
8695 const real_format
*tg_fmt
= REAL_MODE_FORMAT (tg_mode
);
8696 if (arg_fmt
->b
== tg_fmt
->b
8697 && arg_fmt
->p
<= tg_fmt
->p
8698 && arg_fmt
->emax
<= tg_fmt
->emax
8699 && (arg_fmt
->emin
- arg_fmt
->p
8700 >= tg_fmt
->emin
- tg_fmt
->p
))
8702 fn
= &(*cexpr_list
)[j
];
8709 error_at (loc
, "no matching function for type-generic call");
8714 /* Construct a call to FN. */
8715 vec
<tree
, va_gc
> *args
;
8716 vec_alloc (args
, nargs
);
8717 vec
<tree
, va_gc
> *origtypes
;
8718 vec_alloc (origtypes
, nargs
);
8719 auto_vec
<location_t
> arg_loc (nargs
);
8720 for (unsigned int j
= 0; j
< nargs
; j
++)
8722 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
];
8723 args
->quick_push (ce
->value
);
8724 arg_loc
.quick_push (ce
->get_location ());
8725 origtypes
->quick_push (ce
->original_type
);
8727 expr
.value
= c_build_function_call_vec (loc
, arg_loc
, fn
->value
,
8729 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8732 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
8734 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8737 location_t close_paren_loc
;
8739 c_parser_consume_token (parser
);
8740 if (!c_parser_get_builtin_args (parser
,
8741 "__builtin_call_with_static_chain",
8748 if (vec_safe_length (cexpr_list
) != 2)
8750 error_at (loc
, "wrong number of arguments to "
8751 "%<__builtin_call_with_static_chain%>");
8756 expr
= (*cexpr_list
)[0];
8757 e2_p
= &(*cexpr_list
)[1];
8758 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
8759 chain_value
= e2_p
->value
;
8760 mark_exp_read (chain_value
);
8762 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
8763 error_at (loc
, "first argument to "
8764 "%<__builtin_call_with_static_chain%> "
8765 "must be a call expression");
8766 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
8767 error_at (loc
, "second argument to "
8768 "%<__builtin_call_with_static_chain%> "
8769 "must be a pointer type");
8771 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
8772 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8775 case RID_BUILTIN_COMPLEX
:
8777 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8778 c_expr_t
*e1_p
, *e2_p
;
8779 location_t close_paren_loc
;
8781 c_parser_consume_token (parser
);
8782 if (!c_parser_get_builtin_args (parser
,
8783 "__builtin_complex",
8791 if (vec_safe_length (cexpr_list
) != 2)
8793 error_at (loc
, "wrong number of arguments to "
8794 "%<__builtin_complex%>");
8799 e1_p
= &(*cexpr_list
)[0];
8800 e2_p
= &(*cexpr_list
)[1];
8802 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
8803 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
8804 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
8805 TREE_OPERAND (e1_p
->value
, 0));
8806 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
8807 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
8808 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
8809 TREE_OPERAND (e2_p
->value
, 0));
8810 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8811 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8812 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
8813 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
8815 error_at (loc
, "%<__builtin_complex%> operand "
8816 "not of real binary floating-point type");
8820 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
8821 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
8824 "%<__builtin_complex%> operands of different types");
8828 pedwarn_c90 (loc
, OPT_Wpedantic
,
8829 "ISO C90 does not support complex types");
8830 expr
.value
= build2_loc (loc
, COMPLEX_EXPR
,
8833 (TREE_TYPE (e1_p
->value
))),
8834 e1_p
->value
, e2_p
->value
);
8835 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8838 case RID_BUILTIN_SHUFFLE
:
8840 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8843 location_t close_paren_loc
;
8845 c_parser_consume_token (parser
);
8846 if (!c_parser_get_builtin_args (parser
,
8847 "__builtin_shuffle",
8855 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
8856 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8858 if (vec_safe_length (cexpr_list
) == 2)
8860 c_build_vec_perm_expr
8861 (loc
, (*cexpr_list
)[0].value
,
8862 NULL_TREE
, (*cexpr_list
)[1].value
);
8864 else if (vec_safe_length (cexpr_list
) == 3)
8866 c_build_vec_perm_expr
8867 (loc
, (*cexpr_list
)[0].value
,
8868 (*cexpr_list
)[1].value
,
8869 (*cexpr_list
)[2].value
);
8872 error_at (loc
, "wrong number of arguments to "
8873 "%<__builtin_shuffle%>");
8876 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8879 case RID_AT_SELECTOR
:
8881 gcc_assert (c_dialect_objc ());
8882 c_parser_consume_token (parser
);
8883 matching_parens parens
;
8884 if (!parens
.require_open (parser
))
8889 tree sel
= c_parser_objc_selector_arg (parser
);
8890 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8891 parens
.skip_until_found_close (parser
);
8892 expr
.value
= objc_build_selector_expr (loc
, sel
);
8893 set_c_expr_source_range (&expr
, loc
, close_loc
);
8896 case RID_AT_PROTOCOL
:
8898 gcc_assert (c_dialect_objc ());
8899 c_parser_consume_token (parser
);
8900 matching_parens parens
;
8901 if (!parens
.require_open (parser
))
8906 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8908 c_parser_error (parser
, "expected identifier");
8909 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8913 tree id
= c_parser_peek_token (parser
)->value
;
8914 c_parser_consume_token (parser
);
8915 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8916 parens
.skip_until_found_close (parser
);
8917 expr
.value
= objc_build_protocol_expr (id
);
8918 set_c_expr_source_range (&expr
, loc
, close_loc
);
8923 /* Extension to support C-structures in the archiver. */
8924 gcc_assert (c_dialect_objc ());
8925 c_parser_consume_token (parser
);
8926 matching_parens parens
;
8927 if (!parens
.require_open (parser
))
8932 t1
= c_parser_type_name (parser
);
8936 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8939 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8940 parens
.skip_until_found_close (parser
);
8941 tree type
= groktypename (t1
, NULL
, NULL
);
8942 expr
.value
= objc_build_encode_expr (type
);
8943 set_c_expr_source_range (&expr
, loc
, close_loc
);
8947 expr
= c_parser_generic_selection (parser
);
8950 c_parser_error (parser
, "expected expression");
8955 case CPP_OPEN_SQUARE
:
8956 if (c_dialect_objc ())
8958 tree receiver
, args
;
8959 c_parser_consume_token (parser
);
8960 receiver
= c_parser_objc_receiver (parser
);
8961 args
= c_parser_objc_message_args (parser
);
8962 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8963 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8965 expr
.value
= objc_build_message_expr (receiver
, args
);
8966 set_c_expr_source_range (&expr
, loc
, close_loc
);
8969 /* Else fall through to report error. */
8972 c_parser_error (parser
, "expected expression");
8977 return c_parser_postfix_expression_after_primary
8978 (parser
, EXPR_LOC_OR_LOC (expr
.value
, loc
), expr
);
8981 /* Parse a postfix expression after a parenthesized type name: the
8982 brace-enclosed initializer of a compound literal, possibly followed
8983 by some postfix operators. This is separate because it is not
8984 possible to tell until after the type name whether a cast
8985 expression has a cast or a compound literal, or whether the operand
8986 of sizeof is a parenthesized type name or starts with a compound
8987 literal. TYPE_LOC is the location where TYPE_NAME starts--the
8988 location of the first token after the parentheses around the type
8991 static struct c_expr
8992 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
8993 struct c_type_name
*type_name
,
8994 location_t type_loc
)
9000 location_t start_loc
;
9001 tree type_expr
= NULL_TREE
;
9002 bool type_expr_const
= true;
9003 check_compound_literal_type (type_loc
, type_name
);
9004 rich_location
richloc (line_table
, type_loc
);
9005 start_init (NULL_TREE
, NULL
, 0, &richloc
);
9006 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
9007 start_loc
= c_parser_peek_token (parser
)->location
;
9008 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
9010 error_at (type_loc
, "compound literal has variable size");
9011 type
= error_mark_node
;
9013 init
= c_parser_braced_init (parser
, type
, false, NULL
);
9015 maybe_warn_string_init (type_loc
, type
, init
);
9017 if (type
!= error_mark_node
9018 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
9019 && current_function_decl
)
9021 error ("compound literal qualified by address-space qualifier");
9022 type
= error_mark_node
;
9025 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
9026 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
9027 ? CONSTRUCTOR_NON_CONST (init
.value
)
9028 : init
.original_code
== C_MAYBE_CONST_EXPR
);
9029 non_const
|= !type_expr_const
;
9030 unsigned int alignas_align
= 0;
9031 if (type
!= error_mark_node
9032 && type_name
->specs
->align_log
!= -1)
9034 alignas_align
= 1U << type_name
->specs
->align_log
;
9035 if (alignas_align
< min_align_of_type (type
))
9037 error_at (type_name
->specs
->locations
[cdw_alignas
],
9038 "%<_Alignas%> specifiers cannot reduce "
9039 "alignment of compound literal");
9043 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
,
9045 set_c_expr_source_range (&expr
, init
.src_range
);
9046 expr
.original_code
= ERROR_MARK
;
9047 expr
.original_type
= NULL
;
9048 if (type
!= error_mark_node
9049 && expr
.value
!= error_mark_node
9052 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
9054 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
9055 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
9059 gcc_assert (!non_const
);
9060 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
9061 type_expr
, expr
.value
);
9064 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
9067 /* Callback function for sizeof_pointer_memaccess_warning to compare
9071 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
9073 return comptypes (type1
, type2
) == 1;
9076 /* Parse a postfix expression after the initial primary or compound
9077 literal; that is, parse a series of postfix operators.
9079 EXPR_LOC is the location of the primary expression. */
9081 static struct c_expr
9082 c_parser_postfix_expression_after_primary (c_parser
*parser
,
9083 location_t expr_loc
,
9086 struct c_expr orig_expr
;
9088 location_t sizeof_arg_loc
[3], comp_loc
;
9090 unsigned int literal_zero_mask
;
9092 vec
<tree
, va_gc
> *exprlist
;
9093 vec
<tree
, va_gc
> *origtypes
= NULL
;
9094 vec
<location_t
> arg_loc
= vNULL
;
9100 location_t op_loc
= c_parser_peek_token (parser
)->location
;
9101 switch (c_parser_peek_token (parser
)->type
)
9103 case CPP_OPEN_SQUARE
:
9104 /* Array reference. */
9105 c_parser_consume_token (parser
);
9106 idx
= c_parser_expression (parser
).value
;
9107 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
9109 start
= expr
.get_start ();
9110 finish
= parser
->tokens_buf
[0].location
;
9111 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
9112 set_c_expr_source_range (&expr
, start
, finish
);
9113 expr
.original_code
= ERROR_MARK
;
9114 expr
.original_type
= NULL
;
9116 case CPP_OPEN_PAREN
:
9117 /* Function call. */
9118 c_parser_consume_token (parser
);
9119 for (i
= 0; i
< 3; i
++)
9121 sizeof_arg
[i
] = NULL_TREE
;
9122 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
9124 literal_zero_mask
= 0;
9125 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9128 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
9129 sizeof_arg_loc
, sizeof_arg
,
9130 &arg_loc
, &literal_zero_mask
);
9131 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9134 mark_exp_read (expr
.value
);
9135 if (warn_sizeof_pointer_memaccess
)
9136 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
9137 expr
.value
, exprlist
,
9139 sizeof_ptr_memacc_comptypes
);
9140 if (TREE_CODE (expr
.value
) == FUNCTION_DECL
9141 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
9142 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
9143 && vec_safe_length (exprlist
) == 3)
9145 tree arg0
= (*exprlist
)[0];
9146 tree arg2
= (*exprlist
)[2];
9147 warn_for_memset (expr_loc
, arg0
, arg2
, literal_zero_mask
);
9150 start
= expr
.get_start ();
9151 finish
= parser
->tokens_buf
[0].get_finish ();
9153 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
9154 exprlist
, origtypes
);
9155 set_c_expr_source_range (&expr
, start
, finish
);
9157 expr
.original_code
= ERROR_MARK
;
9158 if (TREE_CODE (expr
.value
) == INTEGER_CST
9159 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
9160 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
9161 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
9162 expr
.original_code
= C_MAYBE_CONST_EXPR
;
9163 expr
.original_type
= NULL
;
9166 release_tree_vector (exprlist
);
9167 release_tree_vector (origtypes
);
9172 /* Structure element reference. */
9173 c_parser_consume_token (parser
);
9174 expr
= default_function_array_conversion (expr_loc
, expr
);
9175 if (c_parser_next_token_is (parser
, CPP_NAME
))
9177 c_token
*comp_tok
= c_parser_peek_token (parser
);
9178 ident
= comp_tok
->value
;
9179 comp_loc
= comp_tok
->location
;
9183 c_parser_error (parser
, "expected identifier");
9185 expr
.original_code
= ERROR_MARK
;
9186 expr
.original_type
= NULL
;
9189 start
= expr
.get_start ();
9190 finish
= c_parser_peek_token (parser
)->get_finish ();
9191 c_parser_consume_token (parser
);
9192 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
,
9194 set_c_expr_source_range (&expr
, start
, finish
);
9195 expr
.original_code
= ERROR_MARK
;
9196 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
9197 expr
.original_type
= NULL
;
9200 /* Remember the original type of a bitfield. */
9201 tree field
= TREE_OPERAND (expr
.value
, 1);
9202 if (TREE_CODE (field
) != FIELD_DECL
)
9203 expr
.original_type
= NULL
;
9205 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
9209 /* Structure element reference. */
9210 c_parser_consume_token (parser
);
9211 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
9212 if (c_parser_next_token_is (parser
, CPP_NAME
))
9214 c_token
*comp_tok
= c_parser_peek_token (parser
);
9215 ident
= comp_tok
->value
;
9216 comp_loc
= comp_tok
->location
;
9220 c_parser_error (parser
, "expected identifier");
9222 expr
.original_code
= ERROR_MARK
;
9223 expr
.original_type
= NULL
;
9226 start
= expr
.get_start ();
9227 finish
= c_parser_peek_token (parser
)->get_finish ();
9228 c_parser_consume_token (parser
);
9229 expr
.value
= build_component_ref (op_loc
,
9230 build_indirect_ref (op_loc
,
9234 set_c_expr_source_range (&expr
, start
, finish
);
9235 expr
.original_code
= ERROR_MARK
;
9236 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
9237 expr
.original_type
= NULL
;
9240 /* Remember the original type of a bitfield. */
9241 tree field
= TREE_OPERAND (expr
.value
, 1);
9242 if (TREE_CODE (field
) != FIELD_DECL
)
9243 expr
.original_type
= NULL
;
9245 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
9249 /* Postincrement. */
9250 start
= expr
.get_start ();
9251 finish
= c_parser_peek_token (parser
)->get_finish ();
9252 c_parser_consume_token (parser
);
9253 expr
= default_function_array_read_conversion (expr_loc
, expr
);
9254 expr
.value
= build_unary_op (op_loc
, POSTINCREMENT_EXPR
,
9256 set_c_expr_source_range (&expr
, start
, finish
);
9257 expr
.original_code
= ERROR_MARK
;
9258 expr
.original_type
= NULL
;
9260 case CPP_MINUS_MINUS
:
9261 /* Postdecrement. */
9262 start
= expr
.get_start ();
9263 finish
= c_parser_peek_token (parser
)->get_finish ();
9264 c_parser_consume_token (parser
);
9265 expr
= default_function_array_read_conversion (expr_loc
, expr
);
9266 expr
.value
= build_unary_op (op_loc
, POSTDECREMENT_EXPR
,
9268 set_c_expr_source_range (&expr
, start
, finish
);
9269 expr
.original_code
= ERROR_MARK
;
9270 expr
.original_type
= NULL
;
9278 /* Parse an expression (C90 6.3.17, C99 6.5.17, C11 6.5.17).
9281 assignment-expression
9282 expression , assignment-expression
9285 static struct c_expr
9286 c_parser_expression (c_parser
*parser
)
9288 location_t tloc
= c_parser_peek_token (parser
)->location
;
9290 expr
= c_parser_expr_no_commas (parser
, NULL
);
9291 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9292 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
9293 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9297 location_t loc
= c_parser_peek_token (parser
)->location
;
9298 location_t expr_loc
;
9299 c_parser_consume_token (parser
);
9300 expr_loc
= c_parser_peek_token (parser
)->location
;
9301 lhsval
= expr
.value
;
9302 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
9303 lhsval
= TREE_OPERAND (lhsval
, 1);
9304 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
9305 mark_exp_read (lhsval
);
9306 next
= c_parser_expr_no_commas (parser
, NULL
);
9307 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
9308 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
9309 expr
.original_code
= COMPOUND_EXPR
;
9310 expr
.original_type
= next
.original_type
;
9315 /* Parse an expression and convert functions or arrays to pointers and
9316 lvalues to rvalues. */
9318 static struct c_expr
9319 c_parser_expression_conv (c_parser
*parser
)
9322 location_t loc
= c_parser_peek_token (parser
)->location
;
9323 expr
= c_parser_expression (parser
);
9324 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
9328 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
9329 argument is a literal zero alone and if so, set it in literal_zero_mask. */
9332 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
9335 if (idx
>= HOST_BITS_PER_INT
)
9338 c_token
*tok
= c_parser_peek_token (parser
);
9346 /* If a parameter is literal zero alone, remember it
9347 for -Wmemset-transposed-args warning. */
9348 if (integer_zerop (tok
->value
)
9349 && !TREE_OVERFLOW (tok
->value
)
9350 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9351 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
9352 *literal_zero_mask
|= 1U << idx
;
9358 /* Parse a non-empty list of expressions. If CONVERT_P, convert
9359 functions and arrays to pointers and lvalues to rvalues. If
9360 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
9361 locations of function arguments into this vector.
9364 assignment-expression
9365 nonempty-expr-list , assignment-expression
9368 static vec
<tree
, va_gc
> *
9369 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
9370 vec
<tree
, va_gc
> **p_orig_types
,
9371 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
9372 vec
<location_t
> *locations
,
9373 unsigned int *literal_zero_mask
)
9375 vec
<tree
, va_gc
> *ret
;
9376 vec
<tree
, va_gc
> *orig_types
;
9378 unsigned int idx
= 0;
9380 ret
= make_tree_vector ();
9381 if (p_orig_types
== NULL
)
9384 orig_types
= make_tree_vector ();
9386 if (literal_zero_mask
)
9387 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
9388 expr
= c_parser_expr_no_commas (parser
, NULL
);
9390 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true, true);
9392 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
9393 ret
->quick_push (expr
.value
);
9395 orig_types
->quick_push (expr
.original_type
);
9397 locations
->safe_push (expr
.get_location ());
9398 if (sizeof_arg
!= NULL
9399 && expr
.original_code
== SIZEOF_EXPR
)
9401 sizeof_arg
[0] = c_last_sizeof_arg
;
9402 sizeof_arg_loc
[0] = c_last_sizeof_loc
;
9404 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9406 c_parser_consume_token (parser
);
9407 if (literal_zero_mask
)
9408 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
9409 expr
= c_parser_expr_no_commas (parser
, NULL
);
9411 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true,
9414 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
9415 vec_safe_push (ret
, expr
.value
);
9417 vec_safe_push (orig_types
, expr
.original_type
);
9419 locations
->safe_push (expr
.get_location ());
9421 && sizeof_arg
!= NULL
9422 && expr
.original_code
== SIZEOF_EXPR
)
9424 sizeof_arg
[idx
] = c_last_sizeof_arg
;
9425 sizeof_arg_loc
[idx
] = c_last_sizeof_loc
;
9429 *p_orig_types
= orig_types
;
9433 /* Parse Objective-C-specific constructs. */
9435 /* Parse an objc-class-definition.
9437 objc-class-definition:
9438 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
9439 objc-class-instance-variables[opt] objc-methodprotolist @end
9440 @implementation identifier objc-superclass[opt]
9441 objc-class-instance-variables[opt]
9442 @interface identifier ( identifier ) objc-protocol-refs[opt]
9443 objc-methodprotolist @end
9444 @interface identifier ( ) objc-protocol-refs[opt]
9445 objc-methodprotolist @end
9446 @implementation identifier ( identifier )
9451 "@interface identifier (" must start "@interface identifier (
9452 identifier ) ...": objc-methodprotolist in the first production may
9453 not start with a parenthesized identifier as a declarator of a data
9454 definition with no declaration specifiers if the objc-superclass,
9455 objc-protocol-refs and objc-class-instance-variables are omitted. */
9458 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
9463 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
9465 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
9470 c_parser_consume_token (parser
);
9471 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9473 c_parser_error (parser
, "expected identifier");
9476 id1
= c_parser_peek_token (parser
)->value
;
9477 c_parser_consume_token (parser
);
9478 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9480 /* We have a category or class extension. */
9482 tree proto
= NULL_TREE
;
9483 matching_parens parens
;
9484 parens
.consume_open (parser
);
9485 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9487 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9489 /* We have a class extension. */
9494 c_parser_error (parser
, "expected identifier or %<)%>");
9495 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
9501 id2
= c_parser_peek_token (parser
)->value
;
9502 c_parser_consume_token (parser
);
9504 parens
.skip_until_found_close (parser
);
9507 objc_start_category_implementation (id1
, id2
);
9510 if (c_parser_next_token_is (parser
, CPP_LESS
))
9511 proto
= c_parser_objc_protocol_refs (parser
);
9512 objc_start_category_interface (id1
, id2
, proto
, attributes
);
9513 c_parser_objc_methodprotolist (parser
);
9514 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9515 objc_finish_interface ();
9518 if (c_parser_next_token_is (parser
, CPP_COLON
))
9520 c_parser_consume_token (parser
);
9521 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9523 c_parser_error (parser
, "expected identifier");
9526 superclass
= c_parser_peek_token (parser
)->value
;
9527 c_parser_consume_token (parser
);
9530 superclass
= NULL_TREE
;
9533 tree proto
= NULL_TREE
;
9534 if (c_parser_next_token_is (parser
, CPP_LESS
))
9535 proto
= c_parser_objc_protocol_refs (parser
);
9536 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
9539 objc_start_class_implementation (id1
, superclass
);
9540 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9541 c_parser_objc_class_instance_variables (parser
);
9544 objc_continue_interface ();
9545 c_parser_objc_methodprotolist (parser
);
9546 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9547 objc_finish_interface ();
9551 objc_continue_implementation ();
9556 /* Parse objc-class-instance-variables.
9558 objc-class-instance-variables:
9559 { objc-instance-variable-decl-list[opt] }
9561 objc-instance-variable-decl-list:
9562 objc-visibility-spec
9563 objc-instance-variable-decl ;
9565 objc-instance-variable-decl-list objc-visibility-spec
9566 objc-instance-variable-decl-list objc-instance-variable-decl ;
9567 objc-instance-variable-decl-list ;
9569 objc-visibility-spec:
9574 objc-instance-variable-decl:
9579 c_parser_objc_class_instance_variables (c_parser
*parser
)
9581 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
9582 c_parser_consume_token (parser
);
9583 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
9586 /* Parse any stray semicolon. */
9587 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9589 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9591 c_parser_consume_token (parser
);
9594 /* Stop if at the end of the instance variables. */
9595 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9597 c_parser_consume_token (parser
);
9600 /* Parse any objc-visibility-spec. */
9601 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
9603 c_parser_consume_token (parser
);
9604 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
9607 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
9609 c_parser_consume_token (parser
);
9610 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
9613 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
9615 c_parser_consume_token (parser
);
9616 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
9619 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
9621 c_parser_consume_token (parser
);
9622 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
9625 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
9627 c_parser_pragma (parser
, pragma_external
, NULL
);
9631 /* Parse some comma-separated declarations. */
9632 decls
= c_parser_struct_declaration (parser
);
9635 /* There is a syntax error. We want to skip the offending
9636 tokens up to the next ';' (included) or '}'
9639 /* First, skip manually a ')' or ']'. This is because they
9640 reduce the nesting level, so c_parser_skip_until_found()
9641 wouldn't be able to skip past them. */
9642 c_token
*token
= c_parser_peek_token (parser
);
9643 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
9644 c_parser_consume_token (parser
);
9646 /* Then, do the standard skipping. */
9647 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9649 /* We hopefully recovered. Start normal parsing again. */
9650 parser
->error
= false;
9655 /* Comma-separated instance variables are chained together
9656 in reverse order; add them one by one. */
9657 tree ivar
= nreverse (decls
);
9658 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
9659 objc_add_instance_variable (copy_node (ivar
));
9661 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9665 /* Parse an objc-class-declaration.
9667 objc-class-declaration:
9668 @class identifier-list ;
9672 c_parser_objc_class_declaration (c_parser
*parser
)
9674 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
9675 c_parser_consume_token (parser
);
9676 /* Any identifiers, including those declared as type names, are OK
9681 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9683 c_parser_error (parser
, "expected identifier");
9684 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9685 parser
->error
= false;
9688 id
= c_parser_peek_token (parser
)->value
;
9689 objc_declare_class (id
);
9690 c_parser_consume_token (parser
);
9691 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9692 c_parser_consume_token (parser
);
9696 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9699 /* Parse an objc-alias-declaration.
9701 objc-alias-declaration:
9702 @compatibility_alias identifier identifier ;
9706 c_parser_objc_alias_declaration (c_parser
*parser
)
9709 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
9710 c_parser_consume_token (parser
);
9711 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9713 c_parser_error (parser
, "expected identifier");
9714 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9717 id1
= c_parser_peek_token (parser
)->value
;
9718 c_parser_consume_token (parser
);
9719 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9721 c_parser_error (parser
, "expected identifier");
9722 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9725 id2
= c_parser_peek_token (parser
)->value
;
9726 c_parser_consume_token (parser
);
9727 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9728 objc_declare_alias (id1
, id2
);
9731 /* Parse an objc-protocol-definition.
9733 objc-protocol-definition:
9734 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
9735 @protocol identifier-list ;
9737 "@protocol identifier ;" should be resolved as "@protocol
9738 identifier-list ;": objc-methodprotolist may not start with a
9739 semicolon in the first alternative if objc-protocol-refs are
9743 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
9745 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
9747 c_parser_consume_token (parser
);
9748 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9750 c_parser_error (parser
, "expected identifier");
9753 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9754 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
9756 /* Any identifiers, including those declared as type names, are
9761 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9763 c_parser_error (parser
, "expected identifier");
9766 id
= c_parser_peek_token (parser
)->value
;
9767 objc_declare_protocol (id
, attributes
);
9768 c_parser_consume_token (parser
);
9769 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9770 c_parser_consume_token (parser
);
9774 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9778 tree id
= c_parser_peek_token (parser
)->value
;
9779 tree proto
= NULL_TREE
;
9780 c_parser_consume_token (parser
);
9781 if (c_parser_next_token_is (parser
, CPP_LESS
))
9782 proto
= c_parser_objc_protocol_refs (parser
);
9783 parser
->objc_pq_context
= true;
9784 objc_start_protocol (id
, proto
, attributes
);
9785 c_parser_objc_methodprotolist (parser
);
9786 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9787 parser
->objc_pq_context
= false;
9788 objc_finish_interface ();
9792 /* Parse an objc-method-type.
9798 Return true if it is a class method (+) and false if it is
9799 an instance method (-).
9802 c_parser_objc_method_type (c_parser
*parser
)
9804 switch (c_parser_peek_token (parser
)->type
)
9807 c_parser_consume_token (parser
);
9810 c_parser_consume_token (parser
);
9817 /* Parse an objc-method-definition.
9819 objc-method-definition:
9820 objc-method-type objc-method-decl ;[opt] compound-statement
9824 c_parser_objc_method_definition (c_parser
*parser
)
9826 bool is_class_method
= c_parser_objc_method_type (parser
);
9827 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
9828 parser
->objc_pq_context
= true;
9829 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9831 if (decl
== error_mark_node
)
9832 return; /* Bail here. */
9834 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9836 c_parser_consume_token (parser
);
9837 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9838 "extra semicolon in method definition specified");
9841 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9843 c_parser_error (parser
, "expected %<{%>");
9847 parser
->objc_pq_context
= false;
9848 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
9850 add_stmt (c_parser_compound_statement (parser
));
9851 objc_finish_method_definition (current_function_decl
);
9855 /* This code is executed when we find a method definition
9856 outside of an @implementation context (or invalid for other
9857 reasons). Parse the method (to keep going) but do not emit
9860 c_parser_compound_statement (parser
);
9864 /* Parse an objc-methodprotolist.
9866 objc-methodprotolist:
9868 objc-methodprotolist objc-methodproto
9869 objc-methodprotolist declaration
9870 objc-methodprotolist ;
9874 The declaration is a data definition, which may be missing
9875 declaration specifiers under the same rules and diagnostics as
9876 other data definitions outside functions, and the stray semicolon
9877 is diagnosed the same way as a stray semicolon outside a
9881 c_parser_objc_methodprotolist (c_parser
*parser
)
9885 /* The list is terminated by @end. */
9886 switch (c_parser_peek_token (parser
)->type
)
9889 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9890 "ISO C does not allow extra %<;%> outside of a function");
9891 c_parser_consume_token (parser
);
9895 c_parser_objc_methodproto (parser
);
9898 c_parser_pragma (parser
, pragma_external
, NULL
);
9903 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
9905 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
9906 c_parser_objc_at_property_declaration (parser
);
9907 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
9909 objc_set_method_opt (true);
9910 c_parser_consume_token (parser
);
9912 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
9914 objc_set_method_opt (false);
9915 c_parser_consume_token (parser
);
9918 c_parser_declaration_or_fndef (parser
, false, false, true,
9919 false, true, NULL
, vNULL
);
9925 /* Parse an objc-methodproto.
9928 objc-method-type objc-method-decl ;
9932 c_parser_objc_methodproto (c_parser
*parser
)
9934 bool is_class_method
= c_parser_objc_method_type (parser
);
9935 tree decl
, attributes
= NULL_TREE
;
9937 /* Remember protocol qualifiers in prototypes. */
9938 parser
->objc_pq_context
= true;
9939 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9941 /* Forget protocol qualifiers now. */
9942 parser
->objc_pq_context
= false;
9944 /* Do not allow the presence of attributes to hide an erroneous
9945 method implementation in the interface section. */
9946 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9948 c_parser_error (parser
, "expected %<;%>");
9952 if (decl
!= error_mark_node
)
9953 objc_add_method_declaration (is_class_method
, decl
, attributes
);
9955 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9958 /* If we are at a position that method attributes may be present, check that
9959 there are not any parsed already (a syntax error) and then collect any
9960 specified at the current location. Finally, if new attributes were present,
9961 check that the next token is legal ( ';' for decls and '{' for defs). */
9964 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
9969 c_parser_error (parser
,
9970 "method attributes must be specified at the end only");
9971 *attributes
= NULL_TREE
;
9975 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
9976 *attributes
= c_parser_attributes (parser
);
9978 /* If there were no attributes here, just report any earlier error. */
9979 if (*attributes
== NULL_TREE
|| bad
)
9982 /* If the attributes are followed by a ; or {, then just report any earlier
9984 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
9985 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9988 /* We've got attributes, but not at the end. */
9989 c_parser_error (parser
,
9990 "expected %<;%> or %<{%> after method attribute definition");
9994 /* Parse an objc-method-decl.
9997 ( objc-type-name ) objc-selector
9999 ( objc-type-name ) objc-keyword-selector objc-optparmlist
10000 objc-keyword-selector objc-optparmlist
10003 objc-keyword-selector:
10005 objc-keyword-selector objc-keyword-decl
10008 objc-selector : ( objc-type-name ) identifier
10009 objc-selector : identifier
10010 : ( objc-type-name ) identifier
10014 objc-optparms objc-optellipsis
10018 objc-opt-parms , parameter-declaration
10026 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
10027 tree
*attributes
, tree
*expr
)
10029 tree type
= NULL_TREE
;
10031 tree parms
= NULL_TREE
;
10032 bool ellipsis
= false;
10033 bool attr_err
= false;
10035 *attributes
= NULL_TREE
;
10036 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10038 matching_parens parens
;
10039 parens
.consume_open (parser
);
10040 type
= c_parser_objc_type_name (parser
);
10041 parens
.skip_until_found_close (parser
);
10043 sel
= c_parser_objc_selector (parser
);
10044 /* If there is no selector, or a colon follows, we have an
10045 objc-keyword-selector. If there is a selector, and a colon does
10046 not follow, that selector ends the objc-method-decl. */
10047 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
10050 tree list
= NULL_TREE
;
10053 tree atype
= NULL_TREE
, id
, keyworddecl
;
10054 tree param_attr
= NULL_TREE
;
10055 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10057 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10059 c_parser_consume_token (parser
);
10060 atype
= c_parser_objc_type_name (parser
);
10061 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
10064 /* New ObjC allows attributes on method parameters. */
10065 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
10066 param_attr
= c_parser_attributes (parser
);
10067 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10069 c_parser_error (parser
, "expected identifier");
10070 return error_mark_node
;
10072 id
= c_parser_peek_token (parser
)->value
;
10073 c_parser_consume_token (parser
);
10074 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
10075 list
= chainon (list
, keyworddecl
);
10076 tsel
= c_parser_objc_selector (parser
);
10077 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10081 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
10083 /* Parse the optional parameter list. Optional Objective-C
10084 method parameters follow the C syntax, and may include '...'
10085 to denote a variable number of arguments. */
10086 parms
= make_node (TREE_LIST
);
10087 while (c_parser_next_token_is (parser
, CPP_COMMA
))
10089 struct c_parm
*parm
;
10090 c_parser_consume_token (parser
);
10091 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
10094 c_parser_consume_token (parser
);
10095 attr_err
|= c_parser_objc_maybe_method_attributes
10096 (parser
, attributes
) ;
10099 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
10102 parms
= chainon (parms
,
10103 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
10108 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
10112 c_parser_error (parser
, "objective-c method declaration is expected");
10113 return error_mark_node
;
10117 return error_mark_node
;
10119 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
10122 /* Parse an objc-type-name.
10125 objc-type-qualifiers[opt] type-name
10126 objc-type-qualifiers[opt]
10128 objc-type-qualifiers:
10129 objc-type-qualifier
10130 objc-type-qualifiers objc-type-qualifier
10132 objc-type-qualifier: one of
10133 in out inout bycopy byref oneway
10137 c_parser_objc_type_name (c_parser
*parser
)
10139 tree quals
= NULL_TREE
;
10140 struct c_type_name
*type_name
= NULL
;
10141 tree type
= NULL_TREE
;
10144 c_token
*token
= c_parser_peek_token (parser
);
10145 if (token
->type
== CPP_KEYWORD
10146 && (token
->keyword
== RID_IN
10147 || token
->keyword
== RID_OUT
10148 || token
->keyword
== RID_INOUT
10149 || token
->keyword
== RID_BYCOPY
10150 || token
->keyword
== RID_BYREF
10151 || token
->keyword
== RID_ONEWAY
))
10153 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
10154 c_parser_consume_token (parser
);
10159 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
10160 type_name
= c_parser_type_name (parser
);
10162 type
= groktypename (type_name
, NULL
, NULL
);
10164 /* If the type is unknown, and error has already been produced and
10165 we need to recover from the error. In that case, use NULL_TREE
10166 for the type, as if no type had been specified; this will use the
10167 default type ('id') which is good for error recovery. */
10168 if (type
== error_mark_node
)
10171 return build_tree_list (quals
, type
);
10174 /* Parse objc-protocol-refs.
10176 objc-protocol-refs:
10177 < identifier-list >
10181 c_parser_objc_protocol_refs (c_parser
*parser
)
10183 tree list
= NULL_TREE
;
10184 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
10185 c_parser_consume_token (parser
);
10186 /* Any identifiers, including those declared as type names, are OK
10191 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10193 c_parser_error (parser
, "expected identifier");
10196 id
= c_parser_peek_token (parser
)->value
;
10197 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
10198 c_parser_consume_token (parser
);
10199 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10200 c_parser_consume_token (parser
);
10204 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
10208 /* Parse an objc-try-catch-finally-statement.
10210 objc-try-catch-finally-statement:
10211 @try compound-statement objc-catch-list[opt]
10212 @try compound-statement objc-catch-list[opt] @finally compound-statement
10215 @catch ( objc-catch-parameter-declaration ) compound-statement
10216 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
10218 objc-catch-parameter-declaration:
10219 parameter-declaration
10222 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
10224 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
10225 for C++. Keep them in sync. */
10228 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
10230 location_t location
;
10233 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
10234 c_parser_consume_token (parser
);
10235 location
= c_parser_peek_token (parser
)->location
;
10236 objc_maybe_warn_exceptions (location
);
10237 stmt
= c_parser_compound_statement (parser
);
10238 objc_begin_try_stmt (location
, stmt
);
10240 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
10242 struct c_parm
*parm
;
10243 tree parameter_declaration
= error_mark_node
;
10244 bool seen_open_paren
= false;
10246 c_parser_consume_token (parser
);
10247 matching_parens parens
;
10248 if (!parens
.require_open (parser
))
10249 seen_open_paren
= true;
10250 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
10252 /* We have "@catch (...)" (where the '...' are literally
10253 what is in the code). Skip the '...'.
10254 parameter_declaration is set to NULL_TREE, and
10255 objc_being_catch_clauses() knows that that means
10257 c_parser_consume_token (parser
);
10258 parameter_declaration
= NULL_TREE
;
10262 /* We have "@catch (NSException *exception)" or something
10263 like that. Parse the parameter declaration. */
10264 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
10266 parameter_declaration
= error_mark_node
;
10268 parameter_declaration
= grokparm (parm
, NULL
);
10270 if (seen_open_paren
)
10271 parens
.require_close (parser
);
10274 /* If there was no open parenthesis, we are recovering from
10275 an error, and we are trying to figure out what mistake
10276 the user has made. */
10278 /* If there is an immediate closing parenthesis, the user
10279 probably forgot the opening one (ie, they typed "@catch
10280 NSException *e)". Parse the closing parenthesis and keep
10282 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
10283 c_parser_consume_token (parser
);
10285 /* If these is no immediate closing parenthesis, the user
10286 probably doesn't know that parenthesis are required at
10287 all (ie, they typed "@catch NSException *e"). So, just
10288 forget about the closing parenthesis and keep going. */
10290 objc_begin_catch_clause (parameter_declaration
);
10291 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
10292 c_parser_compound_statement_nostart (parser
);
10293 objc_finish_catch_clause ();
10295 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
10297 c_parser_consume_token (parser
);
10298 location
= c_parser_peek_token (parser
)->location
;
10299 stmt
= c_parser_compound_statement (parser
);
10300 objc_build_finally_clause (location
, stmt
);
10302 objc_finish_try_stmt ();
10305 /* Parse an objc-synchronized-statement.
10307 objc-synchronized-statement:
10308 @synchronized ( expression ) compound-statement
10312 c_parser_objc_synchronized_statement (c_parser
*parser
)
10316 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
10317 c_parser_consume_token (parser
);
10318 loc
= c_parser_peek_token (parser
)->location
;
10319 objc_maybe_warn_exceptions (loc
);
10320 matching_parens parens
;
10321 if (parens
.require_open (parser
))
10323 struct c_expr ce
= c_parser_expression (parser
);
10324 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
10326 expr
= c_fully_fold (expr
, false, NULL
);
10327 parens
.skip_until_found_close (parser
);
10330 expr
= error_mark_node
;
10331 stmt
= c_parser_compound_statement (parser
);
10332 objc_build_synchronized (loc
, expr
, stmt
);
10335 /* Parse an objc-selector; return NULL_TREE without an error if the
10336 next token is not an objc-selector.
10341 enum struct union if else while do for switch case default
10342 break continue return goto asm sizeof typeof __alignof
10343 unsigned long const short volatile signed restrict _Complex
10344 in out inout bycopy byref oneway int char float double void _Bool
10347 ??? Why this selection of keywords but not, for example, storage
10348 class specifiers? */
10351 c_parser_objc_selector (c_parser
*parser
)
10353 c_token
*token
= c_parser_peek_token (parser
);
10354 tree value
= token
->value
;
10355 if (token
->type
== CPP_NAME
)
10357 c_parser_consume_token (parser
);
10360 if (token
->type
!= CPP_KEYWORD
)
10362 switch (token
->keyword
)
10401 CASE_RID_FLOATN_NX
:
10405 case RID_AUTO_TYPE
:
10410 c_parser_consume_token (parser
);
10417 /* Parse an objc-selector-arg.
10421 objc-keywordname-list
10423 objc-keywordname-list:
10425 objc-keywordname-list objc-keywordname
10433 c_parser_objc_selector_arg (c_parser
*parser
)
10435 tree sel
= c_parser_objc_selector (parser
);
10436 tree list
= NULL_TREE
;
10437 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10441 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10443 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
10444 sel
= c_parser_objc_selector (parser
);
10445 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10451 /* Parse an objc-receiver.
10460 c_parser_objc_receiver (c_parser
*parser
)
10462 location_t loc
= c_parser_peek_token (parser
)->location
;
10464 if (c_parser_peek_token (parser
)->type
== CPP_NAME
10465 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
10466 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
10468 tree id
= c_parser_peek_token (parser
)->value
;
10469 c_parser_consume_token (parser
);
10470 return objc_get_class_reference (id
);
10472 struct c_expr ce
= c_parser_expression (parser
);
10473 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
10474 return c_fully_fold (ce
.value
, false, NULL
);
10477 /* Parse objc-message-args.
10481 objc-keywordarg-list
10483 objc-keywordarg-list:
10485 objc-keywordarg-list objc-keywordarg
10488 objc-selector : objc-keywordexpr
10493 c_parser_objc_message_args (c_parser
*parser
)
10495 tree sel
= c_parser_objc_selector (parser
);
10496 tree list
= NULL_TREE
;
10497 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10502 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10503 return error_mark_node
;
10504 keywordexpr
= c_parser_objc_keywordexpr (parser
);
10505 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
10506 sel
= c_parser_objc_selector (parser
);
10507 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10513 /* Parse an objc-keywordexpr.
10520 c_parser_objc_keywordexpr (c_parser
*parser
)
10523 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
10524 NULL
, NULL
, NULL
, NULL
);
10525 if (vec_safe_length (expr_list
) == 1)
10527 /* Just return the expression, remove a level of
10529 ret
= (*expr_list
)[0];
10533 /* We have a comma expression, we will collapse later. */
10534 ret
= build_tree_list_vec (expr_list
);
10536 release_tree_vector (expr_list
);
10540 /* A check, needed in several places, that ObjC interface, implementation or
10541 method definitions are not prefixed by incorrect items. */
10543 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
10544 struct c_declspecs
*specs
)
10546 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
10547 || specs
->typespec_kind
!= ctsk_none
)
10549 c_parser_error (parser
,
10550 "no type or storage class may be specified here,");
10551 c_parser_skip_to_end_of_block_or_statement (parser
);
10557 /* Parse an Objective-C @property declaration. The syntax is:
10559 objc-property-declaration:
10560 '@property' objc-property-attributes[opt] struct-declaration ;
10562 objc-property-attributes:
10563 '(' objc-property-attribute-list ')'
10565 objc-property-attribute-list:
10566 objc-property-attribute
10567 objc-property-attribute-list, objc-property-attribute
10569 objc-property-attribute
10570 'getter' = identifier
10571 'setter' = identifier
10580 @property NSString *name;
10581 @property (readonly) id object;
10582 @property (retain, nonatomic, getter=getTheName) id name;
10583 @property int a, b, c;
10585 PS: This function is identical to cp_parser_objc_at_propery_declaration
10586 for C++. Keep them in sync. */
10588 c_parser_objc_at_property_declaration (c_parser
*parser
)
10590 /* The following variables hold the attributes of the properties as
10591 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
10592 seen. When we see an attribute, we set them to 'true' (if they
10593 are boolean properties) or to the identifier (if they have an
10594 argument, ie, for getter and setter). Note that here we only
10595 parse the list of attributes, check the syntax and accumulate the
10596 attributes that we find. objc_add_property_declaration() will
10597 then process the information. */
10598 bool property_assign
= false;
10599 bool property_copy
= false;
10600 tree property_getter_ident
= NULL_TREE
;
10601 bool property_nonatomic
= false;
10602 bool property_readonly
= false;
10603 bool property_readwrite
= false;
10604 bool property_retain
= false;
10605 tree property_setter_ident
= NULL_TREE
;
10607 /* 'properties' is the list of properties that we read. Usually a
10608 single one, but maybe more (eg, in "@property int a, b, c;" there
10613 loc
= c_parser_peek_token (parser
)->location
;
10614 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
10616 c_parser_consume_token (parser
); /* Eat '@property'. */
10618 /* Parse the optional attribute list... */
10619 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10621 matching_parens parens
;
10624 parens
.consume_open (parser
);
10626 /* Property attribute keywords are valid now. */
10627 parser
->objc_property_attr_context
= true;
10631 bool syntax_error
= false;
10632 c_token
*token
= c_parser_peek_token (parser
);
10635 if (token
->type
!= CPP_KEYWORD
)
10637 if (token
->type
== CPP_CLOSE_PAREN
)
10638 c_parser_error (parser
, "expected identifier");
10641 c_parser_consume_token (parser
);
10642 c_parser_error (parser
, "unknown property attribute");
10646 keyword
= token
->keyword
;
10647 c_parser_consume_token (parser
);
10650 case RID_ASSIGN
: property_assign
= true; break;
10651 case RID_COPY
: property_copy
= true; break;
10652 case RID_NONATOMIC
: property_nonatomic
= true; break;
10653 case RID_READONLY
: property_readonly
= true; break;
10654 case RID_READWRITE
: property_readwrite
= true; break;
10655 case RID_RETAIN
: property_retain
= true; break;
10659 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
10661 if (keyword
== RID_GETTER
)
10662 c_parser_error (parser
,
10663 "missing %<=%> (after %<getter%> attribute)");
10665 c_parser_error (parser
,
10666 "missing %<=%> (after %<setter%> attribute)");
10667 syntax_error
= true;
10670 c_parser_consume_token (parser
); /* eat the = */
10671 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10673 c_parser_error (parser
, "expected identifier");
10674 syntax_error
= true;
10677 if (keyword
== RID_SETTER
)
10679 if (property_setter_ident
!= NULL_TREE
)
10680 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
10682 property_setter_ident
= c_parser_peek_token (parser
)->value
;
10683 c_parser_consume_token (parser
);
10684 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
10685 c_parser_error (parser
, "setter name must terminate with %<:%>");
10687 c_parser_consume_token (parser
);
10691 if (property_getter_ident
!= NULL_TREE
)
10692 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
10694 property_getter_ident
= c_parser_peek_token (parser
)->value
;
10695 c_parser_consume_token (parser
);
10699 c_parser_error (parser
, "unknown property attribute");
10700 syntax_error
= true;
10707 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10708 c_parser_consume_token (parser
);
10712 parser
->objc_property_attr_context
= false;
10713 parens
.skip_until_found_close (parser
);
10715 /* ... and the property declaration(s). */
10716 properties
= c_parser_struct_declaration (parser
);
10718 if (properties
== error_mark_node
)
10720 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10721 parser
->error
= false;
10725 if (properties
== NULL_TREE
)
10726 c_parser_error (parser
, "expected identifier");
10729 /* Comma-separated properties are chained together in
10730 reverse order; add them one by one. */
10731 properties
= nreverse (properties
);
10733 for (; properties
; properties
= TREE_CHAIN (properties
))
10734 objc_add_property_declaration (loc
, copy_node (properties
),
10735 property_readonly
, property_readwrite
,
10736 property_assign
, property_retain
,
10737 property_copy
, property_nonatomic
,
10738 property_getter_ident
, property_setter_ident
);
10741 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10742 parser
->error
= false;
10745 /* Parse an Objective-C @synthesize declaration. The syntax is:
10747 objc-synthesize-declaration:
10748 @synthesize objc-synthesize-identifier-list ;
10750 objc-synthesize-identifier-list:
10751 objc-synthesize-identifier
10752 objc-synthesize-identifier-list, objc-synthesize-identifier
10754 objc-synthesize-identifier
10756 identifier = identifier
10759 @synthesize MyProperty;
10760 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
10762 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
10763 for C++. Keep them in sync.
10766 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
10768 tree list
= NULL_TREE
;
10770 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
10771 loc
= c_parser_peek_token (parser
)->location
;
10773 c_parser_consume_token (parser
);
10776 tree property
, ivar
;
10777 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10779 c_parser_error (parser
, "expected identifier");
10780 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10781 /* Once we find the semicolon, we can resume normal parsing.
10782 We have to reset parser->error manually because
10783 c_parser_skip_until_found() won't reset it for us if the
10784 next token is precisely a semicolon. */
10785 parser
->error
= false;
10788 property
= c_parser_peek_token (parser
)->value
;
10789 c_parser_consume_token (parser
);
10790 if (c_parser_next_token_is (parser
, CPP_EQ
))
10792 c_parser_consume_token (parser
);
10793 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10795 c_parser_error (parser
, "expected identifier");
10796 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10797 parser
->error
= false;
10800 ivar
= c_parser_peek_token (parser
)->value
;
10801 c_parser_consume_token (parser
);
10805 list
= chainon (list
, build_tree_list (ivar
, property
));
10806 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10807 c_parser_consume_token (parser
);
10811 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10812 objc_add_synthesize_declaration (loc
, list
);
10815 /* Parse an Objective-C @dynamic declaration. The syntax is:
10817 objc-dynamic-declaration:
10818 @dynamic identifier-list ;
10821 @dynamic MyProperty;
10822 @dynamic MyProperty, AnotherProperty;
10824 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
10825 for C++. Keep them in sync.
10828 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
10830 tree list
= NULL_TREE
;
10832 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
10833 loc
= c_parser_peek_token (parser
)->location
;
10835 c_parser_consume_token (parser
);
10839 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10841 c_parser_error (parser
, "expected identifier");
10842 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10843 parser
->error
= false;
10846 property
= c_parser_peek_token (parser
)->value
;
10847 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
10848 c_parser_consume_token (parser
);
10849 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10850 c_parser_consume_token (parser
);
10854 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10855 objc_add_dynamic_declaration (loc
, list
);
10859 /* Parse a pragma GCC ivdep. */
10862 c_parse_pragma_ivdep (c_parser
*parser
)
10864 c_parser_consume_pragma (parser
);
10865 c_parser_skip_to_pragma_eol (parser
);
10869 /* Parse a pragma GCC unroll. */
10871 static unsigned short
10872 c_parser_pragma_unroll (c_parser
*parser
)
10874 unsigned short unroll
;
10875 c_parser_consume_pragma (parser
);
10876 location_t location
= c_parser_peek_token (parser
)->location
;
10877 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
10878 mark_exp_read (expr
);
10879 expr
= c_fully_fold (expr
, false, NULL
);
10880 HOST_WIDE_INT lunroll
= 0;
10881 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
10882 || TREE_CODE (expr
) != INTEGER_CST
10883 || (lunroll
= tree_to_shwi (expr
)) < 0
10884 || lunroll
>= USHRT_MAX
)
10886 error_at (location
, "%<#pragma GCC unroll%> requires an"
10887 " assignment-expression that evaluates to a non-negative"
10888 " integral constant less than %u", USHRT_MAX
);
10893 unroll
= (unsigned short)lunroll
;
10898 c_parser_skip_to_pragma_eol (parser
);
10902 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
10903 should be considered, statements. ALLOW_STMT is true if we're within
10904 the context of a function and such pragmas are to be allowed. Returns
10905 true if we actually parsed such a pragma. */
10908 c_parser_pragma (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
10911 const char *construct
= NULL
;
10913 id
= c_parser_peek_token (parser
)->pragma_kind
;
10914 gcc_assert (id
!= PRAGMA_NONE
);
10918 case PRAGMA_OACC_DECLARE
:
10919 c_parser_oacc_declare (parser
);
10922 case PRAGMA_OACC_ENTER_DATA
:
10923 if (context
!= pragma_compound
)
10925 construct
= "acc enter data";
10927 if (context
== pragma_stmt
)
10929 error_at (c_parser_peek_token (parser
)->location
,
10930 "%<#pragma %s%> may only be used in compound "
10931 "statements", construct
);
10932 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10937 c_parser_oacc_enter_exit_data (parser
, true);
10940 case PRAGMA_OACC_EXIT_DATA
:
10941 if (context
!= pragma_compound
)
10943 construct
= "acc exit data";
10946 c_parser_oacc_enter_exit_data (parser
, false);
10949 case PRAGMA_OACC_ROUTINE
:
10950 if (context
!= pragma_external
)
10952 error_at (c_parser_peek_token (parser
)->location
,
10953 "%<#pragma acc routine%> must be at file scope");
10954 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10957 c_parser_oacc_routine (parser
, context
);
10960 case PRAGMA_OACC_UPDATE
:
10961 if (context
!= pragma_compound
)
10963 construct
= "acc update";
10966 c_parser_oacc_update (parser
);
10969 case PRAGMA_OMP_BARRIER
:
10970 if (context
!= pragma_compound
)
10972 construct
= "omp barrier";
10975 c_parser_omp_barrier (parser
);
10978 case PRAGMA_OMP_FLUSH
:
10979 if (context
!= pragma_compound
)
10981 construct
= "omp flush";
10984 c_parser_omp_flush (parser
);
10987 case PRAGMA_OMP_TASKWAIT
:
10988 if (context
!= pragma_compound
)
10990 construct
= "omp taskwait";
10993 c_parser_omp_taskwait (parser
);
10996 case PRAGMA_OMP_TASKYIELD
:
10997 if (context
!= pragma_compound
)
10999 construct
= "omp taskyield";
11002 c_parser_omp_taskyield (parser
);
11005 case PRAGMA_OMP_CANCEL
:
11006 if (context
!= pragma_compound
)
11008 construct
= "omp cancel";
11011 c_parser_omp_cancel (parser
);
11014 case PRAGMA_OMP_CANCELLATION_POINT
:
11015 c_parser_omp_cancellation_point (parser
, context
);
11018 case PRAGMA_OMP_THREADPRIVATE
:
11019 c_parser_omp_threadprivate (parser
);
11022 case PRAGMA_OMP_TARGET
:
11023 return c_parser_omp_target (parser
, context
, if_p
);
11025 case PRAGMA_OMP_END_DECLARE_TARGET
:
11026 c_parser_omp_end_declare_target (parser
);
11029 case PRAGMA_OMP_SECTION
:
11030 error_at (c_parser_peek_token (parser
)->location
,
11031 "%<#pragma omp section%> may only be used in "
11032 "%<#pragma omp sections%> construct");
11033 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11036 case PRAGMA_OMP_DECLARE
:
11037 c_parser_omp_declare (parser
, context
);
11040 case PRAGMA_OMP_ORDERED
:
11041 return c_parser_omp_ordered (parser
, context
, if_p
);
11045 const bool ivdep
= c_parse_pragma_ivdep (parser
);
11046 unsigned short unroll
;
11047 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_UNROLL
)
11048 unroll
= c_parser_pragma_unroll (parser
);
11051 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
11052 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
11053 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
11055 c_parser_error (parser
, "for, while or do statement expected");
11058 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11059 c_parser_for_statement (parser
, ivdep
, unroll
, if_p
);
11060 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
11061 c_parser_while_statement (parser
, ivdep
, unroll
, if_p
);
11063 c_parser_do_statement (parser
, ivdep
, unroll
);
11067 case PRAGMA_UNROLL
:
11069 unsigned short unroll
= c_parser_pragma_unroll (parser
);
11071 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_IVDEP
)
11072 ivdep
= c_parse_pragma_ivdep (parser
);
11075 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
11076 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
11077 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
11079 c_parser_error (parser
, "for, while or do statement expected");
11082 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11083 c_parser_for_statement (parser
, ivdep
, unroll
, if_p
);
11084 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
11085 c_parser_while_statement (parser
, ivdep
, unroll
, if_p
);
11087 c_parser_do_statement (parser
, ivdep
, unroll
);
11091 case PRAGMA_GCC_PCH_PREPROCESS
:
11092 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
11093 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11096 case PRAGMA_OACC_WAIT
:
11097 if (context
!= pragma_compound
)
11099 construct
= "acc wait";
11102 /* FALL THROUGH. */
11105 if (id
< PRAGMA_FIRST_EXTERNAL
)
11107 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
11110 c_parser_error (parser
, "expected declaration specifiers");
11111 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
11114 c_parser_omp_construct (parser
, if_p
);
11120 c_parser_consume_pragma (parser
);
11121 c_invoke_pragma_handler (id
);
11123 /* Skip to EOL, but suppress any error message. Those will have been
11124 generated by the handler routine through calling error, as opposed
11125 to calling c_parser_error. */
11126 parser
->error
= true;
11127 c_parser_skip_to_pragma_eol (parser
);
11132 /* The interface the pragma parsers have to the lexer. */
11135 pragma_lex (tree
*value
, location_t
*loc
)
11137 c_token
*tok
= c_parser_peek_token (the_parser
);
11138 enum cpp_ttype ret
= tok
->type
;
11140 *value
= tok
->value
;
11142 *loc
= tok
->location
;
11144 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
11148 if (ret
== CPP_KEYWORD
)
11150 c_parser_consume_token (the_parser
);
11157 c_parser_pragma_pch_preprocess (c_parser
*parser
)
11161 c_parser_consume_pragma (parser
);
11162 if (c_parser_next_token_is (parser
, CPP_STRING
))
11164 name
= c_parser_peek_token (parser
)->value
;
11165 c_parser_consume_token (parser
);
11168 c_parser_error (parser
, "expected string literal");
11169 c_parser_skip_to_pragma_eol (parser
);
11172 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
11175 /* OpenACC and OpenMP parsing routines. */
11177 /* Returns name of the next clause.
11178 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
11179 the token is not consumed. Otherwise appropriate pragma_omp_clause is
11180 returned and the token is consumed. */
11182 static pragma_omp_clause
11183 c_parser_omp_clause_name (c_parser
*parser
)
11185 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
11187 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
11188 result
= PRAGMA_OACC_CLAUSE_AUTO
;
11189 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
11190 result
= PRAGMA_OMP_CLAUSE_IF
;
11191 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
11192 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
11193 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11194 result
= PRAGMA_OMP_CLAUSE_FOR
;
11195 else if (c_parser_next_token_is (parser
, CPP_NAME
))
11197 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11202 if (!strcmp ("aligned", p
))
11203 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
11204 else if (!strcmp ("async", p
))
11205 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
11208 if (!strcmp ("collapse", p
))
11209 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
11210 else if (!strcmp ("copy", p
))
11211 result
= PRAGMA_OACC_CLAUSE_COPY
;
11212 else if (!strcmp ("copyin", p
))
11213 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
11214 else if (!strcmp ("copyout", p
))
11215 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
11216 else if (!strcmp ("copyprivate", p
))
11217 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
11218 else if (!strcmp ("create", p
))
11219 result
= PRAGMA_OACC_CLAUSE_CREATE
;
11222 if (!strcmp ("defaultmap", p
))
11223 result
= PRAGMA_OMP_CLAUSE_DEFAULTMAP
;
11224 else if (!strcmp ("delete", p
))
11225 result
= PRAGMA_OACC_CLAUSE_DELETE
;
11226 else if (!strcmp ("depend", p
))
11227 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
11228 else if (!strcmp ("device", p
))
11229 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
11230 else if (!strcmp ("deviceptr", p
))
11231 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
11232 else if (!strcmp ("device_resident", p
))
11233 result
= PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
;
11234 else if (!strcmp ("dist_schedule", p
))
11235 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
11238 if (!strcmp ("final", p
))
11239 result
= PRAGMA_OMP_CLAUSE_FINAL
;
11240 else if (!strcmp ("firstprivate", p
))
11241 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
11242 else if (!strcmp ("from", p
))
11243 result
= PRAGMA_OMP_CLAUSE_FROM
;
11246 if (!strcmp ("gang", p
))
11247 result
= PRAGMA_OACC_CLAUSE_GANG
;
11248 else if (!strcmp ("grainsize", p
))
11249 result
= PRAGMA_OMP_CLAUSE_GRAINSIZE
;
11252 if (!strcmp ("hint", p
))
11253 result
= PRAGMA_OMP_CLAUSE_HINT
;
11254 else if (!strcmp ("host", p
))
11255 result
= PRAGMA_OACC_CLAUSE_HOST
;
11258 if (!strcmp ("inbranch", p
))
11259 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
11260 else if (!strcmp ("independent", p
))
11261 result
= PRAGMA_OACC_CLAUSE_INDEPENDENT
;
11262 else if (!strcmp ("is_device_ptr", p
))
11263 result
= PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
;
11266 if (!strcmp ("lastprivate", p
))
11267 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
11268 else if (!strcmp ("linear", p
))
11269 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
11270 else if (!strcmp ("link", p
))
11271 result
= PRAGMA_OMP_CLAUSE_LINK
;
11274 if (!strcmp ("map", p
))
11275 result
= PRAGMA_OMP_CLAUSE_MAP
;
11276 else if (!strcmp ("mergeable", p
))
11277 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
11280 if (!strcmp ("nogroup", p
))
11281 result
= PRAGMA_OMP_CLAUSE_NOGROUP
;
11282 else if (!strcmp ("notinbranch", p
))
11283 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
11284 else if (!strcmp ("nowait", p
))
11285 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
11286 else if (!strcmp ("num_gangs", p
))
11287 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
11288 else if (!strcmp ("num_tasks", p
))
11289 result
= PRAGMA_OMP_CLAUSE_NUM_TASKS
;
11290 else if (!strcmp ("num_teams", p
))
11291 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
11292 else if (!strcmp ("num_threads", p
))
11293 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
11294 else if (!strcmp ("num_workers", p
))
11295 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
11298 if (!strcmp ("ordered", p
))
11299 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
11302 if (!strcmp ("parallel", p
))
11303 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
11304 else if (!strcmp ("present", p
))
11305 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
11306 else if (!strcmp ("present_or_copy", p
)
11307 || !strcmp ("pcopy", p
))
11308 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
;
11309 else if (!strcmp ("present_or_copyin", p
)
11310 || !strcmp ("pcopyin", p
))
11311 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
;
11312 else if (!strcmp ("present_or_copyout", p
)
11313 || !strcmp ("pcopyout", p
))
11314 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
;
11315 else if (!strcmp ("present_or_create", p
)
11316 || !strcmp ("pcreate", p
))
11317 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
;
11318 else if (!strcmp ("priority", p
))
11319 result
= PRAGMA_OMP_CLAUSE_PRIORITY
;
11320 else if (!strcmp ("private", p
))
11321 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
11322 else if (!strcmp ("proc_bind", p
))
11323 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
11326 if (!strcmp ("reduction", p
))
11327 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
11330 if (!strcmp ("safelen", p
))
11331 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
11332 else if (!strcmp ("schedule", p
))
11333 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
11334 else if (!strcmp ("sections", p
))
11335 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
11336 else if (!strcmp ("seq", p
))
11337 result
= PRAGMA_OACC_CLAUSE_SEQ
;
11338 else if (!strcmp ("shared", p
))
11339 result
= PRAGMA_OMP_CLAUSE_SHARED
;
11340 else if (!strcmp ("simd", p
))
11341 result
= PRAGMA_OMP_CLAUSE_SIMD
;
11342 else if (!strcmp ("simdlen", p
))
11343 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
11344 else if (!strcmp ("self", p
))
11345 result
= PRAGMA_OACC_CLAUSE_SELF
;
11348 if (!strcmp ("taskgroup", p
))
11349 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
11350 else if (!strcmp ("thread_limit", p
))
11351 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
11352 else if (!strcmp ("threads", p
))
11353 result
= PRAGMA_OMP_CLAUSE_THREADS
;
11354 else if (!strcmp ("tile", p
))
11355 result
= PRAGMA_OACC_CLAUSE_TILE
;
11356 else if (!strcmp ("to", p
))
11357 result
= PRAGMA_OMP_CLAUSE_TO
;
11360 if (!strcmp ("uniform", p
))
11361 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
11362 else if (!strcmp ("untied", p
))
11363 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
11364 else if (!strcmp ("use_device", p
))
11365 result
= PRAGMA_OACC_CLAUSE_USE_DEVICE
;
11366 else if (!strcmp ("use_device_ptr", p
))
11367 result
= PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
;
11370 if (!strcmp ("vector", p
))
11371 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
11372 else if (!strcmp ("vector_length", p
))
11373 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
11376 if (!strcmp ("wait", p
))
11377 result
= PRAGMA_OACC_CLAUSE_WAIT
;
11378 else if (!strcmp ("worker", p
))
11379 result
= PRAGMA_OACC_CLAUSE_WORKER
;
11384 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
11385 c_parser_consume_token (parser
);
11390 /* Validate that a clause of the given type does not already exist. */
11393 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
11398 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11399 if (OMP_CLAUSE_CODE (c
) == code
)
11401 location_t loc
= OMP_CLAUSE_LOCATION (c
);
11402 error_at (loc
, "too many %qs clauses", name
);
11408 Parse wait clause or wait directive parameters. */
11411 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
11413 vec
<tree
, va_gc
> *args
;
11416 matching_parens parens
;
11417 if (!parens
.require_open (parser
))
11420 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
11422 if (args
->length () == 0)
11424 c_parser_error (parser
, "expected integer expression before ')'");
11425 release_tree_vector (args
);
11429 args_tree
= build_tree_list_vec (args
);
11431 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
11433 tree targ
= TREE_VALUE (t
);
11435 if (targ
!= error_mark_node
)
11437 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
11439 c_parser_error (parser
, "expression must be integral");
11440 targ
= error_mark_node
;
11444 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
11446 OMP_CLAUSE_DECL (c
) = targ
;
11447 OMP_CLAUSE_CHAIN (c
) = list
;
11453 release_tree_vector (args
);
11454 parens
.require_close (parser
);
11458 /* OpenACC 2.0, OpenMP 2.5:
11461 variable-list , identifier
11463 If KIND is nonzero, create the appropriate node and install the
11464 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
11465 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
11467 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
11468 return the list created. */
11471 c_parser_omp_variable_list (c_parser
*parser
,
11472 location_t clause_loc
,
11473 enum omp_clause_code kind
, tree list
)
11475 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
11476 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
11477 c_parser_error (parser
, "expected identifier");
11479 while (c_parser_next_token_is (parser
, CPP_NAME
)
11480 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
11482 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
11484 if (t
== NULL_TREE
)
11486 undeclared_variable (c_parser_peek_token (parser
)->location
,
11487 c_parser_peek_token (parser
)->value
);
11488 t
= error_mark_node
;
11491 c_parser_consume_token (parser
);
11493 if (t
== error_mark_node
)
11495 else if (kind
!= 0)
11499 case OMP_CLAUSE__CACHE_
:
11500 /* The OpenACC cache directive explicitly only allows "array
11501 elements or subarrays". */
11502 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
11504 c_parser_error (parser
, "expected %<[%>");
11505 t
= error_mark_node
;
11509 case OMP_CLAUSE_MAP
:
11510 case OMP_CLAUSE_FROM
:
11511 case OMP_CLAUSE_TO
:
11512 while (c_parser_next_token_is (parser
, CPP_DOT
))
11514 location_t op_loc
= c_parser_peek_token (parser
)->location
;
11515 c_parser_consume_token (parser
);
11516 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11518 c_parser_error (parser
, "expected identifier");
11519 t
= error_mark_node
;
11523 c_token
*comp_tok
= c_parser_peek_token (parser
);
11524 tree ident
= comp_tok
->value
;
11525 location_t comp_loc
= comp_tok
->location
;
11526 c_parser_consume_token (parser
);
11527 t
= build_component_ref (op_loc
, t
, ident
, comp_loc
);
11530 case OMP_CLAUSE_DEPEND
:
11531 case OMP_CLAUSE_REDUCTION
:
11532 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
11534 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
11536 c_parser_consume_token (parser
);
11537 if (!c_parser_next_token_is (parser
, CPP_COLON
))
11539 location_t expr_loc
11540 = c_parser_peek_token (parser
)->location
;
11541 c_expr expr
= c_parser_expression (parser
);
11542 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
11544 low_bound
= expr
.value
;
11546 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
11547 length
= integer_one_node
;
11550 /* Look for `:'. */
11551 if (!c_parser_require (parser
, CPP_COLON
,
11554 t
= error_mark_node
;
11557 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
11559 location_t expr_loc
11560 = c_parser_peek_token (parser
)->location
;
11561 c_expr expr
= c_parser_expression (parser
);
11562 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
11564 length
= expr
.value
;
11567 /* Look for the closing `]'. */
11568 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
11571 t
= error_mark_node
;
11575 t
= tree_cons (low_bound
, length
, t
);
11582 if (t
!= error_mark_node
)
11584 tree u
= build_omp_clause (clause_loc
, kind
);
11585 OMP_CLAUSE_DECL (u
) = t
;
11586 OMP_CLAUSE_CHAIN (u
) = list
;
11591 list
= tree_cons (t
, NULL_TREE
, list
);
11593 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
11596 c_parser_consume_token (parser
);
11602 /* Similarly, but expect leading and trailing parenthesis. This is a very
11603 common case for OpenACC and OpenMP clauses. */
11606 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
11609 /* The clauses location. */
11610 location_t loc
= c_parser_peek_token (parser
)->location
;
11612 matching_parens parens
;
11613 if (parens
.require_open (parser
))
11615 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
11616 parens
.skip_until_found_close (parser
);
11622 copy ( variable-list )
11623 copyin ( variable-list )
11624 copyout ( variable-list )
11625 create ( variable-list )
11626 delete ( variable-list )
11627 present ( variable-list )
11628 present_or_copy ( variable-list )
11629 pcopy ( variable-list )
11630 present_or_copyin ( variable-list )
11631 pcopyin ( variable-list )
11632 present_or_copyout ( variable-list )
11633 pcopyout ( variable-list )
11634 present_or_create ( variable-list )
11635 pcreate ( variable-list ) */
11638 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
11641 enum gomp_map_kind kind
;
11644 case PRAGMA_OACC_CLAUSE_COPY
:
11645 kind
= GOMP_MAP_FORCE_TOFROM
;
11647 case PRAGMA_OACC_CLAUSE_COPYIN
:
11648 kind
= GOMP_MAP_FORCE_TO
;
11650 case PRAGMA_OACC_CLAUSE_COPYOUT
:
11651 kind
= GOMP_MAP_FORCE_FROM
;
11653 case PRAGMA_OACC_CLAUSE_CREATE
:
11654 kind
= GOMP_MAP_FORCE_ALLOC
;
11656 case PRAGMA_OACC_CLAUSE_DELETE
:
11657 kind
= GOMP_MAP_DELETE
;
11659 case PRAGMA_OACC_CLAUSE_DEVICE
:
11660 kind
= GOMP_MAP_FORCE_TO
;
11662 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
11663 kind
= GOMP_MAP_DEVICE_RESIDENT
;
11665 case PRAGMA_OACC_CLAUSE_HOST
:
11666 case PRAGMA_OACC_CLAUSE_SELF
:
11667 kind
= GOMP_MAP_FORCE_FROM
;
11669 case PRAGMA_OACC_CLAUSE_LINK
:
11670 kind
= GOMP_MAP_LINK
;
11672 case PRAGMA_OACC_CLAUSE_PRESENT
:
11673 kind
= GOMP_MAP_FORCE_PRESENT
;
11675 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
11676 kind
= GOMP_MAP_TOFROM
;
11678 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
11679 kind
= GOMP_MAP_TO
;
11681 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
11682 kind
= GOMP_MAP_FROM
;
11684 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
11685 kind
= GOMP_MAP_ALLOC
;
11688 gcc_unreachable ();
11691 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
11693 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11694 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
11700 deviceptr ( variable-list ) */
11703 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
11705 location_t loc
= c_parser_peek_token (parser
)->location
;
11708 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
11709 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
11710 variable-list must only allow for pointer variables. */
11711 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11712 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
11714 tree v
= TREE_PURPOSE (t
);
11716 /* FIXME diagnostics: Ideally we should keep individual
11717 locations for all the variables in the var list to make the
11718 following errors more precise. Perhaps
11719 c_parser_omp_var_list_parens() should construct a list of
11720 locations to go along with the var list. */
11722 if (!VAR_P (v
) && TREE_CODE (v
) != PARM_DECL
)
11723 error_at (loc
, "%qD is not a variable", v
);
11724 else if (TREE_TYPE (v
) == error_mark_node
)
11726 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
11727 error_at (loc
, "%qD is not a pointer variable", v
);
11729 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
11730 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
11731 OMP_CLAUSE_DECL (u
) = v
;
11732 OMP_CLAUSE_CHAIN (u
) = list
;
11739 /* OpenACC 2.0, OpenMP 3.0:
11740 collapse ( constant-expression ) */
11743 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
11745 tree c
, num
= error_mark_node
;
11749 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
11750 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
11752 loc
= c_parser_peek_token (parser
)->location
;
11753 matching_parens parens
;
11754 if (parens
.require_open (parser
))
11756 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
11757 parens
.skip_until_found_close (parser
);
11759 if (num
== error_mark_node
)
11761 mark_exp_read (num
);
11762 num
= c_fully_fold (num
, false, NULL
);
11763 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
11764 || !tree_fits_shwi_p (num
)
11765 || (n
= tree_to_shwi (num
)) <= 0
11769 "collapse argument needs positive constant integer expression");
11772 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
11773 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
11774 OMP_CLAUSE_CHAIN (c
) = list
;
11779 copyin ( variable-list ) */
11782 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
11784 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
11788 copyprivate ( variable-list ) */
11791 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
11793 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
11797 default ( none | shared )
11800 default ( none | present ) */
11803 c_parser_omp_clause_default (c_parser
*parser
, tree list
, bool is_oacc
)
11805 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
11806 location_t loc
= c_parser_peek_token (parser
)->location
;
11809 matching_parens parens
;
11810 if (!parens
.require_open (parser
))
11812 if (c_parser_next_token_is (parser
, CPP_NAME
))
11814 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11819 if (strcmp ("none", p
) != 0)
11821 kind
= OMP_CLAUSE_DEFAULT_NONE
;
11825 if (strcmp ("present", p
) != 0 || !is_oacc
)
11827 kind
= OMP_CLAUSE_DEFAULT_PRESENT
;
11831 if (strcmp ("shared", p
) != 0 || is_oacc
)
11833 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
11840 c_parser_consume_token (parser
);
11846 c_parser_error (parser
, "expected %<none%> or %<present%>");
11848 c_parser_error (parser
, "expected %<none%> or %<shared%>");
11850 parens
.skip_until_found_close (parser
);
11852 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
11855 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
11856 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
11857 OMP_CLAUSE_CHAIN (c
) = list
;
11858 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
11864 firstprivate ( variable-list ) */
11867 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
11869 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
11873 final ( expression ) */
11876 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
11878 location_t loc
= c_parser_peek_token (parser
)->location
;
11879 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11881 tree t
= c_parser_paren_condition (parser
);
11884 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
11886 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
11887 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
11888 OMP_CLAUSE_CHAIN (c
) = list
;
11892 c_parser_error (parser
, "expected %<(%>");
11897 /* OpenACC, OpenMP 2.5:
11901 if ( directive-name-modifier : expression )
11903 directive-name-modifier:
11904 parallel | task | taskloop | target data | target | target update
11905 | target enter data | target exit data */
11908 c_parser_omp_clause_if (c_parser
*parser
, tree list
, bool is_omp
)
11910 location_t location
= c_parser_peek_token (parser
)->location
;
11911 enum tree_code if_modifier
= ERROR_MARK
;
11913 matching_parens parens
;
11914 if (!parens
.require_open (parser
))
11917 if (is_omp
&& c_parser_next_token_is (parser
, CPP_NAME
))
11919 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11921 if (strcmp (p
, "parallel") == 0)
11922 if_modifier
= OMP_PARALLEL
;
11923 else if (strcmp (p
, "task") == 0)
11924 if_modifier
= OMP_TASK
;
11925 else if (strcmp (p
, "taskloop") == 0)
11926 if_modifier
= OMP_TASKLOOP
;
11927 else if (strcmp (p
, "target") == 0)
11929 if_modifier
= OMP_TARGET
;
11930 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11932 p
= IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser
)->value
);
11933 if (strcmp ("data", p
) == 0)
11934 if_modifier
= OMP_TARGET_DATA
;
11935 else if (strcmp ("update", p
) == 0)
11936 if_modifier
= OMP_TARGET_UPDATE
;
11937 else if (strcmp ("enter", p
) == 0)
11938 if_modifier
= OMP_TARGET_ENTER_DATA
;
11939 else if (strcmp ("exit", p
) == 0)
11940 if_modifier
= OMP_TARGET_EXIT_DATA
;
11941 if (if_modifier
!= OMP_TARGET
)
11944 c_parser_consume_token (parser
);
11948 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
11949 error_at (loc
, "expected %<data%>, %<update%>, %<enter%> "
11951 if_modifier
= ERROR_MARK
;
11953 if (if_modifier
== OMP_TARGET_ENTER_DATA
11954 || if_modifier
== OMP_TARGET_EXIT_DATA
)
11956 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11958 p
= IDENTIFIER_POINTER
11959 (c_parser_peek_2nd_token (parser
)->value
);
11960 if (strcmp ("data", p
) == 0)
11964 c_parser_consume_token (parser
);
11968 = c_parser_peek_2nd_token (parser
)->location
;
11969 error_at (loc
, "expected %<data%>");
11970 if_modifier
= ERROR_MARK
;
11975 if (if_modifier
!= ERROR_MARK
)
11977 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11979 c_parser_consume_token (parser
);
11980 c_parser_consume_token (parser
);
11986 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
11987 error_at (loc
, "expected %<:%>");
11989 if_modifier
= ERROR_MARK
;
11994 tree t
= c_parser_condition (parser
), c
;
11995 parens
.skip_until_found_close (parser
);
11997 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11998 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IF
)
12000 if (if_modifier
!= ERROR_MARK
12001 && OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
12003 const char *p
= NULL
;
12004 switch (if_modifier
)
12006 case OMP_PARALLEL
: p
= "parallel"; break;
12007 case OMP_TASK
: p
= "task"; break;
12008 case OMP_TASKLOOP
: p
= "taskloop"; break;
12009 case OMP_TARGET_DATA
: p
= "target data"; break;
12010 case OMP_TARGET
: p
= "target"; break;
12011 case OMP_TARGET_UPDATE
: p
= "target update"; break;
12012 case OMP_TARGET_ENTER_DATA
: p
= "enter data"; break;
12013 case OMP_TARGET_EXIT_DATA
: p
= "exit data"; break;
12014 default: gcc_unreachable ();
12016 error_at (location
, "too many %<if%> clauses with %qs modifier",
12020 else if (OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
12023 error_at (location
, "too many %<if%> clauses");
12025 error_at (location
, "too many %<if%> clauses without modifier");
12028 else if (if_modifier
== ERROR_MARK
12029 || OMP_CLAUSE_IF_MODIFIER (c
) == ERROR_MARK
)
12031 error_at (location
, "if any %<if%> clause has modifier, then all "
12032 "%<if%> clauses have to use modifier");
12037 c
= build_omp_clause (location
, OMP_CLAUSE_IF
);
12038 OMP_CLAUSE_IF_MODIFIER (c
) = if_modifier
;
12039 OMP_CLAUSE_IF_EXPR (c
) = t
;
12040 OMP_CLAUSE_CHAIN (c
) = list
;
12045 lastprivate ( variable-list ) */
12048 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
12050 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
12057 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12061 /* FIXME: Should we allow duplicates? */
12062 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
12064 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12065 OMP_CLAUSE_MERGEABLE
);
12066 OMP_CLAUSE_CHAIN (c
) = list
;
12075 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12078 location_t loc
= c_parser_peek_token (parser
)->location
;
12080 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
12082 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
12083 OMP_CLAUSE_CHAIN (c
) = list
;
12088 num_threads ( expression ) */
12091 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
12093 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
12094 matching_parens parens
;
12095 if (parens
.require_open (parser
))
12097 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12098 c_expr expr
= c_parser_expression (parser
);
12099 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12100 tree c
, t
= expr
.value
;
12101 t
= c_fully_fold (t
, false, NULL
);
12103 parens
.skip_until_found_close (parser
);
12105 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12107 c_parser_error (parser
, "expected integer expression");
12111 /* Attempt to statically determine when the number isn't positive. */
12112 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12113 build_int_cst (TREE_TYPE (t
), 0));
12114 protected_set_expr_location (c
, expr_loc
);
12115 if (c
== boolean_true_node
)
12117 warning_at (expr_loc
, 0,
12118 "%<num_threads%> value must be positive");
12119 t
= integer_one_node
;
12122 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
12124 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
12125 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
12126 OMP_CLAUSE_CHAIN (c
) = list
;
12134 num_tasks ( expression ) */
12137 c_parser_omp_clause_num_tasks (c_parser
*parser
, tree list
)
12139 location_t num_tasks_loc
= c_parser_peek_token (parser
)->location
;
12140 matching_parens parens
;
12141 if (parens
.require_open (parser
))
12143 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12144 c_expr expr
= c_parser_expression (parser
);
12145 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12146 tree c
, t
= expr
.value
;
12147 t
= c_fully_fold (t
, false, NULL
);
12149 parens
.skip_until_found_close (parser
);
12151 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12153 c_parser_error (parser
, "expected integer expression");
12157 /* Attempt to statically determine when the number isn't positive. */
12158 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12159 build_int_cst (TREE_TYPE (t
), 0));
12160 if (CAN_HAVE_LOCATION_P (c
))
12161 SET_EXPR_LOCATION (c
, expr_loc
);
12162 if (c
== boolean_true_node
)
12164 warning_at (expr_loc
, 0, "%<num_tasks%> value must be positive");
12165 t
= integer_one_node
;
12168 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TASKS
, "num_tasks");
12170 c
= build_omp_clause (num_tasks_loc
, OMP_CLAUSE_NUM_TASKS
);
12171 OMP_CLAUSE_NUM_TASKS_EXPR (c
) = t
;
12172 OMP_CLAUSE_CHAIN (c
) = list
;
12180 grainsize ( expression ) */
12183 c_parser_omp_clause_grainsize (c_parser
*parser
, tree list
)
12185 location_t grainsize_loc
= c_parser_peek_token (parser
)->location
;
12186 matching_parens parens
;
12187 if (parens
.require_open (parser
))
12189 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12190 c_expr expr
= c_parser_expression (parser
);
12191 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12192 tree c
, t
= expr
.value
;
12193 t
= c_fully_fold (t
, false, NULL
);
12195 parens
.skip_until_found_close (parser
);
12197 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12199 c_parser_error (parser
, "expected integer expression");
12203 /* Attempt to statically determine when the number isn't positive. */
12204 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12205 build_int_cst (TREE_TYPE (t
), 0));
12206 if (CAN_HAVE_LOCATION_P (c
))
12207 SET_EXPR_LOCATION (c
, expr_loc
);
12208 if (c
== boolean_true_node
)
12210 warning_at (expr_loc
, 0, "%<grainsize%> value must be positive");
12211 t
= integer_one_node
;
12214 check_no_duplicate_clause (list
, OMP_CLAUSE_GRAINSIZE
, "grainsize");
12216 c
= build_omp_clause (grainsize_loc
, OMP_CLAUSE_GRAINSIZE
);
12217 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
12218 OMP_CLAUSE_CHAIN (c
) = list
;
12226 priority ( expression ) */
12229 c_parser_omp_clause_priority (c_parser
*parser
, tree list
)
12231 location_t priority_loc
= c_parser_peek_token (parser
)->location
;
12232 matching_parens parens
;
12233 if (parens
.require_open (parser
))
12235 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12236 c_expr expr
= c_parser_expression (parser
);
12237 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12238 tree c
, t
= expr
.value
;
12239 t
= c_fully_fold (t
, false, NULL
);
12241 parens
.skip_until_found_close (parser
);
12243 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12245 c_parser_error (parser
, "expected integer expression");
12249 /* Attempt to statically determine when the number isn't
12251 c
= fold_build2_loc (expr_loc
, LT_EXPR
, boolean_type_node
, t
,
12252 build_int_cst (TREE_TYPE (t
), 0));
12253 if (CAN_HAVE_LOCATION_P (c
))
12254 SET_EXPR_LOCATION (c
, expr_loc
);
12255 if (c
== boolean_true_node
)
12257 warning_at (expr_loc
, 0, "%<priority%> value must be non-negative");
12258 t
= integer_one_node
;
12261 check_no_duplicate_clause (list
, OMP_CLAUSE_PRIORITY
, "priority");
12263 c
= build_omp_clause (priority_loc
, OMP_CLAUSE_PRIORITY
);
12264 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
12265 OMP_CLAUSE_CHAIN (c
) = list
;
12273 hint ( expression ) */
12276 c_parser_omp_clause_hint (c_parser
*parser
, tree list
)
12278 location_t hint_loc
= c_parser_peek_token (parser
)->location
;
12279 matching_parens parens
;
12280 if (parens
.require_open (parser
))
12282 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12283 c_expr expr
= c_parser_expression (parser
);
12284 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12285 tree c
, t
= expr
.value
;
12286 t
= c_fully_fold (t
, false, NULL
);
12288 parens
.skip_until_found_close (parser
);
12290 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12292 c_parser_error (parser
, "expected integer expression");
12296 check_no_duplicate_clause (list
, OMP_CLAUSE_HINT
, "hint");
12298 c
= build_omp_clause (hint_loc
, OMP_CLAUSE_HINT
);
12299 OMP_CLAUSE_HINT_EXPR (c
) = t
;
12300 OMP_CLAUSE_CHAIN (c
) = list
;
12308 defaultmap ( tofrom : scalar ) */
12311 c_parser_omp_clause_defaultmap (c_parser
*parser
, tree list
)
12313 location_t loc
= c_parser_peek_token (parser
)->location
;
12317 matching_parens parens
;
12318 if (!parens
.require_open (parser
))
12320 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12322 c_parser_error (parser
, "expected %<tofrom%>");
12325 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12326 if (strcmp (p
, "tofrom") != 0)
12328 c_parser_error (parser
, "expected %<tofrom%>");
12331 c_parser_consume_token (parser
);
12332 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12334 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12336 c_parser_error (parser
, "expected %<scalar%>");
12339 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12340 if (strcmp (p
, "scalar") != 0)
12342 c_parser_error (parser
, "expected %<scalar%>");
12345 c_parser_consume_token (parser
);
12346 parens
.skip_until_found_close (parser
);
12347 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULTMAP
, "defaultmap");
12348 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULTMAP
);
12349 OMP_CLAUSE_CHAIN (c
) = list
;
12353 parens
.skip_until_found_close (parser
);
12358 use_device ( variable-list )
12361 use_device_ptr ( variable-list ) */
12364 c_parser_omp_clause_use_device_ptr (c_parser
*parser
, tree list
)
12366 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_USE_DEVICE_PTR
,
12371 is_device_ptr ( variable-list ) */
12374 c_parser_omp_clause_is_device_ptr (c_parser
*parser
, tree list
)
12376 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_IS_DEVICE_PTR
, list
);
12380 num_gangs ( expression )
12381 num_workers ( expression )
12382 vector_length ( expression ) */
12385 c_parser_oacc_single_int_clause (c_parser
*parser
, omp_clause_code code
,
12388 location_t loc
= c_parser_peek_token (parser
)->location
;
12390 matching_parens parens
;
12391 if (!parens
.require_open (parser
))
12394 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12395 c_expr expr
= c_parser_expression (parser
);
12396 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12397 tree c
, t
= expr
.value
;
12398 t
= c_fully_fold (t
, false, NULL
);
12400 parens
.skip_until_found_close (parser
);
12402 if (t
== error_mark_node
)
12404 else if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12406 error_at (expr_loc
, "%qs expression must be integral",
12407 omp_clause_code_name
[code
]);
12411 /* Attempt to statically determine when the number isn't positive. */
12412 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12413 build_int_cst (TREE_TYPE (t
), 0));
12414 protected_set_expr_location (c
, expr_loc
);
12415 if (c
== boolean_true_node
)
12417 warning_at (expr_loc
, 0,
12418 "%qs value must be positive",
12419 omp_clause_code_name
[code
]);
12420 t
= integer_one_node
;
12423 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12425 c
= build_omp_clause (loc
, code
);
12426 OMP_CLAUSE_OPERAND (c
, 0) = t
;
12427 OMP_CLAUSE_CHAIN (c
) = list
;
12433 gang [( gang-arg-list )]
12434 worker [( [num:] int-expr )]
12435 vector [( [length:] int-expr )]
12437 where gang-arg is one of:
12442 and size-expr may be:
12449 c_parser_oacc_shape_clause (c_parser
*parser
, omp_clause_code kind
,
12450 const char *str
, tree list
)
12452 const char *id
= "num";
12453 tree ops
[2] = { NULL_TREE
, NULL_TREE
}, c
;
12454 location_t loc
= c_parser_peek_token (parser
)->location
;
12456 if (kind
== OMP_CLAUSE_VECTOR
)
12459 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12461 c_parser_consume_token (parser
);
12465 c_token
*next
= c_parser_peek_token (parser
);
12468 /* Gang static argument. */
12469 if (kind
== OMP_CLAUSE_GANG
12470 && c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12472 c_parser_consume_token (parser
);
12474 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12475 goto cleanup_error
;
12478 if (ops
[idx
] != NULL_TREE
)
12480 c_parser_error (parser
, "too many %<static%> arguments");
12481 goto cleanup_error
;
12484 /* Check for the '*' argument. */
12485 if (c_parser_next_token_is (parser
, CPP_MULT
)
12486 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
12487 || c_parser_peek_2nd_token (parser
)->type
12488 == CPP_CLOSE_PAREN
))
12490 c_parser_consume_token (parser
);
12491 ops
[idx
] = integer_minus_one_node
;
12493 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12495 c_parser_consume_token (parser
);
12502 /* Worker num: argument and vector length: arguments. */
12503 else if (c_parser_next_token_is (parser
, CPP_NAME
)
12504 && strcmp (id
, IDENTIFIER_POINTER (next
->value
)) == 0
12505 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12507 c_parser_consume_token (parser
); /* id */
12508 c_parser_consume_token (parser
); /* ':' */
12511 /* Now collect the actual argument. */
12512 if (ops
[idx
] != NULL_TREE
)
12514 c_parser_error (parser
, "unexpected argument");
12515 goto cleanup_error
;
12518 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12519 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
12520 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
12521 tree expr
= cexpr
.value
;
12522 if (expr
== error_mark_node
)
12523 goto cleanup_error
;
12525 expr
= c_fully_fold (expr
, false, NULL
);
12527 /* Attempt to statically determine when the number isn't a
12528 positive integer. */
12530 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
12532 c_parser_error (parser
, "expected integer expression");
12536 tree c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
12537 build_int_cst (TREE_TYPE (expr
), 0));
12538 if (c
== boolean_true_node
)
12540 warning_at (loc
, 0,
12541 "%qs value must be positive", str
);
12542 expr
= integer_one_node
;
12547 if (kind
== OMP_CLAUSE_GANG
12548 && c_parser_next_token_is (parser
, CPP_COMMA
))
12550 c_parser_consume_token (parser
);
12557 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12558 goto cleanup_error
;
12561 check_no_duplicate_clause (list
, kind
, str
);
12563 c
= build_omp_clause (loc
, kind
);
12566 OMP_CLAUSE_OPERAND (c
, 1) = ops
[1];
12568 OMP_CLAUSE_OPERAND (c
, 0) = ops
[0];
12569 OMP_CLAUSE_CHAIN (c
) = list
;
12574 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12585 c_parser_oacc_simple_clause (c_parser
*parser
, enum omp_clause_code code
,
12588 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12590 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12591 OMP_CLAUSE_CHAIN (c
) = list
;
12597 async [( int-expr )] */
12600 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
12603 location_t loc
= c_parser_peek_token (parser
)->location
;
12605 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
12607 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12609 c_parser_consume_token (parser
);
12611 t
= c_parser_expression (parser
).value
;
12612 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12613 c_parser_error (parser
, "expected integer expression");
12614 else if (t
== error_mark_node
12615 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12619 t
= c_fully_fold (t
, false, NULL
);
12621 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
12623 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
12624 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
12625 OMP_CLAUSE_CHAIN (c
) = list
;
12632 tile ( size-expr-list ) */
12635 c_parser_oacc_clause_tile (c_parser
*parser
, tree list
)
12637 tree c
, expr
= error_mark_node
;
12639 tree tile
= NULL_TREE
;
12641 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
12642 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
12644 loc
= c_parser_peek_token (parser
)->location
;
12645 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12650 if (tile
&& !c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
12653 if (c_parser_next_token_is (parser
, CPP_MULT
)
12654 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
12655 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
12657 c_parser_consume_token (parser
);
12658 expr
= integer_zero_node
;
12662 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12663 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
12664 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
12665 expr
= cexpr
.value
;
12667 if (expr
== error_mark_node
)
12669 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12674 expr
= c_fully_fold (expr
, false, NULL
);
12676 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
12677 || !tree_fits_shwi_p (expr
)
12678 || tree_to_shwi (expr
) <= 0)
12680 error_at (expr_loc
, "%<tile%> argument needs positive"
12681 " integral constant");
12682 expr
= integer_zero_node
;
12686 tile
= tree_cons (NULL_TREE
, expr
, tile
);
12688 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
));
12690 /* Consume the trailing ')'. */
12691 c_parser_consume_token (parser
);
12693 c
= build_omp_clause (loc
, OMP_CLAUSE_TILE
);
12694 tile
= nreverse (tile
);
12695 OMP_CLAUSE_TILE_LIST (c
) = tile
;
12696 OMP_CLAUSE_CHAIN (c
) = list
;
12701 wait ( int-expr-list ) */
12704 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
12706 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12708 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12709 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
12718 ordered ( constant-expression ) */
12721 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
12723 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
12725 tree c
, num
= NULL_TREE
;
12727 location_t loc
= c_parser_peek_token (parser
)->location
;
12728 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12730 matching_parens parens
;
12731 parens
.consume_open (parser
);
12732 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
12733 parens
.skip_until_found_close (parser
);
12735 if (num
== error_mark_node
)
12739 mark_exp_read (num
);
12740 num
= c_fully_fold (num
, false, NULL
);
12741 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
12742 || !tree_fits_shwi_p (num
)
12743 || (n
= tree_to_shwi (num
)) <= 0
12746 error_at (loc
, "ordered argument needs positive "
12747 "constant integer expression");
12751 c
= build_omp_clause (loc
, OMP_CLAUSE_ORDERED
);
12752 OMP_CLAUSE_ORDERED_EXPR (c
) = num
;
12753 OMP_CLAUSE_CHAIN (c
) = list
;
12758 private ( variable-list ) */
12761 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
12763 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
12767 reduction ( reduction-operator : variable-list )
12769 reduction-operator:
12770 One of: + * - & ^ | && ||
12774 reduction-operator:
12775 One of: + * - & ^ | && || max min
12779 reduction-operator:
12780 One of: + * - & ^ | && ||
12784 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
12786 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12787 matching_parens parens
;
12788 if (parens
.require_open (parser
))
12790 enum tree_code code
= ERROR_MARK
;
12791 tree reduc_id
= NULL_TREE
;
12793 switch (c_parser_peek_token (parser
)->type
)
12805 code
= BIT_AND_EXPR
;
12808 code
= BIT_XOR_EXPR
;
12811 code
= BIT_IOR_EXPR
;
12814 code
= TRUTH_ANDIF_EXPR
;
12817 code
= TRUTH_ORIF_EXPR
;
12822 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12823 if (strcmp (p
, "min") == 0)
12828 if (strcmp (p
, "max") == 0)
12833 reduc_id
= c_parser_peek_token (parser
)->value
;
12837 c_parser_error (parser
,
12838 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
12839 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
12840 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12843 c_parser_consume_token (parser
);
12844 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
12845 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12849 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12850 OMP_CLAUSE_REDUCTION
, list
);
12851 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12853 tree d
= OMP_CLAUSE_DECL (c
), type
;
12854 if (TREE_CODE (d
) != TREE_LIST
)
12855 type
= TREE_TYPE (d
);
12860 for (t
= d
; TREE_CODE (t
) == TREE_LIST
; t
= TREE_CHAIN (t
))
12862 type
= TREE_TYPE (t
);
12865 if (TREE_CODE (type
) != POINTER_TYPE
12866 && TREE_CODE (type
) != ARRAY_TYPE
)
12868 type
= TREE_TYPE (type
);
12872 while (TREE_CODE (type
) == ARRAY_TYPE
)
12873 type
= TREE_TYPE (type
);
12874 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
12875 if (code
== ERROR_MARK
12876 || !(INTEGRAL_TYPE_P (type
)
12877 || TREE_CODE (type
) == REAL_TYPE
12878 || TREE_CODE (type
) == COMPLEX_TYPE
))
12879 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
12880 = c_omp_reduction_lookup (reduc_id
,
12881 TYPE_MAIN_VARIANT (type
));
12886 parens
.skip_until_found_close (parser
);
12892 schedule ( schedule-kind )
12893 schedule ( schedule-kind , expression )
12896 static | dynamic | guided | runtime | auto
12899 schedule ( schedule-modifier : schedule-kind )
12900 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
12908 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
12911 location_t loc
= c_parser_peek_token (parser
)->location
;
12912 int modifiers
= 0, nmodifiers
= 0;
12914 matching_parens parens
;
12915 if (!parens
.require_open (parser
))
12918 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
12920 while (c_parser_next_token_is (parser
, CPP_NAME
))
12922 tree kind
= c_parser_peek_token (parser
)->value
;
12923 const char *p
= IDENTIFIER_POINTER (kind
);
12924 if (strcmp ("simd", p
) == 0)
12925 OMP_CLAUSE_SCHEDULE_SIMD (c
) = 1;
12926 else if (strcmp ("monotonic", p
) == 0)
12927 modifiers
|= OMP_CLAUSE_SCHEDULE_MONOTONIC
;
12928 else if (strcmp ("nonmonotonic", p
) == 0)
12929 modifiers
|= OMP_CLAUSE_SCHEDULE_NONMONOTONIC
;
12932 c_parser_consume_token (parser
);
12933 if (nmodifiers
++ == 0
12934 && c_parser_next_token_is (parser
, CPP_COMMA
))
12935 c_parser_consume_token (parser
);
12938 c_parser_require (parser
, CPP_COLON
, "expected %<:%>");
12943 if ((modifiers
& (OMP_CLAUSE_SCHEDULE_MONOTONIC
12944 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12945 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
12946 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12948 error_at (loc
, "both %<monotonic%> and %<nonmonotonic%> modifiers "
12953 if (c_parser_next_token_is (parser
, CPP_NAME
))
12955 tree kind
= c_parser_peek_token (parser
)->value
;
12956 const char *p
= IDENTIFIER_POINTER (kind
);
12961 if (strcmp ("dynamic", p
) != 0)
12963 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
12967 if (strcmp ("guided", p
) != 0)
12969 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
12973 if (strcmp ("runtime", p
) != 0)
12975 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
12982 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12983 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
12984 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
12985 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
12989 c_parser_consume_token (parser
);
12990 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12993 c_parser_consume_token (parser
);
12995 here
= c_parser_peek_token (parser
)->location
;
12996 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12997 expr
= convert_lvalue_to_rvalue (here
, expr
, false, true);
12999 t
= c_fully_fold (t
, false, NULL
);
13001 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
13002 error_at (here
, "schedule %<runtime%> does not take "
13003 "a %<chunk_size%> parameter");
13004 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
13006 "schedule %<auto%> does not take "
13007 "a %<chunk_size%> parameter");
13008 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
13010 /* Attempt to statically determine when the number isn't
13012 tree s
= fold_build2_loc (loc
, LE_EXPR
, boolean_type_node
, t
,
13013 build_int_cst (TREE_TYPE (t
), 0));
13014 protected_set_expr_location (s
, loc
);
13015 if (s
== boolean_true_node
)
13017 warning_at (loc
, 0,
13018 "chunk size value must be positive");
13019 t
= integer_one_node
;
13021 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
13024 c_parser_error (parser
, "expected integer expression");
13026 parens
.skip_until_found_close (parser
);
13029 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13030 "expected %<,%> or %<)%>");
13032 OMP_CLAUSE_SCHEDULE_KIND (c
)
13033 = (enum omp_clause_schedule_kind
)
13034 (OMP_CLAUSE_SCHEDULE_KIND (c
) | modifiers
);
13036 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
13037 OMP_CLAUSE_CHAIN (c
) = list
;
13041 c_parser_error (parser
, "invalid schedule kind");
13042 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
13047 shared ( variable-list ) */
13050 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
13052 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
13059 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
13063 /* FIXME: Should we allow duplicates? */
13064 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
13066 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
13067 OMP_CLAUSE_UNTIED
);
13068 OMP_CLAUSE_CHAIN (c
) = list
;
13078 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
13079 enum omp_clause_code code
, tree list
)
13081 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
13083 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13084 OMP_CLAUSE_CHAIN (c
) = list
;
13096 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
13097 enum omp_clause_code code
, tree list
)
13099 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13100 OMP_CLAUSE_CHAIN (c
) = list
;
13109 c_parser_omp_clause_nogroup (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
13111 check_no_duplicate_clause (list
, OMP_CLAUSE_NOGROUP
, "nogroup");
13112 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
13113 OMP_CLAUSE_NOGROUP
);
13114 OMP_CLAUSE_CHAIN (c
) = list
;
13123 c_parser_omp_clause_orderedkind (c_parser
*parser ATTRIBUTE_UNUSED
,
13124 enum omp_clause_code code
, tree list
)
13126 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
13127 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
13128 OMP_CLAUSE_CHAIN (c
) = list
;
13133 num_teams ( expression ) */
13136 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
13138 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
13139 matching_parens parens
;
13140 if (parens
.require_open (parser
))
13142 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13143 c_expr expr
= c_parser_expression (parser
);
13144 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13145 tree c
, t
= expr
.value
;
13146 t
= c_fully_fold (t
, false, NULL
);
13148 parens
.skip_until_found_close (parser
);
13150 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13152 c_parser_error (parser
, "expected integer expression");
13156 /* Attempt to statically determine when the number isn't positive. */
13157 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13158 build_int_cst (TREE_TYPE (t
), 0));
13159 protected_set_expr_location (c
, expr_loc
);
13160 if (c
== boolean_true_node
)
13162 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
13163 t
= integer_one_node
;
13166 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
13168 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
13169 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
13170 OMP_CLAUSE_CHAIN (c
) = list
;
13178 thread_limit ( expression ) */
13181 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
13183 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
13184 matching_parens parens
;
13185 if (parens
.require_open (parser
))
13187 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13188 c_expr expr
= c_parser_expression (parser
);
13189 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13190 tree c
, t
= expr
.value
;
13191 t
= c_fully_fold (t
, false, NULL
);
13193 parens
.skip_until_found_close (parser
);
13195 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13197 c_parser_error (parser
, "expected integer expression");
13201 /* Attempt to statically determine when the number isn't positive. */
13202 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13203 build_int_cst (TREE_TYPE (t
), 0));
13204 protected_set_expr_location (c
, expr_loc
);
13205 if (c
== boolean_true_node
)
13207 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
13208 t
= integer_one_node
;
13211 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
13214 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
13215 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
13216 OMP_CLAUSE_CHAIN (c
) = list
;
13224 aligned ( variable-list )
13225 aligned ( variable-list : constant-expression ) */
13228 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
13230 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13233 matching_parens parens
;
13234 if (!parens
.require_open (parser
))
13237 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13238 OMP_CLAUSE_ALIGNED
, list
);
13240 if (c_parser_next_token_is (parser
, CPP_COLON
))
13242 c_parser_consume_token (parser
);
13243 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13244 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13245 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13246 tree alignment
= expr
.value
;
13247 alignment
= c_fully_fold (alignment
, false, NULL
);
13248 if (TREE_CODE (alignment
) != INTEGER_CST
13249 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
13250 || tree_int_cst_sgn (alignment
) != 1)
13252 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
13253 "be positive constant integer expression");
13254 alignment
= NULL_TREE
;
13257 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13258 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
13261 parens
.skip_until_found_close (parser
);
13266 linear ( variable-list )
13267 linear ( variable-list : expression )
13270 linear ( modifier ( variable-list ) )
13271 linear ( modifier ( variable-list ) : expression ) */
13274 c_parser_omp_clause_linear (c_parser
*parser
, tree list
)
13276 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13278 enum omp_clause_linear_kind kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
13280 matching_parens parens
;
13281 if (!parens
.require_open (parser
))
13284 if (c_parser_next_token_is (parser
, CPP_NAME
))
13286 c_token
*tok
= c_parser_peek_token (parser
);
13287 const char *p
= IDENTIFIER_POINTER (tok
->value
);
13288 if (strcmp ("val", p
) == 0)
13289 kind
= OMP_CLAUSE_LINEAR_VAL
;
13290 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
)
13291 kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
13292 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
13294 c_parser_consume_token (parser
);
13295 c_parser_consume_token (parser
);
13299 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13300 OMP_CLAUSE_LINEAR
, list
);
13302 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
13303 parens
.skip_until_found_close (parser
);
13305 if (c_parser_next_token_is (parser
, CPP_COLON
))
13307 c_parser_consume_token (parser
);
13308 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13309 c_expr expr
= c_parser_expression (parser
);
13310 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13312 step
= c_fully_fold (step
, false, NULL
);
13313 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
13315 error_at (clause_loc
, "%<linear%> clause step expression must "
13317 step
= integer_one_node
;
13322 step
= integer_one_node
;
13324 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13326 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
13327 OMP_CLAUSE_LINEAR_KIND (c
) = kind
;
13330 parens
.skip_until_found_close (parser
);
13335 safelen ( constant-expression ) */
13338 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
13340 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13343 matching_parens parens
;
13344 if (!parens
.require_open (parser
))
13347 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13348 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13349 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13351 t
= c_fully_fold (t
, false, NULL
);
13352 if (TREE_CODE (t
) != INTEGER_CST
13353 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
13354 || tree_int_cst_sgn (t
) != 1)
13356 error_at (clause_loc
, "%<safelen%> clause expression must "
13357 "be positive constant integer expression");
13361 parens
.skip_until_found_close (parser
);
13362 if (t
== NULL_TREE
|| t
== error_mark_node
)
13365 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
13367 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
13368 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
13369 OMP_CLAUSE_CHAIN (c
) = list
;
13374 simdlen ( constant-expression ) */
13377 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
13379 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13382 matching_parens parens
;
13383 if (!parens
.require_open (parser
))
13386 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13387 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13388 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13390 t
= c_fully_fold (t
, false, NULL
);
13391 if (TREE_CODE (t
) != INTEGER_CST
13392 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
13393 || tree_int_cst_sgn (t
) != 1)
13395 error_at (clause_loc
, "%<simdlen%> clause expression must "
13396 "be positive constant integer expression");
13400 parens
.skip_until_found_close (parser
);
13401 if (t
== NULL_TREE
|| t
== error_mark_node
)
13404 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
13406 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
13407 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
13408 OMP_CLAUSE_CHAIN (c
) = list
;
13414 identifier [+/- integer]
13415 vec , identifier [+/- integer]
13419 c_parser_omp_clause_depend_sink (c_parser
*parser
, location_t clause_loc
,
13423 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
13424 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13426 c_parser_error (parser
, "expected identifier");
13430 while (c_parser_next_token_is (parser
, CPP_NAME
)
13431 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
13433 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
13434 tree addend
= NULL
;
13436 if (t
== NULL_TREE
)
13438 undeclared_variable (c_parser_peek_token (parser
)->location
,
13439 c_parser_peek_token (parser
)->value
);
13440 t
= error_mark_node
;
13443 c_parser_consume_token (parser
);
13446 if (c_parser_next_token_is (parser
, CPP_MINUS
))
13448 else if (!c_parser_next_token_is (parser
, CPP_PLUS
))
13450 addend
= integer_zero_node
;
13452 goto add_to_vector
;
13454 c_parser_consume_token (parser
);
13456 if (c_parser_next_token_is_not (parser
, CPP_NUMBER
))
13458 c_parser_error (parser
, "expected integer");
13462 addend
= c_parser_peek_token (parser
)->value
;
13463 if (TREE_CODE (addend
) != INTEGER_CST
)
13465 c_parser_error (parser
, "expected integer");
13468 c_parser_consume_token (parser
);
13471 if (t
!= error_mark_node
)
13473 vec
= tree_cons (addend
, t
, vec
);
13475 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec
) = 1;
13478 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
13481 c_parser_consume_token (parser
);
13484 if (vec
== NULL_TREE
)
13487 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
13488 OMP_CLAUSE_DEPEND_KIND (u
) = OMP_CLAUSE_DEPEND_SINK
;
13489 OMP_CLAUSE_DECL (u
) = nreverse (vec
);
13490 OMP_CLAUSE_CHAIN (u
) = list
;
13495 depend ( depend-kind: variable-list )
13503 depend ( sink : vec ) */
13506 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
13508 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13509 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
13512 matching_parens parens
;
13513 if (!parens
.require_open (parser
))
13516 if (c_parser_next_token_is (parser
, CPP_NAME
))
13518 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13519 if (strcmp ("in", p
) == 0)
13520 kind
= OMP_CLAUSE_DEPEND_IN
;
13521 else if (strcmp ("inout", p
) == 0)
13522 kind
= OMP_CLAUSE_DEPEND_INOUT
;
13523 else if (strcmp ("out", p
) == 0)
13524 kind
= OMP_CLAUSE_DEPEND_OUT
;
13525 else if (strcmp ("source", p
) == 0)
13526 kind
= OMP_CLAUSE_DEPEND_SOURCE
;
13527 else if (strcmp ("sink", p
) == 0)
13528 kind
= OMP_CLAUSE_DEPEND_SINK
;
13535 c_parser_consume_token (parser
);
13537 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
13539 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
13540 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
13541 OMP_CLAUSE_DECL (c
) = NULL_TREE
;
13542 OMP_CLAUSE_CHAIN (c
) = list
;
13543 parens
.skip_until_found_close (parser
);
13547 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13550 if (kind
== OMP_CLAUSE_DEPEND_SINK
)
13551 nl
= c_parser_omp_clause_depend_sink (parser
, clause_loc
, list
);
13554 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13555 OMP_CLAUSE_DEPEND
, list
);
13557 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13558 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
13561 parens
.skip_until_found_close (parser
);
13565 c_parser_error (parser
, "invalid depend kind");
13567 parens
.skip_until_found_close (parser
);
13572 map ( map-kind: variable-list )
13573 map ( variable-list )
13576 alloc | to | from | tofrom
13580 alloc | to | from | tofrom | release | delete
13582 map ( always [,] map-kind: variable-list ) */
13585 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
13587 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13588 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
13590 enum c_id_kind always_id_kind
= C_ID_NONE
;
13591 location_t always_loc
= UNKNOWN_LOCATION
;
13592 tree always_id
= NULL_TREE
;
13595 matching_parens parens
;
13596 if (!parens
.require_open (parser
))
13599 if (c_parser_next_token_is (parser
, CPP_NAME
))
13601 c_token
*tok
= c_parser_peek_token (parser
);
13602 const char *p
= IDENTIFIER_POINTER (tok
->value
);
13603 always_id_kind
= tok
->id_kind
;
13604 always_loc
= tok
->location
;
13605 always_id
= tok
->value
;
13606 if (strcmp ("always", p
) == 0)
13608 c_token
*sectok
= c_parser_peek_2nd_token (parser
);
13609 if (sectok
->type
== CPP_COMMA
)
13611 c_parser_consume_token (parser
);
13612 c_parser_consume_token (parser
);
13615 else if (sectok
->type
== CPP_NAME
)
13617 p
= IDENTIFIER_POINTER (sectok
->value
);
13618 if (strcmp ("alloc", p
) == 0
13619 || strcmp ("to", p
) == 0
13620 || strcmp ("from", p
) == 0
13621 || strcmp ("tofrom", p
) == 0
13622 || strcmp ("release", p
) == 0
13623 || strcmp ("delete", p
) == 0)
13625 c_parser_consume_token (parser
);
13632 if (c_parser_next_token_is (parser
, CPP_NAME
)
13633 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13635 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13636 if (strcmp ("alloc", p
) == 0)
13637 kind
= GOMP_MAP_ALLOC
;
13638 else if (strcmp ("to", p
) == 0)
13639 kind
= always
? GOMP_MAP_ALWAYS_TO
: GOMP_MAP_TO
;
13640 else if (strcmp ("from", p
) == 0)
13641 kind
= always
? GOMP_MAP_ALWAYS_FROM
: GOMP_MAP_FROM
;
13642 else if (strcmp ("tofrom", p
) == 0)
13643 kind
= always
? GOMP_MAP_ALWAYS_TOFROM
: GOMP_MAP_TOFROM
;
13644 else if (strcmp ("release", p
) == 0)
13645 kind
= GOMP_MAP_RELEASE
;
13646 else if (strcmp ("delete", p
) == 0)
13647 kind
= GOMP_MAP_DELETE
;
13650 c_parser_error (parser
, "invalid map kind");
13651 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13655 c_parser_consume_token (parser
);
13656 c_parser_consume_token (parser
);
13660 if (always_id_kind
!= C_ID_ID
)
13662 c_parser_error (parser
, "expected identifier");
13663 parens
.skip_until_found_close (parser
);
13667 tree t
= lookup_name (always_id
);
13668 if (t
== NULL_TREE
)
13670 undeclared_variable (always_loc
, always_id
);
13671 t
= error_mark_node
;
13673 if (t
!= error_mark_node
)
13675 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_MAP
);
13676 OMP_CLAUSE_DECL (u
) = t
;
13677 OMP_CLAUSE_CHAIN (u
) = list
;
13678 OMP_CLAUSE_SET_MAP_KIND (u
, kind
);
13683 parens
.skip_until_found_close (parser
);
13688 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
13690 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13691 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
13693 parens
.skip_until_found_close (parser
);
13698 device ( expression ) */
13701 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
13703 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13704 matching_parens parens
;
13705 if (parens
.require_open (parser
))
13707 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13708 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13709 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13710 tree c
, t
= expr
.value
;
13711 t
= c_fully_fold (t
, false, NULL
);
13713 parens
.skip_until_found_close (parser
);
13715 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13717 c_parser_error (parser
, "expected integer expression");
13721 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
13723 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
13724 OMP_CLAUSE_DEVICE_ID (c
) = t
;
13725 OMP_CLAUSE_CHAIN (c
) = list
;
13733 dist_schedule ( static )
13734 dist_schedule ( static , expression ) */
13737 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
13739 tree c
, t
= NULL_TREE
;
13740 location_t loc
= c_parser_peek_token (parser
)->location
;
13742 matching_parens parens
;
13743 if (!parens
.require_open (parser
))
13746 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
13748 c_parser_error (parser
, "invalid dist_schedule kind");
13749 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13754 c_parser_consume_token (parser
);
13755 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13757 c_parser_consume_token (parser
);
13759 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13760 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13761 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13763 t
= c_fully_fold (t
, false, NULL
);
13764 parens
.skip_until_found_close (parser
);
13767 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13768 "expected %<,%> or %<)%>");
13770 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
13771 if (t
== error_mark_node
)
13774 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
13775 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
13776 OMP_CLAUSE_CHAIN (c
) = list
;
13781 proc_bind ( proc-bind-kind )
13784 master | close | spread */
13787 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
13789 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13790 enum omp_clause_proc_bind_kind kind
;
13793 matching_parens parens
;
13794 if (!parens
.require_open (parser
))
13797 if (c_parser_next_token_is (parser
, CPP_NAME
))
13799 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13800 if (strcmp ("master", p
) == 0)
13801 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
13802 else if (strcmp ("close", p
) == 0)
13803 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
13804 else if (strcmp ("spread", p
) == 0)
13805 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
13812 c_parser_consume_token (parser
);
13813 parens
.skip_until_found_close (parser
);
13814 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
13815 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
13816 OMP_CLAUSE_CHAIN (c
) = list
;
13820 c_parser_error (parser
, "invalid proc_bind kind");
13821 parens
.skip_until_found_close (parser
);
13826 to ( variable-list ) */
13829 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
13831 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
13835 from ( variable-list ) */
13838 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
13840 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
13844 uniform ( variable-list ) */
13847 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
13849 /* The clauses location. */
13850 location_t loc
= c_parser_peek_token (parser
)->location
;
13852 matching_parens parens
;
13853 if (parens
.require_open (parser
))
13855 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
13857 parens
.skip_until_found_close (parser
);
13862 /* Parse all OpenACC clauses. The set clauses allowed by the directive
13863 is a bitmask in MASK. Return the list of clauses found. */
13866 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
13867 const char *where
, bool finish_p
= true)
13869 tree clauses
= NULL
;
13872 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13875 pragma_omp_clause c_kind
;
13876 const char *c_name
;
13877 tree prev
= clauses
;
13879 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
13880 c_parser_consume_token (parser
);
13882 here
= c_parser_peek_token (parser
)->location
;
13883 c_kind
= c_parser_omp_clause_name (parser
);
13887 case PRAGMA_OACC_CLAUSE_ASYNC
:
13888 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
13891 case PRAGMA_OACC_CLAUSE_AUTO
:
13892 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_AUTO
,
13896 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
13897 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
13898 c_name
= "collapse";
13900 case PRAGMA_OACC_CLAUSE_COPY
:
13901 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13904 case PRAGMA_OACC_CLAUSE_COPYIN
:
13905 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13908 case PRAGMA_OACC_CLAUSE_COPYOUT
:
13909 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13910 c_name
= "copyout";
13912 case PRAGMA_OACC_CLAUSE_CREATE
:
13913 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13916 case PRAGMA_OACC_CLAUSE_DELETE
:
13917 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13920 case PRAGMA_OMP_CLAUSE_DEFAULT
:
13921 clauses
= c_parser_omp_clause_default (parser
, clauses
, true);
13922 c_name
= "default";
13924 case PRAGMA_OACC_CLAUSE_DEVICE
:
13925 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13928 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
13929 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
13930 c_name
= "deviceptr";
13932 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
13933 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13934 c_name
= "device_resident";
13936 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
13937 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13938 c_name
= "firstprivate";
13940 case PRAGMA_OACC_CLAUSE_GANG
:
13942 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_GANG
,
13945 case PRAGMA_OACC_CLAUSE_HOST
:
13946 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13949 case PRAGMA_OACC_CLAUSE_IF
:
13950 clauses
= c_parser_omp_clause_if (parser
, clauses
, false);
13953 case PRAGMA_OACC_CLAUSE_INDEPENDENT
:
13954 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_INDEPENDENT
,
13956 c_name
= "independent";
13958 case PRAGMA_OACC_CLAUSE_LINK
:
13959 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13962 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
13963 clauses
= c_parser_oacc_single_int_clause (parser
,
13964 OMP_CLAUSE_NUM_GANGS
,
13966 c_name
= "num_gangs";
13968 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
13969 clauses
= c_parser_oacc_single_int_clause (parser
,
13970 OMP_CLAUSE_NUM_WORKERS
,
13972 c_name
= "num_workers";
13974 case PRAGMA_OACC_CLAUSE_PRESENT
:
13975 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13976 c_name
= "present";
13978 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
13979 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13980 c_name
= "present_or_copy";
13982 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
13983 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13984 c_name
= "present_or_copyin";
13986 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
13987 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13988 c_name
= "present_or_copyout";
13990 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
13991 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13992 c_name
= "present_or_create";
13994 case PRAGMA_OACC_CLAUSE_PRIVATE
:
13995 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13996 c_name
= "private";
13998 case PRAGMA_OACC_CLAUSE_REDUCTION
:
13999 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
14000 c_name
= "reduction";
14002 case PRAGMA_OACC_CLAUSE_SELF
:
14003 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
14006 case PRAGMA_OACC_CLAUSE_SEQ
:
14007 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_SEQ
,
14011 case PRAGMA_OACC_CLAUSE_TILE
:
14012 clauses
= c_parser_oacc_clause_tile (parser
, clauses
);
14015 case PRAGMA_OACC_CLAUSE_USE_DEVICE
:
14016 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
14017 c_name
= "use_device";
14019 case PRAGMA_OACC_CLAUSE_VECTOR
:
14021 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_VECTOR
,
14024 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
14025 clauses
= c_parser_oacc_single_int_clause (parser
,
14026 OMP_CLAUSE_VECTOR_LENGTH
,
14028 c_name
= "vector_length";
14030 case PRAGMA_OACC_CLAUSE_WAIT
:
14031 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
14034 case PRAGMA_OACC_CLAUSE_WORKER
:
14036 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_WORKER
,
14040 c_parser_error (parser
, "expected %<#pragma acc%> clause");
14046 if (((mask
>> c_kind
) & 1) == 0)
14048 /* Remove the invalid clause(s) from the list to avoid
14049 confusing the rest of the compiler. */
14051 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
14056 c_parser_skip_to_pragma_eol (parser
);
14059 return c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14064 /* Parse all OpenMP clauses. The set clauses allowed by the directive
14065 is a bitmask in MASK. Return the list of clauses found. */
14068 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
14069 const char *where
, bool finish_p
= true)
14071 tree clauses
= NULL
;
14074 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14077 pragma_omp_clause c_kind
;
14078 const char *c_name
;
14079 tree prev
= clauses
;
14081 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
14082 c_parser_consume_token (parser
);
14084 here
= c_parser_peek_token (parser
)->location
;
14085 c_kind
= c_parser_omp_clause_name (parser
);
14089 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
14090 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
14091 c_name
= "collapse";
14093 case PRAGMA_OMP_CLAUSE_COPYIN
:
14094 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
14097 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
14098 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
14099 c_name
= "copyprivate";
14101 case PRAGMA_OMP_CLAUSE_DEFAULT
:
14102 clauses
= c_parser_omp_clause_default (parser
, clauses
, false);
14103 c_name
= "default";
14105 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
14106 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
14107 c_name
= "firstprivate";
14109 case PRAGMA_OMP_CLAUSE_FINAL
:
14110 clauses
= c_parser_omp_clause_final (parser
, clauses
);
14113 case PRAGMA_OMP_CLAUSE_GRAINSIZE
:
14114 clauses
= c_parser_omp_clause_grainsize (parser
, clauses
);
14115 c_name
= "grainsize";
14117 case PRAGMA_OMP_CLAUSE_HINT
:
14118 clauses
= c_parser_omp_clause_hint (parser
, clauses
);
14121 case PRAGMA_OMP_CLAUSE_DEFAULTMAP
:
14122 clauses
= c_parser_omp_clause_defaultmap (parser
, clauses
);
14123 c_name
= "defaultmap";
14125 case PRAGMA_OMP_CLAUSE_IF
:
14126 clauses
= c_parser_omp_clause_if (parser
, clauses
, true);
14129 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
14130 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
14131 c_name
= "lastprivate";
14133 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
14134 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
14135 c_name
= "mergeable";
14137 case PRAGMA_OMP_CLAUSE_NOWAIT
:
14138 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
14141 case PRAGMA_OMP_CLAUSE_NUM_TASKS
:
14142 clauses
= c_parser_omp_clause_num_tasks (parser
, clauses
);
14143 c_name
= "num_tasks";
14145 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
14146 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
14147 c_name
= "num_threads";
14149 case PRAGMA_OMP_CLAUSE_ORDERED
:
14150 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
14151 c_name
= "ordered";
14153 case PRAGMA_OMP_CLAUSE_PRIORITY
:
14154 clauses
= c_parser_omp_clause_priority (parser
, clauses
);
14155 c_name
= "priority";
14157 case PRAGMA_OMP_CLAUSE_PRIVATE
:
14158 clauses
= c_parser_omp_clause_private (parser
, clauses
);
14159 c_name
= "private";
14161 case PRAGMA_OMP_CLAUSE_REDUCTION
:
14162 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
14163 c_name
= "reduction";
14165 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
14166 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
14167 c_name
= "schedule";
14169 case PRAGMA_OMP_CLAUSE_SHARED
:
14170 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
14173 case PRAGMA_OMP_CLAUSE_UNTIED
:
14174 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
14177 case PRAGMA_OMP_CLAUSE_INBRANCH
:
14178 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
14180 c_name
= "inbranch";
14182 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
14183 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
14185 c_name
= "notinbranch";
14187 case PRAGMA_OMP_CLAUSE_PARALLEL
:
14189 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
14191 c_name
= "parallel";
14195 error_at (here
, "%qs must be the first clause of %qs",
14200 case PRAGMA_OMP_CLAUSE_FOR
:
14202 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
14206 goto clause_not_first
;
14208 case PRAGMA_OMP_CLAUSE_SECTIONS
:
14210 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
14212 c_name
= "sections";
14214 goto clause_not_first
;
14216 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
14218 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
14220 c_name
= "taskgroup";
14222 goto clause_not_first
;
14224 case PRAGMA_OMP_CLAUSE_LINK
:
14226 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LINK
, clauses
);
14229 case PRAGMA_OMP_CLAUSE_TO
:
14230 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINK
)) != 0)
14232 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
14235 clauses
= c_parser_omp_clause_to (parser
, clauses
);
14238 case PRAGMA_OMP_CLAUSE_FROM
:
14239 clauses
= c_parser_omp_clause_from (parser
, clauses
);
14242 case PRAGMA_OMP_CLAUSE_UNIFORM
:
14243 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
14244 c_name
= "uniform";
14246 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
14247 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
14248 c_name
= "num_teams";
14250 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
14251 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
14252 c_name
= "thread_limit";
14254 case PRAGMA_OMP_CLAUSE_ALIGNED
:
14255 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
14256 c_name
= "aligned";
14258 case PRAGMA_OMP_CLAUSE_LINEAR
:
14259 clauses
= c_parser_omp_clause_linear (parser
, clauses
);
14262 case PRAGMA_OMP_CLAUSE_DEPEND
:
14263 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
14266 case PRAGMA_OMP_CLAUSE_MAP
:
14267 clauses
= c_parser_omp_clause_map (parser
, clauses
);
14270 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
:
14271 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
14272 c_name
= "use_device_ptr";
14274 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
:
14275 clauses
= c_parser_omp_clause_is_device_ptr (parser
, clauses
);
14276 c_name
= "is_device_ptr";
14278 case PRAGMA_OMP_CLAUSE_DEVICE
:
14279 clauses
= c_parser_omp_clause_device (parser
, clauses
);
14282 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
14283 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
14284 c_name
= "dist_schedule";
14286 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
14287 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
14288 c_name
= "proc_bind";
14290 case PRAGMA_OMP_CLAUSE_SAFELEN
:
14291 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
14292 c_name
= "safelen";
14294 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
14295 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
14296 c_name
= "simdlen";
14298 case PRAGMA_OMP_CLAUSE_NOGROUP
:
14299 clauses
= c_parser_omp_clause_nogroup (parser
, clauses
);
14300 c_name
= "nogroup";
14302 case PRAGMA_OMP_CLAUSE_THREADS
:
14304 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_THREADS
,
14306 c_name
= "threads";
14308 case PRAGMA_OMP_CLAUSE_SIMD
:
14310 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_SIMD
,
14315 c_parser_error (parser
, "expected %<#pragma omp%> clause");
14321 if (((mask
>> c_kind
) & 1) == 0)
14323 /* Remove the invalid clause(s) from the list to avoid
14324 confusing the rest of the compiler. */
14326 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
14331 c_parser_skip_to_pragma_eol (parser
);
14335 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_UNIFORM
)) != 0)
14336 return c_finish_omp_clauses (clauses
, C_ORT_OMP_DECLARE_SIMD
);
14337 return c_finish_omp_clauses (clauses
, C_ORT_OMP
);
14343 /* OpenACC 2.0, OpenMP 2.5:
14347 In practice, we're also interested in adding the statement to an
14348 outer node. So it is convenient if we work around the fact that
14349 c_parser_statement calls add_stmt. */
14352 c_parser_omp_structured_block (c_parser
*parser
, bool *if_p
)
14354 tree stmt
= push_stmt_list ();
14355 c_parser_statement (parser
, if_p
);
14356 return pop_stmt_list (stmt
);
14360 # pragma acc cache (variable-list) new-line
14362 LOC is the location of the #pragma token.
14366 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
14368 tree stmt
, clauses
;
14370 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
14371 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14373 c_parser_skip_to_pragma_eol (parser
);
14375 stmt
= make_node (OACC_CACHE
);
14376 TREE_TYPE (stmt
) = void_type_node
;
14377 OACC_CACHE_CLAUSES (stmt
) = clauses
;
14378 SET_EXPR_LOCATION (stmt
, loc
);
14385 # pragma acc data oacc-data-clause[optseq] new-line
14388 LOC is the location of the #pragma token.
14391 #define OACC_DATA_CLAUSE_MASK \
14392 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14393 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14394 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14395 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14396 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14397 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14398 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14399 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14400 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14401 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14402 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
14405 c_parser_oacc_data (location_t loc
, c_parser
*parser
, bool *if_p
)
14407 tree stmt
, clauses
, block
;
14409 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
14410 "#pragma acc data");
14412 block
= c_begin_omp_parallel ();
14413 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14415 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
14421 # pragma acc declare oacc-data-clause[optseq] new-line
14424 #define OACC_DECLARE_CLAUSE_MASK \
14425 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14426 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14427 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14428 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14429 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14430 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \
14431 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \
14432 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14433 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14434 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14435 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14436 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
14439 c_parser_oacc_declare (c_parser
*parser
)
14441 location_t pragma_loc
= c_parser_peek_token (parser
)->location
;
14442 tree clauses
, stmt
, t
, decl
;
14444 bool error
= false;
14446 c_parser_consume_pragma (parser
);
14448 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DECLARE_CLAUSE_MASK
,
14449 "#pragma acc declare");
14452 error_at (pragma_loc
,
14453 "no valid clauses specified in %<#pragma acc declare%>");
14457 for (t
= clauses
; t
; t
= OMP_CLAUSE_CHAIN (t
))
14459 location_t loc
= OMP_CLAUSE_LOCATION (t
);
14460 decl
= OMP_CLAUSE_DECL (t
);
14461 if (!DECL_P (decl
))
14463 error_at (loc
, "array section in %<#pragma acc declare%>");
14468 switch (OMP_CLAUSE_MAP_KIND (t
))
14470 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
14471 case GOMP_MAP_FORCE_ALLOC
:
14472 case GOMP_MAP_FORCE_TO
:
14473 case GOMP_MAP_FORCE_DEVICEPTR
:
14474 case GOMP_MAP_DEVICE_RESIDENT
:
14477 case GOMP_MAP_LINK
:
14478 if (!global_bindings_p ()
14479 && (TREE_STATIC (decl
)
14480 || !DECL_EXTERNAL (decl
)))
14483 "%qD must be a global variable in "
14484 "%<#pragma acc declare link%>",
14492 if (global_bindings_p ())
14494 error_at (loc
, "invalid OpenACC clause at file scope");
14498 if (DECL_EXTERNAL (decl
))
14501 "invalid use of %<extern%> variable %qD "
14502 "in %<#pragma acc declare%>", decl
);
14506 else if (TREE_PUBLIC (decl
))
14509 "invalid use of %<global%> variable %qD "
14510 "in %<#pragma acc declare%>", decl
);
14517 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl
))
14518 || lookup_attribute ("omp declare target link",
14519 DECL_ATTRIBUTES (decl
)))
14521 error_at (loc
, "variable %qD used more than once with "
14522 "%<#pragma acc declare%>", decl
);
14531 if (OMP_CLAUSE_MAP_KIND (t
) == GOMP_MAP_LINK
)
14532 id
= get_identifier ("omp declare target link");
14534 id
= get_identifier ("omp declare target");
14536 DECL_ATTRIBUTES (decl
)
14537 = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (decl
));
14539 if (global_bindings_p ())
14541 symtab_node
*node
= symtab_node::get (decl
);
14544 node
->offloadable
= 1;
14545 if (ENABLE_OFFLOADING
)
14547 g
->have_offload
= true;
14548 if (is_a
<varpool_node
*> (node
))
14549 vec_safe_push (offload_vars
, decl
);
14556 if (error
|| global_bindings_p ())
14559 stmt
= make_node (OACC_DECLARE
);
14560 TREE_TYPE (stmt
) = void_type_node
;
14561 OACC_DECLARE_CLAUSES (stmt
) = clauses
;
14562 SET_EXPR_LOCATION (stmt
, pragma_loc
);
14570 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
14574 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
14577 LOC is the location of the #pragma token.
14580 #define OACC_ENTER_DATA_CLAUSE_MASK \
14581 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14582 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14583 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14584 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14585 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14586 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14587 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14589 #define OACC_EXIT_DATA_CLAUSE_MASK \
14590 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14591 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14592 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14593 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
14594 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14597 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
14599 location_t loc
= c_parser_peek_token (parser
)->location
;
14600 tree clauses
, stmt
;
14601 const char *p
= "";
14603 c_parser_consume_pragma (parser
);
14605 if (c_parser_next_token_is (parser
, CPP_NAME
))
14607 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14608 c_parser_consume_token (parser
);
14611 if (strcmp (p
, "data") != 0)
14613 error_at (loc
, "expected %<data%> after %<#pragma acc %s%>",
14614 enter
? "enter" : "exit");
14615 parser
->error
= true;
14616 c_parser_skip_to_pragma_eol (parser
);
14621 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
14622 "#pragma acc enter data");
14624 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
14625 "#pragma acc exit data");
14627 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
14629 error_at (loc
, "%<#pragma acc %s data%> has no data movement clause",
14630 enter
? "enter" : "exit");
14634 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
14635 TREE_TYPE (stmt
) = void_type_node
;
14636 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
14637 SET_EXPR_LOCATION (stmt
, loc
);
14643 # pragma acc host_data oacc-data-clause[optseq] new-line
14647 #define OACC_HOST_DATA_CLAUSE_MASK \
14648 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
14651 c_parser_oacc_host_data (location_t loc
, c_parser
*parser
, bool *if_p
)
14653 tree stmt
, clauses
, block
;
14655 clauses
= c_parser_oacc_all_clauses (parser
, OACC_HOST_DATA_CLAUSE_MASK
,
14656 "#pragma acc host_data");
14658 block
= c_begin_omp_parallel ();
14659 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14660 stmt
= c_finish_oacc_host_data (loc
, clauses
, block
);
14667 # pragma acc loop oacc-loop-clause[optseq] new-line
14670 LOC is the location of the #pragma token.
14673 #define OACC_LOOP_CLAUSE_MASK \
14674 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
14675 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14676 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14677 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14678 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14679 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14680 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
14681 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
14682 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
14683 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
14685 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
,
14686 omp_clause_mask mask
, tree
*cclauses
, bool *if_p
)
14688 bool is_parallel
= ((mask
>> PRAGMA_OACC_CLAUSE_REDUCTION
) & 1) == 1;
14690 strcat (p_name
, " loop");
14691 mask
|= OACC_LOOP_CLAUSE_MASK
;
14693 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
,
14697 clauses
= c_oacc_split_loop_clauses (clauses
, cclauses
, is_parallel
);
14699 *cclauses
= c_finish_omp_clauses (*cclauses
, C_ORT_ACC
);
14701 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14704 tree block
= c_begin_compound_stmt (true);
14705 tree stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
,
14707 block
= c_end_compound_stmt (loc
, block
, true);
14714 # pragma acc kernels oacc-kernels-clause[optseq] new-line
14719 # pragma acc parallel oacc-parallel-clause[optseq] new-line
14722 LOC is the location of the #pragma token.
14725 #define OACC_KERNELS_CLAUSE_MASK \
14726 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14727 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14728 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14729 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14730 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14731 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14732 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14733 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14734 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14735 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14736 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14737 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14738 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14739 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14740 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14741 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14742 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14744 #define OACC_PARALLEL_CLAUSE_MASK \
14745 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14746 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14747 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14748 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14749 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14750 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14751 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14752 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14753 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14754 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
14755 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14756 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14757 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14758 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14759 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14760 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14761 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14762 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14763 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14764 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14767 c_parser_oacc_kernels_parallel (location_t loc
, c_parser
*parser
,
14768 enum pragma_kind p_kind
, char *p_name
,
14771 omp_clause_mask mask
;
14772 enum tree_code code
;
14775 case PRAGMA_OACC_KERNELS
:
14776 strcat (p_name
, " kernels");
14777 mask
= OACC_KERNELS_CLAUSE_MASK
;
14778 code
= OACC_KERNELS
;
14780 case PRAGMA_OACC_PARALLEL
:
14781 strcat (p_name
, " parallel");
14782 mask
= OACC_PARALLEL_CLAUSE_MASK
;
14783 code
= OACC_PARALLEL
;
14786 gcc_unreachable ();
14789 if (c_parser_next_token_is (parser
, CPP_NAME
))
14791 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14792 if (strcmp (p
, "loop") == 0)
14794 c_parser_consume_token (parser
);
14795 tree block
= c_begin_omp_parallel ();
14797 c_parser_oacc_loop (loc
, parser
, p_name
, mask
, &clauses
, if_p
);
14798 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14802 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
);
14804 tree block
= c_begin_omp_parallel ();
14805 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14807 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14811 # pragma acc routine oacc-routine-clause[optseq] new-line
14812 function-definition
14814 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
14817 #define OACC_ROUTINE_CLAUSE_MASK \
14818 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14819 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14820 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14821 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
14823 /* Parse an OpenACC routine directive. For named directives, we apply
14824 immediately to the named function. For unnamed ones we then parse
14825 a declaration or definition, which must be for a function. */
14828 c_parser_oacc_routine (c_parser
*parser
, enum pragma_context context
)
14830 gcc_checking_assert (context
== pragma_external
);
14832 oacc_routine_data data
;
14833 data
.error_seen
= false;
14834 data
.fndecl_seen
= false;
14835 data
.clauses
= NULL_TREE
;
14836 data
.loc
= c_parser_peek_token (parser
)->location
;
14838 c_parser_consume_pragma (parser
);
14840 /* Look for optional '( name )'. */
14841 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14843 c_parser_consume_token (parser
); /* '(' */
14845 tree decl
= NULL_TREE
;
14846 c_token
*name_token
= c_parser_peek_token (parser
);
14847 location_t name_loc
= name_token
->location
;
14848 if (name_token
->type
== CPP_NAME
14849 && (name_token
->id_kind
== C_ID_ID
14850 || name_token
->id_kind
== C_ID_TYPENAME
))
14852 decl
= lookup_name (name_token
->value
);
14854 error_at (name_loc
,
14855 "%qE has not been declared", name_token
->value
);
14856 c_parser_consume_token (parser
);
14859 c_parser_error (parser
, "expected function name");
14862 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14864 c_parser_skip_to_pragma_eol (parser
, false);
14869 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
14870 "#pragma acc routine");
14872 if (TREE_CODE (decl
) != FUNCTION_DECL
)
14874 error_at (name_loc
, "%qD does not refer to a function", decl
);
14878 c_finish_oacc_routine (&data
, decl
, false);
14880 else /* No optional '( name )'. */
14883 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
14884 "#pragma acc routine");
14886 /* Emit a helpful diagnostic if there's another pragma following this
14887 one. Also don't allow a static assertion declaration, as in the
14888 following we'll just parse a *single* "declaration or function
14889 definition", and the static assertion counts an one. */
14890 if (c_parser_next_token_is (parser
, CPP_PRAGMA
)
14891 || c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
14893 error_at (data
.loc
,
14894 "%<#pragma acc routine%> not immediately followed by"
14895 " function declaration or definition");
14896 /* ..., and then just keep going. */
14900 /* We only have to consider the pragma_external case here. */
14901 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14902 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
14904 int ext
= disable_extension_diagnostics ();
14906 c_parser_consume_token (parser
);
14907 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14908 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
14909 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14910 NULL
, vNULL
, &data
);
14911 restore_extension_diagnostics (ext
);
14914 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14915 NULL
, vNULL
, &data
);
14919 /* Finalize an OpenACC routine pragma, applying it to FNDECL.
14920 IS_DEFN is true if we're applying it to the definition. */
14923 c_finish_oacc_routine (struct oacc_routine_data
*data
, tree fndecl
,
14926 /* Keep going if we're in error reporting mode. */
14927 if (data
->error_seen
14928 || fndecl
== error_mark_node
)
14931 if (data
->fndecl_seen
)
14933 error_at (data
->loc
,
14934 "%<#pragma acc routine%> not immediately followed by"
14935 " a single function declaration or definition");
14936 data
->error_seen
= true;
14939 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
14941 error_at (data
->loc
,
14942 "%<#pragma acc routine%> not immediately followed by"
14943 " function declaration or definition");
14944 data
->error_seen
= true;
14948 if (oacc_get_fn_attrib (fndecl
))
14950 error_at (data
->loc
,
14951 "%<#pragma acc routine%> already applied to %qD", fndecl
);
14952 data
->error_seen
= true;
14956 if (TREE_USED (fndecl
) || (!is_defn
&& DECL_SAVED_TREE (fndecl
)))
14958 error_at (data
->loc
,
14960 ? G_("%<#pragma acc routine%> must be applied before use")
14961 : G_("%<#pragma acc routine%> must be applied before "
14963 data
->error_seen
= true;
14967 /* Process the routine's dimension clauses. */
14968 tree dims
= oacc_build_routine_dims (data
->clauses
);
14969 oacc_replace_fn_attrib (fndecl
, dims
);
14971 /* Add an "omp declare target" attribute. */
14972 DECL_ATTRIBUTES (fndecl
)
14973 = tree_cons (get_identifier ("omp declare target"),
14974 NULL_TREE
, DECL_ATTRIBUTES (fndecl
));
14976 /* Remember that we've used this "#pragma acc routine". */
14977 data
->fndecl_seen
= true;
14981 # pragma acc update oacc-update-clause[optseq] new-line
14984 #define OACC_UPDATE_CLAUSE_MASK \
14985 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14986 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
14987 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
14988 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14989 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
14990 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14993 c_parser_oacc_update (c_parser
*parser
)
14995 location_t loc
= c_parser_peek_token (parser
)->location
;
14997 c_parser_consume_pragma (parser
);
14999 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
15000 "#pragma acc update");
15001 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
15004 "%<#pragma acc update%> must contain at least one "
15005 "%<device%> or %<host%> or %<self%> clause");
15012 tree stmt
= make_node (OACC_UPDATE
);
15013 TREE_TYPE (stmt
) = void_type_node
;
15014 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
15015 SET_EXPR_LOCATION (stmt
, loc
);
15020 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
15022 LOC is the location of the #pragma token.
15025 #define OACC_WAIT_CLAUSE_MASK \
15026 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
15029 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
15031 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
15033 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
15034 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
15036 strcpy (p_name
, " wait");
15037 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
15038 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
15045 # pragma omp atomic new-line
15049 x binop= expr | x++ | ++x | x-- | --x
15051 +, *, -, /, &, ^, |, <<, >>
15053 where x is an lvalue expression with scalar type.
15056 # pragma omp atomic new-line
15059 # pragma omp atomic read new-line
15062 # pragma omp atomic write new-line
15065 # pragma omp atomic update new-line
15068 # pragma omp atomic capture new-line
15071 # pragma omp atomic capture new-line
15079 expression-stmt | x = x binop expr
15081 v = expression-stmt
15083 { v = x; update-stmt; } | { update-stmt; v = x; }
15087 expression-stmt | x = x binop expr | x = expr binop x
15091 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
15093 where x and v are lvalue expressions with scalar type.
15095 LOC is the location of the #pragma token. */
15098 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
15100 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
15101 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
15102 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
15103 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
15104 struct c_expr expr
;
15106 bool structured_block
= false;
15107 bool swapped
= false;
15108 bool seq_cst
= false;
15111 if (c_parser_next_token_is (parser
, CPP_NAME
))
15113 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15114 if (!strcmp (p
, "seq_cst"))
15117 c_parser_consume_token (parser
);
15118 if (c_parser_next_token_is (parser
, CPP_COMMA
)
15119 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
15120 c_parser_consume_token (parser
);
15123 if (c_parser_next_token_is (parser
, CPP_NAME
))
15125 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15127 if (!strcmp (p
, "read"))
15128 code
= OMP_ATOMIC_READ
;
15129 else if (!strcmp (p
, "write"))
15131 else if (!strcmp (p
, "update"))
15133 else if (!strcmp (p
, "capture"))
15134 code
= OMP_ATOMIC_CAPTURE_NEW
;
15138 c_parser_consume_token (parser
);
15142 if (c_parser_next_token_is (parser
, CPP_COMMA
)
15143 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
15144 c_parser_consume_token (parser
);
15146 if (c_parser_next_token_is (parser
, CPP_NAME
))
15149 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15150 if (!strcmp (p
, "seq_cst"))
15153 c_parser_consume_token (parser
);
15157 c_parser_skip_to_pragma_eol (parser
);
15161 case OMP_ATOMIC_READ
:
15162 case NOP_EXPR
: /* atomic write */
15163 v
= c_parser_cast_expression (parser
, NULL
).value
;
15164 non_lvalue_p
= !lvalue_p (v
);
15165 v
= c_fully_fold (v
, false, NULL
, true);
15166 if (v
== error_mark_node
)
15169 v
= non_lvalue (v
);
15170 loc
= c_parser_peek_token (parser
)->location
;
15171 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15173 if (code
== NOP_EXPR
)
15175 lhs
= c_parser_expression (parser
).value
;
15176 lhs
= c_fully_fold (lhs
, false, NULL
);
15177 if (lhs
== error_mark_node
)
15182 lhs
= c_parser_cast_expression (parser
, NULL
).value
;
15183 non_lvalue_p
= !lvalue_p (lhs
);
15184 lhs
= c_fully_fold (lhs
, false, NULL
, true);
15185 if (lhs
== error_mark_node
)
15188 lhs
= non_lvalue (lhs
);
15190 if (code
== NOP_EXPR
)
15192 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
15200 case OMP_ATOMIC_CAPTURE_NEW
:
15201 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
15203 c_parser_consume_token (parser
);
15204 structured_block
= true;
15208 v
= c_parser_cast_expression (parser
, NULL
).value
;
15209 non_lvalue_p
= !lvalue_p (v
);
15210 v
= c_fully_fold (v
, false, NULL
, true);
15211 if (v
== error_mark_node
)
15214 v
= non_lvalue (v
);
15215 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15223 /* For structured_block case we don't know yet whether
15224 old or new x should be captured. */
15226 eloc
= c_parser_peek_token (parser
)->location
;
15227 expr
= c_parser_cast_expression (parser
, NULL
);
15229 expr
= default_function_array_conversion (eloc
, expr
);
15230 unfolded_lhs
= expr
.value
;
15231 lhs
= c_fully_fold (lhs
, false, NULL
, true);
15233 switch (TREE_CODE (lhs
))
15237 c_parser_skip_to_end_of_block_or_statement (parser
);
15238 if (structured_block
)
15240 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15241 c_parser_consume_token (parser
);
15242 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
15244 c_parser_skip_to_end_of_block_or_statement (parser
);
15245 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15246 c_parser_consume_token (parser
);
15251 case POSTINCREMENT_EXPR
:
15252 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
15253 code
= OMP_ATOMIC_CAPTURE_OLD
;
15255 case PREINCREMENT_EXPR
:
15256 lhs
= TREE_OPERAND (lhs
, 0);
15257 unfolded_lhs
= NULL_TREE
;
15258 opcode
= PLUS_EXPR
;
15259 rhs
= integer_one_node
;
15262 case POSTDECREMENT_EXPR
:
15263 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
15264 code
= OMP_ATOMIC_CAPTURE_OLD
;
15266 case PREDECREMENT_EXPR
:
15267 lhs
= TREE_OPERAND (lhs
, 0);
15268 unfolded_lhs
= NULL_TREE
;
15269 opcode
= MINUS_EXPR
;
15270 rhs
= integer_one_node
;
15273 case COMPOUND_EXPR
:
15274 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
15275 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
15276 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
15277 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
15278 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
15279 (TREE_OPERAND (lhs
, 1), 0), 0)))
15281 /* Undo effects of boolean_increment for post {in,de}crement. */
15282 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
15285 if (TREE_CODE (lhs
) == MODIFY_EXPR
15286 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
15288 /* Undo effects of boolean_increment. */
15289 if (integer_onep (TREE_OPERAND (lhs
, 1)))
15291 /* This is pre or post increment. */
15292 rhs
= TREE_OPERAND (lhs
, 1);
15293 lhs
= TREE_OPERAND (lhs
, 0);
15294 unfolded_lhs
= NULL_TREE
;
15296 if (code
== OMP_ATOMIC_CAPTURE_NEW
15297 && !structured_block
15298 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
15299 code
= OMP_ATOMIC_CAPTURE_OLD
;
15302 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
15303 && TREE_OPERAND (lhs
, 0)
15304 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
15306 /* This is pre or post decrement. */
15307 rhs
= TREE_OPERAND (lhs
, 1);
15308 lhs
= TREE_OPERAND (lhs
, 0);
15309 unfolded_lhs
= NULL_TREE
;
15311 if (code
== OMP_ATOMIC_CAPTURE_NEW
15312 && !structured_block
15313 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
15314 code
= OMP_ATOMIC_CAPTURE_OLD
;
15320 if (!lvalue_p (unfolded_lhs
))
15321 lhs
= non_lvalue (lhs
);
15322 switch (c_parser_peek_token (parser
)->type
)
15325 opcode
= MULT_EXPR
;
15328 opcode
= TRUNC_DIV_EXPR
;
15331 opcode
= PLUS_EXPR
;
15334 opcode
= MINUS_EXPR
;
15336 case CPP_LSHIFT_EQ
:
15337 opcode
= LSHIFT_EXPR
;
15339 case CPP_RSHIFT_EQ
:
15340 opcode
= RSHIFT_EXPR
;
15343 opcode
= BIT_AND_EXPR
;
15346 opcode
= BIT_IOR_EXPR
;
15349 opcode
= BIT_XOR_EXPR
;
15352 c_parser_consume_token (parser
);
15353 eloc
= c_parser_peek_token (parser
)->location
;
15354 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
15356 switch (TREE_CODE (rhs1
))
15359 case TRUNC_DIV_EXPR
:
15368 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
15370 opcode
= TREE_CODE (rhs1
);
15371 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
,
15373 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
,
15377 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
15379 opcode
= TREE_CODE (rhs1
);
15380 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
,
15382 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
,
15384 swapped
= !commutative_tree_code (opcode
);
15393 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
15395 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
15397 code
= OMP_ATOMIC_CAPTURE_OLD
;
15400 expr
= default_function_array_read_conversion (eloc
, expr
);
15401 unfolded_lhs1
= expr
.value
;
15402 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
, true);
15404 c_parser_consume_token (parser
);
15407 if (structured_block
)
15410 expr
= default_function_array_read_conversion (eloc
, expr
);
15411 rhs
= c_fully_fold (expr
.value
, false, NULL
, true);
15416 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
15419 c_parser_error (parser
,
15420 "invalid operator for %<#pragma omp atomic%>");
15424 /* Arrange to pass the location of the assignment operator to
15425 c_finish_omp_atomic. */
15426 loc
= c_parser_peek_token (parser
)->location
;
15427 c_parser_consume_token (parser
);
15428 eloc
= c_parser_peek_token (parser
)->location
;
15429 expr
= c_parser_expression (parser
);
15430 expr
= default_function_array_read_conversion (eloc
, expr
);
15432 rhs
= c_fully_fold (rhs
, false, NULL
, true);
15436 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
15438 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
15440 v
= c_parser_cast_expression (parser
, NULL
).value
;
15441 non_lvalue_p
= !lvalue_p (v
);
15442 v
= c_fully_fold (v
, false, NULL
, true);
15443 if (v
== error_mark_node
)
15446 v
= non_lvalue (v
);
15447 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15449 eloc
= c_parser_peek_token (parser
)->location
;
15450 expr
= c_parser_cast_expression (parser
, NULL
);
15452 expr
= default_function_array_read_conversion (eloc
, expr
);
15453 unfolded_lhs1
= expr
.value
;
15454 lhs1
= c_fully_fold (lhs1
, false, NULL
, true);
15455 if (lhs1
== error_mark_node
)
15457 if (!lvalue_p (unfolded_lhs1
))
15458 lhs1
= non_lvalue (lhs1
);
15460 if (structured_block
)
15462 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15463 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
15466 if (unfolded_lhs
&& unfolded_lhs1
15467 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
15469 error ("%<#pragma omp atomic capture%> uses two different "
15470 "expressions for memory");
15471 stmt
= error_mark_node
;
15474 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
15476 if (stmt
!= error_mark_node
)
15479 if (!structured_block
)
15480 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15485 # pragma omp barrier new-line
15489 c_parser_omp_barrier (c_parser
*parser
)
15491 location_t loc
= c_parser_peek_token (parser
)->location
;
15492 c_parser_consume_pragma (parser
);
15493 c_parser_skip_to_pragma_eol (parser
);
15495 c_finish_omp_barrier (loc
);
15499 # pragma omp critical [(name)] new-line
15503 # pragma omp critical [(name) [hint(expression)]] new-line
15505 LOC is the location of the #pragma itself. */
15507 #define OMP_CRITICAL_CLAUSE_MASK \
15508 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
15511 c_parser_omp_critical (location_t loc
, c_parser
*parser
, bool *if_p
)
15513 tree stmt
, name
= NULL_TREE
, clauses
= NULL_TREE
;
15515 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
15517 c_parser_consume_token (parser
);
15518 if (c_parser_next_token_is (parser
, CPP_NAME
))
15520 name
= c_parser_peek_token (parser
)->value
;
15521 c_parser_consume_token (parser
);
15522 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
15525 c_parser_error (parser
, "expected identifier");
15527 clauses
= c_parser_omp_all_clauses (parser
,
15528 OMP_CRITICAL_CLAUSE_MASK
,
15529 "#pragma omp critical");
15533 if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15534 c_parser_error (parser
, "expected %<(%> or end of line");
15535 c_parser_skip_to_pragma_eol (parser
);
15538 stmt
= c_parser_omp_structured_block (parser
, if_p
);
15539 return c_finish_omp_critical (loc
, stmt
, name
, clauses
);
15543 # pragma omp flush flush-vars[opt] new-line
15546 ( variable-list ) */
15549 c_parser_omp_flush (c_parser
*parser
)
15551 location_t loc
= c_parser_peek_token (parser
)->location
;
15552 c_parser_consume_pragma (parser
);
15553 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
15554 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
15555 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15556 c_parser_error (parser
, "expected %<(%> or end of line");
15557 c_parser_skip_to_pragma_eol (parser
);
15559 c_finish_omp_flush (loc
);
15562 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
15563 The real trick here is to determine the loop control variable early
15564 so that we can push a new decl if necessary to make it private.
15565 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
15569 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
15570 tree clauses
, tree
*cclauses
, bool *if_p
)
15572 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
15573 tree declv
, condv
, incrv
, initv
, ret
= NULL_TREE
;
15574 tree pre_body
= NULL_TREE
, this_pre_body
;
15575 tree ordered_cl
= NULL_TREE
;
15576 bool fail
= false, open_brace_parsed
= false;
15577 int i
, collapse
= 1, ordered
= 0, count
, nbraces
= 0;
15578 location_t for_loc
;
15579 bool tiling
= false;
15580 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
15582 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
15583 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
15584 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
15585 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_TILE
)
15588 collapse
= list_length (OMP_CLAUSE_TILE_LIST (cl
));
15590 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_ORDERED
15591 && OMP_CLAUSE_ORDERED_EXPR (cl
))
15594 ordered
= tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl
));
15597 if (ordered
&& ordered
< collapse
)
15599 error_at (OMP_CLAUSE_LOCATION (ordered_cl
),
15600 "%<ordered%> clause parameter is less than %<collapse%>");
15601 OMP_CLAUSE_ORDERED_EXPR (ordered_cl
)
15602 = build_int_cst (NULL_TREE
, collapse
);
15603 ordered
= collapse
;
15607 for (tree
*pc
= &clauses
; *pc
; )
15608 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_LINEAR
)
15610 error_at (OMP_CLAUSE_LOCATION (*pc
),
15611 "%<linear%> clause may not be specified together "
15612 "with %<ordered%> clause with a parameter");
15613 *pc
= OMP_CLAUSE_CHAIN (*pc
);
15616 pc
= &OMP_CLAUSE_CHAIN (*pc
);
15619 gcc_assert (tiling
|| (collapse
>= 1 && ordered
>= 0));
15620 count
= ordered
? ordered
: collapse
;
15622 declv
= make_tree_vec (count
);
15623 initv
= make_tree_vec (count
);
15624 condv
= make_tree_vec (count
);
15625 incrv
= make_tree_vec (count
);
15627 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
15629 c_parser_error (parser
, "for statement expected");
15632 for_loc
= c_parser_peek_token (parser
)->location
;
15633 c_parser_consume_token (parser
);
15635 for (i
= 0; i
< count
; i
++)
15637 int bracecount
= 0;
15639 matching_parens parens
;
15640 if (!parens
.require_open (parser
))
15643 /* Parse the initialization declaration or expression. */
15644 if (c_parser_next_tokens_start_declaration (parser
))
15647 vec_safe_push (for_block
, c_begin_compound_stmt (true));
15648 this_pre_body
= push_stmt_list ();
15649 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
15653 this_pre_body
= pop_stmt_list (this_pre_body
);
15657 pre_body
= push_stmt_list ();
15659 add_stmt (this_pre_body
);
15660 pre_body
= pop_stmt_list (pre_body
);
15663 pre_body
= this_pre_body
;
15665 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
15668 if (DECL_INITIAL (decl
) == error_mark_node
)
15669 decl
= error_mark_node
;
15672 else if (c_parser_next_token_is (parser
, CPP_NAME
)
15673 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
15675 struct c_expr decl_exp
;
15676 struct c_expr init_exp
;
15677 location_t init_loc
;
15679 decl_exp
= c_parser_postfix_expression (parser
);
15680 decl
= decl_exp
.value
;
15682 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
15684 init_loc
= c_parser_peek_token (parser
)->location
;
15685 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
15686 init_exp
= default_function_array_read_conversion (init_loc
,
15688 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
15689 NOP_EXPR
, init_loc
, init_exp
.value
,
15690 init_exp
.original_type
);
15691 init
= c_process_expr_stmt (init_loc
, init
);
15693 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15698 c_parser_error (parser
,
15699 "expected iteration declaration or initialization");
15700 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
15706 /* Parse the loop condition. */
15708 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
15710 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
15711 struct c_expr cond_expr
15712 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
15714 cond
= cond_expr
.value
;
15715 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
15716 if (COMPARISON_CLASS_P (cond
))
15718 tree op0
= TREE_OPERAND (cond
, 0), op1
= TREE_OPERAND (cond
, 1);
15719 op0
= c_fully_fold (op0
, false, NULL
);
15720 op1
= c_fully_fold (op1
, false, NULL
);
15721 TREE_OPERAND (cond
, 0) = op0
;
15722 TREE_OPERAND (cond
, 1) = op1
;
15724 switch (cond_expr
.original_code
)
15732 /* Can't be cond = error_mark_node, because we want to preserve
15733 the location until c_finish_omp_for. */
15734 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
15737 protected_set_expr_location (cond
, cond_loc
);
15739 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15741 /* Parse the increment expression. */
15743 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
15745 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
15747 incr
= c_process_expr_stmt (incr_loc
,
15748 c_parser_expression (parser
).value
);
15750 parens
.skip_until_found_close (parser
);
15752 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
15756 TREE_VEC_ELT (declv
, i
) = decl
;
15757 TREE_VEC_ELT (initv
, i
) = init
;
15758 TREE_VEC_ELT (condv
, i
) = cond
;
15759 TREE_VEC_ELT (incrv
, i
) = incr
;
15763 if (i
== count
- 1)
15766 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
15767 in between the collapsed for loops to be still considered perfectly
15768 nested. Hopefully the final version clarifies this.
15769 For now handle (multiple) {'s and empty statements. */
15772 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
15774 c_parser_consume_token (parser
);
15777 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
15779 c_parser_consume_token (parser
);
15782 else if (bracecount
15783 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15784 c_parser_consume_token (parser
);
15787 c_parser_error (parser
, "not enough perfectly nested loops");
15790 open_brace_parsed
= true;
15800 nbraces
+= bracecount
;
15806 save_break
= c_break_label
;
15807 c_break_label
= size_one_node
;
15808 save_cont
= c_cont_label
;
15809 c_cont_label
= NULL_TREE
;
15810 body
= push_stmt_list ();
15812 if (open_brace_parsed
)
15814 location_t here
= c_parser_peek_token (parser
)->location
;
15815 stmt
= c_begin_compound_stmt (true);
15816 c_parser_compound_statement_nostart (parser
);
15817 add_stmt (c_end_compound_stmt (here
, stmt
, true));
15820 add_stmt (c_parser_c99_block_statement (parser
, if_p
));
15823 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
15824 SET_EXPR_LOCATION (t
, loc
);
15828 body
= pop_stmt_list (body
);
15829 c_break_label
= save_break
;
15830 c_cont_label
= save_cont
;
15834 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15836 c_parser_consume_token (parser
);
15839 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15840 c_parser_consume_token (parser
);
15843 c_parser_error (parser
, "collapsed loops not perfectly nested");
15846 location_t here
= c_parser_peek_token (parser
)->location
;
15847 stmt
= c_begin_compound_stmt (true);
15849 c_parser_compound_statement_nostart (parser
);
15850 body
= c_end_compound_stmt (here
, stmt
, true);
15857 /* Only bother calling c_finish_omp_for if we haven't already generated
15858 an error from the initialization parsing. */
15861 stmt
= c_finish_omp_for (loc
, code
, declv
, NULL
, initv
, condv
,
15862 incrv
, body
, pre_body
);
15864 /* Check for iterators appearing in lb, b or incr expressions. */
15865 if (stmt
&& !c_omp_check_loop_iv (stmt
, declv
, NULL
))
15872 if (cclauses
!= NULL
15873 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
15876 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
15877 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
15878 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
15879 c
= &OMP_CLAUSE_CHAIN (*c
);
15882 for (i
= 0; i
< count
; i
++)
15883 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
15886 c
= &OMP_CLAUSE_CHAIN (*c
);
15887 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
15890 "iteration variable %qD should not be firstprivate",
15891 OMP_CLAUSE_DECL (*c
));
15892 *c
= OMP_CLAUSE_CHAIN (*c
);
15896 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
15898 *c
= OMP_CLAUSE_CHAIN (*c
);
15899 if (code
== OMP_SIMD
)
15901 OMP_CLAUSE_CHAIN (l
)
15902 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15903 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
15907 OMP_CLAUSE_CHAIN (l
) = clauses
;
15913 OMP_FOR_CLAUSES (stmt
) = clauses
;
15918 while (!for_block
->is_empty ())
15920 /* FIXME diagnostics: LOC below should be the actual location of
15921 this particular for block. We need to build a list of
15922 locations to go along with FOR_BLOCK. */
15923 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
15926 release_tree_vector (for_block
);
15930 /* Helper function for OpenMP parsing, split clauses and call
15931 finish_omp_clauses on each of the set of clauses afterwards. */
15934 omp_split_clauses (location_t loc
, enum tree_code code
,
15935 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
15938 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
15939 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
15941 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
], C_ORT_OMP
);
15945 #pragma omp simd simd-clause[optseq] new-line
15948 LOC is the location of the #pragma token.
15951 #define OMP_SIMD_CLAUSE_MASK \
15952 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
15953 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
15954 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15955 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
15956 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15957 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15958 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15959 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15962 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
15963 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15966 tree block
, clauses
, ret
;
15968 strcat (p_name
, " simd");
15969 mask
|= OMP_SIMD_CLAUSE_MASK
;
15971 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15974 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
15975 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
15976 tree c
= omp_find_clause (cclauses
[C_OMP_CLAUSE_SPLIT_FOR
],
15977 OMP_CLAUSE_ORDERED
);
15978 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
15980 error_at (OMP_CLAUSE_LOCATION (c
),
15981 "%<ordered%> clause with parameter may not be specified "
15982 "on %qs construct", p_name
);
15983 OMP_CLAUSE_ORDERED_EXPR (c
) = NULL_TREE
;
15987 block
= c_begin_compound_stmt (true);
15988 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
, if_p
);
15989 block
= c_end_compound_stmt (loc
, block
, true);
15996 #pragma omp for for-clause[optseq] new-line
16000 #pragma omp for simd for-simd-clause[optseq] new-line
16003 LOC is the location of the #pragma token.
16006 #define OMP_FOR_CLAUSE_MASK \
16007 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16008 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16009 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16010 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
16011 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16012 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
16013 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
16014 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
16015 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16018 c_parser_omp_for (location_t loc
, c_parser
*parser
,
16019 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16022 tree block
, clauses
, ret
;
16024 strcat (p_name
, " for");
16025 mask
|= OMP_FOR_CLAUSE_MASK
;
16026 /* parallel for{, simd} disallows nowait clause, but for
16027 target {teams distribute ,}parallel for{, simd} it should be accepted. */
16028 if (cclauses
&& (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) == 0)
16029 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
16030 /* Composite distribute parallel for{, simd} disallows ordered clause. */
16031 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
16032 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
16034 if (c_parser_next_token_is (parser
, CPP_NAME
))
16036 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16038 if (strcmp (p
, "simd") == 0)
16040 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16041 if (cclauses
== NULL
)
16042 cclauses
= cclauses_buf
;
16044 c_parser_consume_token (parser
);
16045 if (!flag_openmp
) /* flag_openmp_simd */
16046 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16048 block
= c_begin_compound_stmt (true);
16049 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
16050 block
= c_end_compound_stmt (loc
, block
, true);
16051 if (ret
== NULL_TREE
)
16053 ret
= make_node (OMP_FOR
);
16054 TREE_TYPE (ret
) = void_type_node
;
16055 OMP_FOR_BODY (ret
) = block
;
16056 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
16057 SET_EXPR_LOCATION (ret
, loc
);
16062 if (!flag_openmp
) /* flag_openmp_simd */
16064 c_parser_skip_to_pragma_eol (parser
, false);
16068 /* Composite distribute parallel for disallows linear clause. */
16069 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
16070 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINEAR
);
16072 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16075 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
16076 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
16079 block
= c_begin_compound_stmt (true);
16080 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
, if_p
);
16081 block
= c_end_compound_stmt (loc
, block
, true);
16088 # pragma omp master new-line
16091 LOC is the location of the #pragma token.
16095 c_parser_omp_master (location_t loc
, c_parser
*parser
, bool *if_p
)
16097 c_parser_skip_to_pragma_eol (parser
);
16098 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
,
16103 # pragma omp ordered new-line
16107 # pragma omp ordered ordered-clauses new-line
16110 # pragma omp ordered depend-clauses new-line */
16112 #define OMP_ORDERED_CLAUSE_MASK \
16113 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
16114 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
16116 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
16117 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
16120 c_parser_omp_ordered (c_parser
*parser
, enum pragma_context context
,
16123 location_t loc
= c_parser_peek_token (parser
)->location
;
16124 c_parser_consume_pragma (parser
);
16126 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
16128 c_parser_error (parser
, "expected declaration specifiers");
16129 c_parser_skip_to_pragma_eol (parser
, false);
16133 if (c_parser_next_token_is (parser
, CPP_NAME
))
16135 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16137 if (!strcmp ("depend", p
))
16139 if (!flag_openmp
) /* flag_openmp_simd */
16141 c_parser_skip_to_pragma_eol (parser
, false);
16144 if (context
== pragma_stmt
)
16147 "%<#pragma omp ordered%> with %<depend%> clause may "
16148 "only be used in compound statements");
16149 c_parser_skip_to_pragma_eol (parser
, false);
16154 = c_parser_omp_all_clauses (parser
,
16155 OMP_ORDERED_DEPEND_CLAUSE_MASK
,
16156 "#pragma omp ordered");
16157 c_finish_omp_ordered (loc
, clauses
, NULL_TREE
);
16162 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_ORDERED_CLAUSE_MASK
,
16163 "#pragma omp ordered");
16165 if (!flag_openmp
/* flag_openmp_simd */
16166 && omp_find_clause (clauses
, OMP_CLAUSE_SIMD
) == NULL_TREE
)
16169 c_finish_omp_ordered (loc
, clauses
,
16170 c_parser_omp_structured_block (parser
, if_p
));
16177 { section-sequence }
16180 section-directive[opt] structured-block
16181 section-sequence section-directive structured-block
16183 SECTIONS_LOC is the location of the #pragma omp sections. */
16186 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
16188 tree stmt
, substmt
;
16189 bool error_suppress
= false;
16192 loc
= c_parser_peek_token (parser
)->location
;
16193 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
16195 /* Avoid skipping until the end of the block. */
16196 parser
->error
= false;
16200 stmt
= push_stmt_list ();
16202 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
16204 substmt
= c_parser_omp_structured_block (parser
, NULL
);
16205 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
16206 SET_EXPR_LOCATION (substmt
, loc
);
16207 add_stmt (substmt
);
16212 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
16214 if (c_parser_next_token_is (parser
, CPP_EOF
))
16217 loc
= c_parser_peek_token (parser
)->location
;
16218 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
16220 c_parser_consume_pragma (parser
);
16221 c_parser_skip_to_pragma_eol (parser
);
16222 error_suppress
= false;
16224 else if (!error_suppress
)
16226 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
16227 error_suppress
= true;
16230 substmt
= c_parser_omp_structured_block (parser
, NULL
);
16231 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
16232 SET_EXPR_LOCATION (substmt
, loc
);
16233 add_stmt (substmt
);
16235 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
16236 "expected %<#pragma omp section%> or %<}%>");
16238 substmt
= pop_stmt_list (stmt
);
16240 stmt
= make_node (OMP_SECTIONS
);
16241 SET_EXPR_LOCATION (stmt
, sections_loc
);
16242 TREE_TYPE (stmt
) = void_type_node
;
16243 OMP_SECTIONS_BODY (stmt
) = substmt
;
16245 return add_stmt (stmt
);
16249 # pragma omp sections sections-clause[optseq] newline
16252 LOC is the location of the #pragma token.
16255 #define OMP_SECTIONS_CLAUSE_MASK \
16256 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16257 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16258 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16259 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16260 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16263 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
16264 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
16266 tree block
, clauses
, ret
;
16268 strcat (p_name
, " sections");
16269 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
16271 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
16273 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16276 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
16277 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
16280 block
= c_begin_compound_stmt (true);
16281 ret
= c_parser_omp_sections_scope (loc
, parser
);
16283 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
16284 block
= c_end_compound_stmt (loc
, block
, true);
16291 # pragma omp parallel parallel-clause[optseq] new-line
16293 # pragma omp parallel for parallel-for-clause[optseq] new-line
16295 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
16299 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
16302 LOC is the location of the #pragma token.
16305 #define OMP_PARALLEL_CLAUSE_MASK \
16306 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16307 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16308 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16309 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
16310 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16311 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
16312 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16313 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
16314 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
16317 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
16318 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16321 tree stmt
, clauses
, block
;
16323 strcat (p_name
, " parallel");
16324 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
16325 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
16326 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) != 0
16327 && (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) == 0)
16328 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_COPYIN
);
16330 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
16332 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16333 if (cclauses
== NULL
)
16334 cclauses
= cclauses_buf
;
16336 c_parser_consume_token (parser
);
16337 if (!flag_openmp
) /* flag_openmp_simd */
16338 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
16339 block
= c_begin_omp_parallel ();
16340 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
16342 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
16344 if (ret
== NULL_TREE
)
16346 OMP_PARALLEL_COMBINED (stmt
) = 1;
16349 /* When combined with distribute, parallel has to be followed by for.
16350 #pragma omp target parallel is allowed though. */
16352 && (mask
& (OMP_CLAUSE_MASK_1
16353 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
16355 error_at (loc
, "expected %<for%> after %qs", p_name
);
16356 c_parser_skip_to_pragma_eol (parser
);
16359 else if (!flag_openmp
) /* flag_openmp_simd */
16361 c_parser_skip_to_pragma_eol (parser
, false);
16364 else if (cclauses
== NULL
&& c_parser_next_token_is (parser
, CPP_NAME
))
16366 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16367 if (strcmp (p
, "sections") == 0)
16369 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16370 if (cclauses
== NULL
)
16371 cclauses
= cclauses_buf
;
16373 c_parser_consume_token (parser
);
16374 block
= c_begin_omp_parallel ();
16375 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
16376 stmt
= c_finish_omp_parallel (loc
,
16377 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
16379 OMP_PARALLEL_COMBINED (stmt
) = 1;
16384 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16387 omp_split_clauses (loc
, OMP_PARALLEL
, mask
, clauses
, cclauses
);
16388 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
16391 block
= c_begin_omp_parallel ();
16392 c_parser_statement (parser
, if_p
);
16393 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
16399 # pragma omp single single-clause[optseq] new-line
16402 LOC is the location of the #pragma.
16405 #define OMP_SINGLE_CLAUSE_MASK \
16406 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16407 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16408 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
16409 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16412 c_parser_omp_single (location_t loc
, c_parser
*parser
, bool *if_p
)
16414 tree stmt
= make_node (OMP_SINGLE
);
16415 SET_EXPR_LOCATION (stmt
, loc
);
16416 TREE_TYPE (stmt
) = void_type_node
;
16418 OMP_SINGLE_CLAUSES (stmt
)
16419 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
16420 "#pragma omp single");
16421 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
16423 return add_stmt (stmt
);
16427 # pragma omp task task-clause[optseq] new-line
16429 LOC is the location of the #pragma.
16432 #define OMP_TASK_CLAUSE_MASK \
16433 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16434 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
16435 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
16436 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16437 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16438 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16439 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
16440 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
16441 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16442 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
16445 c_parser_omp_task (location_t loc
, c_parser
*parser
, bool *if_p
)
16447 tree clauses
, block
;
16449 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
16450 "#pragma omp task");
16452 block
= c_begin_omp_task ();
16453 c_parser_statement (parser
, if_p
);
16454 return c_finish_omp_task (loc
, clauses
, block
);
16458 # pragma omp taskwait new-line
16462 c_parser_omp_taskwait (c_parser
*parser
)
16464 location_t loc
= c_parser_peek_token (parser
)->location
;
16465 c_parser_consume_pragma (parser
);
16466 c_parser_skip_to_pragma_eol (parser
);
16468 c_finish_omp_taskwait (loc
);
16472 # pragma omp taskyield new-line
16476 c_parser_omp_taskyield (c_parser
*parser
)
16478 location_t loc
= c_parser_peek_token (parser
)->location
;
16479 c_parser_consume_pragma (parser
);
16480 c_parser_skip_to_pragma_eol (parser
);
16482 c_finish_omp_taskyield (loc
);
16486 # pragma omp taskgroup new-line
16490 c_parser_omp_taskgroup (c_parser
*parser
, bool *if_p
)
16492 location_t loc
= c_parser_peek_token (parser
)->location
;
16493 c_parser_skip_to_pragma_eol (parser
);
16494 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
,
16499 # pragma omp cancel cancel-clause[optseq] new-line
16501 LOC is the location of the #pragma.
16504 #define OMP_CANCEL_CLAUSE_MASK \
16505 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
16506 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
16507 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
16508 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
16509 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
16512 c_parser_omp_cancel (c_parser
*parser
)
16514 location_t loc
= c_parser_peek_token (parser
)->location
;
16516 c_parser_consume_pragma (parser
);
16517 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
16518 "#pragma omp cancel");
16520 c_finish_omp_cancel (loc
, clauses
);
16524 # pragma omp cancellation point cancelpt-clause[optseq] new-line
16526 LOC is the location of the #pragma.
16529 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
16530 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
16531 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
16532 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
16533 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
16536 c_parser_omp_cancellation_point (c_parser
*parser
, enum pragma_context context
)
16538 location_t loc
= c_parser_peek_token (parser
)->location
;
16540 bool point_seen
= false;
16542 c_parser_consume_pragma (parser
);
16543 if (c_parser_next_token_is (parser
, CPP_NAME
))
16545 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16546 if (strcmp (p
, "point") == 0)
16548 c_parser_consume_token (parser
);
16554 c_parser_error (parser
, "expected %<point%>");
16555 c_parser_skip_to_pragma_eol (parser
);
16559 if (context
!= pragma_compound
)
16561 if (context
== pragma_stmt
)
16563 "%<#pragma %s%> may only be used in compound statements",
16564 "omp cancellation point");
16566 c_parser_error (parser
, "expected declaration specifiers");
16567 c_parser_skip_to_pragma_eol (parser
, false);
16572 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
16573 "#pragma omp cancellation point");
16575 c_finish_omp_cancellation_point (loc
, clauses
);
16579 #pragma omp distribute distribute-clause[optseq] new-line
16582 #define OMP_DISTRIBUTE_CLAUSE_MASK \
16583 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16584 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16585 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16586 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
16587 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
16590 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
16591 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16594 tree clauses
, block
, ret
;
16596 strcat (p_name
, " distribute");
16597 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
16599 if (c_parser_next_token_is (parser
, CPP_NAME
))
16601 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16603 bool parallel
= false;
16605 if (strcmp (p
, "simd") == 0)
16608 parallel
= strcmp (p
, "parallel") == 0;
16609 if (parallel
|| simd
)
16611 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16612 if (cclauses
== NULL
)
16613 cclauses
= cclauses_buf
;
16614 c_parser_consume_token (parser
);
16615 if (!flag_openmp
) /* flag_openmp_simd */
16618 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16621 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
16624 block
= c_begin_compound_stmt (true);
16626 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16629 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
,
16631 block
= c_end_compound_stmt (loc
, block
, true);
16634 ret
= make_node (OMP_DISTRIBUTE
);
16635 TREE_TYPE (ret
) = void_type_node
;
16636 OMP_FOR_BODY (ret
) = block
;
16637 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
16638 SET_EXPR_LOCATION (ret
, loc
);
16643 if (!flag_openmp
) /* flag_openmp_simd */
16645 c_parser_skip_to_pragma_eol (parser
, false);
16649 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16652 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
16653 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
16656 block
= c_begin_compound_stmt (true);
16657 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
,
16659 block
= c_end_compound_stmt (loc
, block
, true);
16666 # pragma omp teams teams-clause[optseq] new-line
16667 structured-block */
16669 #define OMP_TEAMS_CLAUSE_MASK \
16670 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16671 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16672 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16673 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16674 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
16675 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
16676 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
16679 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
16680 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16683 tree clauses
, block
, ret
;
16685 strcat (p_name
, " teams");
16686 mask
|= OMP_TEAMS_CLAUSE_MASK
;
16688 if (c_parser_next_token_is (parser
, CPP_NAME
))
16690 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16691 if (strcmp (p
, "distribute") == 0)
16693 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16694 if (cclauses
== NULL
)
16695 cclauses
= cclauses_buf
;
16697 c_parser_consume_token (parser
);
16698 if (!flag_openmp
) /* flag_openmp_simd */
16699 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
,
16701 block
= c_begin_compound_stmt (true);
16702 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
,
16704 block
= c_end_compound_stmt (loc
, block
, true);
16707 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16708 ret
= make_node (OMP_TEAMS
);
16709 TREE_TYPE (ret
) = void_type_node
;
16710 OMP_TEAMS_CLAUSES (ret
) = clauses
;
16711 OMP_TEAMS_BODY (ret
) = block
;
16712 OMP_TEAMS_COMBINED (ret
) = 1;
16713 return add_stmt (ret
);
16716 if (!flag_openmp
) /* flag_openmp_simd */
16718 c_parser_skip_to_pragma_eol (parser
, false);
16722 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16725 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
16726 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16729 tree stmt
= make_node (OMP_TEAMS
);
16730 TREE_TYPE (stmt
) = void_type_node
;
16731 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
16732 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
16734 return add_stmt (stmt
);
16738 # pragma omp target data target-data-clause[optseq] new-line
16739 structured-block */
16741 #define OMP_TARGET_DATA_CLAUSE_MASK \
16742 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16743 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16744 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16745 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
16748 c_parser_omp_target_data (location_t loc
, c_parser
*parser
, bool *if_p
)
16751 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
16752 "#pragma omp target data");
16754 for (tree
*pc
= &clauses
; *pc
;)
16756 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16757 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16760 case GOMP_MAP_ALWAYS_TO
:
16761 case GOMP_MAP_FROM
:
16762 case GOMP_MAP_ALWAYS_FROM
:
16763 case GOMP_MAP_TOFROM
:
16764 case GOMP_MAP_ALWAYS_TOFROM
:
16765 case GOMP_MAP_ALLOC
:
16768 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16769 case GOMP_MAP_ALWAYS_POINTER
:
16773 error_at (OMP_CLAUSE_LOCATION (*pc
),
16774 "%<#pragma omp target data%> with map-type other "
16775 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16776 "on %<map%> clause");
16777 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16780 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16787 "%<#pragma omp target data%> must contain at least "
16788 "one %<map%> clause");
16792 tree stmt
= make_node (OMP_TARGET_DATA
);
16793 TREE_TYPE (stmt
) = void_type_node
;
16794 OMP_TARGET_DATA_CLAUSES (stmt
) = clauses
;
16795 keep_next_level ();
16796 tree block
= c_begin_compound_stmt (true);
16797 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
16798 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
16800 SET_EXPR_LOCATION (stmt
, loc
);
16801 return add_stmt (stmt
);
16805 # pragma omp target update target-update-clause[optseq] new-line */
16807 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
16808 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
16809 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16810 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16811 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16812 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16813 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16816 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
16817 enum pragma_context context
)
16819 if (context
== pragma_stmt
)
16821 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
16822 "omp target update");
16823 c_parser_skip_to_pragma_eol (parser
, false);
16828 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
16829 "#pragma omp target update");
16830 if (omp_find_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
16831 && omp_find_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
16834 "%<#pragma omp target update%> must contain at least one "
16835 "%<from%> or %<to%> clauses");
16839 tree stmt
= make_node (OMP_TARGET_UPDATE
);
16840 TREE_TYPE (stmt
) = void_type_node
;
16841 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
16842 SET_EXPR_LOCATION (stmt
, loc
);
16848 # pragma omp target enter data target-data-clause[optseq] new-line */
16850 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
16851 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16852 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16853 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16854 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16855 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16858 c_parser_omp_target_enter_data (location_t loc
, c_parser
*parser
,
16859 enum pragma_context context
)
16861 bool data_seen
= false;
16862 if (c_parser_next_token_is (parser
, CPP_NAME
))
16864 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16865 if (strcmp (p
, "data") == 0)
16867 c_parser_consume_token (parser
);
16873 c_parser_error (parser
, "expected %<data%>");
16874 c_parser_skip_to_pragma_eol (parser
);
16878 if (context
== pragma_stmt
)
16880 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
16881 "omp target enter data");
16882 c_parser_skip_to_pragma_eol (parser
, false);
16887 = c_parser_omp_all_clauses (parser
, OMP_TARGET_ENTER_DATA_CLAUSE_MASK
,
16888 "#pragma omp target enter data");
16890 for (tree
*pc
= &clauses
; *pc
;)
16892 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16893 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16896 case GOMP_MAP_ALWAYS_TO
:
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 enter data%> with map-type other "
16907 "than %<to%> or %<alloc%> on %<map%> clause");
16908 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16911 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16918 "%<#pragma omp target enter data%> must contain at least "
16919 "one %<map%> clause");
16923 tree stmt
= make_node (OMP_TARGET_ENTER_DATA
);
16924 TREE_TYPE (stmt
) = void_type_node
;
16925 OMP_TARGET_ENTER_DATA_CLAUSES (stmt
) = clauses
;
16926 SET_EXPR_LOCATION (stmt
, loc
);
16932 # pragma omp target exit data target-data-clause[optseq] new-line */
16934 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
16935 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16936 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16937 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16938 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16939 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16942 c_parser_omp_target_exit_data (location_t loc
, c_parser
*parser
,
16943 enum pragma_context context
)
16945 bool data_seen
= false;
16946 if (c_parser_next_token_is (parser
, CPP_NAME
))
16948 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16949 if (strcmp (p
, "data") == 0)
16951 c_parser_consume_token (parser
);
16957 c_parser_error (parser
, "expected %<data%>");
16958 c_parser_skip_to_pragma_eol (parser
);
16962 if (context
== pragma_stmt
)
16964 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
16965 "omp target exit data");
16966 c_parser_skip_to_pragma_eol (parser
, false);
16971 = c_parser_omp_all_clauses (parser
, OMP_TARGET_EXIT_DATA_CLAUSE_MASK
,
16972 "#pragma omp target exit data");
16975 for (tree
*pc
= &clauses
; *pc
;)
16977 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16978 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16980 case GOMP_MAP_FROM
:
16981 case GOMP_MAP_ALWAYS_FROM
:
16982 case GOMP_MAP_RELEASE
:
16983 case GOMP_MAP_DELETE
:
16986 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16987 case GOMP_MAP_ALWAYS_POINTER
:
16991 error_at (OMP_CLAUSE_LOCATION (*pc
),
16992 "%<#pragma omp target exit data%> with map-type other "
16993 "than %<from%>, %<release%> or %<delete%> on %<map%>"
16995 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16998 pc
= &OMP_CLAUSE_CHAIN (*pc
);
17005 "%<#pragma omp target exit data%> must contain at least one "
17010 tree stmt
= make_node (OMP_TARGET_EXIT_DATA
);
17011 TREE_TYPE (stmt
) = void_type_node
;
17012 OMP_TARGET_EXIT_DATA_CLAUSES (stmt
) = clauses
;
17013 SET_EXPR_LOCATION (stmt
, loc
);
17019 # pragma omp target target-clause[optseq] new-line
17020 structured-block */
17022 #define OMP_TARGET_CLAUSE_MASK \
17023 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
17024 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
17025 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17026 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
17027 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
17028 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17029 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17030 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
17031 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
17034 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
17036 location_t loc
= c_parser_peek_token (parser
)->location
;
17037 c_parser_consume_pragma (parser
);
17038 tree
*pc
= NULL
, stmt
, block
;
17040 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
17042 c_parser_error (parser
, "expected declaration specifiers");
17043 c_parser_skip_to_pragma_eol (parser
);
17047 if (c_parser_next_token_is (parser
, CPP_NAME
))
17049 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17050 enum tree_code ccode
= ERROR_MARK
;
17052 if (strcmp (p
, "teams") == 0)
17054 else if (strcmp (p
, "parallel") == 0)
17055 ccode
= OMP_PARALLEL
;
17056 else if (strcmp (p
, "simd") == 0)
17058 if (ccode
!= ERROR_MARK
)
17060 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
17061 char p_name
[sizeof ("#pragma omp target teams distribute "
17062 "parallel for simd")];
17064 c_parser_consume_token (parser
);
17065 strcpy (p_name
, "#pragma omp target");
17066 if (!flag_openmp
) /* flag_openmp_simd */
17072 stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
17073 OMP_TARGET_CLAUSE_MASK
,
17077 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
,
17078 OMP_TARGET_CLAUSE_MASK
,
17082 stmt
= c_parser_omp_simd (loc
, parser
, p_name
,
17083 OMP_TARGET_CLAUSE_MASK
,
17087 gcc_unreachable ();
17089 return stmt
!= NULL_TREE
;
17091 keep_next_level ();
17092 tree block
= c_begin_compound_stmt (true), ret
;
17096 ret
= c_parser_omp_teams (loc
, parser
, p_name
,
17097 OMP_TARGET_CLAUSE_MASK
, cclauses
,
17101 ret
= c_parser_omp_parallel (loc
, parser
, p_name
,
17102 OMP_TARGET_CLAUSE_MASK
, cclauses
,
17106 ret
= c_parser_omp_simd (loc
, parser
, p_name
,
17107 OMP_TARGET_CLAUSE_MASK
, cclauses
,
17111 gcc_unreachable ();
17113 block
= c_end_compound_stmt (loc
, block
, true);
17114 if (ret
== NULL_TREE
)
17116 if (ccode
== OMP_TEAMS
)
17118 /* For combined target teams, ensure the num_teams and
17119 thread_limit clause expressions are evaluated on the host,
17120 before entering the target construct. */
17122 for (c
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
17123 c
; c
= OMP_CLAUSE_CHAIN (c
))
17124 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
17125 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
17126 && TREE_CODE (OMP_CLAUSE_OPERAND (c
, 0)) != INTEGER_CST
)
17128 tree expr
= OMP_CLAUSE_OPERAND (c
, 0);
17129 tree tmp
= create_tmp_var_raw (TREE_TYPE (expr
));
17130 expr
= build4 (TARGET_EXPR
, TREE_TYPE (expr
), tmp
,
17131 expr
, NULL_TREE
, NULL_TREE
);
17133 OMP_CLAUSE_OPERAND (c
, 0) = expr
;
17134 tree tc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
17135 OMP_CLAUSE_FIRSTPRIVATE
);
17136 OMP_CLAUSE_DECL (tc
) = tmp
;
17137 OMP_CLAUSE_CHAIN (tc
)
17138 = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
17139 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = tc
;
17142 tree stmt
= make_node (OMP_TARGET
);
17143 TREE_TYPE (stmt
) = void_type_node
;
17144 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
17145 OMP_TARGET_BODY (stmt
) = block
;
17146 OMP_TARGET_COMBINED (stmt
) = 1;
17148 pc
= &OMP_TARGET_CLAUSES (stmt
);
17149 goto check_clauses
;
17151 else if (!flag_openmp
) /* flag_openmp_simd */
17153 c_parser_skip_to_pragma_eol (parser
, false);
17156 else if (strcmp (p
, "data") == 0)
17158 c_parser_consume_token (parser
);
17159 c_parser_omp_target_data (loc
, parser
, if_p
);
17162 else if (strcmp (p
, "enter") == 0)
17164 c_parser_consume_token (parser
);
17165 c_parser_omp_target_enter_data (loc
, parser
, context
);
17168 else if (strcmp (p
, "exit") == 0)
17170 c_parser_consume_token (parser
);
17171 c_parser_omp_target_exit_data (loc
, parser
, context
);
17174 else if (strcmp (p
, "update") == 0)
17176 c_parser_consume_token (parser
);
17177 return c_parser_omp_target_update (loc
, parser
, context
);
17180 if (!flag_openmp
) /* flag_openmp_simd */
17182 c_parser_skip_to_pragma_eol (parser
, false);
17186 stmt
= make_node (OMP_TARGET
);
17187 TREE_TYPE (stmt
) = void_type_node
;
17189 OMP_TARGET_CLAUSES (stmt
)
17190 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
17191 "#pragma omp target");
17192 pc
= &OMP_TARGET_CLAUSES (stmt
);
17193 keep_next_level ();
17194 block
= c_begin_compound_stmt (true);
17195 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
17196 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
17198 SET_EXPR_LOCATION (stmt
, loc
);
17204 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
17205 switch (OMP_CLAUSE_MAP_KIND (*pc
))
17208 case GOMP_MAP_ALWAYS_TO
:
17209 case GOMP_MAP_FROM
:
17210 case GOMP_MAP_ALWAYS_FROM
:
17211 case GOMP_MAP_TOFROM
:
17212 case GOMP_MAP_ALWAYS_TOFROM
:
17213 case GOMP_MAP_ALLOC
:
17214 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
17215 case GOMP_MAP_ALWAYS_POINTER
:
17218 error_at (OMP_CLAUSE_LOCATION (*pc
),
17219 "%<#pragma omp target%> with map-type other "
17220 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
17221 "on %<map%> clause");
17222 *pc
= OMP_CLAUSE_CHAIN (*pc
);
17225 pc
= &OMP_CLAUSE_CHAIN (*pc
);
17231 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
17233 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
17234 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
17235 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
17236 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
17237 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
17238 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
17239 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
17242 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
17244 auto_vec
<c_token
> clauses
;
17245 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17247 c_token
*token
= c_parser_peek_token (parser
);
17248 if (token
->type
== CPP_EOF
)
17250 c_parser_skip_to_pragma_eol (parser
);
17253 clauses
.safe_push (*token
);
17254 c_parser_consume_token (parser
);
17256 clauses
.safe_push (*c_parser_peek_token (parser
));
17257 c_parser_skip_to_pragma_eol (parser
);
17259 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
17261 if (c_parser_peek_token (parser
)->pragma_kind
17262 != PRAGMA_OMP_DECLARE
17263 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
17264 || strcmp (IDENTIFIER_POINTER
17265 (c_parser_peek_2nd_token (parser
)->value
),
17268 c_parser_error (parser
,
17269 "%<#pragma omp declare simd%> must be followed by "
17270 "function declaration or definition or another "
17271 "%<#pragma omp declare simd%>");
17274 c_parser_consume_pragma (parser
);
17275 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17277 c_token
*token
= c_parser_peek_token (parser
);
17278 if (token
->type
== CPP_EOF
)
17280 c_parser_skip_to_pragma_eol (parser
);
17283 clauses
.safe_push (*token
);
17284 c_parser_consume_token (parser
);
17286 clauses
.safe_push (*c_parser_peek_token (parser
));
17287 c_parser_skip_to_pragma_eol (parser
);
17290 /* Make sure nothing tries to read past the end of the tokens. */
17292 memset (&eof_token
, 0, sizeof (eof_token
));
17293 eof_token
.type
= CPP_EOF
;
17294 clauses
.safe_push (eof_token
);
17295 clauses
.safe_push (eof_token
);
17299 case pragma_external
:
17300 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17301 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
17303 int ext
= disable_extension_diagnostics ();
17305 c_parser_consume_token (parser
);
17306 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17307 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
17308 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
17310 restore_extension_diagnostics (ext
);
17313 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
17316 case pragma_struct
:
17319 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
17320 "function declaration or definition");
17322 case pragma_compound
:
17323 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17324 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
17326 int ext
= disable_extension_diagnostics ();
17328 c_parser_consume_token (parser
);
17329 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17330 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
17331 if (c_parser_next_tokens_start_declaration (parser
))
17333 c_parser_declaration_or_fndef (parser
, true, true, true, true,
17334 true, NULL
, clauses
);
17335 restore_extension_diagnostics (ext
);
17338 restore_extension_diagnostics (ext
);
17340 else if (c_parser_next_tokens_start_declaration (parser
))
17342 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
17346 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
17347 "function declaration or definition");
17350 gcc_unreachable ();
17354 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
17355 and put that into "omp declare simd" attribute. */
17358 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
17359 vec
<c_token
> clauses
)
17361 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
17362 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
17363 has already processed the tokens. */
17364 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
17366 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
17368 error ("%<#pragma omp declare simd%> not immediately followed by "
17369 "a function declaration or definition");
17370 clauses
[0].type
= CPP_EOF
;
17373 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
17375 error_at (DECL_SOURCE_LOCATION (fndecl
),
17376 "%<#pragma omp declare simd%> not immediately followed by "
17377 "a single function declaration or definition");
17378 clauses
[0].type
= CPP_EOF
;
17382 if (parms
== NULL_TREE
)
17383 parms
= DECL_ARGUMENTS (fndecl
);
17385 unsigned int tokens_avail
= parser
->tokens_avail
;
17386 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
17389 parser
->tokens
= clauses
.address ();
17390 parser
->tokens_avail
= clauses
.length ();
17392 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
17393 while (parser
->tokens_avail
> 3)
17395 c_token
*token
= c_parser_peek_token (parser
);
17396 gcc_assert (token
->type
== CPP_NAME
17397 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
17398 c_parser_consume_token (parser
);
17399 parser
->in_pragma
= true;
17401 tree c
= NULL_TREE
;
17402 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
17403 "#pragma omp declare simd");
17404 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
17405 if (c
!= NULL_TREE
)
17406 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
17407 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
17408 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
17409 DECL_ATTRIBUTES (fndecl
) = c
;
17412 parser
->tokens
= &parser
->tokens_buf
[0];
17413 parser
->tokens_avail
= tokens_avail
;
17414 if (clauses
.exists ())
17415 clauses
[0].type
= CPP_PRAGMA
;
17420 # pragma omp declare target new-line
17421 declarations and definitions
17422 # pragma omp end declare target new-line
17425 # pragma omp declare target ( extended-list ) new-line
17427 # pragma omp declare target declare-target-clauses[seq] new-line */
17429 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
17430 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
17431 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
17434 c_parser_omp_declare_target (c_parser
*parser
)
17436 location_t loc
= c_parser_peek_token (parser
)->location
;
17437 tree clauses
= NULL_TREE
;
17438 if (c_parser_next_token_is (parser
, CPP_NAME
))
17439 clauses
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_TARGET_CLAUSE_MASK
,
17440 "#pragma omp declare target");
17441 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
17443 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
17445 clauses
= c_finish_omp_clauses (clauses
, C_ORT_OMP
);
17446 c_parser_skip_to_pragma_eol (parser
);
17450 c_parser_skip_to_pragma_eol (parser
);
17451 current_omp_declare_target_attribute
++;
17454 if (current_omp_declare_target_attribute
)
17455 error_at (loc
, "%<#pragma omp declare target%> with clauses in between "
17456 "%<#pragma omp declare target%> without clauses and "
17457 "%<#pragma omp end declare target%>");
17458 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
17460 tree t
= OMP_CLAUSE_DECL (c
), id
;
17461 tree at1
= lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t
));
17462 tree at2
= lookup_attribute ("omp declare target link",
17463 DECL_ATTRIBUTES (t
));
17464 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINK
)
17466 id
= get_identifier ("omp declare target link");
17467 std::swap (at1
, at2
);
17470 id
= get_identifier ("omp declare target");
17473 error_at (OMP_CLAUSE_LOCATION (c
),
17474 "%qD specified both in declare target %<link%> and %<to%>"
17480 DECL_ATTRIBUTES (t
) = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (t
));
17481 if (TREE_CODE (t
) != FUNCTION_DECL
&& !is_global_var (t
))
17484 symtab_node
*node
= symtab_node::get (t
);
17487 node
->offloadable
= 1;
17488 if (ENABLE_OFFLOADING
)
17490 g
->have_offload
= true;
17491 if (is_a
<varpool_node
*> (node
))
17492 vec_safe_push (offload_vars
, t
);
17500 c_parser_omp_end_declare_target (c_parser
*parser
)
17502 location_t loc
= c_parser_peek_token (parser
)->location
;
17503 c_parser_consume_pragma (parser
);
17504 if (c_parser_next_token_is (parser
, CPP_NAME
)
17505 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
17508 c_parser_consume_token (parser
);
17509 if (c_parser_next_token_is (parser
, CPP_NAME
)
17510 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
17512 c_parser_consume_token (parser
);
17515 c_parser_error (parser
, "expected %<target%>");
17516 c_parser_skip_to_pragma_eol (parser
);
17522 c_parser_error (parser
, "expected %<declare%>");
17523 c_parser_skip_to_pragma_eol (parser
);
17526 c_parser_skip_to_pragma_eol (parser
);
17527 if (!current_omp_declare_target_attribute
)
17528 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
17529 "%<#pragma omp declare target%>");
17531 current_omp_declare_target_attribute
--;
17536 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17537 initializer-clause[opt] new-line
17539 initializer-clause:
17540 initializer (omp_priv = initializer)
17541 initializer (function-name (argument-list)) */
17544 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
17546 unsigned int tokens_avail
= 0, i
;
17547 vec
<tree
> types
= vNULL
;
17548 vec
<c_token
> clauses
= vNULL
;
17549 enum tree_code reduc_code
= ERROR_MARK
;
17550 tree reduc_id
= NULL_TREE
;
17552 location_t rloc
= c_parser_peek_token (parser
)->location
;
17554 if (context
== pragma_struct
|| context
== pragma_param
)
17556 error ("%<#pragma omp declare reduction%> not at file or block scope");
17560 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17563 switch (c_parser_peek_token (parser
)->type
)
17566 reduc_code
= PLUS_EXPR
;
17569 reduc_code
= MULT_EXPR
;
17572 reduc_code
= MINUS_EXPR
;
17575 reduc_code
= BIT_AND_EXPR
;
17578 reduc_code
= BIT_XOR_EXPR
;
17581 reduc_code
= BIT_IOR_EXPR
;
17584 reduc_code
= TRUTH_ANDIF_EXPR
;
17587 reduc_code
= TRUTH_ORIF_EXPR
;
17591 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17592 if (strcmp (p
, "min") == 0)
17594 reduc_code
= MIN_EXPR
;
17597 if (strcmp (p
, "max") == 0)
17599 reduc_code
= MAX_EXPR
;
17602 reduc_id
= c_parser_peek_token (parser
)->value
;
17605 c_parser_error (parser
,
17606 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
17607 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
17611 tree orig_reduc_id
, reduc_decl
;
17612 orig_reduc_id
= reduc_id
;
17613 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
17614 reduc_decl
= c_omp_reduction_decl (reduc_id
);
17615 c_parser_consume_token (parser
);
17617 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
17622 location_t loc
= c_parser_peek_token (parser
)->location
;
17623 struct c_type_name
*ctype
= c_parser_type_name (parser
);
17626 type
= groktypename (ctype
, NULL
, NULL
);
17627 if (type
== error_mark_node
)
17629 else if ((INTEGRAL_TYPE_P (type
)
17630 || TREE_CODE (type
) == REAL_TYPE
17631 || TREE_CODE (type
) == COMPLEX_TYPE
)
17632 && orig_reduc_id
== NULL_TREE
)
17633 error_at (loc
, "predeclared arithmetic type in "
17634 "%<#pragma omp declare reduction%>");
17635 else if (TREE_CODE (type
) == FUNCTION_TYPE
17636 || TREE_CODE (type
) == ARRAY_TYPE
)
17637 error_at (loc
, "function or array type in "
17638 "%<#pragma omp declare reduction%>");
17639 else if (TYPE_ATOMIC (type
))
17640 error_at (loc
, "%<_Atomic%> qualified type in "
17641 "%<#pragma omp declare reduction%>");
17642 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
17643 error_at (loc
, "const, volatile or restrict qualified type in "
17644 "%<#pragma omp declare reduction%>");
17648 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
17649 if (comptypes (TREE_PURPOSE (t
), type
))
17651 error_at (loc
, "redeclaration of %qs "
17652 "%<#pragma omp declare reduction%> for "
17654 IDENTIFIER_POINTER (reduc_id
)
17655 + sizeof ("omp declare reduction ") - 1,
17658 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
17660 error_at (ploc
, "previous %<#pragma omp declare "
17664 if (t
== NULL_TREE
)
17665 types
.safe_push (type
);
17667 if (c_parser_next_token_is (parser
, CPP_COMMA
))
17668 c_parser_consume_token (parser
);
17676 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
17677 || types
.is_empty ())
17680 clauses
.release ();
17684 c_token
*token
= c_parser_peek_token (parser
);
17685 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
17687 c_parser_consume_token (parser
);
17689 c_parser_skip_to_pragma_eol (parser
);
17693 if (types
.length () > 1)
17695 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17697 c_token
*token
= c_parser_peek_token (parser
);
17698 if (token
->type
== CPP_EOF
)
17700 clauses
.safe_push (*token
);
17701 c_parser_consume_token (parser
);
17703 clauses
.safe_push (*c_parser_peek_token (parser
));
17704 c_parser_skip_to_pragma_eol (parser
);
17706 /* Make sure nothing tries to read past the end of the tokens. */
17708 memset (&eof_token
, 0, sizeof (eof_token
));
17709 eof_token
.type
= CPP_EOF
;
17710 clauses
.safe_push (eof_token
);
17711 clauses
.safe_push (eof_token
);
17714 int errs
= errorcount
;
17715 FOR_EACH_VEC_ELT (types
, i
, type
)
17717 tokens_avail
= parser
->tokens_avail
;
17718 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
17719 if (!clauses
.is_empty ())
17721 parser
->tokens
= clauses
.address ();
17722 parser
->tokens_avail
= clauses
.length ();
17723 parser
->in_pragma
= true;
17726 bool nested
= current_function_decl
!= NULL_TREE
;
17728 c_push_function_context ();
17729 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
17730 reduc_id
, default_function_type
);
17731 current_function_decl
= fndecl
;
17732 allocate_struct_function (fndecl
, true);
17734 tree stmt
= push_stmt_list ();
17735 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
17736 warn about these. */
17737 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17738 get_identifier ("omp_out"), type
);
17739 DECL_ARTIFICIAL (omp_out
) = 1;
17740 DECL_CONTEXT (omp_out
) = fndecl
;
17741 pushdecl (omp_out
);
17742 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17743 get_identifier ("omp_in"), type
);
17744 DECL_ARTIFICIAL (omp_in
) = 1;
17745 DECL_CONTEXT (omp_in
) = fndecl
;
17747 struct c_expr combiner
= c_parser_expression (parser
);
17748 struct c_expr initializer
;
17749 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
17751 initializer
.set_error ();
17752 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17754 else if (c_parser_next_token_is (parser
, CPP_NAME
)
17755 && strcmp (IDENTIFIER_POINTER
17756 (c_parser_peek_token (parser
)->value
),
17757 "initializer") == 0)
17759 c_parser_consume_token (parser
);
17762 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17763 get_identifier ("omp_priv"), type
);
17764 DECL_ARTIFICIAL (omp_priv
) = 1;
17765 DECL_INITIAL (omp_priv
) = error_mark_node
;
17766 DECL_CONTEXT (omp_priv
) = fndecl
;
17767 pushdecl (omp_priv
);
17768 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17769 get_identifier ("omp_orig"), type
);
17770 DECL_ARTIFICIAL (omp_orig
) = 1;
17771 DECL_CONTEXT (omp_orig
) = fndecl
;
17772 pushdecl (omp_orig
);
17773 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17775 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
17777 c_parser_error (parser
, "expected %<omp_priv%> or "
17781 else if (strcmp (IDENTIFIER_POINTER
17782 (c_parser_peek_token (parser
)->value
),
17785 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
17786 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
17788 c_parser_error (parser
, "expected function-name %<(%>");
17792 initializer
= c_parser_postfix_expression (parser
);
17793 if (initializer
.value
17794 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
17797 tree c
= initializer
.value
;
17798 for (j
= 0; j
< call_expr_nargs (c
); j
++)
17800 tree a
= CALL_EXPR_ARG (c
, j
);
17802 if (TREE_CODE (a
) == ADDR_EXPR
17803 && TREE_OPERAND (a
, 0) == omp_priv
)
17806 if (j
== call_expr_nargs (c
))
17807 error ("one of the initializer call arguments should be "
17813 c_parser_consume_token (parser
);
17814 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
17818 tree st
= push_stmt_list ();
17819 location_t loc
= c_parser_peek_token (parser
)->location
;
17820 rich_location
richloc (line_table
, loc
);
17821 start_init (omp_priv
, NULL_TREE
, 0, &richloc
);
17822 struct c_expr init
= c_parser_initializer (parser
);
17824 finish_decl (omp_priv
, loc
, init
.value
,
17825 init
.original_type
, NULL_TREE
);
17826 pop_stmt_list (st
);
17830 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17836 c_parser_skip_to_pragma_eol (parser
);
17838 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
17839 DECL_INITIAL (reduc_decl
));
17840 DECL_INITIAL (reduc_decl
) = t
;
17841 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
17842 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
17843 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
17844 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
17845 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
17846 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
17849 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
17850 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
17851 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
17852 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
17853 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
17854 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17855 walk_tree (&DECL_INITIAL (omp_priv
),
17856 c_check_omp_declare_reduction_r
,
17857 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17861 pop_stmt_list (stmt
);
17863 if (cfun
->language
!= NULL
)
17865 ggc_free (cfun
->language
);
17866 cfun
->language
= NULL
;
17869 current_function_decl
= NULL_TREE
;
17871 c_pop_function_context ();
17873 if (!clauses
.is_empty ())
17875 parser
->tokens
= &parser
->tokens_buf
[0];
17876 parser
->tokens_avail
= tokens_avail
;
17880 if (errs
!= errorcount
)
17884 clauses
.release ();
17890 #pragma omp declare simd declare-simd-clauses[optseq] new-line
17891 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17892 initializer-clause[opt] new-line
17893 #pragma omp declare target new-line */
17896 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
17898 c_parser_consume_pragma (parser
);
17899 if (c_parser_next_token_is (parser
, CPP_NAME
))
17901 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17902 if (strcmp (p
, "simd") == 0)
17904 /* c_parser_consume_token (parser); done in
17905 c_parser_omp_declare_simd. */
17906 c_parser_omp_declare_simd (parser
, context
);
17909 if (strcmp (p
, "reduction") == 0)
17911 c_parser_consume_token (parser
);
17912 c_parser_omp_declare_reduction (parser
, context
);
17915 if (!flag_openmp
) /* flag_openmp_simd */
17917 c_parser_skip_to_pragma_eol (parser
, false);
17920 if (strcmp (p
, "target") == 0)
17922 c_parser_consume_token (parser
);
17923 c_parser_omp_declare_target (parser
);
17928 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
17930 c_parser_skip_to_pragma_eol (parser
);
17934 #pragma omp taskloop taskloop-clause[optseq] new-line
17937 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
17940 #define OMP_TASKLOOP_CLAUSE_MASK \
17941 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
17942 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17943 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17944 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
17945 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
17946 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
17947 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
17948 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
17949 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
17950 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17951 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
17952 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
17953 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
17954 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
17957 c_parser_omp_taskloop (location_t loc
, c_parser
*parser
,
17958 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17961 tree clauses
, block
, ret
;
17963 strcat (p_name
, " taskloop");
17964 mask
|= OMP_TASKLOOP_CLAUSE_MASK
;
17966 if (c_parser_next_token_is (parser
, CPP_NAME
))
17968 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17970 if (strcmp (p
, "simd") == 0)
17972 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17973 if (cclauses
== NULL
)
17974 cclauses
= cclauses_buf
;
17975 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_REDUCTION
);
17976 c_parser_consume_token (parser
);
17977 if (!flag_openmp
) /* flag_openmp_simd */
17978 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
17980 block
= c_begin_compound_stmt (true);
17981 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
17982 block
= c_end_compound_stmt (loc
, block
, true);
17985 ret
= make_node (OMP_TASKLOOP
);
17986 TREE_TYPE (ret
) = void_type_node
;
17987 OMP_FOR_BODY (ret
) = block
;
17988 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
17989 SET_EXPR_LOCATION (ret
, loc
);
17994 if (!flag_openmp
) /* flag_openmp_simd */
17996 c_parser_skip_to_pragma_eol (parser
, false);
18000 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
18003 omp_split_clauses (loc
, OMP_TASKLOOP
, mask
, clauses
, cclauses
);
18004 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
18007 block
= c_begin_compound_stmt (true);
18008 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_TASKLOOP
, clauses
, NULL
, if_p
);
18009 block
= c_end_compound_stmt (loc
, block
, true);
18015 /* Main entry point to parsing most OpenMP pragmas. */
18018 c_parser_omp_construct (c_parser
*parser
, bool *if_p
)
18020 enum pragma_kind p_kind
;
18023 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
18024 omp_clause_mask
mask (0);
18026 loc
= c_parser_peek_token (parser
)->location
;
18027 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
18028 c_parser_consume_pragma (parser
);
18032 case PRAGMA_OACC_ATOMIC
:
18033 c_parser_omp_atomic (loc
, parser
);
18035 case PRAGMA_OACC_CACHE
:
18036 strcpy (p_name
, "#pragma acc");
18037 stmt
= c_parser_oacc_cache (loc
, parser
);
18039 case PRAGMA_OACC_DATA
:
18040 stmt
= c_parser_oacc_data (loc
, parser
, if_p
);
18042 case PRAGMA_OACC_HOST_DATA
:
18043 stmt
= c_parser_oacc_host_data (loc
, parser
, if_p
);
18045 case PRAGMA_OACC_KERNELS
:
18046 case PRAGMA_OACC_PARALLEL
:
18047 strcpy (p_name
, "#pragma acc");
18048 stmt
= c_parser_oacc_kernels_parallel (loc
, parser
, p_kind
, p_name
,
18051 case PRAGMA_OACC_LOOP
:
18052 strcpy (p_name
, "#pragma acc");
18053 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18055 case PRAGMA_OACC_WAIT
:
18056 strcpy (p_name
, "#pragma wait");
18057 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
18059 case PRAGMA_OMP_ATOMIC
:
18060 c_parser_omp_atomic (loc
, parser
);
18062 case PRAGMA_OMP_CRITICAL
:
18063 stmt
= c_parser_omp_critical (loc
, parser
, if_p
);
18065 case PRAGMA_OMP_DISTRIBUTE
:
18066 strcpy (p_name
, "#pragma omp");
18067 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18069 case PRAGMA_OMP_FOR
:
18070 strcpy (p_name
, "#pragma omp");
18071 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18073 case PRAGMA_OMP_MASTER
:
18074 stmt
= c_parser_omp_master (loc
, parser
, if_p
);
18076 case PRAGMA_OMP_PARALLEL
:
18077 strcpy (p_name
, "#pragma omp");
18078 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18080 case PRAGMA_OMP_SECTIONS
:
18081 strcpy (p_name
, "#pragma omp");
18082 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
18084 case PRAGMA_OMP_SIMD
:
18085 strcpy (p_name
, "#pragma omp");
18086 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18088 case PRAGMA_OMP_SINGLE
:
18089 stmt
= c_parser_omp_single (loc
, parser
, if_p
);
18091 case PRAGMA_OMP_TASK
:
18092 stmt
= c_parser_omp_task (loc
, parser
, if_p
);
18094 case PRAGMA_OMP_TASKGROUP
:
18095 stmt
= c_parser_omp_taskgroup (parser
, if_p
);
18097 case PRAGMA_OMP_TASKLOOP
:
18098 strcpy (p_name
, "#pragma omp");
18099 stmt
= c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18101 case PRAGMA_OMP_TEAMS
:
18102 strcpy (p_name
, "#pragma omp");
18103 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
, if_p
);
18106 gcc_unreachable ();
18110 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
18115 # pragma omp threadprivate (variable-list) */
18118 c_parser_omp_threadprivate (c_parser
*parser
)
18123 c_parser_consume_pragma (parser
);
18124 loc
= c_parser_peek_token (parser
)->location
;
18125 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
18127 /* Mark every variable in VARS to be assigned thread local storage. */
18128 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
18130 tree v
= TREE_PURPOSE (t
);
18132 /* FIXME diagnostics: Ideally we should keep individual
18133 locations for all the variables in the var list to make the
18134 following errors more precise. Perhaps
18135 c_parser_omp_var_list_parens() should construct a list of
18136 locations to go along with the var list. */
18138 /* If V had already been marked threadprivate, it doesn't matter
18139 whether it had been used prior to this point. */
18141 error_at (loc
, "%qD is not a variable", v
);
18142 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
18143 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
18144 else if (! is_global_var (v
))
18145 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
18146 else if (TREE_TYPE (v
) == error_mark_node
)
18148 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
18149 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
18152 if (! DECL_THREAD_LOCAL_P (v
))
18154 set_decl_tls_model (v
, decl_default_tls_model (v
));
18155 /* If rtl has been already set for this var, call
18156 make_decl_rtl once again, so that encode_section_info
18157 has a chance to look at the new decl flags. */
18158 if (DECL_RTL_SET_P (v
))
18161 C_DECL_THREADPRIVATE_P (v
) = 1;
18165 c_parser_skip_to_pragma_eol (parser
);
18168 /* Parse a transaction attribute (GCC Extension).
18170 transaction-attribute:
18174 The transactional memory language description is written for C++,
18175 and uses the C++0x attribute syntax. For compatibility, allow the
18176 bracket style for transactions in C as well. */
18179 c_parser_transaction_attributes (c_parser
*parser
)
18181 tree attr_name
, attr
= NULL
;
18183 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
18184 return c_parser_attributes (parser
);
18186 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
18188 c_parser_consume_token (parser
);
18189 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
18192 attr_name
= c_parser_attribute_any_word (parser
);
18195 c_parser_consume_token (parser
);
18196 attr
= build_tree_list (attr_name
, NULL_TREE
);
18199 c_parser_error (parser
, "expected identifier");
18201 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18203 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18207 /* Parse a __transaction_atomic or __transaction_relaxed statement
18210 transaction-statement:
18211 __transaction_atomic transaction-attribute[opt] compound-statement
18212 __transaction_relaxed compound-statement
18214 Note that the only valid attribute is: "outer".
18218 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
18220 unsigned int old_in
= parser
->in_transaction
;
18221 unsigned int this_in
= 1, new_in
;
18222 location_t loc
= c_parser_peek_token (parser
)->location
;
18225 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18226 || keyword
== RID_TRANSACTION_RELAXED
)
18227 && c_parser_next_token_is_keyword (parser
, keyword
));
18228 c_parser_consume_token (parser
);
18230 if (keyword
== RID_TRANSACTION_RELAXED
)
18231 this_in
|= TM_STMT_ATTR_RELAXED
;
18234 attrs
= c_parser_transaction_attributes (parser
);
18236 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
18239 /* Keep track if we're in the lexical scope of an outer transaction. */
18240 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
18242 parser
->in_transaction
= new_in
;
18243 stmt
= c_parser_compound_statement (parser
);
18244 parser
->in_transaction
= old_in
;
18247 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
18249 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18250 "%<__transaction_atomic%> without transactional memory support enabled"
18251 : "%<__transaction_relaxed %> "
18252 "without transactional memory support enabled"));
18257 /* Parse a __transaction_atomic or __transaction_relaxed expression
18260 transaction-expression:
18261 __transaction_atomic ( expression )
18262 __transaction_relaxed ( expression )
18265 static struct c_expr
18266 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
18269 unsigned int old_in
= parser
->in_transaction
;
18270 unsigned int this_in
= 1;
18271 location_t loc
= c_parser_peek_token (parser
)->location
;
18274 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18275 || keyword
== RID_TRANSACTION_RELAXED
)
18276 && c_parser_next_token_is_keyword (parser
, keyword
));
18277 c_parser_consume_token (parser
);
18279 if (keyword
== RID_TRANSACTION_RELAXED
)
18280 this_in
|= TM_STMT_ATTR_RELAXED
;
18283 attrs
= c_parser_transaction_attributes (parser
);
18285 this_in
|= parse_tm_stmt_attr (attrs
, 0);
18288 parser
->in_transaction
= this_in
;
18289 matching_parens parens
;
18290 if (parens
.require_open (parser
))
18292 tree expr
= c_parser_expression (parser
).value
;
18293 ret
.original_type
= TREE_TYPE (expr
);
18294 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
18295 if (this_in
& TM_STMT_ATTR_RELAXED
)
18296 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
18297 SET_EXPR_LOCATION (ret
.value
, loc
);
18298 ret
.original_code
= TRANSACTION_EXPR
;
18299 if (!parens
.require_close (parser
))
18301 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
18309 ret
.original_code
= ERROR_MARK
;
18310 ret
.original_type
= NULL
;
18312 parser
->in_transaction
= old_in
;
18315 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18316 "%<__transaction_atomic%> without transactional memory support enabled"
18317 : "%<__transaction_relaxed %> "
18318 "without transactional memory support enabled"));
18320 set_c_expr_source_range (&ret
, loc
, loc
);
18325 /* Parse a __transaction_cancel statement (GCC Extension).
18327 transaction-cancel-statement:
18328 __transaction_cancel transaction-attribute[opt] ;
18330 Note that the only valid attribute is "outer".
18334 c_parser_transaction_cancel (c_parser
*parser
)
18336 location_t loc
= c_parser_peek_token (parser
)->location
;
18338 bool is_outer
= false;
18340 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
18341 c_parser_consume_token (parser
);
18343 attrs
= c_parser_transaction_attributes (parser
);
18345 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
18349 error_at (loc
, "%<__transaction_cancel%> without "
18350 "transactional memory support enabled");
18353 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
18355 error_at (loc
, "%<__transaction_cancel%> within a "
18356 "%<__transaction_relaxed%>");
18361 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
18362 && !is_tm_may_cancel_outer (current_function_decl
))
18364 error_at (loc
, "outer %<__transaction_cancel%> not "
18365 "within outer %<__transaction_atomic%>");
18366 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
18370 else if (parser
->in_transaction
== 0)
18372 error_at (loc
, "%<__transaction_cancel%> not within "
18373 "%<__transaction_atomic%>");
18377 return add_stmt (build_tm_abort_call (loc
, is_outer
));
18380 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
18383 /* Parse a single source file. */
18386 c_parse_file (void)
18388 /* Use local storage to begin. If the first token is a pragma, parse it.
18389 If it is #pragma GCC pch_preprocess, then this will load a PCH file
18390 which will cause garbage collection. */
18393 memset (&tparser
, 0, sizeof tparser
);
18394 tparser
.tokens
= &tparser
.tokens_buf
[0];
18395 the_parser
= &tparser
;
18397 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
18398 c_parser_pragma_pch_preprocess (&tparser
);
18400 the_parser
= ggc_alloc
<c_parser
> ();
18401 *the_parser
= tparser
;
18402 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
18403 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
18405 /* Initialize EH, if we've been told to do so. */
18406 if (flag_exceptions
)
18407 using_eh_for_cleanups ();
18409 c_parser_translation_unit (the_parser
);
18413 /* Parse the body of a function declaration marked with "__RTL".
18415 The RTL parser works on the level of characters read from a
18416 FILE *, whereas c_parser works at the level of tokens.
18417 Square this circle by consuming all of the tokens up to and
18418 including the closing brace, recording the start/end of the RTL
18419 fragment, and reopening the file and re-reading the relevant
18420 lines within the RTL parser.
18422 This requires the opening and closing braces of the C function
18423 to be on separate lines from the RTL they wrap.
18425 Take ownership of START_WITH_PASS, if non-NULL. */
18428 c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
)
18430 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
18432 free (start_with_pass
);
18436 location_t start_loc
= c_parser_peek_token (parser
)->location
;
18438 /* Consume all tokens, up to the closing brace, handling
18439 matching pairs of braces in the rtl dump. */
18440 int num_open_braces
= 1;
18443 switch (c_parser_peek_token (parser
)->type
)
18445 case CPP_OPEN_BRACE
:
18448 case CPP_CLOSE_BRACE
:
18449 if (--num_open_braces
== 0)
18450 goto found_closing_brace
;
18453 error_at (start_loc
, "no closing brace");
18454 free (start_with_pass
);
18459 c_parser_consume_token (parser
);
18462 found_closing_brace
:
18463 /* At the closing brace; record its location. */
18464 location_t end_loc
= c_parser_peek_token (parser
)->location
;
18466 /* Consume the closing brace. */
18467 c_parser_consume_token (parser
);
18469 /* Invoke the RTL parser. */
18470 if (!read_rtl_function_body_from_file_range (start_loc
, end_loc
))
18472 free (start_with_pass
);
18476 /* If a pass name was provided for START_WITH_PASS, run the backend
18477 accordingly now, on the cfun created above, transferring
18478 ownership of START_WITH_PASS. */
18479 if (start_with_pass
)
18480 run_rtl_passes (start_with_pass
);
18483 #include "gt-c-c-parser.h"