1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2017 Free Software Foundation, Inc.
4 Parser actions based on the old Bison parser; structure somewhat
5 influenced by and fragments based on the C++ parser.
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
25 Make sure all relevant comments, and all relevant code from all
26 actions, brought over from old parser. Verify exact correspondence
29 Add testcases covering every input symbol in every state in old and
32 Include full syntax for GNU C, including erroneous cases accepted
33 with error messages, in syntax productions in comments.
35 Make more diagnostics in the front end generally take an explicit
36 location rather than implicitly using input_location. */
39 #define INCLUDE_UNIQUE_PTR
41 #include "coretypes.h"
46 #include "stringpool.h"
49 #include "stor-layout.h"
51 #include "trans-mem.h"
52 #include "c-family/c-pragma.h"
54 #include "c-family/c-objc.h"
56 #include "omp-general.h"
57 #include "omp-offload.h"
59 #include "gomp-constants.h"
60 #include "c-family/c-indentation.h"
61 #include "gimple-expr.h"
63 #include "gcc-rich-location.h"
65 #include "gimple-parser.h"
66 #include "read-rtl-function.h"
67 #include "run-rtl-passes.h"
69 #include "c-family/name-hint.h"
70 #include "tree-iterator.h"
72 /* We need to walk over decls with incomplete struct/union/enum types
73 after parsing the whole translation unit.
74 In finish_decl(), if the decl is static, has incomplete
75 struct/union/enum type, it is appeneded to incomplete_record_decls.
76 In c_parser_translation_unit(), we iterate over incomplete_record_decls
77 and report error if any of the decls are still incomplete. */
79 vec
<tree
> incomplete_record_decls
;
82 set_c_expr_source_range (c_expr
*expr
,
83 location_t start
, location_t finish
)
85 expr
->src_range
.m_start
= start
;
86 expr
->src_range
.m_finish
= finish
;
88 set_source_range (expr
->value
, start
, finish
);
92 set_c_expr_source_range (c_expr
*expr
,
93 source_range src_range
)
95 expr
->src_range
= src_range
;
97 set_source_range (expr
->value
, src_range
);
101 /* Initialization routine for this file. */
106 /* The only initialization required is of the reserved word
112 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
113 the c_token structure. */
114 gcc_assert (RID_MAX
<= 255);
121 mask
|= D_ASM
| D_EXT
;
125 if (!c_dialect_objc ())
126 mask
|= D_OBJC
| D_CXX_OBJC
;
128 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
129 for (i
= 0; i
< num_c_common_reswords
; i
++)
131 /* If a keyword is disabled, do not enter it into the table
132 and so create a canonical spelling that isn't a keyword. */
133 if (c_common_reswords
[i
].disable
& mask
)
136 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
138 id
= get_identifier (c_common_reswords
[i
].word
);
139 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
140 C_IS_RESERVED_WORD (id
) = 1;
145 id
= get_identifier (c_common_reswords
[i
].word
);
146 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
147 C_IS_RESERVED_WORD (id
) = 1;
148 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
151 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
153 /* We always create the symbols but they aren't always supported. */
155 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
156 id
= get_identifier (name
);
157 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
158 C_IS_RESERVED_WORD (id
) = 1;
162 /* A parser structure recording information about the state and
163 context of parsing. Includes lexer information with up to two
164 tokens of look-ahead; more are not needed for C. */
165 struct GTY(()) c_parser
{
166 /* The look-ahead tokens. */
167 c_token
* GTY((skip
)) tokens
;
168 /* Buffer for look-ahead tokens. */
169 c_token tokens_buf
[4];
170 /* How many look-ahead tokens are available (0 - 4, or
171 more if parsing from pre-lexed tokens). */
172 unsigned int tokens_avail
;
173 /* True if a syntax error is being recovered from; false otherwise.
174 c_parser_error sets this flag. It should clear this flag when
175 enough tokens have been consumed to recover from the error. */
176 BOOL_BITFIELD error
: 1;
177 /* True if we're processing a pragma, and shouldn't automatically
178 consume CPP_PRAGMA_EOL. */
179 BOOL_BITFIELD in_pragma
: 1;
180 /* True if we're parsing the outermost block of an if statement. */
181 BOOL_BITFIELD in_if_block
: 1;
182 /* True if we want to lex an untranslated string. */
183 BOOL_BITFIELD lex_untranslated_string
: 1;
185 /* Objective-C specific parser/lexer information. */
187 /* True if we are in a context where the Objective-C "PQ" keywords
188 are considered keywords. */
189 BOOL_BITFIELD objc_pq_context
: 1;
190 /* True if we are parsing a (potential) Objective-C foreach
191 statement. This is set to true after we parsed 'for (' and while
192 we wait for 'in' or ';' to decide if it's a standard C for loop or an
193 Objective-C foreach loop. */
194 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
195 /* The following flag is needed to contextualize Objective-C lexical
196 analysis. In some cases (e.g., 'int NSObject;'), it is
197 undesirable to bind an identifier to an Objective-C class, even
198 if a class with that name exists. */
199 BOOL_BITFIELD objc_need_raw_identifier
: 1;
200 /* Nonzero if we're processing a __transaction statement. The value
201 is 1 | TM_STMT_ATTR_*. */
202 unsigned int in_transaction
: 4;
203 /* True if we are in a context where the Objective-C "Property attribute"
204 keywords are valid. */
205 BOOL_BITFIELD objc_property_attr_context
: 1;
207 /* Location of the last consumed token. */
208 location_t last_token_location
;
211 /* Return a pointer to the Nth token in PARSERs tokens_buf. */
214 c_parser_tokens_buf (c_parser
*parser
, unsigned n
)
216 return &parser
->tokens_buf
[n
];
219 /* Return the error state of PARSER. */
222 c_parser_error (c_parser
*parser
)
224 return parser
->error
;
227 /* Set the error state of PARSER to ERR. */
230 c_parser_set_error (c_parser
*parser
, bool err
)
236 /* The actual parser and external interface. ??? Does this need to be
237 garbage-collected? */
239 static GTY (()) c_parser
*the_parser
;
241 /* Read in and lex a single token, storing it in *TOKEN. */
244 c_lex_one_token (c_parser
*parser
, c_token
*token
)
246 timevar_push (TV_LEX
);
248 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
,
250 (parser
->lex_untranslated_string
251 ? C_LEX_STRING_NO_TRANSLATE
: 0));
252 token
->id_kind
= C_ID_NONE
;
253 token
->keyword
= RID_MAX
;
254 token
->pragma_kind
= PRAGMA_NONE
;
262 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
263 if (c_dialect_objc ())
264 parser
->objc_need_raw_identifier
= false;
266 if (C_IS_RESERVED_WORD (token
->value
))
268 enum rid rid_code
= C_RID_CODE (token
->value
);
270 if (rid_code
== RID_CXX_COMPAT_WARN
)
272 warning_at (token
->location
,
274 "identifier %qE conflicts with C++ keyword",
277 else if (rid_code
>= RID_FIRST_ADDR_SPACE
278 && rid_code
<= RID_LAST_ADDR_SPACE
)
281 as
= (addr_space_t
) (rid_code
- RID_FIRST_ADDR_SPACE
);
282 targetm
.addr_space
.diagnose_usage (as
, token
->location
);
283 token
->id_kind
= C_ID_ADDRSPACE
;
284 token
->keyword
= rid_code
;
287 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
289 /* We found an Objective-C "pq" keyword (in, out,
290 inout, bycopy, byref, oneway). They need special
291 care because the interpretation depends on the
293 if (parser
->objc_pq_context
)
295 token
->type
= CPP_KEYWORD
;
296 token
->keyword
= rid_code
;
299 else if (parser
->objc_could_be_foreach_context
300 && rid_code
== RID_IN
)
302 /* We are in Objective-C, inside a (potential)
303 foreach context (which means after having
304 parsed 'for (', but before having parsed ';'),
305 and we found 'in'. We consider it the keyword
306 which terminates the declaration at the
307 beginning of a foreach-statement. Note that
308 this means you can't use 'in' for anything else
309 in that context; in particular, in Objective-C
310 you can't use 'in' as the name of the running
311 variable in a C for loop. We could potentially
312 try to add code here to disambiguate, but it
313 seems a reasonable limitation. */
314 token
->type
= CPP_KEYWORD
;
315 token
->keyword
= rid_code
;
318 /* Else, "pq" keywords outside of the "pq" context are
319 not keywords, and we fall through to the code for
322 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
324 /* We found an Objective-C "property attribute"
325 keyword (getter, setter, readonly, etc). These are
326 only valid in the property context. */
327 if (parser
->objc_property_attr_context
)
329 token
->type
= CPP_KEYWORD
;
330 token
->keyword
= rid_code
;
333 /* Else they are not special keywords.
336 else if (c_dialect_objc ()
337 && (OBJC_IS_AT_KEYWORD (rid_code
)
338 || OBJC_IS_CXX_KEYWORD (rid_code
)))
340 /* We found one of the Objective-C "@" keywords (defs,
341 selector, synchronized, etc) or one of the
342 Objective-C "cxx" keywords (class, private,
343 protected, public, try, catch, throw) without a
344 preceding '@' sign. Do nothing and fall through to
345 the code for normal tokens (in C++ we would still
346 consider the CXX ones keywords, but not in C). */
351 token
->type
= CPP_KEYWORD
;
352 token
->keyword
= rid_code
;
357 decl
= lookup_name (token
->value
);
360 if (TREE_CODE (decl
) == TYPE_DECL
)
362 token
->id_kind
= C_ID_TYPENAME
;
366 else if (c_dialect_objc ())
368 tree objc_interface_decl
= objc_is_class_name (token
->value
);
369 /* Objective-C class names are in the same namespace as
370 variables and typedefs, and hence are shadowed by local
372 if (objc_interface_decl
373 && (!objc_force_identifier
|| global_bindings_p ()))
375 token
->value
= objc_interface_decl
;
376 token
->id_kind
= C_ID_CLASSNAME
;
380 token
->id_kind
= C_ID_ID
;
384 /* This only happens in Objective-C; it must be a keyword. */
385 token
->type
= CPP_KEYWORD
;
386 switch (C_RID_CODE (token
->value
))
388 /* Replace 'class' with '@class', 'private' with '@private',
389 etc. This prevents confusion with the C++ keyword
390 'class', and makes the tokens consistent with other
391 Objective-C 'AT' keywords. For example '@class' is
392 reported as RID_AT_CLASS which is consistent with
393 '@synchronized', which is reported as
396 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
397 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
398 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
399 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
400 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
401 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
402 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
403 case RID_SYNCHRONIZED
: token
->keyword
= RID_AT_SYNCHRONIZED
; break;
404 default: token
->keyword
= C_RID_CODE (token
->value
);
409 case CPP_CLOSE_PAREN
:
411 /* These tokens may affect the interpretation of any identifiers
412 following, if doing Objective-C. */
413 if (c_dialect_objc ())
414 parser
->objc_need_raw_identifier
= false;
417 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
418 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
424 timevar_pop (TV_LEX
);
427 /* Return a pointer to the next token from PARSER, reading it in if
431 c_parser_peek_token (c_parser
*parser
)
433 if (parser
->tokens_avail
== 0)
435 c_lex_one_token (parser
, &parser
->tokens
[0]);
436 parser
->tokens_avail
= 1;
438 return &parser
->tokens
[0];
441 /* Return a pointer to the next-but-one token from PARSER, reading it
442 in if necessary. The next token is already read in. */
445 c_parser_peek_2nd_token (c_parser
*parser
)
447 if (parser
->tokens_avail
>= 2)
448 return &parser
->tokens
[1];
449 gcc_assert (parser
->tokens_avail
== 1);
450 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
451 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
452 c_lex_one_token (parser
, &parser
->tokens
[1]);
453 parser
->tokens_avail
= 2;
454 return &parser
->tokens
[1];
457 /* Return a pointer to the Nth token from PARSER, reading it
458 in if necessary. The N-1th token is already read in. */
461 c_parser_peek_nth_token (c_parser
*parser
, unsigned int n
)
463 /* N is 1-based, not zero-based. */
466 if (parser
->tokens_avail
>= n
)
467 return &parser
->tokens
[n
- 1];
468 gcc_assert (parser
->tokens_avail
== n
- 1);
469 c_lex_one_token (parser
, &parser
->tokens
[n
- 1]);
470 parser
->tokens_avail
= n
;
471 return &parser
->tokens
[n
- 1];
475 c_keyword_starts_typename (enum rid keyword
)
509 if (keyword
>= RID_FIRST_INT_N
510 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
511 && int_n_enabled_p
[keyword
- RID_FIRST_INT_N
])
517 /* Return true if TOKEN can start a type name,
520 c_token_starts_typename (c_token
*token
)
525 switch (token
->id_kind
)
534 gcc_assert (c_dialect_objc ());
540 return c_keyword_starts_typename (token
->keyword
);
542 if (c_dialect_objc ())
550 /* Return true if the next token from PARSER can start a type name,
551 false otherwise. LA specifies how to do lookahead in order to
552 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
555 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
557 c_token
*token
= c_parser_peek_token (parser
);
558 if (c_token_starts_typename (token
))
561 /* Try a bit harder to detect an unknown typename. */
562 if (la
!= cla_prefer_id
563 && token
->type
== CPP_NAME
564 && token
->id_kind
== C_ID_ID
566 /* Do not try too hard when we could have "object in array". */
567 && !parser
->objc_could_be_foreach_context
569 && (la
== cla_prefer_type
570 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
571 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
573 /* Only unknown identifiers. */
574 && !lookup_name (token
->value
))
580 /* Return true if TOKEN is a type qualifier, false otherwise. */
582 c_token_is_qualifier (c_token
*token
)
587 switch (token
->id_kind
)
595 switch (token
->keyword
)
613 /* Return true if the next token from PARSER is a type qualifier,
616 c_parser_next_token_is_qualifier (c_parser
*parser
)
618 c_token
*token
= c_parser_peek_token (parser
);
619 return c_token_is_qualifier (token
);
622 /* Return true if TOKEN can start declaration specifiers, false
625 c_token_starts_declspecs (c_token
*token
)
630 switch (token
->id_kind
)
639 gcc_assert (c_dialect_objc ());
645 switch (token
->keyword
)
686 if (token
->keyword
>= RID_FIRST_INT_N
687 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
688 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
693 if (c_dialect_objc ())
702 /* Return true if TOKEN can start declaration specifiers or a static
703 assertion, false otherwise. */
705 c_token_starts_declaration (c_token
*token
)
707 if (c_token_starts_declspecs (token
)
708 || token
->keyword
== RID_STATIC_ASSERT
)
714 /* Return true if the next token from PARSER can start declaration
715 specifiers, false otherwise. */
717 c_parser_next_token_starts_declspecs (c_parser
*parser
)
719 c_token
*token
= c_parser_peek_token (parser
);
721 /* In Objective-C, a classname normally starts a declspecs unless it
722 is immediately followed by a dot. In that case, it is the
723 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
724 setter/getter on the class. c_token_starts_declspecs() can't
725 differentiate between the two cases because it only checks the
726 current token, so we have a special check here. */
727 if (c_dialect_objc ()
728 && token
->type
== CPP_NAME
729 && token
->id_kind
== C_ID_CLASSNAME
730 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
733 return c_token_starts_declspecs (token
);
736 /* Return true if the next tokens from PARSER can start declaration
737 specifiers or a static assertion, false otherwise. */
739 c_parser_next_tokens_start_declaration (c_parser
*parser
)
741 c_token
*token
= c_parser_peek_token (parser
);
744 if (c_dialect_objc ()
745 && token
->type
== CPP_NAME
746 && token
->id_kind
== C_ID_CLASSNAME
747 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
750 /* Labels do not start declarations. */
751 if (token
->type
== CPP_NAME
752 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
755 if (c_token_starts_declaration (token
))
758 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
764 /* Consume the next token from PARSER. */
767 c_parser_consume_token (c_parser
*parser
)
769 gcc_assert (parser
->tokens_avail
>= 1);
770 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
771 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
772 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
773 parser
->last_token_location
= parser
->tokens
[0].location
;
774 if (parser
->tokens
!= &parser
->tokens_buf
[0])
776 else if (parser
->tokens_avail
== 2)
777 parser
->tokens
[0] = parser
->tokens
[1];
778 parser
->tokens_avail
--;
781 /* Expect the current token to be a #pragma. Consume it and remember
782 that we've begun parsing a pragma. */
785 c_parser_consume_pragma (c_parser
*parser
)
787 gcc_assert (!parser
->in_pragma
);
788 gcc_assert (parser
->tokens_avail
>= 1);
789 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
790 if (parser
->tokens
!= &parser
->tokens_buf
[0])
792 else if (parser
->tokens_avail
== 2)
793 parser
->tokens
[0] = parser
->tokens
[1];
794 parser
->tokens_avail
--;
795 parser
->in_pragma
= true;
798 /* Update the global input_location from TOKEN. */
800 c_parser_set_source_position_from_token (c_token
*token
)
802 if (token
->type
!= CPP_EOF
)
804 input_location
= token
->location
;
808 /* Helper function for c_parser_error.
809 Having peeked a token of kind TOK1_KIND that might signify
810 a conflict marker, peek successor tokens to determine
811 if we actually do have a conflict marker.
812 Specifically, we consider a run of 7 '<', '=' or '>' characters
813 at the start of a line as a conflict marker.
814 These come through the lexer as three pairs and a single,
815 e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<').
816 If it returns true, *OUT_LOC is written to with the location/range
820 c_parser_peek_conflict_marker (c_parser
*parser
, enum cpp_ttype tok1_kind
,
823 c_token
*token2
= c_parser_peek_2nd_token (parser
);
824 if (token2
->type
!= tok1_kind
)
826 c_token
*token3
= c_parser_peek_nth_token (parser
, 3);
827 if (token3
->type
!= tok1_kind
)
829 c_token
*token4
= c_parser_peek_nth_token (parser
, 4);
830 if (token4
->type
!= conflict_marker_get_final_tok_kind (tok1_kind
))
833 /* It must be at the start of the line. */
834 location_t start_loc
= c_parser_peek_token (parser
)->location
;
835 if (LOCATION_COLUMN (start_loc
) != 1)
838 /* We have a conflict marker. Construct a location of the form:
841 with start == caret, finishing at the end of the marker. */
842 location_t finish_loc
= get_finish (token4
->location
);
843 *out_loc
= make_location (start_loc
, start_loc
, finish_loc
);
848 /* Issue a diagnostic of the form
849 FILE:LINE: MESSAGE before TOKEN
850 where TOKEN is the next token in the input stream of PARSER.
851 MESSAGE (specified by the caller) is usually of the form "expected
854 Use RICHLOC as the location of the diagnostic.
856 Do not issue a diagnostic if still recovering from an error.
858 Return true iff an error was actually emitted.
860 ??? This is taken from the C++ parser, but building up messages in
861 this way is not i18n-friendly and some other approach should be
865 c_parser_error_richloc (c_parser
*parser
, const char *gmsgid
,
866 rich_location
*richloc
)
868 c_token
*token
= c_parser_peek_token (parser
);
871 parser
->error
= true;
875 /* If this is actually a conflict marker, report it as such. */
876 if (token
->type
== CPP_LSHIFT
877 || token
->type
== CPP_RSHIFT
878 || token
->type
== CPP_EQ_EQ
)
881 if (c_parser_peek_conflict_marker (parser
, token
->type
, &loc
))
883 error_at (loc
, "version control conflict marker in file");
888 c_parse_error (gmsgid
,
889 /* Because c_parse_error does not understand
890 CPP_KEYWORD, keywords are treated like
892 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
893 /* ??? The C parser does not save the cpp flags of a
894 token, we need to pass 0 here and we will not get
895 the source spelling of some tokens but rather the
896 canonical spelling. */
897 token
->value
, /*flags=*/0, richloc
);
901 /* As c_parser_error_richloc, but issue the message at the
902 location of PARSER's next token, or at input_location
903 if the next token is EOF. */
906 c_parser_error (c_parser
*parser
, const char *gmsgid
)
908 c_token
*token
= c_parser_peek_token (parser
);
909 c_parser_set_source_position_from_token (token
);
910 rich_location
richloc (line_table
, input_location
);
911 return c_parser_error_richloc (parser
, gmsgid
, &richloc
);
914 /* Some tokens naturally come in pairs e.g.'(' and ')'.
915 This class is for tracking such a matching pair of symbols.
916 In particular, it tracks the location of the first token,
917 so that if the second token is missing, we can highlight the
918 location of the first token when notifying the user about the
921 template <typename traits_t
>
925 /* token_pair's ctor. */
926 token_pair () : m_open_loc (UNKNOWN_LOCATION
) {}
928 /* If the next token is the opening symbol for this pair, consume it and
930 Otherwise, issue an error and return false.
931 In either case, record the location of the opening token. */
933 bool require_open (c_parser
*parser
)
935 c_token
*token
= c_parser_peek_token (parser
);
937 m_open_loc
= token
->location
;
939 return c_parser_require (parser
, traits_t::open_token_type
,
940 traits_t::open_gmsgid
);
943 /* Consume the next token from PARSER, recording its location as
944 that of the opening token within the pair. */
946 void consume_open (c_parser
*parser
)
948 c_token
*token
= c_parser_peek_token (parser
);
949 gcc_assert (token
->type
== traits_t::open_token_type
);
950 m_open_loc
= token
->location
;
951 c_parser_consume_token (parser
);
954 /* If the next token is the closing symbol for this pair, consume it
956 Otherwise, issue an error, highlighting the location of the
957 corresponding opening token, and return false. */
959 bool require_close (c_parser
*parser
) const
961 return c_parser_require (parser
, traits_t::close_token_type
,
962 traits_t::close_gmsgid
, m_open_loc
);
965 /* Like token_pair::require_close, except that tokens will be skipped
966 until the desired token is found. An error message is still produced
967 if the next token is not as expected. */
969 void skip_until_found_close (c_parser
*parser
) const
971 c_parser_skip_until_found (parser
, traits_t::close_token_type
,
972 traits_t::close_gmsgid
, m_open_loc
);
976 location_t m_open_loc
;
979 /* Traits for token_pair<T> for tracking matching pairs of parentheses. */
981 struct matching_paren_traits
983 static const enum cpp_ttype open_token_type
= CPP_OPEN_PAREN
;
984 static const char * const open_gmsgid
;
985 static const enum cpp_ttype close_token_type
= CPP_CLOSE_PAREN
;
986 static const char * const close_gmsgid
;
989 const char * const matching_paren_traits::open_gmsgid
= "expected %<(%>";
990 const char * const matching_paren_traits::close_gmsgid
= "expected %<)%>";
992 /* "matching_parens" is a token_pair<T> class for tracking matching
993 pairs of parentheses. */
995 typedef token_pair
<matching_paren_traits
> matching_parens
;
997 /* Traits for token_pair<T> for tracking matching pairs of braces. */
999 struct matching_brace_traits
1001 static const enum cpp_ttype open_token_type
= CPP_OPEN_BRACE
;
1002 static const char * const open_gmsgid
;
1003 static const enum cpp_ttype close_token_type
= CPP_CLOSE_BRACE
;
1004 static const char * const close_gmsgid
;
1007 const char * const matching_brace_traits::open_gmsgid
= "expected %<{%>";
1008 const char * const matching_brace_traits::close_gmsgid
= "expected %<}%>";
1010 /* "matching_braces" is a token_pair<T> class for tracking matching
1013 typedef token_pair
<matching_brace_traits
> matching_braces
;
1015 /* Get a description of the matching symbol to TYPE e.g. "(" for
1019 get_matching_symbol (enum cpp_ttype type
)
1026 case CPP_CLOSE_PAREN
:
1028 case CPP_CLOSE_BRACE
:
1033 /* If the next token is of the indicated TYPE, consume it. Otherwise,
1034 issue the error MSGID. If MSGID is NULL then a message has already
1035 been produced and no message will be produced this time. Returns
1036 true if found, false otherwise.
1038 If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1039 within any error as the location of an "opening" token matching
1040 the close token TYPE (e.g. the location of the '(' when TYPE is
1043 If TYPE_IS_UNIQUE is true (the default) then msgid describes exactly
1044 one type (e.g. "expected %<)%>") and thus it may be reasonable to
1045 attempt to generate a fix-it hint for the problem.
1046 Otherwise msgid describes multiple token types (e.g.
1047 "expected %<;%>, %<,%> or %<)%>"), and thus we shouldn't attempt to
1048 generate a fix-it hint. */
1051 c_parser_require (c_parser
*parser
,
1052 enum cpp_ttype type
,
1054 location_t matching_location
,
1055 bool type_is_unique
)
1057 if (c_parser_next_token_is (parser
, type
))
1059 c_parser_consume_token (parser
);
1064 location_t next_token_loc
= c_parser_peek_token (parser
)->location
;
1065 gcc_rich_location
richloc (next_token_loc
);
1067 /* Potentially supply a fix-it hint, suggesting to add the
1068 missing token immediately after the *previous* token.
1069 This may move the primary location within richloc. */
1070 if (!parser
->error
&& type_is_unique
)
1071 maybe_suggest_missing_token_insertion (&richloc
, type
,
1072 parser
->last_token_location
);
1074 /* If matching_location != UNKNOWN_LOCATION, highlight it.
1075 Attempt to consolidate diagnostics by printing it as a
1076 secondary range within the main diagnostic. */
1077 bool added_matching_location
= false;
1078 if (matching_location
!= UNKNOWN_LOCATION
)
1079 added_matching_location
1080 = richloc
.add_location_if_nearby (matching_location
);
1082 if (c_parser_error_richloc (parser
, msgid
, &richloc
))
1083 /* If we weren't able to consolidate matching_location, then
1084 print it as a secondary diagnostic. */
1085 if (matching_location
!= UNKNOWN_LOCATION
&& !added_matching_location
)
1086 inform (matching_location
, "to match this %qs",
1087 get_matching_symbol (type
));
1093 /* If the next token is the indicated keyword, consume it. Otherwise,
1094 issue the error MSGID. Returns true if found, false otherwise. */
1097 c_parser_require_keyword (c_parser
*parser
,
1101 if (c_parser_next_token_is_keyword (parser
, keyword
))
1103 c_parser_consume_token (parser
);
1108 c_parser_error (parser
, msgid
);
1113 /* Like c_parser_require, except that tokens will be skipped until the
1114 desired token is found. An error message is still produced if the
1115 next token is not as expected. If MSGID is NULL then a message has
1116 already been produced and no message will be produced this
1119 If MATCHING_LOCATION is not UNKNOWN_LOCATION, then highlight it
1120 within any error as the location of an "opening" token matching
1121 the close token TYPE (e.g. the location of the '(' when TYPE is
1122 CPP_CLOSE_PAREN). */
1125 c_parser_skip_until_found (c_parser
*parser
,
1126 enum cpp_ttype type
,
1128 location_t matching_location
)
1130 unsigned nesting_depth
= 0;
1132 if (c_parser_require (parser
, type
, msgid
, matching_location
))
1135 /* Skip tokens until the desired token is found. */
1138 /* Peek at the next token. */
1139 c_token
*token
= c_parser_peek_token (parser
);
1140 /* If we've reached the token we want, consume it and stop. */
1141 if (token
->type
== type
&& !nesting_depth
)
1143 c_parser_consume_token (parser
);
1147 /* If we've run out of tokens, stop. */
1148 if (token
->type
== CPP_EOF
)
1150 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1152 if (token
->type
== CPP_OPEN_BRACE
1153 || token
->type
== CPP_OPEN_PAREN
1154 || token
->type
== CPP_OPEN_SQUARE
)
1156 else if (token
->type
== CPP_CLOSE_BRACE
1157 || token
->type
== CPP_CLOSE_PAREN
1158 || token
->type
== CPP_CLOSE_SQUARE
)
1160 if (nesting_depth
-- == 0)
1163 /* Consume this token. */
1164 c_parser_consume_token (parser
);
1166 parser
->error
= false;
1169 /* Skip tokens until the end of a parameter is found, but do not
1170 consume the comma, semicolon or closing delimiter. */
1173 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
1175 unsigned nesting_depth
= 0;
1179 c_token
*token
= c_parser_peek_token (parser
);
1180 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
1183 /* If we've run out of tokens, stop. */
1184 if (token
->type
== CPP_EOF
)
1186 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1188 if (token
->type
== CPP_OPEN_BRACE
1189 || token
->type
== CPP_OPEN_PAREN
1190 || token
->type
== CPP_OPEN_SQUARE
)
1192 else if (token
->type
== CPP_CLOSE_BRACE
1193 || token
->type
== CPP_CLOSE_PAREN
1194 || token
->type
== CPP_CLOSE_SQUARE
)
1196 if (nesting_depth
-- == 0)
1199 /* Consume this token. */
1200 c_parser_consume_token (parser
);
1202 parser
->error
= false;
1205 /* Expect to be at the end of the pragma directive and consume an
1206 end of line marker. */
1209 c_parser_skip_to_pragma_eol (c_parser
*parser
, bool error_if_not_eol
= true)
1211 gcc_assert (parser
->in_pragma
);
1212 parser
->in_pragma
= false;
1214 if (error_if_not_eol
&& c_parser_peek_token (parser
)->type
!= CPP_PRAGMA_EOL
)
1215 c_parser_error (parser
, "expected end of line");
1217 cpp_ttype token_type
;
1220 c_token
*token
= c_parser_peek_token (parser
);
1221 token_type
= token
->type
;
1222 if (token_type
== CPP_EOF
)
1224 c_parser_consume_token (parser
);
1226 while (token_type
!= CPP_PRAGMA_EOL
);
1228 parser
->error
= false;
1231 /* Skip tokens until we have consumed an entire block, or until we
1232 have consumed a non-nested ';'. */
1235 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1237 unsigned nesting_depth
= 0;
1238 bool save_error
= parser
->error
;
1244 /* Peek at the next token. */
1245 token
= c_parser_peek_token (parser
);
1247 switch (token
->type
)
1252 case CPP_PRAGMA_EOL
:
1253 if (parser
->in_pragma
)
1258 /* If the next token is a ';', we have reached the
1259 end of the statement. */
1262 /* Consume the ';'. */
1263 c_parser_consume_token (parser
);
1268 case CPP_CLOSE_BRACE
:
1269 /* If the next token is a non-nested '}', then we have
1270 reached the end of the current block. */
1271 if (nesting_depth
== 0 || --nesting_depth
== 0)
1273 c_parser_consume_token (parser
);
1278 case CPP_OPEN_BRACE
:
1279 /* If it the next token is a '{', then we are entering a new
1280 block. Consume the entire block. */
1285 /* If we see a pragma, consume the whole thing at once. We
1286 have some safeguards against consuming pragmas willy-nilly.
1287 Normally, we'd expect to be here with parser->error set,
1288 which disables these safeguards. But it's possible to get
1289 here for secondary error recovery, after parser->error has
1291 c_parser_consume_pragma (parser
);
1292 c_parser_skip_to_pragma_eol (parser
);
1293 parser
->error
= save_error
;
1300 c_parser_consume_token (parser
);
1304 parser
->error
= false;
1307 /* CPP's options (initialized by c-opts.c). */
1308 extern cpp_options
*cpp_opts
;
1310 /* Save the warning flags which are controlled by __extension__. */
1313 disable_extension_diagnostics (void)
1316 | (warn_pointer_arith
<< 1)
1317 | (warn_traditional
<< 2)
1319 | (warn_long_long
<< 4)
1320 | (warn_cxx_compat
<< 5)
1321 | (warn_overlength_strings
<< 6)
1322 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1323 play tricks to properly restore it. */
1324 | ((warn_c90_c99_compat
== 1) << 7)
1325 | ((warn_c90_c99_compat
== -1) << 8)
1326 /* Similarly for warn_c99_c11_compat. */
1327 | ((warn_c99_c11_compat
== 1) << 9)
1328 | ((warn_c99_c11_compat
== -1) << 10)
1330 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1331 warn_pointer_arith
= 0;
1332 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1334 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1335 warn_cxx_compat
= 0;
1336 warn_overlength_strings
= 0;
1337 warn_c90_c99_compat
= 0;
1338 warn_c99_c11_compat
= 0;
1342 /* Restore the warning flags which are controlled by __extension__.
1343 FLAGS is the return value from disable_extension_diagnostics. */
1346 restore_extension_diagnostics (int flags
)
1348 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1349 warn_pointer_arith
= (flags
>> 1) & 1;
1350 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1351 flag_iso
= (flags
>> 3) & 1;
1352 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1353 warn_cxx_compat
= (flags
>> 5) & 1;
1354 warn_overlength_strings
= (flags
>> 6) & 1;
1355 /* See above for why is this needed. */
1356 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1357 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1360 /* Helper data structure for parsing #pragma acc routine. */
1361 struct oacc_routine_data
{
1362 bool error_seen
; /* Set if error has been reported. */
1363 bool fndecl_seen
; /* Set if one fn decl/definition has been seen already. */
1368 static void c_parser_external_declaration (c_parser
*);
1369 static void c_parser_asm_definition (c_parser
*);
1370 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1371 bool, bool, tree
*, vec
<c_token
>,
1372 struct oacc_routine_data
* = NULL
,
1374 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1375 static void c_parser_static_assert_declaration (c_parser
*);
1376 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1377 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1378 static tree
c_parser_struct_declaration (c_parser
*);
1379 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1380 static tree
c_parser_alignas_specifier (c_parser
*);
1381 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1383 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1385 struct c_declarator
*);
1386 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1387 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1389 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1390 static tree
c_parser_simple_asm_expr (c_parser
*);
1391 static tree
c_parser_attributes (c_parser
*);
1392 static struct c_expr
c_parser_initializer (c_parser
*);
1393 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool,
1395 static void c_parser_initelt (c_parser
*, struct obstack
*);
1396 static void c_parser_initval (c_parser
*, struct c_expr
*,
1398 static tree
c_parser_compound_statement (c_parser
*);
1399 static void c_parser_compound_statement_nostart (c_parser
*);
1400 static void c_parser_label (c_parser
*);
1401 static void c_parser_statement (c_parser
*, bool *, location_t
* = NULL
);
1402 static void c_parser_statement_after_labels (c_parser
*, bool *,
1403 vec
<tree
> * = NULL
);
1404 static tree
c_parser_c99_block_statement (c_parser
*, bool *,
1405 location_t
* = NULL
);
1406 static void c_parser_if_statement (c_parser
*, bool *, vec
<tree
> *);
1407 static void c_parser_switch_statement (c_parser
*, bool *);
1408 static void c_parser_while_statement (c_parser
*, bool, bool *);
1409 static void c_parser_do_statement (c_parser
*, bool);
1410 static void c_parser_for_statement (c_parser
*, bool, bool *);
1411 static tree
c_parser_asm_statement (c_parser
*);
1412 static tree
c_parser_asm_operands (c_parser
*);
1413 static tree
c_parser_asm_goto_operands (c_parser
*);
1414 static tree
c_parser_asm_clobbers (c_parser
*);
1415 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1417 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1418 struct c_expr
*, tree
);
1419 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1421 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1422 static struct c_expr
c_parser_unary_expression (c_parser
*);
1423 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1424 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1425 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1426 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1427 struct c_type_name
*,
1429 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1432 static tree
c_parser_transaction (c_parser
*, enum rid
);
1433 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1434 static tree
c_parser_transaction_cancel (c_parser
*);
1435 static struct c_expr
c_parser_expression (c_parser
*);
1436 static struct c_expr
c_parser_expression_conv (c_parser
*);
1437 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1438 vec
<tree
, va_gc
> **, location_t
*,
1439 tree
*, vec
<location_t
> *,
1440 unsigned int * = NULL
);
1441 static void c_parser_oacc_declare (c_parser
*);
1442 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1443 static void c_parser_oacc_update (c_parser
*);
1444 static void c_parser_omp_construct (c_parser
*, bool *);
1445 static void c_parser_omp_threadprivate (c_parser
*);
1446 static void c_parser_omp_barrier (c_parser
*);
1447 static void c_parser_omp_flush (c_parser
*);
1448 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1449 tree
, tree
*, bool *);
1450 static void c_parser_omp_taskwait (c_parser
*);
1451 static void c_parser_omp_taskyield (c_parser
*);
1452 static void c_parser_omp_cancel (c_parser
*);
1454 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1455 pragma_stmt
, pragma_compound
};
1456 static bool c_parser_pragma (c_parser
*, enum pragma_context
, bool *);
1457 static void c_parser_omp_cancellation_point (c_parser
*, enum pragma_context
);
1458 static bool c_parser_omp_target (c_parser
*, enum pragma_context
, bool *);
1459 static void c_parser_omp_end_declare_target (c_parser
*);
1460 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1461 static bool c_parser_omp_ordered (c_parser
*, enum pragma_context
, bool *);
1462 static void c_parser_oacc_routine (c_parser
*, enum pragma_context
);
1464 /* These Objective-C parser functions are only ever called when
1465 compiling Objective-C. */
1466 static void c_parser_objc_class_definition (c_parser
*, tree
);
1467 static void c_parser_objc_class_instance_variables (c_parser
*);
1468 static void c_parser_objc_class_declaration (c_parser
*);
1469 static void c_parser_objc_alias_declaration (c_parser
*);
1470 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1471 static bool c_parser_objc_method_type (c_parser
*);
1472 static void c_parser_objc_method_definition (c_parser
*);
1473 static void c_parser_objc_methodprotolist (c_parser
*);
1474 static void c_parser_objc_methodproto (c_parser
*);
1475 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1476 static tree
c_parser_objc_type_name (c_parser
*);
1477 static tree
c_parser_objc_protocol_refs (c_parser
*);
1478 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1479 static void c_parser_objc_synchronized_statement (c_parser
*);
1480 static tree
c_parser_objc_selector (c_parser
*);
1481 static tree
c_parser_objc_selector_arg (c_parser
*);
1482 static tree
c_parser_objc_receiver (c_parser
*);
1483 static tree
c_parser_objc_message_args (c_parser
*);
1484 static tree
c_parser_objc_keywordexpr (c_parser
*);
1485 static void c_parser_objc_at_property_declaration (c_parser
*);
1486 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1487 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1488 static bool c_parser_objc_diagnose_bad_element_prefix
1489 (c_parser
*, struct c_declspecs
*);
1491 static void c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
);
1493 /* Parse a translation unit (C90 6.7, C99 6.9, C11 6.9).
1496 external-declarations
1498 external-declarations:
1499 external-declaration
1500 external-declarations external-declaration
1509 c_parser_translation_unit (c_parser
*parser
)
1511 if (c_parser_next_token_is (parser
, CPP_EOF
))
1513 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1514 "ISO C forbids an empty translation unit");
1518 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1519 mark_valid_location_for_stdc_pragma (false);
1523 c_parser_external_declaration (parser
);
1524 obstack_free (&parser_obstack
, obstack_position
);
1526 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1531 FOR_EACH_VEC_ELT (incomplete_record_decls
, i
, decl
)
1532 if (DECL_SIZE (decl
) == NULL_TREE
&& TREE_TYPE (decl
) != error_mark_node
)
1533 error ("storage size of %q+D isn%'t known", decl
);
1536 /* Parse an external declaration (C90 6.7, C99 6.9, C11 6.9).
1538 external-declaration:
1544 external-declaration:
1547 __extension__ external-declaration
1551 external-declaration:
1552 objc-class-definition
1553 objc-class-declaration
1554 objc-alias-declaration
1555 objc-protocol-definition
1556 objc-method-definition
1561 c_parser_external_declaration (c_parser
*parser
)
1564 switch (c_parser_peek_token (parser
)->type
)
1567 switch (c_parser_peek_token (parser
)->keyword
)
1570 ext
= disable_extension_diagnostics ();
1571 c_parser_consume_token (parser
);
1572 c_parser_external_declaration (parser
);
1573 restore_extension_diagnostics (ext
);
1576 c_parser_asm_definition (parser
);
1578 case RID_AT_INTERFACE
:
1579 case RID_AT_IMPLEMENTATION
:
1580 gcc_assert (c_dialect_objc ());
1581 c_parser_objc_class_definition (parser
, NULL_TREE
);
1584 gcc_assert (c_dialect_objc ());
1585 c_parser_objc_class_declaration (parser
);
1588 gcc_assert (c_dialect_objc ());
1589 c_parser_objc_alias_declaration (parser
);
1591 case RID_AT_PROTOCOL
:
1592 gcc_assert (c_dialect_objc ());
1593 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1595 case RID_AT_PROPERTY
:
1596 gcc_assert (c_dialect_objc ());
1597 c_parser_objc_at_property_declaration (parser
);
1599 case RID_AT_SYNTHESIZE
:
1600 gcc_assert (c_dialect_objc ());
1601 c_parser_objc_at_synthesize_declaration (parser
);
1603 case RID_AT_DYNAMIC
:
1604 gcc_assert (c_dialect_objc ());
1605 c_parser_objc_at_dynamic_declaration (parser
);
1608 gcc_assert (c_dialect_objc ());
1609 c_parser_consume_token (parser
);
1610 objc_finish_implementation ();
1617 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1618 "ISO C does not allow extra %<;%> outside of a function");
1619 c_parser_consume_token (parser
);
1622 mark_valid_location_for_stdc_pragma (true);
1623 c_parser_pragma (parser
, pragma_external
, NULL
);
1624 mark_valid_location_for_stdc_pragma (false);
1628 if (c_dialect_objc ())
1630 c_parser_objc_method_definition (parser
);
1633 /* Else fall through, and yield a syntax error trying to parse
1634 as a declaration or function definition. */
1638 /* A declaration or a function definition (or, in Objective-C,
1639 an @interface or @protocol with prefix attributes). We can
1640 only tell which after parsing the declaration specifiers, if
1641 any, and the first declarator. */
1642 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1648 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1649 static void c_finish_oacc_routine (struct oacc_routine_data
*, tree
, bool);
1651 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1652 6.7, 6.9.1, C11 6.7, 6.9.1). If FNDEF_OK is true, a function definition
1653 is accepted; otherwise (old-style parameter declarations) only other
1654 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1655 assertion is accepted; otherwise (old-style parameter declarations)
1656 it is not. If NESTED is true, we are inside a function or parsing
1657 old-style parameter declarations; any functions encountered are
1658 nested functions and declaration specifiers are required; otherwise
1659 we are at top level and functions are normal functions and
1660 declaration specifiers may be optional. If EMPTY_OK is true, empty
1661 declarations are OK (subject to all other constraints); otherwise
1662 (old-style parameter declarations) they are diagnosed. If
1663 START_ATTR_OK is true, the declaration specifiers may start with
1664 attributes; otherwise they may not.
1665 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1666 declaration when parsing an Objective-C foreach statement.
1667 FALLTHRU_ATTR_P is used to signal whether this function parsed
1668 "__attribute__((fallthrough));".
1671 declaration-specifiers init-declarator-list[opt] ;
1672 static_assert-declaration
1674 function-definition:
1675 declaration-specifiers[opt] declarator declaration-list[opt]
1680 declaration-list declaration
1682 init-declarator-list:
1684 init-declarator-list , init-declarator
1687 declarator simple-asm-expr[opt] attributes[opt]
1688 declarator simple-asm-expr[opt] attributes[opt] = initializer
1692 nested-function-definition:
1693 declaration-specifiers declarator declaration-list[opt]
1699 attributes objc-class-definition
1700 attributes objc-category-definition
1701 attributes objc-protocol-definition
1703 The simple-asm-expr and attributes are GNU extensions.
1705 This function does not handle __extension__; that is handled in its
1706 callers. ??? Following the old parser, __extension__ may start
1707 external declarations, declarations in functions and declarations
1708 at the start of "for" loops, but not old-style parameter
1711 C99 requires declaration specifiers in a function definition; the
1712 absence is diagnosed through the diagnosis of implicit int. In GNU
1713 C we also allow but diagnose declarations without declaration
1714 specifiers, but only at top level (elsewhere they conflict with
1717 In Objective-C, declarations of the looping variable in a foreach
1718 statement are exceptionally terminated by 'in' (for example, 'for
1719 (NSObject *object in array) { ... }').
1724 threadprivate-directive
1728 gimple-function-definition:
1729 declaration-specifiers[opt] __GIMPLE (gimple-or-rtl-pass-list) declarator
1730 declaration-list[opt] compound-statement
1732 rtl-function-definition:
1733 declaration-specifiers[opt] __RTL (gimple-or-rtl-pass-list) declarator
1734 declaration-list[opt] compound-statement */
1737 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1738 bool static_assert_ok
, bool empty_ok
,
1739 bool nested
, bool start_attr_ok
,
1740 tree
*objc_foreach_object_declaration
,
1741 vec
<c_token
> omp_declare_simd_clauses
,
1742 struct oacc_routine_data
*oacc_routine_data
,
1743 bool *fallthru_attr_p
)
1745 struct c_declspecs
*specs
;
1747 tree all_prefix_attrs
;
1748 bool diagnosed_no_specs
= false;
1749 location_t here
= c_parser_peek_token (parser
)->location
;
1751 if (static_assert_ok
1752 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1754 c_parser_static_assert_declaration (parser
);
1757 specs
= build_null_declspecs ();
1759 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1760 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1761 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1762 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1763 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1764 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1766 tree name
= c_parser_peek_token (parser
)->value
;
1768 /* Issue a warning about NAME being an unknown type name, perhaps
1769 with some kind of hint.
1770 If the user forgot a "struct" etc, suggest inserting
1771 it. Otherwise, attempt to look for misspellings. */
1772 gcc_rich_location
richloc (here
);
1773 if (tag_exists_p (RECORD_TYPE
, name
))
1775 /* This is not C++ with its implicit typedef. */
1776 richloc
.add_fixit_insert_before ("struct ");
1778 "unknown type name %qE;"
1779 " use %<struct%> keyword to refer to the type",
1782 else if (tag_exists_p (UNION_TYPE
, name
))
1784 richloc
.add_fixit_insert_before ("union ");
1786 "unknown type name %qE;"
1787 " use %<union%> keyword to refer to the type",
1790 else if (tag_exists_p (ENUMERAL_TYPE
, name
))
1792 richloc
.add_fixit_insert_before ("enum ");
1794 "unknown type name %qE;"
1795 " use %<enum%> keyword to refer to the type",
1800 name_hint hint
= lookup_name_fuzzy (name
, FUZZY_LOOKUP_TYPENAME
,
1804 richloc
.add_fixit_replace (hint
.suggestion ());
1806 "unknown type name %qE; did you mean %qs?",
1807 name
, hint
.suggestion ());
1810 error_at (here
, "unknown type name %qE", name
);
1813 /* Parse declspecs normally to get a correct pointer type, but avoid
1814 a further "fails to be a type name" error. Refuse nested functions
1815 since it is not how the user likely wants us to recover. */
1816 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1817 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1818 c_parser_peek_token (parser
)->value
= error_mark_node
;
1822 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1823 true, true, cla_nonabstract_decl
);
1826 c_parser_skip_to_end_of_block_or_statement (parser
);
1829 if (nested
&& !specs
->declspecs_seen_p
)
1831 c_parser_error (parser
, "expected declaration specifiers");
1832 c_parser_skip_to_end_of_block_or_statement (parser
);
1836 finish_declspecs (specs
);
1837 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1838 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1841 error_at (here
, "%<__auto_type%> in empty declaration");
1842 else if (specs
->typespec_kind
== ctsk_none
1843 && attribute_fallthrough_p (specs
->attrs
))
1845 if (fallthru_attr_p
!= NULL
)
1846 *fallthru_attr_p
= true;
1847 tree fn
= build_call_expr_internal_loc (here
, IFN_FALLTHROUGH
,
1855 shadow_tag_warned (specs
, 1);
1856 pedwarn (here
, 0, "empty declaration");
1858 c_parser_consume_token (parser
);
1859 if (oacc_routine_data
)
1860 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1864 /* Provide better error recovery. Note that a type name here is usually
1865 better diagnosed as a redeclaration. */
1867 && specs
->typespec_kind
== ctsk_tagdef
1868 && c_parser_next_token_starts_declspecs (parser
)
1869 && !c_parser_next_token_is (parser
, CPP_NAME
))
1871 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1872 parser
->error
= false;
1873 shadow_tag_warned (specs
, 1);
1876 else if (c_dialect_objc () && !auto_type_p
)
1878 /* Prefix attributes are an error on method decls. */
1879 switch (c_parser_peek_token (parser
)->type
)
1883 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1887 warning_at (c_parser_peek_token (parser
)->location
,
1889 "prefix attributes are ignored for methods");
1890 specs
->attrs
= NULL_TREE
;
1893 c_parser_objc_method_definition (parser
);
1895 c_parser_objc_methodproto (parser
);
1901 /* This is where we parse 'attributes @interface ...',
1902 'attributes @implementation ...', 'attributes @protocol ...'
1903 (where attributes could be, for example, __attribute__
1906 switch (c_parser_peek_token (parser
)->keyword
)
1908 case RID_AT_INTERFACE
:
1910 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1912 c_parser_objc_class_definition (parser
, specs
->attrs
);
1916 case RID_AT_IMPLEMENTATION
:
1918 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1922 warning_at (c_parser_peek_token (parser
)->location
,
1924 "prefix attributes are ignored for implementations");
1925 specs
->attrs
= NULL_TREE
;
1927 c_parser_objc_class_definition (parser
, NULL_TREE
);
1931 case RID_AT_PROTOCOL
:
1933 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1935 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1942 case RID_AT_PROPERTY
:
1945 c_parser_error (parser
, "unexpected attribute");
1946 specs
->attrs
= NULL
;
1953 else if (attribute_fallthrough_p (specs
->attrs
))
1954 warning_at (here
, OPT_Wattributes
,
1955 "%<fallthrough%> attribute not followed by %<;%>");
1957 pending_xref_error ();
1958 prefix_attrs
= specs
->attrs
;
1959 all_prefix_attrs
= prefix_attrs
;
1960 specs
->attrs
= NULL_TREE
;
1963 struct c_declarator
*declarator
;
1966 tree fnbody
= NULL_TREE
;
1967 /* Declaring either one or more declarators (in which case we
1968 should diagnose if there were no declaration specifiers) or a
1969 function definition (in which case the diagnostic for
1970 implicit int suffices). */
1971 declarator
= c_parser_declarator (parser
,
1972 specs
->typespec_kind
!= ctsk_none
,
1973 C_DTR_NORMAL
, &dummy
);
1974 if (declarator
== NULL
)
1976 if (omp_declare_simd_clauses
.exists ())
1977 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1978 omp_declare_simd_clauses
);
1979 if (oacc_routine_data
)
1980 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1981 c_parser_skip_to_end_of_block_or_statement (parser
);
1984 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1987 "%<__auto_type%> requires a plain identifier"
1989 c_parser_skip_to_end_of_block_or_statement (parser
);
1992 if (c_parser_next_token_is (parser
, CPP_EQ
)
1993 || c_parser_next_token_is (parser
, CPP_COMMA
)
1994 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1995 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1996 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1997 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1999 tree asm_name
= NULL_TREE
;
2000 tree postfix_attrs
= NULL_TREE
;
2001 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
2003 diagnosed_no_specs
= true;
2004 pedwarn (here
, 0, "data definition has no type or storage class");
2006 /* Having seen a data definition, there cannot now be a
2007 function definition. */
2009 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
2010 asm_name
= c_parser_simple_asm_expr (parser
);
2011 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2013 postfix_attrs
= c_parser_attributes (parser
);
2014 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2016 /* This means there is an attribute specifier after
2017 the declarator in a function definition. Provide
2018 some more information for the user. */
2019 error_at (here
, "attributes should be specified before the "
2020 "declarator in a function definition");
2021 c_parser_skip_to_end_of_block_or_statement (parser
);
2025 if (c_parser_next_token_is (parser
, CPP_EQ
))
2029 location_t init_loc
;
2030 c_parser_consume_token (parser
);
2033 init_loc
= c_parser_peek_token (parser
)->location
;
2034 rich_location
richloc (line_table
, init_loc
);
2035 start_init (NULL_TREE
, asm_name
, global_bindings_p (), &richloc
);
2036 /* A parameter is initialized, which is invalid. Don't
2037 attempt to instrument the initializer. */
2038 int flag_sanitize_save
= flag_sanitize
;
2039 if (nested
&& !empty_ok
)
2041 init
= c_parser_expr_no_commas (parser
, NULL
);
2042 flag_sanitize
= flag_sanitize_save
;
2043 if (TREE_CODE (init
.value
) == COMPONENT_REF
2044 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
2046 "%<__auto_type%> used with a bit-field"
2048 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
2049 tree init_type
= TREE_TYPE (init
.value
);
2050 /* As with typeof, remove all qualifiers from atomic types. */
2051 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
2053 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
2054 bool vm_type
= variably_modified_type_p (init_type
,
2057 init
.value
= save_expr (init
.value
);
2059 specs
->typespec_kind
= ctsk_typeof
;
2060 specs
->locations
[cdw_typedef
] = init_loc
;
2061 specs
->typedef_p
= true;
2062 specs
->type
= init_type
;
2065 bool maybe_const
= true;
2066 tree type_expr
= c_fully_fold (init
.value
, false,
2068 specs
->expr_const_operands
&= maybe_const
;
2070 specs
->expr
= build2 (COMPOUND_EXPR
,
2071 TREE_TYPE (type_expr
),
2072 specs
->expr
, type_expr
);
2074 specs
->expr
= type_expr
;
2076 d
= start_decl (declarator
, specs
, true,
2077 chainon (postfix_attrs
, all_prefix_attrs
));
2079 d
= error_mark_node
;
2080 if (omp_declare_simd_clauses
.exists ())
2081 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
2082 omp_declare_simd_clauses
);
2086 /* The declaration of the variable is in effect while
2087 its initializer is parsed. */
2088 d
= start_decl (declarator
, specs
, true,
2089 chainon (postfix_attrs
, all_prefix_attrs
));
2091 d
= error_mark_node
;
2092 if (omp_declare_simd_clauses
.exists ())
2093 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
2094 omp_declare_simd_clauses
);
2095 init_loc
= c_parser_peek_token (parser
)->location
;
2096 rich_location
richloc (line_table
, init_loc
);
2097 start_init (d
, asm_name
, global_bindings_p (), &richloc
);
2098 /* A parameter is initialized, which is invalid. Don't
2099 attempt to instrument the initializer. */
2100 int flag_sanitize_save
= flag_sanitize
;
2101 if (TREE_CODE (d
) == PARM_DECL
)
2103 init
= c_parser_initializer (parser
);
2104 flag_sanitize
= flag_sanitize_save
;
2107 if (oacc_routine_data
)
2108 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2109 if (d
!= error_mark_node
)
2111 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
2112 finish_decl (d
, init_loc
, init
.value
,
2113 init
.original_type
, asm_name
);
2121 "%<__auto_type%> requires an initialized "
2122 "data declaration");
2123 c_parser_skip_to_end_of_block_or_statement (parser
);
2126 tree d
= start_decl (declarator
, specs
, false,
2127 chainon (postfix_attrs
,
2129 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
2130 if (declarator
->kind
== cdk_function
)
2131 if (DECL_ARGUMENTS (d
) == NULL_TREE
)
2132 DECL_ARGUMENTS (d
) = declarator
->u
.arg_info
->parms
;
2133 if (omp_declare_simd_clauses
.exists ())
2135 tree parms
= NULL_TREE
;
2136 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
2138 struct c_declarator
*ce
= declarator
;
2140 if (ce
->kind
== cdk_function
)
2142 parms
= ce
->u
.arg_info
->parms
;
2146 ce
= ce
->declarator
;
2149 temp_store_parm_decls (d
, parms
);
2150 c_finish_omp_declare_simd (parser
, d
, parms
,
2151 omp_declare_simd_clauses
);
2153 temp_pop_parm_decls ();
2155 if (oacc_routine_data
)
2156 c_finish_oacc_routine (oacc_routine_data
, d
, false);
2158 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
2159 NULL_TREE
, asm_name
);
2161 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2164 *objc_foreach_object_declaration
= d
;
2166 *objc_foreach_object_declaration
= error_mark_node
;
2169 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2174 "%<__auto_type%> may only be used with"
2175 " a single declarator");
2176 c_parser_skip_to_end_of_block_or_statement (parser
);
2179 c_parser_consume_token (parser
);
2180 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
2181 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
2184 all_prefix_attrs
= prefix_attrs
;
2187 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2189 c_parser_consume_token (parser
);
2192 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2194 /* This can only happen in Objective-C: we found the
2195 'in' that terminates the declaration inside an
2196 Objective-C foreach statement. Do not consume the
2197 token, so that the caller can use it to determine
2198 that this indeed is a foreach context. */
2203 c_parser_error (parser
, "expected %<,%> or %<;%>");
2204 c_parser_skip_to_end_of_block_or_statement (parser
);
2208 else if (auto_type_p
)
2211 "%<__auto_type%> requires an initialized data declaration");
2212 c_parser_skip_to_end_of_block_or_statement (parser
);
2217 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
2218 "%<asm%> or %<__attribute__%>");
2219 c_parser_skip_to_end_of_block_or_statement (parser
);
2222 /* Function definition (nested or otherwise). */
2225 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
2226 c_push_function_context ();
2228 if (!start_function (specs
, declarator
, all_prefix_attrs
))
2230 /* At this point we've consumed:
2231 declaration-specifiers declarator
2232 and the next token isn't CPP_EQ, CPP_COMMA, CPP_SEMICOLON,
2233 RID_ASM, RID_ATTRIBUTE, or RID_IN,
2235 declaration-specifiers declarator
2236 aren't grokkable as a function definition, so we have
2238 gcc_assert (!c_parser_next_token_is (parser
, CPP_SEMICOLON
));
2239 if (c_parser_next_token_starts_declspecs (parser
))
2242 declaration-specifiers declarator decl-specs
2243 then assume we have a missing semicolon, which would
2245 declaration-specifiers declarator decl-specs
2248 <~~~~~~~~~ declaration ~~~~~~~~~~>
2249 Use c_parser_require to get an error with a fix-it hint. */
2250 c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>");
2251 parser
->error
= false;
2255 /* This can appear in many cases looking nothing like a
2256 function definition, so we don't give a more specific
2257 error suggesting there was one. */
2258 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2259 "or %<__attribute__%>");
2262 c_pop_function_context ();
2266 if (DECL_DECLARED_INLINE_P (current_function_decl
))
2267 tv
= TV_PARSE_INLINE
;
2270 auto_timevar
at (g_timer
, tv
);
2272 /* Parse old-style parameter declarations. ??? Attributes are
2273 not allowed to start declaration specifiers here because of a
2274 syntax conflict between a function declaration with attribute
2275 suffix and a function definition with an attribute prefix on
2276 first old-style parameter declaration. Following the old
2277 parser, they are not accepted on subsequent old-style
2278 parameter declarations either. However, there is no
2279 ambiguity after the first declaration, nor indeed on the
2280 first as long as we don't allow postfix attributes after a
2281 declarator with a nonempty identifier list in a definition;
2282 and postfix attributes have never been accepted here in
2283 function definitions either. */
2284 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
2285 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
2286 c_parser_declaration_or_fndef (parser
, false, false, false,
2287 true, false, NULL
, vNULL
);
2288 store_parm_decls ();
2289 if (omp_declare_simd_clauses
.exists ())
2290 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
2291 omp_declare_simd_clauses
);
2292 if (oacc_routine_data
)
2293 c_finish_oacc_routine (oacc_routine_data
, current_function_decl
, true);
2294 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
2295 = c_parser_peek_token (parser
)->location
;
2297 /* If the definition was marked with __GIMPLE then parse the
2298 function body as GIMPLE. */
2299 if (specs
->gimple_p
)
2301 cfun
->pass_startwith
= specs
->gimple_or_rtl_pass
;
2302 bool saved
= in_late_binary_op
;
2303 in_late_binary_op
= true;
2304 c_parser_parse_gimple_body (parser
);
2305 in_late_binary_op
= saved
;
2307 /* Similarly, if it was marked with __RTL, use the RTL parser now,
2308 consuming the function body. */
2309 else if (specs
->rtl_p
)
2311 c_parser_parse_rtl_body (parser
, specs
->gimple_or_rtl_pass
);
2313 /* Normally, store_parm_decls sets next_is_function_body,
2314 anticipating a function body. We need a push_scope/pop_scope
2315 pair to flush out this state, or subsequent function parsing
2324 fnbody
= c_parser_compound_statement (parser
);
2325 tree fndecl
= current_function_decl
;
2328 tree decl
= current_function_decl
;
2329 /* Mark nested functions as needing static-chain initially.
2330 lower_nested_functions will recompute it but the
2331 DECL_STATIC_CHAIN flag is also used before that happens,
2332 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2333 DECL_STATIC_CHAIN (decl
) = 1;
2336 c_pop_function_context ();
2337 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
2345 /* Get rid of the empty stmt list for GIMPLE. */
2346 if (specs
->gimple_p
)
2347 DECL_SAVED_TREE (fndecl
) = NULL_TREE
;
2353 /* Parse an asm-definition (asm() outside a function body). This is a
2361 c_parser_asm_definition (c_parser
*parser
)
2363 tree asm_str
= c_parser_simple_asm_expr (parser
);
2365 symtab
->finalize_toplevel_asm (asm_str
);
2366 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2369 /* Parse a static assertion (C11 6.7.10).
2371 static_assert-declaration:
2372 static_assert-declaration-no-semi ;
2376 c_parser_static_assert_declaration (c_parser
*parser
)
2378 c_parser_static_assert_declaration_no_semi (parser
);
2380 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2381 c_parser_skip_to_end_of_block_or_statement (parser
);
2384 /* Parse a static assertion (C11 6.7.10), without the trailing
2387 static_assert-declaration-no-semi:
2388 _Static_assert ( constant-expression , string-literal )
2392 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2394 location_t assert_loc
, value_loc
;
2398 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2399 assert_loc
= c_parser_peek_token (parser
)->location
;
2401 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2402 "ISO C99 does not support %<_Static_assert%>");
2404 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2405 "ISO C90 does not support %<_Static_assert%>");
2406 c_parser_consume_token (parser
);
2407 matching_parens parens
;
2408 if (!parens
.require_open (parser
))
2410 location_t value_tok_loc
= c_parser_peek_token (parser
)->location
;
2411 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2412 value_loc
= EXPR_LOC_OR_LOC (value
, value_tok_loc
);
2413 parser
->lex_untranslated_string
= true;
2414 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2416 parser
->lex_untranslated_string
= false;
2419 switch (c_parser_peek_token (parser
)->type
)
2425 case CPP_UTF8STRING
:
2426 string
= c_parser_peek_token (parser
)->value
;
2427 c_parser_consume_token (parser
);
2428 parser
->lex_untranslated_string
= false;
2431 c_parser_error (parser
, "expected string literal");
2432 parser
->lex_untranslated_string
= false;
2435 parens
.require_close (parser
);
2437 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2439 error_at (value_loc
, "expression in static assertion is not an integer");
2442 if (TREE_CODE (value
) != INTEGER_CST
)
2444 value
= c_fully_fold (value
, false, NULL
);
2445 /* Strip no-op conversions. */
2446 STRIP_TYPE_NOPS (value
);
2447 if (TREE_CODE (value
) == INTEGER_CST
)
2448 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2449 "is not an integer constant expression");
2451 if (TREE_CODE (value
) != INTEGER_CST
)
2453 error_at (value_loc
, "expression in static assertion is not constant");
2456 constant_expression_warning (value
);
2457 if (integer_zerop (value
))
2458 error_at (assert_loc
, "static assertion failed: %E", string
);
2461 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2462 6.7, C11 6.7), adding them to SPECS (which may already include some).
2463 Storage class specifiers are accepted iff SCSPEC_OK; type
2464 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2465 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2466 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2468 declaration-specifiers:
2469 storage-class-specifier declaration-specifiers[opt]
2470 type-specifier declaration-specifiers[opt]
2471 type-qualifier declaration-specifiers[opt]
2472 function-specifier declaration-specifiers[opt]
2473 alignment-specifier declaration-specifiers[opt]
2475 Function specifiers (inline) are from C99, and are currently
2476 handled as storage class specifiers, as is __thread. Alignment
2477 specifiers are from C11.
2479 C90 6.5.1, C99 6.7.1, C11 6.7.1:
2480 storage-class-specifier:
2488 (_Thread_local is new in C11.)
2490 C99 6.7.4, C11 6.7.4:
2495 (_Noreturn is new in C11.)
2497 C90 6.5.2, C99 6.7.2, C11 6.7.2:
2510 [_Imaginary removed in C99 TC2]
2511 struct-or-union-specifier
2514 atomic-type-specifier
2516 (_Bool and _Complex are new in C99.)
2517 (atomic-type-specifier is new in C11.)
2519 C90 6.5.3, C99 6.7.3, C11 6.7.3:
2525 address-space-qualifier
2528 (restrict is new in C99.)
2529 (_Atomic is new in C11.)
2533 declaration-specifiers:
2534 attributes declaration-specifiers[opt]
2540 identifier recognized by the target
2542 storage-class-specifier:
2556 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2557 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2559 atomic-type-specifier
2560 _Atomic ( type-name )
2565 class-name objc-protocol-refs[opt]
2566 typedef-name objc-protocol-refs
2571 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2572 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2573 bool alignspec_ok
, bool auto_type_ok
,
2574 enum c_lookahead_kind la
)
2576 bool attrs_ok
= start_attr_ok
;
2577 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2580 gcc_assert (la
== cla_prefer_id
);
2582 while (c_parser_next_token_is (parser
, CPP_NAME
)
2583 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2584 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2586 struct c_typespec t
;
2589 location_t loc
= c_parser_peek_token (parser
)->location
;
2591 /* If we cannot accept a type, exit if the next token must start
2592 one. Also, if we already have seen a tagged definition,
2593 a typename would be an error anyway and likely the user
2594 has simply forgotten a semicolon, so we exit. */
2595 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2596 && c_parser_next_tokens_start_typename (parser
, la
)
2597 && !c_parser_next_token_is_qualifier (parser
))
2600 if (c_parser_next_token_is (parser
, CPP_NAME
))
2602 c_token
*name_token
= c_parser_peek_token (parser
);
2603 tree value
= name_token
->value
;
2604 c_id_kind kind
= name_token
->id_kind
;
2606 if (kind
== C_ID_ADDRSPACE
)
2609 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2610 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2611 c_parser_consume_token (parser
);
2616 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2618 /* If we cannot accept a type, and the next token must start one,
2619 exit. Do the same if we already have seen a tagged definition,
2620 since it would be an error anyway and likely the user has simply
2621 forgotten a semicolon. */
2622 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2625 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2626 a C_ID_CLASSNAME. */
2627 c_parser_consume_token (parser
);
2630 if (kind
== C_ID_ID
)
2632 error_at (loc
, "unknown type name %qE", value
);
2633 t
.kind
= ctsk_typedef
;
2634 t
.spec
= error_mark_node
;
2636 else if (kind
== C_ID_TYPENAME
2637 && (!c_dialect_objc ()
2638 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2640 t
.kind
= ctsk_typedef
;
2641 /* For a typedef name, record the meaning, not the name.
2642 In case of 'foo foo, bar;'. */
2643 t
.spec
= lookup_name (value
);
2647 tree proto
= NULL_TREE
;
2648 gcc_assert (c_dialect_objc ());
2650 if (c_parser_next_token_is (parser
, CPP_LESS
))
2651 proto
= c_parser_objc_protocol_refs (parser
);
2652 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2655 t
.expr_const_operands
= true;
2656 declspecs_add_type (name_token
->location
, specs
, t
);
2659 if (c_parser_next_token_is (parser
, CPP_LESS
))
2661 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2662 nisse@lysator.liu.se. */
2664 gcc_assert (c_dialect_objc ());
2665 if (!typespec_ok
|| seen_type
)
2667 proto
= c_parser_objc_protocol_refs (parser
);
2669 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2671 t
.expr_const_operands
= true;
2672 declspecs_add_type (loc
, specs
, t
);
2675 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2676 switch (c_parser_peek_token (parser
)->keyword
)
2689 /* TODO: Distinguish between function specifiers (inline, noreturn)
2690 and storage class specifiers, either here or in
2691 declspecs_add_scspec. */
2692 declspecs_add_scspec (loc
, specs
,
2693 c_parser_peek_token (parser
)->value
);
2694 c_parser_consume_token (parser
);
2726 if (c_dialect_objc ())
2727 parser
->objc_need_raw_identifier
= true;
2728 t
.kind
= ctsk_resword
;
2729 t
.spec
= c_parser_peek_token (parser
)->value
;
2731 t
.expr_const_operands
= true;
2732 declspecs_add_type (loc
, specs
, t
);
2733 c_parser_consume_token (parser
);
2740 t
= c_parser_enum_specifier (parser
);
2741 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2742 declspecs_add_type (loc
, specs
, t
);
2750 t
= c_parser_struct_or_union_specifier (parser
);
2751 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2752 declspecs_add_type (loc
, specs
, t
);
2755 /* ??? The old parser rejected typeof after other type
2756 specifiers, but is a syntax error the best way of
2758 if (!typespec_ok
|| seen_type
)
2762 t
= c_parser_typeof_specifier (parser
);
2763 declspecs_add_type (loc
, specs
, t
);
2766 /* C parser handling of Objective-C constructs needs
2767 checking for correct lvalue-to-rvalue conversions, and
2768 the code in build_modify_expr handling various
2769 Objective-C cases, and that in build_unary_op handling
2770 Objective-C cases for increment / decrement, also needs
2771 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2772 and objc_types_are_equivalent may also need updates. */
2773 if (c_dialect_objc ())
2774 sorry ("%<_Atomic%> in Objective-C");
2776 pedwarn_c99 (loc
, OPT_Wpedantic
,
2777 "ISO C99 does not support the %<_Atomic%> qualifier");
2779 pedwarn_c99 (loc
, OPT_Wpedantic
,
2780 "ISO C90 does not support the %<_Atomic%> qualifier");
2783 value
= c_parser_peek_token (parser
)->value
;
2784 c_parser_consume_token (parser
);
2785 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2787 /* _Atomic ( type-name ). */
2789 c_parser_consume_token (parser
);
2790 struct c_type_name
*type
= c_parser_type_name (parser
);
2791 t
.kind
= ctsk_typeof
;
2792 t
.spec
= error_mark_node
;
2794 t
.expr_const_operands
= true;
2796 t
.spec
= groktypename (type
, &t
.expr
,
2797 &t
.expr_const_operands
);
2798 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2800 if (t
.spec
!= error_mark_node
)
2802 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2803 error_at (loc
, "%<_Atomic%>-qualified array type");
2804 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2805 error_at (loc
, "%<_Atomic%>-qualified function type");
2806 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2807 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2809 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2811 declspecs_add_type (loc
, specs
, t
);
2814 declspecs_add_qual (loc
, specs
, value
);
2820 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2821 c_parser_consume_token (parser
);
2826 attrs
= c_parser_attributes (parser
);
2827 declspecs_add_attrs (loc
, specs
, attrs
);
2832 align
= c_parser_alignas_specifier (parser
);
2833 declspecs_add_alignas (loc
, specs
, align
);
2837 error_at (loc
, "%<__GIMPLE%> only valid with -fgimple");
2838 c_parser_consume_token (parser
);
2839 specs
->gimple_p
= true;
2840 specs
->locations
[cdw_gimple
] = loc
;
2841 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2844 c_parser_consume_token (parser
);
2845 specs
->rtl_p
= true;
2846 specs
->locations
[cdw_rtl
] = loc
;
2847 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2856 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2, C11 6.7.2.2).
2859 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2860 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2861 enum attributes[opt] identifier
2863 The form with trailing comma is new in C99. The forms with
2864 attributes are GNU extensions. In GNU C, we accept any expression
2865 without commas in the syntax (assignment expressions, not just
2866 conditional expressions); assignment expressions will be diagnosed
2871 enumerator-list , enumerator
2874 enumeration-constant
2875 enumeration-constant = constant-expression
2880 enumeration-constant attributes[opt]
2881 enumeration-constant attributes[opt] = constant-expression
2885 static struct c_typespec
2886 c_parser_enum_specifier (c_parser
*parser
)
2888 struct c_typespec ret
;
2890 tree ident
= NULL_TREE
;
2891 location_t enum_loc
;
2892 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2893 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2894 c_parser_consume_token (parser
);
2895 attrs
= c_parser_attributes (parser
);
2896 enum_loc
= c_parser_peek_token (parser
)->location
;
2897 /* Set the location in case we create a decl now. */
2898 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2899 if (c_parser_next_token_is (parser
, CPP_NAME
))
2901 ident
= c_parser_peek_token (parser
)->value
;
2902 ident_loc
= c_parser_peek_token (parser
)->location
;
2903 enum_loc
= ident_loc
;
2904 c_parser_consume_token (parser
);
2906 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2908 /* Parse an enum definition. */
2909 struct c_enum_contents the_enum
;
2912 /* We chain the enumerators in reverse order, then put them in
2913 forward order at the end. */
2915 timevar_push (TV_PARSE_ENUM
);
2916 type
= start_enum (enum_loc
, &the_enum
, ident
);
2918 c_parser_consume_token (parser
);
2926 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2927 location_t decl_loc
, value_loc
;
2928 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2930 /* Give a nicer error for "enum {}". */
2931 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2934 error_at (c_parser_peek_token (parser
)->location
,
2935 "empty enum is invalid");
2936 parser
->error
= true;
2939 c_parser_error (parser
, "expected identifier");
2940 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2941 values
= error_mark_node
;
2944 token
= c_parser_peek_token (parser
);
2945 enum_id
= token
->value
;
2946 /* Set the location in case we create a decl now. */
2947 c_parser_set_source_position_from_token (token
);
2948 decl_loc
= value_loc
= token
->location
;
2949 c_parser_consume_token (parser
);
2950 /* Parse any specified attributes. */
2951 tree enum_attrs
= c_parser_attributes (parser
);
2952 if (c_parser_next_token_is (parser
, CPP_EQ
))
2954 c_parser_consume_token (parser
);
2955 value_loc
= c_parser_peek_token (parser
)->location
;
2956 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2959 enum_value
= NULL_TREE
;
2960 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2961 &the_enum
, enum_id
, enum_value
);
2963 decl_attributes (&TREE_PURPOSE (enum_decl
), enum_attrs
, 0);
2964 TREE_CHAIN (enum_decl
) = values
;
2967 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2969 comma_loc
= c_parser_peek_token (parser
)->location
;
2971 c_parser_consume_token (parser
);
2973 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2976 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2977 "comma at end of enumerator list");
2978 c_parser_consume_token (parser
);
2983 c_parser_error (parser
, "expected %<,%> or %<}%>");
2984 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2985 values
= error_mark_node
;
2989 postfix_attrs
= c_parser_attributes (parser
);
2990 ret
.spec
= finish_enum (type
, nreverse (values
),
2991 chainon (attrs
, postfix_attrs
));
2992 ret
.kind
= ctsk_tagdef
;
2993 ret
.expr
= NULL_TREE
;
2994 ret
.expr_const_operands
= true;
2995 timevar_pop (TV_PARSE_ENUM
);
3000 c_parser_error (parser
, "expected %<{%>");
3001 ret
.spec
= error_mark_node
;
3002 ret
.kind
= ctsk_tagref
;
3003 ret
.expr
= NULL_TREE
;
3004 ret
.expr_const_operands
= true;
3007 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
3008 /* In ISO C, enumerated types can be referred to only if already
3010 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
3013 pedwarn (enum_loc
, OPT_Wpedantic
,
3014 "ISO C forbids forward references to %<enum%> types");
3019 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1).
3021 struct-or-union-specifier:
3022 struct-or-union attributes[opt] identifier[opt]
3023 { struct-contents } attributes[opt]
3024 struct-or-union attributes[opt] identifier
3027 struct-declaration-list
3029 struct-declaration-list:
3030 struct-declaration ;
3031 struct-declaration-list struct-declaration ;
3038 struct-declaration-list struct-declaration
3040 struct-declaration-list:
3041 struct-declaration-list ;
3044 (Note that in the syntax here, unlike that in ISO C, the semicolons
3045 are included here rather than in struct-declaration, in order to
3046 describe the syntax with extra semicolons and missing semicolon at
3051 struct-declaration-list:
3052 @defs ( class-name )
3054 (Note this does not include a trailing semicolon, but can be
3055 followed by further declarations, and gets a pedwarn-if-pedantic
3056 when followed by a semicolon.) */
3058 static struct c_typespec
3059 c_parser_struct_or_union_specifier (c_parser
*parser
)
3061 struct c_typespec ret
;
3063 tree ident
= NULL_TREE
;
3064 location_t struct_loc
;
3065 location_t ident_loc
= UNKNOWN_LOCATION
;
3066 enum tree_code code
;
3067 switch (c_parser_peek_token (parser
)->keyword
)
3078 struct_loc
= c_parser_peek_token (parser
)->location
;
3079 c_parser_consume_token (parser
);
3080 attrs
= c_parser_attributes (parser
);
3082 /* Set the location in case we create a decl now. */
3083 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
3085 if (c_parser_next_token_is (parser
, CPP_NAME
))
3087 ident
= c_parser_peek_token (parser
)->value
;
3088 ident_loc
= c_parser_peek_token (parser
)->location
;
3089 struct_loc
= ident_loc
;
3090 c_parser_consume_token (parser
);
3092 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
3094 /* Parse a struct or union definition. Start the scope of the
3095 tag before parsing components. */
3096 struct c_struct_parse_info
*struct_info
;
3097 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
3099 /* We chain the components in reverse order, then put them in
3100 forward order at the end. Each struct-declaration may
3101 declare multiple components (comma-separated), so we must use
3102 chainon to join them, although when parsing each
3103 struct-declaration we can use TREE_CHAIN directly.
3105 The theory behind all this is that there will be more
3106 semicolon separated fields than comma separated fields, and
3107 so we'll be minimizing the number of node traversals required
3110 timevar_push (TV_PARSE_STRUCT
);
3111 contents
= NULL_TREE
;
3112 c_parser_consume_token (parser
);
3113 /* Handle the Objective-C @defs construct,
3114 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
3115 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
3118 gcc_assert (c_dialect_objc ());
3119 c_parser_consume_token (parser
);
3120 matching_parens parens
;
3121 if (!parens
.require_open (parser
))
3123 if (c_parser_next_token_is (parser
, CPP_NAME
)
3124 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
3126 name
= c_parser_peek_token (parser
)->value
;
3127 c_parser_consume_token (parser
);
3131 c_parser_error (parser
, "expected class name");
3132 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3135 parens
.skip_until_found_close (parser
);
3136 contents
= nreverse (objc_get_class_ivars (name
));
3139 /* Parse the struct-declarations and semicolons. Problems with
3140 semicolons are diagnosed here; empty structures are diagnosed
3145 /* Parse any stray semicolon. */
3146 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3148 location_t semicolon_loc
3149 = c_parser_peek_token (parser
)->location
;
3150 gcc_rich_location
richloc (semicolon_loc
);
3151 richloc
.add_fixit_remove ();
3152 pedwarn (&richloc
, OPT_Wpedantic
,
3153 "extra semicolon in struct or union specified");
3154 c_parser_consume_token (parser
);
3157 /* Stop if at the end of the struct or union contents. */
3158 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3160 c_parser_consume_token (parser
);
3163 /* Accept #pragmas at struct scope. */
3164 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3166 c_parser_pragma (parser
, pragma_struct
, NULL
);
3169 /* Parse some comma-separated declarations, but not the
3170 trailing semicolon if any. */
3171 decls
= c_parser_struct_declaration (parser
);
3172 contents
= chainon (decls
, contents
);
3173 /* If no semicolon follows, either we have a parse error or
3174 are at the end of the struct or union and should
3176 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3177 c_parser_consume_token (parser
);
3180 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3181 pedwarn (c_parser_peek_token (parser
)->location
, 0,
3182 "no semicolon at end of struct or union");
3183 else if (parser
->error
3184 || !c_parser_next_token_starts_declspecs (parser
))
3186 c_parser_error (parser
, "expected %<;%>");
3187 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
3191 /* If we come here, we have already emitted an error
3192 for an expected `;', identifier or `(', and we also
3193 recovered already. Go on with the next field. */
3196 postfix_attrs
= c_parser_attributes (parser
);
3197 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
3198 chainon (attrs
, postfix_attrs
), struct_info
);
3199 ret
.kind
= ctsk_tagdef
;
3200 ret
.expr
= NULL_TREE
;
3201 ret
.expr_const_operands
= true;
3202 timevar_pop (TV_PARSE_STRUCT
);
3207 c_parser_error (parser
, "expected %<{%>");
3208 ret
.spec
= error_mark_node
;
3209 ret
.kind
= ctsk_tagref
;
3210 ret
.expr
= NULL_TREE
;
3211 ret
.expr_const_operands
= true;
3214 ret
= parser_xref_tag (ident_loc
, code
, ident
);
3218 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1),
3219 *without* the trailing semicolon.
3222 specifier-qualifier-list struct-declarator-list
3223 static_assert-declaration-no-semi
3225 specifier-qualifier-list:
3226 type-specifier specifier-qualifier-list[opt]
3227 type-qualifier specifier-qualifier-list[opt]
3228 attributes specifier-qualifier-list[opt]
3230 struct-declarator-list:
3232 struct-declarator-list , attributes[opt] struct-declarator
3235 declarator attributes[opt]
3236 declarator[opt] : constant-expression attributes[opt]
3241 __extension__ struct-declaration
3242 specifier-qualifier-list
3244 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
3245 of attributes where shown is a GNU extension. In GNU C, we accept
3246 any expression without commas in the syntax (assignment
3247 expressions, not just conditional expressions); assignment
3248 expressions will be diagnosed as non-constant. */
3251 c_parser_struct_declaration (c_parser
*parser
)
3253 struct c_declspecs
*specs
;
3255 tree all_prefix_attrs
;
3257 location_t decl_loc
;
3258 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3262 ext
= disable_extension_diagnostics ();
3263 c_parser_consume_token (parser
);
3264 decl
= c_parser_struct_declaration (parser
);
3265 restore_extension_diagnostics (ext
);
3268 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
3270 c_parser_static_assert_declaration_no_semi (parser
);
3273 specs
= build_null_declspecs ();
3274 decl_loc
= c_parser_peek_token (parser
)->location
;
3275 /* Strictly by the standard, we shouldn't allow _Alignas here,
3276 but it appears to have been intended to allow it there, so
3277 we're keeping it as it is until WG14 reaches a conclusion
3279 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
3280 c_parser_declspecs (parser
, specs
, false, true, true,
3281 true, false, cla_nonabstract_decl
);
3284 if (!specs
->declspecs_seen_p
)
3286 c_parser_error (parser
, "expected specifier-qualifier-list");
3289 finish_declspecs (specs
);
3290 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3291 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3294 if (specs
->typespec_kind
== ctsk_none
)
3296 pedwarn (decl_loc
, OPT_Wpedantic
,
3297 "ISO C forbids member declarations with no members");
3298 shadow_tag_warned (specs
, pedantic
);
3303 /* Support for unnamed structs or unions as members of
3304 structs or unions (which is [a] useful and [b] supports
3308 ret
= grokfield (c_parser_peek_token (parser
)->location
,
3309 build_id_declarator (NULL_TREE
), specs
,
3312 decl_attributes (&ret
, attrs
, 0);
3317 /* Provide better error recovery. Note that a type name here is valid,
3318 and will be treated as a field name. */
3319 if (specs
->typespec_kind
== ctsk_tagdef
3320 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
3321 && c_parser_next_token_starts_declspecs (parser
)
3322 && !c_parser_next_token_is (parser
, CPP_NAME
))
3324 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
3325 parser
->error
= false;
3329 pending_xref_error ();
3330 prefix_attrs
= specs
->attrs
;
3331 all_prefix_attrs
= prefix_attrs
;
3332 specs
->attrs
= NULL_TREE
;
3336 /* Declaring one or more declarators or un-named bit-fields. */
3337 struct c_declarator
*declarator
;
3339 if (c_parser_next_token_is (parser
, CPP_COLON
))
3340 declarator
= build_id_declarator (NULL_TREE
);
3342 declarator
= c_parser_declarator (parser
,
3343 specs
->typespec_kind
!= ctsk_none
,
3344 C_DTR_NORMAL
, &dummy
);
3345 if (declarator
== NULL
)
3347 c_parser_skip_to_end_of_block_or_statement (parser
);
3350 if (c_parser_next_token_is (parser
, CPP_COLON
)
3351 || c_parser_next_token_is (parser
, CPP_COMMA
)
3352 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3353 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
3354 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3356 tree postfix_attrs
= NULL_TREE
;
3357 tree width
= NULL_TREE
;
3359 if (c_parser_next_token_is (parser
, CPP_COLON
))
3361 c_parser_consume_token (parser
);
3362 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
3364 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3365 postfix_attrs
= c_parser_attributes (parser
);
3366 d
= grokfield (c_parser_peek_token (parser
)->location
,
3367 declarator
, specs
, width
, &all_prefix_attrs
);
3368 decl_attributes (&d
, chainon (postfix_attrs
,
3369 all_prefix_attrs
), 0);
3370 DECL_CHAIN (d
) = decls
;
3372 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3373 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
3376 all_prefix_attrs
= prefix_attrs
;
3377 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3378 c_parser_consume_token (parser
);
3379 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3380 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3382 /* Semicolon consumed in caller. */
3387 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3393 c_parser_error (parser
,
3394 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3395 "%<__attribute__%>");
3402 /* Parse a typeof specifier (a GNU extension).
3405 typeof ( expression )
3406 typeof ( type-name )
3409 static struct c_typespec
3410 c_parser_typeof_specifier (c_parser
*parser
)
3412 struct c_typespec ret
;
3413 ret
.kind
= ctsk_typeof
;
3414 ret
.spec
= error_mark_node
;
3415 ret
.expr
= NULL_TREE
;
3416 ret
.expr_const_operands
= true;
3417 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3418 c_parser_consume_token (parser
);
3419 c_inhibit_evaluation_warnings
++;
3421 matching_parens parens
;
3422 if (!parens
.require_open (parser
))
3424 c_inhibit_evaluation_warnings
--;
3428 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3430 struct c_type_name
*type
= c_parser_type_name (parser
);
3431 c_inhibit_evaluation_warnings
--;
3435 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3436 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3442 location_t here
= c_parser_peek_token (parser
)->location
;
3443 struct c_expr expr
= c_parser_expression (parser
);
3444 c_inhibit_evaluation_warnings
--;
3446 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3447 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3448 error_at (here
, "%<typeof%> applied to a bit-field");
3449 mark_exp_read (expr
.value
);
3450 ret
.spec
= TREE_TYPE (expr
.value
);
3451 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3452 /* This is returned with the type so that when the type is
3453 evaluated, this can be evaluated. */
3455 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3456 pop_maybe_used (was_vm
);
3457 /* For use in macros such as those in <stdatomic.h>, remove all
3458 qualifiers from atomic types. (const can be an issue for more macros
3459 using typeof than just the <stdatomic.h> ones.) */
3460 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3461 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3463 parens
.skip_until_found_close (parser
);
3467 /* Parse an alignment-specifier.
3471 alignment-specifier:
3472 _Alignas ( type-name )
3473 _Alignas ( constant-expression )
3477 c_parser_alignas_specifier (c_parser
* parser
)
3479 tree ret
= error_mark_node
;
3480 location_t loc
= c_parser_peek_token (parser
)->location
;
3481 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3482 c_parser_consume_token (parser
);
3484 pedwarn_c99 (loc
, OPT_Wpedantic
,
3485 "ISO C99 does not support %<_Alignas%>");
3487 pedwarn_c99 (loc
, OPT_Wpedantic
,
3488 "ISO C90 does not support %<_Alignas%>");
3489 matching_parens parens
;
3490 if (!parens
.require_open (parser
))
3492 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3494 struct c_type_name
*type
= c_parser_type_name (parser
);
3496 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3500 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3501 parens
.skip_until_found_close (parser
);
3505 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3506 6.5.5, C99 6.7.5, 6.7.6, C11 6.7.6, 6.7.7). If TYPE_SEEN_P then
3507 a typedef name may be redeclared; otherwise it may not. KIND
3508 indicates which kind of declarator is wanted. Returns a valid
3509 declarator except in the case of a syntax error in which case NULL is
3510 returned. *SEEN_ID is set to true if an identifier being declared is
3511 seen; this is used to diagnose bad forms of abstract array declarators
3512 and to determine whether an identifier list is syntactically permitted.
3515 pointer[opt] direct-declarator
3519 ( attributes[opt] declarator )
3520 direct-declarator array-declarator
3521 direct-declarator ( parameter-type-list )
3522 direct-declarator ( identifier-list[opt] )
3525 * type-qualifier-list[opt]
3526 * type-qualifier-list[opt] pointer
3528 type-qualifier-list:
3531 type-qualifier-list type-qualifier
3532 type-qualifier-list attributes
3535 [ type-qualifier-list[opt] assignment-expression[opt] ]
3536 [ static type-qualifier-list[opt] assignment-expression ]
3537 [ type-qualifier-list static assignment-expression ]
3538 [ type-qualifier-list[opt] * ]
3540 parameter-type-list:
3542 parameter-list , ...
3545 parameter-declaration
3546 parameter-list , parameter-declaration
3548 parameter-declaration:
3549 declaration-specifiers declarator attributes[opt]
3550 declaration-specifiers abstract-declarator[opt] attributes[opt]
3554 identifier-list , identifier
3556 abstract-declarator:
3558 pointer[opt] direct-abstract-declarator
3560 direct-abstract-declarator:
3561 ( attributes[opt] abstract-declarator )
3562 direct-abstract-declarator[opt] array-declarator
3563 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3568 direct-declarator ( parameter-forward-declarations
3569 parameter-type-list[opt] )
3571 direct-abstract-declarator:
3572 direct-abstract-declarator[opt] ( parameter-forward-declarations
3573 parameter-type-list[opt] )
3575 parameter-forward-declarations:
3577 parameter-forward-declarations parameter-list ;
3579 The uses of attributes shown above are GNU extensions.
3581 Some forms of array declarator are not included in C99 in the
3582 syntax for abstract declarators; these are disallowed elsewhere.
3583 This may be a defect (DR#289).
3585 This function also accepts an omitted abstract declarator as being
3586 an abstract declarator, although not part of the formal syntax. */
3588 struct c_declarator
*
3589 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3592 /* Parse any initial pointer part. */
3593 if (c_parser_next_token_is (parser
, CPP_MULT
))
3595 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3596 struct c_declarator
*inner
;
3597 c_parser_consume_token (parser
);
3598 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3599 false, false, cla_prefer_id
);
3600 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3604 return make_pointer_declarator (quals_attrs
, inner
);
3606 /* Now we have a direct declarator, direct abstract declarator or
3607 nothing (which counts as a direct abstract declarator here). */
3608 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3611 /* Parse a direct declarator or direct abstract declarator; arguments
3612 as c_parser_declarator. */
3614 static struct c_declarator
*
3615 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3618 /* The direct declarator must start with an identifier (possibly
3619 omitted) or a parenthesized declarator (possibly abstract). In
3620 an ordinary declarator, initial parentheses must start a
3621 parenthesized declarator. In an abstract declarator or parameter
3622 declarator, they could start a parenthesized declarator or a
3623 parameter list. To tell which, the open parenthesis and any
3624 following attributes must be read. If a declaration specifier
3625 follows, then it is a parameter list; if the specifier is a
3626 typedef name, there might be an ambiguity about redeclaring it,
3627 which is resolved in the direction of treating it as a typedef
3628 name. If a close parenthesis follows, it is also an empty
3629 parameter list, as the syntax does not permit empty abstract
3630 declarators. Otherwise, it is a parenthesized declarator (in
3631 which case the analysis may be repeated inside it, recursively).
3633 ??? There is an ambiguity in a parameter declaration "int
3634 (__attribute__((foo)) x)", where x is not a typedef name: it
3635 could be an abstract declarator for a function, or declare x with
3636 parentheses. The proper resolution of this ambiguity needs
3637 documenting. At present we follow an accident of the old
3638 parser's implementation, whereby the first parameter must have
3639 some declaration specifiers other than just attributes. Thus as
3640 a parameter declaration it is treated as a parenthesized
3641 parameter named x, and as an abstract declarator it is
3644 ??? Also following the old parser, attributes inside an empty
3645 parameter list are ignored, making it a list not yielding a
3646 prototype, rather than giving an error or making it have one
3647 parameter with implicit type int.
3649 ??? Also following the old parser, typedef names may be
3650 redeclared in declarators, but not Objective-C class names. */
3652 if (kind
!= C_DTR_ABSTRACT
3653 && c_parser_next_token_is (parser
, CPP_NAME
)
3655 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3656 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3657 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3659 struct c_declarator
*inner
3660 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3662 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3663 c_parser_consume_token (parser
);
3664 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3667 if (kind
!= C_DTR_NORMAL
3668 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3670 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3671 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3672 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3675 /* Either we are at the end of an abstract declarator, or we have
3678 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3681 struct c_declarator
*inner
;
3682 c_parser_consume_token (parser
);
3683 attrs
= c_parser_attributes (parser
);
3684 if (kind
!= C_DTR_NORMAL
3685 && (c_parser_next_token_starts_declspecs (parser
)
3686 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3688 struct c_arg_info
*args
3689 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3696 = build_function_declarator (args
,
3697 build_id_declarator (NULL_TREE
));
3698 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3702 /* A parenthesized declarator. */
3703 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3704 if (inner
!= NULL
&& attrs
!= NULL
)
3705 inner
= build_attrs_declarator (attrs
, inner
);
3706 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3708 c_parser_consume_token (parser
);
3712 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3716 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3723 if (kind
== C_DTR_NORMAL
)
3725 c_parser_error (parser
, "expected identifier or %<(%>");
3729 return build_id_declarator (NULL_TREE
);
3733 /* Parse part of a direct declarator or direct abstract declarator,
3734 given that some (in INNER) has already been parsed; ID_PRESENT is
3735 true if an identifier is present, false for an abstract
3738 static struct c_declarator
*
3739 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3740 struct c_declarator
*inner
)
3742 /* Parse a sequence of array declarators and parameter lists. */
3743 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3745 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3746 struct c_declarator
*declarator
;
3747 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3750 struct c_expr dimen
;
3751 dimen
.value
= NULL_TREE
;
3752 dimen
.original_code
= ERROR_MARK
;
3753 dimen
.original_type
= NULL_TREE
;
3754 c_parser_consume_token (parser
);
3755 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3756 false, false, cla_prefer_id
);
3757 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3759 c_parser_consume_token (parser
);
3760 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3761 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3762 false, false, cla_prefer_id
);
3763 if (!quals_attrs
->declspecs_seen_p
)
3765 /* If "static" is present, there must be an array dimension.
3766 Otherwise, there may be a dimension, "*", or no
3771 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3775 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3777 dimen
.value
= NULL_TREE
;
3780 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3782 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3784 dimen
.value
= NULL_TREE
;
3786 c_parser_consume_token (parser
);
3791 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3797 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3800 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3801 c_parser_consume_token (parser
);
3804 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3809 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3810 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3811 static_seen
, star_seen
);
3812 if (declarator
== NULL
)
3814 inner
= set_array_declarator_inner (declarator
, inner
);
3815 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3817 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3820 struct c_arg_info
*args
;
3821 c_parser_consume_token (parser
);
3822 attrs
= c_parser_attributes (parser
);
3823 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3828 inner
= build_function_declarator (args
, inner
);
3829 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3835 /* Parse a parameter list or identifier list, including the closing
3836 parenthesis but not the opening one. ATTRS are the attributes at
3837 the start of the list. ID_LIST_OK is true if an identifier list is
3838 acceptable; such a list must not have attributes at the start. */
3840 static struct c_arg_info
*
3841 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3844 declare_parm_level ();
3845 /* If the list starts with an identifier, it is an identifier list.
3846 Otherwise, it is either a prototype list or an empty list. */
3849 && c_parser_next_token_is (parser
, CPP_NAME
)
3850 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3852 /* Look ahead to detect typos in type names. */
3853 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3854 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3855 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3856 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
3857 && c_parser_peek_2nd_token (parser
)->type
!= CPP_KEYWORD
)
3859 tree list
= NULL_TREE
, *nextp
= &list
;
3860 while (c_parser_next_token_is (parser
, CPP_NAME
)
3861 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3863 *nextp
= build_tree_list (NULL_TREE
,
3864 c_parser_peek_token (parser
)->value
);
3865 nextp
= & TREE_CHAIN (*nextp
);
3866 c_parser_consume_token (parser
);
3867 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3869 c_parser_consume_token (parser
);
3870 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3872 c_parser_error (parser
, "expected identifier");
3876 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3878 struct c_arg_info
*ret
= build_arg_info ();
3880 c_parser_consume_token (parser
);
3886 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3894 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3901 /* Parse a parameter list (possibly empty), including the closing
3902 parenthesis but not the opening one. ATTRS are the attributes at
3903 the start of the list. EXPR is NULL or an expression that needs to
3904 be evaluated for the side effects of array size expressions in the
3907 static struct c_arg_info
*
3908 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3910 bool bad_parm
= false;
3912 /* ??? Following the old parser, forward parameter declarations may
3913 use abstract declarators, and if no real parameter declarations
3914 follow the forward declarations then this is not diagnosed. Also
3915 note as above that attributes are ignored as the only contents of
3916 the parentheses, or as the only contents after forward
3918 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3920 struct c_arg_info
*ret
= build_arg_info ();
3921 c_parser_consume_token (parser
);
3924 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3926 struct c_arg_info
*ret
= build_arg_info ();
3928 if (flag_allow_parameterless_variadic_functions
)
3930 /* F (...) is allowed. */
3931 ret
->types
= NULL_TREE
;
3935 /* Suppress -Wold-style-definition for this case. */
3936 ret
->types
= error_mark_node
;
3937 error_at (c_parser_peek_token (parser
)->location
,
3938 "ISO C requires a named argument before %<...%>");
3940 c_parser_consume_token (parser
);
3941 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3943 c_parser_consume_token (parser
);
3948 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3953 /* Nonempty list of parameters, either terminated with semicolon
3954 (forward declarations; recurse) or with close parenthesis (normal
3955 function) or with ", ... )" (variadic function). */
3958 /* Parse a parameter. */
3959 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3964 push_parm_decl (parm
, &expr
);
3965 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3968 c_parser_consume_token (parser
);
3969 mark_forward_parm_decls ();
3970 new_attrs
= c_parser_attributes (parser
);
3971 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3973 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3975 c_parser_consume_token (parser
);
3979 return get_parm_info (false, expr
);
3981 if (!c_parser_require (parser
, CPP_COMMA
,
3982 "expected %<;%>, %<,%> or %<)%>",
3983 UNKNOWN_LOCATION
, false))
3985 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3988 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3990 c_parser_consume_token (parser
);
3991 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3993 c_parser_consume_token (parser
);
3997 return get_parm_info (true, expr
);
4001 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4009 /* Parse a parameter declaration. ATTRS are the attributes at the
4010 start of the declaration if it is the first parameter. */
4012 static struct c_parm
*
4013 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
4015 struct c_declspecs
*specs
;
4016 struct c_declarator
*declarator
;
4018 tree postfix_attrs
= NULL_TREE
;
4021 /* Accept #pragmas between parameter declarations. */
4022 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4023 c_parser_pragma (parser
, pragma_param
, NULL
);
4025 if (!c_parser_next_token_starts_declspecs (parser
))
4027 c_token
*token
= c_parser_peek_token (parser
);
4030 c_parser_set_source_position_from_token (token
);
4031 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
4033 name_hint hint
= lookup_name_fuzzy (token
->value
,
4034 FUZZY_LOOKUP_TYPENAME
,
4038 gcc_rich_location
richloc (token
->location
);
4039 richloc
.add_fixit_replace (hint
.suggestion ());
4041 "unknown type name %qE; did you mean %qs?",
4042 token
->value
, hint
.suggestion ());
4045 error_at (token
->location
, "unknown type name %qE", token
->value
);
4046 parser
->error
= true;
4048 /* ??? In some Objective-C cases '...' isn't applicable so there
4049 should be a different message. */
4051 c_parser_error (parser
,
4052 "expected declaration specifiers or %<...%>");
4053 c_parser_skip_to_end_of_parameter (parser
);
4057 location_t start_loc
= c_parser_peek_token (parser
)->location
;
4059 specs
= build_null_declspecs ();
4062 declspecs_add_attrs (input_location
, specs
, attrs
);
4065 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
4066 cla_nonabstract_decl
);
4067 finish_declspecs (specs
);
4068 pending_xref_error ();
4069 prefix_attrs
= specs
->attrs
;
4070 specs
->attrs
= NULL_TREE
;
4071 declarator
= c_parser_declarator (parser
,
4072 specs
->typespec_kind
!= ctsk_none
,
4073 C_DTR_PARM
, &dummy
);
4074 if (declarator
== NULL
)
4076 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4079 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4080 postfix_attrs
= c_parser_attributes (parser
);
4082 /* Generate a location for the parameter, ranging from the start of the
4083 initial token to the end of the final token.
4085 If we have a identifier, then use it for the caret location, e.g.
4087 extern int callee (int one, int (*two)(int, int), float three);
4088 ~~~~~~^~~~~~~~~~~~~~
4090 otherwise, reuse the start location for the caret location e.g.:
4092 extern int callee (int one, int (*)(int, int), float three);
4095 location_t end_loc
= parser
->last_token_location
;
4097 /* Find any cdk_id declarator; determine if we have an identifier. */
4098 c_declarator
*id_declarator
= declarator
;
4099 while (id_declarator
&& id_declarator
->kind
!= cdk_id
)
4100 id_declarator
= id_declarator
->declarator
;
4101 location_t caret_loc
= (id_declarator
->u
.id
4102 ? id_declarator
->id_loc
4104 location_t param_loc
= make_location (caret_loc
, start_loc
, end_loc
);
4106 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
4107 declarator
, param_loc
);
4110 /* Parse a string literal in an asm expression. It should not be
4111 translated, and wide string literals are an error although
4112 permitted by the syntax. This is a GNU extension.
4117 ??? At present, following the old parser, the caller needs to have
4118 set lex_untranslated_string to 1. It would be better to follow the
4119 C++ parser rather than using this kludge. */
4122 c_parser_asm_string_literal (c_parser
*parser
)
4125 int save_flag
= warn_overlength_strings
;
4126 warn_overlength_strings
= 0;
4127 if (c_parser_next_token_is (parser
, CPP_STRING
))
4129 str
= c_parser_peek_token (parser
)->value
;
4130 c_parser_consume_token (parser
);
4132 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
4134 error_at (c_parser_peek_token (parser
)->location
,
4135 "wide string literal in %<asm%>");
4136 str
= build_string (1, "");
4137 c_parser_consume_token (parser
);
4141 c_parser_error (parser
, "expected string literal");
4144 warn_overlength_strings
= save_flag
;
4148 /* Parse a simple asm expression. This is used in restricted
4149 contexts, where a full expression with inputs and outputs does not
4150 make sense. This is a GNU extension.
4153 asm ( asm-string-literal )
4157 c_parser_simple_asm_expr (c_parser
*parser
)
4160 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
4161 /* ??? Follow the C++ parser rather than using the
4162 lex_untranslated_string kludge. */
4163 parser
->lex_untranslated_string
= true;
4164 c_parser_consume_token (parser
);
4165 matching_parens parens
;
4166 if (!parens
.require_open (parser
))
4168 parser
->lex_untranslated_string
= false;
4171 str
= c_parser_asm_string_literal (parser
);
4172 parser
->lex_untranslated_string
= false;
4173 if (!parens
.require_close (parser
))
4175 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4182 c_parser_attribute_any_word (c_parser
*parser
)
4184 tree attr_name
= NULL_TREE
;
4186 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
4188 /* ??? See comment above about what keywords are accepted here. */
4190 switch (c_parser_peek_token (parser
)->keyword
)
4221 case RID_TRANSACTION_ATOMIC
:
4222 case RID_TRANSACTION_CANCEL
:
4238 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
4239 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
4241 else if (c_parser_next_token_is (parser
, CPP_NAME
))
4242 attr_name
= c_parser_peek_token (parser
)->value
;
4247 /* Parse (possibly empty) attributes. This is a GNU extension.
4251 attributes attribute
4254 __attribute__ ( ( attribute-list ) )
4258 attribute_list , attrib
4263 any-word ( identifier )
4264 any-word ( identifier , nonempty-expr-list )
4265 any-word ( expr-list )
4267 where the "identifier" must not be declared as a type, and
4268 "any-word" may be any identifier (including one declared as a
4269 type), a reserved word storage class specifier, type specifier or
4270 type qualifier. ??? This still leaves out most reserved keywords
4271 (following the old parser), shouldn't we include them, and why not
4272 allow identifiers declared as types to start the arguments? */
4275 c_parser_attributes (c_parser
*parser
)
4277 tree attrs
= NULL_TREE
;
4278 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4280 /* ??? Follow the C++ parser rather than using the
4281 lex_untranslated_string kludge. */
4282 parser
->lex_untranslated_string
= true;
4283 /* Consume the `__attribute__' keyword. */
4284 c_parser_consume_token (parser
);
4285 /* Look for the two `(' tokens. */
4286 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4288 parser
->lex_untranslated_string
= false;
4291 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4293 parser
->lex_untranslated_string
= false;
4294 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4297 /* Parse the attribute list. */
4298 while (c_parser_next_token_is (parser
, CPP_COMMA
)
4299 || c_parser_next_token_is (parser
, CPP_NAME
)
4300 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
4302 tree attr
, attr_name
, attr_args
;
4303 vec
<tree
, va_gc
> *expr_list
;
4304 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4306 c_parser_consume_token (parser
);
4310 attr_name
= c_parser_attribute_any_word (parser
);
4311 if (attr_name
== NULL
)
4313 attr_name
= canonicalize_attr_name (attr_name
);
4314 c_parser_consume_token (parser
);
4315 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
4317 attr
= build_tree_list (attr_name
, NULL_TREE
);
4318 /* Add this attribute to the list. */
4319 attrs
= chainon (attrs
, attr
);
4320 /* If the next token isn't a comma, we're done. */
4321 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4325 c_parser_consume_token (parser
);
4326 /* Parse the attribute contents. If they start with an
4327 identifier which is followed by a comma or close
4328 parenthesis, then the arguments start with that
4329 identifier; otherwise they are an expression list.
4330 In objective-c the identifier may be a classname. */
4331 if (c_parser_next_token_is (parser
, CPP_NAME
)
4332 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4333 || (c_dialect_objc ()
4334 && c_parser_peek_token (parser
)->id_kind
4336 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4337 || (c_parser_peek_2nd_token (parser
)->type
4338 == CPP_CLOSE_PAREN
))
4339 && (attribute_takes_identifier_p (attr_name
)
4340 || (c_dialect_objc ()
4341 && c_parser_peek_token (parser
)->id_kind
4342 == C_ID_CLASSNAME
)))
4344 tree arg1
= c_parser_peek_token (parser
)->value
;
4345 c_parser_consume_token (parser
);
4346 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4347 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4351 c_parser_consume_token (parser
);
4352 expr_list
= c_parser_expr_list (parser
, false, true,
4353 NULL
, NULL
, NULL
, NULL
);
4354 tree_list
= build_tree_list_vec (expr_list
);
4355 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4356 release_tree_vector (expr_list
);
4361 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4362 attr_args
= NULL_TREE
;
4365 expr_list
= c_parser_expr_list (parser
, false, true,
4366 NULL
, NULL
, NULL
, NULL
);
4367 attr_args
= build_tree_list_vec (expr_list
);
4368 release_tree_vector (expr_list
);
4372 attr
= build_tree_list (attr_name
, attr_args
);
4373 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4374 c_parser_consume_token (parser
);
4377 parser
->lex_untranslated_string
= false;
4378 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4382 /* Add this attribute to the list. */
4383 attrs
= chainon (attrs
, attr
);
4384 /* If the next token isn't a comma, we're done. */
4385 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4388 /* Look for the two `)' tokens. */
4389 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4390 c_parser_consume_token (parser
);
4393 parser
->lex_untranslated_string
= false;
4394 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4398 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4399 c_parser_consume_token (parser
);
4402 parser
->lex_untranslated_string
= false;
4403 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4407 parser
->lex_untranslated_string
= false;
4413 /* Parse a type name (C90 6.5.5, C99 6.7.6, C11 6.7.7).
4416 specifier-qualifier-list abstract-declarator[opt]
4419 struct c_type_name
*
4420 c_parser_type_name (c_parser
*parser
)
4422 struct c_declspecs
*specs
= build_null_declspecs ();
4423 struct c_declarator
*declarator
;
4424 struct c_type_name
*ret
;
4426 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4428 if (!specs
->declspecs_seen_p
)
4430 c_parser_error (parser
, "expected specifier-qualifier-list");
4433 if (specs
->type
!= error_mark_node
)
4435 pending_xref_error ();
4436 finish_declspecs (specs
);
4438 declarator
= c_parser_declarator (parser
,
4439 specs
->typespec_kind
!= ctsk_none
,
4440 C_DTR_ABSTRACT
, &dummy
);
4441 if (declarator
== NULL
)
4443 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4445 ret
->declarator
= declarator
;
4449 /* Parse an initializer (C90 6.5.7, C99 6.7.8, C11 6.7.9).
4452 assignment-expression
4453 { initializer-list }
4454 { initializer-list , }
4457 designation[opt] initializer
4458 initializer-list , designation[opt] initializer
4465 designator-list designator
4472 [ constant-expression ]
4484 [ constant-expression ... constant-expression ]
4486 Any expression without commas is accepted in the syntax for the
4487 constant-expressions, with non-constant expressions rejected later.
4489 This function is only used for top-level initializers; for nested
4490 ones, see c_parser_initval. */
4492 static struct c_expr
4493 c_parser_initializer (c_parser
*parser
)
4495 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4496 return c_parser_braced_init (parser
, NULL_TREE
, false, NULL
);
4500 location_t loc
= c_parser_peek_token (parser
)->location
;
4501 ret
= c_parser_expr_no_commas (parser
, NULL
);
4502 if (TREE_CODE (ret
.value
) != STRING_CST
4503 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4504 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4509 /* The location of the last comma within the current initializer list,
4510 or UNKNOWN_LOCATION if not within one. */
4512 location_t last_init_list_comma
;
4514 /* Parse a braced initializer list. TYPE is the type specified for a
4515 compound literal, and NULL_TREE for other initializers and for
4516 nested braced lists. NESTED_P is true for nested braced lists,
4517 false for the list of a compound literal or the list that is the
4518 top-level initializer in a declaration. */
4520 static struct c_expr
4521 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
,
4522 struct obstack
*outer_obstack
)
4525 struct obstack braced_init_obstack
;
4526 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4527 gcc_obstack_init (&braced_init_obstack
);
4528 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4529 matching_braces braces
;
4530 braces
.consume_open (parser
);
4533 finish_implicit_inits (brace_loc
, outer_obstack
);
4534 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4537 really_start_incremental_init (type
);
4538 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4540 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4544 /* Parse a non-empty initializer list, possibly with a trailing
4548 c_parser_initelt (parser
, &braced_init_obstack
);
4551 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4553 last_init_list_comma
= c_parser_peek_token (parser
)->location
;
4554 c_parser_consume_token (parser
);
4558 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4562 c_token
*next_tok
= c_parser_peek_token (parser
);
4563 if (next_tok
->type
!= CPP_CLOSE_BRACE
)
4565 ret
.value
= error_mark_node
;
4566 ret
.original_code
= ERROR_MARK
;
4567 ret
.original_type
= NULL
;
4568 braces
.skip_until_found_close (parser
);
4569 pop_init_level (brace_loc
, 0, &braced_init_obstack
, last_init_list_comma
);
4570 obstack_free (&braced_init_obstack
, NULL
);
4573 location_t close_loc
= next_tok
->location
;
4574 c_parser_consume_token (parser
);
4575 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
, close_loc
);
4576 obstack_free (&braced_init_obstack
, NULL
);
4577 set_c_expr_source_range (&ret
, brace_loc
, close_loc
);
4581 /* Parse a nested initializer, including designators. */
4584 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4586 /* Parse any designator or designator list. A single array
4587 designator may have the subsequent "=" omitted in GNU C, but a
4588 longer list or a structure member designator may not. */
4589 if (c_parser_next_token_is (parser
, CPP_NAME
)
4590 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4592 /* Old-style structure member designator. */
4593 set_init_label (c_parser_peek_token (parser
)->location
,
4594 c_parser_peek_token (parser
)->value
,
4595 c_parser_peek_token (parser
)->location
,
4596 braced_init_obstack
);
4597 /* Use the colon as the error location. */
4598 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4599 "obsolete use of designated initializer with %<:%>");
4600 c_parser_consume_token (parser
);
4601 c_parser_consume_token (parser
);
4605 /* des_seen is 0 if there have been no designators, 1 if there
4606 has been a single array designator and 2 otherwise. */
4608 /* Location of a designator. */
4609 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4610 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4611 || c_parser_next_token_is (parser
, CPP_DOT
))
4613 int des_prev
= des_seen
;
4615 des_loc
= c_parser_peek_token (parser
)->location
;
4618 if (c_parser_next_token_is (parser
, CPP_DOT
))
4621 c_parser_consume_token (parser
);
4622 if (c_parser_next_token_is (parser
, CPP_NAME
))
4624 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4625 c_parser_peek_token (parser
)->location
,
4626 braced_init_obstack
);
4627 c_parser_consume_token (parser
);
4632 init
.value
= error_mark_node
;
4633 init
.original_code
= ERROR_MARK
;
4634 init
.original_type
= NULL
;
4635 c_parser_error (parser
, "expected identifier");
4636 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4637 process_init_element (input_location
, init
, false,
4638 braced_init_obstack
);
4645 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4646 location_t array_index_loc
= UNKNOWN_LOCATION
;
4647 /* ??? Following the old parser, [ objc-receiver
4648 objc-message-args ] is accepted as an initializer,
4649 being distinguished from a designator by what follows
4650 the first assignment expression inside the square
4651 brackets, but after a first array designator a
4652 subsequent square bracket is for Objective-C taken to
4653 start an expression, using the obsolete form of
4654 designated initializer without '=', rather than
4655 possibly being a second level of designation: in LALR
4656 terms, the '[' is shifted rather than reducing
4657 designator to designator-list. */
4658 if (des_prev
== 1 && c_dialect_objc ())
4660 des_seen
= des_prev
;
4663 if (des_prev
== 0 && c_dialect_objc ())
4665 /* This might be an array designator or an
4666 Objective-C message expression. If the former,
4667 continue parsing here; if the latter, parse the
4668 remainder of the initializer given the starting
4669 primary-expression. ??? It might make sense to
4670 distinguish when des_prev == 1 as well; see
4671 previous comment. */
4673 struct c_expr mexpr
;
4674 c_parser_consume_token (parser
);
4675 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4676 && ((c_parser_peek_token (parser
)->id_kind
4678 || (c_parser_peek_token (parser
)->id_kind
4679 == C_ID_CLASSNAME
)))
4681 /* Type name receiver. */
4682 tree id
= c_parser_peek_token (parser
)->value
;
4683 c_parser_consume_token (parser
);
4684 rec
= objc_get_class_reference (id
);
4685 goto parse_message_args
;
4687 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4688 mark_exp_read (first
);
4689 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4690 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4691 goto array_desig_after_first
;
4692 /* Expression receiver. So far only one part
4693 without commas has been parsed; there might be
4694 more of the expression. */
4696 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4699 location_t comma_loc
, exp_loc
;
4700 comma_loc
= c_parser_peek_token (parser
)->location
;
4701 c_parser_consume_token (parser
);
4702 exp_loc
= c_parser_peek_token (parser
)->location
;
4703 next
= c_parser_expr_no_commas (parser
, NULL
);
4704 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4706 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4709 /* Now parse the objc-message-args. */
4710 args
= c_parser_objc_message_args (parser
);
4711 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4714 = objc_build_message_expr (rec
, args
);
4715 mexpr
.original_code
= ERROR_MARK
;
4716 mexpr
.original_type
= NULL
;
4717 /* Now parse and process the remainder of the
4718 initializer, starting with this message
4719 expression as a primary-expression. */
4720 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4723 c_parser_consume_token (parser
);
4724 array_index_loc
= c_parser_peek_token (parser
)->location
;
4725 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4726 mark_exp_read (first
);
4727 array_desig_after_first
:
4728 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4730 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4731 c_parser_consume_token (parser
);
4732 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4733 mark_exp_read (second
);
4737 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4739 c_parser_consume_token (parser
);
4740 set_init_index (array_index_loc
, first
, second
,
4741 braced_init_obstack
);
4743 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4744 "ISO C forbids specifying range of elements to initialize");
4747 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4753 if (c_parser_next_token_is (parser
, CPP_EQ
))
4755 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4756 "ISO C90 forbids specifying subobject "
4758 c_parser_consume_token (parser
);
4763 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4764 "obsolete use of designated initializer without %<=%>");
4768 init
.value
= error_mark_node
;
4769 init
.original_code
= ERROR_MARK
;
4770 init
.original_type
= NULL
;
4771 c_parser_error (parser
, "expected %<=%>");
4772 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4773 process_init_element (input_location
, init
, false,
4774 braced_init_obstack
);
4780 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4783 /* Parse a nested initializer; as c_parser_initializer but parses
4784 initializers within braced lists, after any designators have been
4785 applied. If AFTER is not NULL then it is an Objective-C message
4786 expression which is the primary-expression starting the
4790 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4791 struct obstack
* braced_init_obstack
)
4794 gcc_assert (!after
|| c_dialect_objc ());
4795 location_t loc
= c_parser_peek_token (parser
)->location
;
4797 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4798 init
= c_parser_braced_init (parser
, NULL_TREE
, true,
4799 braced_init_obstack
);
4802 init
= c_parser_expr_no_commas (parser
, after
);
4803 if (init
.value
!= NULL_TREE
4804 && TREE_CODE (init
.value
) != STRING_CST
4805 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4806 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4808 process_init_element (loc
, init
, false, braced_init_obstack
);
4811 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4812 C99 6.8.2, C11 6.8.2).
4815 { block-item-list[opt] }
4816 { label-declarations block-item-list }
4820 block-item-list block-item
4832 { label-declarations block-item-list }
4835 __extension__ nested-declaration
4836 nested-function-definition
4840 label-declarations label-declaration
4843 __label__ identifier-list ;
4845 Allowing the mixing of declarations and code is new in C99. The
4846 GNU syntax also permits (not shown above) labels at the end of
4847 compound statements, which yield an error. We don't allow labels
4848 on declarations; this might seem like a natural extension, but
4849 there would be a conflict between attributes on the label and
4850 prefix attributes on the declaration. ??? The syntax follows the
4851 old parser in requiring something after label declarations.
4852 Although they are erroneous if the labels declared aren't defined,
4853 is it useful for the syntax to be this way?
4874 cancellation-point-directive */
4877 c_parser_compound_statement (c_parser
*parser
)
4880 location_t brace_loc
;
4881 brace_loc
= c_parser_peek_token (parser
)->location
;
4882 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4884 /* Ensure a scope is entered and left anyway to avoid confusion
4885 if we have just prepared to enter a function body. */
4886 stmt
= c_begin_compound_stmt (true);
4887 c_end_compound_stmt (brace_loc
, stmt
, true);
4888 return error_mark_node
;
4890 stmt
= c_begin_compound_stmt (true);
4891 c_parser_compound_statement_nostart (parser
);
4893 return c_end_compound_stmt (brace_loc
, stmt
, true);
4896 /* Parse a compound statement except for the opening brace. This is
4897 used for parsing both compound statements and statement expressions
4898 (which follow different paths to handling the opening). */
4901 c_parser_compound_statement_nostart (c_parser
*parser
)
4903 bool last_stmt
= false;
4904 bool last_label
= false;
4905 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4906 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4907 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4909 c_parser_consume_token (parser
);
4912 mark_valid_location_for_stdc_pragma (true);
4913 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4915 /* Read zero or more forward-declarations for labels that nested
4916 functions can jump to. */
4917 mark_valid_location_for_stdc_pragma (false);
4918 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4920 label_loc
= c_parser_peek_token (parser
)->location
;
4921 c_parser_consume_token (parser
);
4922 /* Any identifiers, including those declared as type names,
4927 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4929 c_parser_error (parser
, "expected identifier");
4933 = declare_label (c_parser_peek_token (parser
)->value
);
4934 C_DECLARED_LABEL_FLAG (label
) = 1;
4935 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4936 c_parser_consume_token (parser
);
4937 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4938 c_parser_consume_token (parser
);
4942 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4944 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4946 /* We must now have at least one statement, label or declaration. */
4947 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4949 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4950 c_parser_error (parser
, "expected declaration or statement");
4951 c_parser_consume_token (parser
);
4954 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4956 location_t loc
= c_parser_peek_token (parser
)->location
;
4957 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4958 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4959 || (c_parser_next_token_is (parser
, CPP_NAME
)
4960 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4962 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4963 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4965 label_loc
= c_parser_peek_token (parser
)->location
;
4968 mark_valid_location_for_stdc_pragma (false);
4969 c_parser_label (parser
);
4971 else if (!last_label
4972 && c_parser_next_tokens_start_declaration (parser
))
4975 mark_valid_location_for_stdc_pragma (false);
4976 bool fallthru_attr_p
= false;
4977 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4978 true, NULL
, vNULL
, NULL
,
4980 if (last_stmt
&& !fallthru_attr_p
)
4981 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4982 "ISO C90 forbids mixed declarations and code");
4983 last_stmt
= fallthru_attr_p
;
4985 else if (!last_label
4986 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4988 /* __extension__ can start a declaration, but is also an
4989 unary operator that can start an expression. Consume all
4990 but the last of a possible series of __extension__ to
4992 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4993 && (c_parser_peek_2nd_token (parser
)->keyword
4995 c_parser_consume_token (parser
);
4996 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4999 ext
= disable_extension_diagnostics ();
5000 c_parser_consume_token (parser
);
5002 mark_valid_location_for_stdc_pragma (false);
5003 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5005 /* Following the old parser, __extension__ does not
5006 disable this diagnostic. */
5007 restore_extension_diagnostics (ext
);
5009 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
5010 "ISO C90 forbids mixed declarations and code");
5016 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
5018 /* External pragmas, and some omp pragmas, are not associated
5019 with regular c code, and so are not to be considered statements
5020 syntactically. This ensures that the user doesn't put them
5021 places that would turn into syntax errors if the directive
5023 if (c_parser_pragma (parser
,
5024 last_label
? pragma_stmt
: pragma_compound
,
5026 last_label
= false, last_stmt
= true;
5028 else if (c_parser_next_token_is (parser
, CPP_EOF
))
5030 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5031 c_parser_error (parser
, "expected declaration or statement");
5034 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5036 if (parser
->in_if_block
)
5038 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5039 error_at (loc
, "expected %<}%> before %<else%>");
5044 error_at (loc
, "%<else%> without a previous %<if%>");
5045 c_parser_consume_token (parser
);
5054 mark_valid_location_for_stdc_pragma (false);
5055 c_parser_statement_after_labels (parser
, NULL
);
5058 parser
->error
= false;
5061 error_at (label_loc
, "label at end of compound statement");
5062 c_parser_consume_token (parser
);
5063 /* Restore the value we started with. */
5064 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
5067 /* Parse all consecutive labels. */
5070 c_parser_all_labels (c_parser
*parser
)
5072 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
5073 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
5074 || (c_parser_next_token_is (parser
, CPP_NAME
)
5075 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
5076 c_parser_label (parser
);
5079 /* Parse a label (C90 6.6.1, C99 6.8.1, C11 6.8.1).
5082 identifier : attributes[opt]
5083 case constant-expression :
5089 case constant-expression ... constant-expression :
5091 The use of attributes on labels is a GNU extension. The syntax in
5092 GNU C accepts any expressions without commas, non-constant
5093 expressions being rejected later. */
5096 c_parser_label (c_parser
*parser
)
5098 location_t loc1
= c_parser_peek_token (parser
)->location
;
5099 tree label
= NULL_TREE
;
5101 /* Remember whether this case or a user-defined label is allowed to fall
5103 bool fallthrough_p
= c_parser_peek_token (parser
)->flags
& PREV_FALLTHROUGH
;
5105 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
5108 c_parser_consume_token (parser
);
5109 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
5110 if (c_parser_next_token_is (parser
, CPP_COLON
))
5112 c_parser_consume_token (parser
);
5113 label
= do_case (loc1
, exp1
, NULL_TREE
);
5115 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
5117 c_parser_consume_token (parser
);
5118 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
5119 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5120 label
= do_case (loc1
, exp1
, exp2
);
5123 c_parser_error (parser
, "expected %<:%> or %<...%>");
5125 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
5127 c_parser_consume_token (parser
);
5128 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
5129 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
5133 tree name
= c_parser_peek_token (parser
)->value
;
5136 location_t loc2
= c_parser_peek_token (parser
)->location
;
5137 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
5138 c_parser_consume_token (parser
);
5139 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
5140 c_parser_consume_token (parser
);
5141 attrs
= c_parser_attributes (parser
);
5142 tlab
= define_label (loc2
, name
);
5145 decl_attributes (&tlab
, attrs
, 0);
5146 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
5151 if (TREE_CODE (label
) == LABEL_EXPR
)
5152 FALLTHROUGH_LABEL_P (LABEL_EXPR_LABEL (label
)) = fallthrough_p
;
5154 FALLTHROUGH_LABEL_P (CASE_LABEL (label
)) = fallthrough_p
;
5156 /* Allow '__attribute__((fallthrough));'. */
5157 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
5159 location_t loc
= c_parser_peek_token (parser
)->location
;
5160 tree attrs
= c_parser_attributes (parser
);
5161 if (attribute_fallthrough_p (attrs
))
5163 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5165 tree fn
= build_call_expr_internal_loc (loc
,
5171 warning_at (loc
, OPT_Wattributes
, "%<fallthrough%> attribute "
5172 "not followed by %<;%>");
5174 else if (attrs
!= NULL_TREE
)
5175 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5176 " can be applied to a null statement");
5178 if (c_parser_next_tokens_start_declaration (parser
))
5180 error_at (c_parser_peek_token (parser
)->location
,
5181 "a label can only be part of a statement and "
5182 "a declaration is not a statement");
5183 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
5184 /*static_assert_ok*/ true,
5185 /*empty_ok*/ true, /*nested*/ true,
5186 /*start_attr_ok*/ true, NULL
,
5192 /* Parse a statement (C90 6.6, C99 6.8, C11 6.8).
5197 expression-statement
5205 expression-statement:
5208 selection-statement:
5212 iteration-statement:
5221 return expression[opt] ;
5231 expression-statement:
5237 objc-throw-statement
5238 objc-try-catch-statement
5239 objc-synchronized-statement
5241 objc-throw-statement:
5257 parallel-directive structured-block
5260 kernels-directive structured-block
5263 data-directive structured-block
5266 loop-directive structured-block
5280 parallel-for-construct
5281 parallel-for-simd-construct
5282 parallel-sections-construct
5289 parallel-directive structured-block
5292 for-directive iteration-statement
5295 simd-directive iteration-statements
5298 for-simd-directive iteration-statements
5301 sections-directive section-scope
5304 single-directive structured-block
5306 parallel-for-construct:
5307 parallel-for-directive iteration-statement
5309 parallel-for-simd-construct:
5310 parallel-for-simd-directive iteration-statement
5312 parallel-sections-construct:
5313 parallel-sections-directive section-scope
5316 master-directive structured-block
5319 critical-directive structured-block
5322 atomic-directive expression-statement
5325 ordered-directive structured-block
5327 Transactional Memory:
5330 transaction-statement
5331 transaction-cancel-statement
5333 IF_P is used to track whether there's a (possibly labeled) if statement
5334 which is not enclosed in braces and has an else clause. This is used to
5335 implement -Wparentheses. */
5338 c_parser_statement (c_parser
*parser
, bool *if_p
, location_t
*loc_after_labels
)
5340 c_parser_all_labels (parser
);
5341 if (loc_after_labels
)
5342 *loc_after_labels
= c_parser_peek_token (parser
)->location
;
5343 c_parser_statement_after_labels (parser
, if_p
, NULL
);
5346 /* Parse a statement, other than a labeled statement. CHAIN is a vector
5347 of if-else-if conditions.
5349 IF_P is used to track whether there's a (possibly labeled) if statement
5350 which is not enclosed in braces and has an else clause. This is used to
5351 implement -Wparentheses. */
5354 c_parser_statement_after_labels (c_parser
*parser
, bool *if_p
,
5357 location_t loc
= c_parser_peek_token (parser
)->location
;
5358 tree stmt
= NULL_TREE
;
5359 bool in_if_block
= parser
->in_if_block
;
5360 parser
->in_if_block
= false;
5363 switch (c_parser_peek_token (parser
)->type
)
5365 case CPP_OPEN_BRACE
:
5366 add_stmt (c_parser_compound_statement (parser
));
5369 switch (c_parser_peek_token (parser
)->keyword
)
5372 c_parser_if_statement (parser
, if_p
, chain
);
5375 c_parser_switch_statement (parser
, if_p
);
5378 c_parser_while_statement (parser
, false, if_p
);
5381 c_parser_do_statement (parser
, false);
5384 c_parser_for_statement (parser
, false, if_p
);
5387 c_parser_consume_token (parser
);
5388 if (c_parser_next_token_is (parser
, CPP_NAME
))
5390 stmt
= c_finish_goto_label (loc
,
5391 c_parser_peek_token (parser
)->value
);
5392 c_parser_consume_token (parser
);
5394 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5398 c_parser_consume_token (parser
);
5399 val
= c_parser_expression (parser
);
5400 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5401 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5404 c_parser_error (parser
, "expected identifier or %<*%>");
5405 goto expect_semicolon
;
5407 c_parser_consume_token (parser
);
5408 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5409 goto expect_semicolon
;
5411 c_parser_consume_token (parser
);
5412 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5413 goto expect_semicolon
;
5415 c_parser_consume_token (parser
);
5416 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5418 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5419 c_parser_consume_token (parser
);
5423 location_t xloc
= c_parser_peek_token (parser
)->location
;
5424 struct c_expr expr
= c_parser_expression_conv (parser
);
5425 mark_exp_read (expr
.value
);
5426 stmt
= c_finish_return (EXPR_LOC_OR_LOC (expr
.value
, xloc
),
5427 expr
.value
, expr
.original_type
);
5428 goto expect_semicolon
;
5432 stmt
= c_parser_asm_statement (parser
);
5434 case RID_TRANSACTION_ATOMIC
:
5435 case RID_TRANSACTION_RELAXED
:
5436 stmt
= c_parser_transaction (parser
,
5437 c_parser_peek_token (parser
)->keyword
);
5439 case RID_TRANSACTION_CANCEL
:
5440 stmt
= c_parser_transaction_cancel (parser
);
5441 goto expect_semicolon
;
5443 gcc_assert (c_dialect_objc ());
5444 c_parser_consume_token (parser
);
5445 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5447 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5448 c_parser_consume_token (parser
);
5452 struct c_expr expr
= c_parser_expression (parser
);
5453 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5454 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5455 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5456 goto expect_semicolon
;
5460 gcc_assert (c_dialect_objc ());
5461 c_parser_objc_try_catch_finally_statement (parser
);
5463 case RID_AT_SYNCHRONIZED
:
5464 gcc_assert (c_dialect_objc ());
5465 c_parser_objc_synchronized_statement (parser
);
5469 /* Allow '__attribute__((fallthrough));'. */
5470 tree attrs
= c_parser_attributes (parser
);
5471 if (attribute_fallthrough_p (attrs
))
5473 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5475 tree fn
= build_call_expr_internal_loc (loc
,
5480 c_parser_consume_token (parser
);
5483 warning_at (loc
, OPT_Wattributes
,
5484 "%<fallthrough%> attribute not followed "
5487 else if (attrs
!= NULL_TREE
)
5488 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5489 " can be applied to a null statement");
5497 c_parser_consume_token (parser
);
5499 case CPP_CLOSE_PAREN
:
5500 case CPP_CLOSE_SQUARE
:
5501 /* Avoid infinite loop in error recovery:
5502 c_parser_skip_until_found stops at a closing nesting
5503 delimiter without consuming it, but here we need to consume
5504 it to proceed further. */
5505 c_parser_error (parser
, "expected statement");
5506 c_parser_consume_token (parser
);
5509 c_parser_pragma (parser
, pragma_stmt
, if_p
);
5513 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5515 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5518 /* Two cases cannot and do not have line numbers associated: If stmt
5519 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5520 cannot hold line numbers. But that's OK because the statement
5521 will either be changed to a MODIFY_EXPR during gimplification of
5522 the statement expr, or discarded. If stmt was compound, but
5523 without new variables, we will have skipped the creation of a
5524 BIND and will have a bare STATEMENT_LIST. But that's OK because
5525 (recursively) all of the component statements should already have
5526 line numbers assigned. ??? Can we discard no-op statements
5528 if (EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5529 protected_set_expr_location (stmt
, loc
);
5531 parser
->in_if_block
= in_if_block
;
5534 /* Parse the condition from an if, do, while or for statements. */
5537 c_parser_condition (c_parser
*parser
)
5539 location_t loc
= c_parser_peek_token (parser
)->location
;
5541 cond
= c_parser_expression_conv (parser
).value
;
5542 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5543 cond
= c_fully_fold (cond
, false, NULL
);
5544 if (warn_sequence_point
)
5545 verify_sequence_points (cond
);
5549 /* Parse a parenthesized condition from an if, do or while statement.
5555 c_parser_paren_condition (c_parser
*parser
)
5558 matching_parens parens
;
5559 if (!parens
.require_open (parser
))
5560 return error_mark_node
;
5561 cond
= c_parser_condition (parser
);
5562 parens
.skip_until_found_close (parser
);
5566 /* Parse a statement which is a block in C99.
5568 IF_P is used to track whether there's a (possibly labeled) if statement
5569 which is not enclosed in braces and has an else clause. This is used to
5570 implement -Wparentheses. */
5573 c_parser_c99_block_statement (c_parser
*parser
, bool *if_p
,
5574 location_t
*loc_after_labels
)
5576 tree block
= c_begin_compound_stmt (flag_isoc99
);
5577 location_t loc
= c_parser_peek_token (parser
)->location
;
5578 c_parser_statement (parser
, if_p
, loc_after_labels
);
5579 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5582 /* Parse the body of an if statement. This is just parsing a
5583 statement but (a) it is a block in C99, (b) we track whether the
5584 body is an if statement for the sake of -Wparentheses warnings, (c)
5585 we handle an empty body specially for the sake of -Wempty-body
5586 warnings, and (d) we call parser_compound_statement directly
5587 because c_parser_statement_after_labels resets
5588 parser->in_if_block.
5590 IF_P is used to track whether there's a (possibly labeled) if statement
5591 which is not enclosed in braces and has an else clause. This is used to
5592 implement -Wparentheses. */
5595 c_parser_if_body (c_parser
*parser
, bool *if_p
,
5596 const token_indent_info
&if_tinfo
)
5598 tree block
= c_begin_compound_stmt (flag_isoc99
);
5599 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5600 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
5601 token_indent_info body_tinfo
5602 = get_token_indent_info (c_parser_peek_token (parser
));
5604 c_parser_all_labels (parser
);
5605 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5607 location_t loc
= c_parser_peek_token (parser
)->location
;
5608 add_stmt (build_empty_stmt (loc
));
5609 c_parser_consume_token (parser
);
5610 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5611 warning_at (loc
, OPT_Wempty_body
,
5612 "suggest braces around empty body in an %<if%> statement");
5614 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5615 add_stmt (c_parser_compound_statement (parser
));
5618 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5619 c_parser_statement_after_labels (parser
, if_p
);
5622 token_indent_info next_tinfo
5623 = get_token_indent_info (c_parser_peek_token (parser
));
5624 warn_for_misleading_indentation (if_tinfo
, body_tinfo
, next_tinfo
);
5625 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5626 && next_tinfo
.type
!= CPP_SEMICOLON
)
5627 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5628 if_tinfo
.location
, RID_IF
);
5630 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5633 /* Parse the else body of an if statement. This is just parsing a
5634 statement but (a) it is a block in C99, (b) we handle an empty body
5635 specially for the sake of -Wempty-body warnings. CHAIN is a vector
5636 of if-else-if conditions. */
5639 c_parser_else_body (c_parser
*parser
, const token_indent_info
&else_tinfo
,
5642 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5643 tree block
= c_begin_compound_stmt (flag_isoc99
);
5644 token_indent_info body_tinfo
5645 = get_token_indent_info (c_parser_peek_token (parser
));
5646 location_t body_loc_after_labels
= UNKNOWN_LOCATION
;
5648 c_parser_all_labels (parser
);
5649 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5651 location_t loc
= c_parser_peek_token (parser
)->location
;
5654 "suggest braces around empty body in an %<else%> statement");
5655 add_stmt (build_empty_stmt (loc
));
5656 c_parser_consume_token (parser
);
5660 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5661 body_loc_after_labels
= c_parser_peek_token (parser
)->location
;
5662 c_parser_statement_after_labels (parser
, NULL
, chain
);
5665 token_indent_info next_tinfo
5666 = get_token_indent_info (c_parser_peek_token (parser
));
5667 warn_for_misleading_indentation (else_tinfo
, body_tinfo
, next_tinfo
);
5668 if (body_loc_after_labels
!= UNKNOWN_LOCATION
5669 && next_tinfo
.type
!= CPP_SEMICOLON
)
5670 warn_for_multistatement_macros (body_loc_after_labels
, next_tinfo
.location
,
5671 else_tinfo
.location
, RID_ELSE
);
5673 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5676 /* We might need to reclassify any previously-lexed identifier, e.g.
5677 when we've left a for loop with an if-statement without else in the
5678 body - we might have used a wrong scope for the token. See PR67784. */
5681 c_parser_maybe_reclassify_token (c_parser
*parser
)
5683 if (c_parser_next_token_is (parser
, CPP_NAME
))
5685 c_token
*token
= c_parser_peek_token (parser
);
5687 if (token
->id_kind
!= C_ID_CLASSNAME
)
5689 tree decl
= lookup_name (token
->value
);
5691 token
->id_kind
= C_ID_ID
;
5694 if (TREE_CODE (decl
) == TYPE_DECL
)
5695 token
->id_kind
= C_ID_TYPENAME
;
5697 else if (c_dialect_objc ())
5699 tree objc_interface_decl
= objc_is_class_name (token
->value
);
5700 /* Objective-C class names are in the same namespace as
5701 variables and typedefs, and hence are shadowed by local
5703 if (objc_interface_decl
)
5705 token
->value
= objc_interface_decl
;
5706 token
->id_kind
= C_ID_CLASSNAME
;
5713 /* Parse an if statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5716 if ( expression ) statement
5717 if ( expression ) statement else statement
5719 CHAIN is a vector of if-else-if conditions.
5720 IF_P is used to track whether there's a (possibly labeled) if statement
5721 which is not enclosed in braces and has an else clause. This is used to
5722 implement -Wparentheses. */
5725 c_parser_if_statement (c_parser
*parser
, bool *if_p
, vec
<tree
> *chain
)
5730 bool nested_if
= false;
5731 tree first_body
, second_body
;
5734 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5735 token_indent_info if_tinfo
5736 = get_token_indent_info (c_parser_peek_token (parser
));
5737 c_parser_consume_token (parser
);
5738 block
= c_begin_compound_stmt (flag_isoc99
);
5739 loc
= c_parser_peek_token (parser
)->location
;
5740 cond
= c_parser_paren_condition (parser
);
5741 in_if_block
= parser
->in_if_block
;
5742 parser
->in_if_block
= true;
5743 first_body
= c_parser_if_body (parser
, &nested_if
, if_tinfo
);
5744 parser
->in_if_block
= in_if_block
;
5746 if (warn_duplicated_cond
)
5747 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond
), cond
, &chain
);
5749 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5751 token_indent_info else_tinfo
5752 = get_token_indent_info (c_parser_peek_token (parser
));
5753 c_parser_consume_token (parser
);
5754 if (warn_duplicated_cond
)
5756 if (c_parser_next_token_is_keyword (parser
, RID_IF
)
5759 /* We've got "if (COND) else if (COND2)". Start the
5760 condition chain and add COND as the first element. */
5761 chain
= new vec
<tree
> ();
5762 if (!CONSTANT_CLASS_P (cond
) && !TREE_SIDE_EFFECTS (cond
))
5763 chain
->safe_push (cond
);
5765 else if (!c_parser_next_token_is_keyword (parser
, RID_IF
))
5767 /* This is if-else without subsequent if. Zap the condition
5768 chain; we would have already warned at this point. */
5773 second_body
= c_parser_else_body (parser
, else_tinfo
, chain
);
5774 /* Set IF_P to true to indicate that this if statement has an
5775 else clause. This may trigger the Wparentheses warning
5776 below when we get back up to the parent if statement. */
5782 second_body
= NULL_TREE
;
5784 /* Diagnose an ambiguous else if if-then-else is nested inside
5787 warning_at (loc
, OPT_Wdangling_else
,
5788 "suggest explicit braces to avoid ambiguous %<else%>");
5790 if (warn_duplicated_cond
)
5792 /* This if statement does not have an else clause. We don't
5793 need the condition chain anymore. */
5798 c_finish_if_stmt (loc
, cond
, first_body
, second_body
);
5799 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5801 c_parser_maybe_reclassify_token (parser
);
5804 /* Parse a switch statement (C90 6.6.4, C99 6.8.4, C11 6.8.4).
5807 switch (expression) statement
5811 c_parser_switch_statement (c_parser
*parser
, bool *if_p
)
5814 tree block
, expr
, body
, save_break
;
5815 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5816 location_t switch_cond_loc
;
5817 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5818 c_parser_consume_token (parser
);
5819 block
= c_begin_compound_stmt (flag_isoc99
);
5820 bool explicit_cast_p
= false;
5821 matching_parens parens
;
5822 if (parens
.require_open (parser
))
5824 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5825 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5826 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5827 explicit_cast_p
= true;
5828 ce
= c_parser_expression (parser
);
5829 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5831 /* ??? expr has no valid location? */
5832 parens
.skip_until_found_close (parser
);
5836 switch_cond_loc
= UNKNOWN_LOCATION
;
5837 expr
= error_mark_node
;
5838 ce
.original_type
= error_mark_node
;
5840 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5841 save_break
= c_break_label
;
5842 c_break_label
= NULL_TREE
;
5843 location_t loc_after_labels
;
5844 bool open_brace_p
= c_parser_peek_token (parser
)->type
== CPP_OPEN_BRACE
;
5845 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
5846 location_t next_loc
= c_parser_peek_token (parser
)->location
;
5847 if (!open_brace_p
&& c_parser_peek_token (parser
)->type
!= CPP_SEMICOLON
)
5848 warn_for_multistatement_macros (loc_after_labels
, next_loc
, switch_loc
,
5852 location_t here
= c_parser_peek_token (parser
)->location
;
5853 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5854 SET_EXPR_LOCATION (t
, here
);
5855 SWITCH_BREAK_LABEL_P (c_break_label
) = 1;
5856 append_to_statement_list_force (t
, &body
);
5858 c_finish_case (body
, ce
.original_type
);
5859 c_break_label
= save_break
;
5860 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5861 c_parser_maybe_reclassify_token (parser
);
5864 /* Parse a while statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5867 while (expression) statement
5869 IF_P is used to track whether there's a (possibly labeled) if statement
5870 which is not enclosed in braces and has an else clause. This is used to
5871 implement -Wparentheses. */
5874 c_parser_while_statement (c_parser
*parser
, bool ivdep
, bool *if_p
)
5876 tree block
, cond
, body
, save_break
, save_cont
;
5878 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5879 token_indent_info while_tinfo
5880 = get_token_indent_info (c_parser_peek_token (parser
));
5881 c_parser_consume_token (parser
);
5882 block
= c_begin_compound_stmt (flag_isoc99
);
5883 loc
= c_parser_peek_token (parser
)->location
;
5884 cond
= c_parser_paren_condition (parser
);
5885 if (ivdep
&& cond
!= error_mark_node
)
5886 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5887 build_int_cst (integer_type_node
,
5888 annot_expr_ivdep_kind
),
5890 save_break
= c_break_label
;
5891 c_break_label
= NULL_TREE
;
5892 save_cont
= c_cont_label
;
5893 c_cont_label
= NULL_TREE
;
5895 token_indent_info body_tinfo
5896 = get_token_indent_info (c_parser_peek_token (parser
));
5898 location_t loc_after_labels
;
5899 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
5900 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
5901 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5902 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5903 c_parser_maybe_reclassify_token (parser
);
5905 token_indent_info next_tinfo
5906 = get_token_indent_info (c_parser_peek_token (parser
));
5907 warn_for_misleading_indentation (while_tinfo
, body_tinfo
, next_tinfo
);
5909 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
5910 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
5911 while_tinfo
.location
, RID_WHILE
);
5913 c_break_label
= save_break
;
5914 c_cont_label
= save_cont
;
5917 /* Parse a do statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5920 do statement while ( expression ) ;
5924 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5926 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5928 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5929 c_parser_consume_token (parser
);
5930 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5931 warning_at (c_parser_peek_token (parser
)->location
,
5933 "suggest braces around empty body in %<do%> statement");
5934 block
= c_begin_compound_stmt (flag_isoc99
);
5935 loc
= c_parser_peek_token (parser
)->location
;
5936 save_break
= c_break_label
;
5937 c_break_label
= NULL_TREE
;
5938 save_cont
= c_cont_label
;
5939 c_cont_label
= NULL_TREE
;
5940 body
= c_parser_c99_block_statement (parser
, NULL
);
5941 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5942 new_break
= c_break_label
;
5943 c_break_label
= save_break
;
5944 new_cont
= c_cont_label
;
5945 c_cont_label
= save_cont
;
5946 cond
= c_parser_paren_condition (parser
);
5947 if (ivdep
&& cond
!= error_mark_node
)
5948 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5949 build_int_cst (integer_type_node
,
5950 annot_expr_ivdep_kind
),
5952 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5953 c_parser_skip_to_end_of_block_or_statement (parser
);
5954 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5955 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5958 /* Parse a for statement (C90 6.6.5, C99 6.8.5, C11 6.8.5).
5961 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5962 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5964 The form with a declaration is new in C99.
5966 ??? In accordance with the old parser, the declaration may be a
5967 nested function, which is then rejected in check_for_loop_decls,
5968 but does it make any sense for this to be included in the grammar?
5969 Note in particular that the nested function does not include a
5970 trailing ';', whereas the "declaration" production includes one.
5971 Also, can we reject bad declarations earlier and cheaper than
5972 check_for_loop_decls?
5974 In Objective-C, there are two additional variants:
5977 for ( expression in expresssion ) statement
5978 for ( declaration in expression ) statement
5980 This is inconsistent with C, because the second variant is allowed
5981 even if c99 is not enabled.
5983 The rest of the comment documents these Objective-C foreach-statement.
5985 Here is the canonical example of the first variant:
5986 for (object in array) { do something with object }
5987 we call the first expression ("object") the "object_expression" and
5988 the second expression ("array") the "collection_expression".
5989 object_expression must be an lvalue of type "id" (a generic Objective-C
5990 object) because the loop works by assigning to object_expression the
5991 various objects from the collection_expression. collection_expression
5992 must evaluate to something of type "id" which responds to the method
5993 countByEnumeratingWithState:objects:count:.
5995 The canonical example of the second variant is:
5996 for (id object in array) { do something with object }
5997 which is completely equivalent to
6000 for (object in array) { do something with object }
6002 Note that initizializing 'object' in some way (eg, "for ((object =
6003 xxx) in array) { do something with object }") is possibly
6004 technically valid, but completely pointless as 'object' will be
6005 assigned to something else as soon as the loop starts. We should
6006 most likely reject it (TODO).
6008 The beginning of the Objective-C foreach-statement looks exactly
6009 like the beginning of the for-statement, and we can tell it is a
6010 foreach-statement only because the initial declaration or
6011 expression is terminated by 'in' instead of ';'.
6013 IF_P is used to track whether there's a (possibly labeled) if statement
6014 which is not enclosed in braces and has an else clause. This is used to
6015 implement -Wparentheses. */
6018 c_parser_for_statement (c_parser
*parser
, bool ivdep
, bool *if_p
)
6020 tree block
, cond
, incr
, save_break
, save_cont
, body
;
6021 /* The following are only used when parsing an ObjC foreach statement. */
6022 tree object_expression
;
6023 /* Silence the bogus uninitialized warning. */
6024 tree collection_expression
= NULL
;
6025 location_t loc
= c_parser_peek_token (parser
)->location
;
6026 location_t for_loc
= c_parser_peek_token (parser
)->location
;
6027 bool is_foreach_statement
= false;
6028 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
6029 token_indent_info for_tinfo
6030 = get_token_indent_info (c_parser_peek_token (parser
));
6031 c_parser_consume_token (parser
);
6032 /* Open a compound statement in Objective-C as well, just in case this is
6033 as foreach expression. */
6034 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
6035 cond
= error_mark_node
;
6036 incr
= error_mark_node
;
6037 matching_parens parens
;
6038 if (parens
.require_open (parser
))
6040 /* Parse the initialization declaration or expression. */
6041 object_expression
= error_mark_node
;
6042 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
6043 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6045 parser
->objc_could_be_foreach_context
= false;
6046 c_parser_consume_token (parser
);
6047 c_finish_expr_stmt (loc
, NULL_TREE
);
6049 else if (c_parser_next_tokens_start_declaration (parser
))
6051 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
6052 &object_expression
, vNULL
);
6053 parser
->objc_could_be_foreach_context
= false;
6055 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6057 c_parser_consume_token (parser
);
6058 is_foreach_statement
= true;
6059 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6060 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
6063 check_for_loop_decls (for_loc
, flag_isoc99
);
6065 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
6067 /* __extension__ can start a declaration, but is also an
6068 unary operator that can start an expression. Consume all
6069 but the last of a possible series of __extension__ to
6071 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
6072 && (c_parser_peek_2nd_token (parser
)->keyword
6074 c_parser_consume_token (parser
);
6075 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
6078 ext
= disable_extension_diagnostics ();
6079 c_parser_consume_token (parser
);
6080 c_parser_declaration_or_fndef (parser
, true, true, true, true,
6081 true, &object_expression
, vNULL
);
6082 parser
->objc_could_be_foreach_context
= false;
6084 restore_extension_diagnostics (ext
);
6085 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6087 c_parser_consume_token (parser
);
6088 is_foreach_statement
= true;
6089 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
6090 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
6093 check_for_loop_decls (for_loc
, flag_isoc99
);
6103 tree init_expression
;
6104 ce
= c_parser_expression (parser
);
6105 init_expression
= ce
.value
;
6106 parser
->objc_could_be_foreach_context
= false;
6107 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
6109 c_parser_consume_token (parser
);
6110 is_foreach_statement
= true;
6111 if (! lvalue_p (init_expression
))
6112 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
6113 object_expression
= c_fully_fold (init_expression
, false, NULL
);
6117 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6118 init_expression
= ce
.value
;
6119 c_finish_expr_stmt (loc
, init_expression
);
6120 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
6124 /* Parse the loop condition. In the case of a foreach
6125 statement, there is no loop condition. */
6126 gcc_assert (!parser
->objc_could_be_foreach_context
);
6127 if (!is_foreach_statement
)
6129 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6133 c_parser_error (parser
, "missing loop condition in loop with "
6134 "%<GCC ivdep%> pragma");
6135 cond
= error_mark_node
;
6139 c_parser_consume_token (parser
);
6145 cond
= c_parser_condition (parser
);
6146 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
6149 if (ivdep
&& cond
!= error_mark_node
)
6150 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6151 build_int_cst (integer_type_node
,
6152 annot_expr_ivdep_kind
),
6155 /* Parse the increment expression (the third expression in a
6156 for-statement). In the case of a foreach-statement, this is
6157 the expression that follows the 'in'. */
6158 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6160 if (is_foreach_statement
)
6162 c_parser_error (parser
, "missing collection in fast enumeration");
6163 collection_expression
= error_mark_node
;
6166 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
6170 if (is_foreach_statement
)
6171 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
6175 struct c_expr ce
= c_parser_expression (parser
);
6176 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6177 incr
= c_process_expr_stmt (loc
, ce
.value
);
6180 parens
.skip_until_found_close (parser
);
6182 save_break
= c_break_label
;
6183 c_break_label
= NULL_TREE
;
6184 save_cont
= c_cont_label
;
6185 c_cont_label
= NULL_TREE
;
6187 token_indent_info body_tinfo
6188 = get_token_indent_info (c_parser_peek_token (parser
));
6190 location_t loc_after_labels
;
6191 bool open_brace
= c_parser_next_token_is (parser
, CPP_OPEN_BRACE
);
6192 body
= c_parser_c99_block_statement (parser
, if_p
, &loc_after_labels
);
6194 if (is_foreach_statement
)
6195 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
6197 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
6198 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
6199 c_parser_maybe_reclassify_token (parser
);
6201 token_indent_info next_tinfo
6202 = get_token_indent_info (c_parser_peek_token (parser
));
6203 warn_for_misleading_indentation (for_tinfo
, body_tinfo
, next_tinfo
);
6205 if (next_tinfo
.type
!= CPP_SEMICOLON
&& !open_brace
)
6206 warn_for_multistatement_macros (loc_after_labels
, next_tinfo
.location
,
6207 for_tinfo
.location
, RID_FOR
);
6209 c_break_label
= save_break
;
6210 c_cont_label
= save_cont
;
6213 /* Parse an asm statement, a GNU extension. This is a full-blown asm
6214 statement with inputs, outputs, clobbers, and volatile tag
6218 asm type-qualifier[opt] ( asm-argument ) ;
6219 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
6223 asm-string-literal : asm-operands[opt]
6224 asm-string-literal : asm-operands[opt] : asm-operands[opt]
6225 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
6228 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
6231 Qualifiers other than volatile are accepted in the syntax but
6235 c_parser_asm_statement (c_parser
*parser
)
6237 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
6238 bool simple
, is_goto
;
6239 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
6240 int section
, nsections
;
6242 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
6243 c_parser_consume_token (parser
);
6244 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
6246 quals
= c_parser_peek_token (parser
)->value
;
6247 c_parser_consume_token (parser
);
6249 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
6250 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
6252 warning_at (c_parser_peek_token (parser
)->location
,
6254 "%E qualifier ignored on asm",
6255 c_parser_peek_token (parser
)->value
);
6257 c_parser_consume_token (parser
);
6263 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
6265 c_parser_consume_token (parser
);
6269 /* ??? Follow the C++ parser rather than using the
6270 lex_untranslated_string kludge. */
6271 parser
->lex_untranslated_string
= true;
6274 matching_parens parens
;
6275 if (!parens
.require_open (parser
))
6278 str
= c_parser_asm_string_literal (parser
);
6279 if (str
== NULL_TREE
)
6280 goto error_close_paren
;
6283 outputs
= NULL_TREE
;
6285 clobbers
= NULL_TREE
;
6288 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6291 /* Parse each colon-delimited section of operands. */
6292 nsections
= 3 + is_goto
;
6293 for (section
= 0; section
< nsections
; ++section
)
6295 if (!c_parser_require (parser
, CPP_COLON
,
6297 ? G_("expected %<:%>")
6298 : G_("expected %<:%> or %<)%>"),
6299 UNKNOWN_LOCATION
, is_goto
))
6300 goto error_close_paren
;
6302 /* Once past any colon, we're no longer a simple asm. */
6305 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
6306 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6311 /* For asm goto, we don't allow output operands, but reserve
6312 the slot for a future extension that does allow them. */
6314 outputs
= c_parser_asm_operands (parser
);
6317 inputs
= c_parser_asm_operands (parser
);
6320 clobbers
= c_parser_asm_clobbers (parser
);
6323 labels
= c_parser_asm_goto_operands (parser
);
6329 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6334 if (!parens
.require_close (parser
))
6336 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6340 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6341 c_parser_skip_to_end_of_block_or_statement (parser
);
6343 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
6344 clobbers
, labels
, simple
));
6347 parser
->lex_untranslated_string
= false;
6351 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6355 /* Parse asm operands, a GNU extension.
6359 asm-operands , asm-operand
6362 asm-string-literal ( expression )
6363 [ identifier ] asm-string-literal ( expression )
6367 c_parser_asm_operands (c_parser
*parser
)
6369 tree list
= NULL_TREE
;
6374 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
6376 c_parser_consume_token (parser
);
6377 if (c_parser_next_token_is (parser
, CPP_NAME
))
6379 tree id
= c_parser_peek_token (parser
)->value
;
6380 c_parser_consume_token (parser
);
6381 name
= build_string (IDENTIFIER_LENGTH (id
),
6382 IDENTIFIER_POINTER (id
));
6386 c_parser_error (parser
, "expected identifier");
6387 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
6390 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6395 str
= c_parser_asm_string_literal (parser
);
6396 if (str
== NULL_TREE
)
6398 parser
->lex_untranslated_string
= false;
6399 matching_parens parens
;
6400 if (!parens
.require_open (parser
))
6402 parser
->lex_untranslated_string
= true;
6405 expr
= c_parser_expression (parser
);
6406 mark_exp_read (expr
.value
);
6407 parser
->lex_untranslated_string
= true;
6408 if (!parens
.require_close (parser
))
6410 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6413 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
6415 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6416 c_parser_consume_token (parser
);
6423 /* Parse asm clobbers, a GNU extension.
6427 asm-clobbers , asm-string-literal
6431 c_parser_asm_clobbers (c_parser
*parser
)
6433 tree list
= NULL_TREE
;
6436 tree str
= c_parser_asm_string_literal (parser
);
6438 list
= tree_cons (NULL_TREE
, str
, list
);
6441 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6442 c_parser_consume_token (parser
);
6449 /* Parse asm goto labels, a GNU extension.
6453 asm-goto-operands , identifier
6457 c_parser_asm_goto_operands (c_parser
*parser
)
6459 tree list
= NULL_TREE
;
6464 if (c_parser_next_token_is (parser
, CPP_NAME
))
6466 c_token
*tok
= c_parser_peek_token (parser
);
6468 label
= lookup_label_for_goto (tok
->location
, name
);
6469 c_parser_consume_token (parser
);
6470 TREE_USED (label
) = 1;
6474 c_parser_error (parser
, "expected identifier");
6478 name
= build_string (IDENTIFIER_LENGTH (name
),
6479 IDENTIFIER_POINTER (name
));
6480 list
= tree_cons (name
, label
, list
);
6481 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6482 c_parser_consume_token (parser
);
6484 return nreverse (list
);
6488 /* Parse an expression other than a compound expression; that is, an
6489 assignment expression (C90 6.3.16, C99 6.5.16, C11 6.5.16). If
6490 AFTER is not NULL then it is an Objective-C message expression which
6491 is the primary-expression starting the expression as an initializer.
6493 assignment-expression:
6494 conditional-expression
6495 unary-expression assignment-operator assignment-expression
6497 assignment-operator: one of
6498 = *= /= %= += -= <<= >>= &= ^= |=
6500 In GNU C we accept any conditional expression on the LHS and
6501 diagnose the invalid lvalue rather than producing a syntax
6504 static struct c_expr
6505 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
6506 tree omp_atomic_lhs
)
6508 struct c_expr lhs
, rhs
, ret
;
6509 enum tree_code code
;
6510 location_t op_location
, exp_location
;
6511 gcc_assert (!after
|| c_dialect_objc ());
6512 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
6513 op_location
= c_parser_peek_token (parser
)->location
;
6514 switch (c_parser_peek_token (parser
)->type
)
6523 code
= TRUNC_DIV_EXPR
;
6526 code
= TRUNC_MOD_EXPR
;
6541 code
= BIT_AND_EXPR
;
6544 code
= BIT_XOR_EXPR
;
6547 code
= BIT_IOR_EXPR
;
6552 c_parser_consume_token (parser
);
6553 exp_location
= c_parser_peek_token (parser
)->location
;
6554 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6555 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6557 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6558 code
, exp_location
, rhs
.value
,
6560 set_c_expr_source_range (&ret
, lhs
.get_start (), rhs
.get_finish ());
6561 if (code
== NOP_EXPR
)
6562 ret
.original_code
= MODIFY_EXPR
;
6565 TREE_NO_WARNING (ret
.value
) = 1;
6566 ret
.original_code
= ERROR_MARK
;
6568 ret
.original_type
= NULL
;
6572 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15, C11 6.5.15). If
6573 AFTER is not NULL then it is an Objective-C message expression which is
6574 the primary-expression starting the expression as an initializer.
6576 conditional-expression:
6577 logical-OR-expression
6578 logical-OR-expression ? expression : conditional-expression
6582 conditional-expression:
6583 logical-OR-expression ? : conditional-expression
6586 static struct c_expr
6587 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6588 tree omp_atomic_lhs
)
6590 struct c_expr cond
, exp1
, exp2
, ret
;
6591 location_t start
, cond_loc
, colon_loc
;
6593 gcc_assert (!after
|| c_dialect_objc ());
6595 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6597 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6599 if (cond
.value
!= error_mark_node
)
6600 start
= cond
.get_start ();
6602 start
= UNKNOWN_LOCATION
;
6603 cond_loc
= c_parser_peek_token (parser
)->location
;
6604 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6605 c_parser_consume_token (parser
);
6606 if (c_parser_next_token_is (parser
, CPP_COLON
))
6608 tree eptype
= NULL_TREE
;
6610 location_t middle_loc
= c_parser_peek_token (parser
)->location
;
6611 pedwarn (middle_loc
, OPT_Wpedantic
,
6612 "ISO C forbids omitting the middle term of a ?: expression");
6613 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6615 eptype
= TREE_TYPE (cond
.value
);
6616 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6618 tree e
= cond
.value
;
6619 while (TREE_CODE (e
) == COMPOUND_EXPR
)
6620 e
= TREE_OPERAND (e
, 1);
6621 warn_for_omitted_condop (middle_loc
, e
);
6622 /* Make sure first operand is calculated only once. */
6623 exp1
.value
= save_expr (default_conversion (cond
.value
));
6625 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6626 exp1
.original_type
= NULL
;
6627 exp1
.src_range
= cond
.src_range
;
6628 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6629 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6634 = c_objc_common_truthvalue_conversion
6635 (cond_loc
, default_conversion (cond
.value
));
6636 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6637 exp1
= c_parser_expression_conv (parser
);
6638 mark_exp_read (exp1
.value
);
6639 c_inhibit_evaluation_warnings
+=
6640 ((cond
.value
== truthvalue_true_node
)
6641 - (cond
.value
== truthvalue_false_node
));
6644 colon_loc
= c_parser_peek_token (parser
)->location
;
6645 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6647 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6648 ret
.value
= error_mark_node
;
6649 ret
.original_code
= ERROR_MARK
;
6650 ret
.original_type
= NULL
;
6654 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6655 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6656 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6658 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6659 location_t loc1
= make_location (exp1
.get_start (), exp1
.src_range
);
6660 location_t loc2
= make_location (exp2
.get_start (), exp2
.src_range
);
6661 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6662 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6663 exp1
.value
, exp1
.original_type
, loc1
,
6664 exp2
.value
, exp2
.original_type
, loc2
);
6665 ret
.original_code
= ERROR_MARK
;
6666 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6667 ret
.original_type
= NULL
;
6672 /* If both sides are enum type, the default conversion will have
6673 made the type of the result be an integer type. We want to
6674 remember the enum types we started with. */
6675 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6676 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6677 ret
.original_type
= ((t1
!= error_mark_node
6678 && t2
!= error_mark_node
6679 && (TYPE_MAIN_VARIANT (t1
)
6680 == TYPE_MAIN_VARIANT (t2
)))
6684 set_c_expr_source_range (&ret
, start
, exp2
.get_finish ());
6688 /* Parse a binary expression; that is, a logical-OR-expression (C90
6689 6.3.5-6.3.14, C99 6.5.5-6.5.14, C11 6.5.5-6.5.14). If AFTER is not
6690 NULL then it is an Objective-C message expression which is the
6691 primary-expression starting the expression as an initializer.
6693 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6694 when it should be the unfolded lhs. In a valid OpenMP source,
6695 one of the operands of the toplevel binary expression must be equal
6696 to it. In that case, just return a build2 created binary operation
6697 rather than result of parser_build_binary_op.
6699 multiplicative-expression:
6701 multiplicative-expression * cast-expression
6702 multiplicative-expression / cast-expression
6703 multiplicative-expression % cast-expression
6705 additive-expression:
6706 multiplicative-expression
6707 additive-expression + multiplicative-expression
6708 additive-expression - multiplicative-expression
6712 shift-expression << additive-expression
6713 shift-expression >> additive-expression
6715 relational-expression:
6717 relational-expression < shift-expression
6718 relational-expression > shift-expression
6719 relational-expression <= shift-expression
6720 relational-expression >= shift-expression
6722 equality-expression:
6723 relational-expression
6724 equality-expression == relational-expression
6725 equality-expression != relational-expression
6729 AND-expression & equality-expression
6731 exclusive-OR-expression:
6733 exclusive-OR-expression ^ AND-expression
6735 inclusive-OR-expression:
6736 exclusive-OR-expression
6737 inclusive-OR-expression | exclusive-OR-expression
6739 logical-AND-expression:
6740 inclusive-OR-expression
6741 logical-AND-expression && inclusive-OR-expression
6743 logical-OR-expression:
6744 logical-AND-expression
6745 logical-OR-expression || logical-AND-expression
6748 static struct c_expr
6749 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6750 tree omp_atomic_lhs
)
6752 /* A binary expression is parsed using operator-precedence parsing,
6753 with the operands being cast expressions. All the binary
6754 operators are left-associative. Thus a binary expression is of
6757 E0 op1 E1 op2 E2 ...
6759 which we represent on a stack. On the stack, the precedence
6760 levels are strictly increasing. When a new operator is
6761 encountered of higher precedence than that at the top of the
6762 stack, it is pushed; its LHS is the top expression, and its RHS
6763 is everything parsed until it is popped. When a new operator is
6764 encountered with precedence less than or equal to that at the top
6765 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6766 by the result of the operation until the operator at the top of
6767 the stack has lower precedence than the new operator or there is
6768 only one element on the stack; then the top expression is the LHS
6769 of the new operator. In the case of logical AND and OR
6770 expressions, we also need to adjust c_inhibit_evaluation_warnings
6771 as appropriate when the operators are pushed and popped. */
6774 /* The expression at this stack level. */
6776 /* The precedence of the operator on its left, PREC_NONE at the
6777 bottom of the stack. */
6778 enum c_parser_prec prec
;
6779 /* The operation on its left. */
6781 /* The source location of this operation. */
6783 /* The sizeof argument if expr.original_code == SIZEOF_EXPR. */
6787 /* Location of the binary operator. */
6788 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6791 switch (stack[sp].op) \
6793 case TRUTH_ANDIF_EXPR: \
6794 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6795 == truthvalue_false_node); \
6797 case TRUTH_ORIF_EXPR: \
6798 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6799 == truthvalue_true_node); \
6801 case TRUNC_DIV_EXPR: \
6802 if (stack[sp - 1].expr.original_code == SIZEOF_EXPR \
6803 && stack[sp].expr.original_code == SIZEOF_EXPR) \
6805 tree type0 = stack[sp - 1].sizeof_arg; \
6806 tree type1 = stack[sp].sizeof_arg; \
6807 tree first_arg = type0; \
6808 if (!TYPE_P (type0)) \
6809 type0 = TREE_TYPE (type0); \
6810 if (!TYPE_P (type1)) \
6811 type1 = TREE_TYPE (type1); \
6812 if (POINTER_TYPE_P (type0) \
6813 && comptypes (TREE_TYPE (type0), type1) \
6814 && !(TREE_CODE (first_arg) == PARM_DECL \
6815 && C_ARRAY_PARAMETER (first_arg) \
6816 && warn_sizeof_array_argument)) \
6817 if (warning_at (stack[sp].loc, OPT_Wsizeof_pointer_div, \
6818 "division %<sizeof (%T) / sizeof (%T)%> does " \
6819 "not compute the number of array elements", \
6821 if (DECL_P (first_arg)) \
6822 inform (DECL_SOURCE_LOCATION (first_arg), \
6823 "first %<sizeof%> operand was declared here"); \
6829 stack[sp - 1].expr \
6830 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6831 stack[sp - 1].expr, true, true); \
6833 = convert_lvalue_to_rvalue (stack[sp].loc, \
6834 stack[sp].expr, true, true); \
6835 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6836 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6837 && ((1 << stack[sp].prec) \
6838 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6839 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6840 && stack[sp].op != TRUNC_MOD_EXPR \
6841 && stack[0].expr.value != error_mark_node \
6842 && stack[1].expr.value != error_mark_node \
6843 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6844 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6845 stack[0].expr.value \
6846 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6847 stack[0].expr.value, stack[1].expr.value); \
6849 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6851 stack[sp - 1].expr, \
6855 gcc_assert (!after
|| c_dialect_objc ());
6856 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6857 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6858 stack
[0].prec
= PREC_NONE
;
6859 stack
[0].sizeof_arg
= c_last_sizeof_arg
;
6863 enum c_parser_prec oprec
;
6864 enum tree_code ocode
;
6865 source_range src_range
;
6868 switch (c_parser_peek_token (parser
)->type
)
6876 ocode
= TRUNC_DIV_EXPR
;
6880 ocode
= TRUNC_MOD_EXPR
;
6892 ocode
= LSHIFT_EXPR
;
6896 ocode
= RSHIFT_EXPR
;
6910 case CPP_GREATER_EQ
:
6923 oprec
= PREC_BITAND
;
6924 ocode
= BIT_AND_EXPR
;
6927 oprec
= PREC_BITXOR
;
6928 ocode
= BIT_XOR_EXPR
;
6932 ocode
= BIT_IOR_EXPR
;
6935 oprec
= PREC_LOGAND
;
6936 ocode
= TRUTH_ANDIF_EXPR
;
6940 ocode
= TRUTH_ORIF_EXPR
;
6943 /* Not a binary operator, so end of the binary
6947 binary_loc
= c_parser_peek_token (parser
)->location
;
6948 while (oprec
<= stack
[sp
].prec
)
6950 c_parser_consume_token (parser
);
6953 case TRUTH_ANDIF_EXPR
:
6954 src_range
= stack
[sp
].expr
.src_range
;
6956 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6957 stack
[sp
].expr
, true, true);
6958 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6959 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6960 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6961 == truthvalue_false_node
);
6962 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
6964 case TRUTH_ORIF_EXPR
:
6965 src_range
= stack
[sp
].expr
.src_range
;
6967 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6968 stack
[sp
].expr
, true, true);
6969 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6970 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6971 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6972 == truthvalue_true_node
);
6973 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
6979 stack
[sp
].loc
= binary_loc
;
6980 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6981 stack
[sp
].prec
= oprec
;
6982 stack
[sp
].op
= ocode
;
6983 stack
[sp
].sizeof_arg
= c_last_sizeof_arg
;
6988 return stack
[0].expr
;
6992 /* Parse a cast expression (C90 6.3.4, C99 6.5.4, C11 6.5.4). If AFTER
6993 is not NULL then it is an Objective-C message expression which is the
6994 primary-expression starting the expression as an initializer.
6998 ( type-name ) unary-expression
7001 static struct c_expr
7002 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
7004 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
7005 gcc_assert (!after
|| c_dialect_objc ());
7007 return c_parser_postfix_expression_after_primary (parser
,
7009 /* If the expression begins with a parenthesized type name, it may
7010 be either a cast or a compound literal; we need to see whether
7011 the next character is '{' to tell the difference. If not, it is
7012 an unary expression. Full detection of unknown typenames here
7013 would require a 3-token lookahead. */
7014 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7015 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7017 struct c_type_name
*type_name
;
7020 matching_parens parens
;
7021 parens
.consume_open (parser
);
7022 type_name
= c_parser_type_name (parser
);
7023 parens
.skip_until_found_close (parser
);
7024 if (type_name
== NULL
)
7026 ret
.value
= error_mark_node
;
7027 ret
.original_code
= ERROR_MARK
;
7028 ret
.original_type
= NULL
;
7032 /* Save casted types in the function's used types hash table. */
7033 used_types_insert (type_name
->specs
->type
);
7035 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7036 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
7039 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
7040 expr
= c_parser_cast_expression (parser
, NULL
);
7041 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
7043 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
7044 if (ret
.value
&& expr
.value
)
7045 set_c_expr_source_range (&ret
, cast_loc
, expr
.get_finish ());
7046 ret
.original_code
= ERROR_MARK
;
7047 ret
.original_type
= NULL
;
7051 return c_parser_unary_expression (parser
);
7054 /* Parse an unary expression (C90 6.3.3, C99 6.5.3, C11 6.5.3).
7060 unary-operator cast-expression
7061 sizeof unary-expression
7062 sizeof ( type-name )
7064 unary-operator: one of
7070 __alignof__ unary-expression
7071 __alignof__ ( type-name )
7074 (C11 permits _Alignof with type names only.)
7076 unary-operator: one of
7077 __extension__ __real__ __imag__
7079 Transactional Memory:
7082 transaction-expression
7084 In addition, the GNU syntax treats ++ and -- as unary operators, so
7085 they may be applied to cast expressions with errors for non-lvalues
7088 static struct c_expr
7089 c_parser_unary_expression (c_parser
*parser
)
7092 struct c_expr ret
, op
;
7093 location_t op_loc
= c_parser_peek_token (parser
)->location
;
7096 ret
.original_code
= ERROR_MARK
;
7097 ret
.original_type
= NULL
;
7098 switch (c_parser_peek_token (parser
)->type
)
7101 c_parser_consume_token (parser
);
7102 exp_loc
= c_parser_peek_token (parser
)->location
;
7103 op
= c_parser_cast_expression (parser
, NULL
);
7105 op
= default_function_array_read_conversion (exp_loc
, op
);
7106 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
7107 case CPP_MINUS_MINUS
:
7108 c_parser_consume_token (parser
);
7109 exp_loc
= c_parser_peek_token (parser
)->location
;
7110 op
= c_parser_cast_expression (parser
, NULL
);
7112 op
= default_function_array_read_conversion (exp_loc
, op
);
7113 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
7115 c_parser_consume_token (parser
);
7116 op
= c_parser_cast_expression (parser
, NULL
);
7117 mark_exp_read (op
.value
);
7118 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
7121 c_parser_consume_token (parser
);
7122 exp_loc
= c_parser_peek_token (parser
)->location
;
7123 op
= c_parser_cast_expression (parser
, NULL
);
7124 finish
= op
.get_finish ();
7125 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7126 location_t combined_loc
= make_location (op_loc
, op_loc
, finish
);
7127 ret
.value
= build_indirect_ref (combined_loc
, op
.value
, RO_UNARY_STAR
);
7128 ret
.src_range
.m_start
= op_loc
;
7129 ret
.src_range
.m_finish
= finish
;
7133 if (!c_dialect_objc () && !in_system_header_at (input_location
))
7136 "traditional C rejects the unary plus operator");
7137 c_parser_consume_token (parser
);
7138 exp_loc
= c_parser_peek_token (parser
)->location
;
7139 op
= c_parser_cast_expression (parser
, NULL
);
7140 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7141 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
7143 c_parser_consume_token (parser
);
7144 exp_loc
= c_parser_peek_token (parser
)->location
;
7145 op
= c_parser_cast_expression (parser
, NULL
);
7146 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7147 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
7149 c_parser_consume_token (parser
);
7150 exp_loc
= c_parser_peek_token (parser
)->location
;
7151 op
= c_parser_cast_expression (parser
, NULL
);
7152 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7153 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
7155 c_parser_consume_token (parser
);
7156 exp_loc
= c_parser_peek_token (parser
)->location
;
7157 op
= c_parser_cast_expression (parser
, NULL
);
7158 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7159 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
7161 /* Refer to the address of a label as a pointer. */
7162 c_parser_consume_token (parser
);
7163 if (c_parser_next_token_is (parser
, CPP_NAME
))
7165 ret
.value
= finish_label_address_expr
7166 (c_parser_peek_token (parser
)->value
, op_loc
);
7167 set_c_expr_source_range (&ret
, op_loc
,
7168 c_parser_peek_token (parser
)->get_finish ());
7169 c_parser_consume_token (parser
);
7173 c_parser_error (parser
, "expected identifier");
7178 switch (c_parser_peek_token (parser
)->keyword
)
7181 return c_parser_sizeof_expression (parser
);
7183 return c_parser_alignof_expression (parser
);
7185 c_parser_consume_token (parser
);
7186 ext
= disable_extension_diagnostics ();
7187 ret
= c_parser_cast_expression (parser
, NULL
);
7188 restore_extension_diagnostics (ext
);
7191 c_parser_consume_token (parser
);
7192 exp_loc
= c_parser_peek_token (parser
)->location
;
7193 op
= c_parser_cast_expression (parser
, NULL
);
7194 op
= default_function_array_conversion (exp_loc
, op
);
7195 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
7197 c_parser_consume_token (parser
);
7198 exp_loc
= c_parser_peek_token (parser
)->location
;
7199 op
= c_parser_cast_expression (parser
, NULL
);
7200 op
= default_function_array_conversion (exp_loc
, op
);
7201 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
7202 case RID_TRANSACTION_ATOMIC
:
7203 case RID_TRANSACTION_RELAXED
:
7204 return c_parser_transaction_expression (parser
,
7205 c_parser_peek_token (parser
)->keyword
);
7207 return c_parser_postfix_expression (parser
);
7210 return c_parser_postfix_expression (parser
);
7214 /* Parse a sizeof expression. */
7216 static struct c_expr
7217 c_parser_sizeof_expression (c_parser
*parser
)
7220 struct c_expr result
;
7221 location_t expr_loc
;
7222 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
7225 location_t finish
= UNKNOWN_LOCATION
;
7227 start
= c_parser_peek_token (parser
)->location
;
7229 c_parser_consume_token (parser
);
7230 c_inhibit_evaluation_warnings
++;
7232 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7233 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7235 /* Either sizeof ( type-name ) or sizeof unary-expression
7236 starting with a compound literal. */
7237 struct c_type_name
*type_name
;
7238 matching_parens parens
;
7239 parens
.consume_open (parser
);
7240 expr_loc
= c_parser_peek_token (parser
)->location
;
7241 type_name
= c_parser_type_name (parser
);
7242 parens
.skip_until_found_close (parser
);
7243 finish
= parser
->tokens_buf
[0].location
;
7244 if (type_name
== NULL
)
7247 c_inhibit_evaluation_warnings
--;
7249 ret
.value
= error_mark_node
;
7250 ret
.original_code
= ERROR_MARK
;
7251 ret
.original_type
= NULL
;
7254 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7256 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7259 finish
= expr
.get_finish ();
7262 /* sizeof ( type-name ). */
7263 c_inhibit_evaluation_warnings
--;
7265 result
= c_expr_sizeof_type (expr_loc
, type_name
);
7269 expr_loc
= c_parser_peek_token (parser
)->location
;
7270 expr
= c_parser_unary_expression (parser
);
7271 finish
= expr
.get_finish ();
7273 c_inhibit_evaluation_warnings
--;
7275 mark_exp_read (expr
.value
);
7276 if (TREE_CODE (expr
.value
) == COMPONENT_REF
7277 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
7278 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
7279 result
= c_expr_sizeof_expr (expr_loc
, expr
);
7281 if (finish
!= UNKNOWN_LOCATION
)
7282 set_c_expr_source_range (&result
, start
, finish
);
7286 /* Parse an alignof expression. */
7288 static struct c_expr
7289 c_parser_alignof_expression (c_parser
*parser
)
7292 location_t start_loc
= c_parser_peek_token (parser
)->location
;
7294 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
7295 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
7296 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
7298 /* A diagnostic is not required for the use of this identifier in
7299 the implementation namespace; only diagnose it for the C11
7300 spelling because of existing code using the other spellings. */
7304 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
7307 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
7310 c_parser_consume_token (parser
);
7311 c_inhibit_evaluation_warnings
++;
7313 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7314 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7316 /* Either __alignof__ ( type-name ) or __alignof__
7317 unary-expression starting with a compound literal. */
7319 struct c_type_name
*type_name
;
7321 matching_parens parens
;
7322 parens
.consume_open (parser
);
7323 loc
= c_parser_peek_token (parser
)->location
;
7324 type_name
= c_parser_type_name (parser
);
7325 end_loc
= c_parser_peek_token (parser
)->location
;
7326 parens
.skip_until_found_close (parser
);
7327 if (type_name
== NULL
)
7330 c_inhibit_evaluation_warnings
--;
7332 ret
.value
= error_mark_node
;
7333 ret
.original_code
= ERROR_MARK
;
7334 ret
.original_type
= NULL
;
7337 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7339 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7344 /* alignof ( type-name ). */
7345 c_inhibit_evaluation_warnings
--;
7347 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
7349 false, is_c11_alignof
, 1);
7350 ret
.original_code
= ERROR_MARK
;
7351 ret
.original_type
= NULL
;
7352 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7358 expr
= c_parser_unary_expression (parser
);
7359 end_loc
= expr
.src_range
.m_finish
;
7361 mark_exp_read (expr
.value
);
7362 c_inhibit_evaluation_warnings
--;
7366 OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
7368 ret
.value
= c_alignof_expr (start_loc
, expr
.value
);
7369 ret
.original_code
= ERROR_MARK
;
7370 ret
.original_type
= NULL
;
7371 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7376 /* Helper function to read arguments of builtins which are interfaces
7377 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
7378 others. The name of the builtin is passed using BNAME parameter.
7379 Function returns true if there were no errors while parsing and
7380 stores the arguments in CEXPR_LIST. If it returns true,
7381 *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
7384 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
7385 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
7387 location_t
*out_close_paren_loc
)
7389 location_t loc
= c_parser_peek_token (parser
)->location
;
7390 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7392 bool saved_force_folding_builtin_constant_p
;
7394 *ret_cexpr_list
= NULL
;
7395 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
7397 error_at (loc
, "cannot take address of %qs", bname
);
7401 c_parser_consume_token (parser
);
7403 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7405 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7406 c_parser_consume_token (parser
);
7410 saved_force_folding_builtin_constant_p
7411 = force_folding_builtin_constant_p
;
7412 force_folding_builtin_constant_p
|= choose_expr_p
;
7413 expr
= c_parser_expr_no_commas (parser
, NULL
);
7414 force_folding_builtin_constant_p
7415 = saved_force_folding_builtin_constant_p
;
7416 vec_alloc (cexpr_list
, 1);
7417 vec_safe_push (cexpr_list
, expr
);
7418 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7420 c_parser_consume_token (parser
);
7421 expr
= c_parser_expr_no_commas (parser
, NULL
);
7422 vec_safe_push (cexpr_list
, expr
);
7425 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7426 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7429 *ret_cexpr_list
= cexpr_list
;
7433 /* This represents a single generic-association. */
7435 struct c_generic_association
7437 /* The location of the starting token of the type. */
7438 location_t type_location
;
7439 /* The association's type, or NULL_TREE for 'default'. */
7441 /* The association's expression. */
7442 struct c_expr expression
;
7445 /* Parse a generic-selection. (C11 6.5.1.1).
7448 _Generic ( assignment-expression , generic-assoc-list )
7452 generic-assoc-list , generic-association
7454 generic-association:
7455 type-name : assignment-expression
7456 default : assignment-expression
7459 static struct c_expr
7460 c_parser_generic_selection (c_parser
*parser
)
7462 struct c_expr selector
, error_expr
;
7464 struct c_generic_association matched_assoc
;
7465 bool match_found
= false;
7466 location_t generic_loc
, selector_loc
;
7468 error_expr
.original_code
= ERROR_MARK
;
7469 error_expr
.original_type
= NULL
;
7470 error_expr
.set_error ();
7471 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
7472 matched_assoc
.type
= NULL_TREE
;
7473 matched_assoc
.expression
= error_expr
;
7475 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
7476 generic_loc
= c_parser_peek_token (parser
)->location
;
7477 c_parser_consume_token (parser
);
7479 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7480 "ISO C99 does not support %<_Generic%>");
7482 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7483 "ISO C90 does not support %<_Generic%>");
7485 matching_parens parens
;
7486 if (!parens
.require_open (parser
))
7489 c_inhibit_evaluation_warnings
++;
7490 selector_loc
= c_parser_peek_token (parser
)->location
;
7491 selector
= c_parser_expr_no_commas (parser
, NULL
);
7492 selector
= default_function_array_conversion (selector_loc
, selector
);
7493 c_inhibit_evaluation_warnings
--;
7495 if (selector
.value
== error_mark_node
)
7497 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7500 selector_type
= TREE_TYPE (selector
.value
);
7501 /* In ISO C terms, rvalues (including the controlling expression of
7502 _Generic) do not have qualified types. */
7503 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
7504 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
7505 /* In ISO C terms, _Noreturn is not part of the type of expressions
7506 such as &abort, but in GCC it is represented internally as a type
7508 if (FUNCTION_POINTER_TYPE_P (selector_type
)
7509 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
7511 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
7513 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7515 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7519 auto_vec
<c_generic_association
> associations
;
7522 struct c_generic_association assoc
, *iter
;
7524 c_token
*token
= c_parser_peek_token (parser
);
7526 assoc
.type_location
= token
->location
;
7527 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
7529 c_parser_consume_token (parser
);
7530 assoc
.type
= NULL_TREE
;
7534 struct c_type_name
*type_name
;
7536 type_name
= c_parser_type_name (parser
);
7537 if (type_name
== NULL
)
7539 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7542 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
7543 if (assoc
.type
== error_mark_node
)
7545 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7549 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
7550 error_at (assoc
.type_location
,
7551 "%<_Generic%> association has function type");
7552 else if (!COMPLETE_TYPE_P (assoc
.type
))
7553 error_at (assoc
.type_location
,
7554 "%<_Generic%> association has incomplete type");
7556 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
7557 error_at (assoc
.type_location
,
7558 "%<_Generic%> association has "
7559 "variable length type");
7562 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7564 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7568 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
7569 if (assoc
.expression
.value
== error_mark_node
)
7571 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7575 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
7577 if (assoc
.type
== NULL_TREE
)
7579 if (iter
->type
== NULL_TREE
)
7581 error_at (assoc
.type_location
,
7582 "duplicate %<default%> case in %<_Generic%>");
7583 inform (iter
->type_location
, "original %<default%> is here");
7586 else if (iter
->type
!= NULL_TREE
)
7588 if (comptypes (assoc
.type
, iter
->type
))
7590 error_at (assoc
.type_location
,
7591 "%<_Generic%> specifies two compatible types");
7592 inform (iter
->type_location
, "compatible type is here");
7597 if (assoc
.type
== NULL_TREE
)
7601 matched_assoc
= assoc
;
7605 else if (comptypes (assoc
.type
, selector_type
))
7607 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7609 matched_assoc
= assoc
;
7614 error_at (assoc
.type_location
,
7615 "%<_Generic%> selector matches multiple associations");
7616 inform (matched_assoc
.type_location
,
7617 "other match is here");
7621 associations
.safe_push (assoc
);
7623 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7625 c_parser_consume_token (parser
);
7628 if (!parens
.require_close (parser
))
7630 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7636 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7637 "compatible with any association",
7642 return matched_assoc
.expression
;
7645 /* Check the validity of a function pointer argument *EXPR (argument
7646 position POS) to __builtin_tgmath. Return the number of function
7647 arguments if possibly valid; return 0 having reported an error if
7651 check_tgmath_function (c_expr
*expr
, unsigned int pos
)
7653 tree type
= TREE_TYPE (expr
->value
);
7654 if (!FUNCTION_POINTER_TYPE_P (type
))
7656 error_at (expr
->get_location (),
7657 "argument %u of %<__builtin_tgmath%> is not a function pointer",
7661 type
= TREE_TYPE (type
);
7662 if (!prototype_p (type
))
7664 error_at (expr
->get_location (),
7665 "argument %u of %<__builtin_tgmath%> is unprototyped", pos
);
7668 if (stdarg_p (type
))
7670 error_at (expr
->get_location (),
7671 "argument %u of %<__builtin_tgmath%> has variable arguments",
7675 unsigned int nargs
= 0;
7676 function_args_iterator iter
;
7678 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
7680 if (t
== void_type_node
)
7686 error_at (expr
->get_location (),
7687 "argument %u of %<__builtin_tgmath%> has no arguments", pos
);
7693 /* Ways in which a parameter or return value of a type-generic macro
7694 may vary between the different functions the macro may call. */
7695 enum tgmath_parm_kind
7697 tgmath_fixed
, tgmath_real
, tgmath_complex
7700 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2,
7701 C11 6.5.1-6.5.2). Compound literals aren't handled here; callers have to
7702 call c_parser_postfix_expression_after_paren_type on encountering them.
7706 postfix-expression [ expression ]
7707 postfix-expression ( argument-expression-list[opt] )
7708 postfix-expression . identifier
7709 postfix-expression -> identifier
7710 postfix-expression ++
7711 postfix-expression --
7712 ( type-name ) { initializer-list }
7713 ( type-name ) { initializer-list , }
7715 argument-expression-list:
7717 argument-expression-list , argument-expression
7730 (treated as a keyword in GNU C)
7733 ( compound-statement )
7734 __builtin_va_arg ( assignment-expression , type-name )
7735 __builtin_offsetof ( type-name , offsetof-member-designator )
7736 __builtin_choose_expr ( assignment-expression ,
7737 assignment-expression ,
7738 assignment-expression )
7739 __builtin_types_compatible_p ( type-name , type-name )
7740 __builtin_tgmath ( expr-list )
7741 __builtin_complex ( assignment-expression , assignment-expression )
7742 __builtin_shuffle ( assignment-expression , assignment-expression )
7743 __builtin_shuffle ( assignment-expression ,
7744 assignment-expression ,
7745 assignment-expression, )
7747 offsetof-member-designator:
7749 offsetof-member-designator . identifier
7750 offsetof-member-designator [ expression ]
7755 [ objc-receiver objc-message-args ]
7756 @selector ( objc-selector-arg )
7757 @protocol ( identifier )
7758 @encode ( type-name )
7760 Classname . identifier
7763 static struct c_expr
7764 c_parser_postfix_expression (c_parser
*parser
)
7766 struct c_expr expr
, e1
;
7767 struct c_type_name
*t1
, *t2
;
7768 location_t loc
= c_parser_peek_token (parser
)->location
;
7769 source_range tok_range
= c_parser_peek_token (parser
)->get_range ();
7770 expr
.original_code
= ERROR_MARK
;
7771 expr
.original_type
= NULL
;
7772 switch (c_parser_peek_token (parser
)->type
)
7775 expr
.value
= c_parser_peek_token (parser
)->value
;
7776 set_c_expr_source_range (&expr
, tok_range
);
7777 loc
= c_parser_peek_token (parser
)->location
;
7778 c_parser_consume_token (parser
);
7779 if (TREE_CODE (expr
.value
) == FIXED_CST
7780 && !targetm
.fixed_point_supported_p ())
7782 error_at (loc
, "fixed-point types not supported for this target");
7783 expr
.value
= error_mark_node
;
7790 expr
.value
= c_parser_peek_token (parser
)->value
;
7791 /* For the purpose of warning when a pointer is compared with
7792 a zero character constant. */
7793 expr
.original_type
= char_type_node
;
7794 set_c_expr_source_range (&expr
, tok_range
);
7795 c_parser_consume_token (parser
);
7801 case CPP_UTF8STRING
:
7802 expr
.value
= c_parser_peek_token (parser
)->value
;
7803 set_c_expr_source_range (&expr
, tok_range
);
7804 expr
.original_code
= STRING_CST
;
7805 c_parser_consume_token (parser
);
7807 case CPP_OBJC_STRING
:
7808 gcc_assert (c_dialect_objc ());
7810 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7811 set_c_expr_source_range (&expr
, tok_range
);
7812 c_parser_consume_token (parser
);
7815 switch (c_parser_peek_token (parser
)->id_kind
)
7819 tree id
= c_parser_peek_token (parser
)->value
;
7820 c_parser_consume_token (parser
);
7821 expr
.value
= build_external_ref (loc
, id
,
7822 (c_parser_peek_token (parser
)->type
7824 &expr
.original_type
);
7825 set_c_expr_source_range (&expr
, tok_range
);
7828 case C_ID_CLASSNAME
:
7830 /* Here we parse the Objective-C 2.0 Class.name dot
7832 tree class_name
= c_parser_peek_token (parser
)->value
;
7834 c_parser_consume_token (parser
);
7835 gcc_assert (c_dialect_objc ());
7836 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7841 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7843 c_parser_error (parser
, "expected identifier");
7847 c_token
*component_tok
= c_parser_peek_token (parser
);
7848 component
= component_tok
->value
;
7849 location_t end_loc
= component_tok
->get_finish ();
7850 c_parser_consume_token (parser
);
7851 expr
.value
= objc_build_class_component_ref (class_name
,
7853 set_c_expr_source_range (&expr
, loc
, end_loc
);
7857 c_parser_error (parser
, "expected expression");
7862 case CPP_OPEN_PAREN
:
7863 /* A parenthesized expression, statement expression or compound
7865 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7867 /* A statement expression. */
7869 location_t brace_loc
;
7870 c_parser_consume_token (parser
);
7871 brace_loc
= c_parser_peek_token (parser
)->location
;
7872 c_parser_consume_token (parser
);
7873 if (!building_stmt_list_p ())
7875 error_at (loc
, "braced-group within expression allowed "
7876 "only inside a function");
7877 parser
->error
= true;
7878 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7879 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7883 stmt
= c_begin_stmt_expr ();
7884 c_parser_compound_statement_nostart (parser
);
7885 location_t close_loc
= c_parser_peek_token (parser
)->location
;
7886 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7888 pedwarn (loc
, OPT_Wpedantic
,
7889 "ISO C forbids braced-groups within expressions");
7890 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7891 set_c_expr_source_range (&expr
, loc
, close_loc
);
7892 mark_exp_read (expr
.value
);
7896 /* A parenthesized expression. */
7897 location_t loc_open_paren
= c_parser_peek_token (parser
)->location
;
7898 c_parser_consume_token (parser
);
7899 expr
= c_parser_expression (parser
);
7900 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7901 TREE_NO_WARNING (expr
.value
) = 1;
7902 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
7903 && expr
.original_code
!= SIZEOF_EXPR
)
7904 expr
.original_code
= ERROR_MARK
;
7905 /* Don't change EXPR.ORIGINAL_TYPE. */
7906 location_t loc_close_paren
= c_parser_peek_token (parser
)->location
;
7907 set_c_expr_source_range (&expr
, loc_open_paren
, loc_close_paren
);
7908 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7909 "expected %<)%>", loc_open_paren
);
7913 switch (c_parser_peek_token (parser
)->keyword
)
7915 case RID_FUNCTION_NAME
:
7916 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7917 "%<__FUNCTION__%> predefined identifier");
7918 expr
.value
= fname_decl (loc
,
7919 c_parser_peek_token (parser
)->keyword
,
7920 c_parser_peek_token (parser
)->value
);
7921 set_c_expr_source_range (&expr
, loc
, loc
);
7922 c_parser_consume_token (parser
);
7924 case RID_PRETTY_FUNCTION_NAME
:
7925 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7926 "%<__PRETTY_FUNCTION__%> predefined identifier");
7927 expr
.value
= fname_decl (loc
,
7928 c_parser_peek_token (parser
)->keyword
,
7929 c_parser_peek_token (parser
)->value
);
7930 set_c_expr_source_range (&expr
, loc
, loc
);
7931 c_parser_consume_token (parser
);
7933 case RID_C99_FUNCTION_NAME
:
7934 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7935 "%<__func__%> predefined identifier");
7936 expr
.value
= fname_decl (loc
,
7937 c_parser_peek_token (parser
)->keyword
,
7938 c_parser_peek_token (parser
)->value
);
7939 set_c_expr_source_range (&expr
, loc
, loc
);
7940 c_parser_consume_token (parser
);
7944 location_t start_loc
= loc
;
7945 c_parser_consume_token (parser
);
7946 matching_parens parens
;
7947 if (!parens
.require_open (parser
))
7952 e1
= c_parser_expr_no_commas (parser
, NULL
);
7953 mark_exp_read (e1
.value
);
7954 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7955 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7957 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7961 loc
= c_parser_peek_token (parser
)->location
;
7962 t1
= c_parser_type_name (parser
);
7963 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
7964 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7972 tree type_expr
= NULL_TREE
;
7973 expr
.value
= c_build_va_arg (start_loc
, e1
.value
, loc
,
7974 groktypename (t1
, &type_expr
, NULL
));
7977 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7978 TREE_TYPE (expr
.value
), type_expr
,
7980 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7982 set_c_expr_source_range (&expr
, start_loc
, end_loc
);
7988 c_parser_consume_token (parser
);
7989 matching_parens parens
;
7990 if (!parens
.require_open (parser
))
7995 t1
= c_parser_type_name (parser
);
7997 parser
->error
= true;
7998 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7999 gcc_assert (parser
->error
);
8002 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8006 tree type
= groktypename (t1
, NULL
, NULL
);
8008 if (type
== error_mark_node
)
8009 offsetof_ref
= error_mark_node
;
8012 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
8013 SET_EXPR_LOCATION (offsetof_ref
, loc
);
8015 /* Parse the second argument to __builtin_offsetof. We
8016 must have one identifier, and beyond that we want to
8017 accept sub structure and sub array references. */
8018 if (c_parser_next_token_is (parser
, CPP_NAME
))
8020 c_token
*comp_tok
= c_parser_peek_token (parser
);
8021 offsetof_ref
= build_component_ref
8022 (loc
, offsetof_ref
, comp_tok
->value
, comp_tok
->location
);
8023 c_parser_consume_token (parser
);
8024 while (c_parser_next_token_is (parser
, CPP_DOT
)
8025 || c_parser_next_token_is (parser
,
8027 || c_parser_next_token_is (parser
,
8030 if (c_parser_next_token_is (parser
, CPP_DEREF
))
8032 loc
= c_parser_peek_token (parser
)->location
;
8033 offsetof_ref
= build_array_ref (loc
,
8038 else if (c_parser_next_token_is (parser
, CPP_DOT
))
8041 c_parser_consume_token (parser
);
8042 if (c_parser_next_token_is_not (parser
,
8045 c_parser_error (parser
, "expected identifier");
8048 c_token
*comp_tok
= c_parser_peek_token (parser
);
8049 offsetof_ref
= build_component_ref
8050 (loc
, offsetof_ref
, comp_tok
->value
,
8051 comp_tok
->location
);
8052 c_parser_consume_token (parser
);
8058 loc
= c_parser_peek_token (parser
)->location
;
8059 c_parser_consume_token (parser
);
8060 ce
= c_parser_expression (parser
);
8061 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
8063 idx
= c_fully_fold (idx
, false, NULL
);
8064 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8066 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
8071 c_parser_error (parser
, "expected identifier");
8072 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
8073 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8075 expr
.value
= fold_offsetof (offsetof_ref
);
8076 set_c_expr_source_range (&expr
, loc
, end_loc
);
8079 case RID_CHOOSE_EXPR
:
8081 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8082 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
8084 location_t close_paren_loc
;
8086 c_parser_consume_token (parser
);
8087 if (!c_parser_get_builtin_args (parser
,
8088 "__builtin_choose_expr",
8096 if (vec_safe_length (cexpr_list
) != 3)
8098 error_at (loc
, "wrong number of arguments to "
8099 "%<__builtin_choose_expr%>");
8104 e1_p
= &(*cexpr_list
)[0];
8105 e2_p
= &(*cexpr_list
)[1];
8106 e3_p
= &(*cexpr_list
)[2];
8109 mark_exp_read (e2_p
->value
);
8110 mark_exp_read (e3_p
->value
);
8111 if (TREE_CODE (c
) != INTEGER_CST
8112 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
8114 "first argument to %<__builtin_choose_expr%> not"
8116 constant_expression_warning (c
);
8117 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
8118 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8121 case RID_TYPES_COMPATIBLE_P
:
8123 c_parser_consume_token (parser
);
8124 matching_parens parens
;
8125 if (!parens
.require_open (parser
))
8130 t1
= c_parser_type_name (parser
);
8136 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
8138 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8142 t2
= c_parser_type_name (parser
);
8148 location_t close_paren_loc
= c_parser_peek_token (parser
)->location
;
8149 parens
.skip_until_found_close (parser
);
8151 e1
= groktypename (t1
, NULL
, NULL
);
8152 e2
= groktypename (t2
, NULL
, NULL
);
8153 if (e1
== error_mark_node
|| e2
== error_mark_node
)
8159 e1
= TYPE_MAIN_VARIANT (e1
);
8160 e2
= TYPE_MAIN_VARIANT (e2
);
8163 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
8164 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8167 case RID_BUILTIN_TGMATH
:
8169 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8170 location_t close_paren_loc
;
8172 c_parser_consume_token (parser
);
8173 if (!c_parser_get_builtin_args (parser
,
8182 if (vec_safe_length (cexpr_list
) < 3)
8184 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8191 FOR_EACH_VEC_ELT (*cexpr_list
, i
, p
)
8192 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8193 unsigned int nargs
= check_tgmath_function (&(*cexpr_list
)[0], 1);
8199 if (vec_safe_length (cexpr_list
) < nargs
)
8201 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8205 unsigned int num_functions
= vec_safe_length (cexpr_list
) - nargs
;
8206 if (num_functions
< 2)
8208 error_at (loc
, "too few arguments to %<__builtin_tgmath%>");
8213 /* The first NUM_FUNCTIONS expressions are the function
8214 pointers. The remaining NARGS expressions are the
8215 arguments that are to be passed to one of those
8216 functions, chosen following <tgmath.h> rules. */
8217 for (unsigned int j
= 1; j
< num_functions
; j
++)
8219 unsigned int this_nargs
8220 = check_tgmath_function (&(*cexpr_list
)[j
], j
+ 1);
8221 if (this_nargs
== 0)
8226 if (this_nargs
!= nargs
)
8228 error_at ((*cexpr_list
)[j
].get_location (),
8229 "argument %u of %<__builtin_tgmath%> has "
8230 "wrong number of arguments", j
+ 1);
8236 /* The functions all have the same number of arguments.
8237 Determine whether arguments and return types vary in
8238 ways permitted for <tgmath.h> functions. */
8239 /* The first entry in each of these vectors is for the
8240 return type, subsequent entries for parameter
8242 auto_vec
<enum tgmath_parm_kind
> parm_kind (nargs
+ 1);
8243 auto_vec
<tree
> parm_first (nargs
+ 1);
8244 auto_vec
<bool> parm_complex (nargs
+ 1);
8245 auto_vec
<bool> parm_varies (nargs
+ 1);
8246 tree first_type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[0].value
));
8247 tree first_ret
= TYPE_MAIN_VARIANT (TREE_TYPE (first_type
));
8248 parm_first
.quick_push (first_ret
);
8249 parm_complex
.quick_push (TREE_CODE (first_ret
) == COMPLEX_TYPE
);
8250 parm_varies
.quick_push (false);
8251 function_args_iterator iter
;
8253 unsigned int argpos
;
8254 FOREACH_FUNCTION_ARGS (first_type
, t
, iter
)
8256 if (t
== void_type_node
)
8258 parm_first
.quick_push (TYPE_MAIN_VARIANT (t
));
8259 parm_complex
.quick_push (TREE_CODE (t
) == COMPLEX_TYPE
);
8260 parm_varies
.quick_push (false);
8262 for (unsigned int j
= 1; j
< num_functions
; j
++)
8264 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8265 tree ret
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
8266 if (ret
!= parm_first
[0])
8268 parm_varies
[0] = true;
8269 if (!SCALAR_FLOAT_TYPE_P (parm_first
[0])
8270 && !COMPLEX_FLOAT_TYPE_P (parm_first
[0]))
8272 error_at ((*cexpr_list
)[0].get_location (),
8273 "invalid type-generic return type for "
8274 "argument %u of %<__builtin_tgmath%>",
8279 if (!SCALAR_FLOAT_TYPE_P (ret
)
8280 && !COMPLEX_FLOAT_TYPE_P (ret
))
8282 error_at ((*cexpr_list
)[j
].get_location (),
8283 "invalid type-generic return type for "
8284 "argument %u of %<__builtin_tgmath%>",
8290 if (TREE_CODE (ret
) == COMPLEX_TYPE
)
8291 parm_complex
[0] = true;
8293 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8295 if (t
== void_type_node
)
8297 t
= TYPE_MAIN_VARIANT (t
);
8298 if (t
!= parm_first
[argpos
])
8300 parm_varies
[argpos
] = true;
8301 if (!SCALAR_FLOAT_TYPE_P (parm_first
[argpos
])
8302 && !COMPLEX_FLOAT_TYPE_P (parm_first
[argpos
]))
8304 error_at ((*cexpr_list
)[0].get_location (),
8305 "invalid type-generic type for "
8306 "argument %u of argument %u of "
8307 "%<__builtin_tgmath%>", argpos
, 1);
8311 if (!SCALAR_FLOAT_TYPE_P (t
)
8312 && !COMPLEX_FLOAT_TYPE_P (t
))
8314 error_at ((*cexpr_list
)[j
].get_location (),
8315 "invalid type-generic type for "
8316 "argument %u of argument %u of "
8317 "%<__builtin_tgmath%>", argpos
, j
+ 1);
8322 if (TREE_CODE (t
) == COMPLEX_TYPE
)
8323 parm_complex
[argpos
] = true;
8327 enum tgmath_parm_kind max_variation
= tgmath_fixed
;
8328 for (unsigned int j
= 0; j
<= nargs
; j
++)
8330 enum tgmath_parm_kind this_kind
;
8333 if (parm_complex
[j
])
8334 max_variation
= this_kind
= tgmath_complex
;
8337 this_kind
= tgmath_real
;
8338 if (max_variation
!= tgmath_complex
)
8339 max_variation
= tgmath_real
;
8343 this_kind
= tgmath_fixed
;
8344 parm_kind
.quick_push (this_kind
);
8346 if (max_variation
== tgmath_fixed
)
8348 error_at (loc
, "function arguments of %<__builtin_tgmath%> "
8349 "all have the same type");
8354 /* Identify a parameter (not the return type) that varies,
8355 including with complex types if any variation includes
8356 complex types; there must be at least one such
8358 unsigned int tgarg
= 0;
8359 for (unsigned int j
= 1; j
<= nargs
; j
++)
8360 if (parm_kind
[j
] == max_variation
)
8367 error_at (loc
, "function arguments of %<__builtin_tgmath%> "
8368 "lack type-generic parameter");
8373 /* Determine the type of the relevant parameter for each
8375 auto_vec
<tree
> tg_type (num_functions
);
8376 for (unsigned int j
= 0; j
< num_functions
; j
++)
8378 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8380 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8382 if (argpos
== tgarg
)
8384 tg_type
.quick_push (TYPE_MAIN_VARIANT (t
));
8391 /* Verify that the corresponding types are different for
8392 all the listed functions. Also determine whether all
8393 the types are complex, whether all the types are
8394 standard or binary, and whether all the types are
8396 bool all_complex
= true;
8397 bool all_binary
= true;
8398 bool all_decimal
= true;
8399 hash_set
<tree
> tg_types
;
8400 FOR_EACH_VEC_ELT (tg_type
, i
, t
)
8402 if (TREE_CODE (t
) == COMPLEX_TYPE
)
8403 all_decimal
= false;
8406 all_complex
= false;
8407 if (DECIMAL_FLOAT_TYPE_P (t
))
8410 all_decimal
= false;
8412 if (tg_types
.add (t
))
8414 error_at ((*cexpr_list
)[i
].get_location (),
8415 "duplicate type-generic parameter type for "
8416 "function argument %u of %<__builtin_tgmath%>",
8423 /* Verify that other parameters and the return type whose
8424 types vary have their types varying in the correct
8426 for (unsigned int j
= 0; j
< num_functions
; j
++)
8428 tree exp_type
= tg_type
[j
];
8429 tree exp_real_type
= exp_type
;
8430 if (TREE_CODE (exp_type
) == COMPLEX_TYPE
)
8431 exp_real_type
= TREE_TYPE (exp_type
);
8432 tree type
= TREE_TYPE (TREE_TYPE ((*cexpr_list
)[j
].value
));
8433 tree ret
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
8434 if ((parm_kind
[0] == tgmath_complex
&& ret
!= exp_type
)
8435 || (parm_kind
[0] == tgmath_real
&& ret
!= exp_real_type
))
8437 error_at ((*cexpr_list
)[j
].get_location (),
8438 "bad return type for function argument %u "
8439 "of %<__builtin_tgmath%>", j
+ 1);
8444 FOREACH_FUNCTION_ARGS (type
, t
, iter
)
8446 if (t
== void_type_node
)
8448 t
= TYPE_MAIN_VARIANT (t
);
8449 if ((parm_kind
[argpos
] == tgmath_complex
8451 || (parm_kind
[argpos
] == tgmath_real
8452 && t
!= exp_real_type
))
8454 error_at ((*cexpr_list
)[j
].get_location (),
8455 "bad type for argument %u of "
8456 "function argument %u of "
8457 "%<__builtin_tgmath%>", argpos
, j
+ 1);
8465 /* The functions listed are a valid set of functions for a
8466 <tgmath.h> macro to select between. Identify the
8467 matching function, if any. First, the argument types
8468 must be combined following <tgmath.h> rules. Integer
8469 types are treated as _Decimal64 if any type-generic
8470 argument is decimal, or if the only alternatives for
8471 type-generic arguments are of decimal types, and are
8472 otherwise treated as double (or _Complex double for
8473 complex integer types). After that adjustment, types
8474 are combined following the usual arithmetic
8475 conversions. If the function only accepts complex
8476 arguments, a complex type is produced. */
8477 bool arg_complex
= all_complex
;
8478 bool arg_binary
= all_binary
;
8479 bool arg_int_decimal
= all_decimal
;
8480 for (unsigned int j
= 1; j
<= nargs
; j
++)
8482 if (parm_kind
[j
] == tgmath_fixed
)
8484 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
- 1];
8485 tree type
= TREE_TYPE (ce
->value
);
8486 if (!INTEGRAL_TYPE_P (type
)
8487 && !SCALAR_FLOAT_TYPE_P (type
)
8488 && TREE_CODE (type
) != COMPLEX_TYPE
)
8490 error_at (ce
->get_location (),
8491 "invalid type of argument %u of type-generic "
8496 if (DECIMAL_FLOAT_TYPE_P (type
))
8498 arg_int_decimal
= true;
8501 error_at (ce
->get_location (),
8502 "decimal floating-point argument %u to "
8503 "complex-only type-generic function", j
);
8507 else if (all_binary
)
8509 error_at (ce
->get_location (),
8510 "decimal floating-point argument %u to "
8511 "binary-only type-generic function", j
);
8515 else if (arg_complex
)
8517 error_at (ce
->get_location (),
8518 "both complex and decimal floating-point "
8519 "arguments to type-generic function");
8523 else if (arg_binary
)
8525 error_at (ce
->get_location (),
8526 "both binary and decimal floating-point "
8527 "arguments to type-generic function");
8532 else if (TREE_CODE (type
) == COMPLEX_TYPE
)
8535 if (COMPLEX_FLOAT_TYPE_P (type
))
8539 error_at (ce
->get_location (),
8540 "complex argument %u to "
8541 "decimal-only type-generic function", j
);
8545 else if (arg_int_decimal
)
8547 error_at (ce
->get_location (),
8548 "both complex and decimal floating-point "
8549 "arguments to type-generic function");
8554 else if (SCALAR_FLOAT_TYPE_P (type
))
8559 error_at (ce
->get_location (),
8560 "binary argument %u to "
8561 "decimal-only type-generic function", j
);
8565 else if (arg_int_decimal
)
8567 error_at (ce
->get_location (),
8568 "both binary and decimal floating-point "
8569 "arguments to type-generic function");
8575 tree arg_real
= NULL_TREE
;
8576 for (unsigned int j
= 1; j
<= nargs
; j
++)
8578 if (parm_kind
[j
] == tgmath_fixed
)
8580 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
- 1];
8581 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (ce
->value
));
8582 if (TREE_CODE (type
) == COMPLEX_TYPE
)
8583 type
= TREE_TYPE (type
);
8584 if (INTEGRAL_TYPE_P (type
))
8585 type
= (arg_int_decimal
8586 ? dfloat64_type_node
8587 : double_type_node
);
8588 if (arg_real
== NULL_TREE
)
8591 arg_real
= common_type (arg_real
, type
);
8592 if (arg_real
== error_mark_node
)
8598 tree arg_type
= (arg_complex
8599 ? build_complex_type (arg_real
)
8602 /* Look for a function to call with type-generic parameter
8604 c_expr_t
*fn
= NULL
;
8605 for (unsigned int j
= 0; j
< num_functions
; j
++)
8607 if (tg_type
[j
] == arg_type
)
8609 fn
= &(*cexpr_list
)[j
];
8614 && parm_kind
[0] == tgmath_fixed
8615 && SCALAR_FLOAT_TYPE_P (parm_first
[0]))
8617 /* Presume this is a macro that rounds its result to a
8618 narrower type, and look for the first function with
8619 at least the range and precision of the argument
8621 for (unsigned int j
= 0; j
< num_functions
; j
++)
8624 != (TREE_CODE (tg_type
[j
]) == COMPLEX_TYPE
))
8626 tree real_tg_type
= (arg_complex
8627 ? TREE_TYPE (tg_type
[j
])
8629 if (DECIMAL_FLOAT_TYPE_P (arg_real
)
8630 != DECIMAL_FLOAT_TYPE_P (real_tg_type
))
8632 scalar_float_mode arg_mode
8633 = SCALAR_FLOAT_TYPE_MODE (arg_real
);
8634 scalar_float_mode tg_mode
8635 = SCALAR_FLOAT_TYPE_MODE (real_tg_type
);
8636 const real_format
*arg_fmt
= REAL_MODE_FORMAT (arg_mode
);
8637 const real_format
*tg_fmt
= REAL_MODE_FORMAT (tg_mode
);
8638 if (arg_fmt
->b
== tg_fmt
->b
8639 && arg_fmt
->p
<= tg_fmt
->p
8640 && arg_fmt
->emax
<= tg_fmt
->emax
8641 && (arg_fmt
->emin
- arg_fmt
->p
8642 >= tg_fmt
->emin
- tg_fmt
->p
))
8644 fn
= &(*cexpr_list
)[j
];
8651 error_at (loc
, "no matching function for type-generic call");
8656 /* Construct a call to FN. */
8657 vec
<tree
, va_gc
> *args
;
8658 vec_alloc (args
, nargs
);
8659 vec
<tree
, va_gc
> *origtypes
;
8660 vec_alloc (origtypes
, nargs
);
8661 auto_vec
<location_t
> arg_loc (nargs
);
8662 for (unsigned int j
= 0; j
< nargs
; j
++)
8664 c_expr_t
*ce
= &(*cexpr_list
)[num_functions
+ j
];
8665 args
->quick_push (ce
->value
);
8666 arg_loc
.quick_push (ce
->get_location ());
8667 origtypes
->quick_push (ce
->original_type
);
8669 expr
.value
= c_build_function_call_vec (loc
, arg_loc
, fn
->value
,
8671 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8674 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
8676 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8679 location_t close_paren_loc
;
8681 c_parser_consume_token (parser
);
8682 if (!c_parser_get_builtin_args (parser
,
8683 "__builtin_call_with_static_chain",
8690 if (vec_safe_length (cexpr_list
) != 2)
8692 error_at (loc
, "wrong number of arguments to "
8693 "%<__builtin_call_with_static_chain%>");
8698 expr
= (*cexpr_list
)[0];
8699 e2_p
= &(*cexpr_list
)[1];
8700 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
8701 chain_value
= e2_p
->value
;
8702 mark_exp_read (chain_value
);
8704 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
8705 error_at (loc
, "first argument to "
8706 "%<__builtin_call_with_static_chain%> "
8707 "must be a call expression");
8708 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
8709 error_at (loc
, "second argument to "
8710 "%<__builtin_call_with_static_chain%> "
8711 "must be a pointer type");
8713 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
8714 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8717 case RID_BUILTIN_COMPLEX
:
8719 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8720 c_expr_t
*e1_p
, *e2_p
;
8721 location_t close_paren_loc
;
8723 c_parser_consume_token (parser
);
8724 if (!c_parser_get_builtin_args (parser
,
8725 "__builtin_complex",
8733 if (vec_safe_length (cexpr_list
) != 2)
8735 error_at (loc
, "wrong number of arguments to "
8736 "%<__builtin_complex%>");
8741 e1_p
= &(*cexpr_list
)[0];
8742 e2_p
= &(*cexpr_list
)[1];
8744 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
8745 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
8746 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
8747 TREE_OPERAND (e1_p
->value
, 0));
8748 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
8749 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
8750 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
8751 TREE_OPERAND (e2_p
->value
, 0));
8752 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8753 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8754 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
8755 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
8757 error_at (loc
, "%<__builtin_complex%> operand "
8758 "not of real binary floating-point type");
8762 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
8763 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
8766 "%<__builtin_complex%> operands of different types");
8770 pedwarn_c90 (loc
, OPT_Wpedantic
,
8771 "ISO C90 does not support complex types");
8772 expr
.value
= build2_loc (loc
, COMPLEX_EXPR
,
8775 (TREE_TYPE (e1_p
->value
))),
8776 e1_p
->value
, e2_p
->value
);
8777 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8780 case RID_BUILTIN_SHUFFLE
:
8782 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8785 location_t close_paren_loc
;
8787 c_parser_consume_token (parser
);
8788 if (!c_parser_get_builtin_args (parser
,
8789 "__builtin_shuffle",
8797 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
8798 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8800 if (vec_safe_length (cexpr_list
) == 2)
8802 c_build_vec_perm_expr
8803 (loc
, (*cexpr_list
)[0].value
,
8804 NULL_TREE
, (*cexpr_list
)[1].value
);
8806 else if (vec_safe_length (cexpr_list
) == 3)
8808 c_build_vec_perm_expr
8809 (loc
, (*cexpr_list
)[0].value
,
8810 (*cexpr_list
)[1].value
,
8811 (*cexpr_list
)[2].value
);
8814 error_at (loc
, "wrong number of arguments to "
8815 "%<__builtin_shuffle%>");
8818 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8821 case RID_AT_SELECTOR
:
8823 gcc_assert (c_dialect_objc ());
8824 c_parser_consume_token (parser
);
8825 matching_parens parens
;
8826 if (!parens
.require_open (parser
))
8831 tree sel
= c_parser_objc_selector_arg (parser
);
8832 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8833 parens
.skip_until_found_close (parser
);
8834 expr
.value
= objc_build_selector_expr (loc
, sel
);
8835 set_c_expr_source_range (&expr
, loc
, close_loc
);
8838 case RID_AT_PROTOCOL
:
8840 gcc_assert (c_dialect_objc ());
8841 c_parser_consume_token (parser
);
8842 matching_parens parens
;
8843 if (!parens
.require_open (parser
))
8848 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8850 c_parser_error (parser
, "expected identifier");
8851 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8855 tree id
= c_parser_peek_token (parser
)->value
;
8856 c_parser_consume_token (parser
);
8857 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8858 parens
.skip_until_found_close (parser
);
8859 expr
.value
= objc_build_protocol_expr (id
);
8860 set_c_expr_source_range (&expr
, loc
, close_loc
);
8865 /* Extension to support C-structures in the archiver. */
8866 gcc_assert (c_dialect_objc ());
8867 c_parser_consume_token (parser
);
8868 matching_parens parens
;
8869 if (!parens
.require_open (parser
))
8874 t1
= c_parser_type_name (parser
);
8878 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8881 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8882 parens
.skip_until_found_close (parser
);
8883 tree type
= groktypename (t1
, NULL
, NULL
);
8884 expr
.value
= objc_build_encode_expr (type
);
8885 set_c_expr_source_range (&expr
, loc
, close_loc
);
8889 expr
= c_parser_generic_selection (parser
);
8892 c_parser_error (parser
, "expected expression");
8897 case CPP_OPEN_SQUARE
:
8898 if (c_dialect_objc ())
8900 tree receiver
, args
;
8901 c_parser_consume_token (parser
);
8902 receiver
= c_parser_objc_receiver (parser
);
8903 args
= c_parser_objc_message_args (parser
);
8904 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8905 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8907 expr
.value
= objc_build_message_expr (receiver
, args
);
8908 set_c_expr_source_range (&expr
, loc
, close_loc
);
8911 /* Else fall through to report error. */
8914 c_parser_error (parser
, "expected expression");
8919 return c_parser_postfix_expression_after_primary
8920 (parser
, EXPR_LOC_OR_LOC (expr
.value
, loc
), expr
);
8923 /* Parse a postfix expression after a parenthesized type name: the
8924 brace-enclosed initializer of a compound literal, possibly followed
8925 by some postfix operators. This is separate because it is not
8926 possible to tell until after the type name whether a cast
8927 expression has a cast or a compound literal, or whether the operand
8928 of sizeof is a parenthesized type name or starts with a compound
8929 literal. TYPE_LOC is the location where TYPE_NAME starts--the
8930 location of the first token after the parentheses around the type
8933 static struct c_expr
8934 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
8935 struct c_type_name
*type_name
,
8936 location_t type_loc
)
8942 location_t start_loc
;
8943 tree type_expr
= NULL_TREE
;
8944 bool type_expr_const
= true;
8945 check_compound_literal_type (type_loc
, type_name
);
8946 rich_location
richloc (line_table
, type_loc
);
8947 start_init (NULL_TREE
, NULL
, 0, &richloc
);
8948 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
8949 start_loc
= c_parser_peek_token (parser
)->location
;
8950 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
8952 error_at (type_loc
, "compound literal has variable size");
8953 type
= error_mark_node
;
8955 init
= c_parser_braced_init (parser
, type
, false, NULL
);
8957 maybe_warn_string_init (type_loc
, type
, init
);
8959 if (type
!= error_mark_node
8960 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
8961 && current_function_decl
)
8963 error ("compound literal qualified by address-space qualifier");
8964 type
= error_mark_node
;
8967 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
8968 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
8969 ? CONSTRUCTOR_NON_CONST (init
.value
)
8970 : init
.original_code
== C_MAYBE_CONST_EXPR
);
8971 non_const
|= !type_expr_const
;
8972 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
8973 set_c_expr_source_range (&expr
, init
.src_range
);
8974 expr
.original_code
= ERROR_MARK
;
8975 expr
.original_type
= NULL
;
8976 if (type
!= error_mark_node
8977 && expr
.value
!= error_mark_node
8980 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
8982 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
8983 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
8987 gcc_assert (!non_const
);
8988 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
8989 type_expr
, expr
.value
);
8992 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
8995 /* Callback function for sizeof_pointer_memaccess_warning to compare
8999 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
9001 return comptypes (type1
, type2
) == 1;
9004 /* Parse a postfix expression after the initial primary or compound
9005 literal; that is, parse a series of postfix operators.
9007 EXPR_LOC is the location of the primary expression. */
9009 static struct c_expr
9010 c_parser_postfix_expression_after_primary (c_parser
*parser
,
9011 location_t expr_loc
,
9014 struct c_expr orig_expr
;
9016 location_t sizeof_arg_loc
[3], comp_loc
;
9018 unsigned int literal_zero_mask
;
9020 vec
<tree
, va_gc
> *exprlist
;
9021 vec
<tree
, va_gc
> *origtypes
= NULL
;
9022 vec
<location_t
> arg_loc
= vNULL
;
9028 location_t op_loc
= c_parser_peek_token (parser
)->location
;
9029 switch (c_parser_peek_token (parser
)->type
)
9031 case CPP_OPEN_SQUARE
:
9032 /* Array reference. */
9033 c_parser_consume_token (parser
);
9034 idx
= c_parser_expression (parser
).value
;
9035 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
9037 start
= expr
.get_start ();
9038 finish
= parser
->tokens_buf
[0].location
;
9039 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
9040 set_c_expr_source_range (&expr
, start
, finish
);
9041 expr
.original_code
= ERROR_MARK
;
9042 expr
.original_type
= NULL
;
9044 case CPP_OPEN_PAREN
:
9045 /* Function call. */
9046 c_parser_consume_token (parser
);
9047 for (i
= 0; i
< 3; i
++)
9049 sizeof_arg
[i
] = NULL_TREE
;
9050 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
9052 literal_zero_mask
= 0;
9053 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9056 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
9057 sizeof_arg_loc
, sizeof_arg
,
9058 &arg_loc
, &literal_zero_mask
);
9059 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9062 mark_exp_read (expr
.value
);
9063 if (warn_sizeof_pointer_memaccess
)
9064 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
9065 expr
.value
, exprlist
,
9067 sizeof_ptr_memacc_comptypes
);
9068 if (TREE_CODE (expr
.value
) == FUNCTION_DECL
9069 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
9070 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
9071 && vec_safe_length (exprlist
) == 3)
9073 tree arg0
= (*exprlist
)[0];
9074 tree arg2
= (*exprlist
)[2];
9075 warn_for_memset (expr_loc
, arg0
, arg2
, literal_zero_mask
);
9078 start
= expr
.get_start ();
9079 finish
= parser
->tokens_buf
[0].get_finish ();
9081 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
9082 exprlist
, origtypes
);
9083 set_c_expr_source_range (&expr
, start
, finish
);
9085 expr
.original_code
= ERROR_MARK
;
9086 if (TREE_CODE (expr
.value
) == INTEGER_CST
9087 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
9088 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
9089 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
9090 expr
.original_code
= C_MAYBE_CONST_EXPR
;
9091 expr
.original_type
= NULL
;
9094 release_tree_vector (exprlist
);
9095 release_tree_vector (origtypes
);
9100 /* Structure element reference. */
9101 c_parser_consume_token (parser
);
9102 expr
= default_function_array_conversion (expr_loc
, expr
);
9103 if (c_parser_next_token_is (parser
, CPP_NAME
))
9105 c_token
*comp_tok
= c_parser_peek_token (parser
);
9106 ident
= comp_tok
->value
;
9107 comp_loc
= comp_tok
->location
;
9111 c_parser_error (parser
, "expected identifier");
9113 expr
.original_code
= ERROR_MARK
;
9114 expr
.original_type
= NULL
;
9117 start
= expr
.get_start ();
9118 finish
= c_parser_peek_token (parser
)->get_finish ();
9119 c_parser_consume_token (parser
);
9120 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
,
9122 set_c_expr_source_range (&expr
, start
, finish
);
9123 expr
.original_code
= ERROR_MARK
;
9124 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
9125 expr
.original_type
= NULL
;
9128 /* Remember the original type of a bitfield. */
9129 tree field
= TREE_OPERAND (expr
.value
, 1);
9130 if (TREE_CODE (field
) != FIELD_DECL
)
9131 expr
.original_type
= NULL
;
9133 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
9137 /* Structure element reference. */
9138 c_parser_consume_token (parser
);
9139 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
9140 if (c_parser_next_token_is (parser
, CPP_NAME
))
9142 c_token
*comp_tok
= c_parser_peek_token (parser
);
9143 ident
= comp_tok
->value
;
9144 comp_loc
= comp_tok
->location
;
9148 c_parser_error (parser
, "expected identifier");
9150 expr
.original_code
= ERROR_MARK
;
9151 expr
.original_type
= NULL
;
9154 start
= expr
.get_start ();
9155 finish
= c_parser_peek_token (parser
)->get_finish ();
9156 c_parser_consume_token (parser
);
9157 expr
.value
= build_component_ref (op_loc
,
9158 build_indirect_ref (op_loc
,
9162 set_c_expr_source_range (&expr
, start
, finish
);
9163 expr
.original_code
= ERROR_MARK
;
9164 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
9165 expr
.original_type
= NULL
;
9168 /* Remember the original type of a bitfield. */
9169 tree field
= TREE_OPERAND (expr
.value
, 1);
9170 if (TREE_CODE (field
) != FIELD_DECL
)
9171 expr
.original_type
= NULL
;
9173 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
9177 /* Postincrement. */
9178 start
= expr
.get_start ();
9179 finish
= c_parser_peek_token (parser
)->get_finish ();
9180 c_parser_consume_token (parser
);
9181 expr
= default_function_array_read_conversion (expr_loc
, expr
);
9182 expr
.value
= build_unary_op (op_loc
, POSTINCREMENT_EXPR
,
9184 set_c_expr_source_range (&expr
, start
, finish
);
9185 expr
.original_code
= ERROR_MARK
;
9186 expr
.original_type
= NULL
;
9188 case CPP_MINUS_MINUS
:
9189 /* Postdecrement. */
9190 start
= expr
.get_start ();
9191 finish
= c_parser_peek_token (parser
)->get_finish ();
9192 c_parser_consume_token (parser
);
9193 expr
= default_function_array_read_conversion (expr_loc
, expr
);
9194 expr
.value
= build_unary_op (op_loc
, POSTDECREMENT_EXPR
,
9196 set_c_expr_source_range (&expr
, start
, finish
);
9197 expr
.original_code
= ERROR_MARK
;
9198 expr
.original_type
= NULL
;
9206 /* Parse an expression (C90 6.3.17, C99 6.5.17, C11 6.5.17).
9209 assignment-expression
9210 expression , assignment-expression
9213 static struct c_expr
9214 c_parser_expression (c_parser
*parser
)
9216 location_t tloc
= c_parser_peek_token (parser
)->location
;
9218 expr
= c_parser_expr_no_commas (parser
, NULL
);
9219 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9220 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
9221 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9225 location_t loc
= c_parser_peek_token (parser
)->location
;
9226 location_t expr_loc
;
9227 c_parser_consume_token (parser
);
9228 expr_loc
= c_parser_peek_token (parser
)->location
;
9229 lhsval
= expr
.value
;
9230 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
9231 lhsval
= TREE_OPERAND (lhsval
, 1);
9232 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
9233 mark_exp_read (lhsval
);
9234 next
= c_parser_expr_no_commas (parser
, NULL
);
9235 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
9236 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
9237 expr
.original_code
= COMPOUND_EXPR
;
9238 expr
.original_type
= next
.original_type
;
9243 /* Parse an expression and convert functions or arrays to pointers and
9244 lvalues to rvalues. */
9246 static struct c_expr
9247 c_parser_expression_conv (c_parser
*parser
)
9250 location_t loc
= c_parser_peek_token (parser
)->location
;
9251 expr
= c_parser_expression (parser
);
9252 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
9256 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
9257 argument is a literal zero alone and if so, set it in literal_zero_mask. */
9260 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
9263 if (idx
>= HOST_BITS_PER_INT
)
9266 c_token
*tok
= c_parser_peek_token (parser
);
9274 /* If a parameter is literal zero alone, remember it
9275 for -Wmemset-transposed-args warning. */
9276 if (integer_zerop (tok
->value
)
9277 && !TREE_OVERFLOW (tok
->value
)
9278 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9279 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
9280 *literal_zero_mask
|= 1U << idx
;
9286 /* Parse a non-empty list of expressions. If CONVERT_P, convert
9287 functions and arrays to pointers and lvalues to rvalues. If
9288 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
9289 locations of function arguments into this vector.
9292 assignment-expression
9293 nonempty-expr-list , assignment-expression
9296 static vec
<tree
, va_gc
> *
9297 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
9298 vec
<tree
, va_gc
> **p_orig_types
,
9299 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
9300 vec
<location_t
> *locations
,
9301 unsigned int *literal_zero_mask
)
9303 vec
<tree
, va_gc
> *ret
;
9304 vec
<tree
, va_gc
> *orig_types
;
9306 unsigned int idx
= 0;
9308 ret
= make_tree_vector ();
9309 if (p_orig_types
== NULL
)
9312 orig_types
= make_tree_vector ();
9314 if (literal_zero_mask
)
9315 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
9316 expr
= c_parser_expr_no_commas (parser
, NULL
);
9318 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true, true);
9320 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
9321 ret
->quick_push (expr
.value
);
9323 orig_types
->quick_push (expr
.original_type
);
9325 locations
->safe_push (expr
.get_location ());
9326 if (sizeof_arg
!= NULL
9327 && expr
.original_code
== SIZEOF_EXPR
)
9329 sizeof_arg
[0] = c_last_sizeof_arg
;
9330 sizeof_arg_loc
[0] = c_last_sizeof_loc
;
9332 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9334 c_parser_consume_token (parser
);
9335 if (literal_zero_mask
)
9336 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
9337 expr
= c_parser_expr_no_commas (parser
, NULL
);
9339 expr
= convert_lvalue_to_rvalue (expr
.get_location (), expr
, true,
9342 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
9343 vec_safe_push (ret
, expr
.value
);
9345 vec_safe_push (orig_types
, expr
.original_type
);
9347 locations
->safe_push (expr
.get_location ());
9349 && sizeof_arg
!= NULL
9350 && expr
.original_code
== SIZEOF_EXPR
)
9352 sizeof_arg
[idx
] = c_last_sizeof_arg
;
9353 sizeof_arg_loc
[idx
] = c_last_sizeof_loc
;
9357 *p_orig_types
= orig_types
;
9361 /* Parse Objective-C-specific constructs. */
9363 /* Parse an objc-class-definition.
9365 objc-class-definition:
9366 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
9367 objc-class-instance-variables[opt] objc-methodprotolist @end
9368 @implementation identifier objc-superclass[opt]
9369 objc-class-instance-variables[opt]
9370 @interface identifier ( identifier ) objc-protocol-refs[opt]
9371 objc-methodprotolist @end
9372 @interface identifier ( ) objc-protocol-refs[opt]
9373 objc-methodprotolist @end
9374 @implementation identifier ( identifier )
9379 "@interface identifier (" must start "@interface identifier (
9380 identifier ) ...": objc-methodprotolist in the first production may
9381 not start with a parenthesized identifier as a declarator of a data
9382 definition with no declaration specifiers if the objc-superclass,
9383 objc-protocol-refs and objc-class-instance-variables are omitted. */
9386 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
9391 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
9393 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
9398 c_parser_consume_token (parser
);
9399 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9401 c_parser_error (parser
, "expected identifier");
9404 id1
= c_parser_peek_token (parser
)->value
;
9405 c_parser_consume_token (parser
);
9406 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9408 /* We have a category or class extension. */
9410 tree proto
= NULL_TREE
;
9411 matching_parens parens
;
9412 parens
.consume_open (parser
);
9413 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9415 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9417 /* We have a class extension. */
9422 c_parser_error (parser
, "expected identifier or %<)%>");
9423 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
9429 id2
= c_parser_peek_token (parser
)->value
;
9430 c_parser_consume_token (parser
);
9432 parens
.skip_until_found_close (parser
);
9435 objc_start_category_implementation (id1
, id2
);
9438 if (c_parser_next_token_is (parser
, CPP_LESS
))
9439 proto
= c_parser_objc_protocol_refs (parser
);
9440 objc_start_category_interface (id1
, id2
, proto
, attributes
);
9441 c_parser_objc_methodprotolist (parser
);
9442 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9443 objc_finish_interface ();
9446 if (c_parser_next_token_is (parser
, CPP_COLON
))
9448 c_parser_consume_token (parser
);
9449 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9451 c_parser_error (parser
, "expected identifier");
9454 superclass
= c_parser_peek_token (parser
)->value
;
9455 c_parser_consume_token (parser
);
9458 superclass
= NULL_TREE
;
9461 tree proto
= NULL_TREE
;
9462 if (c_parser_next_token_is (parser
, CPP_LESS
))
9463 proto
= c_parser_objc_protocol_refs (parser
);
9464 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
9467 objc_start_class_implementation (id1
, superclass
);
9468 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9469 c_parser_objc_class_instance_variables (parser
);
9472 objc_continue_interface ();
9473 c_parser_objc_methodprotolist (parser
);
9474 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9475 objc_finish_interface ();
9479 objc_continue_implementation ();
9484 /* Parse objc-class-instance-variables.
9486 objc-class-instance-variables:
9487 { objc-instance-variable-decl-list[opt] }
9489 objc-instance-variable-decl-list:
9490 objc-visibility-spec
9491 objc-instance-variable-decl ;
9493 objc-instance-variable-decl-list objc-visibility-spec
9494 objc-instance-variable-decl-list objc-instance-variable-decl ;
9495 objc-instance-variable-decl-list ;
9497 objc-visibility-spec:
9502 objc-instance-variable-decl:
9507 c_parser_objc_class_instance_variables (c_parser
*parser
)
9509 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
9510 c_parser_consume_token (parser
);
9511 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
9514 /* Parse any stray semicolon. */
9515 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9517 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9519 c_parser_consume_token (parser
);
9522 /* Stop if at the end of the instance variables. */
9523 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
9525 c_parser_consume_token (parser
);
9528 /* Parse any objc-visibility-spec. */
9529 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
9531 c_parser_consume_token (parser
);
9532 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
9535 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
9537 c_parser_consume_token (parser
);
9538 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
9541 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
9543 c_parser_consume_token (parser
);
9544 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
9547 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
9549 c_parser_consume_token (parser
);
9550 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
9553 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
9555 c_parser_pragma (parser
, pragma_external
, NULL
);
9559 /* Parse some comma-separated declarations. */
9560 decls
= c_parser_struct_declaration (parser
);
9563 /* There is a syntax error. We want to skip the offending
9564 tokens up to the next ';' (included) or '}'
9567 /* First, skip manually a ')' or ']'. This is because they
9568 reduce the nesting level, so c_parser_skip_until_found()
9569 wouldn't be able to skip past them. */
9570 c_token
*token
= c_parser_peek_token (parser
);
9571 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
9572 c_parser_consume_token (parser
);
9574 /* Then, do the standard skipping. */
9575 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9577 /* We hopefully recovered. Start normal parsing again. */
9578 parser
->error
= false;
9583 /* Comma-separated instance variables are chained together
9584 in reverse order; add them one by one. */
9585 tree ivar
= nreverse (decls
);
9586 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
9587 objc_add_instance_variable (copy_node (ivar
));
9589 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9593 /* Parse an objc-class-declaration.
9595 objc-class-declaration:
9596 @class identifier-list ;
9600 c_parser_objc_class_declaration (c_parser
*parser
)
9602 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
9603 c_parser_consume_token (parser
);
9604 /* Any identifiers, including those declared as type names, are OK
9609 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9611 c_parser_error (parser
, "expected identifier");
9612 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9613 parser
->error
= false;
9616 id
= c_parser_peek_token (parser
)->value
;
9617 objc_declare_class (id
);
9618 c_parser_consume_token (parser
);
9619 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9620 c_parser_consume_token (parser
);
9624 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9627 /* Parse an objc-alias-declaration.
9629 objc-alias-declaration:
9630 @compatibility_alias identifier identifier ;
9634 c_parser_objc_alias_declaration (c_parser
*parser
)
9637 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
9638 c_parser_consume_token (parser
);
9639 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9641 c_parser_error (parser
, "expected identifier");
9642 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9645 id1
= c_parser_peek_token (parser
)->value
;
9646 c_parser_consume_token (parser
);
9647 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9649 c_parser_error (parser
, "expected identifier");
9650 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9653 id2
= c_parser_peek_token (parser
)->value
;
9654 c_parser_consume_token (parser
);
9655 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9656 objc_declare_alias (id1
, id2
);
9659 /* Parse an objc-protocol-definition.
9661 objc-protocol-definition:
9662 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
9663 @protocol identifier-list ;
9665 "@protocol identifier ;" should be resolved as "@protocol
9666 identifier-list ;": objc-methodprotolist may not start with a
9667 semicolon in the first alternative if objc-protocol-refs are
9671 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
9673 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
9675 c_parser_consume_token (parser
);
9676 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9678 c_parser_error (parser
, "expected identifier");
9681 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9682 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
9684 /* Any identifiers, including those declared as type names, are
9689 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9691 c_parser_error (parser
, "expected identifier");
9694 id
= c_parser_peek_token (parser
)->value
;
9695 objc_declare_protocol (id
, attributes
);
9696 c_parser_consume_token (parser
);
9697 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9698 c_parser_consume_token (parser
);
9702 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9706 tree id
= c_parser_peek_token (parser
)->value
;
9707 tree proto
= NULL_TREE
;
9708 c_parser_consume_token (parser
);
9709 if (c_parser_next_token_is (parser
, CPP_LESS
))
9710 proto
= c_parser_objc_protocol_refs (parser
);
9711 parser
->objc_pq_context
= true;
9712 objc_start_protocol (id
, proto
, attributes
);
9713 c_parser_objc_methodprotolist (parser
);
9714 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9715 parser
->objc_pq_context
= false;
9716 objc_finish_interface ();
9720 /* Parse an objc-method-type.
9726 Return true if it is a class method (+) and false if it is
9727 an instance method (-).
9730 c_parser_objc_method_type (c_parser
*parser
)
9732 switch (c_parser_peek_token (parser
)->type
)
9735 c_parser_consume_token (parser
);
9738 c_parser_consume_token (parser
);
9745 /* Parse an objc-method-definition.
9747 objc-method-definition:
9748 objc-method-type objc-method-decl ;[opt] compound-statement
9752 c_parser_objc_method_definition (c_parser
*parser
)
9754 bool is_class_method
= c_parser_objc_method_type (parser
);
9755 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
9756 parser
->objc_pq_context
= true;
9757 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9759 if (decl
== error_mark_node
)
9760 return; /* Bail here. */
9762 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9764 c_parser_consume_token (parser
);
9765 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9766 "extra semicolon in method definition specified");
9769 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9771 c_parser_error (parser
, "expected %<{%>");
9775 parser
->objc_pq_context
= false;
9776 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
9778 add_stmt (c_parser_compound_statement (parser
));
9779 objc_finish_method_definition (current_function_decl
);
9783 /* This code is executed when we find a method definition
9784 outside of an @implementation context (or invalid for other
9785 reasons). Parse the method (to keep going) but do not emit
9788 c_parser_compound_statement (parser
);
9792 /* Parse an objc-methodprotolist.
9794 objc-methodprotolist:
9796 objc-methodprotolist objc-methodproto
9797 objc-methodprotolist declaration
9798 objc-methodprotolist ;
9802 The declaration is a data definition, which may be missing
9803 declaration specifiers under the same rules and diagnostics as
9804 other data definitions outside functions, and the stray semicolon
9805 is diagnosed the same way as a stray semicolon outside a
9809 c_parser_objc_methodprotolist (c_parser
*parser
)
9813 /* The list is terminated by @end. */
9814 switch (c_parser_peek_token (parser
)->type
)
9817 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9818 "ISO C does not allow extra %<;%> outside of a function");
9819 c_parser_consume_token (parser
);
9823 c_parser_objc_methodproto (parser
);
9826 c_parser_pragma (parser
, pragma_external
, NULL
);
9831 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
9833 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
9834 c_parser_objc_at_property_declaration (parser
);
9835 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
9837 objc_set_method_opt (true);
9838 c_parser_consume_token (parser
);
9840 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
9842 objc_set_method_opt (false);
9843 c_parser_consume_token (parser
);
9846 c_parser_declaration_or_fndef (parser
, false, false, true,
9847 false, true, NULL
, vNULL
);
9853 /* Parse an objc-methodproto.
9856 objc-method-type objc-method-decl ;
9860 c_parser_objc_methodproto (c_parser
*parser
)
9862 bool is_class_method
= c_parser_objc_method_type (parser
);
9863 tree decl
, attributes
= NULL_TREE
;
9865 /* Remember protocol qualifiers in prototypes. */
9866 parser
->objc_pq_context
= true;
9867 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9869 /* Forget protocol qualifiers now. */
9870 parser
->objc_pq_context
= false;
9872 /* Do not allow the presence of attributes to hide an erroneous
9873 method implementation in the interface section. */
9874 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9876 c_parser_error (parser
, "expected %<;%>");
9880 if (decl
!= error_mark_node
)
9881 objc_add_method_declaration (is_class_method
, decl
, attributes
);
9883 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9886 /* If we are at a position that method attributes may be present, check that
9887 there are not any parsed already (a syntax error) and then collect any
9888 specified at the current location. Finally, if new attributes were present,
9889 check that the next token is legal ( ';' for decls and '{' for defs). */
9892 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
9897 c_parser_error (parser
,
9898 "method attributes must be specified at the end only");
9899 *attributes
= NULL_TREE
;
9903 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
9904 *attributes
= c_parser_attributes (parser
);
9906 /* If there were no attributes here, just report any earlier error. */
9907 if (*attributes
== NULL_TREE
|| bad
)
9910 /* If the attributes are followed by a ; or {, then just report any earlier
9912 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
9913 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9916 /* We've got attributes, but not at the end. */
9917 c_parser_error (parser
,
9918 "expected %<;%> or %<{%> after method attribute definition");
9922 /* Parse an objc-method-decl.
9925 ( objc-type-name ) objc-selector
9927 ( objc-type-name ) objc-keyword-selector objc-optparmlist
9928 objc-keyword-selector objc-optparmlist
9931 objc-keyword-selector:
9933 objc-keyword-selector objc-keyword-decl
9936 objc-selector : ( objc-type-name ) identifier
9937 objc-selector : identifier
9938 : ( objc-type-name ) identifier
9942 objc-optparms objc-optellipsis
9946 objc-opt-parms , parameter-declaration
9954 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
9955 tree
*attributes
, tree
*expr
)
9957 tree type
= NULL_TREE
;
9959 tree parms
= NULL_TREE
;
9960 bool ellipsis
= false;
9961 bool attr_err
= false;
9963 *attributes
= NULL_TREE
;
9964 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9966 matching_parens parens
;
9967 parens
.consume_open (parser
);
9968 type
= c_parser_objc_type_name (parser
);
9969 parens
.skip_until_found_close (parser
);
9971 sel
= c_parser_objc_selector (parser
);
9972 /* If there is no selector, or a colon follows, we have an
9973 objc-keyword-selector. If there is a selector, and a colon does
9974 not follow, that selector ends the objc-method-decl. */
9975 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
9978 tree list
= NULL_TREE
;
9981 tree atype
= NULL_TREE
, id
, keyworddecl
;
9982 tree param_attr
= NULL_TREE
;
9983 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9985 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9987 c_parser_consume_token (parser
);
9988 atype
= c_parser_objc_type_name (parser
);
9989 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9992 /* New ObjC allows attributes on method parameters. */
9993 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
9994 param_attr
= c_parser_attributes (parser
);
9995 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9997 c_parser_error (parser
, "expected identifier");
9998 return error_mark_node
;
10000 id
= c_parser_peek_token (parser
)->value
;
10001 c_parser_consume_token (parser
);
10002 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
10003 list
= chainon (list
, keyworddecl
);
10004 tsel
= c_parser_objc_selector (parser
);
10005 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10009 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
10011 /* Parse the optional parameter list. Optional Objective-C
10012 method parameters follow the C syntax, and may include '...'
10013 to denote a variable number of arguments. */
10014 parms
= make_node (TREE_LIST
);
10015 while (c_parser_next_token_is (parser
, CPP_COMMA
))
10017 struct c_parm
*parm
;
10018 c_parser_consume_token (parser
);
10019 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
10022 c_parser_consume_token (parser
);
10023 attr_err
|= c_parser_objc_maybe_method_attributes
10024 (parser
, attributes
) ;
10027 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
10030 parms
= chainon (parms
,
10031 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
10036 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
10040 c_parser_error (parser
, "objective-c method declaration is expected");
10041 return error_mark_node
;
10045 return error_mark_node
;
10047 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
10050 /* Parse an objc-type-name.
10053 objc-type-qualifiers[opt] type-name
10054 objc-type-qualifiers[opt]
10056 objc-type-qualifiers:
10057 objc-type-qualifier
10058 objc-type-qualifiers objc-type-qualifier
10060 objc-type-qualifier: one of
10061 in out inout bycopy byref oneway
10065 c_parser_objc_type_name (c_parser
*parser
)
10067 tree quals
= NULL_TREE
;
10068 struct c_type_name
*type_name
= NULL
;
10069 tree type
= NULL_TREE
;
10072 c_token
*token
= c_parser_peek_token (parser
);
10073 if (token
->type
== CPP_KEYWORD
10074 && (token
->keyword
== RID_IN
10075 || token
->keyword
== RID_OUT
10076 || token
->keyword
== RID_INOUT
10077 || token
->keyword
== RID_BYCOPY
10078 || token
->keyword
== RID_BYREF
10079 || token
->keyword
== RID_ONEWAY
))
10081 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
10082 c_parser_consume_token (parser
);
10087 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
10088 type_name
= c_parser_type_name (parser
);
10090 type
= groktypename (type_name
, NULL
, NULL
);
10092 /* If the type is unknown, and error has already been produced and
10093 we need to recover from the error. In that case, use NULL_TREE
10094 for the type, as if no type had been specified; this will use the
10095 default type ('id') which is good for error recovery. */
10096 if (type
== error_mark_node
)
10099 return build_tree_list (quals
, type
);
10102 /* Parse objc-protocol-refs.
10104 objc-protocol-refs:
10105 < identifier-list >
10109 c_parser_objc_protocol_refs (c_parser
*parser
)
10111 tree list
= NULL_TREE
;
10112 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
10113 c_parser_consume_token (parser
);
10114 /* Any identifiers, including those declared as type names, are OK
10119 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10121 c_parser_error (parser
, "expected identifier");
10124 id
= c_parser_peek_token (parser
)->value
;
10125 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
10126 c_parser_consume_token (parser
);
10127 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10128 c_parser_consume_token (parser
);
10132 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
10136 /* Parse an objc-try-catch-finally-statement.
10138 objc-try-catch-finally-statement:
10139 @try compound-statement objc-catch-list[opt]
10140 @try compound-statement objc-catch-list[opt] @finally compound-statement
10143 @catch ( objc-catch-parameter-declaration ) compound-statement
10144 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
10146 objc-catch-parameter-declaration:
10147 parameter-declaration
10150 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
10152 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
10153 for C++. Keep them in sync. */
10156 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
10158 location_t location
;
10161 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
10162 c_parser_consume_token (parser
);
10163 location
= c_parser_peek_token (parser
)->location
;
10164 objc_maybe_warn_exceptions (location
);
10165 stmt
= c_parser_compound_statement (parser
);
10166 objc_begin_try_stmt (location
, stmt
);
10168 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
10170 struct c_parm
*parm
;
10171 tree parameter_declaration
= error_mark_node
;
10172 bool seen_open_paren
= false;
10174 c_parser_consume_token (parser
);
10175 matching_parens parens
;
10176 if (!parens
.require_open (parser
))
10177 seen_open_paren
= true;
10178 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
10180 /* We have "@catch (...)" (where the '...' are literally
10181 what is in the code). Skip the '...'.
10182 parameter_declaration is set to NULL_TREE, and
10183 objc_being_catch_clauses() knows that that means
10185 c_parser_consume_token (parser
);
10186 parameter_declaration
= NULL_TREE
;
10190 /* We have "@catch (NSException *exception)" or something
10191 like that. Parse the parameter declaration. */
10192 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
10194 parameter_declaration
= error_mark_node
;
10196 parameter_declaration
= grokparm (parm
, NULL
);
10198 if (seen_open_paren
)
10199 parens
.require_close (parser
);
10202 /* If there was no open parenthesis, we are recovering from
10203 an error, and we are trying to figure out what mistake
10204 the user has made. */
10206 /* If there is an immediate closing parenthesis, the user
10207 probably forgot the opening one (ie, they typed "@catch
10208 NSException *e)". Parse the closing parenthesis and keep
10210 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
10211 c_parser_consume_token (parser
);
10213 /* If these is no immediate closing parenthesis, the user
10214 probably doesn't know that parenthesis are required at
10215 all (ie, they typed "@catch NSException *e"). So, just
10216 forget about the closing parenthesis and keep going. */
10218 objc_begin_catch_clause (parameter_declaration
);
10219 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
10220 c_parser_compound_statement_nostart (parser
);
10221 objc_finish_catch_clause ();
10223 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
10225 c_parser_consume_token (parser
);
10226 location
= c_parser_peek_token (parser
)->location
;
10227 stmt
= c_parser_compound_statement (parser
);
10228 objc_build_finally_clause (location
, stmt
);
10230 objc_finish_try_stmt ();
10233 /* Parse an objc-synchronized-statement.
10235 objc-synchronized-statement:
10236 @synchronized ( expression ) compound-statement
10240 c_parser_objc_synchronized_statement (c_parser
*parser
)
10244 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
10245 c_parser_consume_token (parser
);
10246 loc
= c_parser_peek_token (parser
)->location
;
10247 objc_maybe_warn_exceptions (loc
);
10248 matching_parens parens
;
10249 if (parens
.require_open (parser
))
10251 struct c_expr ce
= c_parser_expression (parser
);
10252 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
10254 expr
= c_fully_fold (expr
, false, NULL
);
10255 parens
.skip_until_found_close (parser
);
10258 expr
= error_mark_node
;
10259 stmt
= c_parser_compound_statement (parser
);
10260 objc_build_synchronized (loc
, expr
, stmt
);
10263 /* Parse an objc-selector; return NULL_TREE without an error if the
10264 next token is not an objc-selector.
10269 enum struct union if else while do for switch case default
10270 break continue return goto asm sizeof typeof __alignof
10271 unsigned long const short volatile signed restrict _Complex
10272 in out inout bycopy byref oneway int char float double void _Bool
10275 ??? Why this selection of keywords but not, for example, storage
10276 class specifiers? */
10279 c_parser_objc_selector (c_parser
*parser
)
10281 c_token
*token
= c_parser_peek_token (parser
);
10282 tree value
= token
->value
;
10283 if (token
->type
== CPP_NAME
)
10285 c_parser_consume_token (parser
);
10288 if (token
->type
!= CPP_KEYWORD
)
10290 switch (token
->keyword
)
10329 CASE_RID_FLOATN_NX
:
10333 case RID_AUTO_TYPE
:
10338 c_parser_consume_token (parser
);
10345 /* Parse an objc-selector-arg.
10349 objc-keywordname-list
10351 objc-keywordname-list:
10353 objc-keywordname-list objc-keywordname
10361 c_parser_objc_selector_arg (c_parser
*parser
)
10363 tree sel
= c_parser_objc_selector (parser
);
10364 tree list
= NULL_TREE
;
10365 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10369 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10371 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
10372 sel
= c_parser_objc_selector (parser
);
10373 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10379 /* Parse an objc-receiver.
10388 c_parser_objc_receiver (c_parser
*parser
)
10390 location_t loc
= c_parser_peek_token (parser
)->location
;
10392 if (c_parser_peek_token (parser
)->type
== CPP_NAME
10393 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
10394 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
10396 tree id
= c_parser_peek_token (parser
)->value
;
10397 c_parser_consume_token (parser
);
10398 return objc_get_class_reference (id
);
10400 struct c_expr ce
= c_parser_expression (parser
);
10401 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
10402 return c_fully_fold (ce
.value
, false, NULL
);
10405 /* Parse objc-message-args.
10409 objc-keywordarg-list
10411 objc-keywordarg-list:
10413 objc-keywordarg-list objc-keywordarg
10416 objc-selector : objc-keywordexpr
10421 c_parser_objc_message_args (c_parser
*parser
)
10423 tree sel
= c_parser_objc_selector (parser
);
10424 tree list
= NULL_TREE
;
10425 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10430 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
10431 return error_mark_node
;
10432 keywordexpr
= c_parser_objc_keywordexpr (parser
);
10433 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
10434 sel
= c_parser_objc_selector (parser
);
10435 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
10441 /* Parse an objc-keywordexpr.
10448 c_parser_objc_keywordexpr (c_parser
*parser
)
10451 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
10452 NULL
, NULL
, NULL
, NULL
);
10453 if (vec_safe_length (expr_list
) == 1)
10455 /* Just return the expression, remove a level of
10457 ret
= (*expr_list
)[0];
10461 /* We have a comma expression, we will collapse later. */
10462 ret
= build_tree_list_vec (expr_list
);
10464 release_tree_vector (expr_list
);
10468 /* A check, needed in several places, that ObjC interface, implementation or
10469 method definitions are not prefixed by incorrect items. */
10471 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
10472 struct c_declspecs
*specs
)
10474 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
10475 || specs
->typespec_kind
!= ctsk_none
)
10477 c_parser_error (parser
,
10478 "no type or storage class may be specified here,");
10479 c_parser_skip_to_end_of_block_or_statement (parser
);
10485 /* Parse an Objective-C @property declaration. The syntax is:
10487 objc-property-declaration:
10488 '@property' objc-property-attributes[opt] struct-declaration ;
10490 objc-property-attributes:
10491 '(' objc-property-attribute-list ')'
10493 objc-property-attribute-list:
10494 objc-property-attribute
10495 objc-property-attribute-list, objc-property-attribute
10497 objc-property-attribute
10498 'getter' = identifier
10499 'setter' = identifier
10508 @property NSString *name;
10509 @property (readonly) id object;
10510 @property (retain, nonatomic, getter=getTheName) id name;
10511 @property int a, b, c;
10513 PS: This function is identical to cp_parser_objc_at_propery_declaration
10514 for C++. Keep them in sync. */
10516 c_parser_objc_at_property_declaration (c_parser
*parser
)
10518 /* The following variables hold the attributes of the properties as
10519 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
10520 seen. When we see an attribute, we set them to 'true' (if they
10521 are boolean properties) or to the identifier (if they have an
10522 argument, ie, for getter and setter). Note that here we only
10523 parse the list of attributes, check the syntax and accumulate the
10524 attributes that we find. objc_add_property_declaration() will
10525 then process the information. */
10526 bool property_assign
= false;
10527 bool property_copy
= false;
10528 tree property_getter_ident
= NULL_TREE
;
10529 bool property_nonatomic
= false;
10530 bool property_readonly
= false;
10531 bool property_readwrite
= false;
10532 bool property_retain
= false;
10533 tree property_setter_ident
= NULL_TREE
;
10535 /* 'properties' is the list of properties that we read. Usually a
10536 single one, but maybe more (eg, in "@property int a, b, c;" there
10541 loc
= c_parser_peek_token (parser
)->location
;
10542 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
10544 c_parser_consume_token (parser
); /* Eat '@property'. */
10546 /* Parse the optional attribute list... */
10547 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
10549 matching_parens parens
;
10552 parens
.consume_open (parser
);
10554 /* Property attribute keywords are valid now. */
10555 parser
->objc_property_attr_context
= true;
10559 bool syntax_error
= false;
10560 c_token
*token
= c_parser_peek_token (parser
);
10563 if (token
->type
!= CPP_KEYWORD
)
10565 if (token
->type
== CPP_CLOSE_PAREN
)
10566 c_parser_error (parser
, "expected identifier");
10569 c_parser_consume_token (parser
);
10570 c_parser_error (parser
, "unknown property attribute");
10574 keyword
= token
->keyword
;
10575 c_parser_consume_token (parser
);
10578 case RID_ASSIGN
: property_assign
= true; break;
10579 case RID_COPY
: property_copy
= true; break;
10580 case RID_NONATOMIC
: property_nonatomic
= true; break;
10581 case RID_READONLY
: property_readonly
= true; break;
10582 case RID_READWRITE
: property_readwrite
= true; break;
10583 case RID_RETAIN
: property_retain
= true; break;
10587 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
10589 if (keyword
== RID_GETTER
)
10590 c_parser_error (parser
,
10591 "missing %<=%> (after %<getter%> attribute)");
10593 c_parser_error (parser
,
10594 "missing %<=%> (after %<setter%> attribute)");
10595 syntax_error
= true;
10598 c_parser_consume_token (parser
); /* eat the = */
10599 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10601 c_parser_error (parser
, "expected identifier");
10602 syntax_error
= true;
10605 if (keyword
== RID_SETTER
)
10607 if (property_setter_ident
!= NULL_TREE
)
10608 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
10610 property_setter_ident
= c_parser_peek_token (parser
)->value
;
10611 c_parser_consume_token (parser
);
10612 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
10613 c_parser_error (parser
, "setter name must terminate with %<:%>");
10615 c_parser_consume_token (parser
);
10619 if (property_getter_ident
!= NULL_TREE
)
10620 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
10622 property_getter_ident
= c_parser_peek_token (parser
)->value
;
10623 c_parser_consume_token (parser
);
10627 c_parser_error (parser
, "unknown property attribute");
10628 syntax_error
= true;
10635 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10636 c_parser_consume_token (parser
);
10640 parser
->objc_property_attr_context
= false;
10641 parens
.skip_until_found_close (parser
);
10643 /* ... and the property declaration(s). */
10644 properties
= c_parser_struct_declaration (parser
);
10646 if (properties
== error_mark_node
)
10648 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10649 parser
->error
= false;
10653 if (properties
== NULL_TREE
)
10654 c_parser_error (parser
, "expected identifier");
10657 /* Comma-separated properties are chained together in
10658 reverse order; add them one by one. */
10659 properties
= nreverse (properties
);
10661 for (; properties
; properties
= TREE_CHAIN (properties
))
10662 objc_add_property_declaration (loc
, copy_node (properties
),
10663 property_readonly
, property_readwrite
,
10664 property_assign
, property_retain
,
10665 property_copy
, property_nonatomic
,
10666 property_getter_ident
, property_setter_ident
);
10669 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10670 parser
->error
= false;
10673 /* Parse an Objective-C @synthesize declaration. The syntax is:
10675 objc-synthesize-declaration:
10676 @synthesize objc-synthesize-identifier-list ;
10678 objc-synthesize-identifier-list:
10679 objc-synthesize-identifier
10680 objc-synthesize-identifier-list, objc-synthesize-identifier
10682 objc-synthesize-identifier
10684 identifier = identifier
10687 @synthesize MyProperty;
10688 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
10690 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
10691 for C++. Keep them in sync.
10694 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
10696 tree list
= NULL_TREE
;
10698 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
10699 loc
= c_parser_peek_token (parser
)->location
;
10701 c_parser_consume_token (parser
);
10704 tree property
, ivar
;
10705 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10707 c_parser_error (parser
, "expected identifier");
10708 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10709 /* Once we find the semicolon, we can resume normal parsing.
10710 We have to reset parser->error manually because
10711 c_parser_skip_until_found() won't reset it for us if the
10712 next token is precisely a semicolon. */
10713 parser
->error
= false;
10716 property
= c_parser_peek_token (parser
)->value
;
10717 c_parser_consume_token (parser
);
10718 if (c_parser_next_token_is (parser
, CPP_EQ
))
10720 c_parser_consume_token (parser
);
10721 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10723 c_parser_error (parser
, "expected identifier");
10724 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10725 parser
->error
= false;
10728 ivar
= c_parser_peek_token (parser
)->value
;
10729 c_parser_consume_token (parser
);
10733 list
= chainon (list
, build_tree_list (ivar
, property
));
10734 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10735 c_parser_consume_token (parser
);
10739 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10740 objc_add_synthesize_declaration (loc
, list
);
10743 /* Parse an Objective-C @dynamic declaration. The syntax is:
10745 objc-dynamic-declaration:
10746 @dynamic identifier-list ;
10749 @dynamic MyProperty;
10750 @dynamic MyProperty, AnotherProperty;
10752 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
10753 for C++. Keep them in sync.
10756 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
10758 tree list
= NULL_TREE
;
10760 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
10761 loc
= c_parser_peek_token (parser
)->location
;
10763 c_parser_consume_token (parser
);
10767 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10769 c_parser_error (parser
, "expected identifier");
10770 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10771 parser
->error
= false;
10774 property
= c_parser_peek_token (parser
)->value
;
10775 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
10776 c_parser_consume_token (parser
);
10777 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10778 c_parser_consume_token (parser
);
10782 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10783 objc_add_dynamic_declaration (loc
, list
);
10787 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
10788 should be considered, statements. ALLOW_STMT is true if we're within
10789 the context of a function and such pragmas are to be allowed. Returns
10790 true if we actually parsed such a pragma. */
10793 c_parser_pragma (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
10796 const char *construct
= NULL
;
10798 id
= c_parser_peek_token (parser
)->pragma_kind
;
10799 gcc_assert (id
!= PRAGMA_NONE
);
10803 case PRAGMA_OACC_DECLARE
:
10804 c_parser_oacc_declare (parser
);
10807 case PRAGMA_OACC_ENTER_DATA
:
10808 if (context
!= pragma_compound
)
10810 construct
= "acc enter data";
10812 if (context
== pragma_stmt
)
10814 error_at (c_parser_peek_token (parser
)->location
,
10815 "%<#pragma %s%> may only be used in compound "
10816 "statements", construct
);
10817 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10822 c_parser_oacc_enter_exit_data (parser
, true);
10825 case PRAGMA_OACC_EXIT_DATA
:
10826 if (context
!= pragma_compound
)
10828 construct
= "acc exit data";
10831 c_parser_oacc_enter_exit_data (parser
, false);
10834 case PRAGMA_OACC_ROUTINE
:
10835 if (context
!= pragma_external
)
10837 error_at (c_parser_peek_token (parser
)->location
,
10838 "%<#pragma acc routine%> must be at file scope");
10839 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10842 c_parser_oacc_routine (parser
, context
);
10845 case PRAGMA_OACC_UPDATE
:
10846 if (context
!= pragma_compound
)
10848 construct
= "acc update";
10851 c_parser_oacc_update (parser
);
10854 case PRAGMA_OMP_BARRIER
:
10855 if (context
!= pragma_compound
)
10857 construct
= "omp barrier";
10860 c_parser_omp_barrier (parser
);
10863 case PRAGMA_OMP_FLUSH
:
10864 if (context
!= pragma_compound
)
10866 construct
= "omp flush";
10869 c_parser_omp_flush (parser
);
10872 case PRAGMA_OMP_TASKWAIT
:
10873 if (context
!= pragma_compound
)
10875 construct
= "omp taskwait";
10878 c_parser_omp_taskwait (parser
);
10881 case PRAGMA_OMP_TASKYIELD
:
10882 if (context
!= pragma_compound
)
10884 construct
= "omp taskyield";
10887 c_parser_omp_taskyield (parser
);
10890 case PRAGMA_OMP_CANCEL
:
10891 if (context
!= pragma_compound
)
10893 construct
= "omp cancel";
10896 c_parser_omp_cancel (parser
);
10899 case PRAGMA_OMP_CANCELLATION_POINT
:
10900 c_parser_omp_cancellation_point (parser
, context
);
10903 case PRAGMA_OMP_THREADPRIVATE
:
10904 c_parser_omp_threadprivate (parser
);
10907 case PRAGMA_OMP_TARGET
:
10908 return c_parser_omp_target (parser
, context
, if_p
);
10910 case PRAGMA_OMP_END_DECLARE_TARGET
:
10911 c_parser_omp_end_declare_target (parser
);
10914 case PRAGMA_OMP_SECTION
:
10915 error_at (c_parser_peek_token (parser
)->location
,
10916 "%<#pragma omp section%> may only be used in "
10917 "%<#pragma omp sections%> construct");
10918 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10921 case PRAGMA_OMP_DECLARE
:
10922 c_parser_omp_declare (parser
, context
);
10925 case PRAGMA_OMP_ORDERED
:
10926 return c_parser_omp_ordered (parser
, context
, if_p
);
10929 c_parser_consume_pragma (parser
);
10930 c_parser_skip_to_pragma_eol (parser
);
10931 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
10932 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
10933 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
10935 c_parser_error (parser
, "for, while or do statement expected");
10938 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10939 c_parser_for_statement (parser
, true, if_p
);
10940 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
10941 c_parser_while_statement (parser
, true, if_p
);
10943 c_parser_do_statement (parser
, true);
10946 case PRAGMA_GCC_PCH_PREPROCESS
:
10947 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
10948 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10951 case PRAGMA_OACC_WAIT
:
10952 if (context
!= pragma_compound
)
10954 construct
= "acc wait";
10957 /* FALL THROUGH. */
10960 if (id
< PRAGMA_FIRST_EXTERNAL
)
10962 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
10965 c_parser_error (parser
, "expected declaration specifiers");
10966 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10969 c_parser_omp_construct (parser
, if_p
);
10975 c_parser_consume_pragma (parser
);
10976 c_invoke_pragma_handler (id
);
10978 /* Skip to EOL, but suppress any error message. Those will have been
10979 generated by the handler routine through calling error, as opposed
10980 to calling c_parser_error. */
10981 parser
->error
= true;
10982 c_parser_skip_to_pragma_eol (parser
);
10987 /* The interface the pragma parsers have to the lexer. */
10990 pragma_lex (tree
*value
, location_t
*loc
)
10992 c_token
*tok
= c_parser_peek_token (the_parser
);
10993 enum cpp_ttype ret
= tok
->type
;
10995 *value
= tok
->value
;
10997 *loc
= tok
->location
;
10999 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
11003 if (ret
== CPP_KEYWORD
)
11005 c_parser_consume_token (the_parser
);
11012 c_parser_pragma_pch_preprocess (c_parser
*parser
)
11016 c_parser_consume_pragma (parser
);
11017 if (c_parser_next_token_is (parser
, CPP_STRING
))
11019 name
= c_parser_peek_token (parser
)->value
;
11020 c_parser_consume_token (parser
);
11023 c_parser_error (parser
, "expected string literal");
11024 c_parser_skip_to_pragma_eol (parser
);
11027 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
11030 /* OpenACC and OpenMP parsing routines. */
11032 /* Returns name of the next clause.
11033 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
11034 the token is not consumed. Otherwise appropriate pragma_omp_clause is
11035 returned and the token is consumed. */
11037 static pragma_omp_clause
11038 c_parser_omp_clause_name (c_parser
*parser
)
11040 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
11042 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
11043 result
= PRAGMA_OACC_CLAUSE_AUTO
;
11044 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
11045 result
= PRAGMA_OMP_CLAUSE_IF
;
11046 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
11047 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
11048 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
11049 result
= PRAGMA_OMP_CLAUSE_FOR
;
11050 else if (c_parser_next_token_is (parser
, CPP_NAME
))
11052 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11057 if (!strcmp ("aligned", p
))
11058 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
11059 else if (!strcmp ("async", p
))
11060 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
11063 if (!strcmp ("collapse", p
))
11064 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
11065 else if (!strcmp ("copy", p
))
11066 result
= PRAGMA_OACC_CLAUSE_COPY
;
11067 else if (!strcmp ("copyin", p
))
11068 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
11069 else if (!strcmp ("copyout", p
))
11070 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
11071 else if (!strcmp ("copyprivate", p
))
11072 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
11073 else if (!strcmp ("create", p
))
11074 result
= PRAGMA_OACC_CLAUSE_CREATE
;
11077 if (!strcmp ("defaultmap", p
))
11078 result
= PRAGMA_OMP_CLAUSE_DEFAULTMAP
;
11079 else if (!strcmp ("delete", p
))
11080 result
= PRAGMA_OACC_CLAUSE_DELETE
;
11081 else if (!strcmp ("depend", p
))
11082 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
11083 else if (!strcmp ("device", p
))
11084 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
11085 else if (!strcmp ("deviceptr", p
))
11086 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
11087 else if (!strcmp ("device_resident", p
))
11088 result
= PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
;
11089 else if (!strcmp ("dist_schedule", p
))
11090 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
11093 if (!strcmp ("final", p
))
11094 result
= PRAGMA_OMP_CLAUSE_FINAL
;
11095 else if (!strcmp ("firstprivate", p
))
11096 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
11097 else if (!strcmp ("from", p
))
11098 result
= PRAGMA_OMP_CLAUSE_FROM
;
11101 if (!strcmp ("gang", p
))
11102 result
= PRAGMA_OACC_CLAUSE_GANG
;
11103 else if (!strcmp ("grainsize", p
))
11104 result
= PRAGMA_OMP_CLAUSE_GRAINSIZE
;
11107 if (!strcmp ("hint", p
))
11108 result
= PRAGMA_OMP_CLAUSE_HINT
;
11109 else if (!strcmp ("host", p
))
11110 result
= PRAGMA_OACC_CLAUSE_HOST
;
11113 if (!strcmp ("inbranch", p
))
11114 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
11115 else if (!strcmp ("independent", p
))
11116 result
= PRAGMA_OACC_CLAUSE_INDEPENDENT
;
11117 else if (!strcmp ("is_device_ptr", p
))
11118 result
= PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
;
11121 if (!strcmp ("lastprivate", p
))
11122 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
11123 else if (!strcmp ("linear", p
))
11124 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
11125 else if (!strcmp ("link", p
))
11126 result
= PRAGMA_OMP_CLAUSE_LINK
;
11129 if (!strcmp ("map", p
))
11130 result
= PRAGMA_OMP_CLAUSE_MAP
;
11131 else if (!strcmp ("mergeable", p
))
11132 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
11135 if (!strcmp ("nogroup", p
))
11136 result
= PRAGMA_OMP_CLAUSE_NOGROUP
;
11137 else if (!strcmp ("notinbranch", p
))
11138 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
11139 else if (!strcmp ("nowait", p
))
11140 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
11141 else if (!strcmp ("num_gangs", p
))
11142 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
11143 else if (!strcmp ("num_tasks", p
))
11144 result
= PRAGMA_OMP_CLAUSE_NUM_TASKS
;
11145 else if (!strcmp ("num_teams", p
))
11146 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
11147 else if (!strcmp ("num_threads", p
))
11148 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
11149 else if (!strcmp ("num_workers", p
))
11150 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
11153 if (!strcmp ("ordered", p
))
11154 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
11157 if (!strcmp ("parallel", p
))
11158 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
11159 else if (!strcmp ("present", p
))
11160 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
11161 else if (!strcmp ("present_or_copy", p
)
11162 || !strcmp ("pcopy", p
))
11163 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
;
11164 else if (!strcmp ("present_or_copyin", p
)
11165 || !strcmp ("pcopyin", p
))
11166 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
;
11167 else if (!strcmp ("present_or_copyout", p
)
11168 || !strcmp ("pcopyout", p
))
11169 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
;
11170 else if (!strcmp ("present_or_create", p
)
11171 || !strcmp ("pcreate", p
))
11172 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
;
11173 else if (!strcmp ("priority", p
))
11174 result
= PRAGMA_OMP_CLAUSE_PRIORITY
;
11175 else if (!strcmp ("private", p
))
11176 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
11177 else if (!strcmp ("proc_bind", p
))
11178 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
11181 if (!strcmp ("reduction", p
))
11182 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
11185 if (!strcmp ("safelen", p
))
11186 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
11187 else if (!strcmp ("schedule", p
))
11188 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
11189 else if (!strcmp ("sections", p
))
11190 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
11191 else if (!strcmp ("seq", p
))
11192 result
= PRAGMA_OACC_CLAUSE_SEQ
;
11193 else if (!strcmp ("shared", p
))
11194 result
= PRAGMA_OMP_CLAUSE_SHARED
;
11195 else if (!strcmp ("simd", p
))
11196 result
= PRAGMA_OMP_CLAUSE_SIMD
;
11197 else if (!strcmp ("simdlen", p
))
11198 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
11199 else if (!strcmp ("self", p
))
11200 result
= PRAGMA_OACC_CLAUSE_SELF
;
11203 if (!strcmp ("taskgroup", p
))
11204 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
11205 else if (!strcmp ("thread_limit", p
))
11206 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
11207 else if (!strcmp ("threads", p
))
11208 result
= PRAGMA_OMP_CLAUSE_THREADS
;
11209 else if (!strcmp ("tile", p
))
11210 result
= PRAGMA_OACC_CLAUSE_TILE
;
11211 else if (!strcmp ("to", p
))
11212 result
= PRAGMA_OMP_CLAUSE_TO
;
11215 if (!strcmp ("uniform", p
))
11216 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
11217 else if (!strcmp ("untied", p
))
11218 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
11219 else if (!strcmp ("use_device", p
))
11220 result
= PRAGMA_OACC_CLAUSE_USE_DEVICE
;
11221 else if (!strcmp ("use_device_ptr", p
))
11222 result
= PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
;
11225 if (!strcmp ("vector", p
))
11226 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
11227 else if (!strcmp ("vector_length", p
))
11228 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
11231 if (!strcmp ("wait", p
))
11232 result
= PRAGMA_OACC_CLAUSE_WAIT
;
11233 else if (!strcmp ("worker", p
))
11234 result
= PRAGMA_OACC_CLAUSE_WORKER
;
11239 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
11240 c_parser_consume_token (parser
);
11245 /* Validate that a clause of the given type does not already exist. */
11248 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
11253 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11254 if (OMP_CLAUSE_CODE (c
) == code
)
11256 location_t loc
= OMP_CLAUSE_LOCATION (c
);
11257 error_at (loc
, "too many %qs clauses", name
);
11263 Parse wait clause or wait directive parameters. */
11266 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
11268 vec
<tree
, va_gc
> *args
;
11271 matching_parens parens
;
11272 if (!parens
.require_open (parser
))
11275 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
11277 if (args
->length () == 0)
11279 c_parser_error (parser
, "expected integer expression before ')'");
11280 release_tree_vector (args
);
11284 args_tree
= build_tree_list_vec (args
);
11286 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
11288 tree targ
= TREE_VALUE (t
);
11290 if (targ
!= error_mark_node
)
11292 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
11294 c_parser_error (parser
, "expression must be integral");
11295 targ
= error_mark_node
;
11299 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
11301 OMP_CLAUSE_DECL (c
) = targ
;
11302 OMP_CLAUSE_CHAIN (c
) = list
;
11308 release_tree_vector (args
);
11309 parens
.require_close (parser
);
11313 /* OpenACC 2.0, OpenMP 2.5:
11316 variable-list , identifier
11318 If KIND is nonzero, create the appropriate node and install the
11319 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
11320 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
11322 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
11323 return the list created. */
11326 c_parser_omp_variable_list (c_parser
*parser
,
11327 location_t clause_loc
,
11328 enum omp_clause_code kind
, tree list
)
11330 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
11331 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
11332 c_parser_error (parser
, "expected identifier");
11334 while (c_parser_next_token_is (parser
, CPP_NAME
)
11335 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
11337 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
11339 if (t
== NULL_TREE
)
11341 undeclared_variable (c_parser_peek_token (parser
)->location
,
11342 c_parser_peek_token (parser
)->value
);
11343 t
= error_mark_node
;
11346 c_parser_consume_token (parser
);
11348 if (t
== error_mark_node
)
11350 else if (kind
!= 0)
11354 case OMP_CLAUSE__CACHE_
:
11355 /* The OpenACC cache directive explicitly only allows "array
11356 elements or subarrays". */
11357 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
11359 c_parser_error (parser
, "expected %<[%>");
11360 t
= error_mark_node
;
11364 case OMP_CLAUSE_MAP
:
11365 case OMP_CLAUSE_FROM
:
11366 case OMP_CLAUSE_TO
:
11367 while (c_parser_next_token_is (parser
, CPP_DOT
))
11369 location_t op_loc
= c_parser_peek_token (parser
)->location
;
11370 c_parser_consume_token (parser
);
11371 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11373 c_parser_error (parser
, "expected identifier");
11374 t
= error_mark_node
;
11378 c_token
*comp_tok
= c_parser_peek_token (parser
);
11379 tree ident
= comp_tok
->value
;
11380 location_t comp_loc
= comp_tok
->location
;
11381 c_parser_consume_token (parser
);
11382 t
= build_component_ref (op_loc
, t
, ident
, comp_loc
);
11385 case OMP_CLAUSE_DEPEND
:
11386 case OMP_CLAUSE_REDUCTION
:
11387 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
11389 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
11391 c_parser_consume_token (parser
);
11392 if (!c_parser_next_token_is (parser
, CPP_COLON
))
11394 location_t expr_loc
11395 = c_parser_peek_token (parser
)->location
;
11396 c_expr expr
= c_parser_expression (parser
);
11397 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
11399 low_bound
= expr
.value
;
11401 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
11402 length
= integer_one_node
;
11405 /* Look for `:'. */
11406 if (!c_parser_require (parser
, CPP_COLON
,
11409 t
= error_mark_node
;
11412 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
11414 location_t expr_loc
11415 = c_parser_peek_token (parser
)->location
;
11416 c_expr expr
= c_parser_expression (parser
);
11417 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
11419 length
= expr
.value
;
11422 /* Look for the closing `]'. */
11423 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
11426 t
= error_mark_node
;
11430 t
= tree_cons (low_bound
, length
, t
);
11437 if (t
!= error_mark_node
)
11439 tree u
= build_omp_clause (clause_loc
, kind
);
11440 OMP_CLAUSE_DECL (u
) = t
;
11441 OMP_CLAUSE_CHAIN (u
) = list
;
11446 list
= tree_cons (t
, NULL_TREE
, list
);
11448 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
11451 c_parser_consume_token (parser
);
11457 /* Similarly, but expect leading and trailing parenthesis. This is a very
11458 common case for OpenACC and OpenMP clauses. */
11461 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
11464 /* The clauses location. */
11465 location_t loc
= c_parser_peek_token (parser
)->location
;
11467 matching_parens parens
;
11468 if (parens
.require_open (parser
))
11470 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
11471 parens
.skip_until_found_close (parser
);
11477 copy ( variable-list )
11478 copyin ( variable-list )
11479 copyout ( variable-list )
11480 create ( variable-list )
11481 delete ( variable-list )
11482 present ( variable-list )
11483 present_or_copy ( variable-list )
11484 pcopy ( variable-list )
11485 present_or_copyin ( variable-list )
11486 pcopyin ( variable-list )
11487 present_or_copyout ( variable-list )
11488 pcopyout ( variable-list )
11489 present_or_create ( variable-list )
11490 pcreate ( variable-list ) */
11493 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
11496 enum gomp_map_kind kind
;
11499 case PRAGMA_OACC_CLAUSE_COPY
:
11500 kind
= GOMP_MAP_FORCE_TOFROM
;
11502 case PRAGMA_OACC_CLAUSE_COPYIN
:
11503 kind
= GOMP_MAP_FORCE_TO
;
11505 case PRAGMA_OACC_CLAUSE_COPYOUT
:
11506 kind
= GOMP_MAP_FORCE_FROM
;
11508 case PRAGMA_OACC_CLAUSE_CREATE
:
11509 kind
= GOMP_MAP_FORCE_ALLOC
;
11511 case PRAGMA_OACC_CLAUSE_DELETE
:
11512 kind
= GOMP_MAP_DELETE
;
11514 case PRAGMA_OACC_CLAUSE_DEVICE
:
11515 kind
= GOMP_MAP_FORCE_TO
;
11517 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
11518 kind
= GOMP_MAP_DEVICE_RESIDENT
;
11520 case PRAGMA_OACC_CLAUSE_HOST
:
11521 case PRAGMA_OACC_CLAUSE_SELF
:
11522 kind
= GOMP_MAP_FORCE_FROM
;
11524 case PRAGMA_OACC_CLAUSE_LINK
:
11525 kind
= GOMP_MAP_LINK
;
11527 case PRAGMA_OACC_CLAUSE_PRESENT
:
11528 kind
= GOMP_MAP_FORCE_PRESENT
;
11530 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
11531 kind
= GOMP_MAP_TOFROM
;
11533 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
11534 kind
= GOMP_MAP_TO
;
11536 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
11537 kind
= GOMP_MAP_FROM
;
11539 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
11540 kind
= GOMP_MAP_ALLOC
;
11543 gcc_unreachable ();
11546 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
11548 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
11549 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
11555 deviceptr ( variable-list ) */
11558 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
11560 location_t loc
= c_parser_peek_token (parser
)->location
;
11563 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
11564 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
11565 variable-list must only allow for pointer variables. */
11566 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
11567 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
11569 tree v
= TREE_PURPOSE (t
);
11571 /* FIXME diagnostics: Ideally we should keep individual
11572 locations for all the variables in the var list to make the
11573 following errors more precise. Perhaps
11574 c_parser_omp_var_list_parens() should construct a list of
11575 locations to go along with the var list. */
11577 if (!VAR_P (v
) && TREE_CODE (v
) != PARM_DECL
)
11578 error_at (loc
, "%qD is not a variable", v
);
11579 else if (TREE_TYPE (v
) == error_mark_node
)
11581 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
11582 error_at (loc
, "%qD is not a pointer variable", v
);
11584 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
11585 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
11586 OMP_CLAUSE_DECL (u
) = v
;
11587 OMP_CLAUSE_CHAIN (u
) = list
;
11594 /* OpenACC 2.0, OpenMP 3.0:
11595 collapse ( constant-expression ) */
11598 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
11600 tree c
, num
= error_mark_node
;
11604 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
11605 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
11607 loc
= c_parser_peek_token (parser
)->location
;
11608 matching_parens parens
;
11609 if (parens
.require_open (parser
))
11611 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
11612 parens
.skip_until_found_close (parser
);
11614 if (num
== error_mark_node
)
11616 mark_exp_read (num
);
11617 num
= c_fully_fold (num
, false, NULL
);
11618 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
11619 || !tree_fits_shwi_p (num
)
11620 || (n
= tree_to_shwi (num
)) <= 0
11624 "collapse argument needs positive constant integer expression");
11627 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
11628 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
11629 OMP_CLAUSE_CHAIN (c
) = list
;
11634 copyin ( variable-list ) */
11637 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
11639 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
11643 copyprivate ( variable-list ) */
11646 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
11648 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
11652 default ( none | shared )
11655 default ( none | present ) */
11658 c_parser_omp_clause_default (c_parser
*parser
, tree list
, bool is_oacc
)
11660 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
11661 location_t loc
= c_parser_peek_token (parser
)->location
;
11664 matching_parens parens
;
11665 if (!parens
.require_open (parser
))
11667 if (c_parser_next_token_is (parser
, CPP_NAME
))
11669 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11674 if (strcmp ("none", p
) != 0)
11676 kind
= OMP_CLAUSE_DEFAULT_NONE
;
11680 if (strcmp ("present", p
) != 0 || !is_oacc
)
11682 kind
= OMP_CLAUSE_DEFAULT_PRESENT
;
11686 if (strcmp ("shared", p
) != 0 || is_oacc
)
11688 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
11695 c_parser_consume_token (parser
);
11701 c_parser_error (parser
, "expected %<none%> or %<present%>");
11703 c_parser_error (parser
, "expected %<none%> or %<shared%>");
11705 parens
.skip_until_found_close (parser
);
11707 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
11710 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
11711 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
11712 OMP_CLAUSE_CHAIN (c
) = list
;
11713 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
11719 firstprivate ( variable-list ) */
11722 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
11724 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
11728 final ( expression ) */
11731 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
11733 location_t loc
= c_parser_peek_token (parser
)->location
;
11734 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11736 tree t
= c_parser_paren_condition (parser
);
11739 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
11741 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
11742 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
11743 OMP_CLAUSE_CHAIN (c
) = list
;
11747 c_parser_error (parser
, "expected %<(%>");
11752 /* OpenACC, OpenMP 2.5:
11756 if ( directive-name-modifier : expression )
11758 directive-name-modifier:
11759 parallel | task | taskloop | target data | target | target update
11760 | target enter data | target exit data */
11763 c_parser_omp_clause_if (c_parser
*parser
, tree list
, bool is_omp
)
11765 location_t location
= c_parser_peek_token (parser
)->location
;
11766 enum tree_code if_modifier
= ERROR_MARK
;
11768 matching_parens parens
;
11769 if (!parens
.require_open (parser
))
11772 if (is_omp
&& c_parser_next_token_is (parser
, CPP_NAME
))
11774 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11776 if (strcmp (p
, "parallel") == 0)
11777 if_modifier
= OMP_PARALLEL
;
11778 else if (strcmp (p
, "task") == 0)
11779 if_modifier
= OMP_TASK
;
11780 else if (strcmp (p
, "taskloop") == 0)
11781 if_modifier
= OMP_TASKLOOP
;
11782 else if (strcmp (p
, "target") == 0)
11784 if_modifier
= OMP_TARGET
;
11785 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11787 p
= IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser
)->value
);
11788 if (strcmp ("data", p
) == 0)
11789 if_modifier
= OMP_TARGET_DATA
;
11790 else if (strcmp ("update", p
) == 0)
11791 if_modifier
= OMP_TARGET_UPDATE
;
11792 else if (strcmp ("enter", p
) == 0)
11793 if_modifier
= OMP_TARGET_ENTER_DATA
;
11794 else if (strcmp ("exit", p
) == 0)
11795 if_modifier
= OMP_TARGET_EXIT_DATA
;
11796 if (if_modifier
!= OMP_TARGET
)
11799 c_parser_consume_token (parser
);
11803 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
11804 error_at (loc
, "expected %<data%>, %<update%>, %<enter%> "
11806 if_modifier
= ERROR_MARK
;
11808 if (if_modifier
== OMP_TARGET_ENTER_DATA
11809 || if_modifier
== OMP_TARGET_EXIT_DATA
)
11811 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11813 p
= IDENTIFIER_POINTER
11814 (c_parser_peek_2nd_token (parser
)->value
);
11815 if (strcmp ("data", p
) == 0)
11819 c_parser_consume_token (parser
);
11823 = c_parser_peek_2nd_token (parser
)->location
;
11824 error_at (loc
, "expected %<data%>");
11825 if_modifier
= ERROR_MARK
;
11830 if (if_modifier
!= ERROR_MARK
)
11832 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11834 c_parser_consume_token (parser
);
11835 c_parser_consume_token (parser
);
11841 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
11842 error_at (loc
, "expected %<:%>");
11844 if_modifier
= ERROR_MARK
;
11849 tree t
= c_parser_condition (parser
), c
;
11850 parens
.skip_until_found_close (parser
);
11852 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11853 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IF
)
11855 if (if_modifier
!= ERROR_MARK
11856 && OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
11858 const char *p
= NULL
;
11859 switch (if_modifier
)
11861 case OMP_PARALLEL
: p
= "parallel"; break;
11862 case OMP_TASK
: p
= "task"; break;
11863 case OMP_TASKLOOP
: p
= "taskloop"; break;
11864 case OMP_TARGET_DATA
: p
= "target data"; break;
11865 case OMP_TARGET
: p
= "target"; break;
11866 case OMP_TARGET_UPDATE
: p
= "target update"; break;
11867 case OMP_TARGET_ENTER_DATA
: p
= "enter data"; break;
11868 case OMP_TARGET_EXIT_DATA
: p
= "exit data"; break;
11869 default: gcc_unreachable ();
11871 error_at (location
, "too many %<if%> clauses with %qs modifier",
11875 else if (OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
11878 error_at (location
, "too many %<if%> clauses");
11880 error_at (location
, "too many %<if%> clauses without modifier");
11883 else if (if_modifier
== ERROR_MARK
11884 || OMP_CLAUSE_IF_MODIFIER (c
) == ERROR_MARK
)
11886 error_at (location
, "if any %<if%> clause has modifier, then all "
11887 "%<if%> clauses have to use modifier");
11892 c
= build_omp_clause (location
, OMP_CLAUSE_IF
);
11893 OMP_CLAUSE_IF_MODIFIER (c
) = if_modifier
;
11894 OMP_CLAUSE_IF_EXPR (c
) = t
;
11895 OMP_CLAUSE_CHAIN (c
) = list
;
11900 lastprivate ( variable-list ) */
11903 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
11905 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
11912 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11916 /* FIXME: Should we allow duplicates? */
11917 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
11919 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
11920 OMP_CLAUSE_MERGEABLE
);
11921 OMP_CLAUSE_CHAIN (c
) = list
;
11930 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11933 location_t loc
= c_parser_peek_token (parser
)->location
;
11935 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
11937 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
11938 OMP_CLAUSE_CHAIN (c
) = list
;
11943 num_threads ( expression ) */
11946 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
11948 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
11949 matching_parens parens
;
11950 if (parens
.require_open (parser
))
11952 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11953 c_expr expr
= c_parser_expression (parser
);
11954 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11955 tree c
, t
= expr
.value
;
11956 t
= c_fully_fold (t
, false, NULL
);
11958 parens
.skip_until_found_close (parser
);
11960 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11962 c_parser_error (parser
, "expected integer expression");
11966 /* Attempt to statically determine when the number isn't positive. */
11967 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11968 build_int_cst (TREE_TYPE (t
), 0));
11969 protected_set_expr_location (c
, expr_loc
);
11970 if (c
== boolean_true_node
)
11972 warning_at (expr_loc
, 0,
11973 "%<num_threads%> value must be positive");
11974 t
= integer_one_node
;
11977 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
11979 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
11980 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
11981 OMP_CLAUSE_CHAIN (c
) = list
;
11989 num_tasks ( expression ) */
11992 c_parser_omp_clause_num_tasks (c_parser
*parser
, tree list
)
11994 location_t num_tasks_loc
= c_parser_peek_token (parser
)->location
;
11995 matching_parens parens
;
11996 if (parens
.require_open (parser
))
11998 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11999 c_expr expr
= c_parser_expression (parser
);
12000 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12001 tree c
, t
= expr
.value
;
12002 t
= c_fully_fold (t
, false, NULL
);
12004 parens
.skip_until_found_close (parser
);
12006 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12008 c_parser_error (parser
, "expected integer expression");
12012 /* Attempt to statically determine when the number isn't positive. */
12013 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12014 build_int_cst (TREE_TYPE (t
), 0));
12015 if (CAN_HAVE_LOCATION_P (c
))
12016 SET_EXPR_LOCATION (c
, expr_loc
);
12017 if (c
== boolean_true_node
)
12019 warning_at (expr_loc
, 0, "%<num_tasks%> value must be positive");
12020 t
= integer_one_node
;
12023 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TASKS
, "num_tasks");
12025 c
= build_omp_clause (num_tasks_loc
, OMP_CLAUSE_NUM_TASKS
);
12026 OMP_CLAUSE_NUM_TASKS_EXPR (c
) = t
;
12027 OMP_CLAUSE_CHAIN (c
) = list
;
12035 grainsize ( expression ) */
12038 c_parser_omp_clause_grainsize (c_parser
*parser
, tree list
)
12040 location_t grainsize_loc
= c_parser_peek_token (parser
)->location
;
12041 matching_parens parens
;
12042 if (parens
.require_open (parser
))
12044 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12045 c_expr expr
= c_parser_expression (parser
);
12046 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12047 tree c
, t
= expr
.value
;
12048 t
= c_fully_fold (t
, false, NULL
);
12050 parens
.skip_until_found_close (parser
);
12052 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12054 c_parser_error (parser
, "expected integer expression");
12058 /* Attempt to statically determine when the number isn't positive. */
12059 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12060 build_int_cst (TREE_TYPE (t
), 0));
12061 if (CAN_HAVE_LOCATION_P (c
))
12062 SET_EXPR_LOCATION (c
, expr_loc
);
12063 if (c
== boolean_true_node
)
12065 warning_at (expr_loc
, 0, "%<grainsize%> value must be positive");
12066 t
= integer_one_node
;
12069 check_no_duplicate_clause (list
, OMP_CLAUSE_GRAINSIZE
, "grainsize");
12071 c
= build_omp_clause (grainsize_loc
, OMP_CLAUSE_GRAINSIZE
);
12072 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
12073 OMP_CLAUSE_CHAIN (c
) = list
;
12081 priority ( expression ) */
12084 c_parser_omp_clause_priority (c_parser
*parser
, tree list
)
12086 location_t priority_loc
= c_parser_peek_token (parser
)->location
;
12087 matching_parens parens
;
12088 if (parens
.require_open (parser
))
12090 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12091 c_expr expr
= c_parser_expression (parser
);
12092 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12093 tree c
, t
= expr
.value
;
12094 t
= c_fully_fold (t
, false, NULL
);
12096 parens
.skip_until_found_close (parser
);
12098 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12100 c_parser_error (parser
, "expected integer expression");
12104 /* Attempt to statically determine when the number isn't
12106 c
= fold_build2_loc (expr_loc
, LT_EXPR
, boolean_type_node
, t
,
12107 build_int_cst (TREE_TYPE (t
), 0));
12108 if (CAN_HAVE_LOCATION_P (c
))
12109 SET_EXPR_LOCATION (c
, expr_loc
);
12110 if (c
== boolean_true_node
)
12112 warning_at (expr_loc
, 0, "%<priority%> value must be non-negative");
12113 t
= integer_one_node
;
12116 check_no_duplicate_clause (list
, OMP_CLAUSE_PRIORITY
, "priority");
12118 c
= build_omp_clause (priority_loc
, OMP_CLAUSE_PRIORITY
);
12119 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
12120 OMP_CLAUSE_CHAIN (c
) = list
;
12128 hint ( expression ) */
12131 c_parser_omp_clause_hint (c_parser
*parser
, tree list
)
12133 location_t hint_loc
= c_parser_peek_token (parser
)->location
;
12134 matching_parens parens
;
12135 if (parens
.require_open (parser
))
12137 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12138 c_expr expr
= c_parser_expression (parser
);
12139 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12140 tree c
, t
= expr
.value
;
12141 t
= c_fully_fold (t
, false, NULL
);
12143 parens
.skip_until_found_close (parser
);
12145 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12147 c_parser_error (parser
, "expected integer expression");
12151 check_no_duplicate_clause (list
, OMP_CLAUSE_HINT
, "hint");
12153 c
= build_omp_clause (hint_loc
, OMP_CLAUSE_HINT
);
12154 OMP_CLAUSE_HINT_EXPR (c
) = t
;
12155 OMP_CLAUSE_CHAIN (c
) = list
;
12163 defaultmap ( tofrom : scalar ) */
12166 c_parser_omp_clause_defaultmap (c_parser
*parser
, tree list
)
12168 location_t loc
= c_parser_peek_token (parser
)->location
;
12172 matching_parens parens
;
12173 if (!parens
.require_open (parser
))
12175 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12177 c_parser_error (parser
, "expected %<tofrom%>");
12180 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12181 if (strcmp (p
, "tofrom") != 0)
12183 c_parser_error (parser
, "expected %<tofrom%>");
12186 c_parser_consume_token (parser
);
12187 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12189 if (!c_parser_next_token_is (parser
, CPP_NAME
))
12191 c_parser_error (parser
, "expected %<scalar%>");
12194 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12195 if (strcmp (p
, "scalar") != 0)
12197 c_parser_error (parser
, "expected %<scalar%>");
12200 c_parser_consume_token (parser
);
12201 parens
.skip_until_found_close (parser
);
12202 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULTMAP
, "defaultmap");
12203 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULTMAP
);
12204 OMP_CLAUSE_CHAIN (c
) = list
;
12208 parens
.skip_until_found_close (parser
);
12213 use_device ( variable-list )
12216 use_device_ptr ( variable-list ) */
12219 c_parser_omp_clause_use_device_ptr (c_parser
*parser
, tree list
)
12221 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_USE_DEVICE_PTR
,
12226 is_device_ptr ( variable-list ) */
12229 c_parser_omp_clause_is_device_ptr (c_parser
*parser
, tree list
)
12231 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_IS_DEVICE_PTR
, list
);
12235 num_gangs ( expression )
12236 num_workers ( expression )
12237 vector_length ( expression ) */
12240 c_parser_oacc_single_int_clause (c_parser
*parser
, omp_clause_code code
,
12243 location_t loc
= c_parser_peek_token (parser
)->location
;
12245 matching_parens parens
;
12246 if (!parens
.require_open (parser
))
12249 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12250 c_expr expr
= c_parser_expression (parser
);
12251 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12252 tree c
, t
= expr
.value
;
12253 t
= c_fully_fold (t
, false, NULL
);
12255 parens
.skip_until_found_close (parser
);
12257 if (t
== error_mark_node
)
12259 else if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12261 error_at (expr_loc
, "%qs expression must be integral",
12262 omp_clause_code_name
[code
]);
12266 /* Attempt to statically determine when the number isn't positive. */
12267 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12268 build_int_cst (TREE_TYPE (t
), 0));
12269 protected_set_expr_location (c
, expr_loc
);
12270 if (c
== boolean_true_node
)
12272 warning_at (expr_loc
, 0,
12273 "%qs value must be positive",
12274 omp_clause_code_name
[code
]);
12275 t
= integer_one_node
;
12278 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12280 c
= build_omp_clause (loc
, code
);
12281 OMP_CLAUSE_OPERAND (c
, 0) = t
;
12282 OMP_CLAUSE_CHAIN (c
) = list
;
12288 gang [( gang-arg-list )]
12289 worker [( [num:] int-expr )]
12290 vector [( [length:] int-expr )]
12292 where gang-arg is one of:
12297 and size-expr may be:
12304 c_parser_oacc_shape_clause (c_parser
*parser
, omp_clause_code kind
,
12305 const char *str
, tree list
)
12307 const char *id
= "num";
12308 tree ops
[2] = { NULL_TREE
, NULL_TREE
}, c
;
12309 location_t loc
= c_parser_peek_token (parser
)->location
;
12311 if (kind
== OMP_CLAUSE_VECTOR
)
12314 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12316 c_parser_consume_token (parser
);
12320 c_token
*next
= c_parser_peek_token (parser
);
12323 /* Gang static argument. */
12324 if (kind
== OMP_CLAUSE_GANG
12325 && c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12327 c_parser_consume_token (parser
);
12329 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12330 goto cleanup_error
;
12333 if (ops
[idx
] != NULL_TREE
)
12335 c_parser_error (parser
, "too many %<static%> arguments");
12336 goto cleanup_error
;
12339 /* Check for the '*' argument. */
12340 if (c_parser_next_token_is (parser
, CPP_MULT
)
12341 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
12342 || c_parser_peek_2nd_token (parser
)->type
12343 == CPP_CLOSE_PAREN
))
12345 c_parser_consume_token (parser
);
12346 ops
[idx
] = integer_minus_one_node
;
12348 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12350 c_parser_consume_token (parser
);
12357 /* Worker num: argument and vector length: arguments. */
12358 else if (c_parser_next_token_is (parser
, CPP_NAME
)
12359 && strcmp (id
, IDENTIFIER_POINTER (next
->value
)) == 0
12360 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12362 c_parser_consume_token (parser
); /* id */
12363 c_parser_consume_token (parser
); /* ':' */
12366 /* Now collect the actual argument. */
12367 if (ops
[idx
] != NULL_TREE
)
12369 c_parser_error (parser
, "unexpected argument");
12370 goto cleanup_error
;
12373 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12374 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
12375 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
12376 tree expr
= cexpr
.value
;
12377 if (expr
== error_mark_node
)
12378 goto cleanup_error
;
12380 expr
= c_fully_fold (expr
, false, NULL
);
12382 /* Attempt to statically determine when the number isn't a
12383 positive integer. */
12385 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
12387 c_parser_error (parser
, "expected integer expression");
12391 tree c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
12392 build_int_cst (TREE_TYPE (expr
), 0));
12393 if (c
== boolean_true_node
)
12395 warning_at (loc
, 0,
12396 "%qs value must be positive", str
);
12397 expr
= integer_one_node
;
12402 if (kind
== OMP_CLAUSE_GANG
12403 && c_parser_next_token_is (parser
, CPP_COMMA
))
12405 c_parser_consume_token (parser
);
12412 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12413 goto cleanup_error
;
12416 check_no_duplicate_clause (list
, kind
, str
);
12418 c
= build_omp_clause (loc
, kind
);
12421 OMP_CLAUSE_OPERAND (c
, 1) = ops
[1];
12423 OMP_CLAUSE_OPERAND (c
, 0) = ops
[0];
12424 OMP_CLAUSE_CHAIN (c
) = list
;
12429 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12440 c_parser_oacc_simple_clause (c_parser
*parser
, enum omp_clause_code code
,
12443 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12445 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12446 OMP_CLAUSE_CHAIN (c
) = list
;
12452 async [( int-expr )] */
12455 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
12458 location_t loc
= c_parser_peek_token (parser
)->location
;
12460 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
12462 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12464 c_parser_consume_token (parser
);
12466 t
= c_parser_expression (parser
).value
;
12467 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12468 c_parser_error (parser
, "expected integer expression");
12469 else if (t
== error_mark_node
12470 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
12474 t
= c_fully_fold (t
, false, NULL
);
12476 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
12478 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
12479 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
12480 OMP_CLAUSE_CHAIN (c
) = list
;
12487 tile ( size-expr-list ) */
12490 c_parser_oacc_clause_tile (c_parser
*parser
, tree list
)
12492 tree c
, expr
= error_mark_node
;
12494 tree tile
= NULL_TREE
;
12496 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
12497 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
12499 loc
= c_parser_peek_token (parser
)->location
;
12500 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12505 if (tile
&& !c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
12508 if (c_parser_next_token_is (parser
, CPP_MULT
)
12509 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
12510 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
12512 c_parser_consume_token (parser
);
12513 expr
= integer_zero_node
;
12517 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12518 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
12519 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
12520 expr
= cexpr
.value
;
12522 if (expr
== error_mark_node
)
12524 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12529 expr
= c_fully_fold (expr
, false, NULL
);
12531 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
12532 || !tree_fits_shwi_p (expr
)
12533 || tree_to_shwi (expr
) <= 0)
12535 error_at (expr_loc
, "%<tile%> argument needs positive"
12536 " integral constant");
12537 expr
= integer_zero_node
;
12541 tile
= tree_cons (NULL_TREE
, expr
, tile
);
12543 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
));
12545 /* Consume the trailing ')'. */
12546 c_parser_consume_token (parser
);
12548 c
= build_omp_clause (loc
, OMP_CLAUSE_TILE
);
12549 tile
= nreverse (tile
);
12550 OMP_CLAUSE_TILE_LIST (c
) = tile
;
12551 OMP_CLAUSE_CHAIN (c
) = list
;
12556 wait ( int-expr-list ) */
12559 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
12561 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12563 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
12564 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
12573 ordered ( constant-expression ) */
12576 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
12578 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
12580 tree c
, num
= NULL_TREE
;
12582 location_t loc
= c_parser_peek_token (parser
)->location
;
12583 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12585 matching_parens parens
;
12586 parens
.consume_open (parser
);
12587 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
12588 parens
.skip_until_found_close (parser
);
12590 if (num
== error_mark_node
)
12594 mark_exp_read (num
);
12595 num
= c_fully_fold (num
, false, NULL
);
12596 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
12597 || !tree_fits_shwi_p (num
)
12598 || (n
= tree_to_shwi (num
)) <= 0
12601 error_at (loc
, "ordered argument needs positive "
12602 "constant integer expression");
12606 c
= build_omp_clause (loc
, OMP_CLAUSE_ORDERED
);
12607 OMP_CLAUSE_ORDERED_EXPR (c
) = num
;
12608 OMP_CLAUSE_CHAIN (c
) = list
;
12613 private ( variable-list ) */
12616 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
12618 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
12622 reduction ( reduction-operator : variable-list )
12624 reduction-operator:
12625 One of: + * - & ^ | && ||
12629 reduction-operator:
12630 One of: + * - & ^ | && || max min
12634 reduction-operator:
12635 One of: + * - & ^ | && ||
12639 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
12641 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12642 matching_parens parens
;
12643 if (parens
.require_open (parser
))
12645 enum tree_code code
= ERROR_MARK
;
12646 tree reduc_id
= NULL_TREE
;
12648 switch (c_parser_peek_token (parser
)->type
)
12660 code
= BIT_AND_EXPR
;
12663 code
= BIT_XOR_EXPR
;
12666 code
= BIT_IOR_EXPR
;
12669 code
= TRUTH_ANDIF_EXPR
;
12672 code
= TRUTH_ORIF_EXPR
;
12677 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12678 if (strcmp (p
, "min") == 0)
12683 if (strcmp (p
, "max") == 0)
12688 reduc_id
= c_parser_peek_token (parser
)->value
;
12692 c_parser_error (parser
,
12693 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
12694 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
12695 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12698 c_parser_consume_token (parser
);
12699 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
12700 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12704 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12705 OMP_CLAUSE_REDUCTION
, list
);
12706 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12708 tree d
= OMP_CLAUSE_DECL (c
), type
;
12709 if (TREE_CODE (d
) != TREE_LIST
)
12710 type
= TREE_TYPE (d
);
12715 for (t
= d
; TREE_CODE (t
) == TREE_LIST
; t
= TREE_CHAIN (t
))
12717 type
= TREE_TYPE (t
);
12720 if (TREE_CODE (type
) != POINTER_TYPE
12721 && TREE_CODE (type
) != ARRAY_TYPE
)
12723 type
= TREE_TYPE (type
);
12727 while (TREE_CODE (type
) == ARRAY_TYPE
)
12728 type
= TREE_TYPE (type
);
12729 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
12730 if (code
== ERROR_MARK
12731 || !(INTEGRAL_TYPE_P (type
)
12732 || TREE_CODE (type
) == REAL_TYPE
12733 || TREE_CODE (type
) == COMPLEX_TYPE
))
12734 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
12735 = c_omp_reduction_lookup (reduc_id
,
12736 TYPE_MAIN_VARIANT (type
));
12741 parens
.skip_until_found_close (parser
);
12747 schedule ( schedule-kind )
12748 schedule ( schedule-kind , expression )
12751 static | dynamic | guided | runtime | auto
12754 schedule ( schedule-modifier : schedule-kind )
12755 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
12763 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
12766 location_t loc
= c_parser_peek_token (parser
)->location
;
12767 int modifiers
= 0, nmodifiers
= 0;
12769 matching_parens parens
;
12770 if (!parens
.require_open (parser
))
12773 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
12775 while (c_parser_next_token_is (parser
, CPP_NAME
))
12777 tree kind
= c_parser_peek_token (parser
)->value
;
12778 const char *p
= IDENTIFIER_POINTER (kind
);
12779 if (strcmp ("simd", p
) == 0)
12780 OMP_CLAUSE_SCHEDULE_SIMD (c
) = 1;
12781 else if (strcmp ("monotonic", p
) == 0)
12782 modifiers
|= OMP_CLAUSE_SCHEDULE_MONOTONIC
;
12783 else if (strcmp ("nonmonotonic", p
) == 0)
12784 modifiers
|= OMP_CLAUSE_SCHEDULE_NONMONOTONIC
;
12787 c_parser_consume_token (parser
);
12788 if (nmodifiers
++ == 0
12789 && c_parser_next_token_is (parser
, CPP_COMMA
))
12790 c_parser_consume_token (parser
);
12793 c_parser_require (parser
, CPP_COLON
, "expected %<:%>");
12798 if ((modifiers
& (OMP_CLAUSE_SCHEDULE_MONOTONIC
12799 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12800 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
12801 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12803 error_at (loc
, "both %<monotonic%> and %<nonmonotonic%> modifiers "
12808 if (c_parser_next_token_is (parser
, CPP_NAME
))
12810 tree kind
= c_parser_peek_token (parser
)->value
;
12811 const char *p
= IDENTIFIER_POINTER (kind
);
12816 if (strcmp ("dynamic", p
) != 0)
12818 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
12822 if (strcmp ("guided", p
) != 0)
12824 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
12828 if (strcmp ("runtime", p
) != 0)
12830 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
12837 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12838 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
12839 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
12840 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
12844 c_parser_consume_token (parser
);
12845 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12848 c_parser_consume_token (parser
);
12850 here
= c_parser_peek_token (parser
)->location
;
12851 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12852 expr
= convert_lvalue_to_rvalue (here
, expr
, false, true);
12854 t
= c_fully_fold (t
, false, NULL
);
12856 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
12857 error_at (here
, "schedule %<runtime%> does not take "
12858 "a %<chunk_size%> parameter");
12859 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
12861 "schedule %<auto%> does not take "
12862 "a %<chunk_size%> parameter");
12863 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
12865 /* Attempt to statically determine when the number isn't
12867 tree s
= fold_build2_loc (loc
, LE_EXPR
, boolean_type_node
, t
,
12868 build_int_cst (TREE_TYPE (t
), 0));
12869 protected_set_expr_location (s
, loc
);
12870 if (s
== boolean_true_node
)
12872 warning_at (loc
, 0,
12873 "chunk size value must be positive");
12874 t
= integer_one_node
;
12876 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
12879 c_parser_error (parser
, "expected integer expression");
12881 parens
.skip_until_found_close (parser
);
12884 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12885 "expected %<,%> or %<)%>");
12887 OMP_CLAUSE_SCHEDULE_KIND (c
)
12888 = (enum omp_clause_schedule_kind
)
12889 (OMP_CLAUSE_SCHEDULE_KIND (c
) | modifiers
);
12891 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
12892 OMP_CLAUSE_CHAIN (c
) = list
;
12896 c_parser_error (parser
, "invalid schedule kind");
12897 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12902 shared ( variable-list ) */
12905 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
12907 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
12914 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12918 /* FIXME: Should we allow duplicates? */
12919 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
12921 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12922 OMP_CLAUSE_UNTIED
);
12923 OMP_CLAUSE_CHAIN (c
) = list
;
12933 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
12934 enum omp_clause_code code
, tree list
)
12936 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12938 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12939 OMP_CLAUSE_CHAIN (c
) = list
;
12951 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
12952 enum omp_clause_code code
, tree list
)
12954 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12955 OMP_CLAUSE_CHAIN (c
) = list
;
12964 c_parser_omp_clause_nogroup (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12966 check_no_duplicate_clause (list
, OMP_CLAUSE_NOGROUP
, "nogroup");
12967 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12968 OMP_CLAUSE_NOGROUP
);
12969 OMP_CLAUSE_CHAIN (c
) = list
;
12978 c_parser_omp_clause_orderedkind (c_parser
*parser ATTRIBUTE_UNUSED
,
12979 enum omp_clause_code code
, tree list
)
12981 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12982 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12983 OMP_CLAUSE_CHAIN (c
) = list
;
12988 num_teams ( expression ) */
12991 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
12993 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
12994 matching_parens parens
;
12995 if (parens
.require_open (parser
))
12997 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12998 c_expr expr
= c_parser_expression (parser
);
12999 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13000 tree c
, t
= expr
.value
;
13001 t
= c_fully_fold (t
, false, NULL
);
13003 parens
.skip_until_found_close (parser
);
13005 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13007 c_parser_error (parser
, "expected integer expression");
13011 /* Attempt to statically determine when the number isn't positive. */
13012 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13013 build_int_cst (TREE_TYPE (t
), 0));
13014 protected_set_expr_location (c
, expr_loc
);
13015 if (c
== boolean_true_node
)
13017 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
13018 t
= integer_one_node
;
13021 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
13023 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
13024 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
13025 OMP_CLAUSE_CHAIN (c
) = list
;
13033 thread_limit ( expression ) */
13036 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
13038 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
13039 matching_parens parens
;
13040 if (parens
.require_open (parser
))
13042 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13043 c_expr expr
= c_parser_expression (parser
);
13044 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13045 tree c
, t
= expr
.value
;
13046 t
= c_fully_fold (t
, false, NULL
);
13048 parens
.skip_until_found_close (parser
);
13050 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13052 c_parser_error (parser
, "expected integer expression");
13056 /* Attempt to statically determine when the number isn't positive. */
13057 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
13058 build_int_cst (TREE_TYPE (t
), 0));
13059 protected_set_expr_location (c
, expr_loc
);
13060 if (c
== boolean_true_node
)
13062 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
13063 t
= integer_one_node
;
13066 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
13069 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
13070 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
13071 OMP_CLAUSE_CHAIN (c
) = list
;
13079 aligned ( variable-list )
13080 aligned ( variable-list : constant-expression ) */
13083 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
13085 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13088 matching_parens parens
;
13089 if (!parens
.require_open (parser
))
13092 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13093 OMP_CLAUSE_ALIGNED
, list
);
13095 if (c_parser_next_token_is (parser
, CPP_COLON
))
13097 c_parser_consume_token (parser
);
13098 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13099 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13100 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13101 tree alignment
= expr
.value
;
13102 alignment
= c_fully_fold (alignment
, false, NULL
);
13103 if (TREE_CODE (alignment
) != INTEGER_CST
13104 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
13105 || tree_int_cst_sgn (alignment
) != 1)
13107 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
13108 "be positive constant integer expression");
13109 alignment
= NULL_TREE
;
13112 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13113 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
13116 parens
.skip_until_found_close (parser
);
13121 linear ( variable-list )
13122 linear ( variable-list : expression )
13125 linear ( modifier ( variable-list ) )
13126 linear ( modifier ( variable-list ) : expression ) */
13129 c_parser_omp_clause_linear (c_parser
*parser
, tree list
)
13131 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13133 enum omp_clause_linear_kind kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
13135 matching_parens parens
;
13136 if (!parens
.require_open (parser
))
13139 if (c_parser_next_token_is (parser
, CPP_NAME
))
13141 c_token
*tok
= c_parser_peek_token (parser
);
13142 const char *p
= IDENTIFIER_POINTER (tok
->value
);
13143 if (strcmp ("val", p
) == 0)
13144 kind
= OMP_CLAUSE_LINEAR_VAL
;
13145 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
)
13146 kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
13147 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
13149 c_parser_consume_token (parser
);
13150 c_parser_consume_token (parser
);
13154 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13155 OMP_CLAUSE_LINEAR
, list
);
13157 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
13158 parens
.skip_until_found_close (parser
);
13160 if (c_parser_next_token_is (parser
, CPP_COLON
))
13162 c_parser_consume_token (parser
);
13163 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13164 c_expr expr
= c_parser_expression (parser
);
13165 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13167 step
= c_fully_fold (step
, false, NULL
);
13168 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
13170 error_at (clause_loc
, "%<linear%> clause step expression must "
13172 step
= integer_one_node
;
13177 step
= integer_one_node
;
13179 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13181 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
13182 OMP_CLAUSE_LINEAR_KIND (c
) = kind
;
13185 parens
.skip_until_found_close (parser
);
13190 safelen ( constant-expression ) */
13193 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
13195 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13198 matching_parens parens
;
13199 if (!parens
.require_open (parser
))
13202 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13203 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13204 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13206 t
= c_fully_fold (t
, false, NULL
);
13207 if (TREE_CODE (t
) != INTEGER_CST
13208 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
13209 || tree_int_cst_sgn (t
) != 1)
13211 error_at (clause_loc
, "%<safelen%> clause expression must "
13212 "be positive constant integer expression");
13216 parens
.skip_until_found_close (parser
);
13217 if (t
== NULL_TREE
|| t
== error_mark_node
)
13220 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
13222 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
13223 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
13224 OMP_CLAUSE_CHAIN (c
) = list
;
13229 simdlen ( constant-expression ) */
13232 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
13234 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13237 matching_parens parens
;
13238 if (!parens
.require_open (parser
))
13241 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13242 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13243 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13245 t
= c_fully_fold (t
, false, NULL
);
13246 if (TREE_CODE (t
) != INTEGER_CST
13247 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
13248 || tree_int_cst_sgn (t
) != 1)
13250 error_at (clause_loc
, "%<simdlen%> clause expression must "
13251 "be positive constant integer expression");
13255 parens
.skip_until_found_close (parser
);
13256 if (t
== NULL_TREE
|| t
== error_mark_node
)
13259 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
13261 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
13262 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
13263 OMP_CLAUSE_CHAIN (c
) = list
;
13269 identifier [+/- integer]
13270 vec , identifier [+/- integer]
13274 c_parser_omp_clause_depend_sink (c_parser
*parser
, location_t clause_loc
,
13278 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
13279 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
13281 c_parser_error (parser
, "expected identifier");
13285 while (c_parser_next_token_is (parser
, CPP_NAME
)
13286 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
13288 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
13289 tree addend
= NULL
;
13291 if (t
== NULL_TREE
)
13293 undeclared_variable (c_parser_peek_token (parser
)->location
,
13294 c_parser_peek_token (parser
)->value
);
13295 t
= error_mark_node
;
13298 c_parser_consume_token (parser
);
13301 if (c_parser_next_token_is (parser
, CPP_MINUS
))
13303 else if (!c_parser_next_token_is (parser
, CPP_PLUS
))
13305 addend
= integer_zero_node
;
13307 goto add_to_vector
;
13309 c_parser_consume_token (parser
);
13311 if (c_parser_next_token_is_not (parser
, CPP_NUMBER
))
13313 c_parser_error (parser
, "expected integer");
13317 addend
= c_parser_peek_token (parser
)->value
;
13318 if (TREE_CODE (addend
) != INTEGER_CST
)
13320 c_parser_error (parser
, "expected integer");
13323 c_parser_consume_token (parser
);
13326 if (t
!= error_mark_node
)
13328 vec
= tree_cons (addend
, t
, vec
);
13330 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec
) = 1;
13333 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
13336 c_parser_consume_token (parser
);
13339 if (vec
== NULL_TREE
)
13342 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
13343 OMP_CLAUSE_DEPEND_KIND (u
) = OMP_CLAUSE_DEPEND_SINK
;
13344 OMP_CLAUSE_DECL (u
) = nreverse (vec
);
13345 OMP_CLAUSE_CHAIN (u
) = list
;
13350 depend ( depend-kind: variable-list )
13358 depend ( sink : vec ) */
13361 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
13363 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13364 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
13367 matching_parens parens
;
13368 if (!parens
.require_open (parser
))
13371 if (c_parser_next_token_is (parser
, CPP_NAME
))
13373 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13374 if (strcmp ("in", p
) == 0)
13375 kind
= OMP_CLAUSE_DEPEND_IN
;
13376 else if (strcmp ("inout", p
) == 0)
13377 kind
= OMP_CLAUSE_DEPEND_INOUT
;
13378 else if (strcmp ("out", p
) == 0)
13379 kind
= OMP_CLAUSE_DEPEND_OUT
;
13380 else if (strcmp ("source", p
) == 0)
13381 kind
= OMP_CLAUSE_DEPEND_SOURCE
;
13382 else if (strcmp ("sink", p
) == 0)
13383 kind
= OMP_CLAUSE_DEPEND_SINK
;
13390 c_parser_consume_token (parser
);
13392 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
13394 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
13395 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
13396 OMP_CLAUSE_DECL (c
) = NULL_TREE
;
13397 OMP_CLAUSE_CHAIN (c
) = list
;
13398 parens
.skip_until_found_close (parser
);
13402 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
13405 if (kind
== OMP_CLAUSE_DEPEND_SINK
)
13406 nl
= c_parser_omp_clause_depend_sink (parser
, clause_loc
, list
);
13409 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
13410 OMP_CLAUSE_DEPEND
, list
);
13412 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13413 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
13416 parens
.skip_until_found_close (parser
);
13420 c_parser_error (parser
, "invalid depend kind");
13422 parens
.skip_until_found_close (parser
);
13427 map ( map-kind: variable-list )
13428 map ( variable-list )
13431 alloc | to | from | tofrom
13435 alloc | to | from | tofrom | release | delete
13437 map ( always [,] map-kind: variable-list ) */
13440 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
13442 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13443 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
13445 enum c_id_kind always_id_kind
= C_ID_NONE
;
13446 location_t always_loc
= UNKNOWN_LOCATION
;
13447 tree always_id
= NULL_TREE
;
13450 matching_parens parens
;
13451 if (!parens
.require_open (parser
))
13454 if (c_parser_next_token_is (parser
, CPP_NAME
))
13456 c_token
*tok
= c_parser_peek_token (parser
);
13457 const char *p
= IDENTIFIER_POINTER (tok
->value
);
13458 always_id_kind
= tok
->id_kind
;
13459 always_loc
= tok
->location
;
13460 always_id
= tok
->value
;
13461 if (strcmp ("always", p
) == 0)
13463 c_token
*sectok
= c_parser_peek_2nd_token (parser
);
13464 if (sectok
->type
== CPP_COMMA
)
13466 c_parser_consume_token (parser
);
13467 c_parser_consume_token (parser
);
13470 else if (sectok
->type
== CPP_NAME
)
13472 p
= IDENTIFIER_POINTER (sectok
->value
);
13473 if (strcmp ("alloc", p
) == 0
13474 || strcmp ("to", p
) == 0
13475 || strcmp ("from", p
) == 0
13476 || strcmp ("tofrom", p
) == 0
13477 || strcmp ("release", p
) == 0
13478 || strcmp ("delete", p
) == 0)
13480 c_parser_consume_token (parser
);
13487 if (c_parser_next_token_is (parser
, CPP_NAME
)
13488 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
13490 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13491 if (strcmp ("alloc", p
) == 0)
13492 kind
= GOMP_MAP_ALLOC
;
13493 else if (strcmp ("to", p
) == 0)
13494 kind
= always
? GOMP_MAP_ALWAYS_TO
: GOMP_MAP_TO
;
13495 else if (strcmp ("from", p
) == 0)
13496 kind
= always
? GOMP_MAP_ALWAYS_FROM
: GOMP_MAP_FROM
;
13497 else if (strcmp ("tofrom", p
) == 0)
13498 kind
= always
? GOMP_MAP_ALWAYS_TOFROM
: GOMP_MAP_TOFROM
;
13499 else if (strcmp ("release", p
) == 0)
13500 kind
= GOMP_MAP_RELEASE
;
13501 else if (strcmp ("delete", p
) == 0)
13502 kind
= GOMP_MAP_DELETE
;
13505 c_parser_error (parser
, "invalid map kind");
13506 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13510 c_parser_consume_token (parser
);
13511 c_parser_consume_token (parser
);
13515 if (always_id_kind
!= C_ID_ID
)
13517 c_parser_error (parser
, "expected identifier");
13518 parens
.skip_until_found_close (parser
);
13522 tree t
= lookup_name (always_id
);
13523 if (t
== NULL_TREE
)
13525 undeclared_variable (always_loc
, always_id
);
13526 t
= error_mark_node
;
13528 if (t
!= error_mark_node
)
13530 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_MAP
);
13531 OMP_CLAUSE_DECL (u
) = t
;
13532 OMP_CLAUSE_CHAIN (u
) = list
;
13533 OMP_CLAUSE_SET_MAP_KIND (u
, kind
);
13538 parens
.skip_until_found_close (parser
);
13543 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
13545 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13546 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
13548 parens
.skip_until_found_close (parser
);
13553 device ( expression ) */
13556 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
13558 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13559 matching_parens parens
;
13560 if (parens
.require_open (parser
))
13562 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13563 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13564 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13565 tree c
, t
= expr
.value
;
13566 t
= c_fully_fold (t
, false, NULL
);
13568 parens
.skip_until_found_close (parser
);
13570 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13572 c_parser_error (parser
, "expected integer expression");
13576 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
13578 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
13579 OMP_CLAUSE_DEVICE_ID (c
) = t
;
13580 OMP_CLAUSE_CHAIN (c
) = list
;
13588 dist_schedule ( static )
13589 dist_schedule ( static , expression ) */
13592 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
13594 tree c
, t
= NULL_TREE
;
13595 location_t loc
= c_parser_peek_token (parser
)->location
;
13597 matching_parens parens
;
13598 if (!parens
.require_open (parser
))
13601 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
13603 c_parser_error (parser
, "invalid dist_schedule kind");
13604 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13609 c_parser_consume_token (parser
);
13610 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13612 c_parser_consume_token (parser
);
13614 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13615 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13616 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13618 t
= c_fully_fold (t
, false, NULL
);
13619 parens
.skip_until_found_close (parser
);
13622 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13623 "expected %<,%> or %<)%>");
13625 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
13626 if (t
== error_mark_node
)
13629 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
13630 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
13631 OMP_CLAUSE_CHAIN (c
) = list
;
13636 proc_bind ( proc-bind-kind )
13639 master | close | spread */
13642 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
13644 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13645 enum omp_clause_proc_bind_kind kind
;
13648 matching_parens parens
;
13649 if (!parens
.require_open (parser
))
13652 if (c_parser_next_token_is (parser
, CPP_NAME
))
13654 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13655 if (strcmp ("master", p
) == 0)
13656 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
13657 else if (strcmp ("close", p
) == 0)
13658 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
13659 else if (strcmp ("spread", p
) == 0)
13660 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
13667 c_parser_consume_token (parser
);
13668 parens
.skip_until_found_close (parser
);
13669 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
13670 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
13671 OMP_CLAUSE_CHAIN (c
) = list
;
13675 c_parser_error (parser
, "invalid proc_bind kind");
13676 parens
.skip_until_found_close (parser
);
13681 to ( variable-list ) */
13684 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
13686 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
13690 from ( variable-list ) */
13693 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
13695 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
13699 uniform ( variable-list ) */
13702 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
13704 /* The clauses location. */
13705 location_t loc
= c_parser_peek_token (parser
)->location
;
13707 matching_parens parens
;
13708 if (parens
.require_open (parser
))
13710 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
13712 parens
.skip_until_found_close (parser
);
13717 /* Parse all OpenACC clauses. The set clauses allowed by the directive
13718 is a bitmask in MASK. Return the list of clauses found. */
13721 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
13722 const char *where
, bool finish_p
= true)
13724 tree clauses
= NULL
;
13727 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13730 pragma_omp_clause c_kind
;
13731 const char *c_name
;
13732 tree prev
= clauses
;
13734 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
13735 c_parser_consume_token (parser
);
13737 here
= c_parser_peek_token (parser
)->location
;
13738 c_kind
= c_parser_omp_clause_name (parser
);
13742 case PRAGMA_OACC_CLAUSE_ASYNC
:
13743 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
13746 case PRAGMA_OACC_CLAUSE_AUTO
:
13747 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_AUTO
,
13751 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
13752 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
13753 c_name
= "collapse";
13755 case PRAGMA_OACC_CLAUSE_COPY
:
13756 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13759 case PRAGMA_OACC_CLAUSE_COPYIN
:
13760 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13763 case PRAGMA_OACC_CLAUSE_COPYOUT
:
13764 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13765 c_name
= "copyout";
13767 case PRAGMA_OACC_CLAUSE_CREATE
:
13768 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13771 case PRAGMA_OACC_CLAUSE_DELETE
:
13772 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13775 case PRAGMA_OMP_CLAUSE_DEFAULT
:
13776 clauses
= c_parser_omp_clause_default (parser
, clauses
, true);
13777 c_name
= "default";
13779 case PRAGMA_OACC_CLAUSE_DEVICE
:
13780 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13783 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
13784 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
13785 c_name
= "deviceptr";
13787 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
13788 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13789 c_name
= "device_resident";
13791 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
13792 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13793 c_name
= "firstprivate";
13795 case PRAGMA_OACC_CLAUSE_GANG
:
13797 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_GANG
,
13800 case PRAGMA_OACC_CLAUSE_HOST
:
13801 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13804 case PRAGMA_OACC_CLAUSE_IF
:
13805 clauses
= c_parser_omp_clause_if (parser
, clauses
, false);
13808 case PRAGMA_OACC_CLAUSE_INDEPENDENT
:
13809 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_INDEPENDENT
,
13811 c_name
= "independent";
13813 case PRAGMA_OACC_CLAUSE_LINK
:
13814 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13817 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
13818 clauses
= c_parser_oacc_single_int_clause (parser
,
13819 OMP_CLAUSE_NUM_GANGS
,
13821 c_name
= "num_gangs";
13823 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
13824 clauses
= c_parser_oacc_single_int_clause (parser
,
13825 OMP_CLAUSE_NUM_WORKERS
,
13827 c_name
= "num_workers";
13829 case PRAGMA_OACC_CLAUSE_PRESENT
:
13830 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13831 c_name
= "present";
13833 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
13834 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13835 c_name
= "present_or_copy";
13837 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
13838 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13839 c_name
= "present_or_copyin";
13841 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
13842 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13843 c_name
= "present_or_copyout";
13845 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
13846 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13847 c_name
= "present_or_create";
13849 case PRAGMA_OACC_CLAUSE_PRIVATE
:
13850 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13851 c_name
= "private";
13853 case PRAGMA_OACC_CLAUSE_REDUCTION
:
13854 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13855 c_name
= "reduction";
13857 case PRAGMA_OACC_CLAUSE_SELF
:
13858 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13861 case PRAGMA_OACC_CLAUSE_SEQ
:
13862 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_SEQ
,
13866 case PRAGMA_OACC_CLAUSE_TILE
:
13867 clauses
= c_parser_oacc_clause_tile (parser
, clauses
);
13870 case PRAGMA_OACC_CLAUSE_USE_DEVICE
:
13871 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
13872 c_name
= "use_device";
13874 case PRAGMA_OACC_CLAUSE_VECTOR
:
13876 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_VECTOR
,
13879 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
13880 clauses
= c_parser_oacc_single_int_clause (parser
,
13881 OMP_CLAUSE_VECTOR_LENGTH
,
13883 c_name
= "vector_length";
13885 case PRAGMA_OACC_CLAUSE_WAIT
:
13886 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
13889 case PRAGMA_OACC_CLAUSE_WORKER
:
13891 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_WORKER
,
13895 c_parser_error (parser
, "expected %<#pragma acc%> clause");
13901 if (((mask
>> c_kind
) & 1) == 0)
13903 /* Remove the invalid clause(s) from the list to avoid
13904 confusing the rest of the compiler. */
13906 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
13911 c_parser_skip_to_pragma_eol (parser
);
13914 return c_finish_omp_clauses (clauses
, C_ORT_ACC
);
13919 /* Parse all OpenMP clauses. The set clauses allowed by the directive
13920 is a bitmask in MASK. Return the list of clauses found. */
13923 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
13924 const char *where
, bool finish_p
= true)
13926 tree clauses
= NULL
;
13929 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13932 pragma_omp_clause c_kind
;
13933 const char *c_name
;
13934 tree prev
= clauses
;
13936 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
13937 c_parser_consume_token (parser
);
13939 here
= c_parser_peek_token (parser
)->location
;
13940 c_kind
= c_parser_omp_clause_name (parser
);
13944 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
13945 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
13946 c_name
= "collapse";
13948 case PRAGMA_OMP_CLAUSE_COPYIN
:
13949 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
13952 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
13953 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
13954 c_name
= "copyprivate";
13956 case PRAGMA_OMP_CLAUSE_DEFAULT
:
13957 clauses
= c_parser_omp_clause_default (parser
, clauses
, false);
13958 c_name
= "default";
13960 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
13961 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13962 c_name
= "firstprivate";
13964 case PRAGMA_OMP_CLAUSE_FINAL
:
13965 clauses
= c_parser_omp_clause_final (parser
, clauses
);
13968 case PRAGMA_OMP_CLAUSE_GRAINSIZE
:
13969 clauses
= c_parser_omp_clause_grainsize (parser
, clauses
);
13970 c_name
= "grainsize";
13972 case PRAGMA_OMP_CLAUSE_HINT
:
13973 clauses
= c_parser_omp_clause_hint (parser
, clauses
);
13976 case PRAGMA_OMP_CLAUSE_DEFAULTMAP
:
13977 clauses
= c_parser_omp_clause_defaultmap (parser
, clauses
);
13978 c_name
= "defaultmap";
13980 case PRAGMA_OMP_CLAUSE_IF
:
13981 clauses
= c_parser_omp_clause_if (parser
, clauses
, true);
13984 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
13985 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
13986 c_name
= "lastprivate";
13988 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
13989 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
13990 c_name
= "mergeable";
13992 case PRAGMA_OMP_CLAUSE_NOWAIT
:
13993 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
13996 case PRAGMA_OMP_CLAUSE_NUM_TASKS
:
13997 clauses
= c_parser_omp_clause_num_tasks (parser
, clauses
);
13998 c_name
= "num_tasks";
14000 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
14001 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
14002 c_name
= "num_threads";
14004 case PRAGMA_OMP_CLAUSE_ORDERED
:
14005 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
14006 c_name
= "ordered";
14008 case PRAGMA_OMP_CLAUSE_PRIORITY
:
14009 clauses
= c_parser_omp_clause_priority (parser
, clauses
);
14010 c_name
= "priority";
14012 case PRAGMA_OMP_CLAUSE_PRIVATE
:
14013 clauses
= c_parser_omp_clause_private (parser
, clauses
);
14014 c_name
= "private";
14016 case PRAGMA_OMP_CLAUSE_REDUCTION
:
14017 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
14018 c_name
= "reduction";
14020 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
14021 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
14022 c_name
= "schedule";
14024 case PRAGMA_OMP_CLAUSE_SHARED
:
14025 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
14028 case PRAGMA_OMP_CLAUSE_UNTIED
:
14029 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
14032 case PRAGMA_OMP_CLAUSE_INBRANCH
:
14033 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
14035 c_name
= "inbranch";
14037 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
14038 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
14040 c_name
= "notinbranch";
14042 case PRAGMA_OMP_CLAUSE_PARALLEL
:
14044 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
14046 c_name
= "parallel";
14050 error_at (here
, "%qs must be the first clause of %qs",
14055 case PRAGMA_OMP_CLAUSE_FOR
:
14057 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
14061 goto clause_not_first
;
14063 case PRAGMA_OMP_CLAUSE_SECTIONS
:
14065 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
14067 c_name
= "sections";
14069 goto clause_not_first
;
14071 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
14073 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
14075 c_name
= "taskgroup";
14077 goto clause_not_first
;
14079 case PRAGMA_OMP_CLAUSE_LINK
:
14081 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LINK
, clauses
);
14084 case PRAGMA_OMP_CLAUSE_TO
:
14085 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINK
)) != 0)
14087 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
14090 clauses
= c_parser_omp_clause_to (parser
, clauses
);
14093 case PRAGMA_OMP_CLAUSE_FROM
:
14094 clauses
= c_parser_omp_clause_from (parser
, clauses
);
14097 case PRAGMA_OMP_CLAUSE_UNIFORM
:
14098 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
14099 c_name
= "uniform";
14101 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
14102 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
14103 c_name
= "num_teams";
14105 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
14106 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
14107 c_name
= "thread_limit";
14109 case PRAGMA_OMP_CLAUSE_ALIGNED
:
14110 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
14111 c_name
= "aligned";
14113 case PRAGMA_OMP_CLAUSE_LINEAR
:
14114 clauses
= c_parser_omp_clause_linear (parser
, clauses
);
14117 case PRAGMA_OMP_CLAUSE_DEPEND
:
14118 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
14121 case PRAGMA_OMP_CLAUSE_MAP
:
14122 clauses
= c_parser_omp_clause_map (parser
, clauses
);
14125 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
:
14126 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
14127 c_name
= "use_device_ptr";
14129 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
:
14130 clauses
= c_parser_omp_clause_is_device_ptr (parser
, clauses
);
14131 c_name
= "is_device_ptr";
14133 case PRAGMA_OMP_CLAUSE_DEVICE
:
14134 clauses
= c_parser_omp_clause_device (parser
, clauses
);
14137 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
14138 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
14139 c_name
= "dist_schedule";
14141 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
14142 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
14143 c_name
= "proc_bind";
14145 case PRAGMA_OMP_CLAUSE_SAFELEN
:
14146 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
14147 c_name
= "safelen";
14149 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
14150 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
14151 c_name
= "simdlen";
14153 case PRAGMA_OMP_CLAUSE_NOGROUP
:
14154 clauses
= c_parser_omp_clause_nogroup (parser
, clauses
);
14155 c_name
= "nogroup";
14157 case PRAGMA_OMP_CLAUSE_THREADS
:
14159 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_THREADS
,
14161 c_name
= "threads";
14163 case PRAGMA_OMP_CLAUSE_SIMD
:
14165 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_SIMD
,
14170 c_parser_error (parser
, "expected %<#pragma omp%> clause");
14176 if (((mask
>> c_kind
) & 1) == 0)
14178 /* Remove the invalid clause(s) from the list to avoid
14179 confusing the rest of the compiler. */
14181 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
14186 c_parser_skip_to_pragma_eol (parser
);
14190 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_UNIFORM
)) != 0)
14191 return c_finish_omp_clauses (clauses
, C_ORT_OMP_DECLARE_SIMD
);
14192 return c_finish_omp_clauses (clauses
, C_ORT_OMP
);
14198 /* OpenACC 2.0, OpenMP 2.5:
14202 In practice, we're also interested in adding the statement to an
14203 outer node. So it is convenient if we work around the fact that
14204 c_parser_statement calls add_stmt. */
14207 c_parser_omp_structured_block (c_parser
*parser
, bool *if_p
)
14209 tree stmt
= push_stmt_list ();
14210 c_parser_statement (parser
, if_p
);
14211 return pop_stmt_list (stmt
);
14215 # pragma acc cache (variable-list) new-line
14217 LOC is the location of the #pragma token.
14221 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
14223 tree stmt
, clauses
;
14225 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
14226 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14228 c_parser_skip_to_pragma_eol (parser
);
14230 stmt
= make_node (OACC_CACHE
);
14231 TREE_TYPE (stmt
) = void_type_node
;
14232 OACC_CACHE_CLAUSES (stmt
) = clauses
;
14233 SET_EXPR_LOCATION (stmt
, loc
);
14240 # pragma acc data oacc-data-clause[optseq] new-line
14243 LOC is the location of the #pragma token.
14246 #define OACC_DATA_CLAUSE_MASK \
14247 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14248 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14249 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14250 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14251 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14252 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14253 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14254 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14255 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14256 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14257 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
14260 c_parser_oacc_data (location_t loc
, c_parser
*parser
, bool *if_p
)
14262 tree stmt
, clauses
, block
;
14264 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
14265 "#pragma acc data");
14267 block
= c_begin_omp_parallel ();
14268 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14270 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
14276 # pragma acc declare oacc-data-clause[optseq] new-line
14279 #define OACC_DECLARE_CLAUSE_MASK \
14280 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14281 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14282 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14283 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14284 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14285 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \
14286 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \
14287 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14288 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14289 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14290 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14291 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
14294 c_parser_oacc_declare (c_parser
*parser
)
14296 location_t pragma_loc
= c_parser_peek_token (parser
)->location
;
14297 tree clauses
, stmt
, t
, decl
;
14299 bool error
= false;
14301 c_parser_consume_pragma (parser
);
14303 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DECLARE_CLAUSE_MASK
,
14304 "#pragma acc declare");
14307 error_at (pragma_loc
,
14308 "no valid clauses specified in %<#pragma acc declare%>");
14312 for (t
= clauses
; t
; t
= OMP_CLAUSE_CHAIN (t
))
14314 location_t loc
= OMP_CLAUSE_LOCATION (t
);
14315 decl
= OMP_CLAUSE_DECL (t
);
14316 if (!DECL_P (decl
))
14318 error_at (loc
, "array section in %<#pragma acc declare%>");
14323 switch (OMP_CLAUSE_MAP_KIND (t
))
14325 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
14326 case GOMP_MAP_FORCE_ALLOC
:
14327 case GOMP_MAP_FORCE_TO
:
14328 case GOMP_MAP_FORCE_DEVICEPTR
:
14329 case GOMP_MAP_DEVICE_RESIDENT
:
14332 case GOMP_MAP_LINK
:
14333 if (!global_bindings_p ()
14334 && (TREE_STATIC (decl
)
14335 || !DECL_EXTERNAL (decl
)))
14338 "%qD must be a global variable in "
14339 "%<#pragma acc declare link%>",
14347 if (global_bindings_p ())
14349 error_at (loc
, "invalid OpenACC clause at file scope");
14353 if (DECL_EXTERNAL (decl
))
14356 "invalid use of %<extern%> variable %qD "
14357 "in %<#pragma acc declare%>", decl
);
14361 else if (TREE_PUBLIC (decl
))
14364 "invalid use of %<global%> variable %qD "
14365 "in %<#pragma acc declare%>", decl
);
14372 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl
))
14373 || lookup_attribute ("omp declare target link",
14374 DECL_ATTRIBUTES (decl
)))
14376 error_at (loc
, "variable %qD used more than once with "
14377 "%<#pragma acc declare%>", decl
);
14386 if (OMP_CLAUSE_MAP_KIND (t
) == GOMP_MAP_LINK
)
14387 id
= get_identifier ("omp declare target link");
14389 id
= get_identifier ("omp declare target");
14391 DECL_ATTRIBUTES (decl
)
14392 = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (decl
));
14394 if (global_bindings_p ())
14396 symtab_node
*node
= symtab_node::get (decl
);
14399 node
->offloadable
= 1;
14400 if (ENABLE_OFFLOADING
)
14402 g
->have_offload
= true;
14403 if (is_a
<varpool_node
*> (node
))
14404 vec_safe_push (offload_vars
, decl
);
14411 if (error
|| global_bindings_p ())
14414 stmt
= make_node (OACC_DECLARE
);
14415 TREE_TYPE (stmt
) = void_type_node
;
14416 OACC_DECLARE_CLAUSES (stmt
) = clauses
;
14417 SET_EXPR_LOCATION (stmt
, pragma_loc
);
14425 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
14429 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
14432 LOC is the location of the #pragma token.
14435 #define OACC_ENTER_DATA_CLAUSE_MASK \
14436 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14437 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14438 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14439 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14440 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14441 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14442 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14444 #define OACC_EXIT_DATA_CLAUSE_MASK \
14445 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14446 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14447 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14448 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
14449 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14452 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
14454 location_t loc
= c_parser_peek_token (parser
)->location
;
14455 tree clauses
, stmt
;
14456 const char *p
= "";
14458 c_parser_consume_pragma (parser
);
14460 if (c_parser_next_token_is (parser
, CPP_NAME
))
14462 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14463 c_parser_consume_token (parser
);
14466 if (strcmp (p
, "data") != 0)
14468 error_at (loc
, "expected %<data%> after %<#pragma acc %s%>",
14469 enter
? "enter" : "exit");
14470 parser
->error
= true;
14471 c_parser_skip_to_pragma_eol (parser
);
14476 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
14477 "#pragma acc enter data");
14479 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
14480 "#pragma acc exit data");
14482 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
14484 error_at (loc
, "%<#pragma acc %s data%> has no data movement clause",
14485 enter
? "enter" : "exit");
14489 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
14490 TREE_TYPE (stmt
) = void_type_node
;
14491 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
14492 SET_EXPR_LOCATION (stmt
, loc
);
14498 # pragma acc host_data oacc-data-clause[optseq] new-line
14502 #define OACC_HOST_DATA_CLAUSE_MASK \
14503 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
14506 c_parser_oacc_host_data (location_t loc
, c_parser
*parser
, bool *if_p
)
14508 tree stmt
, clauses
, block
;
14510 clauses
= c_parser_oacc_all_clauses (parser
, OACC_HOST_DATA_CLAUSE_MASK
,
14511 "#pragma acc host_data");
14513 block
= c_begin_omp_parallel ();
14514 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14515 stmt
= c_finish_oacc_host_data (loc
, clauses
, block
);
14522 # pragma acc loop oacc-loop-clause[optseq] new-line
14525 LOC is the location of the #pragma token.
14528 #define OACC_LOOP_CLAUSE_MASK \
14529 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
14530 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14531 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14532 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14533 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14534 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14535 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
14536 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
14537 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
14538 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
14540 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
,
14541 omp_clause_mask mask
, tree
*cclauses
, bool *if_p
)
14543 bool is_parallel
= ((mask
>> PRAGMA_OACC_CLAUSE_REDUCTION
) & 1) == 1;
14545 strcat (p_name
, " loop");
14546 mask
|= OACC_LOOP_CLAUSE_MASK
;
14548 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
,
14552 clauses
= c_oacc_split_loop_clauses (clauses
, cclauses
, is_parallel
);
14554 *cclauses
= c_finish_omp_clauses (*cclauses
, C_ORT_ACC
);
14556 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14559 tree block
= c_begin_compound_stmt (true);
14560 tree stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
,
14562 block
= c_end_compound_stmt (loc
, block
, true);
14569 # pragma acc kernels oacc-kernels-clause[optseq] new-line
14574 # pragma acc parallel oacc-parallel-clause[optseq] new-line
14577 LOC is the location of the #pragma token.
14580 #define OACC_KERNELS_CLAUSE_MASK \
14581 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14582 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14583 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14584 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14585 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14586 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14587 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14588 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14589 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14590 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14591 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14592 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14593 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14594 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14595 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14596 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14597 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14599 #define OACC_PARALLEL_CLAUSE_MASK \
14600 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14601 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14602 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14603 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14604 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14605 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14606 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14607 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14608 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14609 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
14610 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14611 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14612 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14613 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14614 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14615 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14616 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14617 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14618 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14619 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14622 c_parser_oacc_kernels_parallel (location_t loc
, c_parser
*parser
,
14623 enum pragma_kind p_kind
, char *p_name
,
14626 omp_clause_mask mask
;
14627 enum tree_code code
;
14630 case PRAGMA_OACC_KERNELS
:
14631 strcat (p_name
, " kernels");
14632 mask
= OACC_KERNELS_CLAUSE_MASK
;
14633 code
= OACC_KERNELS
;
14635 case PRAGMA_OACC_PARALLEL
:
14636 strcat (p_name
, " parallel");
14637 mask
= OACC_PARALLEL_CLAUSE_MASK
;
14638 code
= OACC_PARALLEL
;
14641 gcc_unreachable ();
14644 if (c_parser_next_token_is (parser
, CPP_NAME
))
14646 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14647 if (strcmp (p
, "loop") == 0)
14649 c_parser_consume_token (parser
);
14650 tree block
= c_begin_omp_parallel ();
14652 c_parser_oacc_loop (loc
, parser
, p_name
, mask
, &clauses
, if_p
);
14653 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14657 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
);
14659 tree block
= c_begin_omp_parallel ();
14660 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14662 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14666 # pragma acc routine oacc-routine-clause[optseq] new-line
14667 function-definition
14669 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
14672 #define OACC_ROUTINE_CLAUSE_MASK \
14673 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14674 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14675 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14676 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
14678 /* Parse an OpenACC routine directive. For named directives, we apply
14679 immediately to the named function. For unnamed ones we then parse
14680 a declaration or definition, which must be for a function. */
14683 c_parser_oacc_routine (c_parser
*parser
, enum pragma_context context
)
14685 gcc_checking_assert (context
== pragma_external
);
14687 oacc_routine_data data
;
14688 data
.error_seen
= false;
14689 data
.fndecl_seen
= false;
14690 data
.clauses
= NULL_TREE
;
14691 data
.loc
= c_parser_peek_token (parser
)->location
;
14693 c_parser_consume_pragma (parser
);
14695 /* Look for optional '( name )'. */
14696 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14698 c_parser_consume_token (parser
); /* '(' */
14700 tree decl
= NULL_TREE
;
14701 c_token
*name_token
= c_parser_peek_token (parser
);
14702 location_t name_loc
= name_token
->location
;
14703 if (name_token
->type
== CPP_NAME
14704 && (name_token
->id_kind
== C_ID_ID
14705 || name_token
->id_kind
== C_ID_TYPENAME
))
14707 decl
= lookup_name (name_token
->value
);
14709 error_at (name_loc
,
14710 "%qE has not been declared", name_token
->value
);
14711 c_parser_consume_token (parser
);
14714 c_parser_error (parser
, "expected function name");
14717 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14719 c_parser_skip_to_pragma_eol (parser
, false);
14724 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
14725 "#pragma acc routine");
14727 if (TREE_CODE (decl
) != FUNCTION_DECL
)
14729 error_at (name_loc
, "%qD does not refer to a function", decl
);
14733 c_finish_oacc_routine (&data
, decl
, false);
14735 else /* No optional '( name )'. */
14738 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
14739 "#pragma acc routine");
14741 /* Emit a helpful diagnostic if there's another pragma following this
14742 one. Also don't allow a static assertion declaration, as in the
14743 following we'll just parse a *single* "declaration or function
14744 definition", and the static assertion counts an one. */
14745 if (c_parser_next_token_is (parser
, CPP_PRAGMA
)
14746 || c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
14748 error_at (data
.loc
,
14749 "%<#pragma acc routine%> not immediately followed by"
14750 " function declaration or definition");
14751 /* ..., and then just keep going. */
14755 /* We only have to consider the pragma_external case here. */
14756 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14757 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
14759 int ext
= disable_extension_diagnostics ();
14761 c_parser_consume_token (parser
);
14762 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14763 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
14764 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14765 NULL
, vNULL
, &data
);
14766 restore_extension_diagnostics (ext
);
14769 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14770 NULL
, vNULL
, &data
);
14774 /* Finalize an OpenACC routine pragma, applying it to FNDECL.
14775 IS_DEFN is true if we're applying it to the definition. */
14778 c_finish_oacc_routine (struct oacc_routine_data
*data
, tree fndecl
,
14781 /* Keep going if we're in error reporting mode. */
14782 if (data
->error_seen
14783 || fndecl
== error_mark_node
)
14786 if (data
->fndecl_seen
)
14788 error_at (data
->loc
,
14789 "%<#pragma acc routine%> not immediately followed by"
14790 " a single function declaration or definition");
14791 data
->error_seen
= true;
14794 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
14796 error_at (data
->loc
,
14797 "%<#pragma acc routine%> not immediately followed by"
14798 " function declaration or definition");
14799 data
->error_seen
= true;
14803 if (oacc_get_fn_attrib (fndecl
))
14805 error_at (data
->loc
,
14806 "%<#pragma acc routine%> already applied to %qD", fndecl
);
14807 data
->error_seen
= true;
14811 if (TREE_USED (fndecl
) || (!is_defn
&& DECL_SAVED_TREE (fndecl
)))
14813 error_at (data
->loc
,
14815 ? G_("%<#pragma acc routine%> must be applied before use")
14816 : G_("%<#pragma acc routine%> must be applied before "
14818 data
->error_seen
= true;
14822 /* Process the routine's dimension clauses. */
14823 tree dims
= oacc_build_routine_dims (data
->clauses
);
14824 oacc_replace_fn_attrib (fndecl
, dims
);
14826 /* Add an "omp declare target" attribute. */
14827 DECL_ATTRIBUTES (fndecl
)
14828 = tree_cons (get_identifier ("omp declare target"),
14829 NULL_TREE
, DECL_ATTRIBUTES (fndecl
));
14831 /* Remember that we've used this "#pragma acc routine". */
14832 data
->fndecl_seen
= true;
14836 # pragma acc update oacc-update-clause[optseq] new-line
14839 #define OACC_UPDATE_CLAUSE_MASK \
14840 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14841 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
14842 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
14843 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14844 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
14845 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14848 c_parser_oacc_update (c_parser
*parser
)
14850 location_t loc
= c_parser_peek_token (parser
)->location
;
14852 c_parser_consume_pragma (parser
);
14854 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
14855 "#pragma acc update");
14856 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
14859 "%<#pragma acc update%> must contain at least one "
14860 "%<device%> or %<host%> or %<self%> clause");
14867 tree stmt
= make_node (OACC_UPDATE
);
14868 TREE_TYPE (stmt
) = void_type_node
;
14869 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
14870 SET_EXPR_LOCATION (stmt
, loc
);
14875 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
14877 LOC is the location of the #pragma token.
14880 #define OACC_WAIT_CLAUSE_MASK \
14881 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
14884 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
14886 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
14888 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
14889 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
14891 strcpy (p_name
, " wait");
14892 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
14893 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
14900 # pragma omp atomic new-line
14904 x binop= expr | x++ | ++x | x-- | --x
14906 +, *, -, /, &, ^, |, <<, >>
14908 where x is an lvalue expression with scalar type.
14911 # pragma omp atomic new-line
14914 # pragma omp atomic read new-line
14917 # pragma omp atomic write new-line
14920 # pragma omp atomic update new-line
14923 # pragma omp atomic capture new-line
14926 # pragma omp atomic capture new-line
14934 expression-stmt | x = x binop expr
14936 v = expression-stmt
14938 { v = x; update-stmt; } | { update-stmt; v = x; }
14942 expression-stmt | x = x binop expr | x = expr binop x
14946 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
14948 where x and v are lvalue expressions with scalar type.
14950 LOC is the location of the #pragma token. */
14953 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
14955 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
14956 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
14957 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
14958 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
14959 struct c_expr expr
;
14961 bool structured_block
= false;
14962 bool swapped
= false;
14963 bool seq_cst
= false;
14966 if (c_parser_next_token_is (parser
, CPP_NAME
))
14968 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14969 if (!strcmp (p
, "seq_cst"))
14972 c_parser_consume_token (parser
);
14973 if (c_parser_next_token_is (parser
, CPP_COMMA
)
14974 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
14975 c_parser_consume_token (parser
);
14978 if (c_parser_next_token_is (parser
, CPP_NAME
))
14980 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14982 if (!strcmp (p
, "read"))
14983 code
= OMP_ATOMIC_READ
;
14984 else if (!strcmp (p
, "write"))
14986 else if (!strcmp (p
, "update"))
14988 else if (!strcmp (p
, "capture"))
14989 code
= OMP_ATOMIC_CAPTURE_NEW
;
14993 c_parser_consume_token (parser
);
14997 if (c_parser_next_token_is (parser
, CPP_COMMA
)
14998 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
14999 c_parser_consume_token (parser
);
15001 if (c_parser_next_token_is (parser
, CPP_NAME
))
15004 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15005 if (!strcmp (p
, "seq_cst"))
15008 c_parser_consume_token (parser
);
15012 c_parser_skip_to_pragma_eol (parser
);
15016 case OMP_ATOMIC_READ
:
15017 case NOP_EXPR
: /* atomic write */
15018 v
= c_parser_cast_expression (parser
, NULL
).value
;
15019 non_lvalue_p
= !lvalue_p (v
);
15020 v
= c_fully_fold (v
, false, NULL
, true);
15021 if (v
== error_mark_node
)
15024 v
= non_lvalue (v
);
15025 loc
= c_parser_peek_token (parser
)->location
;
15026 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15028 if (code
== NOP_EXPR
)
15030 lhs
= c_parser_expression (parser
).value
;
15031 lhs
= c_fully_fold (lhs
, false, NULL
);
15032 if (lhs
== error_mark_node
)
15037 lhs
= c_parser_cast_expression (parser
, NULL
).value
;
15038 non_lvalue_p
= !lvalue_p (lhs
);
15039 lhs
= c_fully_fold (lhs
, false, NULL
, true);
15040 if (lhs
== error_mark_node
)
15043 lhs
= non_lvalue (lhs
);
15045 if (code
== NOP_EXPR
)
15047 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
15055 case OMP_ATOMIC_CAPTURE_NEW
:
15056 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
15058 c_parser_consume_token (parser
);
15059 structured_block
= true;
15063 v
= c_parser_cast_expression (parser
, NULL
).value
;
15064 non_lvalue_p
= !lvalue_p (v
);
15065 v
= c_fully_fold (v
, false, NULL
, true);
15066 if (v
== error_mark_node
)
15069 v
= non_lvalue (v
);
15070 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15078 /* For structured_block case we don't know yet whether
15079 old or new x should be captured. */
15081 eloc
= c_parser_peek_token (parser
)->location
;
15082 expr
= c_parser_cast_expression (parser
, NULL
);
15084 expr
= default_function_array_conversion (eloc
, expr
);
15085 unfolded_lhs
= expr
.value
;
15086 lhs
= c_fully_fold (lhs
, false, NULL
, true);
15088 switch (TREE_CODE (lhs
))
15092 c_parser_skip_to_end_of_block_or_statement (parser
);
15093 if (structured_block
)
15095 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15096 c_parser_consume_token (parser
);
15097 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
15099 c_parser_skip_to_end_of_block_or_statement (parser
);
15100 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15101 c_parser_consume_token (parser
);
15106 case POSTINCREMENT_EXPR
:
15107 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
15108 code
= OMP_ATOMIC_CAPTURE_OLD
;
15110 case PREINCREMENT_EXPR
:
15111 lhs
= TREE_OPERAND (lhs
, 0);
15112 unfolded_lhs
= NULL_TREE
;
15113 opcode
= PLUS_EXPR
;
15114 rhs
= integer_one_node
;
15117 case POSTDECREMENT_EXPR
:
15118 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
15119 code
= OMP_ATOMIC_CAPTURE_OLD
;
15121 case PREDECREMENT_EXPR
:
15122 lhs
= TREE_OPERAND (lhs
, 0);
15123 unfolded_lhs
= NULL_TREE
;
15124 opcode
= MINUS_EXPR
;
15125 rhs
= integer_one_node
;
15128 case COMPOUND_EXPR
:
15129 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
15130 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
15131 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
15132 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
15133 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
15134 (TREE_OPERAND (lhs
, 1), 0), 0)))
15136 /* Undo effects of boolean_increment for post {in,de}crement. */
15137 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
15140 if (TREE_CODE (lhs
) == MODIFY_EXPR
15141 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
15143 /* Undo effects of boolean_increment. */
15144 if (integer_onep (TREE_OPERAND (lhs
, 1)))
15146 /* This is pre or post increment. */
15147 rhs
= TREE_OPERAND (lhs
, 1);
15148 lhs
= TREE_OPERAND (lhs
, 0);
15149 unfolded_lhs
= NULL_TREE
;
15151 if (code
== OMP_ATOMIC_CAPTURE_NEW
15152 && !structured_block
15153 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
15154 code
= OMP_ATOMIC_CAPTURE_OLD
;
15157 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
15158 && TREE_OPERAND (lhs
, 0)
15159 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
15161 /* This is pre or post decrement. */
15162 rhs
= TREE_OPERAND (lhs
, 1);
15163 lhs
= TREE_OPERAND (lhs
, 0);
15164 unfolded_lhs
= NULL_TREE
;
15166 if (code
== OMP_ATOMIC_CAPTURE_NEW
15167 && !structured_block
15168 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
15169 code
= OMP_ATOMIC_CAPTURE_OLD
;
15175 if (!lvalue_p (unfolded_lhs
))
15176 lhs
= non_lvalue (lhs
);
15177 switch (c_parser_peek_token (parser
)->type
)
15180 opcode
= MULT_EXPR
;
15183 opcode
= TRUNC_DIV_EXPR
;
15186 opcode
= PLUS_EXPR
;
15189 opcode
= MINUS_EXPR
;
15191 case CPP_LSHIFT_EQ
:
15192 opcode
= LSHIFT_EXPR
;
15194 case CPP_RSHIFT_EQ
:
15195 opcode
= RSHIFT_EXPR
;
15198 opcode
= BIT_AND_EXPR
;
15201 opcode
= BIT_IOR_EXPR
;
15204 opcode
= BIT_XOR_EXPR
;
15207 c_parser_consume_token (parser
);
15208 eloc
= c_parser_peek_token (parser
)->location
;
15209 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
15211 switch (TREE_CODE (rhs1
))
15214 case TRUNC_DIV_EXPR
:
15223 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
15225 opcode
= TREE_CODE (rhs1
);
15226 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
,
15228 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
,
15232 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
15234 opcode
= TREE_CODE (rhs1
);
15235 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
,
15237 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
,
15239 swapped
= !commutative_tree_code (opcode
);
15248 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
15250 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
15252 code
= OMP_ATOMIC_CAPTURE_OLD
;
15255 expr
= default_function_array_read_conversion (eloc
, expr
);
15256 unfolded_lhs1
= expr
.value
;
15257 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
, true);
15259 c_parser_consume_token (parser
);
15262 if (structured_block
)
15265 expr
= default_function_array_read_conversion (eloc
, expr
);
15266 rhs
= c_fully_fold (expr
.value
, false, NULL
, true);
15271 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
15274 c_parser_error (parser
,
15275 "invalid operator for %<#pragma omp atomic%>");
15279 /* Arrange to pass the location of the assignment operator to
15280 c_finish_omp_atomic. */
15281 loc
= c_parser_peek_token (parser
)->location
;
15282 c_parser_consume_token (parser
);
15283 eloc
= c_parser_peek_token (parser
)->location
;
15284 expr
= c_parser_expression (parser
);
15285 expr
= default_function_array_read_conversion (eloc
, expr
);
15287 rhs
= c_fully_fold (rhs
, false, NULL
, true);
15291 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
15293 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
15295 v
= c_parser_cast_expression (parser
, NULL
).value
;
15296 non_lvalue_p
= !lvalue_p (v
);
15297 v
= c_fully_fold (v
, false, NULL
, true);
15298 if (v
== error_mark_node
)
15301 v
= non_lvalue (v
);
15302 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
15304 eloc
= c_parser_peek_token (parser
)->location
;
15305 expr
= c_parser_cast_expression (parser
, NULL
);
15307 expr
= default_function_array_read_conversion (eloc
, expr
);
15308 unfolded_lhs1
= expr
.value
;
15309 lhs1
= c_fully_fold (lhs1
, false, NULL
, true);
15310 if (lhs1
== error_mark_node
)
15312 if (!lvalue_p (unfolded_lhs1
))
15313 lhs1
= non_lvalue (lhs1
);
15315 if (structured_block
)
15317 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15318 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
15321 if (unfolded_lhs
&& unfolded_lhs1
15322 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
15324 error ("%<#pragma omp atomic capture%> uses two different "
15325 "expressions for memory");
15326 stmt
= error_mark_node
;
15329 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
15331 if (stmt
!= error_mark_node
)
15334 if (!structured_block
)
15335 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15340 # pragma omp barrier new-line
15344 c_parser_omp_barrier (c_parser
*parser
)
15346 location_t loc
= c_parser_peek_token (parser
)->location
;
15347 c_parser_consume_pragma (parser
);
15348 c_parser_skip_to_pragma_eol (parser
);
15350 c_finish_omp_barrier (loc
);
15354 # pragma omp critical [(name)] new-line
15358 # pragma omp critical [(name) [hint(expression)]] new-line
15360 LOC is the location of the #pragma itself. */
15362 #define OMP_CRITICAL_CLAUSE_MASK \
15363 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
15366 c_parser_omp_critical (location_t loc
, c_parser
*parser
, bool *if_p
)
15368 tree stmt
, name
= NULL_TREE
, clauses
= NULL_TREE
;
15370 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
15372 c_parser_consume_token (parser
);
15373 if (c_parser_next_token_is (parser
, CPP_NAME
))
15375 name
= c_parser_peek_token (parser
)->value
;
15376 c_parser_consume_token (parser
);
15377 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
15380 c_parser_error (parser
, "expected identifier");
15382 clauses
= c_parser_omp_all_clauses (parser
,
15383 OMP_CRITICAL_CLAUSE_MASK
,
15384 "#pragma omp critical");
15388 if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15389 c_parser_error (parser
, "expected %<(%> or end of line");
15390 c_parser_skip_to_pragma_eol (parser
);
15393 stmt
= c_parser_omp_structured_block (parser
, if_p
);
15394 return c_finish_omp_critical (loc
, stmt
, name
, clauses
);
15398 # pragma omp flush flush-vars[opt] new-line
15401 ( variable-list ) */
15404 c_parser_omp_flush (c_parser
*parser
)
15406 location_t loc
= c_parser_peek_token (parser
)->location
;
15407 c_parser_consume_pragma (parser
);
15408 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
15409 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
15410 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
15411 c_parser_error (parser
, "expected %<(%> or end of line");
15412 c_parser_skip_to_pragma_eol (parser
);
15414 c_finish_omp_flush (loc
);
15417 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
15418 The real trick here is to determine the loop control variable early
15419 so that we can push a new decl if necessary to make it private.
15420 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
15424 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
15425 tree clauses
, tree
*cclauses
, bool *if_p
)
15427 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
15428 tree declv
, condv
, incrv
, initv
, ret
= NULL_TREE
;
15429 tree pre_body
= NULL_TREE
, this_pre_body
;
15430 tree ordered_cl
= NULL_TREE
;
15431 bool fail
= false, open_brace_parsed
= false;
15432 int i
, collapse
= 1, ordered
= 0, count
, nbraces
= 0;
15433 location_t for_loc
;
15434 bool tiling
= false;
15435 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
15437 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
15438 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
15439 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
15440 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_TILE
)
15443 collapse
= list_length (OMP_CLAUSE_TILE_LIST (cl
));
15445 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_ORDERED
15446 && OMP_CLAUSE_ORDERED_EXPR (cl
))
15449 ordered
= tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl
));
15452 if (ordered
&& ordered
< collapse
)
15454 error_at (OMP_CLAUSE_LOCATION (ordered_cl
),
15455 "%<ordered%> clause parameter is less than %<collapse%>");
15456 OMP_CLAUSE_ORDERED_EXPR (ordered_cl
)
15457 = build_int_cst (NULL_TREE
, collapse
);
15458 ordered
= collapse
;
15462 for (tree
*pc
= &clauses
; *pc
; )
15463 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_LINEAR
)
15465 error_at (OMP_CLAUSE_LOCATION (*pc
),
15466 "%<linear%> clause may not be specified together "
15467 "with %<ordered%> clause with a parameter");
15468 *pc
= OMP_CLAUSE_CHAIN (*pc
);
15471 pc
= &OMP_CLAUSE_CHAIN (*pc
);
15474 gcc_assert (tiling
|| (collapse
>= 1 && ordered
>= 0));
15475 count
= ordered
? ordered
: collapse
;
15477 declv
= make_tree_vec (count
);
15478 initv
= make_tree_vec (count
);
15479 condv
= make_tree_vec (count
);
15480 incrv
= make_tree_vec (count
);
15482 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
))
15484 c_parser_error (parser
, "for statement expected");
15487 for_loc
= c_parser_peek_token (parser
)->location
;
15488 c_parser_consume_token (parser
);
15490 for (i
= 0; i
< count
; i
++)
15492 int bracecount
= 0;
15494 matching_parens parens
;
15495 if (!parens
.require_open (parser
))
15498 /* Parse the initialization declaration or expression. */
15499 if (c_parser_next_tokens_start_declaration (parser
))
15502 vec_safe_push (for_block
, c_begin_compound_stmt (true));
15503 this_pre_body
= push_stmt_list ();
15504 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
15508 this_pre_body
= pop_stmt_list (this_pre_body
);
15512 pre_body
= push_stmt_list ();
15514 add_stmt (this_pre_body
);
15515 pre_body
= pop_stmt_list (pre_body
);
15518 pre_body
= this_pre_body
;
15520 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
15523 if (DECL_INITIAL (decl
) == error_mark_node
)
15524 decl
= error_mark_node
;
15527 else if (c_parser_next_token_is (parser
, CPP_NAME
)
15528 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
15530 struct c_expr decl_exp
;
15531 struct c_expr init_exp
;
15532 location_t init_loc
;
15534 decl_exp
= c_parser_postfix_expression (parser
);
15535 decl
= decl_exp
.value
;
15537 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
15539 init_loc
= c_parser_peek_token (parser
)->location
;
15540 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
15541 init_exp
= default_function_array_read_conversion (init_loc
,
15543 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
15544 NOP_EXPR
, init_loc
, init_exp
.value
,
15545 init_exp
.original_type
);
15546 init
= c_process_expr_stmt (init_loc
, init
);
15548 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15553 c_parser_error (parser
,
15554 "expected iteration declaration or initialization");
15555 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
15561 /* Parse the loop condition. */
15563 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
15565 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
15566 struct c_expr cond_expr
15567 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
15569 cond
= cond_expr
.value
;
15570 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
15571 if (COMPARISON_CLASS_P (cond
))
15573 tree op0
= TREE_OPERAND (cond
, 0), op1
= TREE_OPERAND (cond
, 1);
15574 op0
= c_fully_fold (op0
, false, NULL
);
15575 op1
= c_fully_fold (op1
, false, NULL
);
15576 TREE_OPERAND (cond
, 0) = op0
;
15577 TREE_OPERAND (cond
, 1) = op1
;
15579 switch (cond_expr
.original_code
)
15587 /* Can't be cond = error_mark_node, because we want to preserve
15588 the location until c_finish_omp_for. */
15589 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
15592 protected_set_expr_location (cond
, cond_loc
);
15594 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15596 /* Parse the increment expression. */
15598 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
15600 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
15602 incr
= c_process_expr_stmt (incr_loc
,
15603 c_parser_expression (parser
).value
);
15605 parens
.skip_until_found_close (parser
);
15607 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
15611 TREE_VEC_ELT (declv
, i
) = decl
;
15612 TREE_VEC_ELT (initv
, i
) = init
;
15613 TREE_VEC_ELT (condv
, i
) = cond
;
15614 TREE_VEC_ELT (incrv
, i
) = incr
;
15618 if (i
== count
- 1)
15621 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
15622 in between the collapsed for loops to be still considered perfectly
15623 nested. Hopefully the final version clarifies this.
15624 For now handle (multiple) {'s and empty statements. */
15627 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
15629 c_parser_consume_token (parser
);
15632 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
15634 c_parser_consume_token (parser
);
15637 else if (bracecount
15638 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15639 c_parser_consume_token (parser
);
15642 c_parser_error (parser
, "not enough perfectly nested loops");
15645 open_brace_parsed
= true;
15655 nbraces
+= bracecount
;
15661 save_break
= c_break_label
;
15662 c_break_label
= size_one_node
;
15663 save_cont
= c_cont_label
;
15664 c_cont_label
= NULL_TREE
;
15665 body
= push_stmt_list ();
15667 if (open_brace_parsed
)
15669 location_t here
= c_parser_peek_token (parser
)->location
;
15670 stmt
= c_begin_compound_stmt (true);
15671 c_parser_compound_statement_nostart (parser
);
15672 add_stmt (c_end_compound_stmt (here
, stmt
, true));
15675 add_stmt (c_parser_c99_block_statement (parser
, if_p
));
15678 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
15679 SET_EXPR_LOCATION (t
, loc
);
15683 body
= pop_stmt_list (body
);
15684 c_break_label
= save_break
;
15685 c_cont_label
= save_cont
;
15689 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15691 c_parser_consume_token (parser
);
15694 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15695 c_parser_consume_token (parser
);
15698 c_parser_error (parser
, "collapsed loops not perfectly nested");
15701 location_t here
= c_parser_peek_token (parser
)->location
;
15702 stmt
= c_begin_compound_stmt (true);
15704 c_parser_compound_statement_nostart (parser
);
15705 body
= c_end_compound_stmt (here
, stmt
, true);
15712 /* Only bother calling c_finish_omp_for if we haven't already generated
15713 an error from the initialization parsing. */
15716 stmt
= c_finish_omp_for (loc
, code
, declv
, NULL
, initv
, condv
,
15717 incrv
, body
, pre_body
);
15719 /* Check for iterators appearing in lb, b or incr expressions. */
15720 if (stmt
&& !c_omp_check_loop_iv (stmt
, declv
, NULL
))
15727 if (cclauses
!= NULL
15728 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
15731 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
15732 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
15733 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
15734 c
= &OMP_CLAUSE_CHAIN (*c
);
15737 for (i
= 0; i
< count
; i
++)
15738 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
15741 c
= &OMP_CLAUSE_CHAIN (*c
);
15742 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
15745 "iteration variable %qD should not be firstprivate",
15746 OMP_CLAUSE_DECL (*c
));
15747 *c
= OMP_CLAUSE_CHAIN (*c
);
15751 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
15753 *c
= OMP_CLAUSE_CHAIN (*c
);
15754 if (code
== OMP_SIMD
)
15756 OMP_CLAUSE_CHAIN (l
)
15757 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15758 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
15762 OMP_CLAUSE_CHAIN (l
) = clauses
;
15768 OMP_FOR_CLAUSES (stmt
) = clauses
;
15773 while (!for_block
->is_empty ())
15775 /* FIXME diagnostics: LOC below should be the actual location of
15776 this particular for block. We need to build a list of
15777 locations to go along with FOR_BLOCK. */
15778 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
15781 release_tree_vector (for_block
);
15785 /* Helper function for OpenMP parsing, split clauses and call
15786 finish_omp_clauses on each of the set of clauses afterwards. */
15789 omp_split_clauses (location_t loc
, enum tree_code code
,
15790 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
15793 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
15794 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
15796 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
], C_ORT_OMP
);
15800 #pragma omp simd simd-clause[optseq] new-line
15803 LOC is the location of the #pragma token.
15806 #define OMP_SIMD_CLAUSE_MASK \
15807 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
15808 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
15809 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15810 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
15811 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15812 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15813 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15814 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15817 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
15818 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15821 tree block
, clauses
, ret
;
15823 strcat (p_name
, " simd");
15824 mask
|= OMP_SIMD_CLAUSE_MASK
;
15826 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15829 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
15830 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
15831 tree c
= omp_find_clause (cclauses
[C_OMP_CLAUSE_SPLIT_FOR
],
15832 OMP_CLAUSE_ORDERED
);
15833 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
15835 error_at (OMP_CLAUSE_LOCATION (c
),
15836 "%<ordered%> clause with parameter may not be specified "
15837 "on %qs construct", p_name
);
15838 OMP_CLAUSE_ORDERED_EXPR (c
) = NULL_TREE
;
15842 block
= c_begin_compound_stmt (true);
15843 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
, if_p
);
15844 block
= c_end_compound_stmt (loc
, block
, true);
15851 #pragma omp for for-clause[optseq] new-line
15855 #pragma omp for simd for-simd-clause[optseq] new-line
15858 LOC is the location of the #pragma token.
15861 #define OMP_FOR_CLAUSE_MASK \
15862 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15863 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15864 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15865 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15866 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15867 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
15868 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
15869 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
15870 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15873 c_parser_omp_for (location_t loc
, c_parser
*parser
,
15874 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15877 tree block
, clauses
, ret
;
15879 strcat (p_name
, " for");
15880 mask
|= OMP_FOR_CLAUSE_MASK
;
15881 /* parallel for{, simd} disallows nowait clause, but for
15882 target {teams distribute ,}parallel for{, simd} it should be accepted. */
15883 if (cclauses
&& (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) == 0)
15884 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
15885 /* Composite distribute parallel for{, simd} disallows ordered clause. */
15886 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15887 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
15889 if (c_parser_next_token_is (parser
, CPP_NAME
))
15891 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15893 if (strcmp (p
, "simd") == 0)
15895 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15896 if (cclauses
== NULL
)
15897 cclauses
= cclauses_buf
;
15899 c_parser_consume_token (parser
);
15900 if (!flag_openmp
) /* flag_openmp_simd */
15901 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
15903 block
= c_begin_compound_stmt (true);
15904 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15905 block
= c_end_compound_stmt (loc
, block
, true);
15906 if (ret
== NULL_TREE
)
15908 ret
= make_node (OMP_FOR
);
15909 TREE_TYPE (ret
) = void_type_node
;
15910 OMP_FOR_BODY (ret
) = block
;
15911 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15912 SET_EXPR_LOCATION (ret
, loc
);
15917 if (!flag_openmp
) /* flag_openmp_simd */
15919 c_parser_skip_to_pragma_eol (parser
, false);
15923 /* Composite distribute parallel for disallows linear clause. */
15924 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15925 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINEAR
);
15927 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15930 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
15931 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15934 block
= c_begin_compound_stmt (true);
15935 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
, if_p
);
15936 block
= c_end_compound_stmt (loc
, block
, true);
15943 # pragma omp master new-line
15946 LOC is the location of the #pragma token.
15950 c_parser_omp_master (location_t loc
, c_parser
*parser
, bool *if_p
)
15952 c_parser_skip_to_pragma_eol (parser
);
15953 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
,
15958 # pragma omp ordered new-line
15962 # pragma omp ordered ordered-clauses new-line
15965 # pragma omp ordered depend-clauses new-line */
15967 #define OMP_ORDERED_CLAUSE_MASK \
15968 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
15969 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
15971 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
15972 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
15975 c_parser_omp_ordered (c_parser
*parser
, enum pragma_context context
,
15978 location_t loc
= c_parser_peek_token (parser
)->location
;
15979 c_parser_consume_pragma (parser
);
15981 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
15983 c_parser_error (parser
, "expected declaration specifiers");
15984 c_parser_skip_to_pragma_eol (parser
, false);
15988 if (c_parser_next_token_is (parser
, CPP_NAME
))
15990 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15992 if (!strcmp ("depend", p
))
15994 if (!flag_openmp
) /* flag_openmp_simd */
15996 c_parser_skip_to_pragma_eol (parser
, false);
15999 if (context
== pragma_stmt
)
16002 "%<#pragma omp ordered%> with %<depend%> clause may "
16003 "only be used in compound statements");
16004 c_parser_skip_to_pragma_eol (parser
, false);
16009 = c_parser_omp_all_clauses (parser
,
16010 OMP_ORDERED_DEPEND_CLAUSE_MASK
,
16011 "#pragma omp ordered");
16012 c_finish_omp_ordered (loc
, clauses
, NULL_TREE
);
16017 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_ORDERED_CLAUSE_MASK
,
16018 "#pragma omp ordered");
16020 if (!flag_openmp
/* flag_openmp_simd */
16021 && omp_find_clause (clauses
, OMP_CLAUSE_SIMD
) == NULL_TREE
)
16024 c_finish_omp_ordered (loc
, clauses
,
16025 c_parser_omp_structured_block (parser
, if_p
));
16032 { section-sequence }
16035 section-directive[opt] structured-block
16036 section-sequence section-directive structured-block
16038 SECTIONS_LOC is the location of the #pragma omp sections. */
16041 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
16043 tree stmt
, substmt
;
16044 bool error_suppress
= false;
16047 loc
= c_parser_peek_token (parser
)->location
;
16048 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
16050 /* Avoid skipping until the end of the block. */
16051 parser
->error
= false;
16055 stmt
= push_stmt_list ();
16057 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
16059 substmt
= c_parser_omp_structured_block (parser
, NULL
);
16060 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
16061 SET_EXPR_LOCATION (substmt
, loc
);
16062 add_stmt (substmt
);
16067 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
16069 if (c_parser_next_token_is (parser
, CPP_EOF
))
16072 loc
= c_parser_peek_token (parser
)->location
;
16073 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
16075 c_parser_consume_pragma (parser
);
16076 c_parser_skip_to_pragma_eol (parser
);
16077 error_suppress
= false;
16079 else if (!error_suppress
)
16081 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
16082 error_suppress
= true;
16085 substmt
= c_parser_omp_structured_block (parser
, NULL
);
16086 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
16087 SET_EXPR_LOCATION (substmt
, loc
);
16088 add_stmt (substmt
);
16090 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
16091 "expected %<#pragma omp section%> or %<}%>");
16093 substmt
= pop_stmt_list (stmt
);
16095 stmt
= make_node (OMP_SECTIONS
);
16096 SET_EXPR_LOCATION (stmt
, sections_loc
);
16097 TREE_TYPE (stmt
) = void_type_node
;
16098 OMP_SECTIONS_BODY (stmt
) = substmt
;
16100 return add_stmt (stmt
);
16104 # pragma omp sections sections-clause[optseq] newline
16107 LOC is the location of the #pragma token.
16110 #define OMP_SECTIONS_CLAUSE_MASK \
16111 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16112 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16113 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16114 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16115 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16118 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
16119 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
16121 tree block
, clauses
, ret
;
16123 strcat (p_name
, " sections");
16124 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
16126 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
16128 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16131 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
16132 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
16135 block
= c_begin_compound_stmt (true);
16136 ret
= c_parser_omp_sections_scope (loc
, parser
);
16138 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
16139 block
= c_end_compound_stmt (loc
, block
, true);
16146 # pragma omp parallel parallel-clause[optseq] new-line
16148 # pragma omp parallel for parallel-for-clause[optseq] new-line
16150 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
16154 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
16157 LOC is the location of the #pragma token.
16160 #define OMP_PARALLEL_CLAUSE_MASK \
16161 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16162 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16163 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16164 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
16165 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16166 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
16167 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16168 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
16169 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
16172 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
16173 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16176 tree stmt
, clauses
, block
;
16178 strcat (p_name
, " parallel");
16179 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
16180 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
16181 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) != 0
16182 && (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) == 0)
16183 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_COPYIN
);
16185 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
16187 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16188 if (cclauses
== NULL
)
16189 cclauses
= cclauses_buf
;
16191 c_parser_consume_token (parser
);
16192 if (!flag_openmp
) /* flag_openmp_simd */
16193 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
16194 block
= c_begin_omp_parallel ();
16195 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
16197 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
16199 if (ret
== NULL_TREE
)
16201 OMP_PARALLEL_COMBINED (stmt
) = 1;
16204 /* When combined with distribute, parallel has to be followed by for.
16205 #pragma omp target parallel is allowed though. */
16207 && (mask
& (OMP_CLAUSE_MASK_1
16208 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
16210 error_at (loc
, "expected %<for%> after %qs", p_name
);
16211 c_parser_skip_to_pragma_eol (parser
);
16214 else if (!flag_openmp
) /* flag_openmp_simd */
16216 c_parser_skip_to_pragma_eol (parser
, false);
16219 else if (cclauses
== NULL
&& c_parser_next_token_is (parser
, CPP_NAME
))
16221 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16222 if (strcmp (p
, "sections") == 0)
16224 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16225 if (cclauses
== NULL
)
16226 cclauses
= cclauses_buf
;
16228 c_parser_consume_token (parser
);
16229 block
= c_begin_omp_parallel ();
16230 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
16231 stmt
= c_finish_omp_parallel (loc
,
16232 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
16234 OMP_PARALLEL_COMBINED (stmt
) = 1;
16239 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16242 omp_split_clauses (loc
, OMP_PARALLEL
, mask
, clauses
, cclauses
);
16243 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
16246 block
= c_begin_omp_parallel ();
16247 c_parser_statement (parser
, if_p
);
16248 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
16254 # pragma omp single single-clause[optseq] new-line
16257 LOC is the location of the #pragma.
16260 #define OMP_SINGLE_CLAUSE_MASK \
16261 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16262 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16263 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
16264 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16267 c_parser_omp_single (location_t loc
, c_parser
*parser
, bool *if_p
)
16269 tree stmt
= make_node (OMP_SINGLE
);
16270 SET_EXPR_LOCATION (stmt
, loc
);
16271 TREE_TYPE (stmt
) = void_type_node
;
16273 OMP_SINGLE_CLAUSES (stmt
)
16274 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
16275 "#pragma omp single");
16276 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
16278 return add_stmt (stmt
);
16282 # pragma omp task task-clause[optseq] new-line
16284 LOC is the location of the #pragma.
16287 #define OMP_TASK_CLAUSE_MASK \
16288 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16289 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
16290 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
16291 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16292 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16293 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16294 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
16295 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
16296 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16297 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
16300 c_parser_omp_task (location_t loc
, c_parser
*parser
, bool *if_p
)
16302 tree clauses
, block
;
16304 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
16305 "#pragma omp task");
16307 block
= c_begin_omp_task ();
16308 c_parser_statement (parser
, if_p
);
16309 return c_finish_omp_task (loc
, clauses
, block
);
16313 # pragma omp taskwait new-line
16317 c_parser_omp_taskwait (c_parser
*parser
)
16319 location_t loc
= c_parser_peek_token (parser
)->location
;
16320 c_parser_consume_pragma (parser
);
16321 c_parser_skip_to_pragma_eol (parser
);
16323 c_finish_omp_taskwait (loc
);
16327 # pragma omp taskyield new-line
16331 c_parser_omp_taskyield (c_parser
*parser
)
16333 location_t loc
= c_parser_peek_token (parser
)->location
;
16334 c_parser_consume_pragma (parser
);
16335 c_parser_skip_to_pragma_eol (parser
);
16337 c_finish_omp_taskyield (loc
);
16341 # pragma omp taskgroup new-line
16345 c_parser_omp_taskgroup (c_parser
*parser
, bool *if_p
)
16347 location_t loc
= c_parser_peek_token (parser
)->location
;
16348 c_parser_skip_to_pragma_eol (parser
);
16349 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
,
16354 # pragma omp cancel cancel-clause[optseq] new-line
16356 LOC is the location of the #pragma.
16359 #define OMP_CANCEL_CLAUSE_MASK \
16360 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
16361 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
16362 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
16363 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
16364 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
16367 c_parser_omp_cancel (c_parser
*parser
)
16369 location_t loc
= c_parser_peek_token (parser
)->location
;
16371 c_parser_consume_pragma (parser
);
16372 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
16373 "#pragma omp cancel");
16375 c_finish_omp_cancel (loc
, clauses
);
16379 # pragma omp cancellation point cancelpt-clause[optseq] new-line
16381 LOC is the location of the #pragma.
16384 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
16385 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
16386 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
16387 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
16388 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
16391 c_parser_omp_cancellation_point (c_parser
*parser
, enum pragma_context context
)
16393 location_t loc
= c_parser_peek_token (parser
)->location
;
16395 bool point_seen
= false;
16397 c_parser_consume_pragma (parser
);
16398 if (c_parser_next_token_is (parser
, CPP_NAME
))
16400 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16401 if (strcmp (p
, "point") == 0)
16403 c_parser_consume_token (parser
);
16409 c_parser_error (parser
, "expected %<point%>");
16410 c_parser_skip_to_pragma_eol (parser
);
16414 if (context
!= pragma_compound
)
16416 if (context
== pragma_stmt
)
16418 "%<#pragma %s%> may only be used in compound statements",
16419 "omp cancellation point");
16421 c_parser_error (parser
, "expected declaration specifiers");
16422 c_parser_skip_to_pragma_eol (parser
, false);
16427 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
16428 "#pragma omp cancellation point");
16430 c_finish_omp_cancellation_point (loc
, clauses
);
16434 #pragma omp distribute distribute-clause[optseq] new-line
16437 #define OMP_DISTRIBUTE_CLAUSE_MASK \
16438 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16439 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16440 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
16441 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
16442 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
16445 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
16446 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16449 tree clauses
, block
, ret
;
16451 strcat (p_name
, " distribute");
16452 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
16454 if (c_parser_next_token_is (parser
, CPP_NAME
))
16456 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16458 bool parallel
= false;
16460 if (strcmp (p
, "simd") == 0)
16463 parallel
= strcmp (p
, "parallel") == 0;
16464 if (parallel
|| simd
)
16466 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16467 if (cclauses
== NULL
)
16468 cclauses
= cclauses_buf
;
16469 c_parser_consume_token (parser
);
16470 if (!flag_openmp
) /* flag_openmp_simd */
16473 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16476 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
16479 block
= c_begin_compound_stmt (true);
16481 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
16484 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
,
16486 block
= c_end_compound_stmt (loc
, block
, true);
16489 ret
= make_node (OMP_DISTRIBUTE
);
16490 TREE_TYPE (ret
) = void_type_node
;
16491 OMP_FOR_BODY (ret
) = block
;
16492 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
16493 SET_EXPR_LOCATION (ret
, loc
);
16498 if (!flag_openmp
) /* flag_openmp_simd */
16500 c_parser_skip_to_pragma_eol (parser
, false);
16504 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16507 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
16508 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
16511 block
= c_begin_compound_stmt (true);
16512 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
,
16514 block
= c_end_compound_stmt (loc
, block
, true);
16521 # pragma omp teams teams-clause[optseq] new-line
16522 structured-block */
16524 #define OMP_TEAMS_CLAUSE_MASK \
16525 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16526 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16527 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
16528 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
16529 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
16530 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
16531 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
16534 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
16535 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
16538 tree clauses
, block
, ret
;
16540 strcat (p_name
, " teams");
16541 mask
|= OMP_TEAMS_CLAUSE_MASK
;
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
, "distribute") == 0)
16548 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
16549 if (cclauses
== NULL
)
16550 cclauses
= cclauses_buf
;
16552 c_parser_consume_token (parser
);
16553 if (!flag_openmp
) /* flag_openmp_simd */
16554 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
,
16556 block
= c_begin_compound_stmt (true);
16557 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
,
16559 block
= c_end_compound_stmt (loc
, block
, true);
16562 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16563 ret
= make_node (OMP_TEAMS
);
16564 TREE_TYPE (ret
) = void_type_node
;
16565 OMP_TEAMS_CLAUSES (ret
) = clauses
;
16566 OMP_TEAMS_BODY (ret
) = block
;
16567 OMP_TEAMS_COMBINED (ret
) = 1;
16568 return add_stmt (ret
);
16571 if (!flag_openmp
) /* flag_openmp_simd */
16573 c_parser_skip_to_pragma_eol (parser
, false);
16577 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16580 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
16581 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16584 tree stmt
= make_node (OMP_TEAMS
);
16585 TREE_TYPE (stmt
) = void_type_node
;
16586 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
16587 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
16589 return add_stmt (stmt
);
16593 # pragma omp target data target-data-clause[optseq] new-line
16594 structured-block */
16596 #define OMP_TARGET_DATA_CLAUSE_MASK \
16597 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16598 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16599 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16600 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
16603 c_parser_omp_target_data (location_t loc
, c_parser
*parser
, bool *if_p
)
16606 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
16607 "#pragma omp target data");
16609 for (tree
*pc
= &clauses
; *pc
;)
16611 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16612 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16615 case GOMP_MAP_ALWAYS_TO
:
16616 case GOMP_MAP_FROM
:
16617 case GOMP_MAP_ALWAYS_FROM
:
16618 case GOMP_MAP_TOFROM
:
16619 case GOMP_MAP_ALWAYS_TOFROM
:
16620 case GOMP_MAP_ALLOC
:
16623 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16624 case GOMP_MAP_ALWAYS_POINTER
:
16628 error_at (OMP_CLAUSE_LOCATION (*pc
),
16629 "%<#pragma omp target data%> with map-type other "
16630 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16631 "on %<map%> clause");
16632 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16635 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16642 "%<#pragma omp target data%> must contain at least "
16643 "one %<map%> clause");
16647 tree stmt
= make_node (OMP_TARGET_DATA
);
16648 TREE_TYPE (stmt
) = void_type_node
;
16649 OMP_TARGET_DATA_CLAUSES (stmt
) = clauses
;
16650 keep_next_level ();
16651 tree block
= c_begin_compound_stmt (true);
16652 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
16653 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
16655 SET_EXPR_LOCATION (stmt
, loc
);
16656 return add_stmt (stmt
);
16660 # pragma omp target update target-update-clause[optseq] new-line */
16662 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
16663 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
16664 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16665 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16666 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16667 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16668 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16671 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
16672 enum pragma_context context
)
16674 if (context
== pragma_stmt
)
16676 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
16677 "omp target update");
16678 c_parser_skip_to_pragma_eol (parser
, false);
16683 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
16684 "#pragma omp target update");
16685 if (omp_find_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
16686 && omp_find_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
16689 "%<#pragma omp target update%> must contain at least one "
16690 "%<from%> or %<to%> clauses");
16694 tree stmt
= make_node (OMP_TARGET_UPDATE
);
16695 TREE_TYPE (stmt
) = void_type_node
;
16696 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
16697 SET_EXPR_LOCATION (stmt
, loc
);
16703 # pragma omp target enter data target-data-clause[optseq] new-line */
16705 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
16706 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16707 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16708 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16709 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16710 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16713 c_parser_omp_target_enter_data (location_t loc
, c_parser
*parser
,
16714 enum pragma_context context
)
16716 bool data_seen
= false;
16717 if (c_parser_next_token_is (parser
, CPP_NAME
))
16719 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16720 if (strcmp (p
, "data") == 0)
16722 c_parser_consume_token (parser
);
16728 c_parser_error (parser
, "expected %<data%>");
16729 c_parser_skip_to_pragma_eol (parser
);
16733 if (context
== pragma_stmt
)
16735 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
16736 "omp target enter data");
16737 c_parser_skip_to_pragma_eol (parser
, false);
16742 = c_parser_omp_all_clauses (parser
, OMP_TARGET_ENTER_DATA_CLAUSE_MASK
,
16743 "#pragma omp target enter data");
16745 for (tree
*pc
= &clauses
; *pc
;)
16747 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16748 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16751 case GOMP_MAP_ALWAYS_TO
:
16752 case GOMP_MAP_ALLOC
:
16755 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16756 case GOMP_MAP_ALWAYS_POINTER
:
16760 error_at (OMP_CLAUSE_LOCATION (*pc
),
16761 "%<#pragma omp target enter data%> with map-type other "
16762 "than %<to%> or %<alloc%> on %<map%> clause");
16763 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16766 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16773 "%<#pragma omp target enter data%> must contain at least "
16774 "one %<map%> clause");
16778 tree stmt
= make_node (OMP_TARGET_ENTER_DATA
);
16779 TREE_TYPE (stmt
) = void_type_node
;
16780 OMP_TARGET_ENTER_DATA_CLAUSES (stmt
) = clauses
;
16781 SET_EXPR_LOCATION (stmt
, loc
);
16787 # pragma omp target exit data target-data-clause[optseq] new-line */
16789 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
16790 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16791 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16792 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16793 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16794 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16797 c_parser_omp_target_exit_data (location_t loc
, c_parser
*parser
,
16798 enum pragma_context context
)
16800 bool data_seen
= false;
16801 if (c_parser_next_token_is (parser
, CPP_NAME
))
16803 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16804 if (strcmp (p
, "data") == 0)
16806 c_parser_consume_token (parser
);
16812 c_parser_error (parser
, "expected %<data%>");
16813 c_parser_skip_to_pragma_eol (parser
);
16817 if (context
== pragma_stmt
)
16819 error_at (loc
, "%<#pragma %s%> may only be used in compound statements",
16820 "omp target exit data");
16821 c_parser_skip_to_pragma_eol (parser
, false);
16826 = c_parser_omp_all_clauses (parser
, OMP_TARGET_EXIT_DATA_CLAUSE_MASK
,
16827 "#pragma omp target exit data");
16830 for (tree
*pc
= &clauses
; *pc
;)
16832 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16833 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16835 case GOMP_MAP_FROM
:
16836 case GOMP_MAP_ALWAYS_FROM
:
16837 case GOMP_MAP_RELEASE
:
16838 case GOMP_MAP_DELETE
:
16841 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16842 case GOMP_MAP_ALWAYS_POINTER
:
16846 error_at (OMP_CLAUSE_LOCATION (*pc
),
16847 "%<#pragma omp target exit data%> with map-type other "
16848 "than %<from%>, %<release%> or %<delete%> on %<map%>"
16850 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16853 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16860 "%<#pragma omp target exit data%> must contain at least one "
16865 tree stmt
= make_node (OMP_TARGET_EXIT_DATA
);
16866 TREE_TYPE (stmt
) = void_type_node
;
16867 OMP_TARGET_EXIT_DATA_CLAUSES (stmt
) = clauses
;
16868 SET_EXPR_LOCATION (stmt
, loc
);
16874 # pragma omp target target-clause[optseq] new-line
16875 structured-block */
16877 #define OMP_TARGET_CLAUSE_MASK \
16878 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16879 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16880 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16881 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16882 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
16883 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16884 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16885 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
16886 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
16889 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
16891 location_t loc
= c_parser_peek_token (parser
)->location
;
16892 c_parser_consume_pragma (parser
);
16893 tree
*pc
= NULL
, stmt
, block
;
16895 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
16897 c_parser_error (parser
, "expected declaration specifiers");
16898 c_parser_skip_to_pragma_eol (parser
);
16902 if (c_parser_next_token_is (parser
, CPP_NAME
))
16904 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16905 enum tree_code ccode
= ERROR_MARK
;
16907 if (strcmp (p
, "teams") == 0)
16909 else if (strcmp (p
, "parallel") == 0)
16910 ccode
= OMP_PARALLEL
;
16911 else if (strcmp (p
, "simd") == 0)
16913 if (ccode
!= ERROR_MARK
)
16915 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
16916 char p_name
[sizeof ("#pragma omp target teams distribute "
16917 "parallel for simd")];
16919 c_parser_consume_token (parser
);
16920 strcpy (p_name
, "#pragma omp target");
16921 if (!flag_openmp
) /* flag_openmp_simd */
16927 stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
16928 OMP_TARGET_CLAUSE_MASK
,
16932 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
,
16933 OMP_TARGET_CLAUSE_MASK
,
16937 stmt
= c_parser_omp_simd (loc
, parser
, p_name
,
16938 OMP_TARGET_CLAUSE_MASK
,
16942 gcc_unreachable ();
16944 return stmt
!= NULL_TREE
;
16946 keep_next_level ();
16947 tree block
= c_begin_compound_stmt (true), ret
;
16951 ret
= c_parser_omp_teams (loc
, parser
, p_name
,
16952 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16956 ret
= c_parser_omp_parallel (loc
, parser
, p_name
,
16957 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16961 ret
= c_parser_omp_simd (loc
, parser
, p_name
,
16962 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16966 gcc_unreachable ();
16968 block
= c_end_compound_stmt (loc
, block
, true);
16969 if (ret
== NULL_TREE
)
16971 if (ccode
== OMP_TEAMS
)
16973 /* For combined target teams, ensure the num_teams and
16974 thread_limit clause expressions are evaluated on the host,
16975 before entering the target construct. */
16977 for (c
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16978 c
; c
= OMP_CLAUSE_CHAIN (c
))
16979 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
16980 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
16981 && TREE_CODE (OMP_CLAUSE_OPERAND (c
, 0)) != INTEGER_CST
)
16983 tree expr
= OMP_CLAUSE_OPERAND (c
, 0);
16984 tree tmp
= create_tmp_var_raw (TREE_TYPE (expr
));
16985 expr
= build4 (TARGET_EXPR
, TREE_TYPE (expr
), tmp
,
16986 expr
, NULL_TREE
, NULL_TREE
);
16988 OMP_CLAUSE_OPERAND (c
, 0) = expr
;
16989 tree tc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
16990 OMP_CLAUSE_FIRSTPRIVATE
);
16991 OMP_CLAUSE_DECL (tc
) = tmp
;
16992 OMP_CLAUSE_CHAIN (tc
)
16993 = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
16994 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = tc
;
16997 tree stmt
= make_node (OMP_TARGET
);
16998 TREE_TYPE (stmt
) = void_type_node
;
16999 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
17000 OMP_TARGET_BODY (stmt
) = block
;
17001 OMP_TARGET_COMBINED (stmt
) = 1;
17003 pc
= &OMP_TARGET_CLAUSES (stmt
);
17004 goto check_clauses
;
17006 else if (!flag_openmp
) /* flag_openmp_simd */
17008 c_parser_skip_to_pragma_eol (parser
, false);
17011 else if (strcmp (p
, "data") == 0)
17013 c_parser_consume_token (parser
);
17014 c_parser_omp_target_data (loc
, parser
, if_p
);
17017 else if (strcmp (p
, "enter") == 0)
17019 c_parser_consume_token (parser
);
17020 c_parser_omp_target_enter_data (loc
, parser
, context
);
17023 else if (strcmp (p
, "exit") == 0)
17025 c_parser_consume_token (parser
);
17026 c_parser_omp_target_exit_data (loc
, parser
, context
);
17029 else if (strcmp (p
, "update") == 0)
17031 c_parser_consume_token (parser
);
17032 return c_parser_omp_target_update (loc
, parser
, context
);
17035 if (!flag_openmp
) /* flag_openmp_simd */
17037 c_parser_skip_to_pragma_eol (parser
, false);
17041 stmt
= make_node (OMP_TARGET
);
17042 TREE_TYPE (stmt
) = void_type_node
;
17044 OMP_TARGET_CLAUSES (stmt
)
17045 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
17046 "#pragma omp target");
17047 pc
= &OMP_TARGET_CLAUSES (stmt
);
17048 keep_next_level ();
17049 block
= c_begin_compound_stmt (true);
17050 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
17051 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
17053 SET_EXPR_LOCATION (stmt
, loc
);
17059 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
17060 switch (OMP_CLAUSE_MAP_KIND (*pc
))
17063 case GOMP_MAP_ALWAYS_TO
:
17064 case GOMP_MAP_FROM
:
17065 case GOMP_MAP_ALWAYS_FROM
:
17066 case GOMP_MAP_TOFROM
:
17067 case GOMP_MAP_ALWAYS_TOFROM
:
17068 case GOMP_MAP_ALLOC
:
17069 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
17070 case GOMP_MAP_ALWAYS_POINTER
:
17073 error_at (OMP_CLAUSE_LOCATION (*pc
),
17074 "%<#pragma omp target%> with map-type other "
17075 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
17076 "on %<map%> clause");
17077 *pc
= OMP_CLAUSE_CHAIN (*pc
);
17080 pc
= &OMP_CLAUSE_CHAIN (*pc
);
17086 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
17088 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
17089 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
17090 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
17091 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
17092 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
17093 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
17094 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
17097 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
17099 auto_vec
<c_token
> clauses
;
17100 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17102 c_token
*token
= c_parser_peek_token (parser
);
17103 if (token
->type
== CPP_EOF
)
17105 c_parser_skip_to_pragma_eol (parser
);
17108 clauses
.safe_push (*token
);
17109 c_parser_consume_token (parser
);
17111 clauses
.safe_push (*c_parser_peek_token (parser
));
17112 c_parser_skip_to_pragma_eol (parser
);
17114 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
17116 if (c_parser_peek_token (parser
)->pragma_kind
17117 != PRAGMA_OMP_DECLARE
17118 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
17119 || strcmp (IDENTIFIER_POINTER
17120 (c_parser_peek_2nd_token (parser
)->value
),
17123 c_parser_error (parser
,
17124 "%<#pragma omp declare simd%> must be followed by "
17125 "function declaration or definition or another "
17126 "%<#pragma omp declare simd%>");
17129 c_parser_consume_pragma (parser
);
17130 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17132 c_token
*token
= c_parser_peek_token (parser
);
17133 if (token
->type
== CPP_EOF
)
17135 c_parser_skip_to_pragma_eol (parser
);
17138 clauses
.safe_push (*token
);
17139 c_parser_consume_token (parser
);
17141 clauses
.safe_push (*c_parser_peek_token (parser
));
17142 c_parser_skip_to_pragma_eol (parser
);
17145 /* Make sure nothing tries to read past the end of the tokens. */
17147 memset (&eof_token
, 0, sizeof (eof_token
));
17148 eof_token
.type
= CPP_EOF
;
17149 clauses
.safe_push (eof_token
);
17150 clauses
.safe_push (eof_token
);
17154 case pragma_external
:
17155 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17156 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
17158 int ext
= disable_extension_diagnostics ();
17160 c_parser_consume_token (parser
);
17161 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17162 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
17163 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
17165 restore_extension_diagnostics (ext
);
17168 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
17171 case pragma_struct
:
17174 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
17175 "function declaration or definition");
17177 case pragma_compound
:
17178 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17179 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
17181 int ext
= disable_extension_diagnostics ();
17183 c_parser_consume_token (parser
);
17184 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
17185 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
17186 if (c_parser_next_tokens_start_declaration (parser
))
17188 c_parser_declaration_or_fndef (parser
, true, true, true, true,
17189 true, NULL
, clauses
);
17190 restore_extension_diagnostics (ext
);
17193 restore_extension_diagnostics (ext
);
17195 else if (c_parser_next_tokens_start_declaration (parser
))
17197 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
17201 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
17202 "function declaration or definition");
17205 gcc_unreachable ();
17209 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
17210 and put that into "omp declare simd" attribute. */
17213 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
17214 vec
<c_token
> clauses
)
17216 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
17217 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
17218 has already processed the tokens. */
17219 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
17221 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
17223 error ("%<#pragma omp declare simd%> not immediately followed by "
17224 "a function declaration or definition");
17225 clauses
[0].type
= CPP_EOF
;
17228 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
17230 error_at (DECL_SOURCE_LOCATION (fndecl
),
17231 "%<#pragma omp declare simd%> not immediately followed by "
17232 "a single function declaration or definition");
17233 clauses
[0].type
= CPP_EOF
;
17237 if (parms
== NULL_TREE
)
17238 parms
= DECL_ARGUMENTS (fndecl
);
17240 unsigned int tokens_avail
= parser
->tokens_avail
;
17241 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
17244 parser
->tokens
= clauses
.address ();
17245 parser
->tokens_avail
= clauses
.length ();
17247 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
17248 while (parser
->tokens_avail
> 3)
17250 c_token
*token
= c_parser_peek_token (parser
);
17251 gcc_assert (token
->type
== CPP_NAME
17252 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
17253 c_parser_consume_token (parser
);
17254 parser
->in_pragma
= true;
17256 tree c
= NULL_TREE
;
17257 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
17258 "#pragma omp declare simd");
17259 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
17260 if (c
!= NULL_TREE
)
17261 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
17262 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
17263 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
17264 DECL_ATTRIBUTES (fndecl
) = c
;
17267 parser
->tokens
= &parser
->tokens_buf
[0];
17268 parser
->tokens_avail
= tokens_avail
;
17269 if (clauses
.exists ())
17270 clauses
[0].type
= CPP_PRAGMA
;
17275 # pragma omp declare target new-line
17276 declarations and definitions
17277 # pragma omp end declare target new-line
17280 # pragma omp declare target ( extended-list ) new-line
17282 # pragma omp declare target declare-target-clauses[seq] new-line */
17284 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
17285 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
17286 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
17289 c_parser_omp_declare_target (c_parser
*parser
)
17291 location_t loc
= c_parser_peek_token (parser
)->location
;
17292 tree clauses
= NULL_TREE
;
17293 if (c_parser_next_token_is (parser
, CPP_NAME
))
17294 clauses
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_TARGET_CLAUSE_MASK
,
17295 "#pragma omp declare target");
17296 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
17298 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
17300 clauses
= c_finish_omp_clauses (clauses
, C_ORT_OMP
);
17301 c_parser_skip_to_pragma_eol (parser
);
17305 c_parser_skip_to_pragma_eol (parser
);
17306 current_omp_declare_target_attribute
++;
17309 if (current_omp_declare_target_attribute
)
17310 error_at (loc
, "%<#pragma omp declare target%> with clauses in between "
17311 "%<#pragma omp declare target%> without clauses and "
17312 "%<#pragma omp end declare target%>");
17313 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
17315 tree t
= OMP_CLAUSE_DECL (c
), id
;
17316 tree at1
= lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t
));
17317 tree at2
= lookup_attribute ("omp declare target link",
17318 DECL_ATTRIBUTES (t
));
17319 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINK
)
17321 id
= get_identifier ("omp declare target link");
17322 std::swap (at1
, at2
);
17325 id
= get_identifier ("omp declare target");
17328 error_at (OMP_CLAUSE_LOCATION (c
),
17329 "%qD specified both in declare target %<link%> and %<to%>"
17335 DECL_ATTRIBUTES (t
) = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (t
));
17336 if (TREE_CODE (t
) != FUNCTION_DECL
&& !is_global_var (t
))
17339 symtab_node
*node
= symtab_node::get (t
);
17342 node
->offloadable
= 1;
17343 if (ENABLE_OFFLOADING
)
17345 g
->have_offload
= true;
17346 if (is_a
<varpool_node
*> (node
))
17347 vec_safe_push (offload_vars
, t
);
17355 c_parser_omp_end_declare_target (c_parser
*parser
)
17357 location_t loc
= c_parser_peek_token (parser
)->location
;
17358 c_parser_consume_pragma (parser
);
17359 if (c_parser_next_token_is (parser
, CPP_NAME
)
17360 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
17363 c_parser_consume_token (parser
);
17364 if (c_parser_next_token_is (parser
, CPP_NAME
)
17365 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
17367 c_parser_consume_token (parser
);
17370 c_parser_error (parser
, "expected %<target%>");
17371 c_parser_skip_to_pragma_eol (parser
);
17377 c_parser_error (parser
, "expected %<declare%>");
17378 c_parser_skip_to_pragma_eol (parser
);
17381 c_parser_skip_to_pragma_eol (parser
);
17382 if (!current_omp_declare_target_attribute
)
17383 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
17384 "%<#pragma omp declare target%>");
17386 current_omp_declare_target_attribute
--;
17391 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17392 initializer-clause[opt] new-line
17394 initializer-clause:
17395 initializer (omp_priv = initializer)
17396 initializer (function-name (argument-list)) */
17399 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
17401 unsigned int tokens_avail
= 0, i
;
17402 vec
<tree
> types
= vNULL
;
17403 vec
<c_token
> clauses
= vNULL
;
17404 enum tree_code reduc_code
= ERROR_MARK
;
17405 tree reduc_id
= NULL_TREE
;
17407 location_t rloc
= c_parser_peek_token (parser
)->location
;
17409 if (context
== pragma_struct
|| context
== pragma_param
)
17411 error ("%<#pragma omp declare reduction%> not at file or block scope");
17415 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17418 switch (c_parser_peek_token (parser
)->type
)
17421 reduc_code
= PLUS_EXPR
;
17424 reduc_code
= MULT_EXPR
;
17427 reduc_code
= MINUS_EXPR
;
17430 reduc_code
= BIT_AND_EXPR
;
17433 reduc_code
= BIT_XOR_EXPR
;
17436 reduc_code
= BIT_IOR_EXPR
;
17439 reduc_code
= TRUTH_ANDIF_EXPR
;
17442 reduc_code
= TRUTH_ORIF_EXPR
;
17446 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17447 if (strcmp (p
, "min") == 0)
17449 reduc_code
= MIN_EXPR
;
17452 if (strcmp (p
, "max") == 0)
17454 reduc_code
= MAX_EXPR
;
17457 reduc_id
= c_parser_peek_token (parser
)->value
;
17460 c_parser_error (parser
,
17461 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
17462 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
17466 tree orig_reduc_id
, reduc_decl
;
17467 orig_reduc_id
= reduc_id
;
17468 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
17469 reduc_decl
= c_omp_reduction_decl (reduc_id
);
17470 c_parser_consume_token (parser
);
17472 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
17477 location_t loc
= c_parser_peek_token (parser
)->location
;
17478 struct c_type_name
*ctype
= c_parser_type_name (parser
);
17481 type
= groktypename (ctype
, NULL
, NULL
);
17482 if (type
== error_mark_node
)
17484 else if ((INTEGRAL_TYPE_P (type
)
17485 || TREE_CODE (type
) == REAL_TYPE
17486 || TREE_CODE (type
) == COMPLEX_TYPE
)
17487 && orig_reduc_id
== NULL_TREE
)
17488 error_at (loc
, "predeclared arithmetic type in "
17489 "%<#pragma omp declare reduction%>");
17490 else if (TREE_CODE (type
) == FUNCTION_TYPE
17491 || TREE_CODE (type
) == ARRAY_TYPE
)
17492 error_at (loc
, "function or array type in "
17493 "%<#pragma omp declare reduction%>");
17494 else if (TYPE_ATOMIC (type
))
17495 error_at (loc
, "%<_Atomic%> qualified type in "
17496 "%<#pragma omp declare reduction%>");
17497 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
17498 error_at (loc
, "const, volatile or restrict qualified type in "
17499 "%<#pragma omp declare reduction%>");
17503 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
17504 if (comptypes (TREE_PURPOSE (t
), type
))
17506 error_at (loc
, "redeclaration of %qs "
17507 "%<#pragma omp declare reduction%> for "
17509 IDENTIFIER_POINTER (reduc_id
)
17510 + sizeof ("omp declare reduction ") - 1,
17513 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
17515 error_at (ploc
, "previous %<#pragma omp declare "
17519 if (t
== NULL_TREE
)
17520 types
.safe_push (type
);
17522 if (c_parser_next_token_is (parser
, CPP_COMMA
))
17523 c_parser_consume_token (parser
);
17531 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
17532 || types
.is_empty ())
17535 clauses
.release ();
17539 c_token
*token
= c_parser_peek_token (parser
);
17540 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
17542 c_parser_consume_token (parser
);
17544 c_parser_skip_to_pragma_eol (parser
);
17548 if (types
.length () > 1)
17550 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17552 c_token
*token
= c_parser_peek_token (parser
);
17553 if (token
->type
== CPP_EOF
)
17555 clauses
.safe_push (*token
);
17556 c_parser_consume_token (parser
);
17558 clauses
.safe_push (*c_parser_peek_token (parser
));
17559 c_parser_skip_to_pragma_eol (parser
);
17561 /* Make sure nothing tries to read past the end of the tokens. */
17563 memset (&eof_token
, 0, sizeof (eof_token
));
17564 eof_token
.type
= CPP_EOF
;
17565 clauses
.safe_push (eof_token
);
17566 clauses
.safe_push (eof_token
);
17569 int errs
= errorcount
;
17570 FOR_EACH_VEC_ELT (types
, i
, type
)
17572 tokens_avail
= parser
->tokens_avail
;
17573 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
17574 if (!clauses
.is_empty ())
17576 parser
->tokens
= clauses
.address ();
17577 parser
->tokens_avail
= clauses
.length ();
17578 parser
->in_pragma
= true;
17581 bool nested
= current_function_decl
!= NULL_TREE
;
17583 c_push_function_context ();
17584 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
17585 reduc_id
, default_function_type
);
17586 current_function_decl
= fndecl
;
17587 allocate_struct_function (fndecl
, true);
17589 tree stmt
= push_stmt_list ();
17590 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
17591 warn about these. */
17592 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17593 get_identifier ("omp_out"), type
);
17594 DECL_ARTIFICIAL (omp_out
) = 1;
17595 DECL_CONTEXT (omp_out
) = fndecl
;
17596 pushdecl (omp_out
);
17597 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17598 get_identifier ("omp_in"), type
);
17599 DECL_ARTIFICIAL (omp_in
) = 1;
17600 DECL_CONTEXT (omp_in
) = fndecl
;
17602 struct c_expr combiner
= c_parser_expression (parser
);
17603 struct c_expr initializer
;
17604 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
17606 initializer
.value
= error_mark_node
;
17607 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17609 else if (c_parser_next_token_is (parser
, CPP_NAME
)
17610 && strcmp (IDENTIFIER_POINTER
17611 (c_parser_peek_token (parser
)->value
),
17612 "initializer") == 0)
17614 c_parser_consume_token (parser
);
17617 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17618 get_identifier ("omp_priv"), type
);
17619 DECL_ARTIFICIAL (omp_priv
) = 1;
17620 DECL_INITIAL (omp_priv
) = error_mark_node
;
17621 DECL_CONTEXT (omp_priv
) = fndecl
;
17622 pushdecl (omp_priv
);
17623 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17624 get_identifier ("omp_orig"), type
);
17625 DECL_ARTIFICIAL (omp_orig
) = 1;
17626 DECL_CONTEXT (omp_orig
) = fndecl
;
17627 pushdecl (omp_orig
);
17628 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17630 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
17632 c_parser_error (parser
, "expected %<omp_priv%> or "
17636 else if (strcmp (IDENTIFIER_POINTER
17637 (c_parser_peek_token (parser
)->value
),
17640 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
17641 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
17643 c_parser_error (parser
, "expected function-name %<(%>");
17647 initializer
= c_parser_postfix_expression (parser
);
17648 if (initializer
.value
17649 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
17652 tree c
= initializer
.value
;
17653 for (j
= 0; j
< call_expr_nargs (c
); j
++)
17655 tree a
= CALL_EXPR_ARG (c
, j
);
17657 if (TREE_CODE (a
) == ADDR_EXPR
17658 && TREE_OPERAND (a
, 0) == omp_priv
)
17661 if (j
== call_expr_nargs (c
))
17662 error ("one of the initializer call arguments should be "
17668 c_parser_consume_token (parser
);
17669 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
17673 tree st
= push_stmt_list ();
17674 location_t loc
= c_parser_peek_token (parser
)->location
;
17675 rich_location
richloc (line_table
, loc
);
17676 start_init (omp_priv
, NULL_TREE
, 0, &richloc
);
17677 struct c_expr init
= c_parser_initializer (parser
);
17679 finish_decl (omp_priv
, loc
, init
.value
,
17680 init
.original_type
, NULL_TREE
);
17681 pop_stmt_list (st
);
17685 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17691 c_parser_skip_to_pragma_eol (parser
);
17693 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
17694 DECL_INITIAL (reduc_decl
));
17695 DECL_INITIAL (reduc_decl
) = t
;
17696 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
17697 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
17698 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
17699 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
17700 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
17701 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
17704 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
17705 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
17706 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
17707 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
17708 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
17709 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17710 walk_tree (&DECL_INITIAL (omp_priv
),
17711 c_check_omp_declare_reduction_r
,
17712 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17716 pop_stmt_list (stmt
);
17718 if (cfun
->language
!= NULL
)
17720 ggc_free (cfun
->language
);
17721 cfun
->language
= NULL
;
17724 current_function_decl
= NULL_TREE
;
17726 c_pop_function_context ();
17728 if (!clauses
.is_empty ())
17730 parser
->tokens
= &parser
->tokens_buf
[0];
17731 parser
->tokens_avail
= tokens_avail
;
17735 if (errs
!= errorcount
)
17739 clauses
.release ();
17745 #pragma omp declare simd declare-simd-clauses[optseq] new-line
17746 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17747 initializer-clause[opt] new-line
17748 #pragma omp declare target new-line */
17751 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
17753 c_parser_consume_pragma (parser
);
17754 if (c_parser_next_token_is (parser
, CPP_NAME
))
17756 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17757 if (strcmp (p
, "simd") == 0)
17759 /* c_parser_consume_token (parser); done in
17760 c_parser_omp_declare_simd. */
17761 c_parser_omp_declare_simd (parser
, context
);
17764 if (strcmp (p
, "reduction") == 0)
17766 c_parser_consume_token (parser
);
17767 c_parser_omp_declare_reduction (parser
, context
);
17770 if (!flag_openmp
) /* flag_openmp_simd */
17772 c_parser_skip_to_pragma_eol (parser
, false);
17775 if (strcmp (p
, "target") == 0)
17777 c_parser_consume_token (parser
);
17778 c_parser_omp_declare_target (parser
);
17783 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
17785 c_parser_skip_to_pragma_eol (parser
);
17789 #pragma omp taskloop taskloop-clause[optseq] new-line
17792 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
17795 #define OMP_TASKLOOP_CLAUSE_MASK \
17796 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
17797 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17798 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17799 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
17800 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
17801 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
17802 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
17803 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
17804 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
17805 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17806 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
17807 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
17808 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
17809 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
17812 c_parser_omp_taskloop (location_t loc
, c_parser
*parser
,
17813 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17816 tree clauses
, block
, ret
;
17818 strcat (p_name
, " taskloop");
17819 mask
|= OMP_TASKLOOP_CLAUSE_MASK
;
17821 if (c_parser_next_token_is (parser
, CPP_NAME
))
17823 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17825 if (strcmp (p
, "simd") == 0)
17827 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17828 if (cclauses
== NULL
)
17829 cclauses
= cclauses_buf
;
17830 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_REDUCTION
);
17831 c_parser_consume_token (parser
);
17832 if (!flag_openmp
) /* flag_openmp_simd */
17833 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
17835 block
= c_begin_compound_stmt (true);
17836 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
17837 block
= c_end_compound_stmt (loc
, block
, true);
17840 ret
= make_node (OMP_TASKLOOP
);
17841 TREE_TYPE (ret
) = void_type_node
;
17842 OMP_FOR_BODY (ret
) = block
;
17843 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
17844 SET_EXPR_LOCATION (ret
, loc
);
17849 if (!flag_openmp
) /* flag_openmp_simd */
17851 c_parser_skip_to_pragma_eol (parser
, false);
17855 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17858 omp_split_clauses (loc
, OMP_TASKLOOP
, mask
, clauses
, cclauses
);
17859 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
17862 block
= c_begin_compound_stmt (true);
17863 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_TASKLOOP
, clauses
, NULL
, if_p
);
17864 block
= c_end_compound_stmt (loc
, block
, true);
17870 /* Main entry point to parsing most OpenMP pragmas. */
17873 c_parser_omp_construct (c_parser
*parser
, bool *if_p
)
17875 enum pragma_kind p_kind
;
17878 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
17879 omp_clause_mask
mask (0);
17881 loc
= c_parser_peek_token (parser
)->location
;
17882 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
17883 c_parser_consume_pragma (parser
);
17887 case PRAGMA_OACC_ATOMIC
:
17888 c_parser_omp_atomic (loc
, parser
);
17890 case PRAGMA_OACC_CACHE
:
17891 strcpy (p_name
, "#pragma acc");
17892 stmt
= c_parser_oacc_cache (loc
, parser
);
17894 case PRAGMA_OACC_DATA
:
17895 stmt
= c_parser_oacc_data (loc
, parser
, if_p
);
17897 case PRAGMA_OACC_HOST_DATA
:
17898 stmt
= c_parser_oacc_host_data (loc
, parser
, if_p
);
17900 case PRAGMA_OACC_KERNELS
:
17901 case PRAGMA_OACC_PARALLEL
:
17902 strcpy (p_name
, "#pragma acc");
17903 stmt
= c_parser_oacc_kernels_parallel (loc
, parser
, p_kind
, p_name
,
17906 case PRAGMA_OACC_LOOP
:
17907 strcpy (p_name
, "#pragma acc");
17908 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17910 case PRAGMA_OACC_WAIT
:
17911 strcpy (p_name
, "#pragma wait");
17912 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
17914 case PRAGMA_OMP_ATOMIC
:
17915 c_parser_omp_atomic (loc
, parser
);
17917 case PRAGMA_OMP_CRITICAL
:
17918 stmt
= c_parser_omp_critical (loc
, parser
, if_p
);
17920 case PRAGMA_OMP_DISTRIBUTE
:
17921 strcpy (p_name
, "#pragma omp");
17922 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17924 case PRAGMA_OMP_FOR
:
17925 strcpy (p_name
, "#pragma omp");
17926 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17928 case PRAGMA_OMP_MASTER
:
17929 stmt
= c_parser_omp_master (loc
, parser
, if_p
);
17931 case PRAGMA_OMP_PARALLEL
:
17932 strcpy (p_name
, "#pragma omp");
17933 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17935 case PRAGMA_OMP_SECTIONS
:
17936 strcpy (p_name
, "#pragma omp");
17937 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
17939 case PRAGMA_OMP_SIMD
:
17940 strcpy (p_name
, "#pragma omp");
17941 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17943 case PRAGMA_OMP_SINGLE
:
17944 stmt
= c_parser_omp_single (loc
, parser
, if_p
);
17946 case PRAGMA_OMP_TASK
:
17947 stmt
= c_parser_omp_task (loc
, parser
, if_p
);
17949 case PRAGMA_OMP_TASKGROUP
:
17950 stmt
= c_parser_omp_taskgroup (parser
, if_p
);
17952 case PRAGMA_OMP_TASKLOOP
:
17953 strcpy (p_name
, "#pragma omp");
17954 stmt
= c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17956 case PRAGMA_OMP_TEAMS
:
17957 strcpy (p_name
, "#pragma omp");
17958 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17961 gcc_unreachable ();
17965 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
17970 # pragma omp threadprivate (variable-list) */
17973 c_parser_omp_threadprivate (c_parser
*parser
)
17978 c_parser_consume_pragma (parser
);
17979 loc
= c_parser_peek_token (parser
)->location
;
17980 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
17982 /* Mark every variable in VARS to be assigned thread local storage. */
17983 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
17985 tree v
= TREE_PURPOSE (t
);
17987 /* FIXME diagnostics: Ideally we should keep individual
17988 locations for all the variables in the var list to make the
17989 following errors more precise. Perhaps
17990 c_parser_omp_var_list_parens() should construct a list of
17991 locations to go along with the var list. */
17993 /* If V had already been marked threadprivate, it doesn't matter
17994 whether it had been used prior to this point. */
17996 error_at (loc
, "%qD is not a variable", v
);
17997 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
17998 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
17999 else if (! is_global_var (v
))
18000 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
18001 else if (TREE_TYPE (v
) == error_mark_node
)
18003 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
18004 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
18007 if (! DECL_THREAD_LOCAL_P (v
))
18009 set_decl_tls_model (v
, decl_default_tls_model (v
));
18010 /* If rtl has been already set for this var, call
18011 make_decl_rtl once again, so that encode_section_info
18012 has a chance to look at the new decl flags. */
18013 if (DECL_RTL_SET_P (v
))
18016 C_DECL_THREADPRIVATE_P (v
) = 1;
18020 c_parser_skip_to_pragma_eol (parser
);
18023 /* Parse a transaction attribute (GCC Extension).
18025 transaction-attribute:
18029 The transactional memory language description is written for C++,
18030 and uses the C++0x attribute syntax. For compatibility, allow the
18031 bracket style for transactions in C as well. */
18034 c_parser_transaction_attributes (c_parser
*parser
)
18036 tree attr_name
, attr
= NULL
;
18038 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
18039 return c_parser_attributes (parser
);
18041 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
18043 c_parser_consume_token (parser
);
18044 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
18047 attr_name
= c_parser_attribute_any_word (parser
);
18050 c_parser_consume_token (parser
);
18051 attr
= build_tree_list (attr_name
, NULL_TREE
);
18054 c_parser_error (parser
, "expected identifier");
18056 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18058 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18062 /* Parse a __transaction_atomic or __transaction_relaxed statement
18065 transaction-statement:
18066 __transaction_atomic transaction-attribute[opt] compound-statement
18067 __transaction_relaxed compound-statement
18069 Note that the only valid attribute is: "outer".
18073 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
18075 unsigned int old_in
= parser
->in_transaction
;
18076 unsigned int this_in
= 1, new_in
;
18077 location_t loc
= c_parser_peek_token (parser
)->location
;
18080 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18081 || keyword
== RID_TRANSACTION_RELAXED
)
18082 && c_parser_next_token_is_keyword (parser
, keyword
));
18083 c_parser_consume_token (parser
);
18085 if (keyword
== RID_TRANSACTION_RELAXED
)
18086 this_in
|= TM_STMT_ATTR_RELAXED
;
18089 attrs
= c_parser_transaction_attributes (parser
);
18091 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
18094 /* Keep track if we're in the lexical scope of an outer transaction. */
18095 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
18097 parser
->in_transaction
= new_in
;
18098 stmt
= c_parser_compound_statement (parser
);
18099 parser
->in_transaction
= old_in
;
18102 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
18104 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18105 "%<__transaction_atomic%> without transactional memory support enabled"
18106 : "%<__transaction_relaxed %> "
18107 "without transactional memory support enabled"));
18112 /* Parse a __transaction_atomic or __transaction_relaxed expression
18115 transaction-expression:
18116 __transaction_atomic ( expression )
18117 __transaction_relaxed ( expression )
18120 static struct c_expr
18121 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
18124 unsigned int old_in
= parser
->in_transaction
;
18125 unsigned int this_in
= 1;
18126 location_t loc
= c_parser_peek_token (parser
)->location
;
18129 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18130 || keyword
== RID_TRANSACTION_RELAXED
)
18131 && c_parser_next_token_is_keyword (parser
, keyword
));
18132 c_parser_consume_token (parser
);
18134 if (keyword
== RID_TRANSACTION_RELAXED
)
18135 this_in
|= TM_STMT_ATTR_RELAXED
;
18138 attrs
= c_parser_transaction_attributes (parser
);
18140 this_in
|= parse_tm_stmt_attr (attrs
, 0);
18143 parser
->in_transaction
= this_in
;
18144 matching_parens parens
;
18145 if (parens
.require_open (parser
))
18147 tree expr
= c_parser_expression (parser
).value
;
18148 ret
.original_type
= TREE_TYPE (expr
);
18149 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
18150 if (this_in
& TM_STMT_ATTR_RELAXED
)
18151 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
18152 SET_EXPR_LOCATION (ret
.value
, loc
);
18153 ret
.original_code
= TRANSACTION_EXPR
;
18154 if (!parens
.require_close (parser
))
18156 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
18163 ret
.value
= error_mark_node
;
18164 ret
.original_code
= ERROR_MARK
;
18165 ret
.original_type
= NULL
;
18167 parser
->in_transaction
= old_in
;
18170 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18171 "%<__transaction_atomic%> without transactional memory support enabled"
18172 : "%<__transaction_relaxed %> "
18173 "without transactional memory support enabled"));
18175 set_c_expr_source_range (&ret
, loc
, loc
);
18180 /* Parse a __transaction_cancel statement (GCC Extension).
18182 transaction-cancel-statement:
18183 __transaction_cancel transaction-attribute[opt] ;
18185 Note that the only valid attribute is "outer".
18189 c_parser_transaction_cancel (c_parser
*parser
)
18191 location_t loc
= c_parser_peek_token (parser
)->location
;
18193 bool is_outer
= false;
18195 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
18196 c_parser_consume_token (parser
);
18198 attrs
= c_parser_transaction_attributes (parser
);
18200 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
18204 error_at (loc
, "%<__transaction_cancel%> without "
18205 "transactional memory support enabled");
18208 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
18210 error_at (loc
, "%<__transaction_cancel%> within a "
18211 "%<__transaction_relaxed%>");
18216 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
18217 && !is_tm_may_cancel_outer (current_function_decl
))
18219 error_at (loc
, "outer %<__transaction_cancel%> not "
18220 "within outer %<__transaction_atomic%>");
18221 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
18225 else if (parser
->in_transaction
== 0)
18227 error_at (loc
, "%<__transaction_cancel%> not within "
18228 "%<__transaction_atomic%>");
18232 return add_stmt (build_tm_abort_call (loc
, is_outer
));
18235 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
18238 /* Parse a single source file. */
18241 c_parse_file (void)
18243 /* Use local storage to begin. If the first token is a pragma, parse it.
18244 If it is #pragma GCC pch_preprocess, then this will load a PCH file
18245 which will cause garbage collection. */
18248 memset (&tparser
, 0, sizeof tparser
);
18249 tparser
.tokens
= &tparser
.tokens_buf
[0];
18250 the_parser
= &tparser
;
18252 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
18253 c_parser_pragma_pch_preprocess (&tparser
);
18255 the_parser
= ggc_alloc
<c_parser
> ();
18256 *the_parser
= tparser
;
18257 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
18258 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
18260 /* Initialize EH, if we've been told to do so. */
18261 if (flag_exceptions
)
18262 using_eh_for_cleanups ();
18264 c_parser_translation_unit (the_parser
);
18268 /* Parse the body of a function declaration marked with "__RTL".
18270 The RTL parser works on the level of characters read from a
18271 FILE *, whereas c_parser works at the level of tokens.
18272 Square this circle by consuming all of the tokens up to and
18273 including the closing brace, recording the start/end of the RTL
18274 fragment, and reopening the file and re-reading the relevant
18275 lines within the RTL parser.
18277 This requires the opening and closing braces of the C function
18278 to be on separate lines from the RTL they wrap.
18280 Take ownership of START_WITH_PASS, if non-NULL. */
18283 c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
)
18285 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
18287 free (start_with_pass
);
18291 location_t start_loc
= c_parser_peek_token (parser
)->location
;
18293 /* Consume all tokens, up to the closing brace, handling
18294 matching pairs of braces in the rtl dump. */
18295 int num_open_braces
= 1;
18298 switch (c_parser_peek_token (parser
)->type
)
18300 case CPP_OPEN_BRACE
:
18303 case CPP_CLOSE_BRACE
:
18304 if (--num_open_braces
== 0)
18305 goto found_closing_brace
;
18308 error_at (start_loc
, "no closing brace");
18309 free (start_with_pass
);
18314 c_parser_consume_token (parser
);
18317 found_closing_brace
:
18318 /* At the closing brace; record its location. */
18319 location_t end_loc
= c_parser_peek_token (parser
)->location
;
18321 /* Consume the closing brace. */
18322 c_parser_consume_token (parser
);
18324 /* Invoke the RTL parser. */
18325 if (!read_rtl_function_body_from_file_range (start_loc
, end_loc
))
18327 free (start_with_pass
);
18331 /* If a pass name was provided for START_WITH_PASS, run the backend
18332 accordingly now, on the cfun created above, transferring
18333 ownership of START_WITH_PASS. */
18334 if (start_with_pass
)
18335 run_rtl_passes (start_with_pass
);
18338 #include "gt-c-c-parser.h"