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. */
40 #include "coretypes.h"
45 #include "stringpool.h"
48 #include "stor-layout.h"
50 #include "trans-mem.h"
51 #include "c-family/c-pragma.h"
53 #include "c-family/c-objc.h"
55 #include "omp-general.h"
56 #include "omp-offload.h"
58 #include "gomp-constants.h"
59 #include "c-family/c-indentation.h"
60 #include "gimple-expr.h"
62 #include "gcc-rich-location.h"
64 #include "gimple-parser.h"
65 #include "read-rtl-function.h"
66 #include "run-rtl-passes.h"
69 /* We need to walk over decls with incomplete struct/union/enum types
70 after parsing the whole translation unit.
71 In finish_decl(), if the decl is static, has incomplete
72 struct/union/enum type, it is appeneded to incomplete_record_decls.
73 In c_parser_translation_unit(), we iterate over incomplete_record_decls
74 and report error if any of the decls are still incomplete. */
76 vec
<tree
> incomplete_record_decls
;
79 set_c_expr_source_range (c_expr
*expr
,
80 location_t start
, location_t finish
)
82 expr
->src_range
.m_start
= start
;
83 expr
->src_range
.m_finish
= finish
;
85 set_source_range (expr
->value
, start
, finish
);
89 set_c_expr_source_range (c_expr
*expr
,
90 source_range src_range
)
92 expr
->src_range
= src_range
;
94 set_source_range (expr
->value
, src_range
);
98 /* Initialization routine for this file. */
103 /* The only initialization required is of the reserved word
109 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
110 the c_token structure. */
111 gcc_assert (RID_MAX
<= 255);
118 mask
|= D_ASM
| D_EXT
;
122 if (!c_dialect_objc ())
123 mask
|= D_OBJC
| D_CXX_OBJC
;
125 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
126 for (i
= 0; i
< num_c_common_reswords
; i
++)
128 /* If a keyword is disabled, do not enter it into the table
129 and so create a canonical spelling that isn't a keyword. */
130 if (c_common_reswords
[i
].disable
& mask
)
133 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
135 id
= get_identifier (c_common_reswords
[i
].word
);
136 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
137 C_IS_RESERVED_WORD (id
) = 1;
142 id
= get_identifier (c_common_reswords
[i
].word
);
143 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
144 C_IS_RESERVED_WORD (id
) = 1;
145 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
148 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
150 /* We always create the symbols but they aren't always supported. */
152 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
153 id
= get_identifier (name
);
154 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
155 C_IS_RESERVED_WORD (id
) = 1;
159 /* A parser structure recording information about the state and
160 context of parsing. Includes lexer information with up to two
161 tokens of look-ahead; more are not needed for C. */
162 struct GTY(()) c_parser
{
163 /* The look-ahead tokens. */
164 c_token
* GTY((skip
)) tokens
;
165 /* Buffer for look-ahead tokens. */
166 c_token tokens_buf
[4];
167 /* How many look-ahead tokens are available (0 - 4, or
168 more if parsing from pre-lexed tokens). */
169 unsigned int tokens_avail
;
170 /* True if a syntax error is being recovered from; false otherwise.
171 c_parser_error sets this flag. It should clear this flag when
172 enough tokens have been consumed to recover from the error. */
173 BOOL_BITFIELD error
: 1;
174 /* True if we're processing a pragma, and shouldn't automatically
175 consume CPP_PRAGMA_EOL. */
176 BOOL_BITFIELD in_pragma
: 1;
177 /* True if we're parsing the outermost block of an if statement. */
178 BOOL_BITFIELD in_if_block
: 1;
179 /* True if we want to lex an untranslated string. */
180 BOOL_BITFIELD lex_untranslated_string
: 1;
182 /* Objective-C specific parser/lexer information. */
184 /* True if we are in a context where the Objective-C "PQ" keywords
185 are considered keywords. */
186 BOOL_BITFIELD objc_pq_context
: 1;
187 /* True if we are parsing a (potential) Objective-C foreach
188 statement. This is set to true after we parsed 'for (' and while
189 we wait for 'in' or ';' to decide if it's a standard C for loop or an
190 Objective-C foreach loop. */
191 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
192 /* The following flag is needed to contextualize Objective-C lexical
193 analysis. In some cases (e.g., 'int NSObject;'), it is
194 undesirable to bind an identifier to an Objective-C class, even
195 if a class with that name exists. */
196 BOOL_BITFIELD objc_need_raw_identifier
: 1;
197 /* Nonzero if we're processing a __transaction statement. The value
198 is 1 | TM_STMT_ATTR_*. */
199 unsigned int in_transaction
: 4;
200 /* True if we are in a context where the Objective-C "Property attribute"
201 keywords are valid. */
202 BOOL_BITFIELD objc_property_attr_context
: 1;
204 /* Cilk Plus specific parser/lexer information. */
206 /* Buffer to hold all the tokens from parsing the vector attribute for the
207 SIMD-enabled functions (formerly known as elemental functions). */
208 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
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 if (parser
->tokens
!= &parser
->tokens_buf
[0])
775 else if (parser
->tokens_avail
== 2)
776 parser
->tokens
[0] = parser
->tokens
[1];
777 parser
->tokens_avail
--;
780 /* Expect the current token to be a #pragma. Consume it and remember
781 that we've begun parsing a pragma. */
784 c_parser_consume_pragma (c_parser
*parser
)
786 gcc_assert (!parser
->in_pragma
);
787 gcc_assert (parser
->tokens_avail
>= 1);
788 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
789 if (parser
->tokens
!= &parser
->tokens_buf
[0])
791 else if (parser
->tokens_avail
== 2)
792 parser
->tokens
[0] = parser
->tokens
[1];
793 parser
->tokens_avail
--;
794 parser
->in_pragma
= true;
797 /* Update the global input_location from TOKEN. */
799 c_parser_set_source_position_from_token (c_token
*token
)
801 if (token
->type
!= CPP_EOF
)
803 input_location
= token
->location
;
807 /* Helper function for c_parser_error.
808 Having peeked a token of kind TOK1_KIND that might signify
809 a conflict marker, peek successor tokens to determine
810 if we actually do have a conflict marker.
811 Specifically, we consider a run of 7 '<', '=' or '>' characters
812 at the start of a line as a conflict marker.
813 These come through the lexer as three pairs and a single,
814 e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<').
815 If it returns true, *OUT_LOC is written to with the location/range
819 c_parser_peek_conflict_marker (c_parser
*parser
, enum cpp_ttype tok1_kind
,
822 c_token
*token2
= c_parser_peek_2nd_token (parser
);
823 if (token2
->type
!= tok1_kind
)
825 c_token
*token3
= c_parser_peek_nth_token (parser
, 3);
826 if (token3
->type
!= tok1_kind
)
828 c_token
*token4
= c_parser_peek_nth_token (parser
, 4);
829 if (token4
->type
!= conflict_marker_get_final_tok_kind (tok1_kind
))
832 /* It must be at the start of the line. */
833 location_t start_loc
= c_parser_peek_token (parser
)->location
;
834 if (LOCATION_COLUMN (start_loc
) != 1)
837 /* We have a conflict marker. Construct a location of the form:
840 with start == caret, finishing at the end of the marker. */
841 location_t finish_loc
= get_finish (token4
->location
);
842 *out_loc
= make_location (start_loc
, start_loc
, finish_loc
);
847 /* Issue a diagnostic of the form
848 FILE:LINE: MESSAGE before TOKEN
849 where TOKEN is the next token in the input stream of PARSER.
850 MESSAGE (specified by the caller) is usually of the form "expected
853 Do not issue a diagnostic if still recovering from an error.
855 ??? This is taken from the C++ parser, but building up messages in
856 this way is not i18n-friendly and some other approach should be
860 c_parser_error (c_parser
*parser
, const char *gmsgid
)
862 c_token
*token
= c_parser_peek_token (parser
);
865 parser
->error
= true;
869 /* If this is actually a conflict marker, report it as such. */
870 if (token
->type
== CPP_LSHIFT
871 || token
->type
== CPP_RSHIFT
872 || token
->type
== CPP_EQ_EQ
)
875 if (c_parser_peek_conflict_marker (parser
, token
->type
, &loc
))
877 error_at (loc
, "version control conflict marker in file");
882 /* This diagnostic makes more sense if it is tagged to the line of
883 the token we just peeked at. */
884 c_parser_set_source_position_from_token (token
);
885 c_parse_error (gmsgid
,
886 /* Because c_parse_error does not understand
887 CPP_KEYWORD, keywords are treated like
889 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
890 /* ??? The C parser does not save the cpp flags of a
891 token, we need to pass 0 here and we will not get
892 the source spelling of some tokens but rather the
893 canonical spelling. */
894 token
->value
, /*flags=*/0);
897 /* If the next token is of the indicated TYPE, consume it. Otherwise,
898 issue the error MSGID. If MSGID is NULL then a message has already
899 been produced and no message will be produced this time. Returns
900 true if found, false otherwise. */
903 c_parser_require (c_parser
*parser
,
907 if (c_parser_next_token_is (parser
, type
))
909 c_parser_consume_token (parser
);
914 c_parser_error (parser
, msgid
);
919 /* If the next token is the indicated keyword, consume it. Otherwise,
920 issue the error MSGID. Returns true if found, false otherwise. */
923 c_parser_require_keyword (c_parser
*parser
,
927 if (c_parser_next_token_is_keyword (parser
, keyword
))
929 c_parser_consume_token (parser
);
934 c_parser_error (parser
, msgid
);
939 /* Like c_parser_require, except that tokens will be skipped until the
940 desired token is found. An error message is still produced if the
941 next token is not as expected. If MSGID is NULL then a message has
942 already been produced and no message will be produced this
946 c_parser_skip_until_found (c_parser
*parser
,
950 unsigned nesting_depth
= 0;
952 if (c_parser_require (parser
, type
, msgid
))
955 /* Skip tokens until the desired token is found. */
958 /* Peek at the next token. */
959 c_token
*token
= c_parser_peek_token (parser
);
960 /* If we've reached the token we want, consume it and stop. */
961 if (token
->type
== type
&& !nesting_depth
)
963 c_parser_consume_token (parser
);
967 /* If we've run out of tokens, stop. */
968 if (token
->type
== CPP_EOF
)
970 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
972 if (token
->type
== CPP_OPEN_BRACE
973 || token
->type
== CPP_OPEN_PAREN
974 || token
->type
== CPP_OPEN_SQUARE
)
976 else if (token
->type
== CPP_CLOSE_BRACE
977 || token
->type
== CPP_CLOSE_PAREN
978 || token
->type
== CPP_CLOSE_SQUARE
)
980 if (nesting_depth
-- == 0)
983 /* Consume this token. */
984 c_parser_consume_token (parser
);
986 parser
->error
= false;
989 /* Skip tokens until the end of a parameter is found, but do not
990 consume the comma, semicolon or closing delimiter. */
993 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
995 unsigned nesting_depth
= 0;
999 c_token
*token
= c_parser_peek_token (parser
);
1000 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
1003 /* If we've run out of tokens, stop. */
1004 if (token
->type
== CPP_EOF
)
1006 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1008 if (token
->type
== CPP_OPEN_BRACE
1009 || token
->type
== CPP_OPEN_PAREN
1010 || token
->type
== CPP_OPEN_SQUARE
)
1012 else if (token
->type
== CPP_CLOSE_BRACE
1013 || token
->type
== CPP_CLOSE_PAREN
1014 || token
->type
== CPP_CLOSE_SQUARE
)
1016 if (nesting_depth
-- == 0)
1019 /* Consume this token. */
1020 c_parser_consume_token (parser
);
1022 parser
->error
= false;
1025 /* Expect to be at the end of the pragma directive and consume an
1026 end of line marker. */
1029 c_parser_skip_to_pragma_eol (c_parser
*parser
, bool error_if_not_eol
= true)
1031 gcc_assert (parser
->in_pragma
);
1032 parser
->in_pragma
= false;
1034 if (error_if_not_eol
&& c_parser_peek_token (parser
)->type
!= CPP_PRAGMA_EOL
)
1035 c_parser_error (parser
, "expected end of line");
1037 cpp_ttype token_type
;
1040 c_token
*token
= c_parser_peek_token (parser
);
1041 token_type
= token
->type
;
1042 if (token_type
== CPP_EOF
)
1044 c_parser_consume_token (parser
);
1046 while (token_type
!= CPP_PRAGMA_EOL
);
1048 parser
->error
= false;
1051 /* Skip tokens until we have consumed an entire block, or until we
1052 have consumed a non-nested ';'. */
1055 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1057 unsigned nesting_depth
= 0;
1058 bool save_error
= parser
->error
;
1064 /* Peek at the next token. */
1065 token
= c_parser_peek_token (parser
);
1067 switch (token
->type
)
1072 case CPP_PRAGMA_EOL
:
1073 if (parser
->in_pragma
)
1078 /* If the next token is a ';', we have reached the
1079 end of the statement. */
1082 /* Consume the ';'. */
1083 c_parser_consume_token (parser
);
1088 case CPP_CLOSE_BRACE
:
1089 /* If the next token is a non-nested '}', then we have
1090 reached the end of the current block. */
1091 if (nesting_depth
== 0 || --nesting_depth
== 0)
1093 c_parser_consume_token (parser
);
1098 case CPP_OPEN_BRACE
:
1099 /* If it the next token is a '{', then we are entering a new
1100 block. Consume the entire block. */
1105 /* If we see a pragma, consume the whole thing at once. We
1106 have some safeguards against consuming pragmas willy-nilly.
1107 Normally, we'd expect to be here with parser->error set,
1108 which disables these safeguards. But it's possible to get
1109 here for secondary error recovery, after parser->error has
1111 c_parser_consume_pragma (parser
);
1112 c_parser_skip_to_pragma_eol (parser
);
1113 parser
->error
= save_error
;
1120 c_parser_consume_token (parser
);
1124 parser
->error
= false;
1127 /* CPP's options (initialized by c-opts.c). */
1128 extern cpp_options
*cpp_opts
;
1130 /* Save the warning flags which are controlled by __extension__. */
1133 disable_extension_diagnostics (void)
1136 | (warn_pointer_arith
<< 1)
1137 | (warn_traditional
<< 2)
1139 | (warn_long_long
<< 4)
1140 | (warn_cxx_compat
<< 5)
1141 | (warn_overlength_strings
<< 6)
1142 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1143 play tricks to properly restore it. */
1144 | ((warn_c90_c99_compat
== 1) << 7)
1145 | ((warn_c90_c99_compat
== -1) << 8)
1146 /* Similarly for warn_c99_c11_compat. */
1147 | ((warn_c99_c11_compat
== 1) << 9)
1148 | ((warn_c99_c11_compat
== -1) << 10)
1150 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1151 warn_pointer_arith
= 0;
1152 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1154 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1155 warn_cxx_compat
= 0;
1156 warn_overlength_strings
= 0;
1157 warn_c90_c99_compat
= 0;
1158 warn_c99_c11_compat
= 0;
1162 /* Restore the warning flags which are controlled by __extension__.
1163 FLAGS is the return value from disable_extension_diagnostics. */
1166 restore_extension_diagnostics (int flags
)
1168 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1169 warn_pointer_arith
= (flags
>> 1) & 1;
1170 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1171 flag_iso
= (flags
>> 3) & 1;
1172 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1173 warn_cxx_compat
= (flags
>> 5) & 1;
1174 warn_overlength_strings
= (flags
>> 6) & 1;
1175 /* See above for why is this needed. */
1176 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1177 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1180 /* Helper data structure for parsing #pragma acc routine. */
1181 struct oacc_routine_data
{
1182 bool error_seen
; /* Set if error has been reported. */
1183 bool fndecl_seen
; /* Set if one fn decl/definition has been seen already. */
1188 static void c_parser_external_declaration (c_parser
*);
1189 static void c_parser_asm_definition (c_parser
*);
1190 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1191 bool, bool, tree
*, vec
<c_token
>,
1192 struct oacc_routine_data
* = NULL
,
1194 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1195 static void c_parser_static_assert_declaration (c_parser
*);
1196 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1197 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1198 static tree
c_parser_struct_declaration (c_parser
*);
1199 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1200 static tree
c_parser_alignas_specifier (c_parser
*);
1201 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1203 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1205 struct c_declarator
*);
1206 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1207 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1209 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1210 static tree
c_parser_simple_asm_expr (c_parser
*);
1211 static tree
c_parser_attributes (c_parser
*);
1212 static struct c_expr
c_parser_initializer (c_parser
*);
1213 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool,
1215 static void c_parser_initelt (c_parser
*, struct obstack
*);
1216 static void c_parser_initval (c_parser
*, struct c_expr
*,
1218 static tree
c_parser_compound_statement (c_parser
*);
1219 static void c_parser_compound_statement_nostart (c_parser
*);
1220 static void c_parser_label (c_parser
*);
1221 static void c_parser_statement (c_parser
*, bool *);
1222 static void c_parser_statement_after_labels (c_parser
*, bool *,
1223 vec
<tree
> * = NULL
);
1224 static void c_parser_if_statement (c_parser
*, bool *, vec
<tree
> *);
1225 static void c_parser_switch_statement (c_parser
*, bool *);
1226 static void c_parser_while_statement (c_parser
*, bool, bool *);
1227 static void c_parser_do_statement (c_parser
*, bool);
1228 static void c_parser_for_statement (c_parser
*, bool, bool *);
1229 static tree
c_parser_asm_statement (c_parser
*);
1230 static tree
c_parser_asm_operands (c_parser
*);
1231 static tree
c_parser_asm_goto_operands (c_parser
*);
1232 static tree
c_parser_asm_clobbers (c_parser
*);
1233 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1235 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1236 struct c_expr
*, tree
);
1237 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1239 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1240 static struct c_expr
c_parser_unary_expression (c_parser
*);
1241 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1242 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1243 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1244 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1245 struct c_type_name
*,
1247 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1250 static tree
c_parser_transaction (c_parser
*, enum rid
);
1251 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1252 static tree
c_parser_transaction_cancel (c_parser
*);
1253 static struct c_expr
c_parser_expression (c_parser
*);
1254 static struct c_expr
c_parser_expression_conv (c_parser
*);
1255 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1256 vec
<tree
, va_gc
> **, location_t
*,
1257 tree
*, vec
<location_t
> *,
1258 unsigned int * = NULL
);
1259 static void c_parser_oacc_declare (c_parser
*);
1260 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1261 static void c_parser_oacc_update (c_parser
*);
1262 static void c_parser_omp_construct (c_parser
*, bool *);
1263 static void c_parser_omp_threadprivate (c_parser
*);
1264 static void c_parser_omp_barrier (c_parser
*);
1265 static void c_parser_omp_flush (c_parser
*);
1266 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1267 tree
, tree
*, bool *);
1268 static void c_parser_omp_taskwait (c_parser
*);
1269 static void c_parser_omp_taskyield (c_parser
*);
1270 static void c_parser_omp_cancel (c_parser
*);
1272 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1273 pragma_stmt
, pragma_compound
};
1274 static bool c_parser_pragma (c_parser
*, enum pragma_context
, bool *);
1275 static void c_parser_omp_cancellation_point (c_parser
*, enum pragma_context
);
1276 static bool c_parser_omp_target (c_parser
*, enum pragma_context
, bool *);
1277 static void c_parser_omp_end_declare_target (c_parser
*);
1278 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1279 static bool c_parser_omp_ordered (c_parser
*, enum pragma_context
, bool *);
1280 static void c_parser_oacc_routine (c_parser
*, enum pragma_context
);
1282 /* These Objective-C parser functions are only ever called when
1283 compiling Objective-C. */
1284 static void c_parser_objc_class_definition (c_parser
*, tree
);
1285 static void c_parser_objc_class_instance_variables (c_parser
*);
1286 static void c_parser_objc_class_declaration (c_parser
*);
1287 static void c_parser_objc_alias_declaration (c_parser
*);
1288 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1289 static bool c_parser_objc_method_type (c_parser
*);
1290 static void c_parser_objc_method_definition (c_parser
*);
1291 static void c_parser_objc_methodprotolist (c_parser
*);
1292 static void c_parser_objc_methodproto (c_parser
*);
1293 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1294 static tree
c_parser_objc_type_name (c_parser
*);
1295 static tree
c_parser_objc_protocol_refs (c_parser
*);
1296 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1297 static void c_parser_objc_synchronized_statement (c_parser
*);
1298 static tree
c_parser_objc_selector (c_parser
*);
1299 static tree
c_parser_objc_selector_arg (c_parser
*);
1300 static tree
c_parser_objc_receiver (c_parser
*);
1301 static tree
c_parser_objc_message_args (c_parser
*);
1302 static tree
c_parser_objc_keywordexpr (c_parser
*);
1303 static void c_parser_objc_at_property_declaration (c_parser
*);
1304 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1305 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1306 static bool c_parser_objc_diagnose_bad_element_prefix
1307 (c_parser
*, struct c_declspecs
*);
1309 /* Cilk Plus supporting routines. */
1310 static void c_parser_cilk_simd (c_parser
*, bool *);
1311 static void c_parser_cilk_for (c_parser
*, tree
, bool *);
1312 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1313 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1314 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1315 static void c_parser_cilk_grainsize (c_parser
*, bool *);
1317 static void c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
);
1319 /* Parse a translation unit (C90 6.7, C99 6.9).
1322 external-declarations
1324 external-declarations:
1325 external-declaration
1326 external-declarations external-declaration
1335 c_parser_translation_unit (c_parser
*parser
)
1337 if (c_parser_next_token_is (parser
, CPP_EOF
))
1339 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1340 "ISO C forbids an empty translation unit");
1344 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1345 mark_valid_location_for_stdc_pragma (false);
1349 c_parser_external_declaration (parser
);
1350 obstack_free (&parser_obstack
, obstack_position
);
1352 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1357 FOR_EACH_VEC_ELT (incomplete_record_decls
, i
, decl
)
1358 if (DECL_SIZE (decl
) == NULL_TREE
&& TREE_TYPE (decl
) != error_mark_node
)
1359 error ("storage size of %q+D isn%'t known", decl
);
1362 /* Parse an external declaration (C90 6.7, C99 6.9).
1364 external-declaration:
1370 external-declaration:
1373 __extension__ external-declaration
1377 external-declaration:
1378 objc-class-definition
1379 objc-class-declaration
1380 objc-alias-declaration
1381 objc-protocol-definition
1382 objc-method-definition
1387 c_parser_external_declaration (c_parser
*parser
)
1390 switch (c_parser_peek_token (parser
)->type
)
1393 switch (c_parser_peek_token (parser
)->keyword
)
1396 ext
= disable_extension_diagnostics ();
1397 c_parser_consume_token (parser
);
1398 c_parser_external_declaration (parser
);
1399 restore_extension_diagnostics (ext
);
1402 c_parser_asm_definition (parser
);
1404 case RID_AT_INTERFACE
:
1405 case RID_AT_IMPLEMENTATION
:
1406 gcc_assert (c_dialect_objc ());
1407 c_parser_objc_class_definition (parser
, NULL_TREE
);
1410 gcc_assert (c_dialect_objc ());
1411 c_parser_objc_class_declaration (parser
);
1414 gcc_assert (c_dialect_objc ());
1415 c_parser_objc_alias_declaration (parser
);
1417 case RID_AT_PROTOCOL
:
1418 gcc_assert (c_dialect_objc ());
1419 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1421 case RID_AT_PROPERTY
:
1422 gcc_assert (c_dialect_objc ());
1423 c_parser_objc_at_property_declaration (parser
);
1425 case RID_AT_SYNTHESIZE
:
1426 gcc_assert (c_dialect_objc ());
1427 c_parser_objc_at_synthesize_declaration (parser
);
1429 case RID_AT_DYNAMIC
:
1430 gcc_assert (c_dialect_objc ());
1431 c_parser_objc_at_dynamic_declaration (parser
);
1434 gcc_assert (c_dialect_objc ());
1435 c_parser_consume_token (parser
);
1436 objc_finish_implementation ();
1443 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1444 "ISO C does not allow extra %<;%> outside of a function");
1445 c_parser_consume_token (parser
);
1448 mark_valid_location_for_stdc_pragma (true);
1449 c_parser_pragma (parser
, pragma_external
, NULL
);
1450 mark_valid_location_for_stdc_pragma (false);
1454 if (c_dialect_objc ())
1456 c_parser_objc_method_definition (parser
);
1459 /* Else fall through, and yield a syntax error trying to parse
1460 as a declaration or function definition. */
1464 /* A declaration or a function definition (or, in Objective-C,
1465 an @interface or @protocol with prefix attributes). We can
1466 only tell which after parsing the declaration specifiers, if
1467 any, and the first declarator. */
1468 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1474 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1475 static void c_finish_oacc_routine (struct oacc_routine_data
*, tree
, bool);
1477 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1478 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1479 accepted; otherwise (old-style parameter declarations) only other
1480 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1481 assertion is accepted; otherwise (old-style parameter declarations)
1482 it is not. If NESTED is true, we are inside a function or parsing
1483 old-style parameter declarations; any functions encountered are
1484 nested functions and declaration specifiers are required; otherwise
1485 we are at top level and functions are normal functions and
1486 declaration specifiers may be optional. If EMPTY_OK is true, empty
1487 declarations are OK (subject to all other constraints); otherwise
1488 (old-style parameter declarations) they are diagnosed. If
1489 START_ATTR_OK is true, the declaration specifiers may start with
1490 attributes; otherwise they may not.
1491 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1492 declaration when parsing an Objective-C foreach statement.
1493 FALLTHRU_ATTR_P is used to signal whether this function parsed
1494 "__attribute__((fallthrough));".
1497 declaration-specifiers init-declarator-list[opt] ;
1498 static_assert-declaration
1500 function-definition:
1501 declaration-specifiers[opt] declarator declaration-list[opt]
1506 declaration-list declaration
1508 init-declarator-list:
1510 init-declarator-list , init-declarator
1513 declarator simple-asm-expr[opt] attributes[opt]
1514 declarator simple-asm-expr[opt] attributes[opt] = initializer
1518 nested-function-definition:
1519 declaration-specifiers declarator declaration-list[opt]
1525 attributes objc-class-definition
1526 attributes objc-category-definition
1527 attributes objc-protocol-definition
1529 The simple-asm-expr and attributes are GNU extensions.
1531 This function does not handle __extension__; that is handled in its
1532 callers. ??? Following the old parser, __extension__ may start
1533 external declarations, declarations in functions and declarations
1534 at the start of "for" loops, but not old-style parameter
1537 C99 requires declaration specifiers in a function definition; the
1538 absence is diagnosed through the diagnosis of implicit int. In GNU
1539 C we also allow but diagnose declarations without declaration
1540 specifiers, but only at top level (elsewhere they conflict with
1543 In Objective-C, declarations of the looping variable in a foreach
1544 statement are exceptionally terminated by 'in' (for example, 'for
1545 (NSObject *object in array) { ... }').
1550 threadprivate-directive
1554 gimple-function-definition:
1555 declaration-specifiers[opt] __GIMPLE (gimple-or-rtl-pass-list) declarator
1556 declaration-list[opt] compound-statement
1558 rtl-function-definition:
1559 declaration-specifiers[opt] __RTL (gimple-or-rtl-pass-list) declarator
1560 declaration-list[opt] compound-statement */
1563 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1564 bool static_assert_ok
, bool empty_ok
,
1565 bool nested
, bool start_attr_ok
,
1566 tree
*objc_foreach_object_declaration
,
1567 vec
<c_token
> omp_declare_simd_clauses
,
1568 struct oacc_routine_data
*oacc_routine_data
,
1569 bool *fallthru_attr_p
)
1571 struct c_declspecs
*specs
;
1573 tree all_prefix_attrs
;
1574 bool diagnosed_no_specs
= false;
1575 location_t here
= c_parser_peek_token (parser
)->location
;
1577 if (static_assert_ok
1578 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1580 c_parser_static_assert_declaration (parser
);
1583 specs
= build_null_declspecs ();
1585 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1586 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1587 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1588 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1589 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1590 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1592 tree name
= c_parser_peek_token (parser
)->value
;
1594 /* Issue a warning about NAME being an unknown type name, perhaps
1595 with some kind of hint.
1596 If the user forgot a "struct" etc, suggest inserting
1597 it. Otherwise, attempt to look for misspellings. */
1598 gcc_rich_location
richloc (here
);
1599 if (tag_exists_p (RECORD_TYPE
, name
))
1601 /* This is not C++ with its implicit typedef. */
1602 richloc
.add_fixit_insert_before ("struct ");
1603 error_at_rich_loc (&richloc
,
1604 "unknown type name %qE;"
1605 " use %<struct%> keyword to refer to the type",
1608 else if (tag_exists_p (UNION_TYPE
, name
))
1610 richloc
.add_fixit_insert_before ("union ");
1611 error_at_rich_loc (&richloc
,
1612 "unknown type name %qE;"
1613 " use %<union%> keyword to refer to the type",
1616 else if (tag_exists_p (ENUMERAL_TYPE
, name
))
1618 richloc
.add_fixit_insert_before ("enum ");
1619 error_at_rich_loc (&richloc
,
1620 "unknown type name %qE;"
1621 " use %<enum%> keyword to refer to the type",
1626 const char *hint
= lookup_name_fuzzy (name
, FUZZY_LOOKUP_TYPENAME
);
1629 richloc
.add_fixit_replace (hint
);
1630 error_at_rich_loc (&richloc
,
1631 "unknown type name %qE; did you mean %qs?",
1635 error_at (here
, "unknown type name %qE", name
);
1638 /* Parse declspecs normally to get a correct pointer type, but avoid
1639 a further "fails to be a type name" error. Refuse nested functions
1640 since it is not how the user likely wants us to recover. */
1641 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1642 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1643 c_parser_peek_token (parser
)->value
= error_mark_node
;
1647 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1648 true, true, cla_nonabstract_decl
);
1651 c_parser_skip_to_end_of_block_or_statement (parser
);
1654 if (nested
&& !specs
->declspecs_seen_p
)
1656 c_parser_error (parser
, "expected declaration specifiers");
1657 c_parser_skip_to_end_of_block_or_statement (parser
);
1661 finish_declspecs (specs
);
1662 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1663 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1666 error_at (here
, "%<__auto_type%> in empty declaration");
1667 else if (specs
->typespec_kind
== ctsk_none
1668 && attribute_fallthrough_p (specs
->attrs
))
1670 if (fallthru_attr_p
!= NULL
)
1671 *fallthru_attr_p
= true;
1672 tree fn
= build_call_expr_internal_loc (here
, IFN_FALLTHROUGH
,
1680 shadow_tag_warned (specs
, 1);
1681 pedwarn (here
, 0, "empty declaration");
1683 c_parser_consume_token (parser
);
1684 if (oacc_routine_data
)
1685 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1689 /* Provide better error recovery. Note that a type name here is usually
1690 better diagnosed as a redeclaration. */
1692 && specs
->typespec_kind
== ctsk_tagdef
1693 && c_parser_next_token_starts_declspecs (parser
)
1694 && !c_parser_next_token_is (parser
, CPP_NAME
))
1696 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1697 parser
->error
= false;
1698 shadow_tag_warned (specs
, 1);
1701 else if (c_dialect_objc () && !auto_type_p
)
1703 /* Prefix attributes are an error on method decls. */
1704 switch (c_parser_peek_token (parser
)->type
)
1708 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1712 warning_at (c_parser_peek_token (parser
)->location
,
1714 "prefix attributes are ignored for methods");
1715 specs
->attrs
= NULL_TREE
;
1718 c_parser_objc_method_definition (parser
);
1720 c_parser_objc_methodproto (parser
);
1726 /* This is where we parse 'attributes @interface ...',
1727 'attributes @implementation ...', 'attributes @protocol ...'
1728 (where attributes could be, for example, __attribute__
1731 switch (c_parser_peek_token (parser
)->keyword
)
1733 case RID_AT_INTERFACE
:
1735 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1737 c_parser_objc_class_definition (parser
, specs
->attrs
);
1741 case RID_AT_IMPLEMENTATION
:
1743 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1747 warning_at (c_parser_peek_token (parser
)->location
,
1749 "prefix attributes are ignored for implementations");
1750 specs
->attrs
= NULL_TREE
;
1752 c_parser_objc_class_definition (parser
, NULL_TREE
);
1756 case RID_AT_PROTOCOL
:
1758 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1760 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1767 case RID_AT_PROPERTY
:
1770 c_parser_error (parser
, "unexpected attribute");
1771 specs
->attrs
= NULL
;
1778 else if (attribute_fallthrough_p (specs
->attrs
))
1779 warning_at (here
, OPT_Wattributes
,
1780 "%<fallthrough%> attribute not followed by %<;%>");
1782 pending_xref_error ();
1783 prefix_attrs
= specs
->attrs
;
1784 all_prefix_attrs
= prefix_attrs
;
1785 specs
->attrs
= NULL_TREE
;
1788 struct c_declarator
*declarator
;
1791 tree fnbody
= NULL_TREE
;
1792 /* Declaring either one or more declarators (in which case we
1793 should diagnose if there were no declaration specifiers) or a
1794 function definition (in which case the diagnostic for
1795 implicit int suffices). */
1796 declarator
= c_parser_declarator (parser
,
1797 specs
->typespec_kind
!= ctsk_none
,
1798 C_DTR_NORMAL
, &dummy
);
1799 if (declarator
== NULL
)
1801 if (omp_declare_simd_clauses
.exists ()
1802 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1803 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1804 omp_declare_simd_clauses
);
1805 if (oacc_routine_data
)
1806 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1807 c_parser_skip_to_end_of_block_or_statement (parser
);
1810 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1813 "%<__auto_type%> requires a plain identifier"
1815 c_parser_skip_to_end_of_block_or_statement (parser
);
1818 if (c_parser_next_token_is (parser
, CPP_EQ
)
1819 || c_parser_next_token_is (parser
, CPP_COMMA
)
1820 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1821 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1822 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1823 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1825 tree asm_name
= NULL_TREE
;
1826 tree postfix_attrs
= NULL_TREE
;
1827 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1829 diagnosed_no_specs
= true;
1830 pedwarn (here
, 0, "data definition has no type or storage class");
1832 /* Having seen a data definition, there cannot now be a
1833 function definition. */
1835 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1836 asm_name
= c_parser_simple_asm_expr (parser
);
1837 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1839 postfix_attrs
= c_parser_attributes (parser
);
1840 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1842 /* This means there is an attribute specifier after
1843 the declarator in a function definition. Provide
1844 some more information for the user. */
1845 error_at (here
, "attributes should be specified before the "
1846 "declarator in a function definition");
1847 c_parser_skip_to_end_of_block_or_statement (parser
);
1851 if (c_parser_next_token_is (parser
, CPP_EQ
))
1855 location_t init_loc
;
1856 c_parser_consume_token (parser
);
1859 init_loc
= c_parser_peek_token (parser
)->location
;
1860 rich_location
richloc (line_table
, init_loc
);
1861 start_init (NULL_TREE
, asm_name
, global_bindings_p (), &richloc
);
1862 init
= c_parser_expr_no_commas (parser
, NULL
);
1863 if (TREE_CODE (init
.value
) == COMPONENT_REF
1864 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1866 "%<__auto_type%> used with a bit-field"
1868 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1869 tree init_type
= TREE_TYPE (init
.value
);
1870 /* As with typeof, remove all qualifiers from atomic types. */
1871 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1873 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
1874 bool vm_type
= variably_modified_type_p (init_type
,
1877 init
.value
= c_save_expr (init
.value
);
1879 specs
->typespec_kind
= ctsk_typeof
;
1880 specs
->locations
[cdw_typedef
] = init_loc
;
1881 specs
->typedef_p
= true;
1882 specs
->type
= init_type
;
1885 bool maybe_const
= true;
1886 tree type_expr
= c_fully_fold (init
.value
, false,
1888 specs
->expr_const_operands
&= maybe_const
;
1890 specs
->expr
= build2 (COMPOUND_EXPR
,
1891 TREE_TYPE (type_expr
),
1892 specs
->expr
, type_expr
);
1894 specs
->expr
= type_expr
;
1896 d
= start_decl (declarator
, specs
, true,
1897 chainon (postfix_attrs
, all_prefix_attrs
));
1899 d
= error_mark_node
;
1900 if (omp_declare_simd_clauses
.exists ()
1901 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1902 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1903 omp_declare_simd_clauses
);
1907 /* The declaration of the variable is in effect while
1908 its initializer is parsed. */
1909 d
= start_decl (declarator
, specs
, true,
1910 chainon (postfix_attrs
, all_prefix_attrs
));
1912 d
= error_mark_node
;
1913 if (omp_declare_simd_clauses
.exists ()
1914 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1915 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1916 omp_declare_simd_clauses
);
1917 init_loc
= c_parser_peek_token (parser
)->location
;
1918 rich_location
richloc (line_table
, init_loc
);
1919 start_init (d
, asm_name
, global_bindings_p (), &richloc
);
1920 init
= c_parser_initializer (parser
);
1923 if (oacc_routine_data
)
1924 c_finish_oacc_routine (oacc_routine_data
, d
, false);
1925 if (d
!= error_mark_node
)
1927 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
1928 finish_decl (d
, init_loc
, init
.value
,
1929 init
.original_type
, asm_name
);
1937 "%<__auto_type%> requires an initialized "
1938 "data declaration");
1939 c_parser_skip_to_end_of_block_or_statement (parser
);
1942 tree d
= start_decl (declarator
, specs
, false,
1943 chainon (postfix_attrs
,
1945 if (omp_declare_simd_clauses
.exists ()
1946 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1948 tree parms
= NULL_TREE
;
1949 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1951 struct c_declarator
*ce
= declarator
;
1953 if (ce
->kind
== cdk_function
)
1955 parms
= ce
->u
.arg_info
->parms
;
1959 ce
= ce
->declarator
;
1962 temp_store_parm_decls (d
, parms
);
1963 c_finish_omp_declare_simd (parser
, d
, parms
,
1964 omp_declare_simd_clauses
);
1966 temp_pop_parm_decls ();
1968 if (oacc_routine_data
)
1969 c_finish_oacc_routine (oacc_routine_data
, d
, false);
1971 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1972 NULL_TREE
, asm_name
);
1974 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1977 *objc_foreach_object_declaration
= d
;
1979 *objc_foreach_object_declaration
= error_mark_node
;
1982 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1987 "%<__auto_type%> may only be used with"
1988 " a single declarator");
1989 c_parser_skip_to_end_of_block_or_statement (parser
);
1992 c_parser_consume_token (parser
);
1993 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1994 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1997 all_prefix_attrs
= prefix_attrs
;
2000 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2002 c_parser_consume_token (parser
);
2005 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
2007 /* This can only happen in Objective-C: we found the
2008 'in' that terminates the declaration inside an
2009 Objective-C foreach statement. Do not consume the
2010 token, so that the caller can use it to determine
2011 that this indeed is a foreach context. */
2016 c_parser_error (parser
, "expected %<,%> or %<;%>");
2017 c_parser_skip_to_end_of_block_or_statement (parser
);
2021 else if (auto_type_p
)
2024 "%<__auto_type%> requires an initialized data declaration");
2025 c_parser_skip_to_end_of_block_or_statement (parser
);
2030 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
2031 "%<asm%> or %<__attribute__%>");
2032 c_parser_skip_to_end_of_block_or_statement (parser
);
2035 /* Function definition (nested or otherwise). */
2038 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
2039 c_push_function_context ();
2041 if (!start_function (specs
, declarator
, all_prefix_attrs
))
2043 /* This can appear in many cases looking nothing like a
2044 function definition, so we don't give a more specific
2045 error suggesting there was one. */
2046 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2047 "or %<__attribute__%>");
2049 c_pop_function_context ();
2053 if (DECL_DECLARED_INLINE_P (current_function_decl
))
2054 tv
= TV_PARSE_INLINE
;
2057 auto_timevar
at (g_timer
, tv
);
2059 /* Parse old-style parameter declarations. ??? Attributes are
2060 not allowed to start declaration specifiers here because of a
2061 syntax conflict between a function declaration with attribute
2062 suffix and a function definition with an attribute prefix on
2063 first old-style parameter declaration. Following the old
2064 parser, they are not accepted on subsequent old-style
2065 parameter declarations either. However, there is no
2066 ambiguity after the first declaration, nor indeed on the
2067 first as long as we don't allow postfix attributes after a
2068 declarator with a nonempty identifier list in a definition;
2069 and postfix attributes have never been accepted here in
2070 function definitions either. */
2071 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
2072 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
2073 c_parser_declaration_or_fndef (parser
, false, false, false,
2074 true, false, NULL
, vNULL
);
2075 store_parm_decls ();
2076 if (omp_declare_simd_clauses
.exists ()
2077 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
2078 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
2079 omp_declare_simd_clauses
);
2080 if (oacc_routine_data
)
2081 c_finish_oacc_routine (oacc_routine_data
, current_function_decl
, true);
2082 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
2083 = c_parser_peek_token (parser
)->location
;
2085 /* If the definition was marked with __GIMPLE then parse the
2086 function body as GIMPLE. */
2087 if (specs
->gimple_p
)
2089 cfun
->pass_startwith
= specs
->gimple_or_rtl_pass
;
2090 bool saved
= in_late_binary_op
;
2091 in_late_binary_op
= true;
2092 c_parser_parse_gimple_body (parser
);
2093 in_late_binary_op
= saved
;
2095 /* Similarly, if it was marked with __RTL, use the RTL parser now,
2096 consuming the function body. */
2097 else if (specs
->rtl_p
)
2099 c_parser_parse_rtl_body (parser
, specs
->gimple_or_rtl_pass
);
2101 /* Normally, store_parm_decls sets next_is_function_body,
2102 anticipating a function body. We need a push_scope/pop_scope
2103 pair to flush out this state, or subsequent function parsing
2113 fnbody
= c_parser_compound_statement (parser
);
2114 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
2115 fnbody
= expand_array_notation_exprs (fnbody
);
2117 tree fndecl
= current_function_decl
;
2120 tree decl
= current_function_decl
;
2121 /* Mark nested functions as needing static-chain initially.
2122 lower_nested_functions will recompute it but the
2123 DECL_STATIC_CHAIN flag is also used before that happens,
2124 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2125 DECL_STATIC_CHAIN (decl
) = 1;
2128 c_pop_function_context ();
2129 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
2137 /* Get rid of the empty stmt list for GIMPLE. */
2138 if (specs
->gimple_p
)
2139 DECL_SAVED_TREE (fndecl
) = NULL_TREE
;
2145 /* Parse an asm-definition (asm() outside a function body). This is a
2153 c_parser_asm_definition (c_parser
*parser
)
2155 tree asm_str
= c_parser_simple_asm_expr (parser
);
2157 symtab
->finalize_toplevel_asm (asm_str
);
2158 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2161 /* Parse a static assertion (C11 6.7.10).
2163 static_assert-declaration:
2164 static_assert-declaration-no-semi ;
2168 c_parser_static_assert_declaration (c_parser
*parser
)
2170 c_parser_static_assert_declaration_no_semi (parser
);
2172 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2173 c_parser_skip_to_end_of_block_or_statement (parser
);
2176 /* Parse a static assertion (C11 6.7.10), without the trailing
2179 static_assert-declaration-no-semi:
2180 _Static_assert ( constant-expression , string-literal )
2184 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2186 location_t assert_loc
, value_loc
;
2190 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2191 assert_loc
= c_parser_peek_token (parser
)->location
;
2193 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2194 "ISO C99 does not support %<_Static_assert%>");
2196 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2197 "ISO C90 does not support %<_Static_assert%>");
2198 c_parser_consume_token (parser
);
2199 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2201 location_t value_tok_loc
= c_parser_peek_token (parser
)->location
;
2202 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2203 value_loc
= EXPR_LOC_OR_LOC (value
, value_tok_loc
);
2204 parser
->lex_untranslated_string
= true;
2205 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2207 parser
->lex_untranslated_string
= false;
2210 switch (c_parser_peek_token (parser
)->type
)
2216 case CPP_UTF8STRING
:
2217 string
= c_parser_peek_token (parser
)->value
;
2218 c_parser_consume_token (parser
);
2219 parser
->lex_untranslated_string
= false;
2222 c_parser_error (parser
, "expected string literal");
2223 parser
->lex_untranslated_string
= false;
2226 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2228 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2230 error_at (value_loc
, "expression in static assertion is not an integer");
2233 if (TREE_CODE (value
) != INTEGER_CST
)
2235 value
= c_fully_fold (value
, false, NULL
);
2236 /* Strip no-op conversions. */
2237 STRIP_TYPE_NOPS (value
);
2238 if (TREE_CODE (value
) == INTEGER_CST
)
2239 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2240 "is not an integer constant expression");
2242 if (TREE_CODE (value
) != INTEGER_CST
)
2244 error_at (value_loc
, "expression in static assertion is not constant");
2247 constant_expression_warning (value
);
2248 if (integer_zerop (value
))
2249 error_at (assert_loc
, "static assertion failed: %E", string
);
2252 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2253 6.7), adding them to SPECS (which may already include some).
2254 Storage class specifiers are accepted iff SCSPEC_OK; type
2255 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2256 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2257 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2259 declaration-specifiers:
2260 storage-class-specifier declaration-specifiers[opt]
2261 type-specifier declaration-specifiers[opt]
2262 type-qualifier declaration-specifiers[opt]
2263 function-specifier declaration-specifiers[opt]
2264 alignment-specifier declaration-specifiers[opt]
2266 Function specifiers (inline) are from C99, and are currently
2267 handled as storage class specifiers, as is __thread. Alignment
2268 specifiers are from C11.
2270 C90 6.5.1, C99 6.7.1:
2271 storage-class-specifier:
2279 (_Thread_local is new in C11.)
2286 (_Noreturn is new in C11.)
2288 C90 6.5.2, C99 6.7.2:
2301 [_Imaginary removed in C99 TC2]
2302 struct-or-union-specifier
2305 atomic-type-specifier
2307 (_Bool and _Complex are new in C99.)
2308 (atomic-type-specifier is new in C11.)
2310 C90 6.5.3, C99 6.7.3:
2316 address-space-qualifier
2319 (restrict is new in C99.)
2320 (_Atomic is new in C11.)
2324 declaration-specifiers:
2325 attributes declaration-specifiers[opt]
2331 identifier recognized by the target
2333 storage-class-specifier:
2347 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2348 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2350 atomic-type-specifier
2351 _Atomic ( type-name )
2356 class-name objc-protocol-refs[opt]
2357 typedef-name objc-protocol-refs
2362 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2363 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2364 bool alignspec_ok
, bool auto_type_ok
,
2365 enum c_lookahead_kind la
)
2367 bool attrs_ok
= start_attr_ok
;
2368 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2371 gcc_assert (la
== cla_prefer_id
);
2373 while (c_parser_next_token_is (parser
, CPP_NAME
)
2374 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2375 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2377 struct c_typespec t
;
2380 location_t loc
= c_parser_peek_token (parser
)->location
;
2382 /* If we cannot accept a type, exit if the next token must start
2383 one. Also, if we already have seen a tagged definition,
2384 a typename would be an error anyway and likely the user
2385 has simply forgotten a semicolon, so we exit. */
2386 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2387 && c_parser_next_tokens_start_typename (parser
, la
)
2388 && !c_parser_next_token_is_qualifier (parser
))
2391 if (c_parser_next_token_is (parser
, CPP_NAME
))
2393 c_token
*name_token
= c_parser_peek_token (parser
);
2394 tree value
= name_token
->value
;
2395 c_id_kind kind
= name_token
->id_kind
;
2397 if (kind
== C_ID_ADDRSPACE
)
2400 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2401 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2402 c_parser_consume_token (parser
);
2407 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2409 /* If we cannot accept a type, and the next token must start one,
2410 exit. Do the same if we already have seen a tagged definition,
2411 since it would be an error anyway and likely the user has simply
2412 forgotten a semicolon. */
2413 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2416 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2417 a C_ID_CLASSNAME. */
2418 c_parser_consume_token (parser
);
2421 if (kind
== C_ID_ID
)
2423 error_at (loc
, "unknown type name %qE", value
);
2424 t
.kind
= ctsk_typedef
;
2425 t
.spec
= error_mark_node
;
2427 else if (kind
== C_ID_TYPENAME
2428 && (!c_dialect_objc ()
2429 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2431 t
.kind
= ctsk_typedef
;
2432 /* For a typedef name, record the meaning, not the name.
2433 In case of 'foo foo, bar;'. */
2434 t
.spec
= lookup_name (value
);
2438 tree proto
= NULL_TREE
;
2439 gcc_assert (c_dialect_objc ());
2441 if (c_parser_next_token_is (parser
, CPP_LESS
))
2442 proto
= c_parser_objc_protocol_refs (parser
);
2443 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2446 t
.expr_const_operands
= true;
2447 declspecs_add_type (name_token
->location
, specs
, t
);
2450 if (c_parser_next_token_is (parser
, CPP_LESS
))
2452 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2453 nisse@lysator.liu.se. */
2455 gcc_assert (c_dialect_objc ());
2456 if (!typespec_ok
|| seen_type
)
2458 proto
= c_parser_objc_protocol_refs (parser
);
2460 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2462 t
.expr_const_operands
= true;
2463 declspecs_add_type (loc
, specs
, t
);
2466 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2467 switch (c_parser_peek_token (parser
)->keyword
)
2480 /* TODO: Distinguish between function specifiers (inline, noreturn)
2481 and storage class specifiers, either here or in
2482 declspecs_add_scspec. */
2483 declspecs_add_scspec (loc
, specs
,
2484 c_parser_peek_token (parser
)->value
);
2485 c_parser_consume_token (parser
);
2517 if (c_dialect_objc ())
2518 parser
->objc_need_raw_identifier
= true;
2519 t
.kind
= ctsk_resword
;
2520 t
.spec
= c_parser_peek_token (parser
)->value
;
2522 t
.expr_const_operands
= true;
2523 declspecs_add_type (loc
, specs
, t
);
2524 c_parser_consume_token (parser
);
2531 t
= c_parser_enum_specifier (parser
);
2532 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2533 declspecs_add_type (loc
, specs
, t
);
2541 t
= c_parser_struct_or_union_specifier (parser
);
2542 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2543 declspecs_add_type (loc
, specs
, t
);
2546 /* ??? The old parser rejected typeof after other type
2547 specifiers, but is a syntax error the best way of
2549 if (!typespec_ok
|| seen_type
)
2553 t
= c_parser_typeof_specifier (parser
);
2554 declspecs_add_type (loc
, specs
, t
);
2557 /* C parser handling of Objective-C constructs needs
2558 checking for correct lvalue-to-rvalue conversions, and
2559 the code in build_modify_expr handling various
2560 Objective-C cases, and that in build_unary_op handling
2561 Objective-C cases for increment / decrement, also needs
2562 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2563 and objc_types_are_equivalent may also need updates. */
2564 if (c_dialect_objc ())
2565 sorry ("%<_Atomic%> in Objective-C");
2567 pedwarn_c99 (loc
, OPT_Wpedantic
,
2568 "ISO C99 does not support the %<_Atomic%> qualifier");
2570 pedwarn_c99 (loc
, OPT_Wpedantic
,
2571 "ISO C90 does not support the %<_Atomic%> qualifier");
2574 value
= c_parser_peek_token (parser
)->value
;
2575 c_parser_consume_token (parser
);
2576 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2578 /* _Atomic ( type-name ). */
2580 c_parser_consume_token (parser
);
2581 struct c_type_name
*type
= c_parser_type_name (parser
);
2582 t
.kind
= ctsk_typeof
;
2583 t
.spec
= error_mark_node
;
2585 t
.expr_const_operands
= true;
2587 t
.spec
= groktypename (type
, &t
.expr
,
2588 &t
.expr_const_operands
);
2589 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2591 if (t
.spec
!= error_mark_node
)
2593 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2594 error_at (loc
, "%<_Atomic%>-qualified array type");
2595 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2596 error_at (loc
, "%<_Atomic%>-qualified function type");
2597 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2598 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2600 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2602 declspecs_add_type (loc
, specs
, t
);
2605 declspecs_add_qual (loc
, specs
, value
);
2611 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2612 c_parser_consume_token (parser
);
2617 attrs
= c_parser_attributes (parser
);
2618 declspecs_add_attrs (loc
, specs
, attrs
);
2623 align
= c_parser_alignas_specifier (parser
);
2624 declspecs_add_alignas (loc
, specs
, align
);
2628 error_at (loc
, "%<__GIMPLE%> only valid with -fgimple");
2629 c_parser_consume_token (parser
);
2630 specs
->gimple_p
= true;
2631 specs
->locations
[cdw_gimple
] = loc
;
2632 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2635 c_parser_consume_token (parser
);
2636 specs
->rtl_p
= true;
2637 specs
->locations
[cdw_rtl
] = loc
;
2638 specs
->gimple_or_rtl_pass
= c_parser_gimple_or_rtl_pass_list (parser
);
2647 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2650 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2651 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2652 enum attributes[opt] identifier
2654 The form with trailing comma is new in C99. The forms with
2655 attributes are GNU extensions. In GNU C, we accept any expression
2656 without commas in the syntax (assignment expressions, not just
2657 conditional expressions); assignment expressions will be diagnosed
2662 enumerator-list , enumerator
2665 enumeration-constant
2666 enumeration-constant = constant-expression
2671 enumeration-constant attributes[opt]
2672 enumeration-constant attributes[opt] = constant-expression
2676 static struct c_typespec
2677 c_parser_enum_specifier (c_parser
*parser
)
2679 struct c_typespec ret
;
2681 tree ident
= NULL_TREE
;
2682 location_t enum_loc
;
2683 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2684 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2685 enum_loc
= c_parser_peek_token (parser
)->location
;
2686 c_parser_consume_token (parser
);
2687 attrs
= c_parser_attributes (parser
);
2688 enum_loc
= c_parser_peek_token (parser
)->location
;
2689 /* Set the location in case we create a decl now. */
2690 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2691 if (c_parser_next_token_is (parser
, CPP_NAME
))
2693 ident
= c_parser_peek_token (parser
)->value
;
2694 ident_loc
= c_parser_peek_token (parser
)->location
;
2695 enum_loc
= ident_loc
;
2696 c_parser_consume_token (parser
);
2698 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2700 /* Parse an enum definition. */
2701 struct c_enum_contents the_enum
;
2704 /* We chain the enumerators in reverse order, then put them in
2705 forward order at the end. */
2707 timevar_push (TV_PARSE_ENUM
);
2708 type
= start_enum (enum_loc
, &the_enum
, ident
);
2710 c_parser_consume_token (parser
);
2718 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2719 location_t decl_loc
, value_loc
;
2720 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2722 /* Give a nicer error for "enum {}". */
2723 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2726 error_at (c_parser_peek_token (parser
)->location
,
2727 "empty enum is invalid");
2728 parser
->error
= true;
2731 c_parser_error (parser
, "expected identifier");
2732 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2733 values
= error_mark_node
;
2736 token
= c_parser_peek_token (parser
);
2737 enum_id
= token
->value
;
2738 /* Set the location in case we create a decl now. */
2739 c_parser_set_source_position_from_token (token
);
2740 decl_loc
= value_loc
= token
->location
;
2741 c_parser_consume_token (parser
);
2742 /* Parse any specified attributes. */
2743 tree enum_attrs
= c_parser_attributes (parser
);
2744 if (c_parser_next_token_is (parser
, CPP_EQ
))
2746 c_parser_consume_token (parser
);
2747 value_loc
= c_parser_peek_token (parser
)->location
;
2748 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2751 enum_value
= NULL_TREE
;
2752 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2753 &the_enum
, enum_id
, enum_value
);
2755 decl_attributes (&TREE_PURPOSE (enum_decl
), enum_attrs
, 0);
2756 TREE_CHAIN (enum_decl
) = values
;
2759 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2761 comma_loc
= c_parser_peek_token (parser
)->location
;
2763 c_parser_consume_token (parser
);
2765 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2768 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2769 "comma at end of enumerator list");
2770 c_parser_consume_token (parser
);
2775 c_parser_error (parser
, "expected %<,%> or %<}%>");
2776 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2777 values
= error_mark_node
;
2781 postfix_attrs
= c_parser_attributes (parser
);
2782 ret
.spec
= finish_enum (type
, nreverse (values
),
2783 chainon (attrs
, postfix_attrs
));
2784 ret
.kind
= ctsk_tagdef
;
2785 ret
.expr
= NULL_TREE
;
2786 ret
.expr_const_operands
= true;
2787 timevar_pop (TV_PARSE_ENUM
);
2792 c_parser_error (parser
, "expected %<{%>");
2793 ret
.spec
= error_mark_node
;
2794 ret
.kind
= ctsk_tagref
;
2795 ret
.expr
= NULL_TREE
;
2796 ret
.expr_const_operands
= true;
2799 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2800 /* In ISO C, enumerated types can be referred to only if already
2802 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2805 pedwarn (enum_loc
, OPT_Wpedantic
,
2806 "ISO C forbids forward references to %<enum%> types");
2811 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2813 struct-or-union-specifier:
2814 struct-or-union attributes[opt] identifier[opt]
2815 { struct-contents } attributes[opt]
2816 struct-or-union attributes[opt] identifier
2819 struct-declaration-list
2821 struct-declaration-list:
2822 struct-declaration ;
2823 struct-declaration-list struct-declaration ;
2830 struct-declaration-list struct-declaration
2832 struct-declaration-list:
2833 struct-declaration-list ;
2836 (Note that in the syntax here, unlike that in ISO C, the semicolons
2837 are included here rather than in struct-declaration, in order to
2838 describe the syntax with extra semicolons and missing semicolon at
2843 struct-declaration-list:
2844 @defs ( class-name )
2846 (Note this does not include a trailing semicolon, but can be
2847 followed by further declarations, and gets a pedwarn-if-pedantic
2848 when followed by a semicolon.) */
2850 static struct c_typespec
2851 c_parser_struct_or_union_specifier (c_parser
*parser
)
2853 struct c_typespec ret
;
2855 tree ident
= NULL_TREE
;
2856 location_t struct_loc
;
2857 location_t ident_loc
= UNKNOWN_LOCATION
;
2858 enum tree_code code
;
2859 switch (c_parser_peek_token (parser
)->keyword
)
2870 struct_loc
= c_parser_peek_token (parser
)->location
;
2871 c_parser_consume_token (parser
);
2872 attrs
= c_parser_attributes (parser
);
2874 /* Set the location in case we create a decl now. */
2875 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2877 if (c_parser_next_token_is (parser
, CPP_NAME
))
2879 ident
= c_parser_peek_token (parser
)->value
;
2880 ident_loc
= c_parser_peek_token (parser
)->location
;
2881 struct_loc
= ident_loc
;
2882 c_parser_consume_token (parser
);
2884 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2886 /* Parse a struct or union definition. Start the scope of the
2887 tag before parsing components. */
2888 struct c_struct_parse_info
*struct_info
;
2889 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2891 /* We chain the components in reverse order, then put them in
2892 forward order at the end. Each struct-declaration may
2893 declare multiple components (comma-separated), so we must use
2894 chainon to join them, although when parsing each
2895 struct-declaration we can use TREE_CHAIN directly.
2897 The theory behind all this is that there will be more
2898 semicolon separated fields than comma separated fields, and
2899 so we'll be minimizing the number of node traversals required
2902 timevar_push (TV_PARSE_STRUCT
);
2903 contents
= NULL_TREE
;
2904 c_parser_consume_token (parser
);
2905 /* Handle the Objective-C @defs construct,
2906 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2907 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2910 gcc_assert (c_dialect_objc ());
2911 c_parser_consume_token (parser
);
2912 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2914 if (c_parser_next_token_is (parser
, CPP_NAME
)
2915 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2917 name
= c_parser_peek_token (parser
)->value
;
2918 c_parser_consume_token (parser
);
2922 c_parser_error (parser
, "expected class name");
2923 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2926 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2928 contents
= nreverse (objc_get_class_ivars (name
));
2931 /* Parse the struct-declarations and semicolons. Problems with
2932 semicolons are diagnosed here; empty structures are diagnosed
2937 /* Parse any stray semicolon. */
2938 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2940 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2941 "extra semicolon in struct or union specified");
2942 c_parser_consume_token (parser
);
2945 /* Stop if at the end of the struct or union contents. */
2946 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2948 c_parser_consume_token (parser
);
2951 /* Accept #pragmas at struct scope. */
2952 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2954 c_parser_pragma (parser
, pragma_struct
, NULL
);
2957 /* Parse some comma-separated declarations, but not the
2958 trailing semicolon if any. */
2959 decls
= c_parser_struct_declaration (parser
);
2960 contents
= chainon (decls
, contents
);
2961 /* If no semicolon follows, either we have a parse error or
2962 are at the end of the struct or union and should
2964 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2965 c_parser_consume_token (parser
);
2968 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2969 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2970 "no semicolon at end of struct or union");
2971 else if (parser
->error
2972 || !c_parser_next_token_starts_declspecs (parser
))
2974 c_parser_error (parser
, "expected %<;%>");
2975 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2979 /* If we come here, we have already emitted an error
2980 for an expected `;', identifier or `(', and we also
2981 recovered already. Go on with the next field. */
2984 postfix_attrs
= c_parser_attributes (parser
);
2985 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2986 chainon (attrs
, postfix_attrs
), struct_info
);
2987 ret
.kind
= ctsk_tagdef
;
2988 ret
.expr
= NULL_TREE
;
2989 ret
.expr_const_operands
= true;
2990 timevar_pop (TV_PARSE_STRUCT
);
2995 c_parser_error (parser
, "expected %<{%>");
2996 ret
.spec
= error_mark_node
;
2997 ret
.kind
= ctsk_tagref
;
2998 ret
.expr
= NULL_TREE
;
2999 ret
.expr_const_operands
= true;
3002 ret
= parser_xref_tag (ident_loc
, code
, ident
);
3006 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
3007 the trailing semicolon.
3010 specifier-qualifier-list struct-declarator-list
3011 static_assert-declaration-no-semi
3013 specifier-qualifier-list:
3014 type-specifier specifier-qualifier-list[opt]
3015 type-qualifier specifier-qualifier-list[opt]
3016 attributes specifier-qualifier-list[opt]
3018 struct-declarator-list:
3020 struct-declarator-list , attributes[opt] struct-declarator
3023 declarator attributes[opt]
3024 declarator[opt] : constant-expression attributes[opt]
3029 __extension__ struct-declaration
3030 specifier-qualifier-list
3032 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
3033 of attributes where shown is a GNU extension. In GNU C, we accept
3034 any expression without commas in the syntax (assignment
3035 expressions, not just conditional expressions); assignment
3036 expressions will be diagnosed as non-constant. */
3039 c_parser_struct_declaration (c_parser
*parser
)
3041 struct c_declspecs
*specs
;
3043 tree all_prefix_attrs
;
3045 location_t decl_loc
;
3046 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3050 ext
= disable_extension_diagnostics ();
3051 c_parser_consume_token (parser
);
3052 decl
= c_parser_struct_declaration (parser
);
3053 restore_extension_diagnostics (ext
);
3056 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
3058 c_parser_static_assert_declaration_no_semi (parser
);
3061 specs
= build_null_declspecs ();
3062 decl_loc
= c_parser_peek_token (parser
)->location
;
3063 /* Strictly by the standard, we shouldn't allow _Alignas here,
3064 but it appears to have been intended to allow it there, so
3065 we're keeping it as it is until WG14 reaches a conclusion
3067 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
3068 c_parser_declspecs (parser
, specs
, false, true, true,
3069 true, false, cla_nonabstract_decl
);
3072 if (!specs
->declspecs_seen_p
)
3074 c_parser_error (parser
, "expected specifier-qualifier-list");
3077 finish_declspecs (specs
);
3078 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3079 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3082 if (specs
->typespec_kind
== ctsk_none
)
3084 pedwarn (decl_loc
, OPT_Wpedantic
,
3085 "ISO C forbids member declarations with no members");
3086 shadow_tag_warned (specs
, pedantic
);
3091 /* Support for unnamed structs or unions as members of
3092 structs or unions (which is [a] useful and [b] supports
3096 ret
= grokfield (c_parser_peek_token (parser
)->location
,
3097 build_id_declarator (NULL_TREE
), specs
,
3100 decl_attributes (&ret
, attrs
, 0);
3105 /* Provide better error recovery. Note that a type name here is valid,
3106 and will be treated as a field name. */
3107 if (specs
->typespec_kind
== ctsk_tagdef
3108 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
3109 && c_parser_next_token_starts_declspecs (parser
)
3110 && !c_parser_next_token_is (parser
, CPP_NAME
))
3112 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
3113 parser
->error
= false;
3117 pending_xref_error ();
3118 prefix_attrs
= specs
->attrs
;
3119 all_prefix_attrs
= prefix_attrs
;
3120 specs
->attrs
= NULL_TREE
;
3124 /* Declaring one or more declarators or un-named bit-fields. */
3125 struct c_declarator
*declarator
;
3127 if (c_parser_next_token_is (parser
, CPP_COLON
))
3128 declarator
= build_id_declarator (NULL_TREE
);
3130 declarator
= c_parser_declarator (parser
,
3131 specs
->typespec_kind
!= ctsk_none
,
3132 C_DTR_NORMAL
, &dummy
);
3133 if (declarator
== NULL
)
3135 c_parser_skip_to_end_of_block_or_statement (parser
);
3138 if (c_parser_next_token_is (parser
, CPP_COLON
)
3139 || c_parser_next_token_is (parser
, CPP_COMMA
)
3140 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3141 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
3142 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3144 tree postfix_attrs
= NULL_TREE
;
3145 tree width
= NULL_TREE
;
3147 if (c_parser_next_token_is (parser
, CPP_COLON
))
3149 c_parser_consume_token (parser
);
3150 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
3152 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3153 postfix_attrs
= c_parser_attributes (parser
);
3154 d
= grokfield (c_parser_peek_token (parser
)->location
,
3155 declarator
, specs
, width
, &all_prefix_attrs
);
3156 decl_attributes (&d
, chainon (postfix_attrs
,
3157 all_prefix_attrs
), 0);
3158 DECL_CHAIN (d
) = decls
;
3160 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3161 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
3164 all_prefix_attrs
= prefix_attrs
;
3165 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3166 c_parser_consume_token (parser
);
3167 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3168 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3170 /* Semicolon consumed in caller. */
3175 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3181 c_parser_error (parser
,
3182 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3183 "%<__attribute__%>");
3190 /* Parse a typeof specifier (a GNU extension).
3193 typeof ( expression )
3194 typeof ( type-name )
3197 static struct c_typespec
3198 c_parser_typeof_specifier (c_parser
*parser
)
3200 struct c_typespec ret
;
3201 ret
.kind
= ctsk_typeof
;
3202 ret
.spec
= error_mark_node
;
3203 ret
.expr
= NULL_TREE
;
3204 ret
.expr_const_operands
= true;
3205 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3206 c_parser_consume_token (parser
);
3207 c_inhibit_evaluation_warnings
++;
3209 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3211 c_inhibit_evaluation_warnings
--;
3215 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3217 struct c_type_name
*type
= c_parser_type_name (parser
);
3218 c_inhibit_evaluation_warnings
--;
3222 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3223 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3229 location_t here
= c_parser_peek_token (parser
)->location
;
3230 struct c_expr expr
= c_parser_expression (parser
);
3231 c_inhibit_evaluation_warnings
--;
3233 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3234 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3235 error_at (here
, "%<typeof%> applied to a bit-field");
3236 mark_exp_read (expr
.value
);
3237 ret
.spec
= TREE_TYPE (expr
.value
);
3238 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3239 /* This is returned with the type so that when the type is
3240 evaluated, this can be evaluated. */
3242 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3243 pop_maybe_used (was_vm
);
3244 /* For use in macros such as those in <stdatomic.h>, remove all
3245 qualifiers from atomic types. (const can be an issue for more macros
3246 using typeof than just the <stdatomic.h> ones.) */
3247 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3248 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3250 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3254 /* Parse an alignment-specifier.
3258 alignment-specifier:
3259 _Alignas ( type-name )
3260 _Alignas ( constant-expression )
3264 c_parser_alignas_specifier (c_parser
* parser
)
3266 tree ret
= error_mark_node
;
3267 location_t loc
= c_parser_peek_token (parser
)->location
;
3268 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3269 c_parser_consume_token (parser
);
3271 pedwarn_c99 (loc
, OPT_Wpedantic
,
3272 "ISO C99 does not support %<_Alignas%>");
3274 pedwarn_c99 (loc
, OPT_Wpedantic
,
3275 "ISO C90 does not support %<_Alignas%>");
3276 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3278 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3280 struct c_type_name
*type
= c_parser_type_name (parser
);
3282 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3286 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3287 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3291 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3292 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3293 be redeclared; otherwise it may not. KIND indicates which kind of
3294 declarator is wanted. Returns a valid declarator except in the
3295 case of a syntax error in which case NULL is returned. *SEEN_ID is
3296 set to true if an identifier being declared is seen; this is used
3297 to diagnose bad forms of abstract array declarators and to
3298 determine whether an identifier list is syntactically permitted.
3301 pointer[opt] direct-declarator
3305 ( attributes[opt] declarator )
3306 direct-declarator array-declarator
3307 direct-declarator ( parameter-type-list )
3308 direct-declarator ( identifier-list[opt] )
3311 * type-qualifier-list[opt]
3312 * type-qualifier-list[opt] pointer
3314 type-qualifier-list:
3317 type-qualifier-list type-qualifier
3318 type-qualifier-list attributes
3321 [ type-qualifier-list[opt] assignment-expression[opt] ]
3322 [ static type-qualifier-list[opt] assignment-expression ]
3323 [ type-qualifier-list static assignment-expression ]
3324 [ type-qualifier-list[opt] * ]
3326 parameter-type-list:
3328 parameter-list , ...
3331 parameter-declaration
3332 parameter-list , parameter-declaration
3334 parameter-declaration:
3335 declaration-specifiers declarator attributes[opt]
3336 declaration-specifiers abstract-declarator[opt] attributes[opt]
3340 identifier-list , identifier
3342 abstract-declarator:
3344 pointer[opt] direct-abstract-declarator
3346 direct-abstract-declarator:
3347 ( attributes[opt] abstract-declarator )
3348 direct-abstract-declarator[opt] array-declarator
3349 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3354 direct-declarator ( parameter-forward-declarations
3355 parameter-type-list[opt] )
3357 direct-abstract-declarator:
3358 direct-abstract-declarator[opt] ( parameter-forward-declarations
3359 parameter-type-list[opt] )
3361 parameter-forward-declarations:
3363 parameter-forward-declarations parameter-list ;
3365 The uses of attributes shown above are GNU extensions.
3367 Some forms of array declarator are not included in C99 in the
3368 syntax for abstract declarators; these are disallowed elsewhere.
3369 This may be a defect (DR#289).
3371 This function also accepts an omitted abstract declarator as being
3372 an abstract declarator, although not part of the formal syntax. */
3374 struct c_declarator
*
3375 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3378 /* Parse any initial pointer part. */
3379 if (c_parser_next_token_is (parser
, CPP_MULT
))
3381 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3382 struct c_declarator
*inner
;
3383 c_parser_consume_token (parser
);
3384 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3385 false, false, cla_prefer_id
);
3386 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3390 return make_pointer_declarator (quals_attrs
, inner
);
3392 /* Now we have a direct declarator, direct abstract declarator or
3393 nothing (which counts as a direct abstract declarator here). */
3394 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3397 /* Parse a direct declarator or direct abstract declarator; arguments
3398 as c_parser_declarator. */
3400 static struct c_declarator
*
3401 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3404 /* The direct declarator must start with an identifier (possibly
3405 omitted) or a parenthesized declarator (possibly abstract). In
3406 an ordinary declarator, initial parentheses must start a
3407 parenthesized declarator. In an abstract declarator or parameter
3408 declarator, they could start a parenthesized declarator or a
3409 parameter list. To tell which, the open parenthesis and any
3410 following attributes must be read. If a declaration specifier
3411 follows, then it is a parameter list; if the specifier is a
3412 typedef name, there might be an ambiguity about redeclaring it,
3413 which is resolved in the direction of treating it as a typedef
3414 name. If a close parenthesis follows, it is also an empty
3415 parameter list, as the syntax does not permit empty abstract
3416 declarators. Otherwise, it is a parenthesized declarator (in
3417 which case the analysis may be repeated inside it, recursively).
3419 ??? There is an ambiguity in a parameter declaration "int
3420 (__attribute__((foo)) x)", where x is not a typedef name: it
3421 could be an abstract declarator for a function, or declare x with
3422 parentheses. The proper resolution of this ambiguity needs
3423 documenting. At present we follow an accident of the old
3424 parser's implementation, whereby the first parameter must have
3425 some declaration specifiers other than just attributes. Thus as
3426 a parameter declaration it is treated as a parenthesized
3427 parameter named x, and as an abstract declarator it is
3430 ??? Also following the old parser, attributes inside an empty
3431 parameter list are ignored, making it a list not yielding a
3432 prototype, rather than giving an error or making it have one
3433 parameter with implicit type int.
3435 ??? Also following the old parser, typedef names may be
3436 redeclared in declarators, but not Objective-C class names. */
3438 if (kind
!= C_DTR_ABSTRACT
3439 && c_parser_next_token_is (parser
, CPP_NAME
)
3441 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3442 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3443 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3445 struct c_declarator
*inner
3446 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3448 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3449 c_parser_consume_token (parser
);
3450 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3453 if (kind
!= C_DTR_NORMAL
3454 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3456 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3457 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3458 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3461 /* Either we are at the end of an abstract declarator, or we have
3464 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3467 struct c_declarator
*inner
;
3468 c_parser_consume_token (parser
);
3469 attrs
= c_parser_attributes (parser
);
3470 if (kind
!= C_DTR_NORMAL
3471 && (c_parser_next_token_starts_declspecs (parser
)
3472 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3474 struct c_arg_info
*args
3475 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3482 = build_function_declarator (args
,
3483 build_id_declarator (NULL_TREE
));
3484 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3488 /* A parenthesized declarator. */
3489 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3490 if (inner
!= NULL
&& attrs
!= NULL
)
3491 inner
= build_attrs_declarator (attrs
, inner
);
3492 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3494 c_parser_consume_token (parser
);
3498 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3502 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3509 if (kind
== C_DTR_NORMAL
)
3511 c_parser_error (parser
, "expected identifier or %<(%>");
3515 return build_id_declarator (NULL_TREE
);
3519 /* Parse part of a direct declarator or direct abstract declarator,
3520 given that some (in INNER) has already been parsed; ID_PRESENT is
3521 true if an identifier is present, false for an abstract
3524 static struct c_declarator
*
3525 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3526 struct c_declarator
*inner
)
3528 /* Parse a sequence of array declarators and parameter lists. */
3529 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3531 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3532 struct c_declarator
*declarator
;
3533 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3536 struct c_expr dimen
;
3537 dimen
.value
= NULL_TREE
;
3538 dimen
.original_code
= ERROR_MARK
;
3539 dimen
.original_type
= NULL_TREE
;
3540 c_parser_consume_token (parser
);
3541 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3542 false, false, cla_prefer_id
);
3543 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3545 c_parser_consume_token (parser
);
3546 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3547 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3548 false, false, cla_prefer_id
);
3549 if (!quals_attrs
->declspecs_seen_p
)
3551 /* If "static" is present, there must be an array dimension.
3552 Otherwise, there may be a dimension, "*", or no
3557 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3561 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3563 dimen
.value
= NULL_TREE
;
3566 else if (flag_cilkplus
3567 && c_parser_next_token_is (parser
, CPP_COLON
))
3569 dimen
.value
= error_mark_node
;
3571 error_at (c_parser_peek_token (parser
)->location
,
3572 "array notations cannot be used in declaration");
3573 c_parser_consume_token (parser
);
3575 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3577 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3579 dimen
.value
= NULL_TREE
;
3581 c_parser_consume_token (parser
);
3586 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3592 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3595 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3596 c_parser_consume_token (parser
);
3597 else if (flag_cilkplus
3598 && c_parser_next_token_is (parser
, CPP_COLON
))
3600 error_at (c_parser_peek_token (parser
)->location
,
3601 "array notations cannot be used in declaration");
3602 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3607 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3612 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3613 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3614 static_seen
, star_seen
);
3615 if (declarator
== NULL
)
3617 inner
= set_array_declarator_inner (declarator
, inner
);
3618 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3620 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3623 struct c_arg_info
*args
;
3624 c_parser_consume_token (parser
);
3625 attrs
= c_parser_attributes (parser
);
3626 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3631 inner
= build_function_declarator (args
, inner
);
3632 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3638 /* Parse a parameter list or identifier list, including the closing
3639 parenthesis but not the opening one. ATTRS are the attributes at
3640 the start of the list. ID_LIST_OK is true if an identifier list is
3641 acceptable; such a list must not have attributes at the start. */
3643 static struct c_arg_info
*
3644 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3647 declare_parm_level ();
3648 /* If the list starts with an identifier, it is an identifier list.
3649 Otherwise, it is either a prototype list or an empty list. */
3652 && c_parser_next_token_is (parser
, CPP_NAME
)
3653 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3655 /* Look ahead to detect typos in type names. */
3656 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3657 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3658 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3659 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
3660 && c_parser_peek_2nd_token (parser
)->type
!= CPP_KEYWORD
)
3662 tree list
= NULL_TREE
, *nextp
= &list
;
3663 while (c_parser_next_token_is (parser
, CPP_NAME
)
3664 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3666 *nextp
= build_tree_list (NULL_TREE
,
3667 c_parser_peek_token (parser
)->value
);
3668 nextp
= & TREE_CHAIN (*nextp
);
3669 c_parser_consume_token (parser
);
3670 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3672 c_parser_consume_token (parser
);
3673 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3675 c_parser_error (parser
, "expected identifier");
3679 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3681 struct c_arg_info
*ret
= build_arg_info ();
3683 c_parser_consume_token (parser
);
3689 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3697 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3704 /* Parse a parameter list (possibly empty), including the closing
3705 parenthesis but not the opening one. ATTRS are the attributes at
3706 the start of the list. EXPR is NULL or an expression that needs to
3707 be evaluated for the side effects of array size expressions in the
3710 static struct c_arg_info
*
3711 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3713 bool bad_parm
= false;
3715 /* ??? Following the old parser, forward parameter declarations may
3716 use abstract declarators, and if no real parameter declarations
3717 follow the forward declarations then this is not diagnosed. Also
3718 note as above that attributes are ignored as the only contents of
3719 the parentheses, or as the only contents after forward
3721 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3723 struct c_arg_info
*ret
= build_arg_info ();
3724 c_parser_consume_token (parser
);
3727 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3729 struct c_arg_info
*ret
= build_arg_info ();
3731 if (flag_allow_parameterless_variadic_functions
)
3733 /* F (...) is allowed. */
3734 ret
->types
= NULL_TREE
;
3738 /* Suppress -Wold-style-definition for this case. */
3739 ret
->types
= error_mark_node
;
3740 error_at (c_parser_peek_token (parser
)->location
,
3741 "ISO C requires a named argument before %<...%>");
3743 c_parser_consume_token (parser
);
3744 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3746 c_parser_consume_token (parser
);
3751 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3756 /* Nonempty list of parameters, either terminated with semicolon
3757 (forward declarations; recurse) or with close parenthesis (normal
3758 function) or with ", ... )" (variadic function). */
3761 /* Parse a parameter. */
3762 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3767 push_parm_decl (parm
, &expr
);
3768 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3771 c_parser_consume_token (parser
);
3772 mark_forward_parm_decls ();
3773 new_attrs
= c_parser_attributes (parser
);
3774 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3776 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3778 c_parser_consume_token (parser
);
3782 return get_parm_info (false, expr
);
3784 if (!c_parser_require (parser
, CPP_COMMA
,
3785 "expected %<;%>, %<,%> or %<)%>"))
3787 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3790 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3792 c_parser_consume_token (parser
);
3793 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3795 c_parser_consume_token (parser
);
3799 return get_parm_info (true, expr
);
3803 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3811 /* Parse a parameter declaration. ATTRS are the attributes at the
3812 start of the declaration if it is the first parameter. */
3814 static struct c_parm
*
3815 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3817 struct c_declspecs
*specs
;
3818 struct c_declarator
*declarator
;
3820 tree postfix_attrs
= NULL_TREE
;
3823 /* Accept #pragmas between parameter declarations. */
3824 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3825 c_parser_pragma (parser
, pragma_param
, NULL
);
3827 if (!c_parser_next_token_starts_declspecs (parser
))
3829 c_token
*token
= c_parser_peek_token (parser
);
3832 c_parser_set_source_position_from_token (token
);
3833 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3835 const char *hint
= lookup_name_fuzzy (token
->value
,
3836 FUZZY_LOOKUP_TYPENAME
);
3839 gcc_rich_location
richloc (token
->location
);
3840 richloc
.add_fixit_replace (hint
);
3841 error_at_rich_loc (&richloc
,
3842 "unknown type name %qE; did you mean %qs?",
3843 token
->value
, hint
);
3846 error_at (token
->location
, "unknown type name %qE", token
->value
);
3847 parser
->error
= true;
3849 /* ??? In some Objective-C cases '...' isn't applicable so there
3850 should be a different message. */
3852 c_parser_error (parser
,
3853 "expected declaration specifiers or %<...%>");
3854 c_parser_skip_to_end_of_parameter (parser
);
3857 specs
= build_null_declspecs ();
3860 declspecs_add_attrs (input_location
, specs
, attrs
);
3863 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3864 cla_nonabstract_decl
);
3865 finish_declspecs (specs
);
3866 pending_xref_error ();
3867 prefix_attrs
= specs
->attrs
;
3868 specs
->attrs
= NULL_TREE
;
3869 declarator
= c_parser_declarator (parser
,
3870 specs
->typespec_kind
!= ctsk_none
,
3871 C_DTR_PARM
, &dummy
);
3872 if (declarator
== NULL
)
3874 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3877 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3878 postfix_attrs
= c_parser_attributes (parser
);
3879 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3883 /* Parse a string literal in an asm expression. It should not be
3884 translated, and wide string literals are an error although
3885 permitted by the syntax. This is a GNU extension.
3890 ??? At present, following the old parser, the caller needs to have
3891 set lex_untranslated_string to 1. It would be better to follow the
3892 C++ parser rather than using this kludge. */
3895 c_parser_asm_string_literal (c_parser
*parser
)
3898 int save_flag
= warn_overlength_strings
;
3899 warn_overlength_strings
= 0;
3900 if (c_parser_next_token_is (parser
, CPP_STRING
))
3902 str
= c_parser_peek_token (parser
)->value
;
3903 c_parser_consume_token (parser
);
3905 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3907 error_at (c_parser_peek_token (parser
)->location
,
3908 "wide string literal in %<asm%>");
3909 str
= build_string (1, "");
3910 c_parser_consume_token (parser
);
3914 c_parser_error (parser
, "expected string literal");
3917 warn_overlength_strings
= save_flag
;
3921 /* Parse a simple asm expression. This is used in restricted
3922 contexts, where a full expression with inputs and outputs does not
3923 make sense. This is a GNU extension.
3926 asm ( asm-string-literal )
3930 c_parser_simple_asm_expr (c_parser
*parser
)
3933 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3934 /* ??? Follow the C++ parser rather than using the
3935 lex_untranslated_string kludge. */
3936 parser
->lex_untranslated_string
= true;
3937 c_parser_consume_token (parser
);
3938 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3940 parser
->lex_untranslated_string
= false;
3943 str
= c_parser_asm_string_literal (parser
);
3944 parser
->lex_untranslated_string
= false;
3945 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3947 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3954 c_parser_attribute_any_word (c_parser
*parser
)
3956 tree attr_name
= NULL_TREE
;
3958 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3960 /* ??? See comment above about what keywords are accepted here. */
3962 switch (c_parser_peek_token (parser
)->keyword
)
3993 case RID_TRANSACTION_ATOMIC
:
3994 case RID_TRANSACTION_CANCEL
:
4010 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
4011 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
4013 else if (c_parser_next_token_is (parser
, CPP_NAME
))
4014 attr_name
= c_parser_peek_token (parser
)->value
;
4019 #define CILK_SIMD_FN_CLAUSE_MASK \
4020 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
4021 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
4022 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
4023 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
4024 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
4026 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
4027 VEC_TOKEN is the "vector" token that is replaced with "simd" and
4028 pushed into the token list.
4031 vector (<vector attributes>). */
4034 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
4036 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
4038 int paren_scope
= 0;
4039 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
4040 /* Consume the "vector" token. */
4041 c_parser_consume_token (parser
);
4043 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
4045 c_parser_consume_token (parser
);
4048 while (paren_scope
> 0)
4050 c_token
*token
= c_parser_peek_token (parser
);
4051 if (token
->type
== CPP_OPEN_PAREN
)
4053 else if (token
->type
== CPP_CLOSE_PAREN
)
4055 /* Do not push the last ')' since we are not pushing the '('. */
4056 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
4057 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
4058 c_parser_consume_token (parser
);
4061 /* Since we are converting an attribute to a pragma, we need to end the
4062 attribute with PRAGMA_EOL. */
4064 memset (&eol_token
, 0, sizeof (eol_token
));
4065 eol_token
.type
= CPP_PRAGMA_EOL
;
4066 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
4069 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
4072 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
4074 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
4076 /* c_parser_attributes is called in several places, so if these EOF
4077 tokens are already inserted, then don't do them again. */
4078 if (last_token
.type
== CPP_EOF
)
4081 /* Two CPP_EOF token are added as a safety net since the normal C
4082 front-end has two token look-ahead. */
4084 eof_token
.type
= CPP_EOF
;
4085 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
4086 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
4089 /* Parse (possibly empty) attributes. This is a GNU extension.
4093 attributes attribute
4096 __attribute__ ( ( attribute-list ) )
4100 attribute_list , attrib
4105 any-word ( identifier )
4106 any-word ( identifier , nonempty-expr-list )
4107 any-word ( expr-list )
4109 where the "identifier" must not be declared as a type, and
4110 "any-word" may be any identifier (including one declared as a
4111 type), a reserved word storage class specifier, type specifier or
4112 type qualifier. ??? This still leaves out most reserved keywords
4113 (following the old parser), shouldn't we include them, and why not
4114 allow identifiers declared as types to start the arguments? */
4117 c_parser_attributes (c_parser
*parser
)
4119 tree attrs
= NULL_TREE
;
4120 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4122 /* ??? Follow the C++ parser rather than using the
4123 lex_untranslated_string kludge. */
4124 parser
->lex_untranslated_string
= true;
4125 /* Consume the `__attribute__' keyword. */
4126 c_parser_consume_token (parser
);
4127 /* Look for the two `(' tokens. */
4128 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4130 parser
->lex_untranslated_string
= false;
4133 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4135 parser
->lex_untranslated_string
= false;
4136 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4139 /* Parse the attribute list. */
4140 while (c_parser_next_token_is (parser
, CPP_COMMA
)
4141 || c_parser_next_token_is (parser
, CPP_NAME
)
4142 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
4144 tree attr
, attr_name
, attr_args
;
4145 vec
<tree
, va_gc
> *expr_list
;
4146 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4148 c_parser_consume_token (parser
);
4152 attr_name
= c_parser_attribute_any_word (parser
);
4153 if (attr_name
== NULL
)
4155 if (is_cilkplus_vector_p (attr_name
))
4157 c_token
*v_token
= c_parser_peek_token (parser
);
4158 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
4159 /* If the next token isn't a comma, we're done. */
4160 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4164 c_parser_consume_token (parser
);
4165 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
4167 attr
= build_tree_list (attr_name
, NULL_TREE
);
4168 /* Add this attribute to the list. */
4169 attrs
= chainon (attrs
, attr
);
4170 /* If the next token isn't a comma, we're done. */
4171 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4175 c_parser_consume_token (parser
);
4176 /* Parse the attribute contents. If they start with an
4177 identifier which is followed by a comma or close
4178 parenthesis, then the arguments start with that
4179 identifier; otherwise they are an expression list.
4180 In objective-c the identifier may be a classname. */
4181 if (c_parser_next_token_is (parser
, CPP_NAME
)
4182 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4183 || (c_dialect_objc ()
4184 && c_parser_peek_token (parser
)->id_kind
4186 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4187 || (c_parser_peek_2nd_token (parser
)->type
4188 == CPP_CLOSE_PAREN
))
4189 && (attribute_takes_identifier_p (attr_name
)
4190 || (c_dialect_objc ()
4191 && c_parser_peek_token (parser
)->id_kind
4192 == C_ID_CLASSNAME
)))
4194 tree arg1
= c_parser_peek_token (parser
)->value
;
4195 c_parser_consume_token (parser
);
4196 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4197 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4201 c_parser_consume_token (parser
);
4202 expr_list
= c_parser_expr_list (parser
, false, true,
4203 NULL
, NULL
, NULL
, NULL
);
4204 tree_list
= build_tree_list_vec (expr_list
);
4205 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4206 release_tree_vector (expr_list
);
4211 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4212 attr_args
= NULL_TREE
;
4215 expr_list
= c_parser_expr_list (parser
, false, true,
4216 NULL
, NULL
, NULL
, NULL
);
4217 attr_args
= build_tree_list_vec (expr_list
);
4218 release_tree_vector (expr_list
);
4221 attr
= build_tree_list (attr_name
, attr_args
);
4222 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4223 c_parser_consume_token (parser
);
4226 parser
->lex_untranslated_string
= false;
4227 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4231 /* Add this attribute to the list. */
4232 attrs
= chainon (attrs
, attr
);
4233 /* If the next token isn't a comma, we're done. */
4234 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4237 /* Look for the two `)' tokens. */
4238 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4239 c_parser_consume_token (parser
);
4242 parser
->lex_untranslated_string
= false;
4243 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4247 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4248 c_parser_consume_token (parser
);
4251 parser
->lex_untranslated_string
= false;
4252 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4256 parser
->lex_untranslated_string
= false;
4259 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4260 c_finish_cilk_simd_fn_tokens (parser
);
4264 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4267 specifier-qualifier-list abstract-declarator[opt]
4270 struct c_type_name
*
4271 c_parser_type_name (c_parser
*parser
)
4273 struct c_declspecs
*specs
= build_null_declspecs ();
4274 struct c_declarator
*declarator
;
4275 struct c_type_name
*ret
;
4277 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4279 if (!specs
->declspecs_seen_p
)
4281 c_parser_error (parser
, "expected specifier-qualifier-list");
4284 if (specs
->type
!= error_mark_node
)
4286 pending_xref_error ();
4287 finish_declspecs (specs
);
4289 declarator
= c_parser_declarator (parser
,
4290 specs
->typespec_kind
!= ctsk_none
,
4291 C_DTR_ABSTRACT
, &dummy
);
4292 if (declarator
== NULL
)
4294 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4296 ret
->declarator
= declarator
;
4300 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4303 assignment-expression
4304 { initializer-list }
4305 { initializer-list , }
4308 designation[opt] initializer
4309 initializer-list , designation[opt] initializer
4316 designator-list designator
4323 [ constant-expression ]
4335 [ constant-expression ... constant-expression ]
4337 Any expression without commas is accepted in the syntax for the
4338 constant-expressions, with non-constant expressions rejected later.
4340 This function is only used for top-level initializers; for nested
4341 ones, see c_parser_initval. */
4343 static struct c_expr
4344 c_parser_initializer (c_parser
*parser
)
4346 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4347 return c_parser_braced_init (parser
, NULL_TREE
, false, NULL
);
4351 location_t loc
= c_parser_peek_token (parser
)->location
;
4352 ret
= c_parser_expr_no_commas (parser
, NULL
);
4353 if (TREE_CODE (ret
.value
) != STRING_CST
4354 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4355 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4360 /* The location of the last comma within the current initializer list,
4361 or UNKNOWN_LOCATION if not within one. */
4363 location_t last_init_list_comma
;
4365 /* Parse a braced initializer list. TYPE is the type specified for a
4366 compound literal, and NULL_TREE for other initializers and for
4367 nested braced lists. NESTED_P is true for nested braced lists,
4368 false for the list of a compound literal or the list that is the
4369 top-level initializer in a declaration. */
4371 static struct c_expr
4372 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
,
4373 struct obstack
*outer_obstack
)
4376 struct obstack braced_init_obstack
;
4377 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4378 gcc_obstack_init (&braced_init_obstack
);
4379 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4380 c_parser_consume_token (parser
);
4383 finish_implicit_inits (brace_loc
, outer_obstack
);
4384 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4387 really_start_incremental_init (type
);
4388 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4390 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4394 /* Parse a non-empty initializer list, possibly with a trailing
4398 c_parser_initelt (parser
, &braced_init_obstack
);
4401 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4403 last_init_list_comma
= c_parser_peek_token (parser
)->location
;
4404 c_parser_consume_token (parser
);
4408 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4412 c_token
*next_tok
= c_parser_peek_token (parser
);
4413 if (next_tok
->type
!= CPP_CLOSE_BRACE
)
4415 ret
.value
= error_mark_node
;
4416 ret
.original_code
= ERROR_MARK
;
4417 ret
.original_type
= NULL
;
4418 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4419 pop_init_level (brace_loc
, 0, &braced_init_obstack
, last_init_list_comma
);
4420 obstack_free (&braced_init_obstack
, NULL
);
4423 location_t close_loc
= next_tok
->location
;
4424 c_parser_consume_token (parser
);
4425 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
, close_loc
);
4426 obstack_free (&braced_init_obstack
, NULL
);
4427 set_c_expr_source_range (&ret
, brace_loc
, close_loc
);
4431 /* Parse a nested initializer, including designators. */
4434 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4436 /* Parse any designator or designator list. A single array
4437 designator may have the subsequent "=" omitted in GNU C, but a
4438 longer list or a structure member designator may not. */
4439 if (c_parser_next_token_is (parser
, CPP_NAME
)
4440 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4442 /* Old-style structure member designator. */
4443 set_init_label (c_parser_peek_token (parser
)->location
,
4444 c_parser_peek_token (parser
)->value
,
4445 c_parser_peek_token (parser
)->location
,
4446 braced_init_obstack
);
4447 /* Use the colon as the error location. */
4448 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4449 "obsolete use of designated initializer with %<:%>");
4450 c_parser_consume_token (parser
);
4451 c_parser_consume_token (parser
);
4455 /* des_seen is 0 if there have been no designators, 1 if there
4456 has been a single array designator and 2 otherwise. */
4458 /* Location of a designator. */
4459 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4460 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4461 || c_parser_next_token_is (parser
, CPP_DOT
))
4463 int des_prev
= des_seen
;
4465 des_loc
= c_parser_peek_token (parser
)->location
;
4468 if (c_parser_next_token_is (parser
, CPP_DOT
))
4471 c_parser_consume_token (parser
);
4472 if (c_parser_next_token_is (parser
, CPP_NAME
))
4474 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4475 c_parser_peek_token (parser
)->location
,
4476 braced_init_obstack
);
4477 c_parser_consume_token (parser
);
4482 init
.value
= error_mark_node
;
4483 init
.original_code
= ERROR_MARK
;
4484 init
.original_type
= NULL
;
4485 c_parser_error (parser
, "expected identifier");
4486 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4487 process_init_element (input_location
, init
, false,
4488 braced_init_obstack
);
4495 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4496 location_t array_index_loc
= UNKNOWN_LOCATION
;
4497 /* ??? Following the old parser, [ objc-receiver
4498 objc-message-args ] is accepted as an initializer,
4499 being distinguished from a designator by what follows
4500 the first assignment expression inside the square
4501 brackets, but after a first array designator a
4502 subsequent square bracket is for Objective-C taken to
4503 start an expression, using the obsolete form of
4504 designated initializer without '=', rather than
4505 possibly being a second level of designation: in LALR
4506 terms, the '[' is shifted rather than reducing
4507 designator to designator-list. */
4508 if (des_prev
== 1 && c_dialect_objc ())
4510 des_seen
= des_prev
;
4513 if (des_prev
== 0 && c_dialect_objc ())
4515 /* This might be an array designator or an
4516 Objective-C message expression. If the former,
4517 continue parsing here; if the latter, parse the
4518 remainder of the initializer given the starting
4519 primary-expression. ??? It might make sense to
4520 distinguish when des_prev == 1 as well; see
4521 previous comment. */
4523 struct c_expr mexpr
;
4524 c_parser_consume_token (parser
);
4525 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4526 && ((c_parser_peek_token (parser
)->id_kind
4528 || (c_parser_peek_token (parser
)->id_kind
4529 == C_ID_CLASSNAME
)))
4531 /* Type name receiver. */
4532 tree id
= c_parser_peek_token (parser
)->value
;
4533 c_parser_consume_token (parser
);
4534 rec
= objc_get_class_reference (id
);
4535 goto parse_message_args
;
4537 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4538 mark_exp_read (first
);
4539 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4540 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4541 goto array_desig_after_first
;
4542 /* Expression receiver. So far only one part
4543 without commas has been parsed; there might be
4544 more of the expression. */
4546 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4549 location_t comma_loc
, exp_loc
;
4550 comma_loc
= c_parser_peek_token (parser
)->location
;
4551 c_parser_consume_token (parser
);
4552 exp_loc
= c_parser_peek_token (parser
)->location
;
4553 next
= c_parser_expr_no_commas (parser
, NULL
);
4554 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4556 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4559 /* Now parse the objc-message-args. */
4560 args
= c_parser_objc_message_args (parser
);
4561 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4564 = objc_build_message_expr (rec
, args
);
4565 mexpr
.original_code
= ERROR_MARK
;
4566 mexpr
.original_type
= NULL
;
4567 /* Now parse and process the remainder of the
4568 initializer, starting with this message
4569 expression as a primary-expression. */
4570 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4573 c_parser_consume_token (parser
);
4574 array_index_loc
= c_parser_peek_token (parser
)->location
;
4575 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4576 mark_exp_read (first
);
4577 array_desig_after_first
:
4578 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4580 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4581 c_parser_consume_token (parser
);
4582 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4583 mark_exp_read (second
);
4587 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4589 c_parser_consume_token (parser
);
4590 set_init_index (array_index_loc
, first
, second
,
4591 braced_init_obstack
);
4593 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4594 "ISO C forbids specifying range of elements to initialize");
4597 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4603 if (c_parser_next_token_is (parser
, CPP_EQ
))
4605 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4606 "ISO C90 forbids specifying subobject "
4608 c_parser_consume_token (parser
);
4613 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4614 "obsolete use of designated initializer without %<=%>");
4618 init
.value
= error_mark_node
;
4619 init
.original_code
= ERROR_MARK
;
4620 init
.original_type
= NULL
;
4621 c_parser_error (parser
, "expected %<=%>");
4622 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4623 process_init_element (input_location
, init
, false,
4624 braced_init_obstack
);
4630 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4633 /* Parse a nested initializer; as c_parser_initializer but parses
4634 initializers within braced lists, after any designators have been
4635 applied. If AFTER is not NULL then it is an Objective-C message
4636 expression which is the primary-expression starting the
4640 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4641 struct obstack
* braced_init_obstack
)
4644 gcc_assert (!after
|| c_dialect_objc ());
4645 location_t loc
= c_parser_peek_token (parser
)->location
;
4647 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4648 init
= c_parser_braced_init (parser
, NULL_TREE
, true,
4649 braced_init_obstack
);
4652 init
= c_parser_expr_no_commas (parser
, after
);
4653 if (init
.value
!= NULL_TREE
4654 && TREE_CODE (init
.value
) != STRING_CST
4655 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4656 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4658 process_init_element (loc
, init
, false, braced_init_obstack
);
4661 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4665 { block-item-list[opt] }
4666 { label-declarations block-item-list }
4670 block-item-list block-item
4682 { label-declarations block-item-list }
4685 __extension__ nested-declaration
4686 nested-function-definition
4690 label-declarations label-declaration
4693 __label__ identifier-list ;
4695 Allowing the mixing of declarations and code is new in C99. The
4696 GNU syntax also permits (not shown above) labels at the end of
4697 compound statements, which yield an error. We don't allow labels
4698 on declarations; this might seem like a natural extension, but
4699 there would be a conflict between attributes on the label and
4700 prefix attributes on the declaration. ??? The syntax follows the
4701 old parser in requiring something after label declarations.
4702 Although they are erroneous if the labels declared aren't defined,
4703 is it useful for the syntax to be this way?
4724 cancellation-point-directive */
4727 c_parser_compound_statement (c_parser
*parser
)
4730 location_t brace_loc
;
4731 brace_loc
= c_parser_peek_token (parser
)->location
;
4732 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4734 /* Ensure a scope is entered and left anyway to avoid confusion
4735 if we have just prepared to enter a function body. */
4736 stmt
= c_begin_compound_stmt (true);
4737 c_end_compound_stmt (brace_loc
, stmt
, true);
4738 return error_mark_node
;
4740 stmt
= c_begin_compound_stmt (true);
4741 c_parser_compound_statement_nostart (parser
);
4743 /* If the compound stmt contains array notations, then we expand them. */
4744 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4745 stmt
= expand_array_notation_exprs (stmt
);
4746 return c_end_compound_stmt (brace_loc
, stmt
, true);
4749 /* Parse a compound statement except for the opening brace. This is
4750 used for parsing both compound statements and statement expressions
4751 (which follow different paths to handling the opening). */
4754 c_parser_compound_statement_nostart (c_parser
*parser
)
4756 bool last_stmt
= false;
4757 bool last_label
= false;
4758 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4759 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4760 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4762 c_parser_consume_token (parser
);
4765 mark_valid_location_for_stdc_pragma (true);
4766 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4768 /* Read zero or more forward-declarations for labels that nested
4769 functions can jump to. */
4770 mark_valid_location_for_stdc_pragma (false);
4771 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4773 label_loc
= c_parser_peek_token (parser
)->location
;
4774 c_parser_consume_token (parser
);
4775 /* Any identifiers, including those declared as type names,
4780 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4782 c_parser_error (parser
, "expected identifier");
4786 = declare_label (c_parser_peek_token (parser
)->value
);
4787 C_DECLARED_LABEL_FLAG (label
) = 1;
4788 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4789 c_parser_consume_token (parser
);
4790 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4791 c_parser_consume_token (parser
);
4795 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4797 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4799 /* We must now have at least one statement, label or declaration. */
4800 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4802 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4803 c_parser_error (parser
, "expected declaration or statement");
4804 c_parser_consume_token (parser
);
4807 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4809 location_t loc
= c_parser_peek_token (parser
)->location
;
4810 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4811 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4812 || (c_parser_next_token_is (parser
, CPP_NAME
)
4813 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4815 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4816 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4818 label_loc
= c_parser_peek_token (parser
)->location
;
4821 mark_valid_location_for_stdc_pragma (false);
4822 c_parser_label (parser
);
4824 else if (!last_label
4825 && c_parser_next_tokens_start_declaration (parser
))
4828 mark_valid_location_for_stdc_pragma (false);
4829 bool fallthru_attr_p
= false;
4830 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4831 true, NULL
, vNULL
, NULL
,
4833 if (last_stmt
&& !fallthru_attr_p
)
4834 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4835 "ISO C90 forbids mixed declarations and code");
4836 last_stmt
= fallthru_attr_p
;
4838 else if (!last_label
4839 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4841 /* __extension__ can start a declaration, but is also an
4842 unary operator that can start an expression. Consume all
4843 but the last of a possible series of __extension__ to
4845 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4846 && (c_parser_peek_2nd_token (parser
)->keyword
4848 c_parser_consume_token (parser
);
4849 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4852 ext
= disable_extension_diagnostics ();
4853 c_parser_consume_token (parser
);
4855 mark_valid_location_for_stdc_pragma (false);
4856 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4858 /* Following the old parser, __extension__ does not
4859 disable this diagnostic. */
4860 restore_extension_diagnostics (ext
);
4862 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4863 "ISO C90 forbids mixed declarations and code");
4869 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4871 /* External pragmas, and some omp pragmas, are not associated
4872 with regular c code, and so are not to be considered statements
4873 syntactically. This ensures that the user doesn't put them
4874 places that would turn into syntax errors if the directive
4876 if (c_parser_pragma (parser
,
4877 last_label
? pragma_stmt
: pragma_compound
,
4879 last_label
= false, last_stmt
= true;
4881 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4883 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4884 c_parser_error (parser
, "expected declaration or statement");
4887 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4889 if (parser
->in_if_block
)
4891 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4892 error_at (loc
, """expected %<}%> before %<else%>");
4897 error_at (loc
, "%<else%> without a previous %<if%>");
4898 c_parser_consume_token (parser
);
4907 mark_valid_location_for_stdc_pragma (false);
4908 c_parser_statement_after_labels (parser
, NULL
);
4911 parser
->error
= false;
4914 error_at (label_loc
, "label at end of compound statement");
4915 c_parser_consume_token (parser
);
4916 /* Restore the value we started with. */
4917 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4920 /* Parse all consecutive labels. */
4923 c_parser_all_labels (c_parser
*parser
)
4925 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4926 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4927 || (c_parser_next_token_is (parser
, CPP_NAME
)
4928 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4929 c_parser_label (parser
);
4932 /* Parse a label (C90 6.6.1, C99 6.8.1).
4935 identifier : attributes[opt]
4936 case constant-expression :
4942 case constant-expression ... constant-expression :
4944 The use of attributes on labels is a GNU extension. The syntax in
4945 GNU C accepts any expressions without commas, non-constant
4946 expressions being rejected later. */
4949 c_parser_label (c_parser
*parser
)
4951 location_t loc1
= c_parser_peek_token (parser
)->location
;
4952 tree label
= NULL_TREE
;
4954 /* Remember whether this case or a user-defined label is allowed to fall
4956 bool fallthrough_p
= c_parser_peek_token (parser
)->flags
& PREV_FALLTHROUGH
;
4958 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4961 c_parser_consume_token (parser
);
4962 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4963 if (c_parser_next_token_is (parser
, CPP_COLON
))
4965 c_parser_consume_token (parser
);
4966 label
= do_case (loc1
, exp1
, NULL_TREE
);
4968 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4970 c_parser_consume_token (parser
);
4971 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4972 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4973 label
= do_case (loc1
, exp1
, exp2
);
4976 c_parser_error (parser
, "expected %<:%> or %<...%>");
4978 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4980 c_parser_consume_token (parser
);
4981 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4982 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4986 tree name
= c_parser_peek_token (parser
)->value
;
4989 location_t loc2
= c_parser_peek_token (parser
)->location
;
4990 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4991 c_parser_consume_token (parser
);
4992 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4993 c_parser_consume_token (parser
);
4994 attrs
= c_parser_attributes (parser
);
4995 tlab
= define_label (loc2
, name
);
4998 decl_attributes (&tlab
, attrs
, 0);
4999 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
5004 if (TREE_CODE (label
) == LABEL_EXPR
)
5005 FALLTHROUGH_LABEL_P (LABEL_EXPR_LABEL (label
)) = fallthrough_p
;
5007 FALLTHROUGH_LABEL_P (CASE_LABEL (label
)) = fallthrough_p
;
5009 /* Allow '__attribute__((fallthrough));'. */
5010 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
5012 location_t loc
= c_parser_peek_token (parser
)->location
;
5013 tree attrs
= c_parser_attributes (parser
);
5014 if (attribute_fallthrough_p (attrs
))
5016 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5018 tree fn
= build_call_expr_internal_loc (loc
,
5024 warning_at (loc
, OPT_Wattributes
, "%<fallthrough%> attribute "
5025 "not followed by %<;%>");
5027 else if (attrs
!= NULL_TREE
)
5028 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5029 " can be applied to a null statement");
5031 if (c_parser_next_tokens_start_declaration (parser
))
5033 error_at (c_parser_peek_token (parser
)->location
,
5034 "a label can only be part of a statement and "
5035 "a declaration is not a statement");
5036 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
5037 /*static_assert_ok*/ true,
5038 /*empty_ok*/ true, /*nested*/ true,
5039 /*start_attr_ok*/ true, NULL
,
5045 /* Parse a statement (C90 6.6, C99 6.8).
5050 expression-statement
5058 expression-statement:
5061 selection-statement:
5065 iteration-statement:
5074 return expression[opt] ;
5084 expression-statement:
5090 objc-throw-statement
5091 objc-try-catch-statement
5092 objc-synchronized-statement
5094 objc-throw-statement:
5110 parallel-directive structured-block
5113 kernels-directive structured-block
5116 data-directive structured-block
5119 loop-directive structured-block
5133 parallel-for-construct
5134 parallel-for-simd-construct
5135 parallel-sections-construct
5142 parallel-directive structured-block
5145 for-directive iteration-statement
5148 simd-directive iteration-statements
5151 for-simd-directive iteration-statements
5154 sections-directive section-scope
5157 single-directive structured-block
5159 parallel-for-construct:
5160 parallel-for-directive iteration-statement
5162 parallel-for-simd-construct:
5163 parallel-for-simd-directive iteration-statement
5165 parallel-sections-construct:
5166 parallel-sections-directive section-scope
5169 master-directive structured-block
5172 critical-directive structured-block
5175 atomic-directive expression-statement
5178 ordered-directive structured-block
5180 Transactional Memory:
5183 transaction-statement
5184 transaction-cancel-statement
5186 IF_P is used to track whether there's a (possibly labeled) if statement
5187 which is not enclosed in braces and has an else clause. This is used to
5188 implement -Wparentheses. */
5191 c_parser_statement (c_parser
*parser
, bool *if_p
)
5193 c_parser_all_labels (parser
);
5194 c_parser_statement_after_labels (parser
, if_p
, NULL
);
5197 /* Parse a statement, other than a labeled statement. CHAIN is a vector
5198 of if-else-if conditions.
5200 IF_P is used to track whether there's a (possibly labeled) if statement
5201 which is not enclosed in braces and has an else clause. This is used to
5202 implement -Wparentheses. */
5205 c_parser_statement_after_labels (c_parser
*parser
, bool *if_p
,
5208 location_t loc
= c_parser_peek_token (parser
)->location
;
5209 tree stmt
= NULL_TREE
;
5210 bool in_if_block
= parser
->in_if_block
;
5211 parser
->in_if_block
= false;
5214 switch (c_parser_peek_token (parser
)->type
)
5216 case CPP_OPEN_BRACE
:
5217 add_stmt (c_parser_compound_statement (parser
));
5220 switch (c_parser_peek_token (parser
)->keyword
)
5223 c_parser_if_statement (parser
, if_p
, chain
);
5226 c_parser_switch_statement (parser
, if_p
);
5229 c_parser_while_statement (parser
, false, if_p
);
5232 c_parser_do_statement (parser
, false);
5235 c_parser_for_statement (parser
, false, if_p
);
5240 error_at (c_parser_peek_token (parser
)->location
,
5241 "-fcilkplus must be enabled to use %<_Cilk_for%>");
5242 c_parser_skip_to_end_of_block_or_statement (parser
);
5245 c_parser_cilk_for (parser
, integer_zero_node
, if_p
);
5248 c_parser_consume_token (parser
);
5249 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5251 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
5253 add_stmt (build_cilk_sync ());
5256 c_parser_consume_token (parser
);
5257 if (c_parser_next_token_is (parser
, CPP_NAME
))
5259 stmt
= c_finish_goto_label (loc
,
5260 c_parser_peek_token (parser
)->value
);
5261 c_parser_consume_token (parser
);
5263 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5267 c_parser_consume_token (parser
);
5268 val
= c_parser_expression (parser
);
5269 if (check_no_cilk (val
.value
,
5270 "Cilk array notation cannot be used as a computed goto expression",
5271 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5273 val
.value
= error_mark_node
;
5274 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5275 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5278 c_parser_error (parser
, "expected identifier or %<*%>");
5279 goto expect_semicolon
;
5281 c_parser_consume_token (parser
);
5282 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5283 goto expect_semicolon
;
5285 c_parser_consume_token (parser
);
5286 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5287 goto expect_semicolon
;
5289 c_parser_consume_token (parser
);
5290 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5292 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5293 c_parser_consume_token (parser
);
5297 location_t xloc
= c_parser_peek_token (parser
)->location
;
5298 struct c_expr expr
= c_parser_expression_conv (parser
);
5299 mark_exp_read (expr
.value
);
5300 stmt
= c_finish_return (EXPR_LOC_OR_LOC (expr
.value
, xloc
),
5301 expr
.value
, expr
.original_type
);
5302 goto expect_semicolon
;
5306 stmt
= c_parser_asm_statement (parser
);
5308 case RID_TRANSACTION_ATOMIC
:
5309 case RID_TRANSACTION_RELAXED
:
5310 stmt
= c_parser_transaction (parser
,
5311 c_parser_peek_token (parser
)->keyword
);
5313 case RID_TRANSACTION_CANCEL
:
5314 stmt
= c_parser_transaction_cancel (parser
);
5315 goto expect_semicolon
;
5317 gcc_assert (c_dialect_objc ());
5318 c_parser_consume_token (parser
);
5319 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5321 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5322 c_parser_consume_token (parser
);
5326 struct c_expr expr
= c_parser_expression (parser
);
5327 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5328 if (check_no_cilk (expr
.value
,
5329 "Cilk array notation cannot be used for a throw expression",
5330 "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5331 expr
.value
= error_mark_node
;
5334 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5335 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5337 goto expect_semicolon
;
5341 gcc_assert (c_dialect_objc ());
5342 c_parser_objc_try_catch_finally_statement (parser
);
5344 case RID_AT_SYNCHRONIZED
:
5345 gcc_assert (c_dialect_objc ());
5346 c_parser_objc_synchronized_statement (parser
);
5350 /* Allow '__attribute__((fallthrough));'. */
5351 tree attrs
= c_parser_attributes (parser
);
5352 if (attribute_fallthrough_p (attrs
))
5354 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5356 tree fn
= build_call_expr_internal_loc (loc
,
5361 c_parser_consume_token (parser
);
5364 warning_at (loc
, OPT_Wattributes
,
5365 "%<fallthrough%> attribute not followed "
5368 else if (attrs
!= NULL_TREE
)
5369 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5370 " can be applied to a null statement");
5378 c_parser_consume_token (parser
);
5380 case CPP_CLOSE_PAREN
:
5381 case CPP_CLOSE_SQUARE
:
5382 /* Avoid infinite loop in error recovery:
5383 c_parser_skip_until_found stops at a closing nesting
5384 delimiter without consuming it, but here we need to consume
5385 it to proceed further. */
5386 c_parser_error (parser
, "expected statement");
5387 c_parser_consume_token (parser
);
5390 c_parser_pragma (parser
, pragma_stmt
, if_p
);
5394 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5396 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5399 /* Two cases cannot and do not have line numbers associated: If stmt
5400 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5401 cannot hold line numbers. But that's OK because the statement
5402 will either be changed to a MODIFY_EXPR during gimplification of
5403 the statement expr, or discarded. If stmt was compound, but
5404 without new variables, we will have skipped the creation of a
5405 BIND and will have a bare STATEMENT_LIST. But that's OK because
5406 (recursively) all of the component statements should already have
5407 line numbers assigned. ??? Can we discard no-op statements
5409 if (EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5410 protected_set_expr_location (stmt
, loc
);
5412 parser
->in_if_block
= in_if_block
;
5415 /* Parse the condition from an if, do, while or for statements. */
5418 c_parser_condition (c_parser
*parser
)
5420 location_t loc
= c_parser_peek_token (parser
)->location
;
5422 cond
= c_parser_expression_conv (parser
).value
;
5423 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5424 cond
= c_fully_fold (cond
, false, NULL
);
5425 if (warn_sequence_point
)
5426 verify_sequence_points (cond
);
5430 /* Parse a parenthesized condition from an if, do or while statement.
5436 c_parser_paren_condition (c_parser
*parser
)
5439 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5440 return error_mark_node
;
5441 cond
= c_parser_condition (parser
);
5442 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5446 /* Parse a statement which is a block in C99.
5448 IF_P is used to track whether there's a (possibly labeled) if statement
5449 which is not enclosed in braces and has an else clause. This is used to
5450 implement -Wparentheses. */
5453 c_parser_c99_block_statement (c_parser
*parser
, bool *if_p
)
5455 tree block
= c_begin_compound_stmt (flag_isoc99
);
5456 location_t loc
= c_parser_peek_token (parser
)->location
;
5457 c_parser_statement (parser
, if_p
);
5458 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5461 /* Parse the body of an if statement. This is just parsing a
5462 statement but (a) it is a block in C99, (b) we track whether the
5463 body is an if statement for the sake of -Wparentheses warnings, (c)
5464 we handle an empty body specially for the sake of -Wempty-body
5465 warnings, and (d) we call parser_compound_statement directly
5466 because c_parser_statement_after_labels resets
5467 parser->in_if_block.
5469 IF_P is used to track whether there's a (possibly labeled) if statement
5470 which is not enclosed in braces and has an else clause. This is used to
5471 implement -Wparentheses. */
5474 c_parser_if_body (c_parser
*parser
, bool *if_p
,
5475 const token_indent_info
&if_tinfo
)
5477 tree block
= c_begin_compound_stmt (flag_isoc99
);
5478 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5479 token_indent_info body_tinfo
5480 = get_token_indent_info (c_parser_peek_token (parser
));
5482 c_parser_all_labels (parser
);
5483 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5485 location_t loc
= c_parser_peek_token (parser
)->location
;
5486 add_stmt (build_empty_stmt (loc
));
5487 c_parser_consume_token (parser
);
5488 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5489 warning_at (loc
, OPT_Wempty_body
,
5490 "suggest braces around empty body in an %<if%> statement");
5492 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5493 add_stmt (c_parser_compound_statement (parser
));
5495 c_parser_statement_after_labels (parser
, if_p
);
5497 token_indent_info next_tinfo
5498 = get_token_indent_info (c_parser_peek_token (parser
));
5499 warn_for_misleading_indentation (if_tinfo
, body_tinfo
, next_tinfo
);
5501 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5504 /* Parse the else body of an if statement. This is just parsing a
5505 statement but (a) it is a block in C99, (b) we handle an empty body
5506 specially for the sake of -Wempty-body warnings. CHAIN is a vector
5507 of if-else-if conditions. */
5510 c_parser_else_body (c_parser
*parser
, const token_indent_info
&else_tinfo
,
5513 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5514 tree block
= c_begin_compound_stmt (flag_isoc99
);
5515 token_indent_info body_tinfo
5516 = get_token_indent_info (c_parser_peek_token (parser
));
5518 c_parser_all_labels (parser
);
5519 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5521 location_t loc
= c_parser_peek_token (parser
)->location
;
5524 "suggest braces around empty body in an %<else%> statement");
5525 add_stmt (build_empty_stmt (loc
));
5526 c_parser_consume_token (parser
);
5529 c_parser_statement_after_labels (parser
, NULL
, chain
);
5531 token_indent_info next_tinfo
5532 = get_token_indent_info (c_parser_peek_token (parser
));
5533 warn_for_misleading_indentation (else_tinfo
, body_tinfo
, next_tinfo
);
5535 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5538 /* We might need to reclassify any previously-lexed identifier, e.g.
5539 when we've left a for loop with an if-statement without else in the
5540 body - we might have used a wrong scope for the token. See PR67784. */
5543 c_parser_maybe_reclassify_token (c_parser
*parser
)
5545 if (c_parser_next_token_is (parser
, CPP_NAME
))
5547 c_token
*token
= c_parser_peek_token (parser
);
5549 if (token
->id_kind
!= C_ID_CLASSNAME
)
5551 tree decl
= lookup_name (token
->value
);
5553 token
->id_kind
= C_ID_ID
;
5556 if (TREE_CODE (decl
) == TYPE_DECL
)
5557 token
->id_kind
= C_ID_TYPENAME
;
5559 else if (c_dialect_objc ())
5561 tree objc_interface_decl
= objc_is_class_name (token
->value
);
5562 /* Objective-C class names are in the same namespace as
5563 variables and typedefs, and hence are shadowed by local
5565 if (objc_interface_decl
)
5567 token
->value
= objc_interface_decl
;
5568 token
->id_kind
= C_ID_CLASSNAME
;
5575 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5578 if ( expression ) statement
5579 if ( expression ) statement else statement
5581 CHAIN is a vector of if-else-if conditions.
5582 IF_P is used to track whether there's a (possibly labeled) if statement
5583 which is not enclosed in braces and has an else clause. This is used to
5584 implement -Wparentheses. */
5587 c_parser_if_statement (c_parser
*parser
, bool *if_p
, vec
<tree
> *chain
)
5592 bool nested_if
= false;
5593 tree first_body
, second_body
;
5597 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5598 token_indent_info if_tinfo
5599 = get_token_indent_info (c_parser_peek_token (parser
));
5600 c_parser_consume_token (parser
);
5601 block
= c_begin_compound_stmt (flag_isoc99
);
5602 loc
= c_parser_peek_token (parser
)->location
;
5603 cond
= c_parser_paren_condition (parser
);
5604 if (flag_cilkplus
&& contains_cilk_spawn_stmt (cond
))
5606 error_at (loc
, "if statement cannot contain %<Cilk_spawn%>");
5607 cond
= error_mark_node
;
5609 in_if_block
= parser
->in_if_block
;
5610 parser
->in_if_block
= true;
5611 first_body
= c_parser_if_body (parser
, &nested_if
, if_tinfo
);
5612 parser
->in_if_block
= in_if_block
;
5614 if (warn_duplicated_cond
)
5615 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond
), cond
, &chain
);
5617 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5619 token_indent_info else_tinfo
5620 = get_token_indent_info (c_parser_peek_token (parser
));
5621 c_parser_consume_token (parser
);
5622 if (warn_duplicated_cond
)
5624 if (c_parser_next_token_is_keyword (parser
, RID_IF
)
5627 /* We've got "if (COND) else if (COND2)". Start the
5628 condition chain and add COND as the first element. */
5629 chain
= new vec
<tree
> ();
5630 if (!CONSTANT_CLASS_P (cond
) && !TREE_SIDE_EFFECTS (cond
))
5631 chain
->safe_push (cond
);
5633 else if (!c_parser_next_token_is_keyword (parser
, RID_IF
))
5635 /* This is if-else without subsequent if. Zap the condition
5636 chain; we would have already warned at this point. */
5641 second_body
= c_parser_else_body (parser
, else_tinfo
, chain
);
5642 /* Set IF_P to true to indicate that this if statement has an
5643 else clause. This may trigger the Wparentheses warning
5644 below when we get back up to the parent if statement. */
5650 second_body
= NULL_TREE
;
5652 /* Diagnose an ambiguous else if if-then-else is nested inside
5655 warning_at (loc
, OPT_Wdangling_else
,
5656 "suggest explicit braces to avoid ambiguous %<else%>");
5658 if (warn_duplicated_cond
)
5660 /* This if statement does not have an else clause. We don't
5661 need the condition chain anymore. */
5666 c_finish_if_stmt (loc
, cond
, first_body
, second_body
);
5667 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5669 /* If the if statement contains array notations, then we expand them. */
5670 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5671 if_stmt
= fix_conditional_array_notations (if_stmt
);
5673 c_parser_maybe_reclassify_token (parser
);
5676 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5679 switch (expression) statement
5683 c_parser_switch_statement (c_parser
*parser
, bool *if_p
)
5686 tree block
, expr
, body
, save_break
;
5687 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5688 location_t switch_cond_loc
;
5689 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5690 c_parser_consume_token (parser
);
5691 block
= c_begin_compound_stmt (flag_isoc99
);
5692 bool explicit_cast_p
= false;
5693 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5695 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5696 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5697 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5698 explicit_cast_p
= true;
5699 ce
= c_parser_expression (parser
);
5700 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5702 /* ??? expr has no valid location? */
5703 if (check_no_cilk (expr
,
5704 "Cilk array notation cannot be used as a condition for switch statement",
5705 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5707 expr
= error_mark_node
;
5708 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5712 switch_cond_loc
= UNKNOWN_LOCATION
;
5713 expr
= error_mark_node
;
5714 ce
.original_type
= error_mark_node
;
5716 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5717 save_break
= c_break_label
;
5718 c_break_label
= NULL_TREE
;
5719 body
= c_parser_c99_block_statement (parser
, if_p
);
5720 c_finish_case (body
, ce
.original_type
);
5723 location_t here
= c_parser_peek_token (parser
)->location
;
5724 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5725 SET_EXPR_LOCATION (t
, here
);
5728 c_break_label
= save_break
;
5729 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5730 c_parser_maybe_reclassify_token (parser
);
5733 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5736 while (expression) statement
5738 IF_P is used to track whether there's a (possibly labeled) if statement
5739 which is not enclosed in braces and has an else clause. This is used to
5740 implement -Wparentheses. */
5743 c_parser_while_statement (c_parser
*parser
, bool ivdep
, bool *if_p
)
5745 tree block
, cond
, body
, save_break
, save_cont
;
5747 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5748 token_indent_info while_tinfo
5749 = get_token_indent_info (c_parser_peek_token (parser
));
5750 c_parser_consume_token (parser
);
5751 block
= c_begin_compound_stmt (flag_isoc99
);
5752 loc
= c_parser_peek_token (parser
)->location
;
5753 cond
= c_parser_paren_condition (parser
);
5754 if (check_no_cilk (cond
,
5755 "Cilk array notation cannot be used as a condition for while statement",
5756 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
5757 cond
= error_mark_node
;
5758 if (ivdep
&& cond
!= error_mark_node
)
5759 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5760 build_int_cst (integer_type_node
,
5761 annot_expr_ivdep_kind
));
5762 save_break
= c_break_label
;
5763 c_break_label
= NULL_TREE
;
5764 save_cont
= c_cont_label
;
5765 c_cont_label
= NULL_TREE
;
5767 token_indent_info body_tinfo
5768 = get_token_indent_info (c_parser_peek_token (parser
));
5770 body
= c_parser_c99_block_statement (parser
, if_p
);
5771 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5772 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5773 c_parser_maybe_reclassify_token (parser
);
5775 token_indent_info next_tinfo
5776 = get_token_indent_info (c_parser_peek_token (parser
));
5777 warn_for_misleading_indentation (while_tinfo
, body_tinfo
, next_tinfo
);
5779 c_break_label
= save_break
;
5780 c_cont_label
= save_cont
;
5783 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5786 do statement while ( expression ) ;
5790 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5792 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5794 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5795 c_parser_consume_token (parser
);
5796 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5797 warning_at (c_parser_peek_token (parser
)->location
,
5799 "suggest braces around empty body in %<do%> statement");
5800 block
= c_begin_compound_stmt (flag_isoc99
);
5801 loc
= c_parser_peek_token (parser
)->location
;
5802 save_break
= c_break_label
;
5803 c_break_label
= NULL_TREE
;
5804 save_cont
= c_cont_label
;
5805 c_cont_label
= NULL_TREE
;
5806 body
= c_parser_c99_block_statement (parser
, NULL
);
5807 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5808 new_break
= c_break_label
;
5809 c_break_label
= save_break
;
5810 new_cont
= c_cont_label
;
5811 c_cont_label
= save_cont
;
5812 cond
= c_parser_paren_condition (parser
);
5813 if (check_no_cilk (cond
,
5814 "Cilk array notation cannot be used as a condition for a do-while statement",
5815 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
5816 cond
= error_mark_node
;
5817 if (ivdep
&& cond
!= error_mark_node
)
5818 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5819 build_int_cst (integer_type_node
,
5820 annot_expr_ivdep_kind
));
5821 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5822 c_parser_skip_to_end_of_block_or_statement (parser
);
5823 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5824 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5827 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5830 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5831 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5833 The form with a declaration is new in C99.
5835 ??? In accordance with the old parser, the declaration may be a
5836 nested function, which is then rejected in check_for_loop_decls,
5837 but does it make any sense for this to be included in the grammar?
5838 Note in particular that the nested function does not include a
5839 trailing ';', whereas the "declaration" production includes one.
5840 Also, can we reject bad declarations earlier and cheaper than
5841 check_for_loop_decls?
5843 In Objective-C, there are two additional variants:
5846 for ( expression in expresssion ) statement
5847 for ( declaration in expression ) statement
5849 This is inconsistent with C, because the second variant is allowed
5850 even if c99 is not enabled.
5852 The rest of the comment documents these Objective-C foreach-statement.
5854 Here is the canonical example of the first variant:
5855 for (object in array) { do something with object }
5856 we call the first expression ("object") the "object_expression" and
5857 the second expression ("array") the "collection_expression".
5858 object_expression must be an lvalue of type "id" (a generic Objective-C
5859 object) because the loop works by assigning to object_expression the
5860 various objects from the collection_expression. collection_expression
5861 must evaluate to something of type "id" which responds to the method
5862 countByEnumeratingWithState:objects:count:.
5864 The canonical example of the second variant is:
5865 for (id object in array) { do something with object }
5866 which is completely equivalent to
5869 for (object in array) { do something with object }
5871 Note that initizializing 'object' in some way (eg, "for ((object =
5872 xxx) in array) { do something with object }") is possibly
5873 technically valid, but completely pointless as 'object' will be
5874 assigned to something else as soon as the loop starts. We should
5875 most likely reject it (TODO).
5877 The beginning of the Objective-C foreach-statement looks exactly
5878 like the beginning of the for-statement, and we can tell it is a
5879 foreach-statement only because the initial declaration or
5880 expression is terminated by 'in' instead of ';'.
5882 IF_P is used to track whether there's a (possibly labeled) if statement
5883 which is not enclosed in braces and has an else clause. This is used to
5884 implement -Wparentheses. */
5887 c_parser_for_statement (c_parser
*parser
, bool ivdep
, bool *if_p
)
5889 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5890 /* The following are only used when parsing an ObjC foreach statement. */
5891 tree object_expression
;
5892 /* Silence the bogus uninitialized warning. */
5893 tree collection_expression
= NULL
;
5894 location_t loc
= c_parser_peek_token (parser
)->location
;
5895 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5896 bool is_foreach_statement
= false;
5897 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5898 token_indent_info for_tinfo
5899 = get_token_indent_info (c_parser_peek_token (parser
));
5900 c_parser_consume_token (parser
);
5901 /* Open a compound statement in Objective-C as well, just in case this is
5902 as foreach expression. */
5903 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5904 cond
= error_mark_node
;
5905 incr
= error_mark_node
;
5906 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5908 /* Parse the initialization declaration or expression. */
5909 object_expression
= error_mark_node
;
5910 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5911 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5913 parser
->objc_could_be_foreach_context
= false;
5914 c_parser_consume_token (parser
);
5915 c_finish_expr_stmt (loc
, NULL_TREE
);
5917 else if (c_parser_next_tokens_start_declaration (parser
))
5919 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5920 &object_expression
, vNULL
);
5921 parser
->objc_could_be_foreach_context
= false;
5923 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5925 c_parser_consume_token (parser
);
5926 is_foreach_statement
= true;
5927 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5928 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5931 check_for_loop_decls (for_loc
, flag_isoc99
);
5933 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5935 /* __extension__ can start a declaration, but is also an
5936 unary operator that can start an expression. Consume all
5937 but the last of a possible series of __extension__ to
5939 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5940 && (c_parser_peek_2nd_token (parser
)->keyword
5942 c_parser_consume_token (parser
);
5943 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5946 ext
= disable_extension_diagnostics ();
5947 c_parser_consume_token (parser
);
5948 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5949 true, &object_expression
, vNULL
);
5950 parser
->objc_could_be_foreach_context
= false;
5952 restore_extension_diagnostics (ext
);
5953 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5955 c_parser_consume_token (parser
);
5956 is_foreach_statement
= true;
5957 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5958 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5961 check_for_loop_decls (for_loc
, flag_isoc99
);
5971 tree init_expression
;
5972 ce
= c_parser_expression (parser
);
5973 /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
5974 level statement", but it works just fine, so allow it. */
5975 init_expression
= ce
.value
;
5976 parser
->objc_could_be_foreach_context
= false;
5977 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5979 c_parser_consume_token (parser
);
5980 is_foreach_statement
= true;
5981 if (! lvalue_p (init_expression
))
5982 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5983 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5987 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5988 init_expression
= ce
.value
;
5989 c_finish_expr_stmt (loc
, init_expression
);
5990 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5994 /* Parse the loop condition. In the case of a foreach
5995 statement, there is no loop condition. */
5996 gcc_assert (!parser
->objc_could_be_foreach_context
);
5997 if (!is_foreach_statement
)
5999 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
6003 c_parser_error (parser
, "missing loop condition in loop with "
6004 "%<GCC ivdep%> pragma");
6005 cond
= error_mark_node
;
6009 c_parser_consume_token (parser
);
6015 cond
= c_parser_condition (parser
);
6016 if (check_no_cilk (cond
,
6017 "Cilk array notation cannot be used in a condition for a for-loop",
6018 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
6019 cond
= error_mark_node
;
6020 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
6023 if (ivdep
&& cond
!= error_mark_node
)
6024 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
6025 build_int_cst (integer_type_node
,
6026 annot_expr_ivdep_kind
));
6028 /* Parse the increment expression (the third expression in a
6029 for-statement). In the case of a foreach-statement, this is
6030 the expression that follows the 'in'. */
6031 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6033 if (is_foreach_statement
)
6035 c_parser_error (parser
, "missing collection in fast enumeration");
6036 collection_expression
= error_mark_node
;
6039 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
6043 if (is_foreach_statement
)
6044 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
6048 struct c_expr ce
= c_parser_expression (parser
);
6049 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6050 incr
= c_process_expr_stmt (loc
, ce
.value
);
6053 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6055 save_break
= c_break_label
;
6056 c_break_label
= NULL_TREE
;
6057 save_cont
= c_cont_label
;
6058 c_cont_label
= NULL_TREE
;
6060 token_indent_info body_tinfo
6061 = get_token_indent_info (c_parser_peek_token (parser
));
6063 body
= c_parser_c99_block_statement (parser
, if_p
);
6065 if (is_foreach_statement
)
6066 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
6068 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
6069 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
6070 c_parser_maybe_reclassify_token (parser
);
6072 token_indent_info next_tinfo
6073 = get_token_indent_info (c_parser_peek_token (parser
));
6074 warn_for_misleading_indentation (for_tinfo
, body_tinfo
, next_tinfo
);
6076 c_break_label
= save_break
;
6077 c_cont_label
= save_cont
;
6080 /* Parse an asm statement, a GNU extension. This is a full-blown asm
6081 statement with inputs, outputs, clobbers, and volatile tag
6085 asm type-qualifier[opt] ( asm-argument ) ;
6086 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
6090 asm-string-literal : asm-operands[opt]
6091 asm-string-literal : asm-operands[opt] : asm-operands[opt]
6092 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
6095 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
6098 Qualifiers other than volatile are accepted in the syntax but
6102 c_parser_asm_statement (c_parser
*parser
)
6104 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
6105 bool simple
, is_goto
;
6106 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
6107 int section
, nsections
;
6109 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
6110 c_parser_consume_token (parser
);
6111 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
6113 quals
= c_parser_peek_token (parser
)->value
;
6114 c_parser_consume_token (parser
);
6116 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
6117 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
6119 warning_at (c_parser_peek_token (parser
)->location
,
6121 "%E qualifier ignored on asm",
6122 c_parser_peek_token (parser
)->value
);
6124 c_parser_consume_token (parser
);
6130 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
6132 c_parser_consume_token (parser
);
6136 /* ??? Follow the C++ parser rather than using the
6137 lex_untranslated_string kludge. */
6138 parser
->lex_untranslated_string
= true;
6141 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6144 str
= c_parser_asm_string_literal (parser
);
6145 if (str
== NULL_TREE
)
6146 goto error_close_paren
;
6149 outputs
= NULL_TREE
;
6151 clobbers
= NULL_TREE
;
6154 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6157 /* Parse each colon-delimited section of operands. */
6158 nsections
= 3 + is_goto
;
6159 for (section
= 0; section
< nsections
; ++section
)
6161 if (!c_parser_require (parser
, CPP_COLON
,
6163 ? G_("expected %<:%>")
6164 : G_("expected %<:%> or %<)%>")))
6165 goto error_close_paren
;
6167 /* Once past any colon, we're no longer a simple asm. */
6170 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
6171 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6176 /* For asm goto, we don't allow output operands, but reserve
6177 the slot for a future extension that does allow them. */
6179 outputs
= c_parser_asm_operands (parser
);
6182 inputs
= c_parser_asm_operands (parser
);
6185 clobbers
= c_parser_asm_clobbers (parser
);
6188 labels
= c_parser_asm_goto_operands (parser
);
6194 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6199 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6201 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6205 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6206 c_parser_skip_to_end_of_block_or_statement (parser
);
6208 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
6209 clobbers
, labels
, simple
));
6212 parser
->lex_untranslated_string
= false;
6216 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6220 /* Parse asm operands, a GNU extension.
6224 asm-operands , asm-operand
6227 asm-string-literal ( expression )
6228 [ identifier ] asm-string-literal ( expression )
6232 c_parser_asm_operands (c_parser
*parser
)
6234 tree list
= NULL_TREE
;
6239 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
6241 c_parser_consume_token (parser
);
6242 if (c_parser_next_token_is (parser
, CPP_NAME
))
6244 tree id
= c_parser_peek_token (parser
)->value
;
6245 c_parser_consume_token (parser
);
6246 name
= build_string (IDENTIFIER_LENGTH (id
),
6247 IDENTIFIER_POINTER (id
));
6251 c_parser_error (parser
, "expected identifier");
6252 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
6255 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6260 str
= c_parser_asm_string_literal (parser
);
6261 if (str
== NULL_TREE
)
6263 parser
->lex_untranslated_string
= false;
6264 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6266 parser
->lex_untranslated_string
= true;
6269 expr
= c_parser_expression (parser
);
6270 mark_exp_read (expr
.value
);
6271 parser
->lex_untranslated_string
= true;
6272 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6274 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6277 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
6279 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6280 c_parser_consume_token (parser
);
6287 /* Parse asm clobbers, a GNU extension.
6291 asm-clobbers , asm-string-literal
6295 c_parser_asm_clobbers (c_parser
*parser
)
6297 tree list
= NULL_TREE
;
6300 tree str
= c_parser_asm_string_literal (parser
);
6302 list
= tree_cons (NULL_TREE
, str
, list
);
6305 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6306 c_parser_consume_token (parser
);
6313 /* Parse asm goto labels, a GNU extension.
6317 asm-goto-operands , identifier
6321 c_parser_asm_goto_operands (c_parser
*parser
)
6323 tree list
= NULL_TREE
;
6328 if (c_parser_next_token_is (parser
, CPP_NAME
))
6330 c_token
*tok
= c_parser_peek_token (parser
);
6332 label
= lookup_label_for_goto (tok
->location
, name
);
6333 c_parser_consume_token (parser
);
6334 TREE_USED (label
) = 1;
6338 c_parser_error (parser
, "expected identifier");
6342 name
= build_string (IDENTIFIER_LENGTH (name
),
6343 IDENTIFIER_POINTER (name
));
6344 list
= tree_cons (name
, label
, list
);
6345 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6346 c_parser_consume_token (parser
);
6348 return nreverse (list
);
6352 /* Parse an expression other than a compound expression; that is, an
6353 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
6354 NULL then it is an Objective-C message expression which is the
6355 primary-expression starting the expression as an initializer.
6357 assignment-expression:
6358 conditional-expression
6359 unary-expression assignment-operator assignment-expression
6361 assignment-operator: one of
6362 = *= /= %= += -= <<= >>= &= ^= |=
6364 In GNU C we accept any conditional expression on the LHS and
6365 diagnose the invalid lvalue rather than producing a syntax
6368 static struct c_expr
6369 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
6370 tree omp_atomic_lhs
)
6372 struct c_expr lhs
, rhs
, ret
;
6373 enum tree_code code
;
6374 location_t op_location
, exp_location
;
6375 gcc_assert (!after
|| c_dialect_objc ());
6376 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
6377 op_location
= c_parser_peek_token (parser
)->location
;
6378 switch (c_parser_peek_token (parser
)->type
)
6387 code
= TRUNC_DIV_EXPR
;
6390 code
= TRUNC_MOD_EXPR
;
6405 code
= BIT_AND_EXPR
;
6408 code
= BIT_XOR_EXPR
;
6411 code
= BIT_IOR_EXPR
;
6416 c_parser_consume_token (parser
);
6417 exp_location
= c_parser_peek_token (parser
)->location
;
6418 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6419 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6421 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6422 code
, exp_location
, rhs
.value
,
6424 set_c_expr_source_range (&ret
, lhs
.get_start (), rhs
.get_finish ());
6425 if (code
== NOP_EXPR
)
6426 ret
.original_code
= MODIFY_EXPR
;
6429 TREE_NO_WARNING (ret
.value
) = 1;
6430 ret
.original_code
= ERROR_MARK
;
6432 ret
.original_type
= NULL
;
6436 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
6437 is not NULL then it is an Objective-C message expression which is
6438 the primary-expression starting the expression as an initializer.
6440 conditional-expression:
6441 logical-OR-expression
6442 logical-OR-expression ? expression : conditional-expression
6446 conditional-expression:
6447 logical-OR-expression ? : conditional-expression
6450 static struct c_expr
6451 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6452 tree omp_atomic_lhs
)
6454 struct c_expr cond
, exp1
, exp2
, ret
;
6455 location_t start
, cond_loc
, colon_loc
, middle_loc
;
6457 gcc_assert (!after
|| c_dialect_objc ());
6459 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6461 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6463 if (cond
.value
!= error_mark_node
)
6464 start
= cond
.get_start ();
6466 start
= UNKNOWN_LOCATION
;
6467 cond_loc
= c_parser_peek_token (parser
)->location
;
6468 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6469 c_parser_consume_token (parser
);
6470 if (c_parser_next_token_is (parser
, CPP_COLON
))
6472 tree eptype
= NULL_TREE
;
6474 middle_loc
= c_parser_peek_token (parser
)->location
;
6475 pedwarn (middle_loc
, OPT_Wpedantic
,
6476 "ISO C forbids omitting the middle term of a ?: expression");
6477 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6479 eptype
= TREE_TYPE (cond
.value
);
6480 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6482 tree e
= cond
.value
;
6483 while (TREE_CODE (e
) == COMPOUND_EXPR
)
6484 e
= TREE_OPERAND (e
, 1);
6485 warn_for_omitted_condop (middle_loc
, e
);
6486 /* Make sure first operand is calculated only once. */
6487 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
6489 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6490 exp1
.original_type
= NULL
;
6491 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6492 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6497 = c_objc_common_truthvalue_conversion
6498 (cond_loc
, default_conversion (cond
.value
));
6499 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6500 exp1
= c_parser_expression_conv (parser
);
6501 mark_exp_read (exp1
.value
);
6502 c_inhibit_evaluation_warnings
+=
6503 ((cond
.value
== truthvalue_true_node
)
6504 - (cond
.value
== truthvalue_false_node
));
6507 colon_loc
= c_parser_peek_token (parser
)->location
;
6508 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6510 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6511 ret
.value
= error_mark_node
;
6512 ret
.original_code
= ERROR_MARK
;
6513 ret
.original_type
= NULL
;
6517 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6518 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6519 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6521 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6522 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6523 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6524 exp1
.value
, exp1
.original_type
,
6525 exp2
.value
, exp2
.original_type
);
6526 ret
.original_code
= ERROR_MARK
;
6527 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6528 ret
.original_type
= NULL
;
6533 /* If both sides are enum type, the default conversion will have
6534 made the type of the result be an integer type. We want to
6535 remember the enum types we started with. */
6536 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6537 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6538 ret
.original_type
= ((t1
!= error_mark_node
6539 && t2
!= error_mark_node
6540 && (TYPE_MAIN_VARIANT (t1
)
6541 == TYPE_MAIN_VARIANT (t2
)))
6545 set_c_expr_source_range (&ret
, start
, exp2
.get_finish ());
6549 /* Parse a binary expression; that is, a logical-OR-expression (C90
6550 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6551 an Objective-C message expression which is the primary-expression
6552 starting the expression as an initializer.
6554 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6555 when it should be the unfolded lhs. In a valid OpenMP source,
6556 one of the operands of the toplevel binary expression must be equal
6557 to it. In that case, just return a build2 created binary operation
6558 rather than result of parser_build_binary_op.
6560 multiplicative-expression:
6562 multiplicative-expression * cast-expression
6563 multiplicative-expression / cast-expression
6564 multiplicative-expression % cast-expression
6566 additive-expression:
6567 multiplicative-expression
6568 additive-expression + multiplicative-expression
6569 additive-expression - multiplicative-expression
6573 shift-expression << additive-expression
6574 shift-expression >> additive-expression
6576 relational-expression:
6578 relational-expression < shift-expression
6579 relational-expression > shift-expression
6580 relational-expression <= shift-expression
6581 relational-expression >= shift-expression
6583 equality-expression:
6584 relational-expression
6585 equality-expression == relational-expression
6586 equality-expression != relational-expression
6590 AND-expression & equality-expression
6592 exclusive-OR-expression:
6594 exclusive-OR-expression ^ AND-expression
6596 inclusive-OR-expression:
6597 exclusive-OR-expression
6598 inclusive-OR-expression | exclusive-OR-expression
6600 logical-AND-expression:
6601 inclusive-OR-expression
6602 logical-AND-expression && inclusive-OR-expression
6604 logical-OR-expression:
6605 logical-AND-expression
6606 logical-OR-expression || logical-AND-expression
6609 static struct c_expr
6610 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6611 tree omp_atomic_lhs
)
6613 /* A binary expression is parsed using operator-precedence parsing,
6614 with the operands being cast expressions. All the binary
6615 operators are left-associative. Thus a binary expression is of
6618 E0 op1 E1 op2 E2 ...
6620 which we represent on a stack. On the stack, the precedence
6621 levels are strictly increasing. When a new operator is
6622 encountered of higher precedence than that at the top of the
6623 stack, it is pushed; its LHS is the top expression, and its RHS
6624 is everything parsed until it is popped. When a new operator is
6625 encountered with precedence less than or equal to that at the top
6626 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6627 by the result of the operation until the operator at the top of
6628 the stack has lower precedence than the new operator or there is
6629 only one element on the stack; then the top expression is the LHS
6630 of the new operator. In the case of logical AND and OR
6631 expressions, we also need to adjust c_inhibit_evaluation_warnings
6632 as appropriate when the operators are pushed and popped. */
6635 /* The expression at this stack level. */
6637 /* The precedence of the operator on its left, PREC_NONE at the
6638 bottom of the stack. */
6639 enum c_parser_prec prec
;
6640 /* The operation on its left. */
6642 /* The source location of this operation. */
6646 /* Location of the binary operator. */
6647 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6650 switch (stack[sp].op) \
6652 case TRUTH_ANDIF_EXPR: \
6653 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6654 == truthvalue_false_node); \
6656 case TRUTH_ORIF_EXPR: \
6657 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6658 == truthvalue_true_node); \
6663 stack[sp - 1].expr \
6664 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6665 stack[sp - 1].expr, true, true); \
6667 = convert_lvalue_to_rvalue (stack[sp].loc, \
6668 stack[sp].expr, true, true); \
6669 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6670 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6671 && ((1 << stack[sp].prec) \
6672 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6673 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6674 && stack[sp].op != TRUNC_MOD_EXPR \
6675 && stack[0].expr.value != error_mark_node \
6676 && stack[1].expr.value != error_mark_node \
6677 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6678 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6679 stack[0].expr.value \
6680 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6681 stack[0].expr.value, stack[1].expr.value); \
6683 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6685 stack[sp - 1].expr, \
6689 gcc_assert (!after
|| c_dialect_objc ());
6690 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6691 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6692 stack
[0].prec
= PREC_NONE
;
6696 enum c_parser_prec oprec
;
6697 enum tree_code ocode
;
6698 source_range src_range
;
6701 switch (c_parser_peek_token (parser
)->type
)
6709 ocode
= TRUNC_DIV_EXPR
;
6713 ocode
= TRUNC_MOD_EXPR
;
6725 ocode
= LSHIFT_EXPR
;
6729 ocode
= RSHIFT_EXPR
;
6743 case CPP_GREATER_EQ
:
6756 oprec
= PREC_BITAND
;
6757 ocode
= BIT_AND_EXPR
;
6760 oprec
= PREC_BITXOR
;
6761 ocode
= BIT_XOR_EXPR
;
6765 ocode
= BIT_IOR_EXPR
;
6768 oprec
= PREC_LOGAND
;
6769 ocode
= TRUTH_ANDIF_EXPR
;
6773 ocode
= TRUTH_ORIF_EXPR
;
6776 /* Not a binary operator, so end of the binary
6780 binary_loc
= c_parser_peek_token (parser
)->location
;
6781 while (oprec
<= stack
[sp
].prec
)
6783 c_parser_consume_token (parser
);
6786 case TRUTH_ANDIF_EXPR
:
6787 src_range
= stack
[sp
].expr
.src_range
;
6789 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6790 stack
[sp
].expr
, true, true);
6791 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6792 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6793 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6794 == truthvalue_false_node
);
6795 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
6797 case TRUTH_ORIF_EXPR
:
6798 src_range
= stack
[sp
].expr
.src_range
;
6800 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6801 stack
[sp
].expr
, true, true);
6802 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6803 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6804 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6805 == truthvalue_true_node
);
6806 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
6812 stack
[sp
].loc
= binary_loc
;
6813 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6814 stack
[sp
].prec
= oprec
;
6815 stack
[sp
].op
= ocode
;
6820 return stack
[0].expr
;
6824 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6825 NULL then it is an Objective-C message expression which is the
6826 primary-expression starting the expression as an initializer.
6830 ( type-name ) unary-expression
6833 static struct c_expr
6834 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6836 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6837 gcc_assert (!after
|| c_dialect_objc ());
6839 return c_parser_postfix_expression_after_primary (parser
,
6841 /* If the expression begins with a parenthesized type name, it may
6842 be either a cast or a compound literal; we need to see whether
6843 the next character is '{' to tell the difference. If not, it is
6844 an unary expression. Full detection of unknown typenames here
6845 would require a 3-token lookahead. */
6846 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6847 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6849 struct c_type_name
*type_name
;
6852 c_parser_consume_token (parser
);
6853 type_name
= c_parser_type_name (parser
);
6854 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6855 if (type_name
== NULL
)
6857 ret
.value
= error_mark_node
;
6858 ret
.original_code
= ERROR_MARK
;
6859 ret
.original_type
= NULL
;
6863 /* Save casted types in the function's used types hash table. */
6864 used_types_insert (type_name
->specs
->type
);
6866 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6867 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6870 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6871 expr
= c_parser_cast_expression (parser
, NULL
);
6872 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6874 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6875 if (ret
.value
&& expr
.value
)
6876 set_c_expr_source_range (&ret
, cast_loc
, expr
.get_finish ());
6877 ret
.original_code
= ERROR_MARK
;
6878 ret
.original_type
= NULL
;
6882 return c_parser_unary_expression (parser
);
6885 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6891 unary-operator cast-expression
6892 sizeof unary-expression
6893 sizeof ( type-name )
6895 unary-operator: one of
6901 __alignof__ unary-expression
6902 __alignof__ ( type-name )
6905 (C11 permits _Alignof with type names only.)
6907 unary-operator: one of
6908 __extension__ __real__ __imag__
6910 Transactional Memory:
6913 transaction-expression
6915 In addition, the GNU syntax treats ++ and -- as unary operators, so
6916 they may be applied to cast expressions with errors for non-lvalues
6919 static struct c_expr
6920 c_parser_unary_expression (c_parser
*parser
)
6923 struct c_expr ret
, op
;
6924 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6927 ret
.original_code
= ERROR_MARK
;
6928 ret
.original_type
= NULL
;
6929 switch (c_parser_peek_token (parser
)->type
)
6932 c_parser_consume_token (parser
);
6933 exp_loc
= c_parser_peek_token (parser
)->location
;
6934 op
= c_parser_cast_expression (parser
, NULL
);
6936 /* If there is array notations in op, we expand them. */
6937 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6938 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6941 op
= default_function_array_read_conversion (exp_loc
, op
);
6942 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6944 case CPP_MINUS_MINUS
:
6945 c_parser_consume_token (parser
);
6946 exp_loc
= c_parser_peek_token (parser
)->location
;
6947 op
= c_parser_cast_expression (parser
, NULL
);
6949 /* If there is array notations in op, we expand them. */
6950 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6951 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6954 op
= default_function_array_read_conversion (exp_loc
, op
);
6955 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6958 c_parser_consume_token (parser
);
6959 op
= c_parser_cast_expression (parser
, NULL
);
6960 mark_exp_read (op
.value
);
6961 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6964 c_parser_consume_token (parser
);
6965 exp_loc
= c_parser_peek_token (parser
)->location
;
6966 op
= c_parser_cast_expression (parser
, NULL
);
6967 finish
= op
.get_finish ();
6968 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6969 location_t combined_loc
= make_location (op_loc
, op_loc
, finish
);
6970 ret
.value
= build_indirect_ref (combined_loc
, op
.value
, RO_UNARY_STAR
);
6971 ret
.src_range
.m_start
= op_loc
;
6972 ret
.src_range
.m_finish
= finish
;
6976 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6979 "traditional C rejects the unary plus operator");
6980 c_parser_consume_token (parser
);
6981 exp_loc
= c_parser_peek_token (parser
)->location
;
6982 op
= c_parser_cast_expression (parser
, NULL
);
6983 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6984 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6986 c_parser_consume_token (parser
);
6987 exp_loc
= c_parser_peek_token (parser
)->location
;
6988 op
= c_parser_cast_expression (parser
, NULL
);
6989 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6990 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6992 c_parser_consume_token (parser
);
6993 exp_loc
= c_parser_peek_token (parser
)->location
;
6994 op
= c_parser_cast_expression (parser
, NULL
);
6995 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6996 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6998 c_parser_consume_token (parser
);
6999 exp_loc
= c_parser_peek_token (parser
)->location
;
7000 op
= c_parser_cast_expression (parser
, NULL
);
7001 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
7002 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
7004 /* Refer to the address of a label as a pointer. */
7005 c_parser_consume_token (parser
);
7006 if (c_parser_next_token_is (parser
, CPP_NAME
))
7008 ret
.value
= finish_label_address_expr
7009 (c_parser_peek_token (parser
)->value
, op_loc
);
7010 set_c_expr_source_range (&ret
, op_loc
,
7011 c_parser_peek_token (parser
)->get_finish ());
7012 c_parser_consume_token (parser
);
7016 c_parser_error (parser
, "expected identifier");
7017 ret
.value
= error_mark_node
;
7021 switch (c_parser_peek_token (parser
)->keyword
)
7024 return c_parser_sizeof_expression (parser
);
7026 return c_parser_alignof_expression (parser
);
7028 c_parser_consume_token (parser
);
7029 ext
= disable_extension_diagnostics ();
7030 ret
= c_parser_cast_expression (parser
, NULL
);
7031 restore_extension_diagnostics (ext
);
7034 c_parser_consume_token (parser
);
7035 exp_loc
= c_parser_peek_token (parser
)->location
;
7036 op
= c_parser_cast_expression (parser
, NULL
);
7037 op
= default_function_array_conversion (exp_loc
, op
);
7038 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
7040 c_parser_consume_token (parser
);
7041 exp_loc
= c_parser_peek_token (parser
)->location
;
7042 op
= c_parser_cast_expression (parser
, NULL
);
7043 op
= default_function_array_conversion (exp_loc
, op
);
7044 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
7045 case RID_TRANSACTION_ATOMIC
:
7046 case RID_TRANSACTION_RELAXED
:
7047 return c_parser_transaction_expression (parser
,
7048 c_parser_peek_token (parser
)->keyword
);
7050 return c_parser_postfix_expression (parser
);
7053 return c_parser_postfix_expression (parser
);
7057 /* Parse a sizeof expression. */
7059 static struct c_expr
7060 c_parser_sizeof_expression (c_parser
*parser
)
7063 struct c_expr result
;
7064 location_t expr_loc
;
7065 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
7068 location_t finish
= UNKNOWN_LOCATION
;
7070 start
= c_parser_peek_token (parser
)->location
;
7072 c_parser_consume_token (parser
);
7073 c_inhibit_evaluation_warnings
++;
7075 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7076 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7078 /* Either sizeof ( type-name ) or sizeof unary-expression
7079 starting with a compound literal. */
7080 struct c_type_name
*type_name
;
7081 c_parser_consume_token (parser
);
7082 expr_loc
= c_parser_peek_token (parser
)->location
;
7083 type_name
= c_parser_type_name (parser
);
7084 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7085 finish
= parser
->tokens_buf
[0].location
;
7086 if (type_name
== NULL
)
7089 c_inhibit_evaluation_warnings
--;
7091 ret
.value
= error_mark_node
;
7092 ret
.original_code
= ERROR_MARK
;
7093 ret
.original_type
= NULL
;
7096 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7098 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7101 finish
= expr
.get_finish ();
7104 /* sizeof ( type-name ). */
7105 c_inhibit_evaluation_warnings
--;
7107 result
= c_expr_sizeof_type (expr_loc
, type_name
);
7111 expr_loc
= c_parser_peek_token (parser
)->location
;
7112 expr
= c_parser_unary_expression (parser
);
7113 finish
= expr
.get_finish ();
7115 c_inhibit_evaluation_warnings
--;
7117 mark_exp_read (expr
.value
);
7118 if (TREE_CODE (expr
.value
) == COMPONENT_REF
7119 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
7120 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
7121 result
= c_expr_sizeof_expr (expr_loc
, expr
);
7123 if (finish
!= UNKNOWN_LOCATION
)
7124 set_c_expr_source_range (&result
, start
, finish
);
7128 /* Parse an alignof expression. */
7130 static struct c_expr
7131 c_parser_alignof_expression (c_parser
*parser
)
7134 location_t start_loc
= c_parser_peek_token (parser
)->location
;
7136 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
7137 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
7138 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
7140 /* A diagnostic is not required for the use of this identifier in
7141 the implementation namespace; only diagnose it for the C11
7142 spelling because of existing code using the other spellings. */
7146 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
7149 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
7152 c_parser_consume_token (parser
);
7153 c_inhibit_evaluation_warnings
++;
7155 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7156 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7158 /* Either __alignof__ ( type-name ) or __alignof__
7159 unary-expression starting with a compound literal. */
7161 struct c_type_name
*type_name
;
7163 c_parser_consume_token (parser
);
7164 loc
= c_parser_peek_token (parser
)->location
;
7165 type_name
= c_parser_type_name (parser
);
7166 end_loc
= c_parser_peek_token (parser
)->location
;
7167 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7168 if (type_name
== NULL
)
7171 c_inhibit_evaluation_warnings
--;
7173 ret
.value
= error_mark_node
;
7174 ret
.original_code
= ERROR_MARK
;
7175 ret
.original_type
= NULL
;
7178 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7180 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7185 /* alignof ( type-name ). */
7186 c_inhibit_evaluation_warnings
--;
7188 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
7190 false, is_c11_alignof
, 1);
7191 ret
.original_code
= ERROR_MARK
;
7192 ret
.original_type
= NULL
;
7193 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7199 expr
= c_parser_unary_expression (parser
);
7200 end_loc
= expr
.src_range
.m_finish
;
7202 mark_exp_read (expr
.value
);
7203 c_inhibit_evaluation_warnings
--;
7207 OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
7209 ret
.value
= c_alignof_expr (start_loc
, expr
.value
);
7210 ret
.original_code
= ERROR_MARK
;
7211 ret
.original_type
= NULL
;
7212 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7217 /* Helper function to read arguments of builtins which are interfaces
7218 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
7219 others. The name of the builtin is passed using BNAME parameter.
7220 Function returns true if there were no errors while parsing and
7221 stores the arguments in CEXPR_LIST. If it returns true,
7222 *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
7225 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
7226 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
7228 location_t
*out_close_paren_loc
)
7230 location_t loc
= c_parser_peek_token (parser
)->location
;
7231 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7233 bool saved_force_folding_builtin_constant_p
;
7235 *ret_cexpr_list
= NULL
;
7236 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
7238 error_at (loc
, "cannot take address of %qs", bname
);
7242 c_parser_consume_token (parser
);
7244 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7246 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7247 c_parser_consume_token (parser
);
7251 saved_force_folding_builtin_constant_p
7252 = force_folding_builtin_constant_p
;
7253 force_folding_builtin_constant_p
|= choose_expr_p
;
7254 expr
= c_parser_expr_no_commas (parser
, NULL
);
7255 force_folding_builtin_constant_p
7256 = saved_force_folding_builtin_constant_p
;
7257 vec_alloc (cexpr_list
, 1);
7258 vec_safe_push (cexpr_list
, expr
);
7259 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7261 c_parser_consume_token (parser
);
7262 expr
= c_parser_expr_no_commas (parser
, NULL
);
7263 vec_safe_push (cexpr_list
, expr
);
7266 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7267 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7270 *ret_cexpr_list
= cexpr_list
;
7274 /* This represents a single generic-association. */
7276 struct c_generic_association
7278 /* The location of the starting token of the type. */
7279 location_t type_location
;
7280 /* The association's type, or NULL_TREE for 'default'. */
7282 /* The association's expression. */
7283 struct c_expr expression
;
7286 /* Parse a generic-selection. (C11 6.5.1.1).
7289 _Generic ( assignment-expression , generic-assoc-list )
7293 generic-assoc-list , generic-association
7295 generic-association:
7296 type-name : assignment-expression
7297 default : assignment-expression
7300 static struct c_expr
7301 c_parser_generic_selection (c_parser
*parser
)
7303 struct c_expr selector
, error_expr
;
7305 struct c_generic_association matched_assoc
;
7306 bool match_found
= false;
7307 location_t generic_loc
, selector_loc
;
7309 error_expr
.original_code
= ERROR_MARK
;
7310 error_expr
.original_type
= NULL
;
7311 error_expr
.set_error ();
7312 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
7313 matched_assoc
.type
= NULL_TREE
;
7314 matched_assoc
.expression
= error_expr
;
7316 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
7317 generic_loc
= c_parser_peek_token (parser
)->location
;
7318 c_parser_consume_token (parser
);
7320 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7321 "ISO C99 does not support %<_Generic%>");
7323 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7324 "ISO C90 does not support %<_Generic%>");
7326 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7329 c_inhibit_evaluation_warnings
++;
7330 selector_loc
= c_parser_peek_token (parser
)->location
;
7331 selector
= c_parser_expr_no_commas (parser
, NULL
);
7332 selector
= default_function_array_conversion (selector_loc
, selector
);
7333 c_inhibit_evaluation_warnings
--;
7335 if (selector
.value
== error_mark_node
)
7337 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7340 selector_type
= TREE_TYPE (selector
.value
);
7341 /* In ISO C terms, rvalues (including the controlling expression of
7342 _Generic) do not have qualified types. */
7343 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
7344 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
7345 /* In ISO C terms, _Noreturn is not part of the type of expressions
7346 such as &abort, but in GCC it is represented internally as a type
7348 if (FUNCTION_POINTER_TYPE_P (selector_type
)
7349 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
7351 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
7353 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7355 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7359 auto_vec
<c_generic_association
> associations
;
7362 struct c_generic_association assoc
, *iter
;
7364 c_token
*token
= c_parser_peek_token (parser
);
7366 assoc
.type_location
= token
->location
;
7367 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
7369 c_parser_consume_token (parser
);
7370 assoc
.type
= NULL_TREE
;
7374 struct c_type_name
*type_name
;
7376 type_name
= c_parser_type_name (parser
);
7377 if (type_name
== NULL
)
7379 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7382 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
7383 if (assoc
.type
== error_mark_node
)
7385 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7389 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
7390 error_at (assoc
.type_location
,
7391 "%<_Generic%> association has function type");
7392 else if (!COMPLETE_TYPE_P (assoc
.type
))
7393 error_at (assoc
.type_location
,
7394 "%<_Generic%> association has incomplete type");
7396 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
7397 error_at (assoc
.type_location
,
7398 "%<_Generic%> association has "
7399 "variable length type");
7402 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7404 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7408 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
7409 if (assoc
.expression
.value
== error_mark_node
)
7411 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7415 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
7417 if (assoc
.type
== NULL_TREE
)
7419 if (iter
->type
== NULL_TREE
)
7421 error_at (assoc
.type_location
,
7422 "duplicate %<default%> case in %<_Generic%>");
7423 inform (iter
->type_location
, "original %<default%> is here");
7426 else if (iter
->type
!= NULL_TREE
)
7428 if (comptypes (assoc
.type
, iter
->type
))
7430 error_at (assoc
.type_location
,
7431 "%<_Generic%> specifies two compatible types");
7432 inform (iter
->type_location
, "compatible type is here");
7437 if (assoc
.type
== NULL_TREE
)
7441 matched_assoc
= assoc
;
7445 else if (comptypes (assoc
.type
, selector_type
))
7447 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7449 matched_assoc
= assoc
;
7454 error_at (assoc
.type_location
,
7455 "%<_Generic%> selector matches multiple associations");
7456 inform (matched_assoc
.type_location
,
7457 "other match is here");
7461 associations
.safe_push (assoc
);
7463 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7465 c_parser_consume_token (parser
);
7468 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7470 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7476 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7477 "compatible with any association",
7482 return matched_assoc
.expression
;
7485 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
7489 postfix-expression [ expression ]
7490 postfix-expression ( argument-expression-list[opt] )
7491 postfix-expression . identifier
7492 postfix-expression -> identifier
7493 postfix-expression ++
7494 postfix-expression --
7495 ( type-name ) { initializer-list }
7496 ( type-name ) { initializer-list , }
7498 argument-expression-list:
7500 argument-expression-list , argument-expression
7513 (treated as a keyword in GNU C)
7516 ( compound-statement )
7517 __builtin_va_arg ( assignment-expression , type-name )
7518 __builtin_offsetof ( type-name , offsetof-member-designator )
7519 __builtin_choose_expr ( assignment-expression ,
7520 assignment-expression ,
7521 assignment-expression )
7522 __builtin_types_compatible_p ( type-name , type-name )
7523 __builtin_complex ( assignment-expression , assignment-expression )
7524 __builtin_shuffle ( assignment-expression , assignment-expression )
7525 __builtin_shuffle ( assignment-expression ,
7526 assignment-expression ,
7527 assignment-expression, )
7529 offsetof-member-designator:
7531 offsetof-member-designator . identifier
7532 offsetof-member-designator [ expression ]
7537 [ objc-receiver objc-message-args ]
7538 @selector ( objc-selector-arg )
7539 @protocol ( identifier )
7540 @encode ( type-name )
7542 Classname . identifier
7545 static struct c_expr
7546 c_parser_postfix_expression (c_parser
*parser
)
7548 struct c_expr expr
, e1
;
7549 struct c_type_name
*t1
, *t2
;
7550 location_t loc
= c_parser_peek_token (parser
)->location
;;
7551 source_range tok_range
= c_parser_peek_token (parser
)->get_range ();
7552 expr
.original_code
= ERROR_MARK
;
7553 expr
.original_type
= NULL
;
7554 switch (c_parser_peek_token (parser
)->type
)
7557 expr
.value
= c_parser_peek_token (parser
)->value
;
7558 set_c_expr_source_range (&expr
, tok_range
);
7559 loc
= c_parser_peek_token (parser
)->location
;
7560 c_parser_consume_token (parser
);
7561 if (TREE_CODE (expr
.value
) == FIXED_CST
7562 && !targetm
.fixed_point_supported_p ())
7564 error_at (loc
, "fixed-point types not supported for this target");
7565 expr
.value
= error_mark_node
;
7572 expr
.value
= c_parser_peek_token (parser
)->value
;
7573 /* For the purpose of warning when a pointer is compared with
7574 a zero character constant. */
7575 expr
.original_type
= char_type_node
;
7576 set_c_expr_source_range (&expr
, tok_range
);
7577 c_parser_consume_token (parser
);
7583 case CPP_UTF8STRING
:
7584 expr
.value
= c_parser_peek_token (parser
)->value
;
7585 set_c_expr_source_range (&expr
, tok_range
);
7586 expr
.original_code
= STRING_CST
;
7587 c_parser_consume_token (parser
);
7589 case CPP_OBJC_STRING
:
7590 gcc_assert (c_dialect_objc ());
7592 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7593 set_c_expr_source_range (&expr
, tok_range
);
7594 c_parser_consume_token (parser
);
7597 switch (c_parser_peek_token (parser
)->id_kind
)
7601 tree id
= c_parser_peek_token (parser
)->value
;
7602 c_parser_consume_token (parser
);
7603 expr
.value
= build_external_ref (loc
, id
,
7604 (c_parser_peek_token (parser
)->type
7606 &expr
.original_type
);
7607 set_c_expr_source_range (&expr
, tok_range
);
7610 case C_ID_CLASSNAME
:
7612 /* Here we parse the Objective-C 2.0 Class.name dot
7614 tree class_name
= c_parser_peek_token (parser
)->value
;
7616 c_parser_consume_token (parser
);
7617 gcc_assert (c_dialect_objc ());
7618 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7623 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7625 c_parser_error (parser
, "expected identifier");
7629 c_token
*component_tok
= c_parser_peek_token (parser
);
7630 component
= component_tok
->value
;
7631 location_t end_loc
= component_tok
->get_finish ();
7632 c_parser_consume_token (parser
);
7633 expr
.value
= objc_build_class_component_ref (class_name
,
7635 set_c_expr_source_range (&expr
, loc
, end_loc
);
7639 c_parser_error (parser
, "expected expression");
7644 case CPP_OPEN_PAREN
:
7645 /* A parenthesized expression, statement expression or compound
7647 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7649 /* A statement expression. */
7651 location_t brace_loc
;
7652 c_parser_consume_token (parser
);
7653 brace_loc
= c_parser_peek_token (parser
)->location
;
7654 c_parser_consume_token (parser
);
7655 if (!building_stmt_list_p ())
7657 error_at (loc
, "braced-group within expression allowed "
7658 "only inside a function");
7659 parser
->error
= true;
7660 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7661 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7665 stmt
= c_begin_stmt_expr ();
7666 c_parser_compound_statement_nostart (parser
);
7667 location_t close_loc
= c_parser_peek_token (parser
)->location
;
7668 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7670 pedwarn (loc
, OPT_Wpedantic
,
7671 "ISO C forbids braced-groups within expressions");
7672 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7673 set_c_expr_source_range (&expr
, loc
, close_loc
);
7674 mark_exp_read (expr
.value
);
7676 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7678 /* A compound literal. ??? Can we actually get here rather
7679 than going directly to
7680 c_parser_postfix_expression_after_paren_type from
7683 struct c_type_name
*type_name
;
7684 c_parser_consume_token (parser
);
7685 loc
= c_parser_peek_token (parser
)->location
;
7686 type_name
= c_parser_type_name (parser
);
7687 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7689 if (type_name
== NULL
)
7694 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7700 /* A parenthesized expression. */
7701 location_t loc_open_paren
= c_parser_peek_token (parser
)->location
;
7702 c_parser_consume_token (parser
);
7703 expr
= c_parser_expression (parser
);
7704 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7705 TREE_NO_WARNING (expr
.value
) = 1;
7706 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7707 expr
.original_code
= ERROR_MARK
;
7708 /* Don't change EXPR.ORIGINAL_TYPE. */
7709 location_t loc_close_paren
= c_parser_peek_token (parser
)->location
;
7710 set_c_expr_source_range (&expr
, loc_open_paren
, loc_close_paren
);
7711 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7716 switch (c_parser_peek_token (parser
)->keyword
)
7718 case RID_FUNCTION_NAME
:
7719 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7720 "%<__FUNCTION__%> predefined identifier");
7721 expr
.value
= fname_decl (loc
,
7722 c_parser_peek_token (parser
)->keyword
,
7723 c_parser_peek_token (parser
)->value
);
7724 set_c_expr_source_range (&expr
, loc
, loc
);
7725 c_parser_consume_token (parser
);
7727 case RID_PRETTY_FUNCTION_NAME
:
7728 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7729 "%<__PRETTY_FUNCTION__%> predefined identifier");
7730 expr
.value
= fname_decl (loc
,
7731 c_parser_peek_token (parser
)->keyword
,
7732 c_parser_peek_token (parser
)->value
);
7733 set_c_expr_source_range (&expr
, loc
, loc
);
7734 c_parser_consume_token (parser
);
7736 case RID_C99_FUNCTION_NAME
:
7737 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7738 "%<__func__%> predefined identifier");
7739 expr
.value
= fname_decl (loc
,
7740 c_parser_peek_token (parser
)->keyword
,
7741 c_parser_peek_token (parser
)->value
);
7742 set_c_expr_source_range (&expr
, loc
, loc
);
7743 c_parser_consume_token (parser
);
7747 location_t start_loc
= loc
;
7748 c_parser_consume_token (parser
);
7749 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7754 e1
= c_parser_expr_no_commas (parser
, NULL
);
7755 mark_exp_read (e1
.value
);
7756 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7757 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7759 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7763 loc
= c_parser_peek_token (parser
)->location
;
7764 t1
= c_parser_type_name (parser
);
7765 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
7766 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7774 tree type_expr
= NULL_TREE
;
7775 expr
.value
= c_build_va_arg (start_loc
, e1
.value
, loc
,
7776 groktypename (t1
, &type_expr
, NULL
));
7779 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7780 TREE_TYPE (expr
.value
), type_expr
,
7782 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7784 set_c_expr_source_range (&expr
, start_loc
, end_loc
);
7789 c_parser_consume_token (parser
);
7790 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7795 t1
= c_parser_type_name (parser
);
7797 parser
->error
= true;
7798 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7799 gcc_assert (parser
->error
);
7802 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7808 tree type
= groktypename (t1
, NULL
, NULL
);
7810 if (type
== error_mark_node
)
7811 offsetof_ref
= error_mark_node
;
7814 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7815 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7817 /* Parse the second argument to __builtin_offsetof. We
7818 must have one identifier, and beyond that we want to
7819 accept sub structure and sub array references. */
7820 if (c_parser_next_token_is (parser
, CPP_NAME
))
7822 c_token
*comp_tok
= c_parser_peek_token (parser
);
7823 offsetof_ref
= build_component_ref
7824 (loc
, offsetof_ref
, comp_tok
->value
, comp_tok
->location
);
7825 c_parser_consume_token (parser
);
7826 while (c_parser_next_token_is (parser
, CPP_DOT
)
7827 || c_parser_next_token_is (parser
,
7829 || c_parser_next_token_is (parser
,
7832 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7834 loc
= c_parser_peek_token (parser
)->location
;
7835 offsetof_ref
= build_array_ref (loc
,
7840 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7843 c_parser_consume_token (parser
);
7844 if (c_parser_next_token_is_not (parser
,
7847 c_parser_error (parser
, "expected identifier");
7850 c_token
*comp_tok
= c_parser_peek_token (parser
);
7851 offsetof_ref
= build_component_ref
7852 (loc
, offsetof_ref
, comp_tok
->value
,
7853 comp_tok
->location
);
7854 c_parser_consume_token (parser
);
7860 loc
= c_parser_peek_token (parser
)->location
;
7861 c_parser_consume_token (parser
);
7862 ce
= c_parser_expression (parser
);
7863 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7865 idx
= c_fully_fold (idx
, false, NULL
);
7866 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7868 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7873 c_parser_error (parser
, "expected identifier");
7874 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
7875 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7877 expr
.value
= fold_offsetof (offsetof_ref
);
7878 set_c_expr_source_range (&expr
, loc
, end_loc
);
7881 case RID_CHOOSE_EXPR
:
7883 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7884 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7886 location_t close_paren_loc
;
7888 c_parser_consume_token (parser
);
7889 if (!c_parser_get_builtin_args (parser
,
7890 "__builtin_choose_expr",
7898 if (vec_safe_length (cexpr_list
) != 3)
7900 error_at (loc
, "wrong number of arguments to "
7901 "%<__builtin_choose_expr%>");
7906 e1_p
= &(*cexpr_list
)[0];
7907 e2_p
= &(*cexpr_list
)[1];
7908 e3_p
= &(*cexpr_list
)[2];
7911 mark_exp_read (e2_p
->value
);
7912 mark_exp_read (e3_p
->value
);
7913 if (TREE_CODE (c
) != INTEGER_CST
7914 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7916 "first argument to %<__builtin_choose_expr%> not"
7918 constant_expression_warning (c
);
7919 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7920 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
7923 case RID_TYPES_COMPATIBLE_P
:
7924 c_parser_consume_token (parser
);
7925 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7930 t1
= c_parser_type_name (parser
);
7936 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7938 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7942 t2
= c_parser_type_name (parser
);
7949 location_t close_paren_loc
= c_parser_peek_token (parser
)->location
;
7950 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7953 e1
= groktypename (t1
, NULL
, NULL
);
7954 e2
= groktypename (t2
, NULL
, NULL
);
7955 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7961 e1
= TYPE_MAIN_VARIANT (e1
);
7962 e2
= TYPE_MAIN_VARIANT (e2
);
7965 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7966 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
7969 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
7971 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7974 location_t close_paren_loc
;
7976 c_parser_consume_token (parser
);
7977 if (!c_parser_get_builtin_args (parser
,
7978 "__builtin_call_with_static_chain",
7985 if (vec_safe_length (cexpr_list
) != 2)
7987 error_at (loc
, "wrong number of arguments to "
7988 "%<__builtin_call_with_static_chain%>");
7993 expr
= (*cexpr_list
)[0];
7994 e2_p
= &(*cexpr_list
)[1];
7995 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7996 chain_value
= e2_p
->value
;
7997 mark_exp_read (chain_value
);
7999 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
8000 error_at (loc
, "first argument to "
8001 "%<__builtin_call_with_static_chain%> "
8002 "must be a call expression");
8003 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
8004 error_at (loc
, "second argument to "
8005 "%<__builtin_call_with_static_chain%> "
8006 "must be a pointer type");
8008 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
8009 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8012 case RID_BUILTIN_COMPLEX
:
8014 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8015 c_expr_t
*e1_p
, *e2_p
;
8016 location_t close_paren_loc
;
8018 c_parser_consume_token (parser
);
8019 if (!c_parser_get_builtin_args (parser
,
8020 "__builtin_complex",
8028 if (vec_safe_length (cexpr_list
) != 2)
8030 error_at (loc
, "wrong number of arguments to "
8031 "%<__builtin_complex%>");
8036 e1_p
= &(*cexpr_list
)[0];
8037 e2_p
= &(*cexpr_list
)[1];
8039 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
8040 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
8041 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
8042 TREE_OPERAND (e1_p
->value
, 0));
8043 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
8044 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
8045 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
8046 TREE_OPERAND (e2_p
->value
, 0));
8047 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8048 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8049 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
8050 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
8052 error_at (loc
, "%<__builtin_complex%> operand "
8053 "not of real binary floating-point type");
8057 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
8058 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
8061 "%<__builtin_complex%> operands of different types");
8065 pedwarn_c90 (loc
, OPT_Wpedantic
,
8066 "ISO C90 does not support complex types");
8067 expr
.value
= build2_loc (loc
, COMPLEX_EXPR
,
8070 (TREE_TYPE (e1_p
->value
))),
8071 e1_p
->value
, e2_p
->value
);
8072 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8075 case RID_BUILTIN_SHUFFLE
:
8077 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8080 location_t close_paren_loc
;
8082 c_parser_consume_token (parser
);
8083 if (!c_parser_get_builtin_args (parser
,
8084 "__builtin_shuffle",
8092 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
8093 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8095 if (vec_safe_length (cexpr_list
) == 2)
8097 c_build_vec_perm_expr
8098 (loc
, (*cexpr_list
)[0].value
,
8099 NULL_TREE
, (*cexpr_list
)[1].value
);
8101 else if (vec_safe_length (cexpr_list
) == 3)
8103 c_build_vec_perm_expr
8104 (loc
, (*cexpr_list
)[0].value
,
8105 (*cexpr_list
)[1].value
,
8106 (*cexpr_list
)[2].value
);
8109 error_at (loc
, "wrong number of arguments to "
8110 "%<__builtin_shuffle%>");
8113 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8116 case RID_AT_SELECTOR
:
8117 gcc_assert (c_dialect_objc ());
8118 c_parser_consume_token (parser
);
8119 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8125 tree sel
= c_parser_objc_selector_arg (parser
);
8126 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8127 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8129 expr
.value
= objc_build_selector_expr (loc
, sel
);
8130 set_c_expr_source_range (&expr
, loc
, close_loc
);
8133 case RID_AT_PROTOCOL
:
8134 gcc_assert (c_dialect_objc ());
8135 c_parser_consume_token (parser
);
8136 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8141 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8143 c_parser_error (parser
, "expected identifier");
8144 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8149 tree id
= c_parser_peek_token (parser
)->value
;
8150 c_parser_consume_token (parser
);
8151 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8152 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8154 expr
.value
= objc_build_protocol_expr (id
);
8155 set_c_expr_source_range (&expr
, loc
, close_loc
);
8159 /* Extension to support C-structures in the archiver. */
8160 gcc_assert (c_dialect_objc ());
8161 c_parser_consume_token (parser
);
8162 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8167 t1
= c_parser_type_name (parser
);
8171 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8175 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8176 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8178 tree type
= groktypename (t1
, NULL
, NULL
);
8179 expr
.value
= objc_build_encode_expr (type
);
8180 set_c_expr_source_range (&expr
, loc
, close_loc
);
8184 expr
= c_parser_generic_selection (parser
);
8186 case RID_CILK_SPAWN
:
8187 c_parser_consume_token (parser
);
8190 error_at (loc
, "-fcilkplus must be enabled to use "
8192 expr
= c_parser_cast_expression (parser
, NULL
);
8195 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
8197 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
8198 "are not permitted");
8199 /* Now flush out all the _Cilk_spawns. */
8200 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
8201 c_parser_consume_token (parser
);
8202 expr
= c_parser_cast_expression (parser
, NULL
);
8206 expr
= c_parser_cast_expression (parser
, NULL
);
8207 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
8211 c_parser_error (parser
, "expected expression");
8216 case CPP_OPEN_SQUARE
:
8217 if (c_dialect_objc ())
8219 tree receiver
, args
;
8220 c_parser_consume_token (parser
);
8221 receiver
= c_parser_objc_receiver (parser
);
8222 args
= c_parser_objc_message_args (parser
);
8223 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8224 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8226 expr
.value
= objc_build_message_expr (receiver
, args
);
8227 set_c_expr_source_range (&expr
, loc
, close_loc
);
8230 /* Else fall through to report error. */
8233 c_parser_error (parser
, "expected expression");
8237 return c_parser_postfix_expression_after_primary
8238 (parser
, EXPR_LOC_OR_LOC (expr
.value
, loc
), expr
);
8241 /* Parse a postfix expression after a parenthesized type name: the
8242 brace-enclosed initializer of a compound literal, possibly followed
8243 by some postfix operators. This is separate because it is not
8244 possible to tell until after the type name whether a cast
8245 expression has a cast or a compound literal, or whether the operand
8246 of sizeof is a parenthesized type name or starts with a compound
8247 literal. TYPE_LOC is the location where TYPE_NAME starts--the
8248 location of the first token after the parentheses around the type
8251 static struct c_expr
8252 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
8253 struct c_type_name
*type_name
,
8254 location_t type_loc
)
8260 location_t start_loc
;
8261 tree type_expr
= NULL_TREE
;
8262 bool type_expr_const
= true;
8263 check_compound_literal_type (type_loc
, type_name
);
8264 rich_location
richloc (line_table
, type_loc
);
8265 start_init (NULL_TREE
, NULL
, 0, &richloc
);
8266 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
8267 start_loc
= c_parser_peek_token (parser
)->location
;
8268 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
8270 error_at (type_loc
, "compound literal has variable size");
8271 type
= error_mark_node
;
8273 init
= c_parser_braced_init (parser
, type
, false, NULL
);
8275 maybe_warn_string_init (type_loc
, type
, init
);
8277 if (type
!= error_mark_node
8278 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
8279 && current_function_decl
)
8281 error ("compound literal qualified by address-space qualifier");
8282 type
= error_mark_node
;
8285 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
8286 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
8287 ? CONSTRUCTOR_NON_CONST (init
.value
)
8288 : init
.original_code
== C_MAYBE_CONST_EXPR
);
8289 non_const
|= !type_expr_const
;
8290 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
8291 set_c_expr_source_range (&expr
, init
.src_range
);
8292 expr
.original_code
= ERROR_MARK
;
8293 expr
.original_type
= NULL
;
8294 if (type
!= error_mark_node
8295 && expr
.value
!= error_mark_node
8298 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
8300 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
8301 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
8305 gcc_assert (!non_const
);
8306 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
8307 type_expr
, expr
.value
);
8310 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
8313 /* Callback function for sizeof_pointer_memaccess_warning to compare
8317 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
8319 return comptypes (type1
, type2
) == 1;
8322 /* Parse a postfix expression after the initial primary or compound
8323 literal; that is, parse a series of postfix operators.
8325 EXPR_LOC is the location of the primary expression. */
8327 static struct c_expr
8328 c_parser_postfix_expression_after_primary (c_parser
*parser
,
8329 location_t expr_loc
,
8332 struct c_expr orig_expr
;
8334 location_t sizeof_arg_loc
[3], comp_loc
;
8336 unsigned int literal_zero_mask
;
8338 vec
<tree
, va_gc
> *exprlist
;
8339 vec
<tree
, va_gc
> *origtypes
= NULL
;
8340 vec
<location_t
> arg_loc
= vNULL
;
8346 location_t op_loc
= c_parser_peek_token (parser
)->location
;
8347 switch (c_parser_peek_token (parser
)->type
)
8349 case CPP_OPEN_SQUARE
:
8350 /* Array reference. */
8351 c_parser_consume_token (parser
);
8353 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
8354 /* If we are here, then we have something like this:
8357 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
8361 idx
= c_parser_expression (parser
).value
;
8362 /* Here we have 3 options:
8363 1. Array [EXPR] -- Normal Array call.
8364 2. Array [EXPR : EXPR] -- Array notation without stride.
8365 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
8367 For 1, we just handle it just like a normal array expression.
8368 For 2 and 3 we handle it like we handle array notations. The
8369 idx value we have above becomes the initial/start index.
8372 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
8373 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
8377 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8379 start
= expr
.get_start ();
8380 finish
= parser
->tokens_buf
[0].location
;
8381 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
8382 set_c_expr_source_range (&expr
, start
, finish
);
8385 expr
.original_code
= ERROR_MARK
;
8386 expr
.original_type
= NULL
;
8388 case CPP_OPEN_PAREN
:
8389 /* Function call. */
8390 c_parser_consume_token (parser
);
8391 for (i
= 0; i
< 3; i
++)
8393 sizeof_arg
[i
] = NULL_TREE
;
8394 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
8396 literal_zero_mask
= 0;
8397 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8400 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
8401 sizeof_arg_loc
, sizeof_arg
,
8402 &arg_loc
, &literal_zero_mask
);
8403 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8406 mark_exp_read (expr
.value
);
8407 if (warn_sizeof_pointer_memaccess
)
8408 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
8409 expr
.value
, exprlist
,
8411 sizeof_ptr_memacc_comptypes
);
8412 if (TREE_CODE (expr
.value
) == FUNCTION_DECL
8413 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
8414 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
8415 && vec_safe_length (exprlist
) == 3)
8417 tree arg0
= (*exprlist
)[0];
8418 tree arg2
= (*exprlist
)[2];
8419 warn_for_memset (expr_loc
, arg0
, arg2
, literal_zero_mask
);
8422 start
= expr
.get_start ();
8423 finish
= parser
->tokens_buf
[0].get_finish ();
8425 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
8426 exprlist
, origtypes
);
8427 set_c_expr_source_range (&expr
, start
, finish
);
8429 expr
.original_code
= ERROR_MARK
;
8430 if (TREE_CODE (expr
.value
) == INTEGER_CST
8431 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
8432 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
8433 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
8434 expr
.original_code
= C_MAYBE_CONST_EXPR
;
8435 expr
.original_type
= NULL
;
8438 release_tree_vector (exprlist
);
8439 release_tree_vector (origtypes
);
8444 /* Structure element reference. */
8445 c_parser_consume_token (parser
);
8446 expr
= default_function_array_conversion (expr_loc
, expr
);
8447 if (c_parser_next_token_is (parser
, CPP_NAME
))
8449 c_token
*comp_tok
= c_parser_peek_token (parser
);
8450 ident
= comp_tok
->value
;
8451 comp_loc
= comp_tok
->location
;
8455 c_parser_error (parser
, "expected identifier");
8457 expr
.original_code
= ERROR_MARK
;
8458 expr
.original_type
= NULL
;
8461 start
= expr
.get_start ();
8462 finish
= c_parser_peek_token (parser
)->get_finish ();
8463 c_parser_consume_token (parser
);
8464 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
,
8466 set_c_expr_source_range (&expr
, start
, finish
);
8467 expr
.original_code
= ERROR_MARK
;
8468 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8469 expr
.original_type
= NULL
;
8472 /* Remember the original type of a bitfield. */
8473 tree field
= TREE_OPERAND (expr
.value
, 1);
8474 if (TREE_CODE (field
) != FIELD_DECL
)
8475 expr
.original_type
= NULL
;
8477 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8481 /* Structure element reference. */
8482 c_parser_consume_token (parser
);
8483 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
8484 if (c_parser_next_token_is (parser
, CPP_NAME
))
8486 c_token
*comp_tok
= c_parser_peek_token (parser
);
8487 ident
= comp_tok
->value
;
8488 comp_loc
= comp_tok
->location
;
8492 c_parser_error (parser
, "expected identifier");
8494 expr
.original_code
= ERROR_MARK
;
8495 expr
.original_type
= NULL
;
8498 start
= expr
.get_start ();
8499 finish
= c_parser_peek_token (parser
)->get_finish ();
8500 c_parser_consume_token (parser
);
8501 expr
.value
= build_component_ref (op_loc
,
8502 build_indirect_ref (op_loc
,
8506 set_c_expr_source_range (&expr
, start
, finish
);
8507 expr
.original_code
= ERROR_MARK
;
8508 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8509 expr
.original_type
= NULL
;
8512 /* Remember the original type of a bitfield. */
8513 tree field
= TREE_OPERAND (expr
.value
, 1);
8514 if (TREE_CODE (field
) != FIELD_DECL
)
8515 expr
.original_type
= NULL
;
8517 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8521 /* Postincrement. */
8522 start
= expr
.get_start ();
8523 finish
= c_parser_peek_token (parser
)->get_finish ();
8524 c_parser_consume_token (parser
);
8525 /* If the expressions have array notations, we expand them. */
8527 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8528 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
8531 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8532 expr
.value
= build_unary_op (op_loc
, POSTINCREMENT_EXPR
,
8535 set_c_expr_source_range (&expr
, start
, finish
);
8536 expr
.original_code
= ERROR_MARK
;
8537 expr
.original_type
= NULL
;
8539 case CPP_MINUS_MINUS
:
8540 /* Postdecrement. */
8541 start
= expr
.get_start ();
8542 finish
= c_parser_peek_token (parser
)->get_finish ();
8543 c_parser_consume_token (parser
);
8544 /* If the expressions have array notations, we expand them. */
8546 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8547 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
8550 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8551 expr
.value
= build_unary_op (op_loc
, POSTDECREMENT_EXPR
,
8554 set_c_expr_source_range (&expr
, start
, finish
);
8555 expr
.original_code
= ERROR_MARK
;
8556 expr
.original_type
= NULL
;
8564 /* Parse an expression (C90 6.3.17, C99 6.5.17).
8567 assignment-expression
8568 expression , assignment-expression
8571 static struct c_expr
8572 c_parser_expression (c_parser
*parser
)
8574 location_t tloc
= c_parser_peek_token (parser
)->location
;
8576 expr
= c_parser_expr_no_commas (parser
, NULL
);
8577 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8578 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
8579 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8583 location_t loc
= c_parser_peek_token (parser
)->location
;
8584 location_t expr_loc
;
8585 c_parser_consume_token (parser
);
8586 expr_loc
= c_parser_peek_token (parser
)->location
;
8587 lhsval
= expr
.value
;
8588 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
8589 lhsval
= TREE_OPERAND (lhsval
, 1);
8590 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
8591 mark_exp_read (lhsval
);
8592 next
= c_parser_expr_no_commas (parser
, NULL
);
8593 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
8594 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
8595 expr
.original_code
= COMPOUND_EXPR
;
8596 expr
.original_type
= next
.original_type
;
8601 /* Parse an expression and convert functions or arrays to pointers and
8602 lvalues to rvalues. */
8604 static struct c_expr
8605 c_parser_expression_conv (c_parser
*parser
)
8608 location_t loc
= c_parser_peek_token (parser
)->location
;
8609 expr
= c_parser_expression (parser
);
8610 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
8614 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
8615 argument is a literal zero alone and if so, set it in literal_zero_mask. */
8618 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
8621 if (idx
>= HOST_BITS_PER_INT
)
8624 c_token
*tok
= c_parser_peek_token (parser
);
8632 /* If a parameter is literal zero alone, remember it
8633 for -Wmemset-transposed-args warning. */
8634 if (integer_zerop (tok
->value
)
8635 && !TREE_OVERFLOW (tok
->value
)
8636 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8637 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
8638 *literal_zero_mask
|= 1U << idx
;
8644 /* Parse a non-empty list of expressions. If CONVERT_P, convert
8645 functions and arrays to pointers and lvalues to rvalues. If
8646 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
8647 locations of function arguments into this vector.
8650 assignment-expression
8651 nonempty-expr-list , assignment-expression
8654 static vec
<tree
, va_gc
> *
8655 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
8656 vec
<tree
, va_gc
> **p_orig_types
,
8657 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
8658 vec
<location_t
> *locations
,
8659 unsigned int *literal_zero_mask
)
8661 vec
<tree
, va_gc
> *ret
;
8662 vec
<tree
, va_gc
> *orig_types
;
8664 location_t loc
= c_parser_peek_token (parser
)->location
;
8665 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8666 unsigned int idx
= 0;
8668 ret
= make_tree_vector ();
8669 if (p_orig_types
== NULL
)
8672 orig_types
= make_tree_vector ();
8674 if (sizeof_arg
!= NULL
8675 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8676 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8677 if (literal_zero_mask
)
8678 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
8679 expr
= c_parser_expr_no_commas (parser
, NULL
);
8681 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8683 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8684 ret
->quick_push (expr
.value
);
8686 orig_types
->quick_push (expr
.original_type
);
8688 locations
->safe_push (loc
);
8689 if (sizeof_arg
!= NULL
8690 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8691 && expr
.original_code
== SIZEOF_EXPR
)
8693 sizeof_arg
[0] = c_last_sizeof_arg
;
8694 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
8696 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8698 c_parser_consume_token (parser
);
8699 loc
= c_parser_peek_token (parser
)->location
;
8700 if (sizeof_arg
!= NULL
8701 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8702 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8704 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8705 if (literal_zero_mask
)
8706 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
8707 expr
= c_parser_expr_no_commas (parser
, NULL
);
8709 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8711 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8712 vec_safe_push (ret
, expr
.value
);
8714 vec_safe_push (orig_types
, expr
.original_type
);
8716 locations
->safe_push (loc
);
8718 && sizeof_arg
!= NULL
8719 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8720 && expr
.original_code
== SIZEOF_EXPR
)
8722 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8723 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
8727 *p_orig_types
= orig_types
;
8731 /* Parse Objective-C-specific constructs. */
8733 /* Parse an objc-class-definition.
8735 objc-class-definition:
8736 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8737 objc-class-instance-variables[opt] objc-methodprotolist @end
8738 @implementation identifier objc-superclass[opt]
8739 objc-class-instance-variables[opt]
8740 @interface identifier ( identifier ) objc-protocol-refs[opt]
8741 objc-methodprotolist @end
8742 @interface identifier ( ) objc-protocol-refs[opt]
8743 objc-methodprotolist @end
8744 @implementation identifier ( identifier )
8749 "@interface identifier (" must start "@interface identifier (
8750 identifier ) ...": objc-methodprotolist in the first production may
8751 not start with a parenthesized identifier as a declarator of a data
8752 definition with no declaration specifiers if the objc-superclass,
8753 objc-protocol-refs and objc-class-instance-variables are omitted. */
8756 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8761 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8763 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8768 c_parser_consume_token (parser
);
8769 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8771 c_parser_error (parser
, "expected identifier");
8774 id1
= c_parser_peek_token (parser
)->value
;
8775 c_parser_consume_token (parser
);
8776 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8778 /* We have a category or class extension. */
8780 tree proto
= NULL_TREE
;
8781 c_parser_consume_token (parser
);
8782 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8784 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8786 /* We have a class extension. */
8791 c_parser_error (parser
, "expected identifier or %<)%>");
8792 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8798 id2
= c_parser_peek_token (parser
)->value
;
8799 c_parser_consume_token (parser
);
8801 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8804 objc_start_category_implementation (id1
, id2
);
8807 if (c_parser_next_token_is (parser
, CPP_LESS
))
8808 proto
= c_parser_objc_protocol_refs (parser
);
8809 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8810 c_parser_objc_methodprotolist (parser
);
8811 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8812 objc_finish_interface ();
8815 if (c_parser_next_token_is (parser
, CPP_COLON
))
8817 c_parser_consume_token (parser
);
8818 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8820 c_parser_error (parser
, "expected identifier");
8823 superclass
= c_parser_peek_token (parser
)->value
;
8824 c_parser_consume_token (parser
);
8827 superclass
= NULL_TREE
;
8830 tree proto
= NULL_TREE
;
8831 if (c_parser_next_token_is (parser
, CPP_LESS
))
8832 proto
= c_parser_objc_protocol_refs (parser
);
8833 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8836 objc_start_class_implementation (id1
, superclass
);
8837 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8838 c_parser_objc_class_instance_variables (parser
);
8841 objc_continue_interface ();
8842 c_parser_objc_methodprotolist (parser
);
8843 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8844 objc_finish_interface ();
8848 objc_continue_implementation ();
8853 /* Parse objc-class-instance-variables.
8855 objc-class-instance-variables:
8856 { objc-instance-variable-decl-list[opt] }
8858 objc-instance-variable-decl-list:
8859 objc-visibility-spec
8860 objc-instance-variable-decl ;
8862 objc-instance-variable-decl-list objc-visibility-spec
8863 objc-instance-variable-decl-list objc-instance-variable-decl ;
8864 objc-instance-variable-decl-list ;
8866 objc-visibility-spec:
8871 objc-instance-variable-decl:
8876 c_parser_objc_class_instance_variables (c_parser
*parser
)
8878 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8879 c_parser_consume_token (parser
);
8880 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8883 /* Parse any stray semicolon. */
8884 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8886 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8888 c_parser_consume_token (parser
);
8891 /* Stop if at the end of the instance variables. */
8892 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8894 c_parser_consume_token (parser
);
8897 /* Parse any objc-visibility-spec. */
8898 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8900 c_parser_consume_token (parser
);
8901 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8904 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8906 c_parser_consume_token (parser
);
8907 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8910 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8912 c_parser_consume_token (parser
);
8913 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8916 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8918 c_parser_consume_token (parser
);
8919 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8922 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8924 c_parser_pragma (parser
, pragma_external
, NULL
);
8928 /* Parse some comma-separated declarations. */
8929 decls
= c_parser_struct_declaration (parser
);
8932 /* There is a syntax error. We want to skip the offending
8933 tokens up to the next ';' (included) or '}'
8936 /* First, skip manually a ')' or ']'. This is because they
8937 reduce the nesting level, so c_parser_skip_until_found()
8938 wouldn't be able to skip past them. */
8939 c_token
*token
= c_parser_peek_token (parser
);
8940 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8941 c_parser_consume_token (parser
);
8943 /* Then, do the standard skipping. */
8944 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8946 /* We hopefully recovered. Start normal parsing again. */
8947 parser
->error
= false;
8952 /* Comma-separated instance variables are chained together
8953 in reverse order; add them one by one. */
8954 tree ivar
= nreverse (decls
);
8955 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8956 objc_add_instance_variable (copy_node (ivar
));
8958 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8962 /* Parse an objc-class-declaration.
8964 objc-class-declaration:
8965 @class identifier-list ;
8969 c_parser_objc_class_declaration (c_parser
*parser
)
8971 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8972 c_parser_consume_token (parser
);
8973 /* Any identifiers, including those declared as type names, are OK
8978 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8980 c_parser_error (parser
, "expected identifier");
8981 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8982 parser
->error
= false;
8985 id
= c_parser_peek_token (parser
)->value
;
8986 objc_declare_class (id
);
8987 c_parser_consume_token (parser
);
8988 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8989 c_parser_consume_token (parser
);
8993 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8996 /* Parse an objc-alias-declaration.
8998 objc-alias-declaration:
8999 @compatibility_alias identifier identifier ;
9003 c_parser_objc_alias_declaration (c_parser
*parser
)
9006 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
9007 c_parser_consume_token (parser
);
9008 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9010 c_parser_error (parser
, "expected identifier");
9011 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9014 id1
= c_parser_peek_token (parser
)->value
;
9015 c_parser_consume_token (parser
);
9016 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9018 c_parser_error (parser
, "expected identifier");
9019 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9022 id2
= c_parser_peek_token (parser
)->value
;
9023 c_parser_consume_token (parser
);
9024 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9025 objc_declare_alias (id1
, id2
);
9028 /* Parse an objc-protocol-definition.
9030 objc-protocol-definition:
9031 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
9032 @protocol identifier-list ;
9034 "@protocol identifier ;" should be resolved as "@protocol
9035 identifier-list ;": objc-methodprotolist may not start with a
9036 semicolon in the first alternative if objc-protocol-refs are
9040 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
9042 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
9044 c_parser_consume_token (parser
);
9045 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9047 c_parser_error (parser
, "expected identifier");
9050 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9051 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
9053 /* Any identifiers, including those declared as type names, are
9058 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9060 c_parser_error (parser
, "expected identifier");
9063 id
= c_parser_peek_token (parser
)->value
;
9064 objc_declare_protocol (id
, attributes
);
9065 c_parser_consume_token (parser
);
9066 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9067 c_parser_consume_token (parser
);
9071 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9075 tree id
= c_parser_peek_token (parser
)->value
;
9076 tree proto
= NULL_TREE
;
9077 c_parser_consume_token (parser
);
9078 if (c_parser_next_token_is (parser
, CPP_LESS
))
9079 proto
= c_parser_objc_protocol_refs (parser
);
9080 parser
->objc_pq_context
= true;
9081 objc_start_protocol (id
, proto
, attributes
);
9082 c_parser_objc_methodprotolist (parser
);
9083 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9084 parser
->objc_pq_context
= false;
9085 objc_finish_interface ();
9089 /* Parse an objc-method-type.
9095 Return true if it is a class method (+) and false if it is
9096 an instance method (-).
9099 c_parser_objc_method_type (c_parser
*parser
)
9101 switch (c_parser_peek_token (parser
)->type
)
9104 c_parser_consume_token (parser
);
9107 c_parser_consume_token (parser
);
9114 /* Parse an objc-method-definition.
9116 objc-method-definition:
9117 objc-method-type objc-method-decl ;[opt] compound-statement
9121 c_parser_objc_method_definition (c_parser
*parser
)
9123 bool is_class_method
= c_parser_objc_method_type (parser
);
9124 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
9125 parser
->objc_pq_context
= true;
9126 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9128 if (decl
== error_mark_node
)
9129 return; /* Bail here. */
9131 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9133 c_parser_consume_token (parser
);
9134 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9135 "extra semicolon in method definition specified");
9138 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9140 c_parser_error (parser
, "expected %<{%>");
9144 parser
->objc_pq_context
= false;
9145 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
9147 add_stmt (c_parser_compound_statement (parser
));
9148 objc_finish_method_definition (current_function_decl
);
9152 /* This code is executed when we find a method definition
9153 outside of an @implementation context (or invalid for other
9154 reasons). Parse the method (to keep going) but do not emit
9157 c_parser_compound_statement (parser
);
9161 /* Parse an objc-methodprotolist.
9163 objc-methodprotolist:
9165 objc-methodprotolist objc-methodproto
9166 objc-methodprotolist declaration
9167 objc-methodprotolist ;
9171 The declaration is a data definition, which may be missing
9172 declaration specifiers under the same rules and diagnostics as
9173 other data definitions outside functions, and the stray semicolon
9174 is diagnosed the same way as a stray semicolon outside a
9178 c_parser_objc_methodprotolist (c_parser
*parser
)
9182 /* The list is terminated by @end. */
9183 switch (c_parser_peek_token (parser
)->type
)
9186 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9187 "ISO C does not allow extra %<;%> outside of a function");
9188 c_parser_consume_token (parser
);
9192 c_parser_objc_methodproto (parser
);
9195 c_parser_pragma (parser
, pragma_external
, NULL
);
9200 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
9202 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
9203 c_parser_objc_at_property_declaration (parser
);
9204 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
9206 objc_set_method_opt (true);
9207 c_parser_consume_token (parser
);
9209 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
9211 objc_set_method_opt (false);
9212 c_parser_consume_token (parser
);
9215 c_parser_declaration_or_fndef (parser
, false, false, true,
9216 false, true, NULL
, vNULL
);
9222 /* Parse an objc-methodproto.
9225 objc-method-type objc-method-decl ;
9229 c_parser_objc_methodproto (c_parser
*parser
)
9231 bool is_class_method
= c_parser_objc_method_type (parser
);
9232 tree decl
, attributes
= NULL_TREE
;
9234 /* Remember protocol qualifiers in prototypes. */
9235 parser
->objc_pq_context
= true;
9236 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9238 /* Forget protocol qualifiers now. */
9239 parser
->objc_pq_context
= false;
9241 /* Do not allow the presence of attributes to hide an erroneous
9242 method implementation in the interface section. */
9243 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9245 c_parser_error (parser
, "expected %<;%>");
9249 if (decl
!= error_mark_node
)
9250 objc_add_method_declaration (is_class_method
, decl
, attributes
);
9252 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9255 /* If we are at a position that method attributes may be present, check that
9256 there are not any parsed already (a syntax error) and then collect any
9257 specified at the current location. Finally, if new attributes were present,
9258 check that the next token is legal ( ';' for decls and '{' for defs). */
9261 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
9266 c_parser_error (parser
,
9267 "method attributes must be specified at the end only");
9268 *attributes
= NULL_TREE
;
9272 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
9273 *attributes
= c_parser_attributes (parser
);
9275 /* If there were no attributes here, just report any earlier error. */
9276 if (*attributes
== NULL_TREE
|| bad
)
9279 /* If the attributes are followed by a ; or {, then just report any earlier
9281 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
9282 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9285 /* We've got attributes, but not at the end. */
9286 c_parser_error (parser
,
9287 "expected %<;%> or %<{%> after method attribute definition");
9291 /* Parse an objc-method-decl.
9294 ( objc-type-name ) objc-selector
9296 ( objc-type-name ) objc-keyword-selector objc-optparmlist
9297 objc-keyword-selector objc-optparmlist
9300 objc-keyword-selector:
9302 objc-keyword-selector objc-keyword-decl
9305 objc-selector : ( objc-type-name ) identifier
9306 objc-selector : identifier
9307 : ( objc-type-name ) identifier
9311 objc-optparms objc-optellipsis
9315 objc-opt-parms , parameter-declaration
9323 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
9324 tree
*attributes
, tree
*expr
)
9326 tree type
= NULL_TREE
;
9328 tree parms
= NULL_TREE
;
9329 bool ellipsis
= false;
9330 bool attr_err
= false;
9332 *attributes
= NULL_TREE
;
9333 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9335 c_parser_consume_token (parser
);
9336 type
= c_parser_objc_type_name (parser
);
9337 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9339 sel
= c_parser_objc_selector (parser
);
9340 /* If there is no selector, or a colon follows, we have an
9341 objc-keyword-selector. If there is a selector, and a colon does
9342 not follow, that selector ends the objc-method-decl. */
9343 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
9346 tree list
= NULL_TREE
;
9349 tree atype
= NULL_TREE
, id
, keyworddecl
;
9350 tree param_attr
= NULL_TREE
;
9351 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9353 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9355 c_parser_consume_token (parser
);
9356 atype
= c_parser_objc_type_name (parser
);
9357 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9360 /* New ObjC allows attributes on method parameters. */
9361 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
9362 param_attr
= c_parser_attributes (parser
);
9363 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9365 c_parser_error (parser
, "expected identifier");
9366 return error_mark_node
;
9368 id
= c_parser_peek_token (parser
)->value
;
9369 c_parser_consume_token (parser
);
9370 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
9371 list
= chainon (list
, keyworddecl
);
9372 tsel
= c_parser_objc_selector (parser
);
9373 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9377 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
9379 /* Parse the optional parameter list. Optional Objective-C
9380 method parameters follow the C syntax, and may include '...'
9381 to denote a variable number of arguments. */
9382 parms
= make_node (TREE_LIST
);
9383 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9385 struct c_parm
*parm
;
9386 c_parser_consume_token (parser
);
9387 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9390 c_parser_consume_token (parser
);
9391 attr_err
|= c_parser_objc_maybe_method_attributes
9392 (parser
, attributes
) ;
9395 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9398 parms
= chainon (parms
,
9399 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
9404 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
9408 c_parser_error (parser
, "objective-c method declaration is expected");
9409 return error_mark_node
;
9413 return error_mark_node
;
9415 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
9418 /* Parse an objc-type-name.
9421 objc-type-qualifiers[opt] type-name
9422 objc-type-qualifiers[opt]
9424 objc-type-qualifiers:
9426 objc-type-qualifiers objc-type-qualifier
9428 objc-type-qualifier: one of
9429 in out inout bycopy byref oneway
9433 c_parser_objc_type_name (c_parser
*parser
)
9435 tree quals
= NULL_TREE
;
9436 struct c_type_name
*type_name
= NULL
;
9437 tree type
= NULL_TREE
;
9440 c_token
*token
= c_parser_peek_token (parser
);
9441 if (token
->type
== CPP_KEYWORD
9442 && (token
->keyword
== RID_IN
9443 || token
->keyword
== RID_OUT
9444 || token
->keyword
== RID_INOUT
9445 || token
->keyword
== RID_BYCOPY
9446 || token
->keyword
== RID_BYREF
9447 || token
->keyword
== RID_ONEWAY
))
9449 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
9450 c_parser_consume_token (parser
);
9455 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
9456 type_name
= c_parser_type_name (parser
);
9458 type
= groktypename (type_name
, NULL
, NULL
);
9460 /* If the type is unknown, and error has already been produced and
9461 we need to recover from the error. In that case, use NULL_TREE
9462 for the type, as if no type had been specified; this will use the
9463 default type ('id') which is good for error recovery. */
9464 if (type
== error_mark_node
)
9467 return build_tree_list (quals
, type
);
9470 /* Parse objc-protocol-refs.
9477 c_parser_objc_protocol_refs (c_parser
*parser
)
9479 tree list
= NULL_TREE
;
9480 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
9481 c_parser_consume_token (parser
);
9482 /* Any identifiers, including those declared as type names, are OK
9487 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9489 c_parser_error (parser
, "expected identifier");
9492 id
= c_parser_peek_token (parser
)->value
;
9493 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
9494 c_parser_consume_token (parser
);
9495 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9496 c_parser_consume_token (parser
);
9500 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
9504 /* Parse an objc-try-catch-finally-statement.
9506 objc-try-catch-finally-statement:
9507 @try compound-statement objc-catch-list[opt]
9508 @try compound-statement objc-catch-list[opt] @finally compound-statement
9511 @catch ( objc-catch-parameter-declaration ) compound-statement
9512 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
9514 objc-catch-parameter-declaration:
9515 parameter-declaration
9518 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
9520 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
9521 for C++. Keep them in sync. */
9524 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
9526 location_t location
;
9529 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
9530 c_parser_consume_token (parser
);
9531 location
= c_parser_peek_token (parser
)->location
;
9532 objc_maybe_warn_exceptions (location
);
9533 stmt
= c_parser_compound_statement (parser
);
9534 objc_begin_try_stmt (location
, stmt
);
9536 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
9538 struct c_parm
*parm
;
9539 tree parameter_declaration
= error_mark_node
;
9540 bool seen_open_paren
= false;
9542 c_parser_consume_token (parser
);
9543 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9544 seen_open_paren
= true;
9545 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9547 /* We have "@catch (...)" (where the '...' are literally
9548 what is in the code). Skip the '...'.
9549 parameter_declaration is set to NULL_TREE, and
9550 objc_being_catch_clauses() knows that that means
9552 c_parser_consume_token (parser
);
9553 parameter_declaration
= NULL_TREE
;
9557 /* We have "@catch (NSException *exception)" or something
9558 like that. Parse the parameter declaration. */
9559 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9561 parameter_declaration
= error_mark_node
;
9563 parameter_declaration
= grokparm (parm
, NULL
);
9565 if (seen_open_paren
)
9566 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9569 /* If there was no open parenthesis, we are recovering from
9570 an error, and we are trying to figure out what mistake
9571 the user has made. */
9573 /* If there is an immediate closing parenthesis, the user
9574 probably forgot the opening one (ie, they typed "@catch
9575 NSException *e)". Parse the closing parenthesis and keep
9577 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9578 c_parser_consume_token (parser
);
9580 /* If these is no immediate closing parenthesis, the user
9581 probably doesn't know that parenthesis are required at
9582 all (ie, they typed "@catch NSException *e"). So, just
9583 forget about the closing parenthesis and keep going. */
9585 objc_begin_catch_clause (parameter_declaration
);
9586 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
9587 c_parser_compound_statement_nostart (parser
);
9588 objc_finish_catch_clause ();
9590 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
9592 c_parser_consume_token (parser
);
9593 location
= c_parser_peek_token (parser
)->location
;
9594 stmt
= c_parser_compound_statement (parser
);
9595 objc_build_finally_clause (location
, stmt
);
9597 objc_finish_try_stmt ();
9600 /* Parse an objc-synchronized-statement.
9602 objc-synchronized-statement:
9603 @synchronized ( expression ) compound-statement
9607 c_parser_objc_synchronized_statement (c_parser
*parser
)
9611 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
9612 c_parser_consume_token (parser
);
9613 loc
= c_parser_peek_token (parser
)->location
;
9614 objc_maybe_warn_exceptions (loc
);
9615 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9617 struct c_expr ce
= c_parser_expression (parser
);
9618 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9620 expr
= c_fully_fold (expr
, false, NULL
);
9621 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9624 expr
= error_mark_node
;
9625 stmt
= c_parser_compound_statement (parser
);
9626 objc_build_synchronized (loc
, expr
, stmt
);
9629 /* Parse an objc-selector; return NULL_TREE without an error if the
9630 next token is not an objc-selector.
9635 enum struct union if else while do for switch case default
9636 break continue return goto asm sizeof typeof __alignof
9637 unsigned long const short volatile signed restrict _Complex
9638 in out inout bycopy byref oneway int char float double void _Bool
9641 ??? Why this selection of keywords but not, for example, storage
9642 class specifiers? */
9645 c_parser_objc_selector (c_parser
*parser
)
9647 c_token
*token
= c_parser_peek_token (parser
);
9648 tree value
= token
->value
;
9649 if (token
->type
== CPP_NAME
)
9651 c_parser_consume_token (parser
);
9654 if (token
->type
!= CPP_KEYWORD
)
9656 switch (token
->keyword
)
9704 c_parser_consume_token (parser
);
9711 /* Parse an objc-selector-arg.
9715 objc-keywordname-list
9717 objc-keywordname-list:
9719 objc-keywordname-list objc-keywordname
9727 c_parser_objc_selector_arg (c_parser
*parser
)
9729 tree sel
= c_parser_objc_selector (parser
);
9730 tree list
= NULL_TREE
;
9731 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9735 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9737 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9738 sel
= c_parser_objc_selector (parser
);
9739 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9745 /* Parse an objc-receiver.
9754 c_parser_objc_receiver (c_parser
*parser
)
9756 location_t loc
= c_parser_peek_token (parser
)->location
;
9758 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9759 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9760 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9762 tree id
= c_parser_peek_token (parser
)->value
;
9763 c_parser_consume_token (parser
);
9764 return objc_get_class_reference (id
);
9766 struct c_expr ce
= c_parser_expression (parser
);
9767 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9768 return c_fully_fold (ce
.value
, false, NULL
);
9771 /* Parse objc-message-args.
9775 objc-keywordarg-list
9777 objc-keywordarg-list:
9779 objc-keywordarg-list objc-keywordarg
9782 objc-selector : objc-keywordexpr
9787 c_parser_objc_message_args (c_parser
*parser
)
9789 tree sel
= c_parser_objc_selector (parser
);
9790 tree list
= NULL_TREE
;
9791 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9796 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9797 return error_mark_node
;
9798 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9799 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9800 sel
= c_parser_objc_selector (parser
);
9801 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9807 /* Parse an objc-keywordexpr.
9814 c_parser_objc_keywordexpr (c_parser
*parser
)
9817 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9818 NULL
, NULL
, NULL
, NULL
);
9819 if (vec_safe_length (expr_list
) == 1)
9821 /* Just return the expression, remove a level of
9823 ret
= (*expr_list
)[0];
9827 /* We have a comma expression, we will collapse later. */
9828 ret
= build_tree_list_vec (expr_list
);
9830 release_tree_vector (expr_list
);
9834 /* A check, needed in several places, that ObjC interface, implementation or
9835 method definitions are not prefixed by incorrect items. */
9837 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9838 struct c_declspecs
*specs
)
9840 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9841 || specs
->typespec_kind
!= ctsk_none
)
9843 c_parser_error (parser
,
9844 "no type or storage class may be specified here,");
9845 c_parser_skip_to_end_of_block_or_statement (parser
);
9851 /* Parse an Objective-C @property declaration. The syntax is:
9853 objc-property-declaration:
9854 '@property' objc-property-attributes[opt] struct-declaration ;
9856 objc-property-attributes:
9857 '(' objc-property-attribute-list ')'
9859 objc-property-attribute-list:
9860 objc-property-attribute
9861 objc-property-attribute-list, objc-property-attribute
9863 objc-property-attribute
9864 'getter' = identifier
9865 'setter' = identifier
9874 @property NSString *name;
9875 @property (readonly) id object;
9876 @property (retain, nonatomic, getter=getTheName) id name;
9877 @property int a, b, c;
9879 PS: This function is identical to cp_parser_objc_at_propery_declaration
9880 for C++. Keep them in sync. */
9882 c_parser_objc_at_property_declaration (c_parser
*parser
)
9884 /* The following variables hold the attributes of the properties as
9885 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9886 seen. When we see an attribute, we set them to 'true' (if they
9887 are boolean properties) or to the identifier (if they have an
9888 argument, ie, for getter and setter). Note that here we only
9889 parse the list of attributes, check the syntax and accumulate the
9890 attributes that we find. objc_add_property_declaration() will
9891 then process the information. */
9892 bool property_assign
= false;
9893 bool property_copy
= false;
9894 tree property_getter_ident
= NULL_TREE
;
9895 bool property_nonatomic
= false;
9896 bool property_readonly
= false;
9897 bool property_readwrite
= false;
9898 bool property_retain
= false;
9899 tree property_setter_ident
= NULL_TREE
;
9901 /* 'properties' is the list of properties that we read. Usually a
9902 single one, but maybe more (eg, in "@property int a, b, c;" there
9907 loc
= c_parser_peek_token (parser
)->location
;
9908 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9910 c_parser_consume_token (parser
); /* Eat '@property'. */
9912 /* Parse the optional attribute list... */
9913 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9916 c_parser_consume_token (parser
);
9918 /* Property attribute keywords are valid now. */
9919 parser
->objc_property_attr_context
= true;
9923 bool syntax_error
= false;
9924 c_token
*token
= c_parser_peek_token (parser
);
9927 if (token
->type
!= CPP_KEYWORD
)
9929 if (token
->type
== CPP_CLOSE_PAREN
)
9930 c_parser_error (parser
, "expected identifier");
9933 c_parser_consume_token (parser
);
9934 c_parser_error (parser
, "unknown property attribute");
9938 keyword
= token
->keyword
;
9939 c_parser_consume_token (parser
);
9942 case RID_ASSIGN
: property_assign
= true; break;
9943 case RID_COPY
: property_copy
= true; break;
9944 case RID_NONATOMIC
: property_nonatomic
= true; break;
9945 case RID_READONLY
: property_readonly
= true; break;
9946 case RID_READWRITE
: property_readwrite
= true; break;
9947 case RID_RETAIN
: property_retain
= true; break;
9951 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9953 if (keyword
== RID_GETTER
)
9954 c_parser_error (parser
,
9955 "missing %<=%> (after %<getter%> attribute)");
9957 c_parser_error (parser
,
9958 "missing %<=%> (after %<setter%> attribute)");
9959 syntax_error
= true;
9962 c_parser_consume_token (parser
); /* eat the = */
9963 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9965 c_parser_error (parser
, "expected identifier");
9966 syntax_error
= true;
9969 if (keyword
== RID_SETTER
)
9971 if (property_setter_ident
!= NULL_TREE
)
9972 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9974 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9975 c_parser_consume_token (parser
);
9976 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9977 c_parser_error (parser
, "setter name must terminate with %<:%>");
9979 c_parser_consume_token (parser
);
9983 if (property_getter_ident
!= NULL_TREE
)
9984 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9986 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9987 c_parser_consume_token (parser
);
9991 c_parser_error (parser
, "unknown property attribute");
9992 syntax_error
= true;
9999 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10000 c_parser_consume_token (parser
);
10004 parser
->objc_property_attr_context
= false;
10005 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10007 /* ... and the property declaration(s). */
10008 properties
= c_parser_struct_declaration (parser
);
10010 if (properties
== error_mark_node
)
10012 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10013 parser
->error
= false;
10017 if (properties
== NULL_TREE
)
10018 c_parser_error (parser
, "expected identifier");
10021 /* Comma-separated properties are chained together in
10022 reverse order; add them one by one. */
10023 properties
= nreverse (properties
);
10025 for (; properties
; properties
= TREE_CHAIN (properties
))
10026 objc_add_property_declaration (loc
, copy_node (properties
),
10027 property_readonly
, property_readwrite
,
10028 property_assign
, property_retain
,
10029 property_copy
, property_nonatomic
,
10030 property_getter_ident
, property_setter_ident
);
10033 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10034 parser
->error
= false;
10037 /* Parse an Objective-C @synthesize declaration. The syntax is:
10039 objc-synthesize-declaration:
10040 @synthesize objc-synthesize-identifier-list ;
10042 objc-synthesize-identifier-list:
10043 objc-synthesize-identifier
10044 objc-synthesize-identifier-list, objc-synthesize-identifier
10046 objc-synthesize-identifier
10048 identifier = identifier
10051 @synthesize MyProperty;
10052 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
10054 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
10055 for C++. Keep them in sync.
10058 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
10060 tree list
= NULL_TREE
;
10062 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
10063 loc
= c_parser_peek_token (parser
)->location
;
10065 c_parser_consume_token (parser
);
10068 tree property
, ivar
;
10069 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10071 c_parser_error (parser
, "expected identifier");
10072 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10073 /* Once we find the semicolon, we can resume normal parsing.
10074 We have to reset parser->error manually because
10075 c_parser_skip_until_found() won't reset it for us if the
10076 next token is precisely a semicolon. */
10077 parser
->error
= false;
10080 property
= c_parser_peek_token (parser
)->value
;
10081 c_parser_consume_token (parser
);
10082 if (c_parser_next_token_is (parser
, CPP_EQ
))
10084 c_parser_consume_token (parser
);
10085 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10087 c_parser_error (parser
, "expected identifier");
10088 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10089 parser
->error
= false;
10092 ivar
= c_parser_peek_token (parser
)->value
;
10093 c_parser_consume_token (parser
);
10097 list
= chainon (list
, build_tree_list (ivar
, property
));
10098 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10099 c_parser_consume_token (parser
);
10103 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10104 objc_add_synthesize_declaration (loc
, list
);
10107 /* Parse an Objective-C @dynamic declaration. The syntax is:
10109 objc-dynamic-declaration:
10110 @dynamic identifier-list ;
10113 @dynamic MyProperty;
10114 @dynamic MyProperty, AnotherProperty;
10116 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
10117 for C++. Keep them in sync.
10120 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
10122 tree list
= NULL_TREE
;
10124 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
10125 loc
= c_parser_peek_token (parser
)->location
;
10127 c_parser_consume_token (parser
);
10131 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10133 c_parser_error (parser
, "expected identifier");
10134 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10135 parser
->error
= false;
10138 property
= c_parser_peek_token (parser
)->value
;
10139 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
10140 c_parser_consume_token (parser
);
10141 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10142 c_parser_consume_token (parser
);
10146 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10147 objc_add_dynamic_declaration (loc
, list
);
10151 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
10152 should be considered, statements. ALLOW_STMT is true if we're within
10153 the context of a function and such pragmas are to be allowed. Returns
10154 true if we actually parsed such a pragma. */
10157 c_parser_pragma (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
10161 id
= c_parser_peek_token (parser
)->pragma_kind
;
10162 gcc_assert (id
!= PRAGMA_NONE
);
10166 case PRAGMA_OACC_DECLARE
:
10167 c_parser_oacc_declare (parser
);
10170 case PRAGMA_OACC_ENTER_DATA
:
10171 if (context
!= pragma_compound
)
10173 if (context
== pragma_stmt
)
10174 c_parser_error (parser
, "%<#pragma acc enter data%> may only be "
10175 "used in compound statements");
10178 c_parser_oacc_enter_exit_data (parser
, true);
10181 case PRAGMA_OACC_EXIT_DATA
:
10182 if (context
!= pragma_compound
)
10184 if (context
== pragma_stmt
)
10185 c_parser_error (parser
, "%<#pragma acc exit data%> may only be "
10186 "used in compound statements");
10189 c_parser_oacc_enter_exit_data (parser
, false);
10192 case PRAGMA_OACC_ROUTINE
:
10193 if (context
!= pragma_external
)
10195 error_at (c_parser_peek_token (parser
)->location
,
10196 "%<#pragma acc routine%> must be at file scope");
10197 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10200 c_parser_oacc_routine (parser
, context
);
10203 case PRAGMA_OACC_UPDATE
:
10204 if (context
!= pragma_compound
)
10206 if (context
== pragma_stmt
)
10207 c_parser_error (parser
, "%<#pragma acc update%> may only be "
10208 "used in compound statements");
10211 c_parser_oacc_update (parser
);
10214 case PRAGMA_OMP_BARRIER
:
10215 if (context
!= pragma_compound
)
10217 if (context
== pragma_stmt
)
10218 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
10219 "used in compound statements");
10222 c_parser_omp_barrier (parser
);
10225 case PRAGMA_OMP_FLUSH
:
10226 if (context
!= pragma_compound
)
10228 if (context
== pragma_stmt
)
10229 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
10230 "used in compound statements");
10233 c_parser_omp_flush (parser
);
10236 case PRAGMA_OMP_TASKWAIT
:
10237 if (context
!= pragma_compound
)
10239 if (context
== pragma_stmt
)
10240 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
10241 "used in compound statements");
10244 c_parser_omp_taskwait (parser
);
10247 case PRAGMA_OMP_TASKYIELD
:
10248 if (context
!= pragma_compound
)
10250 if (context
== pragma_stmt
)
10251 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
10252 "used in compound statements");
10255 c_parser_omp_taskyield (parser
);
10258 case PRAGMA_OMP_CANCEL
:
10259 if (context
!= pragma_compound
)
10261 if (context
== pragma_stmt
)
10262 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
10263 "used in compound statements");
10266 c_parser_omp_cancel (parser
);
10269 case PRAGMA_OMP_CANCELLATION_POINT
:
10270 c_parser_omp_cancellation_point (parser
, context
);
10273 case PRAGMA_OMP_THREADPRIVATE
:
10274 c_parser_omp_threadprivate (parser
);
10277 case PRAGMA_OMP_TARGET
:
10278 return c_parser_omp_target (parser
, context
, if_p
);
10280 case PRAGMA_OMP_END_DECLARE_TARGET
:
10281 c_parser_omp_end_declare_target (parser
);
10284 case PRAGMA_OMP_SECTION
:
10285 error_at (c_parser_peek_token (parser
)->location
,
10286 "%<#pragma omp section%> may only be used in "
10287 "%<#pragma omp sections%> construct");
10288 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10291 case PRAGMA_OMP_DECLARE
:
10292 c_parser_omp_declare (parser
, context
);
10295 case PRAGMA_OMP_ORDERED
:
10296 return c_parser_omp_ordered (parser
, context
, if_p
);
10299 c_parser_consume_pragma (parser
);
10300 c_parser_skip_to_pragma_eol (parser
);
10301 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
10302 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
10303 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
10305 c_parser_error (parser
, "for, while or do statement expected");
10308 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10309 c_parser_for_statement (parser
, true, if_p
);
10310 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
10311 c_parser_while_statement (parser
, true, if_p
);
10313 c_parser_do_statement (parser
, true);
10316 case PRAGMA_GCC_PCH_PREPROCESS
:
10317 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
10318 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10321 case PRAGMA_CILK_SIMD
:
10322 if (!c_parser_cilk_verify_simd (parser
, context
))
10324 c_parser_consume_pragma (parser
);
10325 c_parser_cilk_simd (parser
, if_p
);
10327 case PRAGMA_CILK_GRAINSIZE
:
10328 if (!flag_cilkplus
)
10330 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
10332 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10335 if (context
== pragma_external
)
10337 error_at (c_parser_peek_token (parser
)->location
,
10338 "%<#pragma grainsize%> must be inside a function");
10339 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10342 c_parser_cilk_grainsize (parser
, if_p
);
10345 case PRAGMA_OACC_WAIT
:
10346 if (context
!= pragma_compound
)
10348 if (context
== pragma_stmt
)
10349 c_parser_error (parser
, "%<#pragma acc enter data%> may only be "
10350 "used in compound statements");
10353 /* FALL THROUGH. */
10356 if (id
< PRAGMA_FIRST_EXTERNAL
)
10358 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
10361 c_parser_error (parser
, "expected declaration specifiers");
10362 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10365 c_parser_omp_construct (parser
, if_p
);
10371 c_parser_consume_pragma (parser
);
10372 c_invoke_pragma_handler (id
);
10374 /* Skip to EOL, but suppress any error message. Those will have been
10375 generated by the handler routine through calling error, as opposed
10376 to calling c_parser_error. */
10377 parser
->error
= true;
10378 c_parser_skip_to_pragma_eol (parser
);
10383 /* The interface the pragma parsers have to the lexer. */
10386 pragma_lex (tree
*value
, location_t
*loc
)
10388 c_token
*tok
= c_parser_peek_token (the_parser
);
10389 enum cpp_ttype ret
= tok
->type
;
10391 *value
= tok
->value
;
10393 *loc
= tok
->location
;
10395 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
10399 if (ret
== CPP_KEYWORD
)
10401 c_parser_consume_token (the_parser
);
10408 c_parser_pragma_pch_preprocess (c_parser
*parser
)
10412 c_parser_consume_pragma (parser
);
10413 if (c_parser_next_token_is (parser
, CPP_STRING
))
10415 name
= c_parser_peek_token (parser
)->value
;
10416 c_parser_consume_token (parser
);
10419 c_parser_error (parser
, "expected string literal");
10420 c_parser_skip_to_pragma_eol (parser
);
10423 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
10426 /* OpenACC and OpenMP parsing routines. */
10428 /* Returns name of the next clause.
10429 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
10430 the token is not consumed. Otherwise appropriate pragma_omp_clause is
10431 returned and the token is consumed. */
10433 static pragma_omp_clause
10434 c_parser_omp_clause_name (c_parser
*parser
)
10436 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
10438 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10439 result
= PRAGMA_OACC_CLAUSE_AUTO
;
10440 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
10441 result
= PRAGMA_OMP_CLAUSE_IF
;
10442 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
10443 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
10444 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10445 result
= PRAGMA_OMP_CLAUSE_FOR
;
10446 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10448 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10453 if (!strcmp ("aligned", p
))
10454 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
10455 else if (!strcmp ("async", p
))
10456 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
10459 if (!strcmp ("collapse", p
))
10460 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
10461 else if (!strcmp ("copy", p
))
10462 result
= PRAGMA_OACC_CLAUSE_COPY
;
10463 else if (!strcmp ("copyin", p
))
10464 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
10465 else if (!strcmp ("copyout", p
))
10466 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
10467 else if (!strcmp ("copyprivate", p
))
10468 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
10469 else if (!strcmp ("create", p
))
10470 result
= PRAGMA_OACC_CLAUSE_CREATE
;
10473 if (!strcmp ("defaultmap", p
))
10474 result
= PRAGMA_OMP_CLAUSE_DEFAULTMAP
;
10475 else if (!strcmp ("delete", p
))
10476 result
= PRAGMA_OACC_CLAUSE_DELETE
;
10477 else if (!strcmp ("depend", p
))
10478 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
10479 else if (!strcmp ("device", p
))
10480 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
10481 else if (!strcmp ("deviceptr", p
))
10482 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
10483 else if (!strcmp ("device_resident", p
))
10484 result
= PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
;
10485 else if (!strcmp ("dist_schedule", p
))
10486 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
10489 if (!strcmp ("final", p
))
10490 result
= PRAGMA_OMP_CLAUSE_FINAL
;
10491 else if (!strcmp ("firstprivate", p
))
10492 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
10493 else if (!strcmp ("from", p
))
10494 result
= PRAGMA_OMP_CLAUSE_FROM
;
10497 if (!strcmp ("gang", p
))
10498 result
= PRAGMA_OACC_CLAUSE_GANG
;
10499 else if (!strcmp ("grainsize", p
))
10500 result
= PRAGMA_OMP_CLAUSE_GRAINSIZE
;
10503 if (!strcmp ("hint", p
))
10504 result
= PRAGMA_OMP_CLAUSE_HINT
;
10505 else if (!strcmp ("host", p
))
10506 result
= PRAGMA_OACC_CLAUSE_HOST
;
10509 if (!strcmp ("inbranch", p
))
10510 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
10511 else if (!strcmp ("independent", p
))
10512 result
= PRAGMA_OACC_CLAUSE_INDEPENDENT
;
10513 else if (!strcmp ("is_device_ptr", p
))
10514 result
= PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
;
10517 if (!strcmp ("lastprivate", p
))
10518 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
10519 else if (!strcmp ("linear", p
))
10520 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
10521 else if (!strcmp ("link", p
))
10522 result
= PRAGMA_OMP_CLAUSE_LINK
;
10525 if (!strcmp ("map", p
))
10526 result
= PRAGMA_OMP_CLAUSE_MAP
;
10527 else if (!strcmp ("mergeable", p
))
10528 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
10529 else if (flag_cilkplus
&& !strcmp ("mask", p
))
10530 result
= PRAGMA_CILK_CLAUSE_MASK
;
10533 if (!strcmp ("nogroup", p
))
10534 result
= PRAGMA_OMP_CLAUSE_NOGROUP
;
10535 else if (!strcmp ("notinbranch", p
))
10536 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
10537 else if (!strcmp ("nowait", p
))
10538 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
10539 else if (!strcmp ("num_gangs", p
))
10540 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
10541 else if (!strcmp ("num_tasks", p
))
10542 result
= PRAGMA_OMP_CLAUSE_NUM_TASKS
;
10543 else if (!strcmp ("num_teams", p
))
10544 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
10545 else if (!strcmp ("num_threads", p
))
10546 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
10547 else if (!strcmp ("num_workers", p
))
10548 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
10549 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
10550 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
10553 if (!strcmp ("ordered", p
))
10554 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
10557 if (!strcmp ("parallel", p
))
10558 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
10559 else if (!strcmp ("present", p
))
10560 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
10561 else if (!strcmp ("present_or_copy", p
)
10562 || !strcmp ("pcopy", p
))
10563 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
;
10564 else if (!strcmp ("present_or_copyin", p
)
10565 || !strcmp ("pcopyin", p
))
10566 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
;
10567 else if (!strcmp ("present_or_copyout", p
)
10568 || !strcmp ("pcopyout", p
))
10569 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
;
10570 else if (!strcmp ("present_or_create", p
)
10571 || !strcmp ("pcreate", p
))
10572 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
;
10573 else if (!strcmp ("priority", p
))
10574 result
= PRAGMA_OMP_CLAUSE_PRIORITY
;
10575 else if (!strcmp ("private", p
))
10576 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
10577 else if (!strcmp ("proc_bind", p
))
10578 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
10581 if (!strcmp ("reduction", p
))
10582 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
10585 if (!strcmp ("safelen", p
))
10586 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
10587 else if (!strcmp ("schedule", p
))
10588 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
10589 else if (!strcmp ("sections", p
))
10590 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
10591 else if (!strcmp ("seq", p
))
10592 result
= PRAGMA_OACC_CLAUSE_SEQ
;
10593 else if (!strcmp ("shared", p
))
10594 result
= PRAGMA_OMP_CLAUSE_SHARED
;
10595 else if (!strcmp ("simd", p
))
10596 result
= PRAGMA_OMP_CLAUSE_SIMD
;
10597 else if (!strcmp ("simdlen", p
))
10598 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
10599 else if (!strcmp ("self", p
))
10600 result
= PRAGMA_OACC_CLAUSE_SELF
;
10603 if (!strcmp ("taskgroup", p
))
10604 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
10605 else if (!strcmp ("thread_limit", p
))
10606 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
10607 else if (!strcmp ("threads", p
))
10608 result
= PRAGMA_OMP_CLAUSE_THREADS
;
10609 else if (!strcmp ("tile", p
))
10610 result
= PRAGMA_OACC_CLAUSE_TILE
;
10611 else if (!strcmp ("to", p
))
10612 result
= PRAGMA_OMP_CLAUSE_TO
;
10615 if (!strcmp ("uniform", p
))
10616 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
10617 else if (!strcmp ("untied", p
))
10618 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
10619 else if (!strcmp ("use_device", p
))
10620 result
= PRAGMA_OACC_CLAUSE_USE_DEVICE
;
10621 else if (!strcmp ("use_device_ptr", p
))
10622 result
= PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
;
10625 if (!strcmp ("vector", p
))
10626 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
10627 else if (!strcmp ("vector_length", p
))
10628 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
10629 else if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
10630 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
10633 if (!strcmp ("wait", p
))
10634 result
= PRAGMA_OACC_CLAUSE_WAIT
;
10635 else if (!strcmp ("worker", p
))
10636 result
= PRAGMA_OACC_CLAUSE_WORKER
;
10641 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
10642 c_parser_consume_token (parser
);
10647 /* Validate that a clause of the given type does not already exist. */
10650 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
10655 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10656 if (OMP_CLAUSE_CODE (c
) == code
)
10658 location_t loc
= OMP_CLAUSE_LOCATION (c
);
10659 error_at (loc
, "too many %qs clauses", name
);
10665 Parse wait clause or wait directive parameters. */
10668 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
10670 vec
<tree
, va_gc
> *args
;
10673 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10676 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
10678 if (args
->length () == 0)
10680 c_parser_error (parser
, "expected integer expression before ')'");
10681 release_tree_vector (args
);
10685 args_tree
= build_tree_list_vec (args
);
10687 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
10689 tree targ
= TREE_VALUE (t
);
10691 if (targ
!= error_mark_node
)
10693 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
10695 c_parser_error (parser
, "expression must be integral");
10696 targ
= error_mark_node
;
10700 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
10702 OMP_CLAUSE_DECL (c
) = targ
;
10703 OMP_CLAUSE_CHAIN (c
) = list
;
10709 release_tree_vector (args
);
10710 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10714 /* OpenACC 2.0, OpenMP 2.5:
10717 variable-list , identifier
10719 If KIND is nonzero, create the appropriate node and install the
10720 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10721 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10723 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10724 return the list created. */
10727 c_parser_omp_variable_list (c_parser
*parser
,
10728 location_t clause_loc
,
10729 enum omp_clause_code kind
, tree list
)
10731 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
10732 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
10733 c_parser_error (parser
, "expected identifier");
10735 while (c_parser_next_token_is (parser
, CPP_NAME
)
10736 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
10738 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
10740 if (t
== NULL_TREE
)
10742 undeclared_variable (c_parser_peek_token (parser
)->location
,
10743 c_parser_peek_token (parser
)->value
);
10744 t
= error_mark_node
;
10747 c_parser_consume_token (parser
);
10749 if (t
== error_mark_node
)
10751 else if (kind
!= 0)
10755 case OMP_CLAUSE__CACHE_
:
10756 /* The OpenACC cache directive explicitly only allows "array
10757 elements or subarrays". */
10758 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
10760 c_parser_error (parser
, "expected %<[%>");
10761 t
= error_mark_node
;
10765 case OMP_CLAUSE_MAP
:
10766 case OMP_CLAUSE_FROM
:
10767 case OMP_CLAUSE_TO
:
10768 while (c_parser_next_token_is (parser
, CPP_DOT
))
10770 location_t op_loc
= c_parser_peek_token (parser
)->location
;
10771 c_parser_consume_token (parser
);
10772 if (!c_parser_next_token_is (parser
, CPP_NAME
))
10774 c_parser_error (parser
, "expected identifier");
10775 t
= error_mark_node
;
10779 c_token
*comp_tok
= c_parser_peek_token (parser
);
10780 tree ident
= comp_tok
->value
;
10781 location_t comp_loc
= comp_tok
->location
;
10782 c_parser_consume_token (parser
);
10783 t
= build_component_ref (op_loc
, t
, ident
, comp_loc
);
10786 case OMP_CLAUSE_DEPEND
:
10787 case OMP_CLAUSE_REDUCTION
:
10788 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10790 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
10792 c_parser_consume_token (parser
);
10793 if (!c_parser_next_token_is (parser
, CPP_COLON
))
10795 location_t expr_loc
10796 = c_parser_peek_token (parser
)->location
;
10797 c_expr expr
= c_parser_expression (parser
);
10798 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
10800 low_bound
= expr
.value
;
10802 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10803 length
= integer_one_node
;
10806 /* Look for `:'. */
10807 if (!c_parser_require (parser
, CPP_COLON
,
10810 t
= error_mark_node
;
10813 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10815 location_t expr_loc
10816 = c_parser_peek_token (parser
)->location
;
10817 c_expr expr
= c_parser_expression (parser
);
10818 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
10820 length
= expr
.value
;
10823 /* Look for the closing `]'. */
10824 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
10827 t
= error_mark_node
;
10831 t
= tree_cons (low_bound
, length
, t
);
10838 if (t
!= error_mark_node
)
10840 tree u
= build_omp_clause (clause_loc
, kind
);
10841 OMP_CLAUSE_DECL (u
) = t
;
10842 OMP_CLAUSE_CHAIN (u
) = list
;
10847 list
= tree_cons (t
, NULL_TREE
, list
);
10849 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
10852 c_parser_consume_token (parser
);
10858 /* Similarly, but expect leading and trailing parenthesis. This is a very
10859 common case for OpenACC and OpenMP clauses. */
10862 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
10865 /* The clauses location. */
10866 location_t loc
= c_parser_peek_token (parser
)->location
;
10868 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10870 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
10871 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10877 copy ( variable-list )
10878 copyin ( variable-list )
10879 copyout ( variable-list )
10880 create ( variable-list )
10881 delete ( variable-list )
10882 present ( variable-list )
10883 present_or_copy ( variable-list )
10884 pcopy ( variable-list )
10885 present_or_copyin ( variable-list )
10886 pcopyin ( variable-list )
10887 present_or_copyout ( variable-list )
10888 pcopyout ( variable-list )
10889 present_or_create ( variable-list )
10890 pcreate ( variable-list ) */
10893 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
10896 enum gomp_map_kind kind
;
10899 case PRAGMA_OACC_CLAUSE_COPY
:
10900 kind
= GOMP_MAP_FORCE_TOFROM
;
10902 case PRAGMA_OACC_CLAUSE_COPYIN
:
10903 kind
= GOMP_MAP_FORCE_TO
;
10905 case PRAGMA_OACC_CLAUSE_COPYOUT
:
10906 kind
= GOMP_MAP_FORCE_FROM
;
10908 case PRAGMA_OACC_CLAUSE_CREATE
:
10909 kind
= GOMP_MAP_FORCE_ALLOC
;
10911 case PRAGMA_OACC_CLAUSE_DELETE
:
10912 kind
= GOMP_MAP_DELETE
;
10914 case PRAGMA_OACC_CLAUSE_DEVICE
:
10915 kind
= GOMP_MAP_FORCE_TO
;
10917 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
10918 kind
= GOMP_MAP_DEVICE_RESIDENT
;
10920 case PRAGMA_OACC_CLAUSE_HOST
:
10921 case PRAGMA_OACC_CLAUSE_SELF
:
10922 kind
= GOMP_MAP_FORCE_FROM
;
10924 case PRAGMA_OACC_CLAUSE_LINK
:
10925 kind
= GOMP_MAP_LINK
;
10927 case PRAGMA_OACC_CLAUSE_PRESENT
:
10928 kind
= GOMP_MAP_FORCE_PRESENT
;
10930 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
10931 kind
= GOMP_MAP_TOFROM
;
10933 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
10934 kind
= GOMP_MAP_TO
;
10936 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
10937 kind
= GOMP_MAP_FROM
;
10939 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
10940 kind
= GOMP_MAP_ALLOC
;
10943 gcc_unreachable ();
10946 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
10948 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10949 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
10955 deviceptr ( variable-list ) */
10958 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
10960 location_t loc
= c_parser_peek_token (parser
)->location
;
10963 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10964 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
10965 variable-list must only allow for pointer variables. */
10966 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10967 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
10969 tree v
= TREE_PURPOSE (t
);
10971 /* FIXME diagnostics: Ideally we should keep individual
10972 locations for all the variables in the var list to make the
10973 following errors more precise. Perhaps
10974 c_parser_omp_var_list_parens() should construct a list of
10975 locations to go along with the var list. */
10977 if (!VAR_P (v
) && TREE_CODE (v
) != PARM_DECL
)
10978 error_at (loc
, "%qD is not a variable", v
);
10979 else if (TREE_TYPE (v
) == error_mark_node
)
10981 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
10982 error_at (loc
, "%qD is not a pointer variable", v
);
10984 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10985 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
10986 OMP_CLAUSE_DECL (u
) = v
;
10987 OMP_CLAUSE_CHAIN (u
) = list
;
10994 /* OpenACC 2.0, OpenMP 3.0:
10995 collapse ( constant-expression ) */
10998 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
11000 tree c
, num
= error_mark_node
;
11004 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
11005 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
11007 loc
= c_parser_peek_token (parser
)->location
;
11008 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11010 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
11011 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11013 if (num
== error_mark_node
)
11015 mark_exp_read (num
);
11016 num
= c_fully_fold (num
, false, NULL
);
11017 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
11018 || !tree_fits_shwi_p (num
)
11019 || (n
= tree_to_shwi (num
)) <= 0
11023 "collapse argument needs positive constant integer expression");
11026 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
11027 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
11028 OMP_CLAUSE_CHAIN (c
) = list
;
11033 copyin ( variable-list ) */
11036 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
11038 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
11042 copyprivate ( variable-list ) */
11045 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
11047 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
11051 default ( shared | none )
11057 c_parser_omp_clause_default (c_parser
*parser
, tree list
, bool is_oacc
)
11059 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
11060 location_t loc
= c_parser_peek_token (parser
)->location
;
11063 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11065 if (c_parser_next_token_is (parser
, CPP_NAME
))
11067 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11072 if (strcmp ("none", p
) != 0)
11074 kind
= OMP_CLAUSE_DEFAULT_NONE
;
11078 if (strcmp ("shared", p
) != 0 || is_oacc
)
11080 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
11087 c_parser_consume_token (parser
);
11093 c_parser_error (parser
, "expected %<none%>");
11095 c_parser_error (parser
, "expected %<none%> or %<shared%>");
11097 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11099 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
11102 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
11103 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
11104 OMP_CLAUSE_CHAIN (c
) = list
;
11105 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
11111 firstprivate ( variable-list ) */
11114 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
11116 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
11120 final ( expression ) */
11123 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
11125 location_t loc
= c_parser_peek_token (parser
)->location
;
11126 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11128 tree t
= c_parser_paren_condition (parser
);
11131 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
11133 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
11134 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
11135 OMP_CLAUSE_CHAIN (c
) = list
;
11139 c_parser_error (parser
, "expected %<(%>");
11144 /* OpenACC, OpenMP 2.5:
11148 if ( directive-name-modifier : expression )
11150 directive-name-modifier:
11151 parallel | task | taskloop | target data | target | target update
11152 | target enter data | target exit data */
11155 c_parser_omp_clause_if (c_parser
*parser
, tree list
, bool is_omp
)
11157 location_t location
= c_parser_peek_token (parser
)->location
;
11158 enum tree_code if_modifier
= ERROR_MARK
;
11160 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11163 if (is_omp
&& c_parser_next_token_is (parser
, CPP_NAME
))
11165 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11167 if (strcmp (p
, "parallel") == 0)
11168 if_modifier
= OMP_PARALLEL
;
11169 else if (strcmp (p
, "task") == 0)
11170 if_modifier
= OMP_TASK
;
11171 else if (strcmp (p
, "taskloop") == 0)
11172 if_modifier
= OMP_TASKLOOP
;
11173 else if (strcmp (p
, "target") == 0)
11175 if_modifier
= OMP_TARGET
;
11176 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11178 p
= IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser
)->value
);
11179 if (strcmp ("data", p
) == 0)
11180 if_modifier
= OMP_TARGET_DATA
;
11181 else if (strcmp ("update", p
) == 0)
11182 if_modifier
= OMP_TARGET_UPDATE
;
11183 else if (strcmp ("enter", p
) == 0)
11184 if_modifier
= OMP_TARGET_ENTER_DATA
;
11185 else if (strcmp ("exit", p
) == 0)
11186 if_modifier
= OMP_TARGET_EXIT_DATA
;
11187 if (if_modifier
!= OMP_TARGET
)
11190 c_parser_consume_token (parser
);
11194 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
11195 error_at (loc
, "expected %<data%>, %<update%>, %<enter%> "
11197 if_modifier
= ERROR_MARK
;
11199 if (if_modifier
== OMP_TARGET_ENTER_DATA
11200 || if_modifier
== OMP_TARGET_EXIT_DATA
)
11202 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11204 p
= IDENTIFIER_POINTER
11205 (c_parser_peek_2nd_token (parser
)->value
);
11206 if (strcmp ("data", p
) == 0)
11210 c_parser_consume_token (parser
);
11214 = c_parser_peek_2nd_token (parser
)->location
;
11215 error_at (loc
, "expected %<data%>");
11216 if_modifier
= ERROR_MARK
;
11221 if (if_modifier
!= ERROR_MARK
)
11223 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11225 c_parser_consume_token (parser
);
11226 c_parser_consume_token (parser
);
11232 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
11233 error_at (loc
, "expected %<:%>");
11235 if_modifier
= ERROR_MARK
;
11240 tree t
= c_parser_condition (parser
), c
;
11241 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11243 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11244 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IF
)
11246 if (if_modifier
!= ERROR_MARK
11247 && OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
11249 const char *p
= NULL
;
11250 switch (if_modifier
)
11252 case OMP_PARALLEL
: p
= "parallel"; break;
11253 case OMP_TASK
: p
= "task"; break;
11254 case OMP_TASKLOOP
: p
= "taskloop"; break;
11255 case OMP_TARGET_DATA
: p
= "target data"; break;
11256 case OMP_TARGET
: p
= "target"; break;
11257 case OMP_TARGET_UPDATE
: p
= "target update"; break;
11258 case OMP_TARGET_ENTER_DATA
: p
= "enter data"; break;
11259 case OMP_TARGET_EXIT_DATA
: p
= "exit data"; break;
11260 default: gcc_unreachable ();
11262 error_at (location
, "too many %<if%> clauses with %qs modifier",
11266 else if (OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
11269 error_at (location
, "too many %<if%> clauses");
11271 error_at (location
, "too many %<if%> clauses without modifier");
11274 else if (if_modifier
== ERROR_MARK
11275 || OMP_CLAUSE_IF_MODIFIER (c
) == ERROR_MARK
)
11277 error_at (location
, "if any %<if%> clause has modifier, then all "
11278 "%<if%> clauses have to use modifier");
11283 c
= build_omp_clause (location
, OMP_CLAUSE_IF
);
11284 OMP_CLAUSE_IF_MODIFIER (c
) = if_modifier
;
11285 OMP_CLAUSE_IF_EXPR (c
) = t
;
11286 OMP_CLAUSE_CHAIN (c
) = list
;
11291 lastprivate ( variable-list ) */
11294 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
11296 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
11303 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11307 /* FIXME: Should we allow duplicates? */
11308 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
11310 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
11311 OMP_CLAUSE_MERGEABLE
);
11312 OMP_CLAUSE_CHAIN (c
) = list
;
11321 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11324 location_t loc
= c_parser_peek_token (parser
)->location
;
11326 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
11328 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
11329 OMP_CLAUSE_CHAIN (c
) = list
;
11334 num_gangs ( expression ) */
11337 c_parser_omp_clause_num_gangs (c_parser
*parser
, tree list
)
11339 location_t num_gangs_loc
= c_parser_peek_token (parser
)->location
;
11340 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11342 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11343 c_expr expr
= c_parser_expression (parser
);
11344 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11345 tree c
, t
= expr
.value
;
11346 t
= c_fully_fold (t
, false, NULL
);
11348 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11350 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11352 c_parser_error (parser
, "expected integer expression");
11356 /* Attempt to statically determine when the number isn't positive. */
11357 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11358 build_int_cst (TREE_TYPE (t
), 0));
11359 protected_set_expr_location (c
, expr_loc
);
11360 if (c
== boolean_true_node
)
11362 warning_at (expr_loc
, 0,
11363 "%<num_gangs%> value must be positive");
11364 t
= integer_one_node
;
11367 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_GANGS
, "num_gangs");
11369 c
= build_omp_clause (num_gangs_loc
, OMP_CLAUSE_NUM_GANGS
);
11370 OMP_CLAUSE_NUM_GANGS_EXPR (c
) = t
;
11371 OMP_CLAUSE_CHAIN (c
) = list
;
11379 num_threads ( expression ) */
11382 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
11384 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
11385 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11387 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11388 c_expr expr
= c_parser_expression (parser
);
11389 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11390 tree c
, t
= expr
.value
;
11391 t
= c_fully_fold (t
, false, NULL
);
11393 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11395 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11397 c_parser_error (parser
, "expected integer expression");
11401 /* Attempt to statically determine when the number isn't positive. */
11402 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11403 build_int_cst (TREE_TYPE (t
), 0));
11404 protected_set_expr_location (c
, expr_loc
);
11405 if (c
== boolean_true_node
)
11407 warning_at (expr_loc
, 0,
11408 "%<num_threads%> value must be positive");
11409 t
= integer_one_node
;
11412 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
11414 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
11415 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
11416 OMP_CLAUSE_CHAIN (c
) = list
;
11424 num_tasks ( expression ) */
11427 c_parser_omp_clause_num_tasks (c_parser
*parser
, tree list
)
11429 location_t num_tasks_loc
= c_parser_peek_token (parser
)->location
;
11430 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11432 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11433 c_expr expr
= c_parser_expression (parser
);
11434 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11435 tree c
, t
= expr
.value
;
11436 t
= c_fully_fold (t
, false, NULL
);
11438 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11440 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11442 c_parser_error (parser
, "expected integer expression");
11446 /* Attempt to statically determine when the number isn't positive. */
11447 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11448 build_int_cst (TREE_TYPE (t
), 0));
11449 if (CAN_HAVE_LOCATION_P (c
))
11450 SET_EXPR_LOCATION (c
, expr_loc
);
11451 if (c
== boolean_true_node
)
11453 warning_at (expr_loc
, 0, "%<num_tasks%> value must be positive");
11454 t
= integer_one_node
;
11457 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TASKS
, "num_tasks");
11459 c
= build_omp_clause (num_tasks_loc
, OMP_CLAUSE_NUM_TASKS
);
11460 OMP_CLAUSE_NUM_TASKS_EXPR (c
) = t
;
11461 OMP_CLAUSE_CHAIN (c
) = list
;
11469 grainsize ( expression ) */
11472 c_parser_omp_clause_grainsize (c_parser
*parser
, tree list
)
11474 location_t grainsize_loc
= c_parser_peek_token (parser
)->location
;
11475 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11477 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11478 c_expr expr
= c_parser_expression (parser
);
11479 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11480 tree c
, t
= expr
.value
;
11481 t
= c_fully_fold (t
, false, NULL
);
11483 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11485 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11487 c_parser_error (parser
, "expected integer expression");
11491 /* Attempt to statically determine when the number isn't positive. */
11492 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11493 build_int_cst (TREE_TYPE (t
), 0));
11494 if (CAN_HAVE_LOCATION_P (c
))
11495 SET_EXPR_LOCATION (c
, expr_loc
);
11496 if (c
== boolean_true_node
)
11498 warning_at (expr_loc
, 0, "%<grainsize%> value must be positive");
11499 t
= integer_one_node
;
11502 check_no_duplicate_clause (list
, OMP_CLAUSE_GRAINSIZE
, "grainsize");
11504 c
= build_omp_clause (grainsize_loc
, OMP_CLAUSE_GRAINSIZE
);
11505 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
11506 OMP_CLAUSE_CHAIN (c
) = list
;
11514 priority ( expression ) */
11517 c_parser_omp_clause_priority (c_parser
*parser
, tree list
)
11519 location_t priority_loc
= c_parser_peek_token (parser
)->location
;
11520 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11522 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11523 c_expr expr
= c_parser_expression (parser
);
11524 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11525 tree c
, t
= expr
.value
;
11526 t
= c_fully_fold (t
, false, NULL
);
11528 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11530 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11532 c_parser_error (parser
, "expected integer expression");
11536 /* Attempt to statically determine when the number isn't
11538 c
= fold_build2_loc (expr_loc
, LT_EXPR
, boolean_type_node
, t
,
11539 build_int_cst (TREE_TYPE (t
), 0));
11540 if (CAN_HAVE_LOCATION_P (c
))
11541 SET_EXPR_LOCATION (c
, expr_loc
);
11542 if (c
== boolean_true_node
)
11544 warning_at (expr_loc
, 0, "%<priority%> value must be non-negative");
11545 t
= integer_one_node
;
11548 check_no_duplicate_clause (list
, OMP_CLAUSE_PRIORITY
, "priority");
11550 c
= build_omp_clause (priority_loc
, OMP_CLAUSE_PRIORITY
);
11551 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
11552 OMP_CLAUSE_CHAIN (c
) = list
;
11560 hint ( expression ) */
11563 c_parser_omp_clause_hint (c_parser
*parser
, tree list
)
11565 location_t hint_loc
= c_parser_peek_token (parser
)->location
;
11566 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11568 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11569 c_expr expr
= c_parser_expression (parser
);
11570 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11571 tree c
, t
= expr
.value
;
11572 t
= c_fully_fold (t
, false, NULL
);
11574 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11576 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11578 c_parser_error (parser
, "expected integer expression");
11582 check_no_duplicate_clause (list
, OMP_CLAUSE_HINT
, "hint");
11584 c
= build_omp_clause (hint_loc
, OMP_CLAUSE_HINT
);
11585 OMP_CLAUSE_HINT_EXPR (c
) = t
;
11586 OMP_CLAUSE_CHAIN (c
) = list
;
11594 defaultmap ( tofrom : scalar ) */
11597 c_parser_omp_clause_defaultmap (c_parser
*parser
, tree list
)
11599 location_t loc
= c_parser_peek_token (parser
)->location
;
11603 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11605 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11607 c_parser_error (parser
, "expected %<tofrom%>");
11610 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11611 if (strcmp (p
, "tofrom") != 0)
11613 c_parser_error (parser
, "expected %<tofrom%>");
11616 c_parser_consume_token (parser
);
11617 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11619 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11621 c_parser_error (parser
, "expected %<scalar%>");
11624 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11625 if (strcmp (p
, "scalar") != 0)
11627 c_parser_error (parser
, "expected %<scalar%>");
11630 c_parser_consume_token (parser
);
11631 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11632 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULTMAP
, "defaultmap");
11633 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULTMAP
);
11634 OMP_CLAUSE_CHAIN (c
) = list
;
11638 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11643 use_device ( variable-list )
11646 use_device_ptr ( variable-list ) */
11649 c_parser_omp_clause_use_device_ptr (c_parser
*parser
, tree list
)
11651 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_USE_DEVICE_PTR
,
11656 is_device_ptr ( variable-list ) */
11659 c_parser_omp_clause_is_device_ptr (c_parser
*parser
, tree list
)
11661 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_IS_DEVICE_PTR
, list
);
11665 num_workers ( expression ) */
11668 c_parser_omp_clause_num_workers (c_parser
*parser
, tree list
)
11670 location_t num_workers_loc
= c_parser_peek_token (parser
)->location
;
11671 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11673 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11674 c_expr expr
= c_parser_expression (parser
);
11675 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11676 tree c
, t
= expr
.value
;
11677 t
= c_fully_fold (t
, false, NULL
);
11679 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11681 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11683 c_parser_error (parser
, "expected integer expression");
11687 /* Attempt to statically determine when the number isn't positive. */
11688 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11689 build_int_cst (TREE_TYPE (t
), 0));
11690 protected_set_expr_location (c
, expr_loc
);
11691 if (c
== boolean_true_node
)
11693 warning_at (expr_loc
, 0,
11694 "%<num_workers%> value must be positive");
11695 t
= integer_one_node
;
11698 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_WORKERS
, "num_workers");
11700 c
= build_omp_clause (num_workers_loc
, OMP_CLAUSE_NUM_WORKERS
);
11701 OMP_CLAUSE_NUM_WORKERS_EXPR (c
) = t
;
11702 OMP_CLAUSE_CHAIN (c
) = list
;
11711 gang [( gang-arg-list )]
11712 worker [( [num:] int-expr )]
11713 vector [( [length:] int-expr )]
11715 where gang-arg is one of:
11720 and size-expr may be:
11727 c_parser_oacc_shape_clause (c_parser
*parser
, omp_clause_code kind
,
11728 const char *str
, tree list
)
11730 const char *id
= "num";
11731 tree ops
[2] = { NULL_TREE
, NULL_TREE
}, c
;
11732 location_t loc
= c_parser_peek_token (parser
)->location
;
11734 if (kind
== OMP_CLAUSE_VECTOR
)
11737 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11739 c_parser_consume_token (parser
);
11743 c_token
*next
= c_parser_peek_token (parser
);
11746 /* Gang static argument. */
11747 if (kind
== OMP_CLAUSE_GANG
11748 && c_parser_next_token_is_keyword (parser
, RID_STATIC
))
11750 c_parser_consume_token (parser
);
11752 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11753 goto cleanup_error
;
11756 if (ops
[idx
] != NULL_TREE
)
11758 c_parser_error (parser
, "too many %<static%> arguments");
11759 goto cleanup_error
;
11762 /* Check for the '*' argument. */
11763 if (c_parser_next_token_is (parser
, CPP_MULT
)
11764 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
11765 || c_parser_peek_2nd_token (parser
)->type
11766 == CPP_CLOSE_PAREN
))
11768 c_parser_consume_token (parser
);
11769 ops
[idx
] = integer_minus_one_node
;
11771 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11773 c_parser_consume_token (parser
);
11780 /* Worker num: argument and vector length: arguments. */
11781 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11782 && strcmp (id
, IDENTIFIER_POINTER (next
->value
)) == 0
11783 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11785 c_parser_consume_token (parser
); /* id */
11786 c_parser_consume_token (parser
); /* ':' */
11789 /* Now collect the actual argument. */
11790 if (ops
[idx
] != NULL_TREE
)
11792 c_parser_error (parser
, "unexpected argument");
11793 goto cleanup_error
;
11796 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11797 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
11798 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
11799 tree expr
= cexpr
.value
;
11800 if (expr
== error_mark_node
)
11801 goto cleanup_error
;
11803 expr
= c_fully_fold (expr
, false, NULL
);
11805 /* Attempt to statically determine when the number isn't a
11806 positive integer. */
11808 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
11810 c_parser_error (parser
, "expected integer expression");
11814 tree c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
11815 build_int_cst (TREE_TYPE (expr
), 0));
11816 if (c
== boolean_true_node
)
11818 warning_at (loc
, 0,
11819 "%<%s%> value must be positive", str
);
11820 expr
= integer_one_node
;
11825 if (kind
== OMP_CLAUSE_GANG
11826 && c_parser_next_token_is (parser
, CPP_COMMA
))
11828 c_parser_consume_token (parser
);
11835 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
11836 goto cleanup_error
;
11839 check_no_duplicate_clause (list
, kind
, str
);
11841 c
= build_omp_clause (loc
, kind
);
11844 OMP_CLAUSE_OPERAND (c
, 1) = ops
[1];
11846 OMP_CLAUSE_OPERAND (c
, 0) = ops
[0];
11847 OMP_CLAUSE_CHAIN (c
) = list
;
11852 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
11863 c_parser_oacc_simple_clause (c_parser
*parser
, enum omp_clause_code code
,
11866 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
11868 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11869 OMP_CLAUSE_CHAIN (c
) = list
;
11875 async [( int-expr )] */
11878 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
11881 location_t loc
= c_parser_peek_token (parser
)->location
;
11883 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
11885 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
11887 c_parser_consume_token (parser
);
11889 t
= c_parser_expression (parser
).value
;
11890 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11891 c_parser_error (parser
, "expected integer expression");
11892 else if (t
== error_mark_node
11893 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
11897 t
= c_fully_fold (t
, false, NULL
);
11899 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
11901 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
11902 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
11903 OMP_CLAUSE_CHAIN (c
) = list
;
11910 tile ( size-expr-list ) */
11913 c_parser_oacc_clause_tile (c_parser
*parser
, tree list
)
11915 tree c
, expr
= error_mark_node
;
11917 tree tile
= NULL_TREE
;
11919 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
11920 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
11922 loc
= c_parser_peek_token (parser
)->location
;
11923 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11928 if (tile
&& !c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
11931 if (c_parser_next_token_is (parser
, CPP_MULT
)
11932 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
11933 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
11935 c_parser_consume_token (parser
);
11936 expr
= integer_zero_node
;
11940 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11941 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
11942 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
11943 expr
= cexpr
.value
;
11945 if (expr
== error_mark_node
)
11947 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11952 expr
= c_fully_fold (expr
, false, NULL
);
11954 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
))
11955 || !tree_fits_shwi_p (expr
)
11956 || tree_to_shwi (expr
) <= 0)
11958 error_at (expr_loc
, "%<tile%> argument needs positive"
11959 " integral constant");
11960 expr
= integer_zero_node
;
11964 tile
= tree_cons (NULL_TREE
, expr
, tile
);
11966 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
));
11968 /* Consume the trailing ')'. */
11969 c_parser_consume_token (parser
);
11971 c
= build_omp_clause (loc
, OMP_CLAUSE_TILE
);
11972 tile
= nreverse (tile
);
11973 OMP_CLAUSE_TILE_LIST (c
) = tile
;
11974 OMP_CLAUSE_CHAIN (c
) = list
;
11979 wait ( int-expr-list ) */
11982 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
11984 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11986 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
11987 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
11996 ordered ( constant-expression ) */
11999 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
12001 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
12003 tree c
, num
= NULL_TREE
;
12005 location_t loc
= c_parser_peek_token (parser
)->location
;
12006 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
12008 c_parser_consume_token (parser
);
12009 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
12010 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12012 if (num
== error_mark_node
)
12016 mark_exp_read (num
);
12017 num
= c_fully_fold (num
, false, NULL
);
12018 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
12019 || !tree_fits_shwi_p (num
)
12020 || (n
= tree_to_shwi (num
)) <= 0
12023 error_at (loc
, "ordered argument needs positive "
12024 "constant integer expression");
12028 c
= build_omp_clause (loc
, OMP_CLAUSE_ORDERED
);
12029 OMP_CLAUSE_ORDERED_EXPR (c
) = num
;
12030 OMP_CLAUSE_CHAIN (c
) = list
;
12035 private ( variable-list ) */
12038 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
12040 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
12044 reduction ( reduction-operator : variable-list )
12046 reduction-operator:
12047 One of: + * - & ^ | && ||
12051 reduction-operator:
12052 One of: + * - & ^ | && || max min
12056 reduction-operator:
12057 One of: + * - & ^ | && ||
12061 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
12063 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12064 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12066 enum tree_code code
= ERROR_MARK
;
12067 tree reduc_id
= NULL_TREE
;
12069 switch (c_parser_peek_token (parser
)->type
)
12081 code
= BIT_AND_EXPR
;
12084 code
= BIT_XOR_EXPR
;
12087 code
= BIT_IOR_EXPR
;
12090 code
= TRUTH_ANDIF_EXPR
;
12093 code
= TRUTH_ORIF_EXPR
;
12098 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12099 if (strcmp (p
, "min") == 0)
12104 if (strcmp (p
, "max") == 0)
12109 reduc_id
= c_parser_peek_token (parser
)->value
;
12113 c_parser_error (parser
,
12114 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
12115 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
12116 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12119 c_parser_consume_token (parser
);
12120 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
12121 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12125 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12126 OMP_CLAUSE_REDUCTION
, list
);
12127 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12129 tree d
= OMP_CLAUSE_DECL (c
), type
;
12130 if (TREE_CODE (d
) != TREE_LIST
)
12131 type
= TREE_TYPE (d
);
12136 for (t
= d
; TREE_CODE (t
) == TREE_LIST
; t
= TREE_CHAIN (t
))
12138 type
= TREE_TYPE (t
);
12141 if (TREE_CODE (type
) != POINTER_TYPE
12142 && TREE_CODE (type
) != ARRAY_TYPE
)
12144 type
= TREE_TYPE (type
);
12148 while (TREE_CODE (type
) == ARRAY_TYPE
)
12149 type
= TREE_TYPE (type
);
12150 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
12151 if (code
== ERROR_MARK
12152 || !(INTEGRAL_TYPE_P (type
)
12153 || TREE_CODE (type
) == REAL_TYPE
12154 || TREE_CODE (type
) == COMPLEX_TYPE
))
12155 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
12156 = c_omp_reduction_lookup (reduc_id
,
12157 TYPE_MAIN_VARIANT (type
));
12162 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12168 schedule ( schedule-kind )
12169 schedule ( schedule-kind , expression )
12172 static | dynamic | guided | runtime | auto
12175 schedule ( schedule-modifier : schedule-kind )
12176 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
12184 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
12187 location_t loc
= c_parser_peek_token (parser
)->location
;
12188 int modifiers
= 0, nmodifiers
= 0;
12190 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12193 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
12195 while (c_parser_next_token_is (parser
, CPP_NAME
))
12197 tree kind
= c_parser_peek_token (parser
)->value
;
12198 const char *p
= IDENTIFIER_POINTER (kind
);
12199 if (strcmp ("simd", p
) == 0)
12200 OMP_CLAUSE_SCHEDULE_SIMD (c
) = 1;
12201 else if (strcmp ("monotonic", p
) == 0)
12202 modifiers
|= OMP_CLAUSE_SCHEDULE_MONOTONIC
;
12203 else if (strcmp ("nonmonotonic", p
) == 0)
12204 modifiers
|= OMP_CLAUSE_SCHEDULE_NONMONOTONIC
;
12207 c_parser_consume_token (parser
);
12208 if (nmodifiers
++ == 0
12209 && c_parser_next_token_is (parser
, CPP_COMMA
))
12210 c_parser_consume_token (parser
);
12213 c_parser_require (parser
, CPP_COLON
, "expected %<:%>");
12218 if ((modifiers
& (OMP_CLAUSE_SCHEDULE_MONOTONIC
12219 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12220 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
12221 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12223 error_at (loc
, "both %<monotonic%> and %<nonmonotonic%> modifiers "
12228 if (c_parser_next_token_is (parser
, CPP_NAME
))
12230 tree kind
= c_parser_peek_token (parser
)->value
;
12231 const char *p
= IDENTIFIER_POINTER (kind
);
12236 if (strcmp ("dynamic", p
) != 0)
12238 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
12242 if (strcmp ("guided", p
) != 0)
12244 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
12248 if (strcmp ("runtime", p
) != 0)
12250 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
12257 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12258 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
12259 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
12260 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
12264 c_parser_consume_token (parser
);
12265 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12268 c_parser_consume_token (parser
);
12270 here
= c_parser_peek_token (parser
)->location
;
12271 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12272 expr
= convert_lvalue_to_rvalue (here
, expr
, false, true);
12274 t
= c_fully_fold (t
, false, NULL
);
12276 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
12277 error_at (here
, "schedule %<runtime%> does not take "
12278 "a %<chunk_size%> parameter");
12279 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
12281 "schedule %<auto%> does not take "
12282 "a %<chunk_size%> parameter");
12283 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
12285 /* Attempt to statically determine when the number isn't
12287 tree s
= fold_build2_loc (loc
, LE_EXPR
, boolean_type_node
, t
,
12288 build_int_cst (TREE_TYPE (t
), 0));
12289 protected_set_expr_location (s
, loc
);
12290 if (s
== boolean_true_node
)
12292 warning_at (loc
, 0,
12293 "chunk size value must be positive");
12294 t
= integer_one_node
;
12296 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
12299 c_parser_error (parser
, "expected integer expression");
12301 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12304 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12305 "expected %<,%> or %<)%>");
12307 OMP_CLAUSE_SCHEDULE_KIND (c
)
12308 = (enum omp_clause_schedule_kind
)
12309 (OMP_CLAUSE_SCHEDULE_KIND (c
) | modifiers
);
12311 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
12312 OMP_CLAUSE_CHAIN (c
) = list
;
12316 c_parser_error (parser
, "invalid schedule kind");
12317 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12322 shared ( variable-list ) */
12325 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
12327 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
12334 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12338 /* FIXME: Should we allow duplicates? */
12339 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
12341 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12342 OMP_CLAUSE_UNTIED
);
12343 OMP_CLAUSE_CHAIN (c
) = list
;
12349 vector_length ( expression ) */
12352 c_parser_omp_clause_vector_length (c_parser
*parser
, tree list
)
12354 location_t vector_length_loc
= c_parser_peek_token (parser
)->location
;
12355 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12357 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12358 c_expr expr
= c_parser_expression (parser
);
12359 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12360 tree c
, t
= expr
.value
;
12361 t
= c_fully_fold (t
, false, NULL
);
12363 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12365 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12367 c_parser_error (parser
, "expected integer expression");
12371 /* Attempt to statically determine when the number isn't positive. */
12372 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12373 build_int_cst (TREE_TYPE (t
), 0));
12374 protected_set_expr_location (c
, expr_loc
);
12375 if (c
== boolean_true_node
)
12377 warning_at (expr_loc
, 0,
12378 "%<vector_length%> value must be positive");
12379 t
= integer_one_node
;
12382 check_no_duplicate_clause (list
, OMP_CLAUSE_VECTOR_LENGTH
, "vector_length");
12384 c
= build_omp_clause (vector_length_loc
, OMP_CLAUSE_VECTOR_LENGTH
);
12385 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c
) = t
;
12386 OMP_CLAUSE_CHAIN (c
) = list
;
12398 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
12399 enum omp_clause_code code
, tree list
)
12401 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12403 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12404 OMP_CLAUSE_CHAIN (c
) = list
;
12416 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
12417 enum omp_clause_code code
, tree list
)
12419 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12420 OMP_CLAUSE_CHAIN (c
) = list
;
12429 c_parser_omp_clause_nogroup (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12431 check_no_duplicate_clause (list
, OMP_CLAUSE_NOGROUP
, "nogroup");
12432 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12433 OMP_CLAUSE_NOGROUP
);
12434 OMP_CLAUSE_CHAIN (c
) = list
;
12443 c_parser_omp_clause_orderedkind (c_parser
*parser ATTRIBUTE_UNUSED
,
12444 enum omp_clause_code code
, tree list
)
12446 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12447 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12448 OMP_CLAUSE_CHAIN (c
) = list
;
12453 num_teams ( expression ) */
12456 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
12458 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
12459 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12461 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12462 c_expr expr
= c_parser_expression (parser
);
12463 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12464 tree c
, t
= expr
.value
;
12465 t
= c_fully_fold (t
, false, NULL
);
12467 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12469 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12471 c_parser_error (parser
, "expected integer expression");
12475 /* Attempt to statically determine when the number isn't positive. */
12476 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12477 build_int_cst (TREE_TYPE (t
), 0));
12478 protected_set_expr_location (c
, expr_loc
);
12479 if (c
== boolean_true_node
)
12481 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
12482 t
= integer_one_node
;
12485 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
12487 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
12488 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
12489 OMP_CLAUSE_CHAIN (c
) = list
;
12497 thread_limit ( expression ) */
12500 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
12502 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
12503 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12505 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12506 c_expr expr
= c_parser_expression (parser
);
12507 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12508 tree c
, t
= expr
.value
;
12509 t
= c_fully_fold (t
, false, NULL
);
12511 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12513 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12515 c_parser_error (parser
, "expected integer expression");
12519 /* Attempt to statically determine when the number isn't positive. */
12520 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12521 build_int_cst (TREE_TYPE (t
), 0));
12522 protected_set_expr_location (c
, expr_loc
);
12523 if (c
== boolean_true_node
)
12525 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
12526 t
= integer_one_node
;
12529 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
12532 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
12533 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
12534 OMP_CLAUSE_CHAIN (c
) = list
;
12542 aligned ( variable-list )
12543 aligned ( variable-list : constant-expression ) */
12546 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
12548 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12551 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12554 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12555 OMP_CLAUSE_ALIGNED
, list
);
12557 if (c_parser_next_token_is (parser
, CPP_COLON
))
12559 c_parser_consume_token (parser
);
12560 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12561 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12562 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12563 tree alignment
= expr
.value
;
12564 alignment
= c_fully_fold (alignment
, false, NULL
);
12565 if (TREE_CODE (alignment
) != INTEGER_CST
12566 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
12567 || tree_int_cst_sgn (alignment
) != 1)
12569 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
12570 "be positive constant integer expression");
12571 alignment
= NULL_TREE
;
12574 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12575 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
12578 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12583 linear ( variable-list )
12584 linear ( variable-list : expression )
12587 linear ( modifier ( variable-list ) )
12588 linear ( modifier ( variable-list ) : expression ) */
12591 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
12593 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12595 enum omp_clause_linear_kind kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
12597 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12600 if (!is_cilk_simd_fn
12601 && c_parser_next_token_is (parser
, CPP_NAME
))
12603 c_token
*tok
= c_parser_peek_token (parser
);
12604 const char *p
= IDENTIFIER_POINTER (tok
->value
);
12605 if (strcmp ("val", p
) == 0)
12606 kind
= OMP_CLAUSE_LINEAR_VAL
;
12607 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
)
12608 kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
12609 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
12611 c_parser_consume_token (parser
);
12612 c_parser_consume_token (parser
);
12616 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12617 OMP_CLAUSE_LINEAR
, list
);
12619 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
12620 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12622 if (c_parser_next_token_is (parser
, CPP_COLON
))
12624 c_parser_consume_token (parser
);
12625 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12626 c_expr expr
= c_parser_expression (parser
);
12627 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12629 step
= c_fully_fold (step
, false, NULL
);
12630 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
12632 sorry ("using parameters for %<linear%> step is not supported yet");
12633 step
= integer_one_node
;
12635 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
12637 error_at (clause_loc
, "%<linear%> clause step expression must "
12639 step
= integer_one_node
;
12644 step
= integer_one_node
;
12646 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12648 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
12649 OMP_CLAUSE_LINEAR_KIND (c
) = kind
;
12652 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12657 safelen ( constant-expression ) */
12660 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
12662 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12665 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12668 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12669 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12670 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12672 t
= c_fully_fold (t
, false, NULL
);
12673 if (TREE_CODE (t
) != INTEGER_CST
12674 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
12675 || tree_int_cst_sgn (t
) != 1)
12677 error_at (clause_loc
, "%<safelen%> clause expression must "
12678 "be positive constant integer expression");
12682 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12683 if (t
== NULL_TREE
|| t
== error_mark_node
)
12686 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
12688 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
12689 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
12690 OMP_CLAUSE_CHAIN (c
) = list
;
12695 simdlen ( constant-expression ) */
12698 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
12700 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12703 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12706 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12707 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12708 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12710 t
= c_fully_fold (t
, false, NULL
);
12711 if (TREE_CODE (t
) != INTEGER_CST
12712 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
12713 || tree_int_cst_sgn (t
) != 1)
12715 error_at (clause_loc
, "%<simdlen%> clause expression must "
12716 "be positive constant integer expression");
12720 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12721 if (t
== NULL_TREE
|| t
== error_mark_node
)
12724 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
12726 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
12727 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
12728 OMP_CLAUSE_CHAIN (c
) = list
;
12734 identifier [+/- integer]
12735 vec , identifier [+/- integer]
12739 c_parser_omp_clause_depend_sink (c_parser
*parser
, location_t clause_loc
,
12743 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
12744 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
12746 c_parser_error (parser
, "expected identifier");
12750 while (c_parser_next_token_is (parser
, CPP_NAME
)
12751 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
12753 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
12754 tree addend
= NULL
;
12756 if (t
== NULL_TREE
)
12758 undeclared_variable (c_parser_peek_token (parser
)->location
,
12759 c_parser_peek_token (parser
)->value
);
12760 t
= error_mark_node
;
12763 c_parser_consume_token (parser
);
12766 if (c_parser_next_token_is (parser
, CPP_MINUS
))
12768 else if (!c_parser_next_token_is (parser
, CPP_PLUS
))
12770 addend
= integer_zero_node
;
12772 goto add_to_vector
;
12774 c_parser_consume_token (parser
);
12776 if (c_parser_next_token_is_not (parser
, CPP_NUMBER
))
12778 c_parser_error (parser
, "expected integer");
12782 addend
= c_parser_peek_token (parser
)->value
;
12783 if (TREE_CODE (addend
) != INTEGER_CST
)
12785 c_parser_error (parser
, "expected integer");
12788 c_parser_consume_token (parser
);
12791 if (t
!= error_mark_node
)
12793 vec
= tree_cons (addend
, t
, vec
);
12795 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec
) = 1;
12798 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
12801 c_parser_consume_token (parser
);
12804 if (vec
== NULL_TREE
)
12807 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
12808 OMP_CLAUSE_DEPEND_KIND (u
) = OMP_CLAUSE_DEPEND_SINK
;
12809 OMP_CLAUSE_DECL (u
) = nreverse (vec
);
12810 OMP_CLAUSE_CHAIN (u
) = list
;
12815 depend ( depend-kind: variable-list )
12823 depend ( sink : vec ) */
12826 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
12828 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12829 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
12832 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12835 if (c_parser_next_token_is (parser
, CPP_NAME
))
12837 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12838 if (strcmp ("in", p
) == 0)
12839 kind
= OMP_CLAUSE_DEPEND_IN
;
12840 else if (strcmp ("inout", p
) == 0)
12841 kind
= OMP_CLAUSE_DEPEND_INOUT
;
12842 else if (strcmp ("out", p
) == 0)
12843 kind
= OMP_CLAUSE_DEPEND_OUT
;
12844 else if (strcmp ("source", p
) == 0)
12845 kind
= OMP_CLAUSE_DEPEND_SOURCE
;
12846 else if (strcmp ("sink", p
) == 0)
12847 kind
= OMP_CLAUSE_DEPEND_SINK
;
12854 c_parser_consume_token (parser
);
12856 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
12858 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
12859 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
12860 OMP_CLAUSE_DECL (c
) = NULL_TREE
;
12861 OMP_CLAUSE_CHAIN (c
) = list
;
12862 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12866 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12869 if (kind
== OMP_CLAUSE_DEPEND_SINK
)
12870 nl
= c_parser_omp_clause_depend_sink (parser
, clause_loc
, list
);
12873 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12874 OMP_CLAUSE_DEPEND
, list
);
12876 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12877 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
12880 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12884 c_parser_error (parser
, "invalid depend kind");
12886 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12891 map ( map-kind: variable-list )
12892 map ( variable-list )
12895 alloc | to | from | tofrom
12899 alloc | to | from | tofrom | release | delete
12901 map ( always [,] map-kind: variable-list ) */
12904 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
12906 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12907 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
12909 enum c_id_kind always_id_kind
= C_ID_NONE
;
12910 location_t always_loc
= UNKNOWN_LOCATION
;
12911 tree always_id
= NULL_TREE
;
12914 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12917 if (c_parser_next_token_is (parser
, CPP_NAME
))
12919 c_token
*tok
= c_parser_peek_token (parser
);
12920 const char *p
= IDENTIFIER_POINTER (tok
->value
);
12921 always_id_kind
= tok
->id_kind
;
12922 always_loc
= tok
->location
;
12923 always_id
= tok
->value
;
12924 if (strcmp ("always", p
) == 0)
12926 c_token
*sectok
= c_parser_peek_2nd_token (parser
);
12927 if (sectok
->type
== CPP_COMMA
)
12929 c_parser_consume_token (parser
);
12930 c_parser_consume_token (parser
);
12933 else if (sectok
->type
== CPP_NAME
)
12935 p
= IDENTIFIER_POINTER (sectok
->value
);
12936 if (strcmp ("alloc", p
) == 0
12937 || strcmp ("to", p
) == 0
12938 || strcmp ("from", p
) == 0
12939 || strcmp ("tofrom", p
) == 0
12940 || strcmp ("release", p
) == 0
12941 || strcmp ("delete", p
) == 0)
12943 c_parser_consume_token (parser
);
12950 if (c_parser_next_token_is (parser
, CPP_NAME
)
12951 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12953 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12954 if (strcmp ("alloc", p
) == 0)
12955 kind
= GOMP_MAP_ALLOC
;
12956 else if (strcmp ("to", p
) == 0)
12957 kind
= always
? GOMP_MAP_ALWAYS_TO
: GOMP_MAP_TO
;
12958 else if (strcmp ("from", p
) == 0)
12959 kind
= always
? GOMP_MAP_ALWAYS_FROM
: GOMP_MAP_FROM
;
12960 else if (strcmp ("tofrom", p
) == 0)
12961 kind
= always
? GOMP_MAP_ALWAYS_TOFROM
: GOMP_MAP_TOFROM
;
12962 else if (strcmp ("release", p
) == 0)
12963 kind
= GOMP_MAP_RELEASE
;
12964 else if (strcmp ("delete", p
) == 0)
12965 kind
= GOMP_MAP_DELETE
;
12968 c_parser_error (parser
, "invalid map kind");
12969 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12973 c_parser_consume_token (parser
);
12974 c_parser_consume_token (parser
);
12978 if (always_id_kind
!= C_ID_ID
)
12980 c_parser_error (parser
, "expected identifier");
12981 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12985 tree t
= lookup_name (always_id
);
12986 if (t
== NULL_TREE
)
12988 undeclared_variable (always_loc
, always_id
);
12989 t
= error_mark_node
;
12991 if (t
!= error_mark_node
)
12993 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_MAP
);
12994 OMP_CLAUSE_DECL (u
) = t
;
12995 OMP_CLAUSE_CHAIN (u
) = list
;
12996 OMP_CLAUSE_SET_MAP_KIND (u
, kind
);
13001 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13006 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
13008 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
13009 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
13011 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13016 device ( expression ) */
13019 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
13021 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13022 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13024 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13025 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13026 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13027 tree c
, t
= expr
.value
;
13028 t
= c_fully_fold (t
, false, NULL
);
13030 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13032 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13034 c_parser_error (parser
, "expected integer expression");
13038 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
13040 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
13041 OMP_CLAUSE_DEVICE_ID (c
) = t
;
13042 OMP_CLAUSE_CHAIN (c
) = list
;
13050 dist_schedule ( static )
13051 dist_schedule ( static , expression ) */
13054 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
13056 tree c
, t
= NULL_TREE
;
13057 location_t loc
= c_parser_peek_token (parser
)->location
;
13059 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13062 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
13064 c_parser_error (parser
, "invalid dist_schedule kind");
13065 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13070 c_parser_consume_token (parser
);
13071 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13073 c_parser_consume_token (parser
);
13075 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13076 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13077 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13079 t
= c_fully_fold (t
, false, NULL
);
13080 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13083 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13084 "expected %<,%> or %<)%>");
13086 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
13087 if (t
== error_mark_node
)
13090 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
13091 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
13092 OMP_CLAUSE_CHAIN (c
) = list
;
13097 proc_bind ( proc-bind-kind )
13100 master | close | spread */
13103 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
13105 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13106 enum omp_clause_proc_bind_kind kind
;
13109 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13112 if (c_parser_next_token_is (parser
, CPP_NAME
))
13114 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13115 if (strcmp ("master", p
) == 0)
13116 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
13117 else if (strcmp ("close", p
) == 0)
13118 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
13119 else if (strcmp ("spread", p
) == 0)
13120 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
13127 c_parser_consume_token (parser
);
13128 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13129 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
13130 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
13131 OMP_CLAUSE_CHAIN (c
) = list
;
13135 c_parser_error (parser
, "invalid proc_bind kind");
13136 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13141 to ( variable-list ) */
13144 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
13146 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
13150 from ( variable-list ) */
13153 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
13155 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
13159 uniform ( variable-list ) */
13162 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
13164 /* The clauses location. */
13165 location_t loc
= c_parser_peek_token (parser
)->location
;
13167 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13169 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
13171 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13176 /* Parse all OpenACC clauses. The set clauses allowed by the directive
13177 is a bitmask in MASK. Return the list of clauses found. */
13180 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
13181 const char *where
, bool finish_p
= true)
13183 tree clauses
= NULL
;
13186 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13189 pragma_omp_clause c_kind
;
13190 const char *c_name
;
13191 tree prev
= clauses
;
13193 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
13194 c_parser_consume_token (parser
);
13196 here
= c_parser_peek_token (parser
)->location
;
13197 c_kind
= c_parser_omp_clause_name (parser
);
13201 case PRAGMA_OACC_CLAUSE_ASYNC
:
13202 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
13205 case PRAGMA_OACC_CLAUSE_AUTO
:
13206 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_AUTO
,
13210 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
13211 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
13212 c_name
= "collapse";
13214 case PRAGMA_OACC_CLAUSE_COPY
:
13215 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13218 case PRAGMA_OACC_CLAUSE_COPYIN
:
13219 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13222 case PRAGMA_OACC_CLAUSE_COPYOUT
:
13223 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13224 c_name
= "copyout";
13226 case PRAGMA_OACC_CLAUSE_CREATE
:
13227 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13230 case PRAGMA_OACC_CLAUSE_DELETE
:
13231 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13234 case PRAGMA_OMP_CLAUSE_DEFAULT
:
13235 clauses
= c_parser_omp_clause_default (parser
, clauses
, true);
13236 c_name
= "default";
13238 case PRAGMA_OACC_CLAUSE_DEVICE
:
13239 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13242 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
13243 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
13244 c_name
= "deviceptr";
13246 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
13247 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13248 c_name
= "device_resident";
13250 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
13251 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13252 c_name
= "firstprivate";
13254 case PRAGMA_OACC_CLAUSE_GANG
:
13256 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_GANG
,
13259 case PRAGMA_OACC_CLAUSE_HOST
:
13260 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13263 case PRAGMA_OACC_CLAUSE_IF
:
13264 clauses
= c_parser_omp_clause_if (parser
, clauses
, false);
13267 case PRAGMA_OACC_CLAUSE_INDEPENDENT
:
13268 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_INDEPENDENT
,
13270 c_name
= "independent";
13272 case PRAGMA_OACC_CLAUSE_LINK
:
13273 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13276 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
13277 clauses
= c_parser_omp_clause_num_gangs (parser
, clauses
);
13278 c_name
= "num_gangs";
13280 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
13281 clauses
= c_parser_omp_clause_num_workers (parser
, clauses
);
13282 c_name
= "num_workers";
13284 case PRAGMA_OACC_CLAUSE_PRESENT
:
13285 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13286 c_name
= "present";
13288 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
13289 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13290 c_name
= "present_or_copy";
13292 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
13293 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13294 c_name
= "present_or_copyin";
13296 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
13297 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13298 c_name
= "present_or_copyout";
13300 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
13301 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13302 c_name
= "present_or_create";
13304 case PRAGMA_OACC_CLAUSE_PRIVATE
:
13305 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13306 c_name
= "private";
13308 case PRAGMA_OACC_CLAUSE_REDUCTION
:
13309 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13310 c_name
= "reduction";
13312 case PRAGMA_OACC_CLAUSE_SELF
:
13313 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13316 case PRAGMA_OACC_CLAUSE_SEQ
:
13317 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_SEQ
,
13321 case PRAGMA_OACC_CLAUSE_TILE
:
13322 clauses
= c_parser_oacc_clause_tile (parser
, clauses
);
13325 case PRAGMA_OACC_CLAUSE_USE_DEVICE
:
13326 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
13327 c_name
= "use_device";
13329 case PRAGMA_OACC_CLAUSE_VECTOR
:
13331 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_VECTOR
,
13334 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
13335 clauses
= c_parser_omp_clause_vector_length (parser
, clauses
);
13336 c_name
= "vector_length";
13338 case PRAGMA_OACC_CLAUSE_WAIT
:
13339 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
13342 case PRAGMA_OACC_CLAUSE_WORKER
:
13344 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_WORKER
,
13348 c_parser_error (parser
, "expected %<#pragma acc%> clause");
13354 if (((mask
>> c_kind
) & 1) == 0)
13356 /* Remove the invalid clause(s) from the list to avoid
13357 confusing the rest of the compiler. */
13359 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
13364 c_parser_skip_to_pragma_eol (parser
);
13367 return c_finish_omp_clauses (clauses
, C_ORT_ACC
);
13372 /* Parse all OpenMP clauses. The set clauses allowed by the directive
13373 is a bitmask in MASK. Return the list of clauses found. */
13376 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
13377 const char *where
, bool finish_p
= true)
13379 tree clauses
= NULL
;
13380 bool first
= true, cilk_simd_fn
= false;
13382 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13385 pragma_omp_clause c_kind
;
13386 const char *c_name
;
13387 tree prev
= clauses
;
13389 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
13390 c_parser_consume_token (parser
);
13392 here
= c_parser_peek_token (parser
)->location
;
13393 c_kind
= c_parser_omp_clause_name (parser
);
13397 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
13398 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
13399 c_name
= "collapse";
13401 case PRAGMA_OMP_CLAUSE_COPYIN
:
13402 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
13405 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
13406 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
13407 c_name
= "copyprivate";
13409 case PRAGMA_OMP_CLAUSE_DEFAULT
:
13410 clauses
= c_parser_omp_clause_default (parser
, clauses
, false);
13411 c_name
= "default";
13413 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
13414 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13415 c_name
= "firstprivate";
13417 case PRAGMA_OMP_CLAUSE_FINAL
:
13418 clauses
= c_parser_omp_clause_final (parser
, clauses
);
13421 case PRAGMA_OMP_CLAUSE_GRAINSIZE
:
13422 clauses
= c_parser_omp_clause_grainsize (parser
, clauses
);
13423 c_name
= "grainsize";
13425 case PRAGMA_OMP_CLAUSE_HINT
:
13426 clauses
= c_parser_omp_clause_hint (parser
, clauses
);
13429 case PRAGMA_OMP_CLAUSE_DEFAULTMAP
:
13430 clauses
= c_parser_omp_clause_defaultmap (parser
, clauses
);
13431 c_name
= "defaultmap";
13433 case PRAGMA_OMP_CLAUSE_IF
:
13434 clauses
= c_parser_omp_clause_if (parser
, clauses
, true);
13437 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
13438 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
13439 c_name
= "lastprivate";
13441 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
13442 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
13443 c_name
= "mergeable";
13445 case PRAGMA_OMP_CLAUSE_NOWAIT
:
13446 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
13449 case PRAGMA_OMP_CLAUSE_NUM_TASKS
:
13450 clauses
= c_parser_omp_clause_num_tasks (parser
, clauses
);
13451 c_name
= "num_tasks";
13453 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
13454 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
13455 c_name
= "num_threads";
13457 case PRAGMA_OMP_CLAUSE_ORDERED
:
13458 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
13459 c_name
= "ordered";
13461 case PRAGMA_OMP_CLAUSE_PRIORITY
:
13462 clauses
= c_parser_omp_clause_priority (parser
, clauses
);
13463 c_name
= "priority";
13465 case PRAGMA_OMP_CLAUSE_PRIVATE
:
13466 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13467 c_name
= "private";
13469 case PRAGMA_OMP_CLAUSE_REDUCTION
:
13470 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13471 c_name
= "reduction";
13473 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
13474 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
13475 c_name
= "schedule";
13477 case PRAGMA_OMP_CLAUSE_SHARED
:
13478 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
13481 case PRAGMA_OMP_CLAUSE_UNTIED
:
13482 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
13485 case PRAGMA_OMP_CLAUSE_INBRANCH
:
13486 case PRAGMA_CILK_CLAUSE_MASK
:
13487 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
13489 c_name
= "inbranch";
13491 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
13492 case PRAGMA_CILK_CLAUSE_NOMASK
:
13493 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
13495 c_name
= "notinbranch";
13497 case PRAGMA_OMP_CLAUSE_PARALLEL
:
13499 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
13501 c_name
= "parallel";
13505 error_at (here
, "%qs must be the first clause of %qs",
13510 case PRAGMA_OMP_CLAUSE_FOR
:
13512 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
13516 goto clause_not_first
;
13518 case PRAGMA_OMP_CLAUSE_SECTIONS
:
13520 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
13522 c_name
= "sections";
13524 goto clause_not_first
;
13526 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
13528 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
13530 c_name
= "taskgroup";
13532 goto clause_not_first
;
13534 case PRAGMA_OMP_CLAUSE_LINK
:
13536 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LINK
, clauses
);
13539 case PRAGMA_OMP_CLAUSE_TO
:
13540 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINK
)) != 0)
13542 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
13545 clauses
= c_parser_omp_clause_to (parser
, clauses
);
13548 case PRAGMA_OMP_CLAUSE_FROM
:
13549 clauses
= c_parser_omp_clause_from (parser
, clauses
);
13552 case PRAGMA_OMP_CLAUSE_UNIFORM
:
13553 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
13554 c_name
= "uniform";
13556 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
13557 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
13558 c_name
= "num_teams";
13560 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
13561 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
13562 c_name
= "thread_limit";
13564 case PRAGMA_OMP_CLAUSE_ALIGNED
:
13565 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
13566 c_name
= "aligned";
13568 case PRAGMA_OMP_CLAUSE_LINEAR
:
13569 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
13570 cilk_simd_fn
= true;
13571 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
13574 case PRAGMA_OMP_CLAUSE_DEPEND
:
13575 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
13578 case PRAGMA_OMP_CLAUSE_MAP
:
13579 clauses
= c_parser_omp_clause_map (parser
, clauses
);
13582 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
:
13583 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
13584 c_name
= "use_device_ptr";
13586 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
:
13587 clauses
= c_parser_omp_clause_is_device_ptr (parser
, clauses
);
13588 c_name
= "is_device_ptr";
13590 case PRAGMA_OMP_CLAUSE_DEVICE
:
13591 clauses
= c_parser_omp_clause_device (parser
, clauses
);
13594 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
13595 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
13596 c_name
= "dist_schedule";
13598 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
13599 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
13600 c_name
= "proc_bind";
13602 case PRAGMA_OMP_CLAUSE_SAFELEN
:
13603 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
13604 c_name
= "safelen";
13606 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
13607 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
13608 c_name
= "simdlen";
13610 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
13611 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
13612 c_name
= "simdlen";
13614 case PRAGMA_OMP_CLAUSE_NOGROUP
:
13615 clauses
= c_parser_omp_clause_nogroup (parser
, clauses
);
13616 c_name
= "nogroup";
13618 case PRAGMA_OMP_CLAUSE_THREADS
:
13620 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_THREADS
,
13622 c_name
= "threads";
13624 case PRAGMA_OMP_CLAUSE_SIMD
:
13626 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_SIMD
,
13631 c_parser_error (parser
, "expected %<#pragma omp%> clause");
13637 if (((mask
>> c_kind
) & 1) == 0)
13639 /* Remove the invalid clause(s) from the list to avoid
13640 confusing the rest of the compiler. */
13642 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
13647 c_parser_skip_to_pragma_eol (parser
);
13651 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_UNIFORM
)) != 0)
13652 return c_finish_omp_clauses (clauses
, C_ORT_OMP_DECLARE_SIMD
);
13653 return c_finish_omp_clauses (clauses
, C_ORT_OMP
);
13659 /* OpenACC 2.0, OpenMP 2.5:
13663 In practice, we're also interested in adding the statement to an
13664 outer node. So it is convenient if we work around the fact that
13665 c_parser_statement calls add_stmt. */
13668 c_parser_omp_structured_block (c_parser
*parser
, bool *if_p
)
13670 tree stmt
= push_stmt_list ();
13671 c_parser_statement (parser
, if_p
);
13672 return pop_stmt_list (stmt
);
13676 # pragma acc cache (variable-list) new-line
13678 LOC is the location of the #pragma token.
13682 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
13684 tree stmt
, clauses
;
13686 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
13687 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
13689 c_parser_skip_to_pragma_eol (parser
);
13691 stmt
= make_node (OACC_CACHE
);
13692 TREE_TYPE (stmt
) = void_type_node
;
13693 OACC_CACHE_CLAUSES (stmt
) = clauses
;
13694 SET_EXPR_LOCATION (stmt
, loc
);
13701 # pragma acc data oacc-data-clause[optseq] new-line
13704 LOC is the location of the #pragma token.
13707 #define OACC_DATA_CLAUSE_MASK \
13708 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13709 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13710 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13711 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13712 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13713 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13714 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13715 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13716 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13717 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13718 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
13721 c_parser_oacc_data (location_t loc
, c_parser
*parser
, bool *if_p
)
13723 tree stmt
, clauses
, block
;
13725 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
13726 "#pragma acc data");
13728 block
= c_begin_omp_parallel ();
13729 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
13731 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
13737 # pragma acc declare oacc-data-clause[optseq] new-line
13740 #define OACC_DECLARE_CLAUSE_MASK \
13741 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13742 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13743 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13744 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13745 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13746 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \
13747 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \
13748 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13749 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13750 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13751 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13752 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
13755 c_parser_oacc_declare (c_parser
*parser
)
13757 location_t pragma_loc
= c_parser_peek_token (parser
)->location
;
13758 tree clauses
, stmt
, t
, decl
;
13760 bool error
= false;
13762 c_parser_consume_pragma (parser
);
13764 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DECLARE_CLAUSE_MASK
,
13765 "#pragma acc declare");
13768 error_at (pragma_loc
,
13769 "no valid clauses specified in %<#pragma acc declare%>");
13773 for (t
= clauses
; t
; t
= OMP_CLAUSE_CHAIN (t
))
13775 location_t loc
= OMP_CLAUSE_LOCATION (t
);
13776 decl
= OMP_CLAUSE_DECL (t
);
13777 if (!DECL_P (decl
))
13779 error_at (loc
, "array section in %<#pragma acc declare%>");
13784 switch (OMP_CLAUSE_MAP_KIND (t
))
13786 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
13787 case GOMP_MAP_FORCE_ALLOC
:
13788 case GOMP_MAP_FORCE_TO
:
13789 case GOMP_MAP_FORCE_DEVICEPTR
:
13790 case GOMP_MAP_DEVICE_RESIDENT
:
13793 case GOMP_MAP_LINK
:
13794 if (!global_bindings_p ()
13795 && (TREE_STATIC (decl
)
13796 || !DECL_EXTERNAL (decl
)))
13799 "%qD must be a global variable in "
13800 "%<#pragma acc declare link%>",
13808 if (global_bindings_p ())
13810 error_at (loc
, "invalid OpenACC clause at file scope");
13814 if (DECL_EXTERNAL (decl
))
13817 "invalid use of %<extern%> variable %qD "
13818 "in %<#pragma acc declare%>", decl
);
13822 else if (TREE_PUBLIC (decl
))
13825 "invalid use of %<global%> variable %qD "
13826 "in %<#pragma acc declare%>", decl
);
13833 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl
))
13834 || lookup_attribute ("omp declare target link",
13835 DECL_ATTRIBUTES (decl
)))
13837 error_at (loc
, "variable %qD used more than once with "
13838 "%<#pragma acc declare%>", decl
);
13847 if (OMP_CLAUSE_MAP_KIND (t
) == GOMP_MAP_LINK
)
13848 id
= get_identifier ("omp declare target link");
13850 id
= get_identifier ("omp declare target");
13852 DECL_ATTRIBUTES (decl
)
13853 = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (decl
));
13855 if (global_bindings_p ())
13857 symtab_node
*node
= symtab_node::get (decl
);
13860 node
->offloadable
= 1;
13861 if (ENABLE_OFFLOADING
)
13863 g
->have_offload
= true;
13864 if (is_a
<varpool_node
*> (node
))
13865 vec_safe_push (offload_vars
, decl
);
13872 if (error
|| global_bindings_p ())
13875 stmt
= make_node (OACC_DECLARE
);
13876 TREE_TYPE (stmt
) = void_type_node
;
13877 OACC_DECLARE_CLAUSES (stmt
) = clauses
;
13878 SET_EXPR_LOCATION (stmt
, pragma_loc
);
13886 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
13890 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
13893 LOC is the location of the #pragma token.
13896 #define OACC_ENTER_DATA_CLAUSE_MASK \
13897 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13898 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13899 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13900 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13901 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13902 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
13903 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13905 #define OACC_EXIT_DATA_CLAUSE_MASK \
13906 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13907 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13908 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13909 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
13910 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13913 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
13915 location_t loc
= c_parser_peek_token (parser
)->location
;
13916 tree clauses
, stmt
;
13917 const char *p
= "";
13919 c_parser_consume_pragma (parser
);
13921 if (c_parser_next_token_is (parser
, CPP_NAME
))
13923 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13924 c_parser_consume_token (parser
);
13927 if (strcmp (p
, "data") != 0)
13929 error_at (loc
, "expected %<data%> after %<#pragma acc %s%>",
13930 enter
? "enter" : "exit");
13931 parser
->error
= true;
13932 c_parser_skip_to_pragma_eol (parser
);
13937 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
13938 "#pragma acc enter data");
13940 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
13941 "#pragma acc exit data");
13943 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
13945 error_at (loc
, "%<#pragma acc %s data%> has no data movement clause",
13946 enter
? "enter" : "exit");
13950 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
13951 TREE_TYPE (stmt
) = void_type_node
;
13952 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
13953 SET_EXPR_LOCATION (stmt
, loc
);
13959 # pragma acc host_data oacc-data-clause[optseq] new-line
13963 #define OACC_HOST_DATA_CLAUSE_MASK \
13964 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
13967 c_parser_oacc_host_data (location_t loc
, c_parser
*parser
, bool *if_p
)
13969 tree stmt
, clauses
, block
;
13971 clauses
= c_parser_oacc_all_clauses (parser
, OACC_HOST_DATA_CLAUSE_MASK
,
13972 "#pragma acc host_data");
13974 block
= c_begin_omp_parallel ();
13975 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
13976 stmt
= c_finish_oacc_host_data (loc
, clauses
, block
);
13983 # pragma acc loop oacc-loop-clause[optseq] new-line
13986 LOC is the location of the #pragma token.
13989 #define OACC_LOOP_CLAUSE_MASK \
13990 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
13991 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
13992 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
13993 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
13994 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
13995 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
13996 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
13997 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
13998 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
13999 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
14001 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
,
14002 omp_clause_mask mask
, tree
*cclauses
, bool *if_p
)
14004 bool is_parallel
= ((mask
>> PRAGMA_OACC_CLAUSE_REDUCTION
) & 1) == 1;
14006 strcat (p_name
, " loop");
14007 mask
|= OACC_LOOP_CLAUSE_MASK
;
14009 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
,
14013 clauses
= c_oacc_split_loop_clauses (clauses
, cclauses
, is_parallel
);
14015 *cclauses
= c_finish_omp_clauses (*cclauses
, C_ORT_ACC
);
14017 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14020 tree block
= c_begin_compound_stmt (true);
14021 tree stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
,
14023 block
= c_end_compound_stmt (loc
, block
, true);
14030 # pragma acc kernels oacc-kernels-clause[optseq] new-line
14035 # pragma acc parallel oacc-parallel-clause[optseq] new-line
14038 LOC is the location of the #pragma token.
14041 #define OACC_KERNELS_CLAUSE_MASK \
14042 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14043 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14044 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14045 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14046 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14047 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14048 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14049 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14050 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14051 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14052 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14053 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14054 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14055 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14057 #define OACC_PARALLEL_CLAUSE_MASK \
14058 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14059 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14060 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14061 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14062 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14063 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14064 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14065 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14066 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
14067 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
14068 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14069 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14070 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14071 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14072 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14073 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14074 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14075 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14076 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14077 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14080 c_parser_oacc_kernels_parallel (location_t loc
, c_parser
*parser
,
14081 enum pragma_kind p_kind
, char *p_name
,
14084 omp_clause_mask mask
;
14085 enum tree_code code
;
14088 case PRAGMA_OACC_KERNELS
:
14089 strcat (p_name
, " kernels");
14090 mask
= OACC_KERNELS_CLAUSE_MASK
;
14091 code
= OACC_KERNELS
;
14093 case PRAGMA_OACC_PARALLEL
:
14094 strcat (p_name
, " parallel");
14095 mask
= OACC_PARALLEL_CLAUSE_MASK
;
14096 code
= OACC_PARALLEL
;
14099 gcc_unreachable ();
14102 if (c_parser_next_token_is (parser
, CPP_NAME
))
14104 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14105 if (strcmp (p
, "loop") == 0)
14107 c_parser_consume_token (parser
);
14108 tree block
= c_begin_omp_parallel ();
14110 c_parser_oacc_loop (loc
, parser
, p_name
, mask
, &clauses
, if_p
);
14111 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14115 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
);
14117 tree block
= c_begin_omp_parallel ();
14118 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14120 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14124 # pragma acc routine oacc-routine-clause[optseq] new-line
14125 function-definition
14127 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
14130 #define OACC_ROUTINE_CLAUSE_MASK \
14131 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14132 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14133 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14134 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
14136 /* Parse an OpenACC routine directive. For named directives, we apply
14137 immediately to the named function. For unnamed ones we then parse
14138 a declaration or definition, which must be for a function. */
14141 c_parser_oacc_routine (c_parser
*parser
, enum pragma_context context
)
14143 gcc_checking_assert (context
== pragma_external
);
14145 oacc_routine_data data
;
14146 data
.error_seen
= false;
14147 data
.fndecl_seen
= false;
14148 data
.clauses
= NULL_TREE
;
14149 data
.loc
= c_parser_peek_token (parser
)->location
;
14151 c_parser_consume_pragma (parser
);
14153 /* Look for optional '( name )'. */
14154 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14156 c_parser_consume_token (parser
); /* '(' */
14158 tree decl
= NULL_TREE
;
14159 c_token
*name_token
= c_parser_peek_token (parser
);
14160 location_t name_loc
= name_token
->location
;
14161 if (name_token
->type
== CPP_NAME
14162 && (name_token
->id_kind
== C_ID_ID
14163 || name_token
->id_kind
== C_ID_TYPENAME
))
14165 decl
= lookup_name (name_token
->value
);
14167 error_at (name_loc
,
14168 "%qE has not been declared", name_token
->value
);
14169 c_parser_consume_token (parser
);
14172 c_parser_error (parser
, "expected function name");
14175 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14177 c_parser_skip_to_pragma_eol (parser
, false);
14182 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
14183 "#pragma acc routine");
14185 if (TREE_CODE (decl
) != FUNCTION_DECL
)
14187 error_at (name_loc
, "%qD does not refer to a function", decl
);
14191 c_finish_oacc_routine (&data
, decl
, false);
14193 else /* No optional '( name )'. */
14196 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
14197 "#pragma acc routine");
14199 /* Emit a helpful diagnostic if there's another pragma following this
14200 one. Also don't allow a static assertion declaration, as in the
14201 following we'll just parse a *single* "declaration or function
14202 definition", and the static assertion counts an one. */
14203 if (c_parser_next_token_is (parser
, CPP_PRAGMA
)
14204 || c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
14206 error_at (data
.loc
,
14207 "%<#pragma acc routine%> not immediately followed by"
14208 " function declaration or definition");
14209 /* ..., and then just keep going. */
14213 /* We only have to consider the pragma_external case here. */
14214 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14215 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
14217 int ext
= disable_extension_diagnostics ();
14219 c_parser_consume_token (parser
);
14220 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14221 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
14222 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14223 NULL
, vNULL
, &data
);
14224 restore_extension_diagnostics (ext
);
14227 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14228 NULL
, vNULL
, &data
);
14232 /* Finalize an OpenACC routine pragma, applying it to FNDECL.
14233 IS_DEFN is true if we're applying it to the definition. */
14236 c_finish_oacc_routine (struct oacc_routine_data
*data
, tree fndecl
,
14239 /* Keep going if we're in error reporting mode. */
14240 if (data
->error_seen
14241 || fndecl
== error_mark_node
)
14244 if (data
->fndecl_seen
)
14246 error_at (data
->loc
,
14247 "%<#pragma acc routine%> not immediately followed by"
14248 " a single function declaration or definition");
14249 data
->error_seen
= true;
14252 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
14254 error_at (data
->loc
,
14255 "%<#pragma acc routine%> not immediately followed by"
14256 " function declaration or definition");
14257 data
->error_seen
= true;
14261 if (oacc_get_fn_attrib (fndecl
))
14263 error_at (data
->loc
,
14264 "%<#pragma acc routine%> already applied to %qD", fndecl
);
14265 data
->error_seen
= true;
14269 if (TREE_USED (fndecl
) || (!is_defn
&& DECL_SAVED_TREE (fndecl
)))
14271 error_at (data
->loc
,
14273 ? G_("%<#pragma acc routine%> must be applied before use")
14274 : G_("%<#pragma acc routine%> must be applied before "
14276 data
->error_seen
= true;
14280 /* Process the routine's dimension clauses. */
14281 tree dims
= oacc_build_routine_dims (data
->clauses
);
14282 oacc_replace_fn_attrib (fndecl
, dims
);
14284 /* Add an "omp declare target" attribute. */
14285 DECL_ATTRIBUTES (fndecl
)
14286 = tree_cons (get_identifier ("omp declare target"),
14287 NULL_TREE
, DECL_ATTRIBUTES (fndecl
));
14289 /* Remember that we've used this "#pragma acc routine". */
14290 data
->fndecl_seen
= true;
14294 # pragma acc update oacc-update-clause[optseq] new-line
14297 #define OACC_UPDATE_CLAUSE_MASK \
14298 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14299 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
14300 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
14301 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14302 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
14303 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14306 c_parser_oacc_update (c_parser
*parser
)
14308 location_t loc
= c_parser_peek_token (parser
)->location
;
14310 c_parser_consume_pragma (parser
);
14312 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
14313 "#pragma acc update");
14314 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
14317 "%<#pragma acc update%> must contain at least one "
14318 "%<device%> or %<host%> or %<self%> clause");
14325 tree stmt
= make_node (OACC_UPDATE
);
14326 TREE_TYPE (stmt
) = void_type_node
;
14327 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
14328 SET_EXPR_LOCATION (stmt
, loc
);
14333 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
14335 LOC is the location of the #pragma token.
14338 #define OACC_WAIT_CLAUSE_MASK \
14339 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
14342 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
14344 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
14346 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
14347 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
14349 strcpy (p_name
, " wait");
14350 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
14351 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
14358 # pragma omp atomic new-line
14362 x binop= expr | x++ | ++x | x-- | --x
14364 +, *, -, /, &, ^, |, <<, >>
14366 where x is an lvalue expression with scalar type.
14369 # pragma omp atomic new-line
14372 # pragma omp atomic read new-line
14375 # pragma omp atomic write new-line
14378 # pragma omp atomic update new-line
14381 # pragma omp atomic capture new-line
14384 # pragma omp atomic capture new-line
14392 expression-stmt | x = x binop expr
14394 v = expression-stmt
14396 { v = x; update-stmt; } | { update-stmt; v = x; }
14400 expression-stmt | x = x binop expr | x = expr binop x
14404 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
14406 where x and v are lvalue expressions with scalar type.
14408 LOC is the location of the #pragma token. */
14411 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
14413 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
14414 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
14415 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
14416 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
14417 struct c_expr expr
;
14419 bool structured_block
= false;
14420 bool swapped
= false;
14421 bool seq_cst
= false;
14424 if (c_parser_next_token_is (parser
, CPP_NAME
))
14426 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14427 if (!strcmp (p
, "seq_cst"))
14430 c_parser_consume_token (parser
);
14431 if (c_parser_next_token_is (parser
, CPP_COMMA
)
14432 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
14433 c_parser_consume_token (parser
);
14436 if (c_parser_next_token_is (parser
, CPP_NAME
))
14438 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14440 if (!strcmp (p
, "read"))
14441 code
= OMP_ATOMIC_READ
;
14442 else if (!strcmp (p
, "write"))
14444 else if (!strcmp (p
, "update"))
14446 else if (!strcmp (p
, "capture"))
14447 code
= OMP_ATOMIC_CAPTURE_NEW
;
14451 c_parser_consume_token (parser
);
14455 if (c_parser_next_token_is (parser
, CPP_COMMA
)
14456 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
14457 c_parser_consume_token (parser
);
14459 if (c_parser_next_token_is (parser
, CPP_NAME
))
14462 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14463 if (!strcmp (p
, "seq_cst"))
14466 c_parser_consume_token (parser
);
14470 c_parser_skip_to_pragma_eol (parser
);
14474 case OMP_ATOMIC_READ
:
14475 case NOP_EXPR
: /* atomic write */
14476 v
= c_parser_cast_expression (parser
, NULL
).value
;
14477 non_lvalue_p
= !lvalue_p (v
);
14478 v
= c_fully_fold (v
, false, NULL
);
14479 if (v
== error_mark_node
)
14482 v
= non_lvalue (v
);
14483 loc
= c_parser_peek_token (parser
)->location
;
14484 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14486 if (code
== NOP_EXPR
)
14488 lhs
= c_parser_expression (parser
).value
;
14489 lhs
= c_fully_fold (lhs
, false, NULL
);
14490 if (lhs
== error_mark_node
)
14495 lhs
= c_parser_cast_expression (parser
, NULL
).value
;
14496 non_lvalue_p
= !lvalue_p (lhs
);
14497 lhs
= c_fully_fold (lhs
, false, NULL
);
14498 if (lhs
== error_mark_node
)
14501 lhs
= non_lvalue (lhs
);
14503 if (code
== NOP_EXPR
)
14505 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
14513 case OMP_ATOMIC_CAPTURE_NEW
:
14514 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
14516 c_parser_consume_token (parser
);
14517 structured_block
= true;
14521 v
= c_parser_cast_expression (parser
, NULL
).value
;
14522 non_lvalue_p
= !lvalue_p (v
);
14523 v
= c_fully_fold (v
, false, NULL
);
14524 if (v
== error_mark_node
)
14527 v
= non_lvalue (v
);
14528 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14536 /* For structured_block case we don't know yet whether
14537 old or new x should be captured. */
14539 eloc
= c_parser_peek_token (parser
)->location
;
14540 expr
= c_parser_cast_expression (parser
, NULL
);
14542 expr
= default_function_array_conversion (eloc
, expr
);
14543 unfolded_lhs
= expr
.value
;
14544 lhs
= c_fully_fold (lhs
, false, NULL
);
14546 switch (TREE_CODE (lhs
))
14550 c_parser_skip_to_end_of_block_or_statement (parser
);
14551 if (structured_block
)
14553 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
14554 c_parser_consume_token (parser
);
14555 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
14557 c_parser_skip_to_end_of_block_or_statement (parser
);
14558 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
14559 c_parser_consume_token (parser
);
14564 case POSTINCREMENT_EXPR
:
14565 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
14566 code
= OMP_ATOMIC_CAPTURE_OLD
;
14568 case PREINCREMENT_EXPR
:
14569 lhs
= TREE_OPERAND (lhs
, 0);
14570 unfolded_lhs
= NULL_TREE
;
14571 opcode
= PLUS_EXPR
;
14572 rhs
= integer_one_node
;
14575 case POSTDECREMENT_EXPR
:
14576 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
14577 code
= OMP_ATOMIC_CAPTURE_OLD
;
14579 case PREDECREMENT_EXPR
:
14580 lhs
= TREE_OPERAND (lhs
, 0);
14581 unfolded_lhs
= NULL_TREE
;
14582 opcode
= MINUS_EXPR
;
14583 rhs
= integer_one_node
;
14586 case COMPOUND_EXPR
:
14587 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
14588 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
14589 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
14590 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
14591 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
14592 (TREE_OPERAND (lhs
, 1), 0), 0)))
14594 /* Undo effects of boolean_increment for post {in,de}crement. */
14595 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
14598 if (TREE_CODE (lhs
) == MODIFY_EXPR
14599 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
14601 /* Undo effects of boolean_increment. */
14602 if (integer_onep (TREE_OPERAND (lhs
, 1)))
14604 /* This is pre or post increment. */
14605 rhs
= TREE_OPERAND (lhs
, 1);
14606 lhs
= TREE_OPERAND (lhs
, 0);
14607 unfolded_lhs
= NULL_TREE
;
14609 if (code
== OMP_ATOMIC_CAPTURE_NEW
14610 && !structured_block
14611 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
14612 code
= OMP_ATOMIC_CAPTURE_OLD
;
14615 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
14616 && TREE_OPERAND (lhs
, 0)
14617 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
14619 /* This is pre or post decrement. */
14620 rhs
= TREE_OPERAND (lhs
, 1);
14621 lhs
= TREE_OPERAND (lhs
, 0);
14622 unfolded_lhs
= NULL_TREE
;
14624 if (code
== OMP_ATOMIC_CAPTURE_NEW
14625 && !structured_block
14626 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
14627 code
= OMP_ATOMIC_CAPTURE_OLD
;
14633 if (!lvalue_p (unfolded_lhs
))
14634 lhs
= non_lvalue (lhs
);
14635 switch (c_parser_peek_token (parser
)->type
)
14638 opcode
= MULT_EXPR
;
14641 opcode
= TRUNC_DIV_EXPR
;
14644 opcode
= PLUS_EXPR
;
14647 opcode
= MINUS_EXPR
;
14649 case CPP_LSHIFT_EQ
:
14650 opcode
= LSHIFT_EXPR
;
14652 case CPP_RSHIFT_EQ
:
14653 opcode
= RSHIFT_EXPR
;
14656 opcode
= BIT_AND_EXPR
;
14659 opcode
= BIT_IOR_EXPR
;
14662 opcode
= BIT_XOR_EXPR
;
14665 c_parser_consume_token (parser
);
14666 eloc
= c_parser_peek_token (parser
)->location
;
14667 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
14669 switch (TREE_CODE (rhs1
))
14672 case TRUNC_DIV_EXPR
:
14681 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
14683 opcode
= TREE_CODE (rhs1
);
14684 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
14685 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
14688 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
14690 opcode
= TREE_CODE (rhs1
);
14691 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
14692 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
14693 swapped
= !commutative_tree_code (opcode
);
14702 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
14704 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
14706 code
= OMP_ATOMIC_CAPTURE_OLD
;
14709 expr
= default_function_array_read_conversion (eloc
, expr
);
14710 unfolded_lhs1
= expr
.value
;
14711 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
14713 c_parser_consume_token (parser
);
14716 if (structured_block
)
14719 expr
= default_function_array_read_conversion (eloc
, expr
);
14720 rhs
= c_fully_fold (expr
.value
, false, NULL
);
14725 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
14728 c_parser_error (parser
,
14729 "invalid operator for %<#pragma omp atomic%>");
14733 /* Arrange to pass the location of the assignment operator to
14734 c_finish_omp_atomic. */
14735 loc
= c_parser_peek_token (parser
)->location
;
14736 c_parser_consume_token (parser
);
14737 eloc
= c_parser_peek_token (parser
)->location
;
14738 expr
= c_parser_expression (parser
);
14739 expr
= default_function_array_read_conversion (eloc
, expr
);
14741 rhs
= c_fully_fold (rhs
, false, NULL
);
14745 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
14747 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
14749 v
= c_parser_cast_expression (parser
, NULL
).value
;
14750 non_lvalue_p
= !lvalue_p (v
);
14751 v
= c_fully_fold (v
, false, NULL
);
14752 if (v
== error_mark_node
)
14755 v
= non_lvalue (v
);
14756 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14758 eloc
= c_parser_peek_token (parser
)->location
;
14759 expr
= c_parser_cast_expression (parser
, NULL
);
14761 expr
= default_function_array_read_conversion (eloc
, expr
);
14762 unfolded_lhs1
= expr
.value
;
14763 lhs1
= c_fully_fold (lhs1
, false, NULL
);
14764 if (lhs1
== error_mark_node
)
14766 if (!lvalue_p (unfolded_lhs1
))
14767 lhs1
= non_lvalue (lhs1
);
14769 if (structured_block
)
14771 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14772 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
14775 if (unfolded_lhs
&& unfolded_lhs1
14776 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
14778 error ("%<#pragma omp atomic capture%> uses two different "
14779 "expressions for memory");
14780 stmt
= error_mark_node
;
14783 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
14785 if (stmt
!= error_mark_node
)
14788 if (!structured_block
)
14789 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14794 # pragma omp barrier new-line
14798 c_parser_omp_barrier (c_parser
*parser
)
14800 location_t loc
= c_parser_peek_token (parser
)->location
;
14801 c_parser_consume_pragma (parser
);
14802 c_parser_skip_to_pragma_eol (parser
);
14804 c_finish_omp_barrier (loc
);
14808 # pragma omp critical [(name)] new-line
14812 # pragma omp critical [(name) [hint(expression)]] new-line
14814 LOC is the location of the #pragma itself. */
14816 #define OMP_CRITICAL_CLAUSE_MASK \
14817 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
14820 c_parser_omp_critical (location_t loc
, c_parser
*parser
, bool *if_p
)
14822 tree stmt
, name
= NULL_TREE
, clauses
= NULL_TREE
;
14824 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14826 c_parser_consume_token (parser
);
14827 if (c_parser_next_token_is (parser
, CPP_NAME
))
14829 name
= c_parser_peek_token (parser
)->value
;
14830 c_parser_consume_token (parser
);
14831 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14834 c_parser_error (parser
, "expected identifier");
14836 clauses
= c_parser_omp_all_clauses (parser
,
14837 OMP_CRITICAL_CLAUSE_MASK
,
14838 "#pragma omp critical");
14842 if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14843 c_parser_error (parser
, "expected %<(%> or end of line");
14844 c_parser_skip_to_pragma_eol (parser
);
14847 stmt
= c_parser_omp_structured_block (parser
, if_p
);
14848 return c_finish_omp_critical (loc
, stmt
, name
, clauses
);
14852 # pragma omp flush flush-vars[opt] new-line
14855 ( variable-list ) */
14858 c_parser_omp_flush (c_parser
*parser
)
14860 location_t loc
= c_parser_peek_token (parser
)->location
;
14861 c_parser_consume_pragma (parser
);
14862 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14863 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
14864 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14865 c_parser_error (parser
, "expected %<(%> or end of line");
14866 c_parser_skip_to_pragma_eol (parser
);
14868 c_finish_omp_flush (loc
);
14871 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
14872 The real trick here is to determine the loop control variable early
14873 so that we can push a new decl if necessary to make it private.
14874 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
14878 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
14879 tree clauses
, tree
*cclauses
, bool *if_p
)
14881 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
14882 tree declv
, condv
, incrv
, initv
, ret
= NULL_TREE
;
14883 tree pre_body
= NULL_TREE
, this_pre_body
;
14884 tree ordered_cl
= NULL_TREE
;
14885 bool fail
= false, open_brace_parsed
= false;
14886 int i
, collapse
= 1, ordered
= 0, count
, nbraces
= 0;
14887 location_t for_loc
;
14888 bool tiling
= false;
14889 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
14891 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
14892 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
14893 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
14894 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_TILE
)
14897 collapse
= list_length (OMP_CLAUSE_TILE_LIST (cl
));
14899 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_ORDERED
14900 && OMP_CLAUSE_ORDERED_EXPR (cl
))
14903 ordered
= tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl
));
14906 if (ordered
&& ordered
< collapse
)
14908 error_at (OMP_CLAUSE_LOCATION (ordered_cl
),
14909 "%<ordered%> clause parameter is less than %<collapse%>");
14910 OMP_CLAUSE_ORDERED_EXPR (ordered_cl
)
14911 = build_int_cst (NULL_TREE
, collapse
);
14912 ordered
= collapse
;
14916 for (tree
*pc
= &clauses
; *pc
; )
14917 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_LINEAR
)
14919 error_at (OMP_CLAUSE_LOCATION (*pc
),
14920 "%<linear%> clause may not be specified together "
14921 "with %<ordered%> clause with a parameter");
14922 *pc
= OMP_CLAUSE_CHAIN (*pc
);
14925 pc
= &OMP_CLAUSE_CHAIN (*pc
);
14928 gcc_assert (tiling
|| (collapse
>= 1 && ordered
>= 0));
14929 count
= ordered
? ordered
: collapse
;
14931 declv
= make_tree_vec (count
);
14932 initv
= make_tree_vec (count
);
14933 condv
= make_tree_vec (count
);
14934 incrv
= make_tree_vec (count
);
14936 if (code
!= CILK_FOR
14937 && !c_parser_next_token_is_keyword (parser
, RID_FOR
))
14939 c_parser_error (parser
, "for statement expected");
14942 if (code
== CILK_FOR
14943 && !c_parser_next_token_is_keyword (parser
, RID_CILK_FOR
))
14945 c_parser_error (parser
, "_Cilk_for statement expected");
14948 for_loc
= c_parser_peek_token (parser
)->location
;
14949 c_parser_consume_token (parser
);
14951 for (i
= 0; i
< count
; i
++)
14953 int bracecount
= 0;
14955 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14958 /* Parse the initialization declaration or expression. */
14959 if (c_parser_next_tokens_start_declaration (parser
))
14962 vec_safe_push (for_block
, c_begin_compound_stmt (true));
14963 this_pre_body
= push_stmt_list ();
14964 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
14968 this_pre_body
= pop_stmt_list (this_pre_body
);
14972 pre_body
= push_stmt_list ();
14974 add_stmt (this_pre_body
);
14975 pre_body
= pop_stmt_list (pre_body
);
14978 pre_body
= this_pre_body
;
14980 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
14983 if (DECL_INITIAL (decl
) == error_mark_node
)
14984 decl
= error_mark_node
;
14987 else if (c_parser_next_token_is (parser
, CPP_NAME
)
14988 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
14990 struct c_expr decl_exp
;
14991 struct c_expr init_exp
;
14992 location_t init_loc
;
14994 decl_exp
= c_parser_postfix_expression (parser
);
14995 decl
= decl_exp
.value
;
14997 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
14999 init_loc
= c_parser_peek_token (parser
)->location
;
15000 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
15001 init_exp
= default_function_array_read_conversion (init_loc
,
15003 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
15004 NOP_EXPR
, init_loc
, init_exp
.value
,
15005 init_exp
.original_type
);
15006 init
= c_process_expr_stmt (init_loc
, init
);
15008 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15013 c_parser_error (parser
,
15014 "expected iteration declaration or initialization");
15015 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
15021 /* Parse the loop condition. */
15023 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
15025 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
15026 struct c_expr cond_expr
15027 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
15029 cond
= cond_expr
.value
;
15030 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
15031 cond
= c_fully_fold (cond
, false, NULL
);
15032 switch (cond_expr
.original_code
)
15040 if (code
== CILK_SIMD
|| code
== CILK_FOR
)
15044 /* Can't be cond = error_mark_node, because we want to preserve
15045 the location until c_finish_omp_for. */
15046 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
15049 protected_set_expr_location (cond
, cond_loc
);
15051 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15053 /* Parse the increment expression. */
15055 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
15057 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
15059 incr
= c_process_expr_stmt (incr_loc
,
15060 c_parser_expression (parser
).value
);
15062 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
15064 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
15068 TREE_VEC_ELT (declv
, i
) = decl
;
15069 TREE_VEC_ELT (initv
, i
) = init
;
15070 TREE_VEC_ELT (condv
, i
) = cond
;
15071 TREE_VEC_ELT (incrv
, i
) = incr
;
15075 if (i
== count
- 1)
15078 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
15079 in between the collapsed for loops to be still considered perfectly
15080 nested. Hopefully the final version clarifies this.
15081 For now handle (multiple) {'s and empty statements. */
15084 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
15086 c_parser_consume_token (parser
);
15089 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
15091 c_parser_consume_token (parser
);
15094 else if (bracecount
15095 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15096 c_parser_consume_token (parser
);
15099 c_parser_error (parser
, "not enough perfectly nested loops");
15102 open_brace_parsed
= true;
15112 nbraces
+= bracecount
;
15118 save_break
= c_break_label
;
15119 if (code
== CILK_SIMD
)
15120 c_break_label
= build_int_cst (size_type_node
, 2);
15122 c_break_label
= size_one_node
;
15123 save_cont
= c_cont_label
;
15124 c_cont_label
= NULL_TREE
;
15125 body
= push_stmt_list ();
15127 if (open_brace_parsed
)
15129 location_t here
= c_parser_peek_token (parser
)->location
;
15130 stmt
= c_begin_compound_stmt (true);
15131 c_parser_compound_statement_nostart (parser
);
15132 add_stmt (c_end_compound_stmt (here
, stmt
, true));
15135 add_stmt (c_parser_c99_block_statement (parser
, if_p
));
15138 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
15139 SET_EXPR_LOCATION (t
, loc
);
15143 body
= pop_stmt_list (body
);
15144 c_break_label
= save_break
;
15145 c_cont_label
= save_cont
;
15149 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15151 c_parser_consume_token (parser
);
15154 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15155 c_parser_consume_token (parser
);
15158 c_parser_error (parser
, "collapsed loops not perfectly nested");
15161 location_t here
= c_parser_peek_token (parser
)->location
;
15162 stmt
= c_begin_compound_stmt (true);
15164 c_parser_compound_statement_nostart (parser
);
15165 body
= c_end_compound_stmt (here
, stmt
, true);
15172 /* Only bother calling c_finish_omp_for if we haven't already generated
15173 an error from the initialization parsing. */
15176 stmt
= c_finish_omp_for (loc
, code
, declv
, NULL
, initv
, condv
,
15177 incrv
, body
, pre_body
);
15179 /* Check for iterators appearing in lb, b or incr expressions. */
15180 if (stmt
&& !c_omp_check_loop_iv (stmt
, declv
, NULL
))
15187 if (cclauses
!= NULL
15188 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
15191 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
15192 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
15193 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
15194 c
= &OMP_CLAUSE_CHAIN (*c
);
15197 for (i
= 0; i
< count
; i
++)
15198 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
15201 c
= &OMP_CLAUSE_CHAIN (*c
);
15202 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
15205 "iteration variable %qD should not be firstprivate",
15206 OMP_CLAUSE_DECL (*c
));
15207 *c
= OMP_CLAUSE_CHAIN (*c
);
15211 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
15213 *c
= OMP_CLAUSE_CHAIN (*c
);
15214 if (code
== OMP_SIMD
)
15216 OMP_CLAUSE_CHAIN (l
)
15217 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15218 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
15222 OMP_CLAUSE_CHAIN (l
) = clauses
;
15228 OMP_FOR_CLAUSES (stmt
) = clauses
;
15233 while (!for_block
->is_empty ())
15235 /* FIXME diagnostics: LOC below should be the actual location of
15236 this particular for block. We need to build a list of
15237 locations to go along with FOR_BLOCK. */
15238 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
15241 release_tree_vector (for_block
);
15245 /* Helper function for OpenMP parsing, split clauses and call
15246 finish_omp_clauses on each of the set of clauses afterwards. */
15249 omp_split_clauses (location_t loc
, enum tree_code code
,
15250 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
15253 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
15254 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
15256 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
], C_ORT_OMP
);
15260 #pragma omp simd simd-clause[optseq] new-line
15263 LOC is the location of the #pragma token.
15266 #define OMP_SIMD_CLAUSE_MASK \
15267 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
15268 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
15269 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15270 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
15271 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15272 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15273 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15274 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15277 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
15278 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15281 tree block
, clauses
, ret
;
15283 strcat (p_name
, " simd");
15284 mask
|= OMP_SIMD_CLAUSE_MASK
;
15286 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15289 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
15290 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
15291 tree c
= omp_find_clause (cclauses
[C_OMP_CLAUSE_SPLIT_FOR
],
15292 OMP_CLAUSE_ORDERED
);
15293 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
15295 error_at (OMP_CLAUSE_LOCATION (c
),
15296 "%<ordered%> clause with parameter may not be specified "
15297 "on %qs construct", p_name
);
15298 OMP_CLAUSE_ORDERED_EXPR (c
) = NULL_TREE
;
15302 block
= c_begin_compound_stmt (true);
15303 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
, if_p
);
15304 block
= c_end_compound_stmt (loc
, block
, true);
15311 #pragma omp for for-clause[optseq] new-line
15315 #pragma omp for simd for-simd-clause[optseq] new-line
15318 LOC is the location of the #pragma token.
15321 #define OMP_FOR_CLAUSE_MASK \
15322 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15323 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15324 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15325 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15326 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15327 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
15328 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
15329 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
15330 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15333 c_parser_omp_for (location_t loc
, c_parser
*parser
,
15334 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15337 tree block
, clauses
, ret
;
15339 strcat (p_name
, " for");
15340 mask
|= OMP_FOR_CLAUSE_MASK
;
15341 /* parallel for{, simd} disallows nowait clause, but for
15342 target {teams distribute ,}parallel for{, simd} it should be accepted. */
15343 if (cclauses
&& (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) == 0)
15344 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
15345 /* Composite distribute parallel for{, simd} disallows ordered clause. */
15346 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15347 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
15349 if (c_parser_next_token_is (parser
, CPP_NAME
))
15351 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15353 if (strcmp (p
, "simd") == 0)
15355 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15356 if (cclauses
== NULL
)
15357 cclauses
= cclauses_buf
;
15359 c_parser_consume_token (parser
);
15360 if (!flag_openmp
) /* flag_openmp_simd */
15361 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
15363 block
= c_begin_compound_stmt (true);
15364 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15365 block
= c_end_compound_stmt (loc
, block
, true);
15366 if (ret
== NULL_TREE
)
15368 ret
= make_node (OMP_FOR
);
15369 TREE_TYPE (ret
) = void_type_node
;
15370 OMP_FOR_BODY (ret
) = block
;
15371 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15372 SET_EXPR_LOCATION (ret
, loc
);
15377 if (!flag_openmp
) /* flag_openmp_simd */
15379 c_parser_skip_to_pragma_eol (parser
, false);
15383 /* Composite distribute parallel for disallows linear clause. */
15384 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15385 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINEAR
);
15387 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15390 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
15391 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15394 block
= c_begin_compound_stmt (true);
15395 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
, if_p
);
15396 block
= c_end_compound_stmt (loc
, block
, true);
15403 # pragma omp master new-line
15406 LOC is the location of the #pragma token.
15410 c_parser_omp_master (location_t loc
, c_parser
*parser
, bool *if_p
)
15412 c_parser_skip_to_pragma_eol (parser
);
15413 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
,
15418 # pragma omp ordered new-line
15422 # pragma omp ordered ordered-clauses new-line
15425 # pragma omp ordered depend-clauses new-line */
15427 #define OMP_ORDERED_CLAUSE_MASK \
15428 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
15429 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
15431 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
15432 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
15435 c_parser_omp_ordered (c_parser
*parser
, enum pragma_context context
,
15438 location_t loc
= c_parser_peek_token (parser
)->location
;
15439 c_parser_consume_pragma (parser
);
15441 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
15443 c_parser_error (parser
, "expected declaration specifiers");
15444 c_parser_skip_to_pragma_eol (parser
, false);
15448 if (c_parser_next_token_is (parser
, CPP_NAME
))
15450 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15452 if (!strcmp ("depend", p
))
15454 if (context
== pragma_stmt
)
15457 "%<#pragma omp ordered%> with %<depend%> clause may "
15458 "only be used in compound statements");
15459 c_parser_skip_to_pragma_eol (parser
, false);
15464 = c_parser_omp_all_clauses (parser
,
15465 OMP_ORDERED_DEPEND_CLAUSE_MASK
,
15466 "#pragma omp ordered");
15467 c_finish_omp_ordered (loc
, clauses
, NULL_TREE
);
15472 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_ORDERED_CLAUSE_MASK
,
15473 "#pragma omp ordered");
15474 c_finish_omp_ordered (loc
, clauses
,
15475 c_parser_omp_structured_block (parser
, if_p
));
15482 { section-sequence }
15485 section-directive[opt] structured-block
15486 section-sequence section-directive structured-block
15488 SECTIONS_LOC is the location of the #pragma omp sections. */
15491 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
15493 tree stmt
, substmt
;
15494 bool error_suppress
= false;
15497 loc
= c_parser_peek_token (parser
)->location
;
15498 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
15500 /* Avoid skipping until the end of the block. */
15501 parser
->error
= false;
15505 stmt
= push_stmt_list ();
15507 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
15509 substmt
= c_parser_omp_structured_block (parser
, NULL
);
15510 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
15511 SET_EXPR_LOCATION (substmt
, loc
);
15512 add_stmt (substmt
);
15517 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15519 if (c_parser_next_token_is (parser
, CPP_EOF
))
15522 loc
= c_parser_peek_token (parser
)->location
;
15523 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
15525 c_parser_consume_pragma (parser
);
15526 c_parser_skip_to_pragma_eol (parser
);
15527 error_suppress
= false;
15529 else if (!error_suppress
)
15531 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
15532 error_suppress
= true;
15535 substmt
= c_parser_omp_structured_block (parser
, NULL
);
15536 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
15537 SET_EXPR_LOCATION (substmt
, loc
);
15538 add_stmt (substmt
);
15540 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
15541 "expected %<#pragma omp section%> or %<}%>");
15543 substmt
= pop_stmt_list (stmt
);
15545 stmt
= make_node (OMP_SECTIONS
);
15546 SET_EXPR_LOCATION (stmt
, sections_loc
);
15547 TREE_TYPE (stmt
) = void_type_node
;
15548 OMP_SECTIONS_BODY (stmt
) = substmt
;
15550 return add_stmt (stmt
);
15554 # pragma omp sections sections-clause[optseq] newline
15557 LOC is the location of the #pragma token.
15560 #define OMP_SECTIONS_CLAUSE_MASK \
15561 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15562 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15563 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15564 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15565 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15568 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
15569 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
15571 tree block
, clauses
, ret
;
15573 strcat (p_name
, " sections");
15574 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
15576 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
15578 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15581 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
15582 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
15585 block
= c_begin_compound_stmt (true);
15586 ret
= c_parser_omp_sections_scope (loc
, parser
);
15588 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
15589 block
= c_end_compound_stmt (loc
, block
, true);
15596 # pragma omp parallel parallel-clause[optseq] new-line
15598 # pragma omp parallel for parallel-for-clause[optseq] new-line
15600 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
15604 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
15607 LOC is the location of the #pragma token.
15610 #define OMP_PARALLEL_CLAUSE_MASK \
15611 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15612 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15613 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15614 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
15615 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15616 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
15617 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15618 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
15619 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
15622 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
15623 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15626 tree stmt
, clauses
, block
;
15628 strcat (p_name
, " parallel");
15629 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
15630 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
15631 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) != 0
15632 && (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) == 0)
15633 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_COPYIN
);
15635 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
15637 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15638 if (cclauses
== NULL
)
15639 cclauses
= cclauses_buf
;
15641 c_parser_consume_token (parser
);
15642 if (!flag_openmp
) /* flag_openmp_simd */
15643 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15644 block
= c_begin_omp_parallel ();
15645 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15647 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
15649 if (ret
== NULL_TREE
)
15651 OMP_PARALLEL_COMBINED (stmt
) = 1;
15654 /* When combined with distribute, parallel has to be followed by for.
15655 #pragma omp target parallel is allowed though. */
15657 && (mask
& (OMP_CLAUSE_MASK_1
15658 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15660 error_at (loc
, "expected %<for%> after %qs", p_name
);
15661 c_parser_skip_to_pragma_eol (parser
);
15664 else if (!flag_openmp
) /* flag_openmp_simd */
15666 c_parser_skip_to_pragma_eol (parser
, false);
15669 else if (cclauses
== NULL
&& c_parser_next_token_is (parser
, CPP_NAME
))
15671 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15672 if (strcmp (p
, "sections") == 0)
15674 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15675 if (cclauses
== NULL
)
15676 cclauses
= cclauses_buf
;
15678 c_parser_consume_token (parser
);
15679 block
= c_begin_omp_parallel ();
15680 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
15681 stmt
= c_finish_omp_parallel (loc
,
15682 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
15684 OMP_PARALLEL_COMBINED (stmt
) = 1;
15689 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15692 omp_split_clauses (loc
, OMP_PARALLEL
, mask
, clauses
, cclauses
);
15693 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
15696 block
= c_begin_omp_parallel ();
15697 c_parser_statement (parser
, if_p
);
15698 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
15704 # pragma omp single single-clause[optseq] new-line
15707 LOC is the location of the #pragma.
15710 #define OMP_SINGLE_CLAUSE_MASK \
15711 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15712 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15713 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
15714 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15717 c_parser_omp_single (location_t loc
, c_parser
*parser
, bool *if_p
)
15719 tree stmt
= make_node (OMP_SINGLE
);
15720 SET_EXPR_LOCATION (stmt
, loc
);
15721 TREE_TYPE (stmt
) = void_type_node
;
15723 OMP_SINGLE_CLAUSES (stmt
)
15724 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
15725 "#pragma omp single");
15726 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
15728 return add_stmt (stmt
);
15732 # pragma omp task task-clause[optseq] new-line
15734 LOC is the location of the #pragma.
15737 #define OMP_TASK_CLAUSE_MASK \
15738 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15739 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
15740 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
15741 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15742 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15743 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15744 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
15745 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
15746 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15747 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
15750 c_parser_omp_task (location_t loc
, c_parser
*parser
, bool *if_p
)
15752 tree clauses
, block
;
15754 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
15755 "#pragma omp task");
15757 block
= c_begin_omp_task ();
15758 c_parser_statement (parser
, if_p
);
15759 return c_finish_omp_task (loc
, clauses
, block
);
15763 # pragma omp taskwait new-line
15767 c_parser_omp_taskwait (c_parser
*parser
)
15769 location_t loc
= c_parser_peek_token (parser
)->location
;
15770 c_parser_consume_pragma (parser
);
15771 c_parser_skip_to_pragma_eol (parser
);
15773 c_finish_omp_taskwait (loc
);
15777 # pragma omp taskyield new-line
15781 c_parser_omp_taskyield (c_parser
*parser
)
15783 location_t loc
= c_parser_peek_token (parser
)->location
;
15784 c_parser_consume_pragma (parser
);
15785 c_parser_skip_to_pragma_eol (parser
);
15787 c_finish_omp_taskyield (loc
);
15791 # pragma omp taskgroup new-line
15795 c_parser_omp_taskgroup (c_parser
*parser
, bool *if_p
)
15797 location_t loc
= c_parser_peek_token (parser
)->location
;
15798 c_parser_skip_to_pragma_eol (parser
);
15799 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
,
15804 # pragma omp cancel cancel-clause[optseq] new-line
15806 LOC is the location of the #pragma.
15809 #define OMP_CANCEL_CLAUSE_MASK \
15810 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
15811 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
15812 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
15813 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
15814 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
15817 c_parser_omp_cancel (c_parser
*parser
)
15819 location_t loc
= c_parser_peek_token (parser
)->location
;
15821 c_parser_consume_pragma (parser
);
15822 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
15823 "#pragma omp cancel");
15825 c_finish_omp_cancel (loc
, clauses
);
15829 # pragma omp cancellation point cancelpt-clause[optseq] new-line
15831 LOC is the location of the #pragma.
15834 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
15835 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
15836 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
15837 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
15838 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
15841 c_parser_omp_cancellation_point (c_parser
*parser
, enum pragma_context context
)
15843 location_t loc
= c_parser_peek_token (parser
)->location
;
15845 bool point_seen
= false;
15847 c_parser_consume_pragma (parser
);
15848 if (c_parser_next_token_is (parser
, CPP_NAME
))
15850 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15851 if (strcmp (p
, "point") == 0)
15853 c_parser_consume_token (parser
);
15859 c_parser_error (parser
, "expected %<point%>");
15860 c_parser_skip_to_pragma_eol (parser
);
15864 if (context
!= pragma_compound
)
15866 if (context
== pragma_stmt
)
15867 error_at (loc
, "%<#pragma omp cancellation point%> may only be used in"
15868 " compound statements");
15870 c_parser_error (parser
, "expected declaration specifiers");
15871 c_parser_skip_to_pragma_eol (parser
, false);
15876 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
15877 "#pragma omp cancellation point");
15879 c_finish_omp_cancellation_point (loc
, clauses
);
15883 #pragma omp distribute distribute-clause[optseq] new-line
15886 #define OMP_DISTRIBUTE_CLAUSE_MASK \
15887 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15888 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15889 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15890 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
15891 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15894 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
15895 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15898 tree clauses
, block
, ret
;
15900 strcat (p_name
, " distribute");
15901 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
15903 if (c_parser_next_token_is (parser
, CPP_NAME
))
15905 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15907 bool parallel
= false;
15909 if (strcmp (p
, "simd") == 0)
15912 parallel
= strcmp (p
, "parallel") == 0;
15913 if (parallel
|| simd
)
15915 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15916 if (cclauses
== NULL
)
15917 cclauses
= cclauses_buf
;
15918 c_parser_consume_token (parser
);
15919 if (!flag_openmp
) /* flag_openmp_simd */
15922 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
15925 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
15928 block
= c_begin_compound_stmt (true);
15930 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
15933 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
,
15935 block
= c_end_compound_stmt (loc
, block
, true);
15938 ret
= make_node (OMP_DISTRIBUTE
);
15939 TREE_TYPE (ret
) = void_type_node
;
15940 OMP_FOR_BODY (ret
) = block
;
15941 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
15942 SET_EXPR_LOCATION (ret
, loc
);
15947 if (!flag_openmp
) /* flag_openmp_simd */
15949 c_parser_skip_to_pragma_eol (parser
, false);
15953 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15956 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
15957 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
15960 block
= c_begin_compound_stmt (true);
15961 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
,
15963 block
= c_end_compound_stmt (loc
, block
, true);
15970 # pragma omp teams teams-clause[optseq] new-line
15971 structured-block */
15973 #define OMP_TEAMS_CLAUSE_MASK \
15974 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15975 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15976 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15977 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15978 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
15979 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
15980 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
15983 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
15984 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15987 tree clauses
, block
, ret
;
15989 strcat (p_name
, " teams");
15990 mask
|= OMP_TEAMS_CLAUSE_MASK
;
15992 if (c_parser_next_token_is (parser
, CPP_NAME
))
15994 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15995 if (strcmp (p
, "distribute") == 0)
15997 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15998 if (cclauses
== NULL
)
15999 cclauses
= cclauses_buf
;
16001 c_parser_consume_token (parser
);
16002 if (!flag_openmp
) /* flag_openmp_simd */
16003 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
,
16005 block
= c_begin_compound_stmt (true);
16006 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
,
16008 block
= c_end_compound_stmt (loc
, block
, true);
16011 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16012 ret
= make_node (OMP_TEAMS
);
16013 TREE_TYPE (ret
) = void_type_node
;
16014 OMP_TEAMS_CLAUSES (ret
) = clauses
;
16015 OMP_TEAMS_BODY (ret
) = block
;
16016 OMP_TEAMS_COMBINED (ret
) = 1;
16017 return add_stmt (ret
);
16020 if (!flag_openmp
) /* flag_openmp_simd */
16022 c_parser_skip_to_pragma_eol (parser
, false);
16026 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16029 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
16030 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16033 tree stmt
= make_node (OMP_TEAMS
);
16034 TREE_TYPE (stmt
) = void_type_node
;
16035 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
16036 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
16038 return add_stmt (stmt
);
16042 # pragma omp target data target-data-clause[optseq] new-line
16043 structured-block */
16045 #define OMP_TARGET_DATA_CLAUSE_MASK \
16046 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16047 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16048 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16049 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
16052 c_parser_omp_target_data (location_t loc
, c_parser
*parser
, bool *if_p
)
16055 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
16056 "#pragma omp target data");
16058 for (tree
*pc
= &clauses
; *pc
;)
16060 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16061 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16064 case GOMP_MAP_ALWAYS_TO
:
16065 case GOMP_MAP_FROM
:
16066 case GOMP_MAP_ALWAYS_FROM
:
16067 case GOMP_MAP_TOFROM
:
16068 case GOMP_MAP_ALWAYS_TOFROM
:
16069 case GOMP_MAP_ALLOC
:
16072 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16073 case GOMP_MAP_ALWAYS_POINTER
:
16077 error_at (OMP_CLAUSE_LOCATION (*pc
),
16078 "%<#pragma omp target data%> with map-type other "
16079 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16080 "on %<map%> clause");
16081 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16084 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16091 "%<#pragma omp target data%> must contain at least "
16092 "one %<map%> clause");
16096 tree stmt
= make_node (OMP_TARGET_DATA
);
16097 TREE_TYPE (stmt
) = void_type_node
;
16098 OMP_TARGET_DATA_CLAUSES (stmt
) = clauses
;
16099 keep_next_level ();
16100 tree block
= c_begin_compound_stmt (true);
16101 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
16102 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
16104 SET_EXPR_LOCATION (stmt
, loc
);
16105 return add_stmt (stmt
);
16109 # pragma omp target update target-update-clause[optseq] new-line */
16111 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
16112 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
16113 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16114 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16115 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16116 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16117 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16120 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
16121 enum pragma_context context
)
16123 if (context
== pragma_stmt
)
16126 "%<#pragma omp target update%> may only be "
16127 "used in compound statements");
16128 c_parser_skip_to_pragma_eol (parser
, false);
16133 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
16134 "#pragma omp target update");
16135 if (omp_find_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
16136 && omp_find_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
16139 "%<#pragma omp target update%> must contain at least one "
16140 "%<from%> or %<to%> clauses");
16144 tree stmt
= make_node (OMP_TARGET_UPDATE
);
16145 TREE_TYPE (stmt
) = void_type_node
;
16146 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
16147 SET_EXPR_LOCATION (stmt
, loc
);
16153 # pragma omp target enter data target-data-clause[optseq] new-line */
16155 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
16156 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16157 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16158 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16159 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16160 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16163 c_parser_omp_target_enter_data (location_t loc
, c_parser
*parser
,
16164 enum pragma_context context
)
16166 bool data_seen
= false;
16167 if (c_parser_next_token_is (parser
, CPP_NAME
))
16169 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16170 if (strcmp (p
, "data") == 0)
16172 c_parser_consume_token (parser
);
16178 c_parser_error (parser
, "expected %<data%>");
16179 c_parser_skip_to_pragma_eol (parser
);
16183 if (context
== pragma_stmt
)
16186 "%<#pragma omp target enter data%> may only be "
16187 "used in compound statements");
16188 c_parser_skip_to_pragma_eol (parser
, false);
16193 = c_parser_omp_all_clauses (parser
, OMP_TARGET_ENTER_DATA_CLAUSE_MASK
,
16194 "#pragma omp target enter data");
16196 for (tree
*pc
= &clauses
; *pc
;)
16198 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16199 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16202 case GOMP_MAP_ALWAYS_TO
:
16203 case GOMP_MAP_ALLOC
:
16206 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16207 case GOMP_MAP_ALWAYS_POINTER
:
16211 error_at (OMP_CLAUSE_LOCATION (*pc
),
16212 "%<#pragma omp target enter data%> with map-type other "
16213 "than %<to%> or %<alloc%> on %<map%> clause");
16214 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16217 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16224 "%<#pragma omp target enter data%> must contain at least "
16225 "one %<map%> clause");
16229 tree stmt
= make_node (OMP_TARGET_ENTER_DATA
);
16230 TREE_TYPE (stmt
) = void_type_node
;
16231 OMP_TARGET_ENTER_DATA_CLAUSES (stmt
) = clauses
;
16232 SET_EXPR_LOCATION (stmt
, loc
);
16238 # pragma omp target exit data target-data-clause[optseq] new-line */
16240 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
16241 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16242 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16243 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16244 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16245 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16248 c_parser_omp_target_exit_data (location_t loc
, c_parser
*parser
,
16249 enum pragma_context context
)
16251 bool data_seen
= false;
16252 if (c_parser_next_token_is (parser
, CPP_NAME
))
16254 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16255 if (strcmp (p
, "data") == 0)
16257 c_parser_consume_token (parser
);
16263 c_parser_error (parser
, "expected %<data%>");
16264 c_parser_skip_to_pragma_eol (parser
);
16268 if (context
== pragma_stmt
)
16271 "%<#pragma omp target exit data%> may only be "
16272 "used in compound statements");
16273 c_parser_skip_to_pragma_eol (parser
, false);
16278 = c_parser_omp_all_clauses (parser
, OMP_TARGET_EXIT_DATA_CLAUSE_MASK
,
16279 "#pragma omp target exit data");
16282 for (tree
*pc
= &clauses
; *pc
;)
16284 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16285 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16287 case GOMP_MAP_FROM
:
16288 case GOMP_MAP_ALWAYS_FROM
:
16289 case GOMP_MAP_RELEASE
:
16290 case GOMP_MAP_DELETE
:
16293 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16294 case GOMP_MAP_ALWAYS_POINTER
:
16298 error_at (OMP_CLAUSE_LOCATION (*pc
),
16299 "%<#pragma omp target exit data%> with map-type other "
16300 "than %<from%>, %<release%> or %<delete%> on %<map%>"
16302 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16305 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16312 "%<#pragma omp target exit data%> must contain at least one "
16317 tree stmt
= make_node (OMP_TARGET_EXIT_DATA
);
16318 TREE_TYPE (stmt
) = void_type_node
;
16319 OMP_TARGET_EXIT_DATA_CLAUSES (stmt
) = clauses
;
16320 SET_EXPR_LOCATION (stmt
, loc
);
16326 # pragma omp target target-clause[optseq] new-line
16327 structured-block */
16329 #define OMP_TARGET_CLAUSE_MASK \
16330 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16331 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16332 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16333 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16334 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
16335 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16336 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16337 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
16338 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
16341 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
16343 location_t loc
= c_parser_peek_token (parser
)->location
;
16344 c_parser_consume_pragma (parser
);
16345 tree
*pc
= NULL
, stmt
, block
;
16347 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
16349 c_parser_error (parser
, "expected declaration specifiers");
16350 c_parser_skip_to_pragma_eol (parser
);
16354 if (c_parser_next_token_is (parser
, CPP_NAME
))
16356 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16357 enum tree_code ccode
= ERROR_MARK
;
16359 if (strcmp (p
, "teams") == 0)
16361 else if (strcmp (p
, "parallel") == 0)
16362 ccode
= OMP_PARALLEL
;
16363 else if (strcmp (p
, "simd") == 0)
16365 if (ccode
!= ERROR_MARK
)
16367 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
16368 char p_name
[sizeof ("#pragma omp target teams distribute "
16369 "parallel for simd")];
16371 c_parser_consume_token (parser
);
16372 strcpy (p_name
, "#pragma omp target");
16373 if (!flag_openmp
) /* flag_openmp_simd */
16379 stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
16380 OMP_TARGET_CLAUSE_MASK
,
16384 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
,
16385 OMP_TARGET_CLAUSE_MASK
,
16389 stmt
= c_parser_omp_simd (loc
, parser
, p_name
,
16390 OMP_TARGET_CLAUSE_MASK
,
16394 gcc_unreachable ();
16396 return stmt
!= NULL_TREE
;
16398 keep_next_level ();
16399 tree block
= c_begin_compound_stmt (true), ret
;
16403 ret
= c_parser_omp_teams (loc
, parser
, p_name
,
16404 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16408 ret
= c_parser_omp_parallel (loc
, parser
, p_name
,
16409 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16413 ret
= c_parser_omp_simd (loc
, parser
, p_name
,
16414 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16418 gcc_unreachable ();
16420 block
= c_end_compound_stmt (loc
, block
, true);
16421 if (ret
== NULL_TREE
)
16423 if (ccode
== OMP_TEAMS
)
16425 /* For combined target teams, ensure the num_teams and
16426 thread_limit clause expressions are evaluated on the host,
16427 before entering the target construct. */
16429 for (c
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16430 c
; c
= OMP_CLAUSE_CHAIN (c
))
16431 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
16432 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
16433 && TREE_CODE (OMP_CLAUSE_OPERAND (c
, 0)) != INTEGER_CST
)
16435 tree expr
= OMP_CLAUSE_OPERAND (c
, 0);
16436 tree tmp
= create_tmp_var_raw (TREE_TYPE (expr
));
16437 expr
= build4 (TARGET_EXPR
, TREE_TYPE (expr
), tmp
,
16438 expr
, NULL_TREE
, NULL_TREE
);
16440 OMP_CLAUSE_OPERAND (c
, 0) = expr
;
16441 tree tc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
16442 OMP_CLAUSE_FIRSTPRIVATE
);
16443 OMP_CLAUSE_DECL (tc
) = tmp
;
16444 OMP_CLAUSE_CHAIN (tc
)
16445 = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
16446 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = tc
;
16449 tree stmt
= make_node (OMP_TARGET
);
16450 TREE_TYPE (stmt
) = void_type_node
;
16451 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
16452 OMP_TARGET_BODY (stmt
) = block
;
16453 OMP_TARGET_COMBINED (stmt
) = 1;
16455 pc
= &OMP_TARGET_CLAUSES (stmt
);
16456 goto check_clauses
;
16458 else if (!flag_openmp
) /* flag_openmp_simd */
16460 c_parser_skip_to_pragma_eol (parser
, false);
16463 else if (strcmp (p
, "data") == 0)
16465 c_parser_consume_token (parser
);
16466 c_parser_omp_target_data (loc
, parser
, if_p
);
16469 else if (strcmp (p
, "enter") == 0)
16471 c_parser_consume_token (parser
);
16472 c_parser_omp_target_enter_data (loc
, parser
, context
);
16475 else if (strcmp (p
, "exit") == 0)
16477 c_parser_consume_token (parser
);
16478 c_parser_omp_target_exit_data (loc
, parser
, context
);
16481 else if (strcmp (p
, "update") == 0)
16483 c_parser_consume_token (parser
);
16484 return c_parser_omp_target_update (loc
, parser
, context
);
16487 if (!flag_openmp
) /* flag_openmp_simd */
16489 c_parser_skip_to_pragma_eol (parser
, false);
16493 stmt
= make_node (OMP_TARGET
);
16494 TREE_TYPE (stmt
) = void_type_node
;
16496 OMP_TARGET_CLAUSES (stmt
)
16497 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
16498 "#pragma omp target");
16499 pc
= &OMP_TARGET_CLAUSES (stmt
);
16500 keep_next_level ();
16501 block
= c_begin_compound_stmt (true);
16502 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
16503 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
16505 SET_EXPR_LOCATION (stmt
, loc
);
16511 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16512 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16515 case GOMP_MAP_ALWAYS_TO
:
16516 case GOMP_MAP_FROM
:
16517 case GOMP_MAP_ALWAYS_FROM
:
16518 case GOMP_MAP_TOFROM
:
16519 case GOMP_MAP_ALWAYS_TOFROM
:
16520 case GOMP_MAP_ALLOC
:
16521 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16522 case GOMP_MAP_ALWAYS_POINTER
:
16525 error_at (OMP_CLAUSE_LOCATION (*pc
),
16526 "%<#pragma omp target%> with map-type other "
16527 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16528 "on %<map%> clause");
16529 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16532 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16538 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
16540 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
16541 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
16542 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
16543 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
16544 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
16545 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
16546 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
16549 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
16551 auto_vec
<c_token
> clauses
;
16552 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16554 c_token
*token
= c_parser_peek_token (parser
);
16555 if (token
->type
== CPP_EOF
)
16557 c_parser_skip_to_pragma_eol (parser
);
16560 clauses
.safe_push (*token
);
16561 c_parser_consume_token (parser
);
16563 clauses
.safe_push (*c_parser_peek_token (parser
));
16564 c_parser_skip_to_pragma_eol (parser
);
16566 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
16568 if (c_parser_peek_token (parser
)->pragma_kind
16569 != PRAGMA_OMP_DECLARE
16570 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
16571 || strcmp (IDENTIFIER_POINTER
16572 (c_parser_peek_2nd_token (parser
)->value
),
16575 c_parser_error (parser
,
16576 "%<#pragma omp declare simd%> must be followed by "
16577 "function declaration or definition or another "
16578 "%<#pragma omp declare simd%>");
16581 c_parser_consume_pragma (parser
);
16582 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16584 c_token
*token
= c_parser_peek_token (parser
);
16585 if (token
->type
== CPP_EOF
)
16587 c_parser_skip_to_pragma_eol (parser
);
16590 clauses
.safe_push (*token
);
16591 c_parser_consume_token (parser
);
16593 clauses
.safe_push (*c_parser_peek_token (parser
));
16594 c_parser_skip_to_pragma_eol (parser
);
16597 /* Make sure nothing tries to read past the end of the tokens. */
16599 memset (&eof_token
, 0, sizeof (eof_token
));
16600 eof_token
.type
= CPP_EOF
;
16601 clauses
.safe_push (eof_token
);
16602 clauses
.safe_push (eof_token
);
16606 case pragma_external
:
16607 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16608 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
16610 int ext
= disable_extension_diagnostics ();
16612 c_parser_consume_token (parser
);
16613 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16614 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
16615 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
16617 restore_extension_diagnostics (ext
);
16620 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
16623 case pragma_struct
:
16625 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
16626 "function declaration or definition");
16628 case pragma_compound
:
16630 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16631 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
16633 int ext
= disable_extension_diagnostics ();
16635 c_parser_consume_token (parser
);
16636 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16637 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
16638 if (c_parser_next_tokens_start_declaration (parser
))
16640 c_parser_declaration_or_fndef (parser
, true, true, true, true,
16641 true, NULL
, clauses
);
16642 restore_extension_diagnostics (ext
);
16645 restore_extension_diagnostics (ext
);
16647 else if (c_parser_next_tokens_start_declaration (parser
))
16649 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
16653 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
16654 "function declaration or definition");
16657 gcc_unreachable ();
16661 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
16662 and put that into "omp declare simd" attribute. */
16665 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
16666 vec
<c_token
> clauses
)
16669 && (clauses
.exists ()
16670 || lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl
)))
16671 && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16673 error ("%<#pragma omp declare simd%> or %<simd%> attribute cannot be "
16674 "used in the same function marked as a Cilk Plus SIMD-enabled "
16676 vec_free (parser
->cilk_simd_fn_tokens
);
16680 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
16681 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
16682 has already processed the tokens. */
16683 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
16685 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
16687 error ("%<#pragma omp declare simd%> not immediately followed by "
16688 "a function declaration or definition");
16689 clauses
[0].type
= CPP_EOF
;
16692 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
16694 error_at (DECL_SOURCE_LOCATION (fndecl
),
16695 "%<#pragma omp declare simd%> not immediately followed by "
16696 "a single function declaration or definition");
16697 clauses
[0].type
= CPP_EOF
;
16701 if (parms
== NULL_TREE
)
16702 parms
= DECL_ARGUMENTS (fndecl
);
16704 unsigned int tokens_avail
= parser
->tokens_avail
;
16705 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
16706 bool is_cilkplus_cilk_simd_fn
= false;
16708 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16710 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
16711 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
16712 is_cilkplus_cilk_simd_fn
= true;
16714 if (lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl
)) != NULL
)
16716 error_at (DECL_SOURCE_LOCATION (fndecl
),
16717 "%<__simd__%> attribute cannot be used in the same "
16718 "function marked as a Cilk Plus SIMD-enabled function");
16719 vec_free (parser
->cilk_simd_fn_tokens
);
16726 parser
->tokens
= clauses
.address ();
16727 parser
->tokens_avail
= clauses
.length ();
16730 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
16731 while (parser
->tokens_avail
> 3)
16733 c_token
*token
= c_parser_peek_token (parser
);
16734 if (!is_cilkplus_cilk_simd_fn
)
16735 gcc_assert (token
->type
== CPP_NAME
16736 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
16738 gcc_assert (token
->type
== CPP_NAME
16739 && is_cilkplus_vector_p (token
->value
));
16740 c_parser_consume_token (parser
);
16741 parser
->in_pragma
= true;
16743 tree c
= NULL_TREE
;
16744 if (is_cilkplus_cilk_simd_fn
)
16745 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
16746 "SIMD-enabled functions attribute");
16748 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
16749 "#pragma omp declare simd");
16750 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
16751 if (c
!= NULL_TREE
)
16752 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
16753 if (is_cilkplus_cilk_simd_fn
)
16755 tree k
= build_tree_list (get_identifier ("cilk simd function"),
16757 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
16758 DECL_ATTRIBUTES (fndecl
) = k
;
16760 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
16761 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
16762 DECL_ATTRIBUTES (fndecl
) = c
;
16765 parser
->tokens
= &parser
->tokens_buf
[0];
16766 parser
->tokens_avail
= tokens_avail
;
16767 if (clauses
.exists ())
16768 clauses
[0].type
= CPP_PRAGMA
;
16770 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16771 vec_free (parser
->cilk_simd_fn_tokens
);
16776 # pragma omp declare target new-line
16777 declarations and definitions
16778 # pragma omp end declare target new-line
16781 # pragma omp declare target ( extended-list ) new-line
16783 # pragma omp declare target declare-target-clauses[seq] new-line */
16785 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
16786 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16787 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
16790 c_parser_omp_declare_target (c_parser
*parser
)
16792 location_t loc
= c_parser_peek_token (parser
)->location
;
16793 tree clauses
= NULL_TREE
;
16794 if (c_parser_next_token_is (parser
, CPP_NAME
))
16795 clauses
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_TARGET_CLAUSE_MASK
,
16796 "#pragma omp declare target");
16797 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
16799 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
16801 clauses
= c_finish_omp_clauses (clauses
, C_ORT_OMP
);
16802 c_parser_skip_to_pragma_eol (parser
);
16806 c_parser_skip_to_pragma_eol (parser
);
16807 current_omp_declare_target_attribute
++;
16810 if (current_omp_declare_target_attribute
)
16811 error_at (loc
, "%<#pragma omp declare target%> with clauses in between "
16812 "%<#pragma omp declare target%> without clauses and "
16813 "%<#pragma omp end declare target%>");
16814 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
16816 tree t
= OMP_CLAUSE_DECL (c
), id
;
16817 tree at1
= lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t
));
16818 tree at2
= lookup_attribute ("omp declare target link",
16819 DECL_ATTRIBUTES (t
));
16820 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINK
)
16822 id
= get_identifier ("omp declare target link");
16823 std::swap (at1
, at2
);
16826 id
= get_identifier ("omp declare target");
16829 error_at (OMP_CLAUSE_LOCATION (c
),
16830 "%qD specified both in declare target %<link%> and %<to%>"
16836 DECL_ATTRIBUTES (t
) = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (t
));
16837 if (TREE_CODE (t
) != FUNCTION_DECL
&& !is_global_var (t
))
16840 symtab_node
*node
= symtab_node::get (t
);
16843 node
->offloadable
= 1;
16844 if (ENABLE_OFFLOADING
)
16846 g
->have_offload
= true;
16847 if (is_a
<varpool_node
*> (node
))
16848 vec_safe_push (offload_vars
, t
);
16856 c_parser_omp_end_declare_target (c_parser
*parser
)
16858 location_t loc
= c_parser_peek_token (parser
)->location
;
16859 c_parser_consume_pragma (parser
);
16860 if (c_parser_next_token_is (parser
, CPP_NAME
)
16861 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
16864 c_parser_consume_token (parser
);
16865 if (c_parser_next_token_is (parser
, CPP_NAME
)
16866 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
16868 c_parser_consume_token (parser
);
16871 c_parser_error (parser
, "expected %<target%>");
16872 c_parser_skip_to_pragma_eol (parser
);
16878 c_parser_error (parser
, "expected %<declare%>");
16879 c_parser_skip_to_pragma_eol (parser
);
16882 c_parser_skip_to_pragma_eol (parser
);
16883 if (!current_omp_declare_target_attribute
)
16884 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
16885 "%<#pragma omp declare target%>");
16887 current_omp_declare_target_attribute
--;
16892 #pragma omp declare reduction (reduction-id : typename-list : expression) \
16893 initializer-clause[opt] new-line
16895 initializer-clause:
16896 initializer (omp_priv = initializer)
16897 initializer (function-name (argument-list)) */
16900 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
16902 unsigned int tokens_avail
= 0, i
;
16903 vec
<tree
> types
= vNULL
;
16904 vec
<c_token
> clauses
= vNULL
;
16905 enum tree_code reduc_code
= ERROR_MARK
;
16906 tree reduc_id
= NULL_TREE
;
16908 location_t rloc
= c_parser_peek_token (parser
)->location
;
16910 if (context
== pragma_struct
|| context
== pragma_param
)
16912 error ("%<#pragma omp declare reduction%> not at file or block scope");
16916 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
16919 switch (c_parser_peek_token (parser
)->type
)
16922 reduc_code
= PLUS_EXPR
;
16925 reduc_code
= MULT_EXPR
;
16928 reduc_code
= MINUS_EXPR
;
16931 reduc_code
= BIT_AND_EXPR
;
16934 reduc_code
= BIT_XOR_EXPR
;
16937 reduc_code
= BIT_IOR_EXPR
;
16940 reduc_code
= TRUTH_ANDIF_EXPR
;
16943 reduc_code
= TRUTH_ORIF_EXPR
;
16947 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16948 if (strcmp (p
, "min") == 0)
16950 reduc_code
= MIN_EXPR
;
16953 if (strcmp (p
, "max") == 0)
16955 reduc_code
= MAX_EXPR
;
16958 reduc_id
= c_parser_peek_token (parser
)->value
;
16961 c_parser_error (parser
,
16962 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
16963 "%<^%>, %<|%>, %<&&%>, %<||%> or identifier");
16967 tree orig_reduc_id
, reduc_decl
;
16968 orig_reduc_id
= reduc_id
;
16969 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
16970 reduc_decl
= c_omp_reduction_decl (reduc_id
);
16971 c_parser_consume_token (parser
);
16973 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
16978 location_t loc
= c_parser_peek_token (parser
)->location
;
16979 struct c_type_name
*ctype
= c_parser_type_name (parser
);
16982 type
= groktypename (ctype
, NULL
, NULL
);
16983 if (type
== error_mark_node
)
16985 else if ((INTEGRAL_TYPE_P (type
)
16986 || TREE_CODE (type
) == REAL_TYPE
16987 || TREE_CODE (type
) == COMPLEX_TYPE
)
16988 && orig_reduc_id
== NULL_TREE
)
16989 error_at (loc
, "predeclared arithmetic type in "
16990 "%<#pragma omp declare reduction%>");
16991 else if (TREE_CODE (type
) == FUNCTION_TYPE
16992 || TREE_CODE (type
) == ARRAY_TYPE
)
16993 error_at (loc
, "function or array type in "
16994 "%<#pragma omp declare reduction%>");
16995 else if (TYPE_ATOMIC (type
))
16996 error_at (loc
, "%<_Atomic%> qualified type in "
16997 "%<#pragma omp declare reduction%>");
16998 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
16999 error_at (loc
, "const, volatile or restrict qualified type in "
17000 "%<#pragma omp declare reduction%>");
17004 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
17005 if (comptypes (TREE_PURPOSE (t
), type
))
17007 error_at (loc
, "redeclaration of %qs "
17008 "%<#pragma omp declare reduction%> for "
17010 IDENTIFIER_POINTER (reduc_id
)
17011 + sizeof ("omp declare reduction ") - 1,
17014 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
17016 error_at (ploc
, "previous %<#pragma omp declare "
17020 if (t
== NULL_TREE
)
17021 types
.safe_push (type
);
17023 if (c_parser_next_token_is (parser
, CPP_COMMA
))
17024 c_parser_consume_token (parser
);
17032 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
17033 || types
.is_empty ())
17036 clauses
.release ();
17040 c_token
*token
= c_parser_peek_token (parser
);
17041 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
17043 c_parser_consume_token (parser
);
17045 c_parser_skip_to_pragma_eol (parser
);
17049 if (types
.length () > 1)
17051 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17053 c_token
*token
= c_parser_peek_token (parser
);
17054 if (token
->type
== CPP_EOF
)
17056 clauses
.safe_push (*token
);
17057 c_parser_consume_token (parser
);
17059 clauses
.safe_push (*c_parser_peek_token (parser
));
17060 c_parser_skip_to_pragma_eol (parser
);
17062 /* Make sure nothing tries to read past the end of the tokens. */
17064 memset (&eof_token
, 0, sizeof (eof_token
));
17065 eof_token
.type
= CPP_EOF
;
17066 clauses
.safe_push (eof_token
);
17067 clauses
.safe_push (eof_token
);
17070 int errs
= errorcount
;
17071 FOR_EACH_VEC_ELT (types
, i
, type
)
17073 tokens_avail
= parser
->tokens_avail
;
17074 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
17075 if (!clauses
.is_empty ())
17077 parser
->tokens
= clauses
.address ();
17078 parser
->tokens_avail
= clauses
.length ();
17079 parser
->in_pragma
= true;
17082 bool nested
= current_function_decl
!= NULL_TREE
;
17084 c_push_function_context ();
17085 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
17086 reduc_id
, default_function_type
);
17087 current_function_decl
= fndecl
;
17088 allocate_struct_function (fndecl
, true);
17090 tree stmt
= push_stmt_list ();
17091 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
17092 warn about these. */
17093 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17094 get_identifier ("omp_out"), type
);
17095 DECL_ARTIFICIAL (omp_out
) = 1;
17096 DECL_CONTEXT (omp_out
) = fndecl
;
17097 pushdecl (omp_out
);
17098 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17099 get_identifier ("omp_in"), type
);
17100 DECL_ARTIFICIAL (omp_in
) = 1;
17101 DECL_CONTEXT (omp_in
) = fndecl
;
17103 struct c_expr combiner
= c_parser_expression (parser
);
17104 struct c_expr initializer
;
17105 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
17107 initializer
.value
= error_mark_node
;
17108 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17110 else if (c_parser_next_token_is (parser
, CPP_NAME
)
17111 && strcmp (IDENTIFIER_POINTER
17112 (c_parser_peek_token (parser
)->value
),
17113 "initializer") == 0)
17115 c_parser_consume_token (parser
);
17118 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17119 get_identifier ("omp_priv"), type
);
17120 DECL_ARTIFICIAL (omp_priv
) = 1;
17121 DECL_INITIAL (omp_priv
) = error_mark_node
;
17122 DECL_CONTEXT (omp_priv
) = fndecl
;
17123 pushdecl (omp_priv
);
17124 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17125 get_identifier ("omp_orig"), type
);
17126 DECL_ARTIFICIAL (omp_orig
) = 1;
17127 DECL_CONTEXT (omp_orig
) = fndecl
;
17128 pushdecl (omp_orig
);
17129 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17131 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
17133 c_parser_error (parser
, "expected %<omp_priv%> or "
17137 else if (strcmp (IDENTIFIER_POINTER
17138 (c_parser_peek_token (parser
)->value
),
17141 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
17142 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
17144 c_parser_error (parser
, "expected function-name %<(%>");
17148 initializer
= c_parser_postfix_expression (parser
);
17149 if (initializer
.value
17150 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
17153 tree c
= initializer
.value
;
17154 for (j
= 0; j
< call_expr_nargs (c
); j
++)
17156 tree a
= CALL_EXPR_ARG (c
, j
);
17158 if (TREE_CODE (a
) == ADDR_EXPR
17159 && TREE_OPERAND (a
, 0) == omp_priv
)
17162 if (j
== call_expr_nargs (c
))
17163 error ("one of the initializer call arguments should be "
17169 c_parser_consume_token (parser
);
17170 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
17174 tree st
= push_stmt_list ();
17175 location_t loc
= c_parser_peek_token (parser
)->location
;
17176 rich_location
richloc (line_table
, loc
);
17177 start_init (omp_priv
, NULL_TREE
, 0, &richloc
);
17178 struct c_expr init
= c_parser_initializer (parser
);
17180 finish_decl (omp_priv
, loc
, init
.value
,
17181 init
.original_type
, NULL_TREE
);
17182 pop_stmt_list (st
);
17186 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17192 c_parser_skip_to_pragma_eol (parser
);
17194 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
17195 DECL_INITIAL (reduc_decl
));
17196 DECL_INITIAL (reduc_decl
) = t
;
17197 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
17198 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
17199 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
17200 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
17201 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
17202 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
17205 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
17206 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
17207 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
17208 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
17209 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
17210 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17211 walk_tree (&DECL_INITIAL (omp_priv
),
17212 c_check_omp_declare_reduction_r
,
17213 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17217 pop_stmt_list (stmt
);
17219 if (cfun
->language
!= NULL
)
17221 ggc_free (cfun
->language
);
17222 cfun
->language
= NULL
;
17225 current_function_decl
= NULL_TREE
;
17227 c_pop_function_context ();
17229 if (!clauses
.is_empty ())
17231 parser
->tokens
= &parser
->tokens_buf
[0];
17232 parser
->tokens_avail
= tokens_avail
;
17236 if (errs
!= errorcount
)
17240 clauses
.release ();
17246 #pragma omp declare simd declare-simd-clauses[optseq] new-line
17247 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17248 initializer-clause[opt] new-line
17249 #pragma omp declare target new-line */
17252 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
17254 c_parser_consume_pragma (parser
);
17255 if (c_parser_next_token_is (parser
, CPP_NAME
))
17257 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17258 if (strcmp (p
, "simd") == 0)
17260 /* c_parser_consume_token (parser); done in
17261 c_parser_omp_declare_simd. */
17262 c_parser_omp_declare_simd (parser
, context
);
17265 if (strcmp (p
, "reduction") == 0)
17267 c_parser_consume_token (parser
);
17268 c_parser_omp_declare_reduction (parser
, context
);
17271 if (!flag_openmp
) /* flag_openmp_simd */
17273 c_parser_skip_to_pragma_eol (parser
, false);
17276 if (strcmp (p
, "target") == 0)
17278 c_parser_consume_token (parser
);
17279 c_parser_omp_declare_target (parser
);
17284 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
17286 c_parser_skip_to_pragma_eol (parser
);
17290 #pragma omp taskloop taskloop-clause[optseq] new-line
17293 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
17296 #define OMP_TASKLOOP_CLAUSE_MASK \
17297 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
17298 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17299 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17300 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
17301 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
17302 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
17303 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
17304 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
17305 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
17306 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17307 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
17308 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
17309 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
17310 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
17313 c_parser_omp_taskloop (location_t loc
, c_parser
*parser
,
17314 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17317 tree clauses
, block
, ret
;
17319 strcat (p_name
, " taskloop");
17320 mask
|= OMP_TASKLOOP_CLAUSE_MASK
;
17322 if (c_parser_next_token_is (parser
, CPP_NAME
))
17324 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17326 if (strcmp (p
, "simd") == 0)
17328 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17329 if (cclauses
== NULL
)
17330 cclauses
= cclauses_buf
;
17331 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_REDUCTION
);
17332 c_parser_consume_token (parser
);
17333 if (!flag_openmp
) /* flag_openmp_simd */
17334 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
17336 block
= c_begin_compound_stmt (true);
17337 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
17338 block
= c_end_compound_stmt (loc
, block
, true);
17341 ret
= make_node (OMP_TASKLOOP
);
17342 TREE_TYPE (ret
) = void_type_node
;
17343 OMP_FOR_BODY (ret
) = block
;
17344 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
17345 SET_EXPR_LOCATION (ret
, loc
);
17350 if (!flag_openmp
) /* flag_openmp_simd */
17352 c_parser_skip_to_pragma_eol (parser
, false);
17356 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17359 omp_split_clauses (loc
, OMP_TASKLOOP
, mask
, clauses
, cclauses
);
17360 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
17363 block
= c_begin_compound_stmt (true);
17364 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_TASKLOOP
, clauses
, NULL
, if_p
);
17365 block
= c_end_compound_stmt (loc
, block
, true);
17371 /* Main entry point to parsing most OpenMP pragmas. */
17374 c_parser_omp_construct (c_parser
*parser
, bool *if_p
)
17376 enum pragma_kind p_kind
;
17379 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
17380 omp_clause_mask
mask (0);
17382 loc
= c_parser_peek_token (parser
)->location
;
17383 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
17384 c_parser_consume_pragma (parser
);
17388 case PRAGMA_OACC_ATOMIC
:
17389 c_parser_omp_atomic (loc
, parser
);
17391 case PRAGMA_OACC_CACHE
:
17392 strcpy (p_name
, "#pragma acc");
17393 stmt
= c_parser_oacc_cache (loc
, parser
);
17395 case PRAGMA_OACC_DATA
:
17396 stmt
= c_parser_oacc_data (loc
, parser
, if_p
);
17398 case PRAGMA_OACC_HOST_DATA
:
17399 stmt
= c_parser_oacc_host_data (loc
, parser
, if_p
);
17401 case PRAGMA_OACC_KERNELS
:
17402 case PRAGMA_OACC_PARALLEL
:
17403 strcpy (p_name
, "#pragma acc");
17404 stmt
= c_parser_oacc_kernels_parallel (loc
, parser
, p_kind
, p_name
,
17407 case PRAGMA_OACC_LOOP
:
17408 strcpy (p_name
, "#pragma acc");
17409 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17411 case PRAGMA_OACC_WAIT
:
17412 strcpy (p_name
, "#pragma wait");
17413 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
17415 case PRAGMA_OMP_ATOMIC
:
17416 c_parser_omp_atomic (loc
, parser
);
17418 case PRAGMA_OMP_CRITICAL
:
17419 stmt
= c_parser_omp_critical (loc
, parser
, if_p
);
17421 case PRAGMA_OMP_DISTRIBUTE
:
17422 strcpy (p_name
, "#pragma omp");
17423 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17425 case PRAGMA_OMP_FOR
:
17426 strcpy (p_name
, "#pragma omp");
17427 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17429 case PRAGMA_OMP_MASTER
:
17430 stmt
= c_parser_omp_master (loc
, parser
, if_p
);
17432 case PRAGMA_OMP_PARALLEL
:
17433 strcpy (p_name
, "#pragma omp");
17434 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17436 case PRAGMA_OMP_SECTIONS
:
17437 strcpy (p_name
, "#pragma omp");
17438 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
17440 case PRAGMA_OMP_SIMD
:
17441 strcpy (p_name
, "#pragma omp");
17442 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17444 case PRAGMA_OMP_SINGLE
:
17445 stmt
= c_parser_omp_single (loc
, parser
, if_p
);
17447 case PRAGMA_OMP_TASK
:
17448 stmt
= c_parser_omp_task (loc
, parser
, if_p
);
17450 case PRAGMA_OMP_TASKGROUP
:
17451 stmt
= c_parser_omp_taskgroup (parser
, if_p
);
17453 case PRAGMA_OMP_TASKLOOP
:
17454 strcpy (p_name
, "#pragma omp");
17455 stmt
= c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17457 case PRAGMA_OMP_TEAMS
:
17458 strcpy (p_name
, "#pragma omp");
17459 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17462 gcc_unreachable ();
17466 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
17471 # pragma omp threadprivate (variable-list) */
17474 c_parser_omp_threadprivate (c_parser
*parser
)
17479 c_parser_consume_pragma (parser
);
17480 loc
= c_parser_peek_token (parser
)->location
;
17481 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
17483 /* Mark every variable in VARS to be assigned thread local storage. */
17484 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
17486 tree v
= TREE_PURPOSE (t
);
17488 /* FIXME diagnostics: Ideally we should keep individual
17489 locations for all the variables in the var list to make the
17490 following errors more precise. Perhaps
17491 c_parser_omp_var_list_parens() should construct a list of
17492 locations to go along with the var list. */
17494 /* If V had already been marked threadprivate, it doesn't matter
17495 whether it had been used prior to this point. */
17497 error_at (loc
, "%qD is not a variable", v
);
17498 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
17499 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
17500 else if (! is_global_var (v
))
17501 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
17502 else if (TREE_TYPE (v
) == error_mark_node
)
17504 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
17505 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
17508 if (! DECL_THREAD_LOCAL_P (v
))
17510 set_decl_tls_model (v
, decl_default_tls_model (v
));
17511 /* If rtl has been already set for this var, call
17512 make_decl_rtl once again, so that encode_section_info
17513 has a chance to look at the new decl flags. */
17514 if (DECL_RTL_SET_P (v
))
17517 C_DECL_THREADPRIVATE_P (v
) = 1;
17521 c_parser_skip_to_pragma_eol (parser
);
17524 /* Cilk Plus <#pragma simd> parsing routines. */
17526 /* Helper function for c_parser_pragma. Perform some sanity checking
17527 for <#pragma simd> constructs. Returns FALSE if there was a
17531 c_parser_cilk_verify_simd (c_parser
*parser
,
17532 enum pragma_context context
)
17534 if (!flag_cilkplus
)
17536 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
17537 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
17540 if (context
== pragma_external
)
17542 c_parser_error (parser
,"pragma simd must be inside a function");
17543 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
17550 This function is shared by SIMD-enabled functions and #pragma simd.
17551 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
17552 CLAUSES is unused. The main purpose of this function is to parse a
17553 vectorlength attribute or clause and check for parse errors.
17554 When IS_SIMD_FN is true then the function is merely caching the tokens
17555 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
17556 cache is cleared since there is no reason to continue.
17558 vectorlength ( constant-expression ) */
17561 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
17565 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
17567 /* The vectorlength clause behaves exactly like OpenMP's safelen
17568 clause. Represent it in OpenMP terms. */
17569 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
17571 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17574 location_t loc
= c_parser_peek_token (parser
)->location
;
17575 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
17576 expr
= c_fully_fold (expr
, false, NULL
);
17578 /* If expr is an error_mark_node then the above function would have
17579 emitted an error. No reason to do it twice. */
17580 if (expr
== error_mark_node
)
17582 else if (!TREE_TYPE (expr
)
17583 || !TREE_CONSTANT (expr
)
17584 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
17586 error_at (loc
, "vectorlength must be an integer constant");
17587 else if (wi::exact_log2 (expr
) == -1)
17588 error_at (loc
, "vectorlength must be a power of 2");
17593 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
17594 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
17595 OMP_CLAUSE_CHAIN (u
) = clauses
;
17600 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
17601 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
17602 OMP_CLAUSE_CHAIN (u
) = clauses
;
17607 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
17613 linear ( simd-linear-variable-list )
17615 simd-linear-variable-list:
17616 simd-linear-variable
17617 simd-linear-variable-list , simd-linear-variable
17619 simd-linear-variable:
17621 id-expression : simd-linear-step
17624 conditional-expression */
17627 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
17629 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17632 location_t loc
= c_parser_peek_token (parser
)->location
;
17634 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
17635 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
17636 c_parser_error (parser
, "expected identifier");
17638 while (c_parser_next_token_is (parser
, CPP_NAME
)
17639 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
17641 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
17645 undeclared_variable (c_parser_peek_token (parser
)->location
,
17646 c_parser_peek_token (parser
)->value
);
17647 c_parser_consume_token (parser
);
17649 else if (var
== error_mark_node
)
17650 c_parser_consume_token (parser
);
17653 tree step
= integer_one_node
;
17655 /* Parse the linear step if present. */
17656 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
17658 c_parser_consume_token (parser
);
17659 c_parser_consume_token (parser
);
17661 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
17662 expr
= c_fully_fold (expr
, false, NULL
);
17664 if (TREE_TYPE (expr
)
17665 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
17666 && (TREE_CONSTANT (expr
)
17670 c_parser_error (parser
,
17671 "step size must be an integer constant "
17672 "expression or an integer variable");
17675 c_parser_consume_token (parser
);
17677 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
17678 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
17679 OMP_CLAUSE_DECL (u
) = var
;
17680 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
17681 OMP_CLAUSE_CHAIN (u
) = clauses
;
17685 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
17688 c_parser_consume_token (parser
);
17691 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
17696 /* Returns the name of the next clause. If the clause is not
17697 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
17698 not consumed. Otherwise, the appropriate pragma_simd_clause is
17699 returned and the token is consumed. */
17701 static pragma_omp_clause
17702 c_parser_cilk_clause_name (c_parser
*parser
)
17704 pragma_omp_clause result
;
17705 c_token
*token
= c_parser_peek_token (parser
);
17707 if (!token
->value
|| token
->type
!= CPP_NAME
)
17708 return PRAGMA_CILK_CLAUSE_NONE
;
17710 const char *p
= IDENTIFIER_POINTER (token
->value
);
17712 if (!strcmp (p
, "vectorlength"))
17713 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
17714 else if (!strcmp (p
, "linear"))
17715 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
17716 else if (!strcmp (p
, "private"))
17717 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
17718 else if (!strcmp (p
, "firstprivate"))
17719 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
17720 else if (!strcmp (p
, "lastprivate"))
17721 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
17722 else if (!strcmp (p
, "reduction"))
17723 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
17725 return PRAGMA_CILK_CLAUSE_NONE
;
17727 c_parser_consume_token (parser
);
17731 /* Parse all #<pragma simd> clauses. Return the list of clauses
17735 c_parser_cilk_all_clauses (c_parser
*parser
)
17737 tree clauses
= NULL
;
17739 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17741 pragma_omp_clause c_kind
;
17743 c_kind
= c_parser_cilk_clause_name (parser
);
17747 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
17748 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
17750 case PRAGMA_CILK_CLAUSE_LINEAR
:
17751 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
17753 case PRAGMA_CILK_CLAUSE_PRIVATE
:
17754 /* Use the OpenMP counterpart. */
17755 clauses
= c_parser_omp_clause_private (parser
, clauses
);
17757 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
17758 /* Use the OpenMP counterpart. */
17759 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
17761 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
17762 /* Use the OpenMP counterpart. */
17763 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
17765 case PRAGMA_CILK_CLAUSE_REDUCTION
:
17766 /* Use the OpenMP counterpart. */
17767 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
17770 c_parser_error (parser
, "expected %<#pragma simd%> clause");
17776 c_parser_skip_to_pragma_eol (parser
);
17777 return c_finish_omp_clauses (clauses
, C_ORT_CILK
);
17780 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
17781 Here is the correct syntax of this pragma:
17782 #pragma cilk grainsize = <EXP>
17786 c_parser_cilk_grainsize (c_parser
*parser
, bool *if_p
)
17788 extern tree
convert_to_integer (tree
, tree
);
17790 /* consume the 'grainsize' keyword. */
17791 c_parser_consume_pragma (parser
);
17793 if (c_parser_require (parser
, CPP_EQ
, "expected %<=%>") != 0)
17795 struct c_expr g_expr
= c_parser_binary_expression (parser
, NULL
, NULL
);
17796 if (g_expr
.value
== error_mark_node
)
17798 c_parser_skip_to_pragma_eol (parser
);
17801 tree grain
= convert_to_integer (long_integer_type_node
,
17802 c_fully_fold (g_expr
.value
, false,
17804 c_parser_skip_to_pragma_eol (parser
);
17805 c_token
*token
= c_parser_peek_token (parser
);
17806 if (token
&& token
->type
== CPP_KEYWORD
17807 && token
->keyword
== RID_CILK_FOR
)
17809 if (grain
== NULL_TREE
|| grain
== error_mark_node
)
17810 grain
= integer_zero_node
;
17811 c_parser_cilk_for (parser
, grain
, if_p
);
17814 warning (0, "%<#pragma cilk grainsize%> is not followed by "
17818 c_parser_skip_to_pragma_eol (parser
);
17821 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
17824 c_parser_cilk_simd (c_parser
*parser
, bool *if_p
)
17826 tree clauses
= c_parser_cilk_all_clauses (parser
);
17827 tree block
= c_begin_compound_stmt (true);
17828 location_t loc
= c_parser_peek_token (parser
)->location
;
17829 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
, if_p
);
17830 block
= c_end_compound_stmt (loc
, block
, true);
17834 /* Create an artificial decl with TYPE and emit initialization of it with
17838 c_get_temp_regvar (tree type
, tree init
)
17840 location_t loc
= EXPR_LOCATION (init
);
17841 tree decl
= build_decl (loc
, VAR_DECL
, NULL_TREE
, type
);
17842 DECL_ARTIFICIAL (decl
) = 1;
17843 DECL_IGNORED_P (decl
) = 1;
17845 tree t
= build2 (INIT_EXPR
, type
, decl
, init
);
17850 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
17851 GRAIN is the grain value passed in through pragma or 0. */
17854 c_parser_cilk_for (c_parser
*parser
, tree grain
, bool *if_p
)
17856 tree clauses
= build_omp_clause (EXPR_LOCATION (grain
), OMP_CLAUSE_SCHEDULE
);
17857 OMP_CLAUSE_SCHEDULE_KIND (clauses
) = OMP_CLAUSE_SCHEDULE_CILKFOR
;
17858 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses
) = grain
;
17859 clauses
= c_finish_omp_clauses (clauses
, C_ORT_CILK
);
17861 tree block
= c_begin_compound_stmt (true);
17862 tree sb
= push_stmt_list ();
17863 location_t loc
= c_parser_peek_token (parser
)->location
;
17864 tree omp_for
= c_parser_omp_for_loop (loc
, parser
, CILK_FOR
, clauses
, NULL
,
17866 sb
= pop_stmt_list (sb
);
17870 tree omp_par
= make_node (OMP_PARALLEL
);
17871 TREE_TYPE (omp_par
) = void_type_node
;
17872 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
17873 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
17874 TREE_SIDE_EFFECTS (bind
) = 1;
17875 BIND_EXPR_BODY (bind
) = sb
;
17876 OMP_PARALLEL_BODY (omp_par
) = bind
;
17877 if (OMP_FOR_PRE_BODY (omp_for
))
17879 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
17880 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
17882 tree init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
17883 tree decl
= TREE_OPERAND (init
, 0);
17884 tree cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
17885 tree incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
17886 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
= NULL_TREE
;
17887 if (TREE_CODE (t
) != INTEGER_CST
)
17889 TREE_OPERAND (cond
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
17890 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
17891 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
17892 OMP_CLAUSE_CHAIN (c
) = clauses
;
17895 if (TREE_CODE (incr
) == MODIFY_EXPR
)
17897 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
17898 if (TREE_CODE (t
) != INTEGER_CST
)
17900 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
17901 = c_get_temp_regvar (TREE_TYPE (t
), t
);
17902 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
17903 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
17904 OMP_CLAUSE_CHAIN (c
) = clauses
;
17908 t
= TREE_OPERAND (init
, 1);
17909 if (TREE_CODE (t
) != INTEGER_CST
)
17911 TREE_OPERAND (init
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
17912 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
17913 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
17914 OMP_CLAUSE_CHAIN (c
) = clauses
;
17917 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
17918 OMP_CLAUSE_DECL (c
) = decl
;
17919 OMP_CLAUSE_CHAIN (c
) = clauses
;
17921 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
17922 OMP_CLAUSE_OPERAND (c
, 0)
17923 = cilk_for_number_of_iterations (omp_for
);
17924 OMP_CLAUSE_CHAIN (c
) = clauses
;
17925 OMP_PARALLEL_CLAUSES (omp_par
) = c_finish_omp_clauses (c
, C_ORT_CILK
);
17926 add_stmt (omp_par
);
17929 block
= c_end_compound_stmt (loc
, block
, true);
17934 /* Parse a transaction attribute (GCC Extension).
17936 transaction-attribute:
17940 The transactional memory language description is written for C++,
17941 and uses the C++0x attribute syntax. For compatibility, allow the
17942 bracket style for transactions in C as well. */
17945 c_parser_transaction_attributes (c_parser
*parser
)
17947 tree attr_name
, attr
= NULL
;
17949 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
17950 return c_parser_attributes (parser
);
17952 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
17954 c_parser_consume_token (parser
);
17955 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
17958 attr_name
= c_parser_attribute_any_word (parser
);
17961 c_parser_consume_token (parser
);
17962 attr
= build_tree_list (attr_name
, NULL_TREE
);
17965 c_parser_error (parser
, "expected identifier");
17967 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
17969 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
17973 /* Parse a __transaction_atomic or __transaction_relaxed statement
17976 transaction-statement:
17977 __transaction_atomic transaction-attribute[opt] compound-statement
17978 __transaction_relaxed compound-statement
17980 Note that the only valid attribute is: "outer".
17984 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
17986 unsigned int old_in
= parser
->in_transaction
;
17987 unsigned int this_in
= 1, new_in
;
17988 location_t loc
= c_parser_peek_token (parser
)->location
;
17991 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
17992 || keyword
== RID_TRANSACTION_RELAXED
)
17993 && c_parser_next_token_is_keyword (parser
, keyword
));
17994 c_parser_consume_token (parser
);
17996 if (keyword
== RID_TRANSACTION_RELAXED
)
17997 this_in
|= TM_STMT_ATTR_RELAXED
;
18000 attrs
= c_parser_transaction_attributes (parser
);
18002 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
18005 /* Keep track if we're in the lexical scope of an outer transaction. */
18006 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
18008 parser
->in_transaction
= new_in
;
18009 stmt
= c_parser_compound_statement (parser
);
18010 parser
->in_transaction
= old_in
;
18013 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
18015 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18016 "%<__transaction_atomic%> without transactional memory support enabled"
18017 : "%<__transaction_relaxed %> "
18018 "without transactional memory support enabled"));
18023 /* Parse a __transaction_atomic or __transaction_relaxed expression
18026 transaction-expression:
18027 __transaction_atomic ( expression )
18028 __transaction_relaxed ( expression )
18031 static struct c_expr
18032 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
18035 unsigned int old_in
= parser
->in_transaction
;
18036 unsigned int this_in
= 1;
18037 location_t loc
= c_parser_peek_token (parser
)->location
;
18040 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18041 || keyword
== RID_TRANSACTION_RELAXED
)
18042 && c_parser_next_token_is_keyword (parser
, keyword
));
18043 c_parser_consume_token (parser
);
18045 if (keyword
== RID_TRANSACTION_RELAXED
)
18046 this_in
|= TM_STMT_ATTR_RELAXED
;
18049 attrs
= c_parser_transaction_attributes (parser
);
18051 this_in
|= parse_tm_stmt_attr (attrs
, 0);
18054 parser
->in_transaction
= this_in
;
18055 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
18057 tree expr
= c_parser_expression (parser
).value
;
18058 ret
.original_type
= TREE_TYPE (expr
);
18059 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
18060 if (this_in
& TM_STMT_ATTR_RELAXED
)
18061 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
18062 SET_EXPR_LOCATION (ret
.value
, loc
);
18063 ret
.original_code
= TRANSACTION_EXPR
;
18064 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
18066 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
18073 ret
.value
= error_mark_node
;
18074 ret
.original_code
= ERROR_MARK
;
18075 ret
.original_type
= NULL
;
18077 parser
->in_transaction
= old_in
;
18080 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18081 "%<__transaction_atomic%> without transactional memory support enabled"
18082 : "%<__transaction_relaxed %> "
18083 "without transactional memory support enabled"));
18085 set_c_expr_source_range (&ret
, loc
, loc
);
18090 /* Parse a __transaction_cancel statement (GCC Extension).
18092 transaction-cancel-statement:
18093 __transaction_cancel transaction-attribute[opt] ;
18095 Note that the only valid attribute is "outer".
18099 c_parser_transaction_cancel (c_parser
*parser
)
18101 location_t loc
= c_parser_peek_token (parser
)->location
;
18103 bool is_outer
= false;
18105 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
18106 c_parser_consume_token (parser
);
18108 attrs
= c_parser_transaction_attributes (parser
);
18110 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
18114 error_at (loc
, "%<__transaction_cancel%> without "
18115 "transactional memory support enabled");
18118 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
18120 error_at (loc
, "%<__transaction_cancel%> within a "
18121 "%<__transaction_relaxed%>");
18126 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
18127 && !is_tm_may_cancel_outer (current_function_decl
))
18129 error_at (loc
, "outer %<__transaction_cancel%> not "
18130 "within outer %<__transaction_atomic%>");
18131 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
18135 else if (parser
->in_transaction
== 0)
18137 error_at (loc
, "%<__transaction_cancel%> not within "
18138 "%<__transaction_atomic%>");
18142 return add_stmt (build_tm_abort_call (loc
, is_outer
));
18145 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
18148 /* Parse a single source file. */
18151 c_parse_file (void)
18153 /* Use local storage to begin. If the first token is a pragma, parse it.
18154 If it is #pragma GCC pch_preprocess, then this will load a PCH file
18155 which will cause garbage collection. */
18158 memset (&tparser
, 0, sizeof tparser
);
18159 tparser
.tokens
= &tparser
.tokens_buf
[0];
18160 the_parser
= &tparser
;
18162 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
18163 c_parser_pragma_pch_preprocess (&tparser
);
18165 the_parser
= ggc_alloc
<c_parser
> ();
18166 *the_parser
= tparser
;
18167 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
18168 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
18170 /* Initialize EH, if we've been told to do so. */
18171 if (flag_exceptions
)
18172 using_eh_for_cleanups ();
18174 c_parser_translation_unit (the_parser
);
18178 /* This function parses Cilk Plus array notation. The starting index is
18179 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
18180 return value of this function is a tree_node called VALUE_TREE of type
18181 ARRAY_NOTATION_REF. */
18184 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
18187 c_token
*token
= NULL
;
18188 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
18189 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
18190 tree array_type_domain
= NULL_TREE
;
18192 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
18194 /* No need to continue. If either of these 2 were true, then an error
18195 must be emitted already. Thus, no need to emit them twice. */
18196 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18197 return error_mark_node
;
18200 array_type
= TREE_TYPE (array_value
);
18201 gcc_assert (array_type
);
18202 if (TREE_CODE (array_type
) != ARRAY_TYPE
18203 && TREE_CODE (array_type
) != POINTER_TYPE
)
18205 error_at (loc
, "base of array section must be pointer or array type");
18206 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18207 return error_mark_node
;
18209 type
= TREE_TYPE (array_type
);
18210 token
= c_parser_peek_token (parser
);
18212 if (token
->type
== CPP_EOF
)
18214 c_parser_error (parser
, "expected %<:%> or numeral");
18217 else if (token
->type
== CPP_COLON
)
18219 if (!initial_index
)
18221 /* If we are here, then we have a case like this A[:]. */
18222 c_parser_consume_token (parser
);
18223 if (TREE_CODE (array_type
) == POINTER_TYPE
)
18225 error_at (loc
, "start-index and length fields necessary for "
18226 "using array notations in pointers");
18227 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18228 return error_mark_node
;
18230 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
18232 error_at (loc
, "array notations cannot be used with function "
18234 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18235 return error_mark_node
;
18237 array_type_domain
= TYPE_DOMAIN (array_type
);
18239 if (!array_type_domain
)
18241 error_at (loc
, "start-index and length fields necessary for "
18242 "using array notations in dimensionless arrays");
18243 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18244 return error_mark_node
;
18247 start_index
= TYPE_MINVAL (array_type_domain
);
18248 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
18250 if (!TYPE_MAXVAL (array_type_domain
)
18251 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
18253 error_at (loc
, "start-index and length fields necessary for "
18254 "using array notations in variable-length arrays");
18255 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18256 return error_mark_node
;
18258 end_index
= TYPE_MAXVAL (array_type_domain
);
18259 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
18260 end_index
, integer_one_node
);
18261 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
18262 stride
= build_int_cst (integer_type_node
, 1);
18263 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
18265 else if (initial_index
!= error_mark_node
)
18267 /* If we are here, then there should be 2 possibilities:
18268 1. Array [EXPR : EXPR]
18269 2. Array [EXPR : EXPR : EXPR]
18271 start_index
= initial_index
;
18273 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
18275 error_at (loc
, "array notations cannot be used with function "
18277 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18278 return error_mark_node
;
18280 c_parser_consume_token (parser
); /* consume the ':' */
18281 struct c_expr ce
= c_parser_expression (parser
);
18282 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
18283 end_index
= ce
.value
;
18284 if (!end_index
|| end_index
== error_mark_node
)
18286 c_parser_skip_to_end_of_block_or_statement (parser
);
18287 return error_mark_node
;
18289 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
18291 c_parser_consume_token (parser
);
18292 ce
= c_parser_expression (parser
);
18293 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
18295 if (!stride
|| stride
== error_mark_node
)
18297 c_parser_skip_to_end_of_block_or_statement (parser
);
18298 return error_mark_node
;
18303 c_parser_error (parser
, "expected array notation expression");
18306 c_parser_error (parser
, "expected array notation expression");
18308 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18310 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
18311 end_index
, stride
, type
);
18312 if (value_tree
!= error_mark_node
)
18313 SET_EXPR_LOCATION (value_tree
, loc
);
18317 /* Parse the body of a function declaration marked with "__RTL".
18319 The RTL parser works on the level of characters read from a
18320 FILE *, whereas c_parser works at the level of tokens.
18321 Square this circle by consuming all of the tokens up to and
18322 including the closing brace, recording the start/end of the RTL
18323 fragment, and reopening the file and re-reading the relevant
18324 lines within the RTL parser.
18326 This requires the opening and closing braces of the C function
18327 to be on separate lines from the RTL they wrap.
18329 Take ownership of START_WITH_PASS, if non-NULL. */
18332 c_parser_parse_rtl_body (c_parser
*parser
, char *start_with_pass
)
18334 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
18336 free (start_with_pass
);
18340 location_t start_loc
= c_parser_peek_token (parser
)->location
;
18342 /* Consume all tokens, up to the closing brace, handling
18343 matching pairs of braces in the rtl dump. */
18344 int num_open_braces
= 1;
18347 switch (c_parser_peek_token (parser
)->type
)
18349 case CPP_OPEN_BRACE
:
18352 case CPP_CLOSE_BRACE
:
18353 if (--num_open_braces
== 0)
18354 goto found_closing_brace
;
18357 error_at (start_loc
, "no closing brace");
18358 free (start_with_pass
);
18363 c_parser_consume_token (parser
);
18366 found_closing_brace
:
18367 /* At the closing brace; record its location. */
18368 location_t end_loc
= c_parser_peek_token (parser
)->location
;
18370 /* Consume the closing brace. */
18371 c_parser_consume_token (parser
);
18373 /* Invoke the RTL parser. */
18374 if (!read_rtl_function_body_from_file_range (start_loc
, end_loc
))
18376 free (start_with_pass
);
18380 /* If a pass name was provided for START_WITH_PASS, run the backend
18381 accordingly now, on the cfun created above, transferring
18382 ownership of START_WITH_PASS. */
18383 if (start_with_pass
)
18384 run_rtl_passes (start_with_pass
);
18387 #include "gt-c-c-parser.h"