1 /* Parser for C and Objective-C.
2 Copyright (C) 1987-2016 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"
66 /* We need to walk over decls with incomplete struct/union/enum types
67 after parsing the whole translation unit.
68 In finish_decl(), if the decl is static, has incomplete
69 struct/union/enum type, it is appeneded to incomplete_record_decls.
70 In c_parser_translation_unit(), we iterate over incomplete_record_decls
71 and report error if any of the decls are still incomplete. */
73 vec
<tree
> incomplete_record_decls
;
76 set_c_expr_source_range (c_expr
*expr
,
77 location_t start
, location_t finish
)
79 expr
->src_range
.m_start
= start
;
80 expr
->src_range
.m_finish
= finish
;
82 set_source_range (expr
->value
, start
, finish
);
86 set_c_expr_source_range (c_expr
*expr
,
87 source_range src_range
)
89 expr
->src_range
= src_range
;
91 set_source_range (expr
->value
, src_range
);
95 /* Initialization routine for this file. */
100 /* The only initialization required is of the reserved word
106 /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in
107 the c_token structure. */
108 gcc_assert (RID_MAX
<= 255);
115 mask
|= D_ASM
| D_EXT
;
119 if (!c_dialect_objc ())
120 mask
|= D_OBJC
| D_CXX_OBJC
;
122 ridpointers
= ggc_cleared_vec_alloc
<tree
> ((int) RID_MAX
);
123 for (i
= 0; i
< num_c_common_reswords
; i
++)
125 /* If a keyword is disabled, do not enter it into the table
126 and so create a canonical spelling that isn't a keyword. */
127 if (c_common_reswords
[i
].disable
& mask
)
130 && (c_common_reswords
[i
].disable
& D_CXXWARN
))
132 id
= get_identifier (c_common_reswords
[i
].word
);
133 C_SET_RID_CODE (id
, RID_CXX_COMPAT_WARN
);
134 C_IS_RESERVED_WORD (id
) = 1;
139 id
= get_identifier (c_common_reswords
[i
].word
);
140 C_SET_RID_CODE (id
, c_common_reswords
[i
].rid
);
141 C_IS_RESERVED_WORD (id
) = 1;
142 ridpointers
[(int) c_common_reswords
[i
].rid
] = id
;
145 for (i
= 0; i
< NUM_INT_N_ENTS
; i
++)
147 /* We always create the symbols but they aren't always supported. */
149 sprintf (name
, "__int%d", int_n_data
[i
].bitsize
);
150 id
= get_identifier (name
);
151 C_SET_RID_CODE (id
, RID_FIRST_INT_N
+ i
);
152 C_IS_RESERVED_WORD (id
) = 1;
156 /* A parser structure recording information about the state and
157 context of parsing. Includes lexer information with up to two
158 tokens of look-ahead; more are not needed for C. */
159 struct GTY(()) c_parser
{
160 /* The look-ahead tokens. */
161 c_token
* GTY((skip
)) tokens
;
162 /* Buffer for look-ahead tokens. */
163 c_token tokens_buf
[4];
164 /* How many look-ahead tokens are available (0 - 4, or
165 more if parsing from pre-lexed tokens). */
166 unsigned int tokens_avail
;
167 /* True if a syntax error is being recovered from; false otherwise.
168 c_parser_error sets this flag. It should clear this flag when
169 enough tokens have been consumed to recover from the error. */
170 BOOL_BITFIELD error
: 1;
171 /* True if we're processing a pragma, and shouldn't automatically
172 consume CPP_PRAGMA_EOL. */
173 BOOL_BITFIELD in_pragma
: 1;
174 /* True if we're parsing the outermost block of an if statement. */
175 BOOL_BITFIELD in_if_block
: 1;
176 /* True if we want to lex an untranslated string. */
177 BOOL_BITFIELD lex_untranslated_string
: 1;
179 /* Objective-C specific parser/lexer information. */
181 /* True if we are in a context where the Objective-C "PQ" keywords
182 are considered keywords. */
183 BOOL_BITFIELD objc_pq_context
: 1;
184 /* True if we are parsing a (potential) Objective-C foreach
185 statement. This is set to true after we parsed 'for (' and while
186 we wait for 'in' or ';' to decide if it's a standard C for loop or an
187 Objective-C foreach loop. */
188 BOOL_BITFIELD objc_could_be_foreach_context
: 1;
189 /* The following flag is needed to contextualize Objective-C lexical
190 analysis. In some cases (e.g., 'int NSObject;'), it is
191 undesirable to bind an identifier to an Objective-C class, even
192 if a class with that name exists. */
193 BOOL_BITFIELD objc_need_raw_identifier
: 1;
194 /* Nonzero if we're processing a __transaction statement. The value
195 is 1 | TM_STMT_ATTR_*. */
196 unsigned int in_transaction
: 4;
197 /* True if we are in a context where the Objective-C "Property attribute"
198 keywords are valid. */
199 BOOL_BITFIELD objc_property_attr_context
: 1;
201 /* Cilk Plus specific parser/lexer information. */
203 /* Buffer to hold all the tokens from parsing the vector attribute for the
204 SIMD-enabled functions (formerly known as elemental functions). */
205 vec
<c_token
, va_gc
> *cilk_simd_fn_tokens
;
208 /* Return a pointer to the Nth token in PARSERs tokens_buf. */
211 c_parser_tokens_buf (c_parser
*parser
, unsigned n
)
213 return &parser
->tokens_buf
[n
];
216 /* Return the error state of PARSER. */
219 c_parser_error (c_parser
*parser
)
221 return parser
->error
;
224 /* Set the error state of PARSER to ERR. */
227 c_parser_set_error (c_parser
*parser
, bool err
)
233 /* The actual parser and external interface. ??? Does this need to be
234 garbage-collected? */
236 static GTY (()) c_parser
*the_parser
;
238 /* Read in and lex a single token, storing it in *TOKEN. */
241 c_lex_one_token (c_parser
*parser
, c_token
*token
)
243 timevar_push (TV_LEX
);
245 token
->type
= c_lex_with_flags (&token
->value
, &token
->location
,
247 (parser
->lex_untranslated_string
248 ? C_LEX_STRING_NO_TRANSLATE
: 0));
249 token
->id_kind
= C_ID_NONE
;
250 token
->keyword
= RID_MAX
;
251 token
->pragma_kind
= PRAGMA_NONE
;
259 bool objc_force_identifier
= parser
->objc_need_raw_identifier
;
260 if (c_dialect_objc ())
261 parser
->objc_need_raw_identifier
= false;
263 if (C_IS_RESERVED_WORD (token
->value
))
265 enum rid rid_code
= C_RID_CODE (token
->value
);
267 if (rid_code
== RID_CXX_COMPAT_WARN
)
269 warning_at (token
->location
,
271 "identifier %qE conflicts with C++ keyword",
274 else if (rid_code
>= RID_FIRST_ADDR_SPACE
275 && rid_code
<= RID_LAST_ADDR_SPACE
)
278 as
= (addr_space_t
) (rid_code
- RID_FIRST_ADDR_SPACE
);
279 targetm
.addr_space
.diagnose_usage (as
, token
->location
);
280 token
->id_kind
= C_ID_ADDRSPACE
;
281 token
->keyword
= rid_code
;
284 else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code
))
286 /* We found an Objective-C "pq" keyword (in, out,
287 inout, bycopy, byref, oneway). They need special
288 care because the interpretation depends on the
290 if (parser
->objc_pq_context
)
292 token
->type
= CPP_KEYWORD
;
293 token
->keyword
= rid_code
;
296 else if (parser
->objc_could_be_foreach_context
297 && rid_code
== RID_IN
)
299 /* We are in Objective-C, inside a (potential)
300 foreach context (which means after having
301 parsed 'for (', but before having parsed ';'),
302 and we found 'in'. We consider it the keyword
303 which terminates the declaration at the
304 beginning of a foreach-statement. Note that
305 this means you can't use 'in' for anything else
306 in that context; in particular, in Objective-C
307 you can't use 'in' as the name of the running
308 variable in a C for loop. We could potentially
309 try to add code here to disambiguate, but it
310 seems a reasonable limitation. */
311 token
->type
= CPP_KEYWORD
;
312 token
->keyword
= rid_code
;
315 /* Else, "pq" keywords outside of the "pq" context are
316 not keywords, and we fall through to the code for
319 else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code
))
321 /* We found an Objective-C "property attribute"
322 keyword (getter, setter, readonly, etc). These are
323 only valid in the property context. */
324 if (parser
->objc_property_attr_context
)
326 token
->type
= CPP_KEYWORD
;
327 token
->keyword
= rid_code
;
330 /* Else they are not special keywords.
333 else if (c_dialect_objc ()
334 && (OBJC_IS_AT_KEYWORD (rid_code
)
335 || OBJC_IS_CXX_KEYWORD (rid_code
)))
337 /* We found one of the Objective-C "@" keywords (defs,
338 selector, synchronized, etc) or one of the
339 Objective-C "cxx" keywords (class, private,
340 protected, public, try, catch, throw) without a
341 preceding '@' sign. Do nothing and fall through to
342 the code for normal tokens (in C++ we would still
343 consider the CXX ones keywords, but not in C). */
348 token
->type
= CPP_KEYWORD
;
349 token
->keyword
= rid_code
;
354 decl
= lookup_name (token
->value
);
357 if (TREE_CODE (decl
) == TYPE_DECL
)
359 token
->id_kind
= C_ID_TYPENAME
;
363 else if (c_dialect_objc ())
365 tree objc_interface_decl
= objc_is_class_name (token
->value
);
366 /* Objective-C class names are in the same namespace as
367 variables and typedefs, and hence are shadowed by local
369 if (objc_interface_decl
370 && (!objc_force_identifier
|| global_bindings_p ()))
372 token
->value
= objc_interface_decl
;
373 token
->id_kind
= C_ID_CLASSNAME
;
377 token
->id_kind
= C_ID_ID
;
381 /* This only happens in Objective-C; it must be a keyword. */
382 token
->type
= CPP_KEYWORD
;
383 switch (C_RID_CODE (token
->value
))
385 /* Replace 'class' with '@class', 'private' with '@private',
386 etc. This prevents confusion with the C++ keyword
387 'class', and makes the tokens consistent with other
388 Objective-C 'AT' keywords. For example '@class' is
389 reported as RID_AT_CLASS which is consistent with
390 '@synchronized', which is reported as
393 case RID_CLASS
: token
->keyword
= RID_AT_CLASS
; break;
394 case RID_PRIVATE
: token
->keyword
= RID_AT_PRIVATE
; break;
395 case RID_PROTECTED
: token
->keyword
= RID_AT_PROTECTED
; break;
396 case RID_PUBLIC
: token
->keyword
= RID_AT_PUBLIC
; break;
397 case RID_THROW
: token
->keyword
= RID_AT_THROW
; break;
398 case RID_TRY
: token
->keyword
= RID_AT_TRY
; break;
399 case RID_CATCH
: token
->keyword
= RID_AT_CATCH
; break;
400 case RID_SYNCHRONIZED
: token
->keyword
= RID_AT_SYNCHRONIZED
; break;
401 default: token
->keyword
= C_RID_CODE (token
->value
);
406 case CPP_CLOSE_PAREN
:
408 /* These tokens may affect the interpretation of any identifiers
409 following, if doing Objective-C. */
410 if (c_dialect_objc ())
411 parser
->objc_need_raw_identifier
= false;
414 /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */
415 token
->pragma_kind
= (enum pragma_kind
) TREE_INT_CST_LOW (token
->value
);
421 timevar_pop (TV_LEX
);
424 /* Return a pointer to the next token from PARSER, reading it in if
428 c_parser_peek_token (c_parser
*parser
)
430 if (parser
->tokens_avail
== 0)
432 c_lex_one_token (parser
, &parser
->tokens
[0]);
433 parser
->tokens_avail
= 1;
435 return &parser
->tokens
[0];
438 /* Return a pointer to the next-but-one token from PARSER, reading it
439 in if necessary. The next token is already read in. */
442 c_parser_peek_2nd_token (c_parser
*parser
)
444 if (parser
->tokens_avail
>= 2)
445 return &parser
->tokens
[1];
446 gcc_assert (parser
->tokens_avail
== 1);
447 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
448 gcc_assert (parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
449 c_lex_one_token (parser
, &parser
->tokens
[1]);
450 parser
->tokens_avail
= 2;
451 return &parser
->tokens
[1];
454 /* Return a pointer to the Nth token from PARSER, reading it
455 in if necessary. The N-1th token is already read in. */
458 c_parser_peek_nth_token (c_parser
*parser
, unsigned int n
)
460 /* N is 1-based, not zero-based. */
463 if (parser
->tokens_avail
>= n
)
464 return &parser
->tokens
[n
- 1];
465 gcc_assert (parser
->tokens_avail
== n
- 1);
466 c_lex_one_token (parser
, &parser
->tokens
[n
- 1]);
467 parser
->tokens_avail
= n
;
468 return &parser
->tokens
[n
- 1];
472 c_keyword_starts_typename (enum rid keyword
)
506 if (keyword
>= RID_FIRST_INT_N
507 && keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
508 && int_n_enabled_p
[keyword
- RID_FIRST_INT_N
])
514 /* Return true if TOKEN can start a type name,
517 c_token_starts_typename (c_token
*token
)
522 switch (token
->id_kind
)
531 gcc_assert (c_dialect_objc ());
537 return c_keyword_starts_typename (token
->keyword
);
539 if (c_dialect_objc ())
547 /* Return true if the next token from PARSER can start a type name,
548 false otherwise. LA specifies how to do lookahead in order to
549 detect unknown type names. If unsure, pick CLA_PREFER_ID. */
552 c_parser_next_tokens_start_typename (c_parser
*parser
, enum c_lookahead_kind la
)
554 c_token
*token
= c_parser_peek_token (parser
);
555 if (c_token_starts_typename (token
))
558 /* Try a bit harder to detect an unknown typename. */
559 if (la
!= cla_prefer_id
560 && token
->type
== CPP_NAME
561 && token
->id_kind
== C_ID_ID
563 /* Do not try too hard when we could have "object in array". */
564 && !parser
->objc_could_be_foreach_context
566 && (la
== cla_prefer_type
567 || c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
568 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
570 /* Only unknown identifiers. */
571 && !lookup_name (token
->value
))
577 /* Return true if TOKEN is a type qualifier, false otherwise. */
579 c_token_is_qualifier (c_token
*token
)
584 switch (token
->id_kind
)
592 switch (token
->keyword
)
610 /* Return true if the next token from PARSER is a type qualifier,
613 c_parser_next_token_is_qualifier (c_parser
*parser
)
615 c_token
*token
= c_parser_peek_token (parser
);
616 return c_token_is_qualifier (token
);
619 /* Return true if TOKEN can start declaration specifiers, false
622 c_token_starts_declspecs (c_token
*token
)
627 switch (token
->id_kind
)
636 gcc_assert (c_dialect_objc ());
642 switch (token
->keyword
)
683 if (token
->keyword
>= RID_FIRST_INT_N
684 && token
->keyword
< RID_FIRST_INT_N
+ NUM_INT_N_ENTS
685 && int_n_enabled_p
[token
->keyword
- RID_FIRST_INT_N
])
690 if (c_dialect_objc ())
699 /* Return true if TOKEN can start declaration specifiers or a static
700 assertion, false otherwise. */
702 c_token_starts_declaration (c_token
*token
)
704 if (c_token_starts_declspecs (token
)
705 || token
->keyword
== RID_STATIC_ASSERT
)
711 /* Return true if the next token from PARSER can start declaration
712 specifiers, false otherwise. */
714 c_parser_next_token_starts_declspecs (c_parser
*parser
)
716 c_token
*token
= c_parser_peek_token (parser
);
718 /* In Objective-C, a classname normally starts a declspecs unless it
719 is immediately followed by a dot. In that case, it is the
720 Objective-C 2.0 "dot-syntax" for class objects, ie, calls the
721 setter/getter on the class. c_token_starts_declspecs() can't
722 differentiate between the two cases because it only checks the
723 current token, so we have a special check here. */
724 if (c_dialect_objc ()
725 && token
->type
== CPP_NAME
726 && token
->id_kind
== C_ID_CLASSNAME
727 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
730 return c_token_starts_declspecs (token
);
733 /* Return true if the next tokens from PARSER can start declaration
734 specifiers or a static assertion, false otherwise. */
736 c_parser_next_tokens_start_declaration (c_parser
*parser
)
738 c_token
*token
= c_parser_peek_token (parser
);
741 if (c_dialect_objc ()
742 && token
->type
== CPP_NAME
743 && token
->id_kind
== C_ID_CLASSNAME
744 && c_parser_peek_2nd_token (parser
)->type
== CPP_DOT
)
747 /* Labels do not start declarations. */
748 if (token
->type
== CPP_NAME
749 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
752 if (c_token_starts_declaration (token
))
755 if (c_parser_next_tokens_start_typename (parser
, cla_nonabstract_decl
))
761 /* Consume the next token from PARSER. */
764 c_parser_consume_token (c_parser
*parser
)
766 gcc_assert (parser
->tokens_avail
>= 1);
767 gcc_assert (parser
->tokens
[0].type
!= CPP_EOF
);
768 gcc_assert (!parser
->in_pragma
|| parser
->tokens
[0].type
!= CPP_PRAGMA_EOL
);
769 gcc_assert (parser
->error
|| parser
->tokens
[0].type
!= CPP_PRAGMA
);
770 if (parser
->tokens
!= &parser
->tokens_buf
[0])
772 else if (parser
->tokens_avail
== 2)
773 parser
->tokens
[0] = parser
->tokens
[1];
774 parser
->tokens_avail
--;
777 /* Expect the current token to be a #pragma. Consume it and remember
778 that we've begun parsing a pragma. */
781 c_parser_consume_pragma (c_parser
*parser
)
783 gcc_assert (!parser
->in_pragma
);
784 gcc_assert (parser
->tokens_avail
>= 1);
785 gcc_assert (parser
->tokens
[0].type
== CPP_PRAGMA
);
786 if (parser
->tokens
!= &parser
->tokens_buf
[0])
788 else if (parser
->tokens_avail
== 2)
789 parser
->tokens
[0] = parser
->tokens
[1];
790 parser
->tokens_avail
--;
791 parser
->in_pragma
= true;
794 /* Update the global input_location from TOKEN. */
796 c_parser_set_source_position_from_token (c_token
*token
)
798 if (token
->type
!= CPP_EOF
)
800 input_location
= token
->location
;
804 /* Helper function for c_parser_error.
805 Having peeked a token of kind TOK1_KIND that might signify
806 a conflict marker, peek successor tokens to determine
807 if we actually do have a conflict marker.
808 Specifically, we consider a run of 7 '<', '=' or '>' characters
809 at the start of a line as a conflict marker.
810 These come through the lexer as three pairs and a single,
811 e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<').
812 If it returns true, *OUT_LOC is written to with the location/range
816 c_parser_peek_conflict_marker (c_parser
*parser
, enum cpp_ttype tok1_kind
,
819 c_token
*token2
= c_parser_peek_2nd_token (parser
);
820 if (token2
->type
!= tok1_kind
)
822 c_token
*token3
= c_parser_peek_nth_token (parser
, 3);
823 if (token3
->type
!= tok1_kind
)
825 c_token
*token4
= c_parser_peek_nth_token (parser
, 4);
826 if (token4
->type
!= conflict_marker_get_final_tok_kind (tok1_kind
))
829 /* It must be at the start of the line. */
830 location_t start_loc
= c_parser_peek_token (parser
)->location
;
831 if (LOCATION_COLUMN (start_loc
) != 1)
834 /* We have a conflict marker. Construct a location of the form:
837 with start == caret, finishing at the end of the marker. */
838 location_t finish_loc
= get_finish (token4
->location
);
839 *out_loc
= make_location (start_loc
, start_loc
, finish_loc
);
844 /* Issue a diagnostic of the form
845 FILE:LINE: MESSAGE before TOKEN
846 where TOKEN is the next token in the input stream of PARSER.
847 MESSAGE (specified by the caller) is usually of the form "expected
850 Do not issue a diagnostic if still recovering from an error.
852 ??? This is taken from the C++ parser, but building up messages in
853 this way is not i18n-friendly and some other approach should be
857 c_parser_error (c_parser
*parser
, const char *gmsgid
)
859 c_token
*token
= c_parser_peek_token (parser
);
862 parser
->error
= true;
866 /* If this is actually a conflict marker, report it as such. */
867 if (token
->type
== CPP_LSHIFT
868 || token
->type
== CPP_RSHIFT
869 || token
->type
== CPP_EQ_EQ
)
872 if (c_parser_peek_conflict_marker (parser
, token
->type
, &loc
))
874 error_at (loc
, "version control conflict marker in file");
879 /* This diagnostic makes more sense if it is tagged to the line of
880 the token we just peeked at. */
881 c_parser_set_source_position_from_token (token
);
882 c_parse_error (gmsgid
,
883 /* Because c_parse_error does not understand
884 CPP_KEYWORD, keywords are treated like
886 (token
->type
== CPP_KEYWORD
? CPP_NAME
: token
->type
),
887 /* ??? The C parser does not save the cpp flags of a
888 token, we need to pass 0 here and we will not get
889 the source spelling of some tokens but rather the
890 canonical spelling. */
891 token
->value
, /*flags=*/0);
894 /* If the next token is of the indicated TYPE, consume it. Otherwise,
895 issue the error MSGID. If MSGID is NULL then a message has already
896 been produced and no message will be produced this time. Returns
897 true if found, false otherwise. */
900 c_parser_require (c_parser
*parser
,
904 if (c_parser_next_token_is (parser
, type
))
906 c_parser_consume_token (parser
);
911 c_parser_error (parser
, msgid
);
916 /* If the next token is the indicated keyword, consume it. Otherwise,
917 issue the error MSGID. Returns true if found, false otherwise. */
920 c_parser_require_keyword (c_parser
*parser
,
924 if (c_parser_next_token_is_keyword (parser
, keyword
))
926 c_parser_consume_token (parser
);
931 c_parser_error (parser
, msgid
);
936 /* Like c_parser_require, except that tokens will be skipped until the
937 desired token is found. An error message is still produced if the
938 next token is not as expected. If MSGID is NULL then a message has
939 already been produced and no message will be produced this
943 c_parser_skip_until_found (c_parser
*parser
,
947 unsigned nesting_depth
= 0;
949 if (c_parser_require (parser
, type
, msgid
))
952 /* Skip tokens until the desired token is found. */
955 /* Peek at the next token. */
956 c_token
*token
= c_parser_peek_token (parser
);
957 /* If we've reached the token we want, consume it and stop. */
958 if (token
->type
== type
&& !nesting_depth
)
960 c_parser_consume_token (parser
);
964 /* If we've run out of tokens, stop. */
965 if (token
->type
== CPP_EOF
)
967 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
969 if (token
->type
== CPP_OPEN_BRACE
970 || token
->type
== CPP_OPEN_PAREN
971 || token
->type
== CPP_OPEN_SQUARE
)
973 else if (token
->type
== CPP_CLOSE_BRACE
974 || token
->type
== CPP_CLOSE_PAREN
975 || token
->type
== CPP_CLOSE_SQUARE
)
977 if (nesting_depth
-- == 0)
980 /* Consume this token. */
981 c_parser_consume_token (parser
);
983 parser
->error
= false;
986 /* Skip tokens until the end of a parameter is found, but do not
987 consume the comma, semicolon or closing delimiter. */
990 c_parser_skip_to_end_of_parameter (c_parser
*parser
)
992 unsigned nesting_depth
= 0;
996 c_token
*token
= c_parser_peek_token (parser
);
997 if ((token
->type
== CPP_COMMA
|| token
->type
== CPP_SEMICOLON
)
1000 /* If we've run out of tokens, stop. */
1001 if (token
->type
== CPP_EOF
)
1003 if (token
->type
== CPP_PRAGMA_EOL
&& parser
->in_pragma
)
1005 if (token
->type
== CPP_OPEN_BRACE
1006 || token
->type
== CPP_OPEN_PAREN
1007 || token
->type
== CPP_OPEN_SQUARE
)
1009 else if (token
->type
== CPP_CLOSE_BRACE
1010 || token
->type
== CPP_CLOSE_PAREN
1011 || token
->type
== CPP_CLOSE_SQUARE
)
1013 if (nesting_depth
-- == 0)
1016 /* Consume this token. */
1017 c_parser_consume_token (parser
);
1019 parser
->error
= false;
1022 /* Expect to be at the end of the pragma directive and consume an
1023 end of line marker. */
1026 c_parser_skip_to_pragma_eol (c_parser
*parser
, bool error_if_not_eol
= true)
1028 gcc_assert (parser
->in_pragma
);
1029 parser
->in_pragma
= false;
1031 if (error_if_not_eol
&& c_parser_peek_token (parser
)->type
!= CPP_PRAGMA_EOL
)
1032 c_parser_error (parser
, "expected end of line");
1034 cpp_ttype token_type
;
1037 c_token
*token
= c_parser_peek_token (parser
);
1038 token_type
= token
->type
;
1039 if (token_type
== CPP_EOF
)
1041 c_parser_consume_token (parser
);
1043 while (token_type
!= CPP_PRAGMA_EOL
);
1045 parser
->error
= false;
1048 /* Skip tokens until we have consumed an entire block, or until we
1049 have consumed a non-nested ';'. */
1052 c_parser_skip_to_end_of_block_or_statement (c_parser
*parser
)
1054 unsigned nesting_depth
= 0;
1055 bool save_error
= parser
->error
;
1061 /* Peek at the next token. */
1062 token
= c_parser_peek_token (parser
);
1064 switch (token
->type
)
1069 case CPP_PRAGMA_EOL
:
1070 if (parser
->in_pragma
)
1075 /* If the next token is a ';', we have reached the
1076 end of the statement. */
1079 /* Consume the ';'. */
1080 c_parser_consume_token (parser
);
1085 case CPP_CLOSE_BRACE
:
1086 /* If the next token is a non-nested '}', then we have
1087 reached the end of the current block. */
1088 if (nesting_depth
== 0 || --nesting_depth
== 0)
1090 c_parser_consume_token (parser
);
1095 case CPP_OPEN_BRACE
:
1096 /* If it the next token is a '{', then we are entering a new
1097 block. Consume the entire block. */
1102 /* If we see a pragma, consume the whole thing at once. We
1103 have some safeguards against consuming pragmas willy-nilly.
1104 Normally, we'd expect to be here with parser->error set,
1105 which disables these safeguards. But it's possible to get
1106 here for secondary error recovery, after parser->error has
1108 c_parser_consume_pragma (parser
);
1109 c_parser_skip_to_pragma_eol (parser
);
1110 parser
->error
= save_error
;
1117 c_parser_consume_token (parser
);
1121 parser
->error
= false;
1124 /* CPP's options (initialized by c-opts.c). */
1125 extern cpp_options
*cpp_opts
;
1127 /* Save the warning flags which are controlled by __extension__. */
1130 disable_extension_diagnostics (void)
1133 | (warn_pointer_arith
<< 1)
1134 | (warn_traditional
<< 2)
1136 | (warn_long_long
<< 4)
1137 | (warn_cxx_compat
<< 5)
1138 | (warn_overlength_strings
<< 6)
1139 /* warn_c90_c99_compat has three states: -1/0/1, so we must
1140 play tricks to properly restore it. */
1141 | ((warn_c90_c99_compat
== 1) << 7)
1142 | ((warn_c90_c99_compat
== -1) << 8)
1143 /* Similarly for warn_c99_c11_compat. */
1144 | ((warn_c99_c11_compat
== 1) << 9)
1145 | ((warn_c99_c11_compat
== -1) << 10)
1147 cpp_opts
->cpp_pedantic
= pedantic
= 0;
1148 warn_pointer_arith
= 0;
1149 cpp_opts
->cpp_warn_traditional
= warn_traditional
= 0;
1151 cpp_opts
->cpp_warn_long_long
= warn_long_long
= 0;
1152 warn_cxx_compat
= 0;
1153 warn_overlength_strings
= 0;
1154 warn_c90_c99_compat
= 0;
1155 warn_c99_c11_compat
= 0;
1159 /* Restore the warning flags which are controlled by __extension__.
1160 FLAGS is the return value from disable_extension_diagnostics. */
1163 restore_extension_diagnostics (int flags
)
1165 cpp_opts
->cpp_pedantic
= pedantic
= flags
& 1;
1166 warn_pointer_arith
= (flags
>> 1) & 1;
1167 cpp_opts
->cpp_warn_traditional
= warn_traditional
= (flags
>> 2) & 1;
1168 flag_iso
= (flags
>> 3) & 1;
1169 cpp_opts
->cpp_warn_long_long
= warn_long_long
= (flags
>> 4) & 1;
1170 warn_cxx_compat
= (flags
>> 5) & 1;
1171 warn_overlength_strings
= (flags
>> 6) & 1;
1172 /* See above for why is this needed. */
1173 warn_c90_c99_compat
= (flags
>> 7) & 1 ? 1 : ((flags
>> 8) & 1 ? -1 : 0);
1174 warn_c99_c11_compat
= (flags
>> 9) & 1 ? 1 : ((flags
>> 10) & 1 ? -1 : 0);
1177 /* Helper data structure for parsing #pragma acc routine. */
1178 struct oacc_routine_data
{
1179 bool error_seen
; /* Set if error has been reported. */
1180 bool fndecl_seen
; /* Set if one fn decl/definition has been seen already. */
1185 static void c_parser_external_declaration (c_parser
*);
1186 static void c_parser_asm_definition (c_parser
*);
1187 static void c_parser_declaration_or_fndef (c_parser
*, bool, bool, bool,
1188 bool, bool, tree
*, vec
<c_token
>,
1189 struct oacc_routine_data
* = NULL
,
1191 static void c_parser_static_assert_declaration_no_semi (c_parser
*);
1192 static void c_parser_static_assert_declaration (c_parser
*);
1193 static struct c_typespec
c_parser_enum_specifier (c_parser
*);
1194 static struct c_typespec
c_parser_struct_or_union_specifier (c_parser
*);
1195 static tree
c_parser_struct_declaration (c_parser
*);
1196 static struct c_typespec
c_parser_typeof_specifier (c_parser
*);
1197 static tree
c_parser_alignas_specifier (c_parser
*);
1198 static struct c_declarator
*c_parser_direct_declarator (c_parser
*, bool,
1200 static struct c_declarator
*c_parser_direct_declarator_inner (c_parser
*,
1202 struct c_declarator
*);
1203 static struct c_arg_info
*c_parser_parms_declarator (c_parser
*, bool, tree
);
1204 static struct c_arg_info
*c_parser_parms_list_declarator (c_parser
*, tree
,
1206 static struct c_parm
*c_parser_parameter_declaration (c_parser
*, tree
);
1207 static tree
c_parser_simple_asm_expr (c_parser
*);
1208 static tree
c_parser_attributes (c_parser
*);
1209 static struct c_expr
c_parser_initializer (c_parser
*);
1210 static struct c_expr
c_parser_braced_init (c_parser
*, tree
, bool,
1212 static void c_parser_initelt (c_parser
*, struct obstack
*);
1213 static void c_parser_initval (c_parser
*, struct c_expr
*,
1215 static tree
c_parser_compound_statement (c_parser
*);
1216 static void c_parser_compound_statement_nostart (c_parser
*);
1217 static void c_parser_label (c_parser
*);
1218 static void c_parser_statement (c_parser
*, bool *);
1219 static void c_parser_statement_after_labels (c_parser
*, bool *,
1220 vec
<tree
> * = NULL
);
1221 static void c_parser_if_statement (c_parser
*, bool *, vec
<tree
> *);
1222 static void c_parser_switch_statement (c_parser
*, bool *);
1223 static void c_parser_while_statement (c_parser
*, bool, bool *);
1224 static void c_parser_do_statement (c_parser
*, bool);
1225 static void c_parser_for_statement (c_parser
*, bool, bool *);
1226 static tree
c_parser_asm_statement (c_parser
*);
1227 static tree
c_parser_asm_operands (c_parser
*);
1228 static tree
c_parser_asm_goto_operands (c_parser
*);
1229 static tree
c_parser_asm_clobbers (c_parser
*);
1230 static struct c_expr
c_parser_expr_no_commas (c_parser
*, struct c_expr
*,
1232 static struct c_expr
c_parser_conditional_expression (c_parser
*,
1233 struct c_expr
*, tree
);
1234 static struct c_expr
c_parser_binary_expression (c_parser
*, struct c_expr
*,
1236 static struct c_expr
c_parser_cast_expression (c_parser
*, struct c_expr
*);
1237 static struct c_expr
c_parser_unary_expression (c_parser
*);
1238 static struct c_expr
c_parser_sizeof_expression (c_parser
*);
1239 static struct c_expr
c_parser_alignof_expression (c_parser
*);
1240 static struct c_expr
c_parser_postfix_expression (c_parser
*);
1241 static struct c_expr
c_parser_postfix_expression_after_paren_type (c_parser
*,
1242 struct c_type_name
*,
1244 static struct c_expr
c_parser_postfix_expression_after_primary (c_parser
*,
1247 static tree
c_parser_transaction (c_parser
*, enum rid
);
1248 static struct c_expr
c_parser_transaction_expression (c_parser
*, enum rid
);
1249 static tree
c_parser_transaction_cancel (c_parser
*);
1250 static struct c_expr
c_parser_expression (c_parser
*);
1251 static struct c_expr
c_parser_expression_conv (c_parser
*);
1252 static vec
<tree
, va_gc
> *c_parser_expr_list (c_parser
*, bool, bool,
1253 vec
<tree
, va_gc
> **, location_t
*,
1254 tree
*, vec
<location_t
> *,
1255 unsigned int * = NULL
);
1256 static void c_parser_oacc_declare (c_parser
*);
1257 static void c_parser_oacc_enter_exit_data (c_parser
*, bool);
1258 static void c_parser_oacc_update (c_parser
*);
1259 static void c_parser_omp_construct (c_parser
*, bool *);
1260 static void c_parser_omp_threadprivate (c_parser
*);
1261 static void c_parser_omp_barrier (c_parser
*);
1262 static void c_parser_omp_flush (c_parser
*);
1263 static tree
c_parser_omp_for_loop (location_t
, c_parser
*, enum tree_code
,
1264 tree
, tree
*, bool *);
1265 static void c_parser_omp_taskwait (c_parser
*);
1266 static void c_parser_omp_taskyield (c_parser
*);
1267 static void c_parser_omp_cancel (c_parser
*);
1269 enum pragma_context
{ pragma_external
, pragma_struct
, pragma_param
,
1270 pragma_stmt
, pragma_compound
};
1271 static bool c_parser_pragma (c_parser
*, enum pragma_context
, bool *);
1272 static void c_parser_omp_cancellation_point (c_parser
*, enum pragma_context
);
1273 static bool c_parser_omp_target (c_parser
*, enum pragma_context
, bool *);
1274 static void c_parser_omp_end_declare_target (c_parser
*);
1275 static void c_parser_omp_declare (c_parser
*, enum pragma_context
);
1276 static bool c_parser_omp_ordered (c_parser
*, enum pragma_context
, bool *);
1277 static void c_parser_oacc_routine (c_parser
*, enum pragma_context
);
1279 /* These Objective-C parser functions are only ever called when
1280 compiling Objective-C. */
1281 static void c_parser_objc_class_definition (c_parser
*, tree
);
1282 static void c_parser_objc_class_instance_variables (c_parser
*);
1283 static void c_parser_objc_class_declaration (c_parser
*);
1284 static void c_parser_objc_alias_declaration (c_parser
*);
1285 static void c_parser_objc_protocol_definition (c_parser
*, tree
);
1286 static bool c_parser_objc_method_type (c_parser
*);
1287 static void c_parser_objc_method_definition (c_parser
*);
1288 static void c_parser_objc_methodprotolist (c_parser
*);
1289 static void c_parser_objc_methodproto (c_parser
*);
1290 static tree
c_parser_objc_method_decl (c_parser
*, bool, tree
*, tree
*);
1291 static tree
c_parser_objc_type_name (c_parser
*);
1292 static tree
c_parser_objc_protocol_refs (c_parser
*);
1293 static void c_parser_objc_try_catch_finally_statement (c_parser
*);
1294 static void c_parser_objc_synchronized_statement (c_parser
*);
1295 static tree
c_parser_objc_selector (c_parser
*);
1296 static tree
c_parser_objc_selector_arg (c_parser
*);
1297 static tree
c_parser_objc_receiver (c_parser
*);
1298 static tree
c_parser_objc_message_args (c_parser
*);
1299 static tree
c_parser_objc_keywordexpr (c_parser
*);
1300 static void c_parser_objc_at_property_declaration (c_parser
*);
1301 static void c_parser_objc_at_synthesize_declaration (c_parser
*);
1302 static void c_parser_objc_at_dynamic_declaration (c_parser
*);
1303 static bool c_parser_objc_diagnose_bad_element_prefix
1304 (c_parser
*, struct c_declspecs
*);
1306 /* Cilk Plus supporting routines. */
1307 static void c_parser_cilk_simd (c_parser
*, bool *);
1308 static void c_parser_cilk_for (c_parser
*, tree
, bool *);
1309 static bool c_parser_cilk_verify_simd (c_parser
*, enum pragma_context
);
1310 static tree
c_parser_array_notation (location_t
, c_parser
*, tree
, tree
);
1311 static tree
c_parser_cilk_clause_vectorlength (c_parser
*, tree
, bool);
1312 static void c_parser_cilk_grainsize (c_parser
*, bool *);
1314 /* Parse a translation unit (C90 6.7, C99 6.9).
1317 external-declarations
1319 external-declarations:
1320 external-declaration
1321 external-declarations external-declaration
1330 c_parser_translation_unit (c_parser
*parser
)
1332 if (c_parser_next_token_is (parser
, CPP_EOF
))
1334 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1335 "ISO C forbids an empty translation unit");
1339 void *obstack_position
= obstack_alloc (&parser_obstack
, 0);
1340 mark_valid_location_for_stdc_pragma (false);
1344 c_parser_external_declaration (parser
);
1345 obstack_free (&parser_obstack
, obstack_position
);
1347 while (c_parser_next_token_is_not (parser
, CPP_EOF
));
1352 FOR_EACH_VEC_ELT (incomplete_record_decls
, i
, decl
)
1353 if (DECL_SIZE (decl
) == NULL_TREE
&& TREE_TYPE (decl
) != error_mark_node
)
1354 error ("storage size of %q+D isn%'t known", decl
);
1357 /* Parse an external declaration (C90 6.7, C99 6.9).
1359 external-declaration:
1365 external-declaration:
1368 __extension__ external-declaration
1372 external-declaration:
1373 objc-class-definition
1374 objc-class-declaration
1375 objc-alias-declaration
1376 objc-protocol-definition
1377 objc-method-definition
1382 c_parser_external_declaration (c_parser
*parser
)
1385 switch (c_parser_peek_token (parser
)->type
)
1388 switch (c_parser_peek_token (parser
)->keyword
)
1391 ext
= disable_extension_diagnostics ();
1392 c_parser_consume_token (parser
);
1393 c_parser_external_declaration (parser
);
1394 restore_extension_diagnostics (ext
);
1397 c_parser_asm_definition (parser
);
1399 case RID_AT_INTERFACE
:
1400 case RID_AT_IMPLEMENTATION
:
1401 gcc_assert (c_dialect_objc ());
1402 c_parser_objc_class_definition (parser
, NULL_TREE
);
1405 gcc_assert (c_dialect_objc ());
1406 c_parser_objc_class_declaration (parser
);
1409 gcc_assert (c_dialect_objc ());
1410 c_parser_objc_alias_declaration (parser
);
1412 case RID_AT_PROTOCOL
:
1413 gcc_assert (c_dialect_objc ());
1414 c_parser_objc_protocol_definition (parser
, NULL_TREE
);
1416 case RID_AT_PROPERTY
:
1417 gcc_assert (c_dialect_objc ());
1418 c_parser_objc_at_property_declaration (parser
);
1420 case RID_AT_SYNTHESIZE
:
1421 gcc_assert (c_dialect_objc ());
1422 c_parser_objc_at_synthesize_declaration (parser
);
1424 case RID_AT_DYNAMIC
:
1425 gcc_assert (c_dialect_objc ());
1426 c_parser_objc_at_dynamic_declaration (parser
);
1429 gcc_assert (c_dialect_objc ());
1430 c_parser_consume_token (parser
);
1431 objc_finish_implementation ();
1438 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
1439 "ISO C does not allow extra %<;%> outside of a function");
1440 c_parser_consume_token (parser
);
1443 mark_valid_location_for_stdc_pragma (true);
1444 c_parser_pragma (parser
, pragma_external
, NULL
);
1445 mark_valid_location_for_stdc_pragma (false);
1449 if (c_dialect_objc ())
1451 c_parser_objc_method_definition (parser
);
1454 /* Else fall through, and yield a syntax error trying to parse
1455 as a declaration or function definition. */
1459 /* A declaration or a function definition (or, in Objective-C,
1460 an @interface or @protocol with prefix attributes). We can
1461 only tell which after parsing the declaration specifiers, if
1462 any, and the first declarator. */
1463 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
1469 static void c_finish_omp_declare_simd (c_parser
*, tree
, tree
, vec
<c_token
>);
1470 static void c_finish_oacc_routine (struct oacc_routine_data
*, tree
, bool);
1472 /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99
1473 6.7, 6.9.1). If FNDEF_OK is true, a function definition is
1474 accepted; otherwise (old-style parameter declarations) only other
1475 declarations are accepted. If STATIC_ASSERT_OK is true, a static
1476 assertion is accepted; otherwise (old-style parameter declarations)
1477 it is not. If NESTED is true, we are inside a function or parsing
1478 old-style parameter declarations; any functions encountered are
1479 nested functions and declaration specifiers are required; otherwise
1480 we are at top level and functions are normal functions and
1481 declaration specifiers may be optional. If EMPTY_OK is true, empty
1482 declarations are OK (subject to all other constraints); otherwise
1483 (old-style parameter declarations) they are diagnosed. If
1484 START_ATTR_OK is true, the declaration specifiers may start with
1485 attributes; otherwise they may not.
1486 OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed
1487 declaration when parsing an Objective-C foreach statement.
1488 FALLTHRU_ATTR_P is used to signal whether this function parsed
1489 "__attribute__((fallthrough));".
1492 declaration-specifiers init-declarator-list[opt] ;
1493 static_assert-declaration
1495 function-definition:
1496 declaration-specifiers[opt] declarator declaration-list[opt]
1501 declaration-list declaration
1503 init-declarator-list:
1505 init-declarator-list , init-declarator
1508 declarator simple-asm-expr[opt] attributes[opt]
1509 declarator simple-asm-expr[opt] attributes[opt] = initializer
1513 nested-function-definition:
1514 declaration-specifiers declarator declaration-list[opt]
1520 attributes objc-class-definition
1521 attributes objc-category-definition
1522 attributes objc-protocol-definition
1524 The simple-asm-expr and attributes are GNU extensions.
1526 This function does not handle __extension__; that is handled in its
1527 callers. ??? Following the old parser, __extension__ may start
1528 external declarations, declarations in functions and declarations
1529 at the start of "for" loops, but not old-style parameter
1532 C99 requires declaration specifiers in a function definition; the
1533 absence is diagnosed through the diagnosis of implicit int. In GNU
1534 C we also allow but diagnose declarations without declaration
1535 specifiers, but only at top level (elsewhere they conflict with
1538 In Objective-C, declarations of the looping variable in a foreach
1539 statement are exceptionally terminated by 'in' (for example, 'for
1540 (NSObject *object in array) { ... }').
1545 threadprivate-directive
1549 gimple-function-definition:
1550 declaration-specifiers[opt] __GIMPLE (gimple-pass-list) declarator
1551 declaration-list[opt] compound-statement */
1554 c_parser_declaration_or_fndef (c_parser
*parser
, bool fndef_ok
,
1555 bool static_assert_ok
, bool empty_ok
,
1556 bool nested
, bool start_attr_ok
,
1557 tree
*objc_foreach_object_declaration
,
1558 vec
<c_token
> omp_declare_simd_clauses
,
1559 struct oacc_routine_data
*oacc_routine_data
,
1560 bool *fallthru_attr_p
)
1562 struct c_declspecs
*specs
;
1564 tree all_prefix_attrs
;
1565 bool diagnosed_no_specs
= false;
1566 location_t here
= c_parser_peek_token (parser
)->location
;
1568 if (static_assert_ok
1569 && c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
1571 c_parser_static_assert_declaration (parser
);
1574 specs
= build_null_declspecs ();
1576 /* Try to detect an unknown type name when we have "A B" or "A *B". */
1577 if (c_parser_peek_token (parser
)->type
== CPP_NAME
1578 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
1579 && (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
1580 || c_parser_peek_2nd_token (parser
)->type
== CPP_MULT
)
1581 && (!nested
|| !lookup_name (c_parser_peek_token (parser
)->value
)))
1583 tree name
= c_parser_peek_token (parser
)->value
;
1585 /* Issue a warning about NAME being an unknown type name, perhaps
1586 with some kind of hint.
1587 If the user forgot a "struct" etc, suggest inserting
1588 it. Otherwise, attempt to look for misspellings. */
1589 gcc_rich_location
richloc (here
);
1590 if (tag_exists_p (RECORD_TYPE
, name
))
1592 /* This is not C++ with its implicit typedef. */
1593 richloc
.add_fixit_insert_before ("struct ");
1594 error_at_rich_loc (&richloc
,
1595 "unknown type name %qE;"
1596 " use %<struct%> keyword to refer to the type",
1599 else if (tag_exists_p (UNION_TYPE
, name
))
1601 richloc
.add_fixit_insert_before ("union ");
1602 error_at_rich_loc (&richloc
,
1603 "unknown type name %qE;"
1604 " use %<union%> keyword to refer to the type",
1607 else if (tag_exists_p (ENUMERAL_TYPE
, name
))
1609 richloc
.add_fixit_insert_before ("enum ");
1610 error_at_rich_loc (&richloc
,
1611 "unknown type name %qE;"
1612 " use %<enum%> keyword to refer to the type",
1617 const char *hint
= lookup_name_fuzzy (name
, FUZZY_LOOKUP_TYPENAME
);
1620 richloc
.add_fixit_replace (hint
);
1621 error_at_rich_loc (&richloc
,
1622 "unknown type name %qE; did you mean %qs?",
1626 error_at (here
, "unknown type name %qE", name
);
1629 /* Parse declspecs normally to get a correct pointer type, but avoid
1630 a further "fails to be a type name" error. Refuse nested functions
1631 since it is not how the user likely wants us to recover. */
1632 c_parser_peek_token (parser
)->type
= CPP_KEYWORD
;
1633 c_parser_peek_token (parser
)->keyword
= RID_VOID
;
1634 c_parser_peek_token (parser
)->value
= error_mark_node
;
1638 c_parser_declspecs (parser
, specs
, true, true, start_attr_ok
,
1639 true, true, cla_nonabstract_decl
);
1642 c_parser_skip_to_end_of_block_or_statement (parser
);
1645 if (nested
&& !specs
->declspecs_seen_p
)
1647 c_parser_error (parser
, "expected declaration specifiers");
1648 c_parser_skip_to_end_of_block_or_statement (parser
);
1652 finish_declspecs (specs
);
1653 bool auto_type_p
= specs
->typespec_word
== cts_auto_type
;
1654 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1657 error_at (here
, "%<__auto_type%> in empty declaration");
1658 else if (specs
->typespec_kind
== ctsk_none
1659 && attribute_fallthrough_p (specs
->attrs
))
1661 if (fallthru_attr_p
!= NULL
)
1662 *fallthru_attr_p
= true;
1663 tree fn
= build_call_expr_internal_loc (here
, IFN_FALLTHROUGH
,
1671 shadow_tag_warned (specs
, 1);
1672 pedwarn (here
, 0, "empty declaration");
1674 c_parser_consume_token (parser
);
1675 if (oacc_routine_data
)
1676 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1680 /* Provide better error recovery. Note that a type name here is usually
1681 better diagnosed as a redeclaration. */
1683 && specs
->typespec_kind
== ctsk_tagdef
1684 && c_parser_next_token_starts_declspecs (parser
)
1685 && !c_parser_next_token_is (parser
, CPP_NAME
))
1687 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
1688 parser
->error
= false;
1689 shadow_tag_warned (specs
, 1);
1692 else if (c_dialect_objc () && !auto_type_p
)
1694 /* Prefix attributes are an error on method decls. */
1695 switch (c_parser_peek_token (parser
)->type
)
1699 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1703 warning_at (c_parser_peek_token (parser
)->location
,
1705 "prefix attributes are ignored for methods");
1706 specs
->attrs
= NULL_TREE
;
1709 c_parser_objc_method_definition (parser
);
1711 c_parser_objc_methodproto (parser
);
1717 /* This is where we parse 'attributes @interface ...',
1718 'attributes @implementation ...', 'attributes @protocol ...'
1719 (where attributes could be, for example, __attribute__
1722 switch (c_parser_peek_token (parser
)->keyword
)
1724 case RID_AT_INTERFACE
:
1726 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1728 c_parser_objc_class_definition (parser
, specs
->attrs
);
1732 case RID_AT_IMPLEMENTATION
:
1734 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1738 warning_at (c_parser_peek_token (parser
)->location
,
1740 "prefix attributes are ignored for implementations");
1741 specs
->attrs
= NULL_TREE
;
1743 c_parser_objc_class_definition (parser
, NULL_TREE
);
1747 case RID_AT_PROTOCOL
:
1749 if (c_parser_objc_diagnose_bad_element_prefix (parser
, specs
))
1751 c_parser_objc_protocol_definition (parser
, specs
->attrs
);
1758 case RID_AT_PROPERTY
:
1761 c_parser_error (parser
, "unexpected attribute");
1762 specs
->attrs
= NULL
;
1769 else if (attribute_fallthrough_p (specs
->attrs
))
1770 warning_at (here
, OPT_Wattributes
,
1771 "%<fallthrough%> attribute not followed by %<;%>");
1773 pending_xref_error ();
1774 prefix_attrs
= specs
->attrs
;
1775 all_prefix_attrs
= prefix_attrs
;
1776 specs
->attrs
= NULL_TREE
;
1779 struct c_declarator
*declarator
;
1782 tree fnbody
= NULL_TREE
;
1783 /* Declaring either one or more declarators (in which case we
1784 should diagnose if there were no declaration specifiers) or a
1785 function definition (in which case the diagnostic for
1786 implicit int suffices). */
1787 declarator
= c_parser_declarator (parser
,
1788 specs
->typespec_kind
!= ctsk_none
,
1789 C_DTR_NORMAL
, &dummy
);
1790 if (declarator
== NULL
)
1792 if (omp_declare_simd_clauses
.exists ()
1793 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1794 c_finish_omp_declare_simd (parser
, NULL_TREE
, NULL_TREE
,
1795 omp_declare_simd_clauses
);
1796 if (oacc_routine_data
)
1797 c_finish_oacc_routine (oacc_routine_data
, NULL_TREE
, false);
1798 c_parser_skip_to_end_of_block_or_statement (parser
);
1801 if (auto_type_p
&& declarator
->kind
!= cdk_id
)
1804 "%<__auto_type%> requires a plain identifier"
1806 c_parser_skip_to_end_of_block_or_statement (parser
);
1809 if (c_parser_next_token_is (parser
, CPP_EQ
)
1810 || c_parser_next_token_is (parser
, CPP_COMMA
)
1811 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
1812 || c_parser_next_token_is_keyword (parser
, RID_ASM
)
1813 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
)
1814 || c_parser_next_token_is_keyword (parser
, RID_IN
))
1816 tree asm_name
= NULL_TREE
;
1817 tree postfix_attrs
= NULL_TREE
;
1818 if (!diagnosed_no_specs
&& !specs
->declspecs_seen_p
)
1820 diagnosed_no_specs
= true;
1821 pedwarn (here
, 0, "data definition has no type or storage class");
1823 /* Having seen a data definition, there cannot now be a
1824 function definition. */
1826 if (c_parser_next_token_is_keyword (parser
, RID_ASM
))
1827 asm_name
= c_parser_simple_asm_expr (parser
);
1828 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1830 postfix_attrs
= c_parser_attributes (parser
);
1831 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
1833 /* This means there is an attribute specifier after
1834 the declarator in a function definition. Provide
1835 some more information for the user. */
1836 error_at (here
, "attributes should be specified before the "
1837 "declarator in a function definition");
1838 c_parser_skip_to_end_of_block_or_statement (parser
);
1842 if (c_parser_next_token_is (parser
, CPP_EQ
))
1846 location_t init_loc
;
1847 c_parser_consume_token (parser
);
1850 start_init (NULL_TREE
, asm_name
, global_bindings_p ());
1851 init_loc
= c_parser_peek_token (parser
)->location
;
1852 init
= c_parser_expr_no_commas (parser
, NULL
);
1853 if (TREE_CODE (init
.value
) == COMPONENT_REF
1854 && DECL_C_BIT_FIELD (TREE_OPERAND (init
.value
, 1)))
1856 "%<__auto_type%> used with a bit-field"
1858 init
= convert_lvalue_to_rvalue (init_loc
, init
, true, true);
1859 tree init_type
= TREE_TYPE (init
.value
);
1860 /* As with typeof, remove all qualifiers from atomic types. */
1861 if (init_type
!= error_mark_node
&& TYPE_ATOMIC (init_type
))
1863 = c_build_qualified_type (init_type
, TYPE_UNQUALIFIED
);
1864 bool vm_type
= variably_modified_type_p (init_type
,
1867 init
.value
= c_save_expr (init
.value
);
1869 specs
->typespec_kind
= ctsk_typeof
;
1870 specs
->locations
[cdw_typedef
] = init_loc
;
1871 specs
->typedef_p
= true;
1872 specs
->type
= init_type
;
1875 bool maybe_const
= true;
1876 tree type_expr
= c_fully_fold (init
.value
, false,
1878 specs
->expr_const_operands
&= maybe_const
;
1880 specs
->expr
= build2 (COMPOUND_EXPR
,
1881 TREE_TYPE (type_expr
),
1882 specs
->expr
, type_expr
);
1884 specs
->expr
= type_expr
;
1886 d
= start_decl (declarator
, specs
, true,
1887 chainon (postfix_attrs
, all_prefix_attrs
));
1889 d
= error_mark_node
;
1890 if (omp_declare_simd_clauses
.exists ()
1891 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1892 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1893 omp_declare_simd_clauses
);
1897 /* The declaration of the variable is in effect while
1898 its initializer is parsed. */
1899 d
= start_decl (declarator
, specs
, true,
1900 chainon (postfix_attrs
, all_prefix_attrs
));
1902 d
= error_mark_node
;
1903 if (omp_declare_simd_clauses
.exists ()
1904 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1905 c_finish_omp_declare_simd (parser
, d
, NULL_TREE
,
1906 omp_declare_simd_clauses
);
1907 start_init (d
, asm_name
, global_bindings_p ());
1908 init_loc
= c_parser_peek_token (parser
)->location
;
1909 init
= c_parser_initializer (parser
);
1912 if (oacc_routine_data
)
1913 c_finish_oacc_routine (oacc_routine_data
, d
, false);
1914 if (d
!= error_mark_node
)
1916 maybe_warn_string_init (init_loc
, TREE_TYPE (d
), init
);
1917 finish_decl (d
, init_loc
, init
.value
,
1918 init
.original_type
, asm_name
);
1926 "%<__auto_type%> requires an initialized "
1927 "data declaration");
1928 c_parser_skip_to_end_of_block_or_statement (parser
);
1931 tree d
= start_decl (declarator
, specs
, false,
1932 chainon (postfix_attrs
,
1934 if (omp_declare_simd_clauses
.exists ()
1935 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
1937 tree parms
= NULL_TREE
;
1938 if (d
&& TREE_CODE (d
) == FUNCTION_DECL
)
1940 struct c_declarator
*ce
= declarator
;
1942 if (ce
->kind
== cdk_function
)
1944 parms
= ce
->u
.arg_info
->parms
;
1948 ce
= ce
->declarator
;
1951 temp_store_parm_decls (d
, parms
);
1952 c_finish_omp_declare_simd (parser
, d
, parms
,
1953 omp_declare_simd_clauses
);
1955 temp_pop_parm_decls ();
1957 if (oacc_routine_data
)
1958 c_finish_oacc_routine (oacc_routine_data
, d
, false);
1960 finish_decl (d
, UNKNOWN_LOCATION
, NULL_TREE
,
1961 NULL_TREE
, asm_name
);
1963 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1966 *objc_foreach_object_declaration
= d
;
1968 *objc_foreach_object_declaration
= error_mark_node
;
1971 if (c_parser_next_token_is (parser
, CPP_COMMA
))
1976 "%<__auto_type%> may only be used with"
1977 " a single declarator");
1978 c_parser_skip_to_end_of_block_or_statement (parser
);
1981 c_parser_consume_token (parser
);
1982 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
1983 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
1986 all_prefix_attrs
= prefix_attrs
;
1989 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1991 c_parser_consume_token (parser
);
1994 else if (c_parser_next_token_is_keyword (parser
, RID_IN
))
1996 /* This can only happen in Objective-C: we found the
1997 'in' that terminates the declaration inside an
1998 Objective-C foreach statement. Do not consume the
1999 token, so that the caller can use it to determine
2000 that this indeed is a foreach context. */
2005 c_parser_error (parser
, "expected %<,%> or %<;%>");
2006 c_parser_skip_to_end_of_block_or_statement (parser
);
2010 else if (auto_type_p
)
2013 "%<__auto_type%> requires an initialized data declaration");
2014 c_parser_skip_to_end_of_block_or_statement (parser
);
2019 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, "
2020 "%<asm%> or %<__attribute__%>");
2021 c_parser_skip_to_end_of_block_or_statement (parser
);
2024 /* Function definition (nested or otherwise). */
2027 pedwarn (here
, OPT_Wpedantic
, "ISO C forbids nested functions");
2028 c_push_function_context ();
2030 if (!start_function (specs
, declarator
, all_prefix_attrs
))
2032 /* This can appear in many cases looking nothing like a
2033 function definition, so we don't give a more specific
2034 error suggesting there was one. */
2035 c_parser_error (parser
, "expected %<=%>, %<,%>, %<;%>, %<asm%> "
2036 "or %<__attribute__%>");
2038 c_pop_function_context ();
2042 if (DECL_DECLARED_INLINE_P (current_function_decl
))
2043 tv
= TV_PARSE_INLINE
;
2048 /* Parse old-style parameter declarations. ??? Attributes are
2049 not allowed to start declaration specifiers here because of a
2050 syntax conflict between a function declaration with attribute
2051 suffix and a function definition with an attribute prefix on
2052 first old-style parameter declaration. Following the old
2053 parser, they are not accepted on subsequent old-style
2054 parameter declarations either. However, there is no
2055 ambiguity after the first declaration, nor indeed on the
2056 first as long as we don't allow postfix attributes after a
2057 declarator with a nonempty identifier list in a definition;
2058 and postfix attributes have never been accepted here in
2059 function definitions either. */
2060 while (c_parser_next_token_is_not (parser
, CPP_EOF
)
2061 && c_parser_next_token_is_not (parser
, CPP_OPEN_BRACE
))
2062 c_parser_declaration_or_fndef (parser
, false, false, false,
2063 true, false, NULL
, vNULL
);
2064 store_parm_decls ();
2065 if (omp_declare_simd_clauses
.exists ()
2066 || !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
2067 c_finish_omp_declare_simd (parser
, current_function_decl
, NULL_TREE
,
2068 omp_declare_simd_clauses
);
2069 if (oacc_routine_data
)
2070 c_finish_oacc_routine (oacc_routine_data
, current_function_decl
, true);
2071 DECL_STRUCT_FUNCTION (current_function_decl
)->function_start_locus
2072 = c_parser_peek_token (parser
)->location
;
2074 /* If the definition was marked with __GIMPLE then parse the
2075 function body as GIMPLE. */
2076 if (specs
->gimple_p
)
2078 cfun
->pass_startwith
= specs
->gimple_pass
;
2079 bool saved
= in_late_binary_op
;
2080 in_late_binary_op
= true;
2081 c_parser_parse_gimple_body (parser
);
2082 in_late_binary_op
= saved
;
2086 fnbody
= c_parser_compound_statement (parser
);
2087 if (flag_cilkplus
&& contains_array_notation_expr (fnbody
))
2088 fnbody
= expand_array_notation_exprs (fnbody
);
2090 tree fndecl
= current_function_decl
;
2093 tree decl
= current_function_decl
;
2094 /* Mark nested functions as needing static-chain initially.
2095 lower_nested_functions will recompute it but the
2096 DECL_STATIC_CHAIN flag is also used before that happens,
2097 by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */
2098 DECL_STATIC_CHAIN (decl
) = 1;
2101 c_pop_function_context ();
2102 add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
));
2110 /* Get rid of the empty stmt list for GIMPLE. */
2111 if (specs
->gimple_p
)
2112 DECL_SAVED_TREE (fndecl
) = NULL_TREE
;
2119 /* Parse an asm-definition (asm() outside a function body). This is a
2127 c_parser_asm_definition (c_parser
*parser
)
2129 tree asm_str
= c_parser_simple_asm_expr (parser
);
2131 symtab
->finalize_toplevel_asm (asm_str
);
2132 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
2135 /* Parse a static assertion (C11 6.7.10).
2137 static_assert-declaration:
2138 static_assert-declaration-no-semi ;
2142 c_parser_static_assert_declaration (c_parser
*parser
)
2144 c_parser_static_assert_declaration_no_semi (parser
);
2146 || !c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
2147 c_parser_skip_to_end_of_block_or_statement (parser
);
2150 /* Parse a static assertion (C11 6.7.10), without the trailing
2153 static_assert-declaration-no-semi:
2154 _Static_assert ( constant-expression , string-literal )
2158 c_parser_static_assert_declaration_no_semi (c_parser
*parser
)
2160 location_t assert_loc
, value_loc
;
2164 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
));
2165 assert_loc
= c_parser_peek_token (parser
)->location
;
2167 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2168 "ISO C99 does not support %<_Static_assert%>");
2170 pedwarn_c99 (assert_loc
, OPT_Wpedantic
,
2171 "ISO C90 does not support %<_Static_assert%>");
2172 c_parser_consume_token (parser
);
2173 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2175 location_t value_tok_loc
= c_parser_peek_token (parser
)->location
;
2176 value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2177 value_loc
= EXPR_LOC_OR_LOC (value
, value_tok_loc
);
2178 parser
->lex_untranslated_string
= true;
2179 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
2181 parser
->lex_untranslated_string
= false;
2184 switch (c_parser_peek_token (parser
)->type
)
2190 case CPP_UTF8STRING
:
2191 string
= c_parser_peek_token (parser
)->value
;
2192 c_parser_consume_token (parser
);
2193 parser
->lex_untranslated_string
= false;
2196 c_parser_error (parser
, "expected string literal");
2197 parser
->lex_untranslated_string
= false;
2200 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
2202 if (!INTEGRAL_TYPE_P (TREE_TYPE (value
)))
2204 error_at (value_loc
, "expression in static assertion is not an integer");
2207 if (TREE_CODE (value
) != INTEGER_CST
)
2209 value
= c_fully_fold (value
, false, NULL
);
2210 /* Strip no-op conversions. */
2211 STRIP_TYPE_NOPS (value
);
2212 if (TREE_CODE (value
) == INTEGER_CST
)
2213 pedwarn (value_loc
, OPT_Wpedantic
, "expression in static assertion "
2214 "is not an integer constant expression");
2216 if (TREE_CODE (value
) != INTEGER_CST
)
2218 error_at (value_loc
, "expression in static assertion is not constant");
2221 constant_expression_warning (value
);
2222 if (integer_zerop (value
))
2223 error_at (assert_loc
, "static assertion failed: %E", string
);
2226 /* Parse some declaration specifiers (possibly none) (C90 6.5, C99
2227 6.7), adding them to SPECS (which may already include some).
2228 Storage class specifiers are accepted iff SCSPEC_OK; type
2229 specifiers are accepted iff TYPESPEC_OK; alignment specifiers are
2230 accepted iff ALIGNSPEC_OK; attributes are accepted at the start
2231 iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK.
2233 declaration-specifiers:
2234 storage-class-specifier declaration-specifiers[opt]
2235 type-specifier declaration-specifiers[opt]
2236 type-qualifier declaration-specifiers[opt]
2237 function-specifier declaration-specifiers[opt]
2238 alignment-specifier declaration-specifiers[opt]
2240 Function specifiers (inline) are from C99, and are currently
2241 handled as storage class specifiers, as is __thread. Alignment
2242 specifiers are from C11.
2244 C90 6.5.1, C99 6.7.1:
2245 storage-class-specifier:
2253 (_Thread_local is new in C11.)
2260 (_Noreturn is new in C11.)
2262 C90 6.5.2, C99 6.7.2:
2275 [_Imaginary removed in C99 TC2]
2276 struct-or-union-specifier
2279 atomic-type-specifier
2281 (_Bool and _Complex are new in C99.)
2282 (atomic-type-specifier is new in C11.)
2284 C90 6.5.3, C99 6.7.3:
2290 address-space-qualifier
2293 (restrict is new in C99.)
2294 (_Atomic is new in C11.)
2298 declaration-specifiers:
2299 attributes declaration-specifiers[opt]
2305 identifier recognized by the target
2307 storage-class-specifier:
2321 (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037:
2322 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf)
2324 atomic-type-specifier
2325 _Atomic ( type-name )
2330 class-name objc-protocol-refs[opt]
2331 typedef-name objc-protocol-refs
2336 c_parser_declspecs (c_parser
*parser
, struct c_declspecs
*specs
,
2337 bool scspec_ok
, bool typespec_ok
, bool start_attr_ok
,
2338 bool alignspec_ok
, bool auto_type_ok
,
2339 enum c_lookahead_kind la
)
2341 bool attrs_ok
= start_attr_ok
;
2342 bool seen_type
= specs
->typespec_kind
!= ctsk_none
;
2345 gcc_assert (la
== cla_prefer_id
);
2347 while (c_parser_next_token_is (parser
, CPP_NAME
)
2348 || c_parser_next_token_is (parser
, CPP_KEYWORD
)
2349 || (c_dialect_objc () && c_parser_next_token_is (parser
, CPP_LESS
)))
2351 struct c_typespec t
;
2354 location_t loc
= c_parser_peek_token (parser
)->location
;
2356 /* If we cannot accept a type, exit if the next token must start
2357 one. Also, if we already have seen a tagged definition,
2358 a typename would be an error anyway and likely the user
2359 has simply forgotten a semicolon, so we exit. */
2360 if ((!typespec_ok
|| specs
->typespec_kind
== ctsk_tagdef
)
2361 && c_parser_next_tokens_start_typename (parser
, la
)
2362 && !c_parser_next_token_is_qualifier (parser
))
2365 if (c_parser_next_token_is (parser
, CPP_NAME
))
2367 c_token
*name_token
= c_parser_peek_token (parser
);
2368 tree value
= name_token
->value
;
2369 c_id_kind kind
= name_token
->id_kind
;
2371 if (kind
== C_ID_ADDRSPACE
)
2374 = name_token
->keyword
- RID_FIRST_ADDR_SPACE
;
2375 declspecs_add_addrspace (name_token
->location
, specs
, as
);
2376 c_parser_consume_token (parser
);
2381 gcc_assert (!c_parser_next_token_is_qualifier (parser
));
2383 /* If we cannot accept a type, and the next token must start one,
2384 exit. Do the same if we already have seen a tagged definition,
2385 since it would be an error anyway and likely the user has simply
2386 forgotten a semicolon. */
2387 if (seen_type
|| !c_parser_next_tokens_start_typename (parser
, la
))
2390 /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or
2391 a C_ID_CLASSNAME. */
2392 c_parser_consume_token (parser
);
2395 if (kind
== C_ID_ID
)
2397 error_at (loc
, "unknown type name %qE", value
);
2398 t
.kind
= ctsk_typedef
;
2399 t
.spec
= error_mark_node
;
2401 else if (kind
== C_ID_TYPENAME
2402 && (!c_dialect_objc ()
2403 || c_parser_next_token_is_not (parser
, CPP_LESS
)))
2405 t
.kind
= ctsk_typedef
;
2406 /* For a typedef name, record the meaning, not the name.
2407 In case of 'foo foo, bar;'. */
2408 t
.spec
= lookup_name (value
);
2412 tree proto
= NULL_TREE
;
2413 gcc_assert (c_dialect_objc ());
2415 if (c_parser_next_token_is (parser
, CPP_LESS
))
2416 proto
= c_parser_objc_protocol_refs (parser
);
2417 t
.spec
= objc_get_protocol_qualified_type (value
, proto
);
2420 t
.expr_const_operands
= true;
2421 declspecs_add_type (name_token
->location
, specs
, t
);
2424 if (c_parser_next_token_is (parser
, CPP_LESS
))
2426 /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" -
2427 nisse@lysator.liu.se. */
2429 gcc_assert (c_dialect_objc ());
2430 if (!typespec_ok
|| seen_type
)
2432 proto
= c_parser_objc_protocol_refs (parser
);
2434 t
.spec
= objc_get_protocol_qualified_type (NULL_TREE
, proto
);
2436 t
.expr_const_operands
= true;
2437 declspecs_add_type (loc
, specs
, t
);
2440 gcc_assert (c_parser_next_token_is (parser
, CPP_KEYWORD
));
2441 switch (c_parser_peek_token (parser
)->keyword
)
2454 /* TODO: Distinguish between function specifiers (inline, noreturn)
2455 and storage class specifiers, either here or in
2456 declspecs_add_scspec. */
2457 declspecs_add_scspec (loc
, specs
,
2458 c_parser_peek_token (parser
)->value
);
2459 c_parser_consume_token (parser
);
2491 if (c_dialect_objc ())
2492 parser
->objc_need_raw_identifier
= true;
2493 t
.kind
= ctsk_resword
;
2494 t
.spec
= c_parser_peek_token (parser
)->value
;
2496 t
.expr_const_operands
= true;
2497 declspecs_add_type (loc
, specs
, t
);
2498 c_parser_consume_token (parser
);
2505 t
= c_parser_enum_specifier (parser
);
2506 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2507 declspecs_add_type (loc
, specs
, t
);
2515 t
= c_parser_struct_or_union_specifier (parser
);
2516 invoke_plugin_callbacks (PLUGIN_FINISH_TYPE
, t
.spec
);
2517 declspecs_add_type (loc
, specs
, t
);
2520 /* ??? The old parser rejected typeof after other type
2521 specifiers, but is a syntax error the best way of
2523 if (!typespec_ok
|| seen_type
)
2527 t
= c_parser_typeof_specifier (parser
);
2528 declspecs_add_type (loc
, specs
, t
);
2531 /* C parser handling of Objective-C constructs needs
2532 checking for correct lvalue-to-rvalue conversions, and
2533 the code in build_modify_expr handling various
2534 Objective-C cases, and that in build_unary_op handling
2535 Objective-C cases for increment / decrement, also needs
2536 updating; uses of TYPE_MAIN_VARIANT in objc_compare_types
2537 and objc_types_are_equivalent may also need updates. */
2538 if (c_dialect_objc ())
2539 sorry ("%<_Atomic%> in Objective-C");
2541 pedwarn_c99 (loc
, OPT_Wpedantic
,
2542 "ISO C99 does not support the %<_Atomic%> qualifier");
2544 pedwarn_c99 (loc
, OPT_Wpedantic
,
2545 "ISO C90 does not support the %<_Atomic%> qualifier");
2548 value
= c_parser_peek_token (parser
)->value
;
2549 c_parser_consume_token (parser
);
2550 if (typespec_ok
&& c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
2552 /* _Atomic ( type-name ). */
2554 c_parser_consume_token (parser
);
2555 struct c_type_name
*type
= c_parser_type_name (parser
);
2556 t
.kind
= ctsk_typeof
;
2557 t
.spec
= error_mark_node
;
2559 t
.expr_const_operands
= true;
2561 t
.spec
= groktypename (type
, &t
.expr
,
2562 &t
.expr_const_operands
);
2563 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2565 if (t
.spec
!= error_mark_node
)
2567 if (TREE_CODE (t
.spec
) == ARRAY_TYPE
)
2568 error_at (loc
, "%<_Atomic%>-qualified array type");
2569 else if (TREE_CODE (t
.spec
) == FUNCTION_TYPE
)
2570 error_at (loc
, "%<_Atomic%>-qualified function type");
2571 else if (TYPE_QUALS (t
.spec
) != TYPE_UNQUALIFIED
)
2572 error_at (loc
, "%<_Atomic%> applied to a qualified type");
2574 t
.spec
= c_build_qualified_type (t
.spec
, TYPE_QUAL_ATOMIC
);
2576 declspecs_add_type (loc
, specs
, t
);
2579 declspecs_add_qual (loc
, specs
, value
);
2585 declspecs_add_qual (loc
, specs
, c_parser_peek_token (parser
)->value
);
2586 c_parser_consume_token (parser
);
2591 attrs
= c_parser_attributes (parser
);
2592 declspecs_add_attrs (loc
, specs
, attrs
);
2597 align
= c_parser_alignas_specifier (parser
);
2598 declspecs_add_alignas (loc
, specs
, align
);
2602 error_at (loc
, "%<__GIMPLE%> only valid with -fgimple");
2603 c_parser_consume_token (parser
);
2604 specs
->gimple_p
= true;
2605 specs
->locations
[cdw_gimple
] = loc
;
2606 specs
->gimple_pass
= c_parser_gimple_pass_list (parser
);
2615 /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2).
2618 enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt]
2619 enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt]
2620 enum attributes[opt] identifier
2622 The form with trailing comma is new in C99. The forms with
2623 attributes are GNU extensions. In GNU C, we accept any expression
2624 without commas in the syntax (assignment expressions, not just
2625 conditional expressions); assignment expressions will be diagnosed
2630 enumerator-list , enumerator
2633 enumeration-constant
2634 enumeration-constant = constant-expression
2639 enumeration-constant attributes[opt]
2640 enumeration-constant attributes[opt] = constant-expression
2644 static struct c_typespec
2645 c_parser_enum_specifier (c_parser
*parser
)
2647 struct c_typespec ret
;
2649 tree ident
= NULL_TREE
;
2650 location_t enum_loc
;
2651 location_t ident_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2652 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ENUM
));
2653 enum_loc
= c_parser_peek_token (parser
)->location
;
2654 c_parser_consume_token (parser
);
2655 attrs
= c_parser_attributes (parser
);
2656 enum_loc
= c_parser_peek_token (parser
)->location
;
2657 /* Set the location in case we create a decl now. */
2658 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2659 if (c_parser_next_token_is (parser
, CPP_NAME
))
2661 ident
= c_parser_peek_token (parser
)->value
;
2662 ident_loc
= c_parser_peek_token (parser
)->location
;
2663 enum_loc
= ident_loc
;
2664 c_parser_consume_token (parser
);
2666 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2668 /* Parse an enum definition. */
2669 struct c_enum_contents the_enum
;
2672 /* We chain the enumerators in reverse order, then put them in
2673 forward order at the end. */
2675 timevar_push (TV_PARSE_ENUM
);
2676 type
= start_enum (enum_loc
, &the_enum
, ident
);
2678 c_parser_consume_token (parser
);
2686 location_t comma_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
2687 location_t decl_loc
, value_loc
;
2688 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
2690 /* Give a nicer error for "enum {}". */
2691 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
2694 error_at (c_parser_peek_token (parser
)->location
,
2695 "empty enum is invalid");
2696 parser
->error
= true;
2699 c_parser_error (parser
, "expected identifier");
2700 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2701 values
= error_mark_node
;
2704 token
= c_parser_peek_token (parser
);
2705 enum_id
= token
->value
;
2706 /* Set the location in case we create a decl now. */
2707 c_parser_set_source_position_from_token (token
);
2708 decl_loc
= value_loc
= token
->location
;
2709 c_parser_consume_token (parser
);
2710 /* Parse any specified attributes. */
2711 tree enum_attrs
= c_parser_attributes (parser
);
2712 if (c_parser_next_token_is (parser
, CPP_EQ
))
2714 c_parser_consume_token (parser
);
2715 value_loc
= c_parser_peek_token (parser
)->location
;
2716 enum_value
= c_parser_expr_no_commas (parser
, NULL
).value
;
2719 enum_value
= NULL_TREE
;
2720 enum_decl
= build_enumerator (decl_loc
, value_loc
,
2721 &the_enum
, enum_id
, enum_value
);
2723 decl_attributes (&TREE_PURPOSE (enum_decl
), enum_attrs
, 0);
2724 TREE_CHAIN (enum_decl
) = values
;
2727 if (c_parser_next_token_is (parser
, CPP_COMMA
))
2729 comma_loc
= c_parser_peek_token (parser
)->location
;
2731 c_parser_consume_token (parser
);
2733 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2736 pedwarn_c90 (comma_loc
, OPT_Wpedantic
,
2737 "comma at end of enumerator list");
2738 c_parser_consume_token (parser
);
2743 c_parser_error (parser
, "expected %<,%> or %<}%>");
2744 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2745 values
= error_mark_node
;
2749 postfix_attrs
= c_parser_attributes (parser
);
2750 ret
.spec
= finish_enum (type
, nreverse (values
),
2751 chainon (attrs
, postfix_attrs
));
2752 ret
.kind
= ctsk_tagdef
;
2753 ret
.expr
= NULL_TREE
;
2754 ret
.expr_const_operands
= true;
2755 timevar_pop (TV_PARSE_ENUM
);
2760 c_parser_error (parser
, "expected %<{%>");
2761 ret
.spec
= error_mark_node
;
2762 ret
.kind
= ctsk_tagref
;
2763 ret
.expr
= NULL_TREE
;
2764 ret
.expr_const_operands
= true;
2767 ret
= parser_xref_tag (ident_loc
, ENUMERAL_TYPE
, ident
);
2768 /* In ISO C, enumerated types can be referred to only if already
2770 if (pedantic
&& !COMPLETE_TYPE_P (ret
.spec
))
2773 pedwarn (enum_loc
, OPT_Wpedantic
,
2774 "ISO C forbids forward references to %<enum%> types");
2779 /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1).
2781 struct-or-union-specifier:
2782 struct-or-union attributes[opt] identifier[opt]
2783 { struct-contents } attributes[opt]
2784 struct-or-union attributes[opt] identifier
2787 struct-declaration-list
2789 struct-declaration-list:
2790 struct-declaration ;
2791 struct-declaration-list struct-declaration ;
2798 struct-declaration-list struct-declaration
2800 struct-declaration-list:
2801 struct-declaration-list ;
2804 (Note that in the syntax here, unlike that in ISO C, the semicolons
2805 are included here rather than in struct-declaration, in order to
2806 describe the syntax with extra semicolons and missing semicolon at
2811 struct-declaration-list:
2812 @defs ( class-name )
2814 (Note this does not include a trailing semicolon, but can be
2815 followed by further declarations, and gets a pedwarn-if-pedantic
2816 when followed by a semicolon.) */
2818 static struct c_typespec
2819 c_parser_struct_or_union_specifier (c_parser
*parser
)
2821 struct c_typespec ret
;
2823 tree ident
= NULL_TREE
;
2824 location_t struct_loc
;
2825 location_t ident_loc
= UNKNOWN_LOCATION
;
2826 enum tree_code code
;
2827 switch (c_parser_peek_token (parser
)->keyword
)
2838 struct_loc
= c_parser_peek_token (parser
)->location
;
2839 c_parser_consume_token (parser
);
2840 attrs
= c_parser_attributes (parser
);
2842 /* Set the location in case we create a decl now. */
2843 c_parser_set_source_position_from_token (c_parser_peek_token (parser
));
2845 if (c_parser_next_token_is (parser
, CPP_NAME
))
2847 ident
= c_parser_peek_token (parser
)->value
;
2848 ident_loc
= c_parser_peek_token (parser
)->location
;
2849 struct_loc
= ident_loc
;
2850 c_parser_consume_token (parser
);
2852 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
2854 /* Parse a struct or union definition. Start the scope of the
2855 tag before parsing components. */
2856 struct c_struct_parse_info
*struct_info
;
2857 tree type
= start_struct (struct_loc
, code
, ident
, &struct_info
);
2859 /* We chain the components in reverse order, then put them in
2860 forward order at the end. Each struct-declaration may
2861 declare multiple components (comma-separated), so we must use
2862 chainon to join them, although when parsing each
2863 struct-declaration we can use TREE_CHAIN directly.
2865 The theory behind all this is that there will be more
2866 semicolon separated fields than comma separated fields, and
2867 so we'll be minimizing the number of node traversals required
2870 timevar_push (TV_PARSE_STRUCT
);
2871 contents
= NULL_TREE
;
2872 c_parser_consume_token (parser
);
2873 /* Handle the Objective-C @defs construct,
2874 e.g. foo(sizeof(struct{ @defs(ClassName) }));. */
2875 if (c_parser_next_token_is_keyword (parser
, RID_AT_DEFS
))
2878 gcc_assert (c_dialect_objc ());
2879 c_parser_consume_token (parser
);
2880 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
2882 if (c_parser_next_token_is (parser
, CPP_NAME
)
2883 && c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
)
2885 name
= c_parser_peek_token (parser
)->value
;
2886 c_parser_consume_token (parser
);
2890 c_parser_error (parser
, "expected class name");
2891 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
2894 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
2896 contents
= nreverse (objc_get_class_ivars (name
));
2899 /* Parse the struct-declarations and semicolons. Problems with
2900 semicolons are diagnosed here; empty structures are diagnosed
2905 /* Parse any stray semicolon. */
2906 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2908 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
2909 "extra semicolon in struct or union specified");
2910 c_parser_consume_token (parser
);
2913 /* Stop if at the end of the struct or union contents. */
2914 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2916 c_parser_consume_token (parser
);
2919 /* Accept #pragmas at struct scope. */
2920 if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
2922 c_parser_pragma (parser
, pragma_struct
, NULL
);
2925 /* Parse some comma-separated declarations, but not the
2926 trailing semicolon if any. */
2927 decls
= c_parser_struct_declaration (parser
);
2928 contents
= chainon (decls
, contents
);
2929 /* If no semicolon follows, either we have a parse error or
2930 are at the end of the struct or union and should
2932 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
2933 c_parser_consume_token (parser
);
2936 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
2937 pedwarn (c_parser_peek_token (parser
)->location
, 0,
2938 "no semicolon at end of struct or union");
2939 else if (parser
->error
2940 || !c_parser_next_token_starts_declspecs (parser
))
2942 c_parser_error (parser
, "expected %<;%>");
2943 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
2947 /* If we come here, we have already emitted an error
2948 for an expected `;', identifier or `(', and we also
2949 recovered already. Go on with the next field. */
2952 postfix_attrs
= c_parser_attributes (parser
);
2953 ret
.spec
= finish_struct (struct_loc
, type
, nreverse (contents
),
2954 chainon (attrs
, postfix_attrs
), struct_info
);
2955 ret
.kind
= ctsk_tagdef
;
2956 ret
.expr
= NULL_TREE
;
2957 ret
.expr_const_operands
= true;
2958 timevar_pop (TV_PARSE_STRUCT
);
2963 c_parser_error (parser
, "expected %<{%>");
2964 ret
.spec
= error_mark_node
;
2965 ret
.kind
= ctsk_tagref
;
2966 ret
.expr
= NULL_TREE
;
2967 ret
.expr_const_operands
= true;
2970 ret
= parser_xref_tag (ident_loc
, code
, ident
);
2974 /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without*
2975 the trailing semicolon.
2978 specifier-qualifier-list struct-declarator-list
2979 static_assert-declaration-no-semi
2981 specifier-qualifier-list:
2982 type-specifier specifier-qualifier-list[opt]
2983 type-qualifier specifier-qualifier-list[opt]
2984 attributes specifier-qualifier-list[opt]
2986 struct-declarator-list:
2988 struct-declarator-list , attributes[opt] struct-declarator
2991 declarator attributes[opt]
2992 declarator[opt] : constant-expression attributes[opt]
2997 __extension__ struct-declaration
2998 specifier-qualifier-list
3000 Unlike the ISO C syntax, semicolons are handled elsewhere. The use
3001 of attributes where shown is a GNU extension. In GNU C, we accept
3002 any expression without commas in the syntax (assignment
3003 expressions, not just conditional expressions); assignment
3004 expressions will be diagnosed as non-constant. */
3007 c_parser_struct_declaration (c_parser
*parser
)
3009 struct c_declspecs
*specs
;
3011 tree all_prefix_attrs
;
3013 location_t decl_loc
;
3014 if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
3018 ext
= disable_extension_diagnostics ();
3019 c_parser_consume_token (parser
);
3020 decl
= c_parser_struct_declaration (parser
);
3021 restore_extension_diagnostics (ext
);
3024 if (c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
3026 c_parser_static_assert_declaration_no_semi (parser
);
3029 specs
= build_null_declspecs ();
3030 decl_loc
= c_parser_peek_token (parser
)->location
;
3031 /* Strictly by the standard, we shouldn't allow _Alignas here,
3032 but it appears to have been intended to allow it there, so
3033 we're keeping it as it is until WG14 reaches a conclusion
3035 <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */
3036 c_parser_declspecs (parser
, specs
, false, true, true,
3037 true, false, cla_nonabstract_decl
);
3040 if (!specs
->declspecs_seen_p
)
3042 c_parser_error (parser
, "expected specifier-qualifier-list");
3045 finish_declspecs (specs
);
3046 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3047 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3050 if (specs
->typespec_kind
== ctsk_none
)
3052 pedwarn (decl_loc
, OPT_Wpedantic
,
3053 "ISO C forbids member declarations with no members");
3054 shadow_tag_warned (specs
, pedantic
);
3059 /* Support for unnamed structs or unions as members of
3060 structs or unions (which is [a] useful and [b] supports
3064 ret
= grokfield (c_parser_peek_token (parser
)->location
,
3065 build_id_declarator (NULL_TREE
), specs
,
3068 decl_attributes (&ret
, attrs
, 0);
3073 /* Provide better error recovery. Note that a type name here is valid,
3074 and will be treated as a field name. */
3075 if (specs
->typespec_kind
== ctsk_tagdef
3076 && TREE_CODE (specs
->type
) != ENUMERAL_TYPE
3077 && c_parser_next_token_starts_declspecs (parser
)
3078 && !c_parser_next_token_is (parser
, CPP_NAME
))
3080 c_parser_error (parser
, "expected %<;%>, identifier or %<(%>");
3081 parser
->error
= false;
3085 pending_xref_error ();
3086 prefix_attrs
= specs
->attrs
;
3087 all_prefix_attrs
= prefix_attrs
;
3088 specs
->attrs
= NULL_TREE
;
3092 /* Declaring one or more declarators or un-named bit-fields. */
3093 struct c_declarator
*declarator
;
3095 if (c_parser_next_token_is (parser
, CPP_COLON
))
3096 declarator
= build_id_declarator (NULL_TREE
);
3098 declarator
= c_parser_declarator (parser
,
3099 specs
->typespec_kind
!= ctsk_none
,
3100 C_DTR_NORMAL
, &dummy
);
3101 if (declarator
== NULL
)
3103 c_parser_skip_to_end_of_block_or_statement (parser
);
3106 if (c_parser_next_token_is (parser
, CPP_COLON
)
3107 || c_parser_next_token_is (parser
, CPP_COMMA
)
3108 || c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3109 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
)
3110 || c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3112 tree postfix_attrs
= NULL_TREE
;
3113 tree width
= NULL_TREE
;
3115 if (c_parser_next_token_is (parser
, CPP_COLON
))
3117 c_parser_consume_token (parser
);
3118 width
= c_parser_expr_no_commas (parser
, NULL
).value
;
3120 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3121 postfix_attrs
= c_parser_attributes (parser
);
3122 d
= grokfield (c_parser_peek_token (parser
)->location
,
3123 declarator
, specs
, width
, &all_prefix_attrs
);
3124 decl_attributes (&d
, chainon (postfix_attrs
,
3125 all_prefix_attrs
), 0);
3126 DECL_CHAIN (d
) = decls
;
3128 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3129 all_prefix_attrs
= chainon (c_parser_attributes (parser
),
3132 all_prefix_attrs
= prefix_attrs
;
3133 if (c_parser_next_token_is (parser
, CPP_COMMA
))
3134 c_parser_consume_token (parser
);
3135 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
3136 || c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
3138 /* Semicolon consumed in caller. */
3143 c_parser_error (parser
, "expected %<,%>, %<;%> or %<}%>");
3149 c_parser_error (parser
,
3150 "expected %<:%>, %<,%>, %<;%>, %<}%> or "
3151 "%<__attribute__%>");
3158 /* Parse a typeof specifier (a GNU extension).
3161 typeof ( expression )
3162 typeof ( type-name )
3165 static struct c_typespec
3166 c_parser_typeof_specifier (c_parser
*parser
)
3168 struct c_typespec ret
;
3169 ret
.kind
= ctsk_typeof
;
3170 ret
.spec
= error_mark_node
;
3171 ret
.expr
= NULL_TREE
;
3172 ret
.expr_const_operands
= true;
3173 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TYPEOF
));
3174 c_parser_consume_token (parser
);
3175 c_inhibit_evaluation_warnings
++;
3177 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3179 c_inhibit_evaluation_warnings
--;
3183 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3185 struct c_type_name
*type
= c_parser_type_name (parser
);
3186 c_inhibit_evaluation_warnings
--;
3190 ret
.spec
= groktypename (type
, &ret
.expr
, &ret
.expr_const_operands
);
3191 pop_maybe_used (variably_modified_type_p (ret
.spec
, NULL_TREE
));
3197 location_t here
= c_parser_peek_token (parser
)->location
;
3198 struct c_expr expr
= c_parser_expression (parser
);
3199 c_inhibit_evaluation_warnings
--;
3201 if (TREE_CODE (expr
.value
) == COMPONENT_REF
3202 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
3203 error_at (here
, "%<typeof%> applied to a bit-field");
3204 mark_exp_read (expr
.value
);
3205 ret
.spec
= TREE_TYPE (expr
.value
);
3206 was_vm
= variably_modified_type_p (ret
.spec
, NULL_TREE
);
3207 /* This is returned with the type so that when the type is
3208 evaluated, this can be evaluated. */
3210 ret
.expr
= c_fully_fold (expr
.value
, false, &ret
.expr_const_operands
);
3211 pop_maybe_used (was_vm
);
3212 /* For use in macros such as those in <stdatomic.h>, remove all
3213 qualifiers from atomic types. (const can be an issue for more macros
3214 using typeof than just the <stdatomic.h> ones.) */
3215 if (ret
.spec
!= error_mark_node
&& TYPE_ATOMIC (ret
.spec
))
3216 ret
.spec
= c_build_qualified_type (ret
.spec
, TYPE_UNQUALIFIED
);
3218 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3222 /* Parse an alignment-specifier.
3226 alignment-specifier:
3227 _Alignas ( type-name )
3228 _Alignas ( constant-expression )
3232 c_parser_alignas_specifier (c_parser
* parser
)
3234 tree ret
= error_mark_node
;
3235 location_t loc
= c_parser_peek_token (parser
)->location
;
3236 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNAS
));
3237 c_parser_consume_token (parser
);
3239 pedwarn_c99 (loc
, OPT_Wpedantic
,
3240 "ISO C99 does not support %<_Alignas%>");
3242 pedwarn_c99 (loc
, OPT_Wpedantic
,
3243 "ISO C90 does not support %<_Alignas%>");
3244 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3246 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_id
))
3248 struct c_type_name
*type
= c_parser_type_name (parser
);
3250 ret
= c_sizeof_or_alignof_type (loc
, groktypename (type
, NULL
, NULL
),
3254 ret
= c_parser_expr_no_commas (parser
, NULL
).value
;
3255 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
3259 /* Parse a declarator, possibly an abstract declarator (C90 6.5.4,
3260 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may
3261 be redeclared; otherwise it may not. KIND indicates which kind of
3262 declarator is wanted. Returns a valid declarator except in the
3263 case of a syntax error in which case NULL is returned. *SEEN_ID is
3264 set to true if an identifier being declared is seen; this is used
3265 to diagnose bad forms of abstract array declarators and to
3266 determine whether an identifier list is syntactically permitted.
3269 pointer[opt] direct-declarator
3273 ( attributes[opt] declarator )
3274 direct-declarator array-declarator
3275 direct-declarator ( parameter-type-list )
3276 direct-declarator ( identifier-list[opt] )
3279 * type-qualifier-list[opt]
3280 * type-qualifier-list[opt] pointer
3282 type-qualifier-list:
3285 type-qualifier-list type-qualifier
3286 type-qualifier-list attributes
3289 [ type-qualifier-list[opt] assignment-expression[opt] ]
3290 [ static type-qualifier-list[opt] assignment-expression ]
3291 [ type-qualifier-list static assignment-expression ]
3292 [ type-qualifier-list[opt] * ]
3294 parameter-type-list:
3296 parameter-list , ...
3299 parameter-declaration
3300 parameter-list , parameter-declaration
3302 parameter-declaration:
3303 declaration-specifiers declarator attributes[opt]
3304 declaration-specifiers abstract-declarator[opt] attributes[opt]
3308 identifier-list , identifier
3310 abstract-declarator:
3312 pointer[opt] direct-abstract-declarator
3314 direct-abstract-declarator:
3315 ( attributes[opt] abstract-declarator )
3316 direct-abstract-declarator[opt] array-declarator
3317 direct-abstract-declarator[opt] ( parameter-type-list[opt] )
3322 direct-declarator ( parameter-forward-declarations
3323 parameter-type-list[opt] )
3325 direct-abstract-declarator:
3326 direct-abstract-declarator[opt] ( parameter-forward-declarations
3327 parameter-type-list[opt] )
3329 parameter-forward-declarations:
3331 parameter-forward-declarations parameter-list ;
3333 The uses of attributes shown above are GNU extensions.
3335 Some forms of array declarator are not included in C99 in the
3336 syntax for abstract declarators; these are disallowed elsewhere.
3337 This may be a defect (DR#289).
3339 This function also accepts an omitted abstract declarator as being
3340 an abstract declarator, although not part of the formal syntax. */
3342 struct c_declarator
*
3343 c_parser_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3346 /* Parse any initial pointer part. */
3347 if (c_parser_next_token_is (parser
, CPP_MULT
))
3349 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3350 struct c_declarator
*inner
;
3351 c_parser_consume_token (parser
);
3352 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3353 false, false, cla_prefer_id
);
3354 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3358 return make_pointer_declarator (quals_attrs
, inner
);
3360 /* Now we have a direct declarator, direct abstract declarator or
3361 nothing (which counts as a direct abstract declarator here). */
3362 return c_parser_direct_declarator (parser
, type_seen_p
, kind
, seen_id
);
3365 /* Parse a direct declarator or direct abstract declarator; arguments
3366 as c_parser_declarator. */
3368 static struct c_declarator
*
3369 c_parser_direct_declarator (c_parser
*parser
, bool type_seen_p
, c_dtr_syn kind
,
3372 /* The direct declarator must start with an identifier (possibly
3373 omitted) or a parenthesized declarator (possibly abstract). In
3374 an ordinary declarator, initial parentheses must start a
3375 parenthesized declarator. In an abstract declarator or parameter
3376 declarator, they could start a parenthesized declarator or a
3377 parameter list. To tell which, the open parenthesis and any
3378 following attributes must be read. If a declaration specifier
3379 follows, then it is a parameter list; if the specifier is a
3380 typedef name, there might be an ambiguity about redeclaring it,
3381 which is resolved in the direction of treating it as a typedef
3382 name. If a close parenthesis follows, it is also an empty
3383 parameter list, as the syntax does not permit empty abstract
3384 declarators. Otherwise, it is a parenthesized declarator (in
3385 which case the analysis may be repeated inside it, recursively).
3387 ??? There is an ambiguity in a parameter declaration "int
3388 (__attribute__((foo)) x)", where x is not a typedef name: it
3389 could be an abstract declarator for a function, or declare x with
3390 parentheses. The proper resolution of this ambiguity needs
3391 documenting. At present we follow an accident of the old
3392 parser's implementation, whereby the first parameter must have
3393 some declaration specifiers other than just attributes. Thus as
3394 a parameter declaration it is treated as a parenthesized
3395 parameter named x, and as an abstract declarator it is
3398 ??? Also following the old parser, attributes inside an empty
3399 parameter list are ignored, making it a list not yielding a
3400 prototype, rather than giving an error or making it have one
3401 parameter with implicit type int.
3403 ??? Also following the old parser, typedef names may be
3404 redeclared in declarators, but not Objective-C class names. */
3406 if (kind
!= C_DTR_ABSTRACT
3407 && c_parser_next_token_is (parser
, CPP_NAME
)
3409 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
3410 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
3411 || c_parser_peek_token (parser
)->id_kind
== C_ID_ID
))
3413 struct c_declarator
*inner
3414 = build_id_declarator (c_parser_peek_token (parser
)->value
);
3416 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3417 c_parser_consume_token (parser
);
3418 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3421 if (kind
!= C_DTR_NORMAL
3422 && c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3424 struct c_declarator
*inner
= build_id_declarator (NULL_TREE
);
3425 inner
->id_loc
= c_parser_peek_token (parser
)->location
;
3426 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3429 /* Either we are at the end of an abstract declarator, or we have
3432 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3435 struct c_declarator
*inner
;
3436 c_parser_consume_token (parser
);
3437 attrs
= c_parser_attributes (parser
);
3438 if (kind
!= C_DTR_NORMAL
3439 && (c_parser_next_token_starts_declspecs (parser
)
3440 || c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
)))
3442 struct c_arg_info
*args
3443 = c_parser_parms_declarator (parser
, kind
== C_DTR_NORMAL
,
3450 = build_function_declarator (args
,
3451 build_id_declarator (NULL_TREE
));
3452 return c_parser_direct_declarator_inner (parser
, *seen_id
,
3456 /* A parenthesized declarator. */
3457 inner
= c_parser_declarator (parser
, type_seen_p
, kind
, seen_id
);
3458 if (inner
!= NULL
&& attrs
!= NULL
)
3459 inner
= build_attrs_declarator (attrs
, inner
);
3460 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3462 c_parser_consume_token (parser
);
3466 return c_parser_direct_declarator_inner (parser
, *seen_id
, inner
);
3470 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3477 if (kind
== C_DTR_NORMAL
)
3479 c_parser_error (parser
, "expected identifier or %<(%>");
3483 return build_id_declarator (NULL_TREE
);
3487 /* Parse part of a direct declarator or direct abstract declarator,
3488 given that some (in INNER) has already been parsed; ID_PRESENT is
3489 true if an identifier is present, false for an abstract
3492 static struct c_declarator
*
3493 c_parser_direct_declarator_inner (c_parser
*parser
, bool id_present
,
3494 struct c_declarator
*inner
)
3496 /* Parse a sequence of array declarators and parameter lists. */
3497 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
3499 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
3500 struct c_declarator
*declarator
;
3501 struct c_declspecs
*quals_attrs
= build_null_declspecs ();
3504 struct c_expr dimen
;
3505 dimen
.value
= NULL_TREE
;
3506 dimen
.original_code
= ERROR_MARK
;
3507 dimen
.original_type
= NULL_TREE
;
3508 c_parser_consume_token (parser
);
3509 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3510 false, false, cla_prefer_id
);
3511 static_seen
= c_parser_next_token_is_keyword (parser
, RID_STATIC
);
3513 c_parser_consume_token (parser
);
3514 if (static_seen
&& !quals_attrs
->declspecs_seen_p
)
3515 c_parser_declspecs (parser
, quals_attrs
, false, false, true,
3516 false, false, cla_prefer_id
);
3517 if (!quals_attrs
->declspecs_seen_p
)
3519 /* If "static" is present, there must be an array dimension.
3520 Otherwise, there may be a dimension, "*", or no
3525 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3529 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3531 dimen
.value
= NULL_TREE
;
3534 else if (flag_cilkplus
3535 && c_parser_next_token_is (parser
, CPP_COLON
))
3537 dimen
.value
= error_mark_node
;
3539 error_at (c_parser_peek_token (parser
)->location
,
3540 "array notations cannot be used in declaration");
3541 c_parser_consume_token (parser
);
3543 else if (c_parser_next_token_is (parser
, CPP_MULT
))
3545 if (c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_SQUARE
)
3547 dimen
.value
= NULL_TREE
;
3549 c_parser_consume_token (parser
);
3554 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3560 dimen
= c_parser_expr_no_commas (parser
, NULL
);
3563 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
3564 c_parser_consume_token (parser
);
3565 else if (flag_cilkplus
3566 && c_parser_next_token_is (parser
, CPP_COLON
))
3568 error_at (c_parser_peek_token (parser
)->location
,
3569 "array notations cannot be used in declaration");
3570 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
3575 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
3580 dimen
= convert_lvalue_to_rvalue (brace_loc
, dimen
, true, true);
3581 declarator
= build_array_declarator (brace_loc
, dimen
.value
, quals_attrs
,
3582 static_seen
, star_seen
);
3583 if (declarator
== NULL
)
3585 inner
= set_array_declarator_inner (declarator
, inner
);
3586 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3588 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
3591 struct c_arg_info
*args
;
3592 c_parser_consume_token (parser
);
3593 attrs
= c_parser_attributes (parser
);
3594 args
= c_parser_parms_declarator (parser
, id_present
, attrs
);
3599 inner
= build_function_declarator (args
, inner
);
3600 return c_parser_direct_declarator_inner (parser
, id_present
, inner
);
3606 /* Parse a parameter list or identifier list, including the closing
3607 parenthesis but not the opening one. ATTRS are the attributes at
3608 the start of the list. ID_LIST_OK is true if an identifier list is
3609 acceptable; such a list must not have attributes at the start. */
3611 static struct c_arg_info
*
3612 c_parser_parms_declarator (c_parser
*parser
, bool id_list_ok
, tree attrs
)
3615 declare_parm_level ();
3616 /* If the list starts with an identifier, it is an identifier list.
3617 Otherwise, it is either a prototype list or an empty list. */
3620 && c_parser_next_token_is (parser
, CPP_NAME
)
3621 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
3623 /* Look ahead to detect typos in type names. */
3624 && c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
3625 && c_parser_peek_2nd_token (parser
)->type
!= CPP_MULT
3626 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
3627 && c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_SQUARE
3628 && c_parser_peek_2nd_token (parser
)->type
!= CPP_KEYWORD
)
3630 tree list
= NULL_TREE
, *nextp
= &list
;
3631 while (c_parser_next_token_is (parser
, CPP_NAME
)
3632 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
3634 *nextp
= build_tree_list (NULL_TREE
,
3635 c_parser_peek_token (parser
)->value
);
3636 nextp
= & TREE_CHAIN (*nextp
);
3637 c_parser_consume_token (parser
);
3638 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
3640 c_parser_consume_token (parser
);
3641 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3643 c_parser_error (parser
, "expected identifier");
3647 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3649 struct c_arg_info
*ret
= build_arg_info ();
3651 c_parser_consume_token (parser
);
3657 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3665 struct c_arg_info
*ret
= c_parser_parms_list_declarator (parser
, attrs
,
3672 /* Parse a parameter list (possibly empty), including the closing
3673 parenthesis but not the opening one. ATTRS are the attributes at
3674 the start of the list. EXPR is NULL or an expression that needs to
3675 be evaluated for the side effects of array size expressions in the
3678 static struct c_arg_info
*
3679 c_parser_parms_list_declarator (c_parser
*parser
, tree attrs
, tree expr
)
3681 bool bad_parm
= false;
3683 /* ??? Following the old parser, forward parameter declarations may
3684 use abstract declarators, and if no real parameter declarations
3685 follow the forward declarations then this is not diagnosed. Also
3686 note as above that attributes are ignored as the only contents of
3687 the parentheses, or as the only contents after forward
3689 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3691 struct c_arg_info
*ret
= build_arg_info ();
3692 c_parser_consume_token (parser
);
3695 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3697 struct c_arg_info
*ret
= build_arg_info ();
3699 if (flag_allow_parameterless_variadic_functions
)
3701 /* F (...) is allowed. */
3702 ret
->types
= NULL_TREE
;
3706 /* Suppress -Wold-style-definition for this case. */
3707 ret
->types
= error_mark_node
;
3708 error_at (c_parser_peek_token (parser
)->location
,
3709 "ISO C requires a named argument before %<...%>");
3711 c_parser_consume_token (parser
);
3712 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3714 c_parser_consume_token (parser
);
3719 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3724 /* Nonempty list of parameters, either terminated with semicolon
3725 (forward declarations; recurse) or with close parenthesis (normal
3726 function) or with ", ... )" (variadic function). */
3729 /* Parse a parameter. */
3730 struct c_parm
*parm
= c_parser_parameter_declaration (parser
, attrs
);
3735 push_parm_decl (parm
, &expr
);
3736 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
3739 c_parser_consume_token (parser
);
3740 mark_forward_parm_decls ();
3741 new_attrs
= c_parser_attributes (parser
);
3742 return c_parser_parms_list_declarator (parser
, new_attrs
, expr
);
3744 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3746 c_parser_consume_token (parser
);
3750 return get_parm_info (false, expr
);
3752 if (!c_parser_require (parser
, CPP_COMMA
,
3753 "expected %<;%>, %<,%> or %<)%>"))
3755 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3758 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
3760 c_parser_consume_token (parser
);
3761 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
3763 c_parser_consume_token (parser
);
3767 return get_parm_info (true, expr
);
3771 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
3779 /* Parse a parameter declaration. ATTRS are the attributes at the
3780 start of the declaration if it is the first parameter. */
3782 static struct c_parm
*
3783 c_parser_parameter_declaration (c_parser
*parser
, tree attrs
)
3785 struct c_declspecs
*specs
;
3786 struct c_declarator
*declarator
;
3788 tree postfix_attrs
= NULL_TREE
;
3791 /* Accept #pragmas between parameter declarations. */
3792 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
3793 c_parser_pragma (parser
, pragma_param
, NULL
);
3795 if (!c_parser_next_token_starts_declspecs (parser
))
3797 c_token
*token
= c_parser_peek_token (parser
);
3800 c_parser_set_source_position_from_token (token
);
3801 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
3803 const char *hint
= lookup_name_fuzzy (token
->value
,
3804 FUZZY_LOOKUP_TYPENAME
);
3807 gcc_rich_location
richloc (token
->location
);
3808 richloc
.add_fixit_replace (hint
);
3809 error_at_rich_loc (&richloc
,
3810 "unknown type name %qE; did you mean %qs?",
3811 token
->value
, hint
);
3814 error_at (token
->location
, "unknown type name %qE", token
->value
);
3815 parser
->error
= true;
3817 /* ??? In some Objective-C cases '...' isn't applicable so there
3818 should be a different message. */
3820 c_parser_error (parser
,
3821 "expected declaration specifiers or %<...%>");
3822 c_parser_skip_to_end_of_parameter (parser
);
3825 specs
= build_null_declspecs ();
3828 declspecs_add_attrs (input_location
, specs
, attrs
);
3831 c_parser_declspecs (parser
, specs
, true, true, true, true, false,
3832 cla_nonabstract_decl
);
3833 finish_declspecs (specs
);
3834 pending_xref_error ();
3835 prefix_attrs
= specs
->attrs
;
3836 specs
->attrs
= NULL_TREE
;
3837 declarator
= c_parser_declarator (parser
,
3838 specs
->typespec_kind
!= ctsk_none
,
3839 C_DTR_PARM
, &dummy
);
3840 if (declarator
== NULL
)
3842 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
3845 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
3846 postfix_attrs
= c_parser_attributes (parser
);
3847 return build_c_parm (specs
, chainon (postfix_attrs
, prefix_attrs
),
3851 /* Parse a string literal in an asm expression. It should not be
3852 translated, and wide string literals are an error although
3853 permitted by the syntax. This is a GNU extension.
3858 ??? At present, following the old parser, the caller needs to have
3859 set lex_untranslated_string to 1. It would be better to follow the
3860 C++ parser rather than using this kludge. */
3863 c_parser_asm_string_literal (c_parser
*parser
)
3866 int save_flag
= warn_overlength_strings
;
3867 warn_overlength_strings
= 0;
3868 if (c_parser_next_token_is (parser
, CPP_STRING
))
3870 str
= c_parser_peek_token (parser
)->value
;
3871 c_parser_consume_token (parser
);
3873 else if (c_parser_next_token_is (parser
, CPP_WSTRING
))
3875 error_at (c_parser_peek_token (parser
)->location
,
3876 "wide string literal in %<asm%>");
3877 str
= build_string (1, "");
3878 c_parser_consume_token (parser
);
3882 c_parser_error (parser
, "expected string literal");
3885 warn_overlength_strings
= save_flag
;
3889 /* Parse a simple asm expression. This is used in restricted
3890 contexts, where a full expression with inputs and outputs does not
3891 make sense. This is a GNU extension.
3894 asm ( asm-string-literal )
3898 c_parser_simple_asm_expr (c_parser
*parser
)
3901 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
3902 /* ??? Follow the C++ parser rather than using the
3903 lex_untranslated_string kludge. */
3904 parser
->lex_untranslated_string
= true;
3905 c_parser_consume_token (parser
);
3906 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
3908 parser
->lex_untranslated_string
= false;
3911 str
= c_parser_asm_string_literal (parser
);
3912 parser
->lex_untranslated_string
= false;
3913 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
3915 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
3922 c_parser_attribute_any_word (c_parser
*parser
)
3924 tree attr_name
= NULL_TREE
;
3926 if (c_parser_next_token_is (parser
, CPP_KEYWORD
))
3928 /* ??? See comment above about what keywords are accepted here. */
3930 switch (c_parser_peek_token (parser
)->keyword
)
3961 case RID_TRANSACTION_ATOMIC
:
3962 case RID_TRANSACTION_CANCEL
:
3978 /* Accept __attribute__((__const)) as __attribute__((const)) etc. */
3979 attr_name
= ridpointers
[(int) c_parser_peek_token (parser
)->keyword
];
3981 else if (c_parser_next_token_is (parser
, CPP_NAME
))
3982 attr_name
= c_parser_peek_token (parser
)->value
;
3987 #define CILK_SIMD_FN_CLAUSE_MASK \
3988 ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \
3989 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \
3990 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \
3991 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \
3992 | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK))
3994 /* Parses the vector attribute of SIMD enabled functions in Cilk Plus.
3995 VEC_TOKEN is the "vector" token that is replaced with "simd" and
3996 pushed into the token list.
3999 vector (<vector attributes>). */
4002 c_parser_cilk_simd_fn_vector_attrs (c_parser
*parser
, c_token vec_token
)
4004 gcc_assert (is_cilkplus_vector_p (vec_token
.value
));
4006 int paren_scope
= 0;
4007 vec_safe_push (parser
->cilk_simd_fn_tokens
, vec_token
);
4008 /* Consume the "vector" token. */
4009 c_parser_consume_token (parser
);
4011 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
4013 c_parser_consume_token (parser
);
4016 while (paren_scope
> 0)
4018 c_token
*token
= c_parser_peek_token (parser
);
4019 if (token
->type
== CPP_OPEN_PAREN
)
4021 else if (token
->type
== CPP_CLOSE_PAREN
)
4023 /* Do not push the last ')' since we are not pushing the '('. */
4024 if (!(token
->type
== CPP_CLOSE_PAREN
&& paren_scope
== 0))
4025 vec_safe_push (parser
->cilk_simd_fn_tokens
, *token
);
4026 c_parser_consume_token (parser
);
4029 /* Since we are converting an attribute to a pragma, we need to end the
4030 attribute with PRAGMA_EOL. */
4032 memset (&eol_token
, 0, sizeof (eol_token
));
4033 eol_token
.type
= CPP_PRAGMA_EOL
;
4034 vec_safe_push (parser
->cilk_simd_fn_tokens
, eol_token
);
4037 /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */
4040 c_finish_cilk_simd_fn_tokens (c_parser
*parser
)
4042 c_token last_token
= parser
->cilk_simd_fn_tokens
->last ();
4044 /* c_parser_attributes is called in several places, so if these EOF
4045 tokens are already inserted, then don't do them again. */
4046 if (last_token
.type
== CPP_EOF
)
4049 /* Two CPP_EOF token are added as a safety net since the normal C
4050 front-end has two token look-ahead. */
4052 eof_token
.type
= CPP_EOF
;
4053 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
4054 vec_safe_push (parser
->cilk_simd_fn_tokens
, eof_token
);
4057 /* Parse (possibly empty) attributes. This is a GNU extension.
4061 attributes attribute
4064 __attribute__ ( ( attribute-list ) )
4068 attribute_list , attrib
4073 any-word ( identifier )
4074 any-word ( identifier , nonempty-expr-list )
4075 any-word ( expr-list )
4077 where the "identifier" must not be declared as a type, and
4078 "any-word" may be any identifier (including one declared as a
4079 type), a reserved word storage class specifier, type specifier or
4080 type qualifier. ??? This still leaves out most reserved keywords
4081 (following the old parser), shouldn't we include them, and why not
4082 allow identifiers declared as types to start the arguments? */
4085 c_parser_attributes (c_parser
*parser
)
4087 tree attrs
= NULL_TREE
;
4088 while (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4090 /* ??? Follow the C++ parser rather than using the
4091 lex_untranslated_string kludge. */
4092 parser
->lex_untranslated_string
= true;
4093 /* Consume the `__attribute__' keyword. */
4094 c_parser_consume_token (parser
);
4095 /* Look for the two `(' tokens. */
4096 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4098 parser
->lex_untranslated_string
= false;
4101 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
4103 parser
->lex_untranslated_string
= false;
4104 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
4107 /* Parse the attribute list. */
4108 while (c_parser_next_token_is (parser
, CPP_COMMA
)
4109 || c_parser_next_token_is (parser
, CPP_NAME
)
4110 || c_parser_next_token_is (parser
, CPP_KEYWORD
))
4112 tree attr
, attr_name
, attr_args
;
4113 vec
<tree
, va_gc
> *expr_list
;
4114 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4116 c_parser_consume_token (parser
);
4120 attr_name
= c_parser_attribute_any_word (parser
);
4121 if (attr_name
== NULL
)
4123 if (is_cilkplus_vector_p (attr_name
))
4125 c_token
*v_token
= c_parser_peek_token (parser
);
4126 c_parser_cilk_simd_fn_vector_attrs (parser
, *v_token
);
4127 /* If the next token isn't a comma, we're done. */
4128 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4132 c_parser_consume_token (parser
);
4133 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
4135 attr
= build_tree_list (attr_name
, NULL_TREE
);
4136 /* Add this attribute to the list. */
4137 attrs
= chainon (attrs
, attr
);
4138 /* If the next token isn't a comma, we're done. */
4139 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4143 c_parser_consume_token (parser
);
4144 /* Parse the attribute contents. If they start with an
4145 identifier which is followed by a comma or close
4146 parenthesis, then the arguments start with that
4147 identifier; otherwise they are an expression list.
4148 In objective-c the identifier may be a classname. */
4149 if (c_parser_next_token_is (parser
, CPP_NAME
)
4150 && (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
4151 || (c_dialect_objc ()
4152 && c_parser_peek_token (parser
)->id_kind
4154 && ((c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
)
4155 || (c_parser_peek_2nd_token (parser
)->type
4156 == CPP_CLOSE_PAREN
))
4157 && (attribute_takes_identifier_p (attr_name
)
4158 || (c_dialect_objc ()
4159 && c_parser_peek_token (parser
)->id_kind
4160 == C_ID_CLASSNAME
)))
4162 tree arg1
= c_parser_peek_token (parser
)->value
;
4163 c_parser_consume_token (parser
);
4164 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4165 attr_args
= build_tree_list (NULL_TREE
, arg1
);
4169 c_parser_consume_token (parser
);
4170 expr_list
= c_parser_expr_list (parser
, false, true,
4171 NULL
, NULL
, NULL
, NULL
);
4172 tree_list
= build_tree_list_vec (expr_list
);
4173 attr_args
= tree_cons (NULL_TREE
, arg1
, tree_list
);
4174 release_tree_vector (expr_list
);
4179 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4180 attr_args
= NULL_TREE
;
4183 expr_list
= c_parser_expr_list (parser
, false, true,
4184 NULL
, NULL
, NULL
, NULL
);
4185 attr_args
= build_tree_list_vec (expr_list
);
4186 release_tree_vector (expr_list
);
4189 attr
= build_tree_list (attr_name
, attr_args
);
4190 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4191 c_parser_consume_token (parser
);
4194 parser
->lex_untranslated_string
= false;
4195 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4199 /* Add this attribute to the list. */
4200 attrs
= chainon (attrs
, attr
);
4201 /* If the next token isn't a comma, we're done. */
4202 if (!c_parser_next_token_is (parser
, CPP_COMMA
))
4205 /* Look for the two `)' tokens. */
4206 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4207 c_parser_consume_token (parser
);
4210 parser
->lex_untranslated_string
= false;
4211 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4215 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
4216 c_parser_consume_token (parser
);
4219 parser
->lex_untranslated_string
= false;
4220 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
4224 parser
->lex_untranslated_string
= false;
4227 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
4228 c_finish_cilk_simd_fn_tokens (parser
);
4232 /* Parse a type name (C90 6.5.5, C99 6.7.6).
4235 specifier-qualifier-list abstract-declarator[opt]
4238 struct c_type_name
*
4239 c_parser_type_name (c_parser
*parser
)
4241 struct c_declspecs
*specs
= build_null_declspecs ();
4242 struct c_declarator
*declarator
;
4243 struct c_type_name
*ret
;
4245 c_parser_declspecs (parser
, specs
, false, true, true, false, false,
4247 if (!specs
->declspecs_seen_p
)
4249 c_parser_error (parser
, "expected specifier-qualifier-list");
4252 if (specs
->type
!= error_mark_node
)
4254 pending_xref_error ();
4255 finish_declspecs (specs
);
4257 declarator
= c_parser_declarator (parser
,
4258 specs
->typespec_kind
!= ctsk_none
,
4259 C_DTR_ABSTRACT
, &dummy
);
4260 if (declarator
== NULL
)
4262 ret
= XOBNEW (&parser_obstack
, struct c_type_name
);
4264 ret
->declarator
= declarator
;
4268 /* Parse an initializer (C90 6.5.7, C99 6.7.8).
4271 assignment-expression
4272 { initializer-list }
4273 { initializer-list , }
4276 designation[opt] initializer
4277 initializer-list , designation[opt] initializer
4284 designator-list designator
4291 [ constant-expression ]
4303 [ constant-expression ... constant-expression ]
4305 Any expression without commas is accepted in the syntax for the
4306 constant-expressions, with non-constant expressions rejected later.
4308 This function is only used for top-level initializers; for nested
4309 ones, see c_parser_initval. */
4311 static struct c_expr
4312 c_parser_initializer (c_parser
*parser
)
4314 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
4315 return c_parser_braced_init (parser
, NULL_TREE
, false, NULL
);
4319 location_t loc
= c_parser_peek_token (parser
)->location
;
4320 ret
= c_parser_expr_no_commas (parser
, NULL
);
4321 if (TREE_CODE (ret
.value
) != STRING_CST
4322 && TREE_CODE (ret
.value
) != COMPOUND_LITERAL_EXPR
)
4323 ret
= convert_lvalue_to_rvalue (loc
, ret
, true, true);
4328 /* Parse a braced initializer list. TYPE is the type specified for a
4329 compound literal, and NULL_TREE for other initializers and for
4330 nested braced lists. NESTED_P is true for nested braced lists,
4331 false for the list of a compound literal or the list that is the
4332 top-level initializer in a declaration. */
4334 static struct c_expr
4335 c_parser_braced_init (c_parser
*parser
, tree type
, bool nested_p
,
4336 struct obstack
*outer_obstack
)
4339 struct obstack braced_init_obstack
;
4340 location_t brace_loc
= c_parser_peek_token (parser
)->location
;
4341 gcc_obstack_init (&braced_init_obstack
);
4342 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
4343 c_parser_consume_token (parser
);
4346 finish_implicit_inits (brace_loc
, outer_obstack
);
4347 push_init_level (brace_loc
, 0, &braced_init_obstack
);
4350 really_start_incremental_init (type
);
4351 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4353 pedwarn (brace_loc
, OPT_Wpedantic
, "ISO C forbids empty initializer braces");
4357 /* Parse a non-empty initializer list, possibly with a trailing
4361 c_parser_initelt (parser
, &braced_init_obstack
);
4364 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4365 c_parser_consume_token (parser
);
4368 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4372 c_token
*next_tok
= c_parser_peek_token (parser
);
4373 if (next_tok
->type
!= CPP_CLOSE_BRACE
)
4375 ret
.value
= error_mark_node
;
4376 ret
.original_code
= ERROR_MARK
;
4377 ret
.original_type
= NULL
;
4378 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
4379 pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4380 obstack_free (&braced_init_obstack
, NULL
);
4383 location_t close_loc
= next_tok
->location
;
4384 c_parser_consume_token (parser
);
4385 ret
= pop_init_level (brace_loc
, 0, &braced_init_obstack
);
4386 obstack_free (&braced_init_obstack
, NULL
);
4387 set_c_expr_source_range (&ret
, brace_loc
, close_loc
);
4391 /* Parse a nested initializer, including designators. */
4394 c_parser_initelt (c_parser
*parser
, struct obstack
* braced_init_obstack
)
4396 /* Parse any designator or designator list. A single array
4397 designator may have the subsequent "=" omitted in GNU C, but a
4398 longer list or a structure member designator may not. */
4399 if (c_parser_next_token_is (parser
, CPP_NAME
)
4400 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
4402 /* Old-style structure member designator. */
4403 set_init_label (c_parser_peek_token (parser
)->location
,
4404 c_parser_peek_token (parser
)->value
,
4405 c_parser_peek_token (parser
)->location
,
4406 braced_init_obstack
);
4407 /* Use the colon as the error location. */
4408 pedwarn (c_parser_peek_2nd_token (parser
)->location
, OPT_Wpedantic
,
4409 "obsolete use of designated initializer with %<:%>");
4410 c_parser_consume_token (parser
);
4411 c_parser_consume_token (parser
);
4415 /* des_seen is 0 if there have been no designators, 1 if there
4416 has been a single array designator and 2 otherwise. */
4418 /* Location of a designator. */
4419 location_t des_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4420 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
)
4421 || c_parser_next_token_is (parser
, CPP_DOT
))
4423 int des_prev
= des_seen
;
4425 des_loc
= c_parser_peek_token (parser
)->location
;
4428 if (c_parser_next_token_is (parser
, CPP_DOT
))
4431 c_parser_consume_token (parser
);
4432 if (c_parser_next_token_is (parser
, CPP_NAME
))
4434 set_init_label (des_loc
, c_parser_peek_token (parser
)->value
,
4435 c_parser_peek_token (parser
)->location
,
4436 braced_init_obstack
);
4437 c_parser_consume_token (parser
);
4442 init
.value
= error_mark_node
;
4443 init
.original_code
= ERROR_MARK
;
4444 init
.original_type
= NULL
;
4445 c_parser_error (parser
, "expected identifier");
4446 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4447 process_init_element (input_location
, init
, false,
4448 braced_init_obstack
);
4455 location_t ellipsis_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4456 location_t array_index_loc
= UNKNOWN_LOCATION
;
4457 /* ??? Following the old parser, [ objc-receiver
4458 objc-message-args ] is accepted as an initializer,
4459 being distinguished from a designator by what follows
4460 the first assignment expression inside the square
4461 brackets, but after a first array designator a
4462 subsequent square bracket is for Objective-C taken to
4463 start an expression, using the obsolete form of
4464 designated initializer without '=', rather than
4465 possibly being a second level of designation: in LALR
4466 terms, the '[' is shifted rather than reducing
4467 designator to designator-list. */
4468 if (des_prev
== 1 && c_dialect_objc ())
4470 des_seen
= des_prev
;
4473 if (des_prev
== 0 && c_dialect_objc ())
4475 /* This might be an array designator or an
4476 Objective-C message expression. If the former,
4477 continue parsing here; if the latter, parse the
4478 remainder of the initializer given the starting
4479 primary-expression. ??? It might make sense to
4480 distinguish when des_prev == 1 as well; see
4481 previous comment. */
4483 struct c_expr mexpr
;
4484 c_parser_consume_token (parser
);
4485 if (c_parser_peek_token (parser
)->type
== CPP_NAME
4486 && ((c_parser_peek_token (parser
)->id_kind
4488 || (c_parser_peek_token (parser
)->id_kind
4489 == C_ID_CLASSNAME
)))
4491 /* Type name receiver. */
4492 tree id
= c_parser_peek_token (parser
)->value
;
4493 c_parser_consume_token (parser
);
4494 rec
= objc_get_class_reference (id
);
4495 goto parse_message_args
;
4497 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4498 mark_exp_read (first
);
4499 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
)
4500 || c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4501 goto array_desig_after_first
;
4502 /* Expression receiver. So far only one part
4503 without commas has been parsed; there might be
4504 more of the expression. */
4506 while (c_parser_next_token_is (parser
, CPP_COMMA
))
4509 location_t comma_loc
, exp_loc
;
4510 comma_loc
= c_parser_peek_token (parser
)->location
;
4511 c_parser_consume_token (parser
);
4512 exp_loc
= c_parser_peek_token (parser
)->location
;
4513 next
= c_parser_expr_no_commas (parser
, NULL
);
4514 next
= convert_lvalue_to_rvalue (exp_loc
, next
,
4516 rec
= build_compound_expr (comma_loc
, rec
, next
.value
);
4519 /* Now parse the objc-message-args. */
4520 args
= c_parser_objc_message_args (parser
);
4521 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4524 = objc_build_message_expr (rec
, args
);
4525 mexpr
.original_code
= ERROR_MARK
;
4526 mexpr
.original_type
= NULL
;
4527 /* Now parse and process the remainder of the
4528 initializer, starting with this message
4529 expression as a primary-expression. */
4530 c_parser_initval (parser
, &mexpr
, braced_init_obstack
);
4533 c_parser_consume_token (parser
);
4534 array_index_loc
= c_parser_peek_token (parser
)->location
;
4535 first
= c_parser_expr_no_commas (parser
, NULL
).value
;
4536 mark_exp_read (first
);
4537 array_desig_after_first
:
4538 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4540 ellipsis_loc
= c_parser_peek_token (parser
)->location
;
4541 c_parser_consume_token (parser
);
4542 second
= c_parser_expr_no_commas (parser
, NULL
).value
;
4543 mark_exp_read (second
);
4547 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
4549 c_parser_consume_token (parser
);
4550 set_init_index (array_index_loc
, first
, second
,
4551 braced_init_obstack
);
4553 pedwarn (ellipsis_loc
, OPT_Wpedantic
,
4554 "ISO C forbids specifying range of elements to initialize");
4557 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
4563 if (c_parser_next_token_is (parser
, CPP_EQ
))
4565 pedwarn_c90 (des_loc
, OPT_Wpedantic
,
4566 "ISO C90 forbids specifying subobject "
4568 c_parser_consume_token (parser
);
4573 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
4574 "obsolete use of designated initializer without %<=%>");
4578 init
.value
= error_mark_node
;
4579 init
.original_code
= ERROR_MARK
;
4580 init
.original_type
= NULL
;
4581 c_parser_error (parser
, "expected %<=%>");
4582 c_parser_skip_until_found (parser
, CPP_COMMA
, NULL
);
4583 process_init_element (input_location
, init
, false,
4584 braced_init_obstack
);
4590 c_parser_initval (parser
, NULL
, braced_init_obstack
);
4593 /* Parse a nested initializer; as c_parser_initializer but parses
4594 initializers within braced lists, after any designators have been
4595 applied. If AFTER is not NULL then it is an Objective-C message
4596 expression which is the primary-expression starting the
4600 c_parser_initval (c_parser
*parser
, struct c_expr
*after
,
4601 struct obstack
* braced_init_obstack
)
4604 gcc_assert (!after
|| c_dialect_objc ());
4605 location_t loc
= c_parser_peek_token (parser
)->location
;
4607 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
) && !after
)
4608 init
= c_parser_braced_init (parser
, NULL_TREE
, true,
4609 braced_init_obstack
);
4612 init
= c_parser_expr_no_commas (parser
, after
);
4613 if (init
.value
!= NULL_TREE
4614 && TREE_CODE (init
.value
) != STRING_CST
4615 && TREE_CODE (init
.value
) != COMPOUND_LITERAL_EXPR
)
4616 init
= convert_lvalue_to_rvalue (loc
, init
, true, true);
4618 process_init_element (loc
, init
, false, braced_init_obstack
);
4621 /* Parse a compound statement (possibly a function body) (C90 6.6.2,
4625 { block-item-list[opt] }
4626 { label-declarations block-item-list }
4630 block-item-list block-item
4642 { label-declarations block-item-list }
4645 __extension__ nested-declaration
4646 nested-function-definition
4650 label-declarations label-declaration
4653 __label__ identifier-list ;
4655 Allowing the mixing of declarations and code is new in C99. The
4656 GNU syntax also permits (not shown above) labels at the end of
4657 compound statements, which yield an error. We don't allow labels
4658 on declarations; this might seem like a natural extension, but
4659 there would be a conflict between attributes on the label and
4660 prefix attributes on the declaration. ??? The syntax follows the
4661 old parser in requiring something after label declarations.
4662 Although they are erroneous if the labels declared aren't defined,
4663 is it useful for the syntax to be this way?
4684 cancellation-point-directive */
4687 c_parser_compound_statement (c_parser
*parser
)
4690 location_t brace_loc
;
4691 brace_loc
= c_parser_peek_token (parser
)->location
;
4692 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
4694 /* Ensure a scope is entered and left anyway to avoid confusion
4695 if we have just prepared to enter a function body. */
4696 stmt
= c_begin_compound_stmt (true);
4697 c_end_compound_stmt (brace_loc
, stmt
, true);
4698 return error_mark_node
;
4700 stmt
= c_begin_compound_stmt (true);
4701 c_parser_compound_statement_nostart (parser
);
4703 /* If the compound stmt contains array notations, then we expand them. */
4704 if (flag_cilkplus
&& contains_array_notation_expr (stmt
))
4705 stmt
= expand_array_notation_exprs (stmt
);
4706 return c_end_compound_stmt (brace_loc
, stmt
, true);
4709 /* Parse a compound statement except for the opening brace. This is
4710 used for parsing both compound statements and statement expressions
4711 (which follow different paths to handling the opening). */
4714 c_parser_compound_statement_nostart (c_parser
*parser
)
4716 bool last_stmt
= false;
4717 bool last_label
= false;
4718 bool save_valid_for_pragma
= valid_location_for_stdc_pragma_p ();
4719 location_t label_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
4720 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4722 c_parser_consume_token (parser
);
4725 mark_valid_location_for_stdc_pragma (true);
4726 if (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4728 /* Read zero or more forward-declarations for labels that nested
4729 functions can jump to. */
4730 mark_valid_location_for_stdc_pragma (false);
4731 while (c_parser_next_token_is_keyword (parser
, RID_LABEL
))
4733 label_loc
= c_parser_peek_token (parser
)->location
;
4734 c_parser_consume_token (parser
);
4735 /* Any identifiers, including those declared as type names,
4740 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
4742 c_parser_error (parser
, "expected identifier");
4746 = declare_label (c_parser_peek_token (parser
)->value
);
4747 C_DECLARED_LABEL_FLAG (label
) = 1;
4748 add_stmt (build_stmt (label_loc
, DECL_EXPR
, label
));
4749 c_parser_consume_token (parser
);
4750 if (c_parser_next_token_is (parser
, CPP_COMMA
))
4751 c_parser_consume_token (parser
);
4755 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
4757 pedwarn (label_loc
, OPT_Wpedantic
, "ISO C forbids label declarations");
4759 /* We must now have at least one statement, label or declaration. */
4760 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
4762 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4763 c_parser_error (parser
, "expected declaration or statement");
4764 c_parser_consume_token (parser
);
4767 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
4769 location_t loc
= c_parser_peek_token (parser
)->location
;
4770 if (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4771 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4772 || (c_parser_next_token_is (parser
, CPP_NAME
)
4773 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4775 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4776 label_loc
= c_parser_peek_2nd_token (parser
)->location
;
4778 label_loc
= c_parser_peek_token (parser
)->location
;
4781 mark_valid_location_for_stdc_pragma (false);
4782 c_parser_label (parser
);
4784 else if (!last_label
4785 && c_parser_next_tokens_start_declaration (parser
))
4788 mark_valid_location_for_stdc_pragma (false);
4789 bool fallthru_attr_p
= false;
4790 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4791 true, NULL
, vNULL
, NULL
,
4793 if (last_stmt
&& !fallthru_attr_p
)
4794 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4795 "ISO C90 forbids mixed declarations and code");
4796 last_stmt
= fallthru_attr_p
;
4798 else if (!last_label
4799 && c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
4801 /* __extension__ can start a declaration, but is also an
4802 unary operator that can start an expression. Consume all
4803 but the last of a possible series of __extension__ to
4805 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
4806 && (c_parser_peek_2nd_token (parser
)->keyword
4808 c_parser_consume_token (parser
);
4809 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
4812 ext
= disable_extension_diagnostics ();
4813 c_parser_consume_token (parser
);
4815 mark_valid_location_for_stdc_pragma (false);
4816 c_parser_declaration_or_fndef (parser
, true, true, true, true,
4818 /* Following the old parser, __extension__ does not
4819 disable this diagnostic. */
4820 restore_extension_diagnostics (ext
);
4822 pedwarn_c90 (loc
, OPT_Wdeclaration_after_statement
,
4823 "ISO C90 forbids mixed declarations and code");
4829 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
4831 /* External pragmas, and some omp pragmas, are not associated
4832 with regular c code, and so are not to be considered statements
4833 syntactically. This ensures that the user doesn't put them
4834 places that would turn into syntax errors if the directive
4836 if (c_parser_pragma (parser
,
4837 last_label
? pragma_stmt
: pragma_compound
,
4839 last_label
= false, last_stmt
= true;
4841 else if (c_parser_next_token_is (parser
, CPP_EOF
))
4843 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4844 c_parser_error (parser
, "expected declaration or statement");
4847 else if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
4849 if (parser
->in_if_block
)
4851 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4852 error_at (loc
, """expected %<}%> before %<else%>");
4857 error_at (loc
, "%<else%> without a previous %<if%>");
4858 c_parser_consume_token (parser
);
4867 mark_valid_location_for_stdc_pragma (false);
4868 c_parser_statement_after_labels (parser
, NULL
);
4871 parser
->error
= false;
4874 error_at (label_loc
, "label at end of compound statement");
4875 c_parser_consume_token (parser
);
4876 /* Restore the value we started with. */
4877 mark_valid_location_for_stdc_pragma (save_valid_for_pragma
);
4880 /* Parse all consecutive labels. */
4883 c_parser_all_labels (c_parser
*parser
)
4885 while (c_parser_next_token_is_keyword (parser
, RID_CASE
)
4886 || c_parser_next_token_is_keyword (parser
, RID_DEFAULT
)
4887 || (c_parser_next_token_is (parser
, CPP_NAME
)
4888 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
))
4889 c_parser_label (parser
);
4892 /* Parse a label (C90 6.6.1, C99 6.8.1).
4895 identifier : attributes[opt]
4896 case constant-expression :
4902 case constant-expression ... constant-expression :
4904 The use of attributes on labels is a GNU extension. The syntax in
4905 GNU C accepts any expressions without commas, non-constant
4906 expressions being rejected later. */
4909 c_parser_label (c_parser
*parser
)
4911 location_t loc1
= c_parser_peek_token (parser
)->location
;
4912 tree label
= NULL_TREE
;
4914 /* Remember whether this case or a user-defined label is allowed to fall
4916 bool fallthrough_p
= c_parser_peek_token (parser
)->flags
& PREV_FALLTHROUGH
;
4918 if (c_parser_next_token_is_keyword (parser
, RID_CASE
))
4921 c_parser_consume_token (parser
);
4922 exp1
= c_parser_expr_no_commas (parser
, NULL
).value
;
4923 if (c_parser_next_token_is (parser
, CPP_COLON
))
4925 c_parser_consume_token (parser
);
4926 label
= do_case (loc1
, exp1
, NULL_TREE
);
4928 else if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
4930 c_parser_consume_token (parser
);
4931 exp2
= c_parser_expr_no_commas (parser
, NULL
).value
;
4932 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4933 label
= do_case (loc1
, exp1
, exp2
);
4936 c_parser_error (parser
, "expected %<:%> or %<...%>");
4938 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
4940 c_parser_consume_token (parser
);
4941 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
4942 label
= do_case (loc1
, NULL_TREE
, NULL_TREE
);
4946 tree name
= c_parser_peek_token (parser
)->value
;
4949 location_t loc2
= c_parser_peek_token (parser
)->location
;
4950 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
4951 c_parser_consume_token (parser
);
4952 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
4953 c_parser_consume_token (parser
);
4954 attrs
= c_parser_attributes (parser
);
4955 tlab
= define_label (loc2
, name
);
4958 decl_attributes (&tlab
, attrs
, 0);
4959 label
= add_stmt (build_stmt (loc1
, LABEL_EXPR
, tlab
));
4964 if (TREE_CODE (label
) == LABEL_EXPR
)
4965 FALLTHROUGH_LABEL_P (LABEL_EXPR_LABEL (label
)) = fallthrough_p
;
4967 FALLTHROUGH_LABEL_P (CASE_LABEL (label
)) = fallthrough_p
;
4969 /* Allow '__attribute__((fallthrough));'. */
4970 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
4972 location_t loc
= c_parser_peek_token (parser
)->location
;
4973 tree attrs
= c_parser_attributes (parser
);
4974 if (attribute_fallthrough_p (attrs
))
4976 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
4978 tree fn
= build_call_expr_internal_loc (loc
,
4984 warning_at (loc
, OPT_Wattributes
, "%<fallthrough%> attribute "
4985 "not followed by %<;%>");
4987 else if (attrs
!= NULL_TREE
)
4988 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
4989 " can be applied to a null statement");
4991 if (c_parser_next_tokens_start_declaration (parser
))
4993 error_at (c_parser_peek_token (parser
)->location
,
4994 "a label can only be part of a statement and "
4995 "a declaration is not a statement");
4996 c_parser_declaration_or_fndef (parser
, /*fndef_ok*/ false,
4997 /*static_assert_ok*/ true,
4998 /*empty_ok*/ true, /*nested*/ true,
4999 /*start_attr_ok*/ true, NULL
,
5005 /* Parse a statement (C90 6.6, C99 6.8).
5010 expression-statement
5018 expression-statement:
5021 selection-statement:
5025 iteration-statement:
5034 return expression[opt] ;
5044 expression-statement:
5050 objc-throw-statement
5051 objc-try-catch-statement
5052 objc-synchronized-statement
5054 objc-throw-statement:
5070 parallel-directive structured-block
5073 kernels-directive structured-block
5076 data-directive structured-block
5079 loop-directive structured-block
5093 parallel-for-construct
5094 parallel-for-simd-construct
5095 parallel-sections-construct
5102 parallel-directive structured-block
5105 for-directive iteration-statement
5108 simd-directive iteration-statements
5111 for-simd-directive iteration-statements
5114 sections-directive section-scope
5117 single-directive structured-block
5119 parallel-for-construct:
5120 parallel-for-directive iteration-statement
5122 parallel-for-simd-construct:
5123 parallel-for-simd-directive iteration-statement
5125 parallel-sections-construct:
5126 parallel-sections-directive section-scope
5129 master-directive structured-block
5132 critical-directive structured-block
5135 atomic-directive expression-statement
5138 ordered-directive structured-block
5140 Transactional Memory:
5143 transaction-statement
5144 transaction-cancel-statement
5146 IF_P is used to track whether there's a (possibly labeled) if statement
5147 which is not enclosed in braces and has an else clause. This is used to
5148 implement -Wparentheses. */
5151 c_parser_statement (c_parser
*parser
, bool *if_p
)
5153 c_parser_all_labels (parser
);
5154 c_parser_statement_after_labels (parser
, if_p
, NULL
);
5157 /* Parse a statement, other than a labeled statement. CHAIN is a vector
5158 of if-else-if conditions.
5160 IF_P is used to track whether there's a (possibly labeled) if statement
5161 which is not enclosed in braces and has an else clause. This is used to
5162 implement -Wparentheses. */
5165 c_parser_statement_after_labels (c_parser
*parser
, bool *if_p
,
5168 location_t loc
= c_parser_peek_token (parser
)->location
;
5169 tree stmt
= NULL_TREE
;
5170 bool in_if_block
= parser
->in_if_block
;
5171 parser
->in_if_block
= false;
5174 switch (c_parser_peek_token (parser
)->type
)
5176 case CPP_OPEN_BRACE
:
5177 add_stmt (c_parser_compound_statement (parser
));
5180 switch (c_parser_peek_token (parser
)->keyword
)
5183 c_parser_if_statement (parser
, if_p
, chain
);
5186 c_parser_switch_statement (parser
, if_p
);
5189 c_parser_while_statement (parser
, false, if_p
);
5192 c_parser_do_statement (parser
, false);
5195 c_parser_for_statement (parser
, false, if_p
);
5200 error_at (c_parser_peek_token (parser
)->location
,
5201 "-fcilkplus must be enabled to use %<_Cilk_for%>");
5202 c_parser_skip_to_end_of_block_or_statement (parser
);
5205 c_parser_cilk_for (parser
, integer_zero_node
, if_p
);
5208 c_parser_consume_token (parser
);
5209 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5211 error_at (loc
, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
5213 add_stmt (build_cilk_sync ());
5216 c_parser_consume_token (parser
);
5217 if (c_parser_next_token_is (parser
, CPP_NAME
))
5219 stmt
= c_finish_goto_label (loc
,
5220 c_parser_peek_token (parser
)->value
);
5221 c_parser_consume_token (parser
);
5223 else if (c_parser_next_token_is (parser
, CPP_MULT
))
5227 c_parser_consume_token (parser
);
5228 val
= c_parser_expression (parser
);
5229 if (check_no_cilk (val
.value
,
5230 "Cilk array notation cannot be used as a computed goto expression",
5231 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression",
5233 val
.value
= error_mark_node
;
5234 val
= convert_lvalue_to_rvalue (loc
, val
, false, true);
5235 stmt
= c_finish_goto_ptr (loc
, val
.value
);
5238 c_parser_error (parser
, "expected identifier or %<*%>");
5239 goto expect_semicolon
;
5241 c_parser_consume_token (parser
);
5242 stmt
= c_finish_bc_stmt (loc
, &c_cont_label
, false);
5243 goto expect_semicolon
;
5245 c_parser_consume_token (parser
);
5246 stmt
= c_finish_bc_stmt (loc
, &c_break_label
, true);
5247 goto expect_semicolon
;
5249 c_parser_consume_token (parser
);
5250 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5252 stmt
= c_finish_return (loc
, NULL_TREE
, NULL_TREE
);
5253 c_parser_consume_token (parser
);
5257 location_t xloc
= c_parser_peek_token (parser
)->location
;
5258 struct c_expr expr
= c_parser_expression_conv (parser
);
5259 mark_exp_read (expr
.value
);
5260 stmt
= c_finish_return (EXPR_LOC_OR_LOC (expr
.value
, xloc
),
5261 expr
.value
, expr
.original_type
);
5262 goto expect_semicolon
;
5266 stmt
= c_parser_asm_statement (parser
);
5268 case RID_TRANSACTION_ATOMIC
:
5269 case RID_TRANSACTION_RELAXED
:
5270 stmt
= c_parser_transaction (parser
,
5271 c_parser_peek_token (parser
)->keyword
);
5273 case RID_TRANSACTION_CANCEL
:
5274 stmt
= c_parser_transaction_cancel (parser
);
5275 goto expect_semicolon
;
5277 gcc_assert (c_dialect_objc ());
5278 c_parser_consume_token (parser
);
5279 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5281 stmt
= objc_build_throw_stmt (loc
, NULL_TREE
);
5282 c_parser_consume_token (parser
);
5286 struct c_expr expr
= c_parser_expression (parser
);
5287 expr
= convert_lvalue_to_rvalue (loc
, expr
, false, false);
5288 if (check_no_cilk (expr
.value
,
5289 "Cilk array notation cannot be used for a throw expression",
5290 "%<_Cilk_spawn%> statement cannot be used for a throw expression"))
5291 expr
.value
= error_mark_node
;
5294 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
5295 stmt
= objc_build_throw_stmt (loc
, expr
.value
);
5297 goto expect_semicolon
;
5301 gcc_assert (c_dialect_objc ());
5302 c_parser_objc_try_catch_finally_statement (parser
);
5304 case RID_AT_SYNCHRONIZED
:
5305 gcc_assert (c_dialect_objc ());
5306 c_parser_objc_synchronized_statement (parser
);
5310 /* Allow '__attribute__((fallthrough));'. */
5311 tree attrs
= c_parser_attributes (parser
);
5312 if (attribute_fallthrough_p (attrs
))
5314 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5316 tree fn
= build_call_expr_internal_loc (loc
,
5321 c_parser_consume_token (parser
);
5324 warning_at (loc
, OPT_Wattributes
,
5325 "%<fallthrough%> attribute not followed "
5328 else if (attrs
!= NULL_TREE
)
5329 warning_at (loc
, OPT_Wattributes
, "only attribute %<fallthrough%>"
5330 " can be applied to a null statement");
5338 c_parser_consume_token (parser
);
5340 case CPP_CLOSE_PAREN
:
5341 case CPP_CLOSE_SQUARE
:
5342 /* Avoid infinite loop in error recovery:
5343 c_parser_skip_until_found stops at a closing nesting
5344 delimiter without consuming it, but here we need to consume
5345 it to proceed further. */
5346 c_parser_error (parser
, "expected statement");
5347 c_parser_consume_token (parser
);
5350 c_parser_pragma (parser
, pragma_stmt
, if_p
);
5354 stmt
= c_finish_expr_stmt (loc
, c_parser_expression_conv (parser
).value
);
5356 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5359 /* Two cases cannot and do not have line numbers associated: If stmt
5360 is degenerate, such as "2;", then stmt is an INTEGER_CST, which
5361 cannot hold line numbers. But that's OK because the statement
5362 will either be changed to a MODIFY_EXPR during gimplification of
5363 the statement expr, or discarded. If stmt was compound, but
5364 without new variables, we will have skipped the creation of a
5365 BIND and will have a bare STATEMENT_LIST. But that's OK because
5366 (recursively) all of the component statements should already have
5367 line numbers assigned. ??? Can we discard no-op statements
5369 if (EXPR_LOCATION (stmt
) == UNKNOWN_LOCATION
)
5370 protected_set_expr_location (stmt
, loc
);
5372 parser
->in_if_block
= in_if_block
;
5375 /* Parse the condition from an if, do, while or for statements. */
5378 c_parser_condition (c_parser
*parser
)
5380 location_t loc
= c_parser_peek_token (parser
)->location
;
5382 cond
= c_parser_expression_conv (parser
).value
;
5383 cond
= c_objc_common_truthvalue_conversion (loc
, cond
);
5384 cond
= c_fully_fold (cond
, false, NULL
);
5385 if (warn_sequence_point
)
5386 verify_sequence_points (cond
);
5390 /* Parse a parenthesized condition from an if, do or while statement.
5396 c_parser_paren_condition (c_parser
*parser
)
5399 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5400 return error_mark_node
;
5401 cond
= c_parser_condition (parser
);
5402 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5406 /* Parse a statement which is a block in C99.
5408 IF_P is used to track whether there's a (possibly labeled) if statement
5409 which is not enclosed in braces and has an else clause. This is used to
5410 implement -Wparentheses. */
5413 c_parser_c99_block_statement (c_parser
*parser
, bool *if_p
)
5415 tree block
= c_begin_compound_stmt (flag_isoc99
);
5416 location_t loc
= c_parser_peek_token (parser
)->location
;
5417 c_parser_statement (parser
, if_p
);
5418 return c_end_compound_stmt (loc
, block
, flag_isoc99
);
5421 /* Parse the body of an if statement. This is just parsing a
5422 statement but (a) it is a block in C99, (b) we track whether the
5423 body is an if statement for the sake of -Wparentheses warnings, (c)
5424 we handle an empty body specially for the sake of -Wempty-body
5425 warnings, and (d) we call parser_compound_statement directly
5426 because c_parser_statement_after_labels resets
5427 parser->in_if_block.
5429 IF_P is used to track whether there's a (possibly labeled) if statement
5430 which is not enclosed in braces and has an else clause. This is used to
5431 implement -Wparentheses. */
5434 c_parser_if_body (c_parser
*parser
, bool *if_p
,
5435 const token_indent_info
&if_tinfo
)
5437 tree block
= c_begin_compound_stmt (flag_isoc99
);
5438 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5439 token_indent_info body_tinfo
5440 = get_token_indent_info (c_parser_peek_token (parser
));
5442 c_parser_all_labels (parser
);
5443 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5445 location_t loc
= c_parser_peek_token (parser
)->location
;
5446 add_stmt (build_empty_stmt (loc
));
5447 c_parser_consume_token (parser
);
5448 if (!c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5449 warning_at (loc
, OPT_Wempty_body
,
5450 "suggest braces around empty body in an %<if%> statement");
5452 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
5453 add_stmt (c_parser_compound_statement (parser
));
5455 c_parser_statement_after_labels (parser
, if_p
);
5457 token_indent_info next_tinfo
5458 = get_token_indent_info (c_parser_peek_token (parser
));
5459 warn_for_misleading_indentation (if_tinfo
, body_tinfo
, next_tinfo
);
5461 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5464 /* Parse the else body of an if statement. This is just parsing a
5465 statement but (a) it is a block in C99, (b) we handle an empty body
5466 specially for the sake of -Wempty-body warnings. CHAIN is a vector
5467 of if-else-if conditions. */
5470 c_parser_else_body (c_parser
*parser
, const token_indent_info
&else_tinfo
,
5473 location_t body_loc
= c_parser_peek_token (parser
)->location
;
5474 tree block
= c_begin_compound_stmt (flag_isoc99
);
5475 token_indent_info body_tinfo
5476 = get_token_indent_info (c_parser_peek_token (parser
));
5478 c_parser_all_labels (parser
);
5479 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5481 location_t loc
= c_parser_peek_token (parser
)->location
;
5484 "suggest braces around empty body in an %<else%> statement");
5485 add_stmt (build_empty_stmt (loc
));
5486 c_parser_consume_token (parser
);
5489 c_parser_statement_after_labels (parser
, NULL
, chain
);
5491 token_indent_info next_tinfo
5492 = get_token_indent_info (c_parser_peek_token (parser
));
5493 warn_for_misleading_indentation (else_tinfo
, body_tinfo
, next_tinfo
);
5495 return c_end_compound_stmt (body_loc
, block
, flag_isoc99
);
5498 /* We might need to reclassify any previously-lexed identifier, e.g.
5499 when we've left a for loop with an if-statement without else in the
5500 body - we might have used a wrong scope for the token. See PR67784. */
5503 c_parser_maybe_reclassify_token (c_parser
*parser
)
5505 if (c_parser_next_token_is (parser
, CPP_NAME
))
5507 c_token
*token
= c_parser_peek_token (parser
);
5509 if (token
->id_kind
!= C_ID_CLASSNAME
)
5511 tree decl
= lookup_name (token
->value
);
5513 token
->id_kind
= C_ID_ID
;
5516 if (TREE_CODE (decl
) == TYPE_DECL
)
5517 token
->id_kind
= C_ID_TYPENAME
;
5519 else if (c_dialect_objc ())
5521 tree objc_interface_decl
= objc_is_class_name (token
->value
);
5522 /* Objective-C class names are in the same namespace as
5523 variables and typedefs, and hence are shadowed by local
5525 if (objc_interface_decl
)
5527 token
->value
= objc_interface_decl
;
5528 token
->id_kind
= C_ID_CLASSNAME
;
5535 /* Parse an if statement (C90 6.6.4, C99 6.8.4).
5538 if ( expression ) statement
5539 if ( expression ) statement else statement
5541 CHAIN is a vector of if-else-if conditions.
5542 IF_P is used to track whether there's a (possibly labeled) if statement
5543 which is not enclosed in braces and has an else clause. This is used to
5544 implement -Wparentheses. */
5547 c_parser_if_statement (c_parser
*parser
, bool *if_p
, vec
<tree
> *chain
)
5552 bool nested_if
= false;
5553 tree first_body
, second_body
;
5557 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_IF
));
5558 token_indent_info if_tinfo
5559 = get_token_indent_info (c_parser_peek_token (parser
));
5560 c_parser_consume_token (parser
);
5561 block
= c_begin_compound_stmt (flag_isoc99
);
5562 loc
= c_parser_peek_token (parser
)->location
;
5563 cond
= c_parser_paren_condition (parser
);
5564 if (flag_cilkplus
&& contains_cilk_spawn_stmt (cond
))
5566 error_at (loc
, "if statement cannot contain %<Cilk_spawn%>");
5567 cond
= error_mark_node
;
5569 in_if_block
= parser
->in_if_block
;
5570 parser
->in_if_block
= true;
5571 first_body
= c_parser_if_body (parser
, &nested_if
, if_tinfo
);
5572 parser
->in_if_block
= in_if_block
;
5574 if (warn_duplicated_cond
)
5575 warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond
), cond
, &chain
);
5577 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
5579 token_indent_info else_tinfo
5580 = get_token_indent_info (c_parser_peek_token (parser
));
5581 c_parser_consume_token (parser
);
5582 if (warn_duplicated_cond
)
5584 if (c_parser_next_token_is_keyword (parser
, RID_IF
)
5587 /* We've got "if (COND) else if (COND2)". Start the
5588 condition chain and add COND as the first element. */
5589 chain
= new vec
<tree
> ();
5590 if (!CONSTANT_CLASS_P (cond
) && !TREE_SIDE_EFFECTS (cond
))
5591 chain
->safe_push (cond
);
5593 else if (!c_parser_next_token_is_keyword (parser
, RID_IF
))
5595 /* This is if-else without subsequent if. Zap the condition
5596 chain; we would have already warned at this point. */
5601 second_body
= c_parser_else_body (parser
, else_tinfo
, chain
);
5602 /* Set IF_P to true to indicate that this if statement has an
5603 else clause. This may trigger the Wparentheses warning
5604 below when we get back up to the parent if statement. */
5610 second_body
= NULL_TREE
;
5612 /* Diagnose an ambiguous else if if-then-else is nested inside
5615 warning_at (loc
, OPT_Wdangling_else
,
5616 "suggest explicit braces to avoid ambiguous %<else%>");
5618 if (warn_duplicated_cond
)
5620 /* This if statement does not have an else clause. We don't
5621 need the condition chain anymore. */
5626 c_finish_if_stmt (loc
, cond
, first_body
, second_body
);
5627 if_stmt
= c_end_compound_stmt (loc
, block
, flag_isoc99
);
5629 /* If the if statement contains array notations, then we expand them. */
5630 if (flag_cilkplus
&& contains_array_notation_expr (if_stmt
))
5631 if_stmt
= fix_conditional_array_notations (if_stmt
);
5633 c_parser_maybe_reclassify_token (parser
);
5636 /* Parse a switch statement (C90 6.6.4, C99 6.8.4).
5639 switch (expression) statement
5643 c_parser_switch_statement (c_parser
*parser
, bool *if_p
)
5646 tree block
, expr
, body
, save_break
;
5647 location_t switch_loc
= c_parser_peek_token (parser
)->location
;
5648 location_t switch_cond_loc
;
5649 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SWITCH
));
5650 c_parser_consume_token (parser
);
5651 block
= c_begin_compound_stmt (flag_isoc99
);
5652 bool explicit_cast_p
= false;
5653 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5655 switch_cond_loc
= c_parser_peek_token (parser
)->location
;
5656 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
5657 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
5658 explicit_cast_p
= true;
5659 ce
= c_parser_expression (parser
);
5660 ce
= convert_lvalue_to_rvalue (switch_cond_loc
, ce
, true, false);
5662 /* ??? expr has no valid location? */
5663 if (check_no_cilk (expr
,
5664 "Cilk array notation cannot be used as a condition for switch statement",
5665 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement",
5667 expr
= error_mark_node
;
5668 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
5672 switch_cond_loc
= UNKNOWN_LOCATION
;
5673 expr
= error_mark_node
;
5674 ce
.original_type
= error_mark_node
;
5676 c_start_case (switch_loc
, switch_cond_loc
, expr
, explicit_cast_p
);
5677 save_break
= c_break_label
;
5678 c_break_label
= NULL_TREE
;
5679 body
= c_parser_c99_block_statement (parser
, if_p
);
5680 c_finish_case (body
, ce
.original_type
);
5683 location_t here
= c_parser_peek_token (parser
)->location
;
5684 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_break_label
);
5685 SET_EXPR_LOCATION (t
, here
);
5688 c_break_label
= save_break
;
5689 add_stmt (c_end_compound_stmt (switch_loc
, block
, flag_isoc99
));
5690 c_parser_maybe_reclassify_token (parser
);
5693 /* Parse a while statement (C90 6.6.5, C99 6.8.5).
5696 while (expression) statement
5698 IF_P is used to track whether there's a (possibly labeled) if statement
5699 which is not enclosed in braces and has an else clause. This is used to
5700 implement -Wparentheses. */
5703 c_parser_while_statement (c_parser
*parser
, bool ivdep
, bool *if_p
)
5705 tree block
, cond
, body
, save_break
, save_cont
;
5707 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_WHILE
));
5708 token_indent_info while_tinfo
5709 = get_token_indent_info (c_parser_peek_token (parser
));
5710 c_parser_consume_token (parser
);
5711 block
= c_begin_compound_stmt (flag_isoc99
);
5712 loc
= c_parser_peek_token (parser
)->location
;
5713 cond
= c_parser_paren_condition (parser
);
5714 if (check_no_cilk (cond
,
5715 "Cilk array notation cannot be used as a condition for while statement",
5716 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
5717 cond
= error_mark_node
;
5718 if (ivdep
&& cond
!= error_mark_node
)
5719 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5720 build_int_cst (integer_type_node
,
5721 annot_expr_ivdep_kind
));
5722 save_break
= c_break_label
;
5723 c_break_label
= NULL_TREE
;
5724 save_cont
= c_cont_label
;
5725 c_cont_label
= NULL_TREE
;
5727 token_indent_info body_tinfo
5728 = get_token_indent_info (c_parser_peek_token (parser
));
5730 body
= c_parser_c99_block_statement (parser
, if_p
);
5731 c_finish_loop (loc
, cond
, NULL
, body
, c_break_label
, c_cont_label
, true);
5732 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5733 c_parser_maybe_reclassify_token (parser
);
5735 token_indent_info next_tinfo
5736 = get_token_indent_info (c_parser_peek_token (parser
));
5737 warn_for_misleading_indentation (while_tinfo
, body_tinfo
, next_tinfo
);
5739 c_break_label
= save_break
;
5740 c_cont_label
= save_cont
;
5743 /* Parse a do statement (C90 6.6.5, C99 6.8.5).
5746 do statement while ( expression ) ;
5750 c_parser_do_statement (c_parser
*parser
, bool ivdep
)
5752 tree block
, cond
, body
, save_break
, save_cont
, new_break
, new_cont
;
5754 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_DO
));
5755 c_parser_consume_token (parser
);
5756 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5757 warning_at (c_parser_peek_token (parser
)->location
,
5759 "suggest braces around empty body in %<do%> statement");
5760 block
= c_begin_compound_stmt (flag_isoc99
);
5761 loc
= c_parser_peek_token (parser
)->location
;
5762 save_break
= c_break_label
;
5763 c_break_label
= NULL_TREE
;
5764 save_cont
= c_cont_label
;
5765 c_cont_label
= NULL_TREE
;
5766 body
= c_parser_c99_block_statement (parser
, NULL
);
5767 c_parser_require_keyword (parser
, RID_WHILE
, "expected %<while%>");
5768 new_break
= c_break_label
;
5769 c_break_label
= save_break
;
5770 new_cont
= c_cont_label
;
5771 c_cont_label
= save_cont
;
5772 cond
= c_parser_paren_condition (parser
);
5773 if (check_no_cilk (cond
,
5774 "Cilk array notation cannot be used as a condition for a do-while statement",
5775 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
5776 cond
= error_mark_node
;
5777 if (ivdep
&& cond
!= error_mark_node
)
5778 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5779 build_int_cst (integer_type_node
,
5780 annot_expr_ivdep_kind
));
5781 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
5782 c_parser_skip_to_end_of_block_or_statement (parser
);
5783 c_finish_loop (loc
, cond
, NULL
, body
, new_break
, new_cont
, false);
5784 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
));
5787 /* Parse a for statement (C90 6.6.5, C99 6.8.5).
5790 for ( expression[opt] ; expression[opt] ; expression[opt] ) statement
5791 for ( nested-declaration expression[opt] ; expression[opt] ) statement
5793 The form with a declaration is new in C99.
5795 ??? In accordance with the old parser, the declaration may be a
5796 nested function, which is then rejected in check_for_loop_decls,
5797 but does it make any sense for this to be included in the grammar?
5798 Note in particular that the nested function does not include a
5799 trailing ';', whereas the "declaration" production includes one.
5800 Also, can we reject bad declarations earlier and cheaper than
5801 check_for_loop_decls?
5803 In Objective-C, there are two additional variants:
5806 for ( expression in expresssion ) statement
5807 for ( declaration in expression ) statement
5809 This is inconsistent with C, because the second variant is allowed
5810 even if c99 is not enabled.
5812 The rest of the comment documents these Objective-C foreach-statement.
5814 Here is the canonical example of the first variant:
5815 for (object in array) { do something with object }
5816 we call the first expression ("object") the "object_expression" and
5817 the second expression ("array") the "collection_expression".
5818 object_expression must be an lvalue of type "id" (a generic Objective-C
5819 object) because the loop works by assigning to object_expression the
5820 various objects from the collection_expression. collection_expression
5821 must evaluate to something of type "id" which responds to the method
5822 countByEnumeratingWithState:objects:count:.
5824 The canonical example of the second variant is:
5825 for (id object in array) { do something with object }
5826 which is completely equivalent to
5829 for (object in array) { do something with object }
5831 Note that initizializing 'object' in some way (eg, "for ((object =
5832 xxx) in array) { do something with object }") is possibly
5833 technically valid, but completely pointless as 'object' will be
5834 assigned to something else as soon as the loop starts. We should
5835 most likely reject it (TODO).
5837 The beginning of the Objective-C foreach-statement looks exactly
5838 like the beginning of the for-statement, and we can tell it is a
5839 foreach-statement only because the initial declaration or
5840 expression is terminated by 'in' instead of ';'.
5842 IF_P is used to track whether there's a (possibly labeled) if statement
5843 which is not enclosed in braces and has an else clause. This is used to
5844 implement -Wparentheses. */
5847 c_parser_for_statement (c_parser
*parser
, bool ivdep
, bool *if_p
)
5849 tree block
, cond
, incr
, save_break
, save_cont
, body
;
5850 /* The following are only used when parsing an ObjC foreach statement. */
5851 tree object_expression
;
5852 /* Silence the bogus uninitialized warning. */
5853 tree collection_expression
= NULL
;
5854 location_t loc
= c_parser_peek_token (parser
)->location
;
5855 location_t for_loc
= c_parser_peek_token (parser
)->location
;
5856 bool is_foreach_statement
= false;
5857 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_FOR
));
5858 token_indent_info for_tinfo
5859 = get_token_indent_info (c_parser_peek_token (parser
));
5860 c_parser_consume_token (parser
);
5861 /* Open a compound statement in Objective-C as well, just in case this is
5862 as foreach expression. */
5863 block
= c_begin_compound_stmt (flag_isoc99
|| c_dialect_objc ());
5864 cond
= error_mark_node
;
5865 incr
= error_mark_node
;
5866 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
5868 /* Parse the initialization declaration or expression. */
5869 object_expression
= error_mark_node
;
5870 parser
->objc_could_be_foreach_context
= c_dialect_objc ();
5871 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5873 parser
->objc_could_be_foreach_context
= false;
5874 c_parser_consume_token (parser
);
5875 c_finish_expr_stmt (loc
, NULL_TREE
);
5877 else if (c_parser_next_tokens_start_declaration (parser
))
5879 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
5880 &object_expression
, vNULL
);
5881 parser
->objc_could_be_foreach_context
= false;
5883 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5885 c_parser_consume_token (parser
);
5886 is_foreach_statement
= true;
5887 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5888 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5891 check_for_loop_decls (for_loc
, flag_isoc99
);
5893 else if (c_parser_next_token_is_keyword (parser
, RID_EXTENSION
))
5895 /* __extension__ can start a declaration, but is also an
5896 unary operator that can start an expression. Consume all
5897 but the last of a possible series of __extension__ to
5899 while (c_parser_peek_2nd_token (parser
)->type
== CPP_KEYWORD
5900 && (c_parser_peek_2nd_token (parser
)->keyword
5902 c_parser_consume_token (parser
);
5903 if (c_token_starts_declaration (c_parser_peek_2nd_token (parser
)))
5906 ext
= disable_extension_diagnostics ();
5907 c_parser_consume_token (parser
);
5908 c_parser_declaration_or_fndef (parser
, true, true, true, true,
5909 true, &object_expression
, vNULL
);
5910 parser
->objc_could_be_foreach_context
= false;
5912 restore_extension_diagnostics (ext
);
5913 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5915 c_parser_consume_token (parser
);
5916 is_foreach_statement
= true;
5917 if (check_for_loop_decls (for_loc
, true) == NULL_TREE
)
5918 c_parser_error (parser
, "multiple iterating variables in fast enumeration");
5921 check_for_loop_decls (for_loc
, flag_isoc99
);
5931 tree init_expression
;
5932 ce
= c_parser_expression (parser
);
5933 /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top
5934 level statement", but it works just fine, so allow it. */
5935 init_expression
= ce
.value
;
5936 parser
->objc_could_be_foreach_context
= false;
5937 if (c_parser_next_token_is_keyword (parser
, RID_IN
))
5939 c_parser_consume_token (parser
);
5940 is_foreach_statement
= true;
5941 if (! lvalue_p (init_expression
))
5942 c_parser_error (parser
, "invalid iterating variable in fast enumeration");
5943 object_expression
= c_fully_fold (init_expression
, false, NULL
);
5947 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
5948 init_expression
= ce
.value
;
5949 c_finish_expr_stmt (loc
, init_expression
);
5950 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
5954 /* Parse the loop condition. In the case of a foreach
5955 statement, there is no loop condition. */
5956 gcc_assert (!parser
->objc_could_be_foreach_context
);
5957 if (!is_foreach_statement
)
5959 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
5963 c_parser_error (parser
, "missing loop condition in loop with "
5964 "%<GCC ivdep%> pragma");
5965 cond
= error_mark_node
;
5969 c_parser_consume_token (parser
);
5975 cond
= c_parser_condition (parser
);
5976 if (check_no_cilk (cond
,
5977 "Cilk array notation cannot be used in a condition for a for-loop",
5978 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
5979 cond
= error_mark_node
;
5980 c_parser_skip_until_found (parser
, CPP_SEMICOLON
,
5983 if (ivdep
&& cond
!= error_mark_node
)
5984 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
5985 build_int_cst (integer_type_node
,
5986 annot_expr_ivdep_kind
));
5988 /* Parse the increment expression (the third expression in a
5989 for-statement). In the case of a foreach-statement, this is
5990 the expression that follows the 'in'. */
5991 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
5993 if (is_foreach_statement
)
5995 c_parser_error (parser
, "missing collection in fast enumeration");
5996 collection_expression
= error_mark_node
;
5999 incr
= c_process_expr_stmt (loc
, NULL_TREE
);
6003 if (is_foreach_statement
)
6004 collection_expression
= c_fully_fold (c_parser_expression (parser
).value
,
6008 struct c_expr ce
= c_parser_expression (parser
);
6009 ce
= convert_lvalue_to_rvalue (loc
, ce
, true, false);
6010 incr
= c_process_expr_stmt (loc
, ce
.value
);
6013 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6015 save_break
= c_break_label
;
6016 c_break_label
= NULL_TREE
;
6017 save_cont
= c_cont_label
;
6018 c_cont_label
= NULL_TREE
;
6020 token_indent_info body_tinfo
6021 = get_token_indent_info (c_parser_peek_token (parser
));
6023 body
= c_parser_c99_block_statement (parser
, if_p
);
6025 if (is_foreach_statement
)
6026 objc_finish_foreach_loop (loc
, object_expression
, collection_expression
, body
, c_break_label
, c_cont_label
);
6028 c_finish_loop (loc
, cond
, incr
, body
, c_break_label
, c_cont_label
, true);
6029 add_stmt (c_end_compound_stmt (loc
, block
, flag_isoc99
|| c_dialect_objc ()));
6030 c_parser_maybe_reclassify_token (parser
);
6032 token_indent_info next_tinfo
6033 = get_token_indent_info (c_parser_peek_token (parser
));
6034 warn_for_misleading_indentation (for_tinfo
, body_tinfo
, next_tinfo
);
6036 c_break_label
= save_break
;
6037 c_cont_label
= save_cont
;
6040 /* Parse an asm statement, a GNU extension. This is a full-blown asm
6041 statement with inputs, outputs, clobbers, and volatile tag
6045 asm type-qualifier[opt] ( asm-argument ) ;
6046 asm type-qualifier[opt] goto ( asm-goto-argument ) ;
6050 asm-string-literal : asm-operands[opt]
6051 asm-string-literal : asm-operands[opt] : asm-operands[opt]
6052 asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt]
6055 asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \
6058 Qualifiers other than volatile are accepted in the syntax but
6062 c_parser_asm_statement (c_parser
*parser
)
6064 tree quals
, str
, outputs
, inputs
, clobbers
, labels
, ret
;
6065 bool simple
, is_goto
;
6066 location_t asm_loc
= c_parser_peek_token (parser
)->location
;
6067 int section
, nsections
;
6069 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ASM
));
6070 c_parser_consume_token (parser
);
6071 if (c_parser_next_token_is_keyword (parser
, RID_VOLATILE
))
6073 quals
= c_parser_peek_token (parser
)->value
;
6074 c_parser_consume_token (parser
);
6076 else if (c_parser_next_token_is_keyword (parser
, RID_CONST
)
6077 || c_parser_next_token_is_keyword (parser
, RID_RESTRICT
))
6079 warning_at (c_parser_peek_token (parser
)->location
,
6081 "%E qualifier ignored on asm",
6082 c_parser_peek_token (parser
)->value
);
6084 c_parser_consume_token (parser
);
6090 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
6092 c_parser_consume_token (parser
);
6096 /* ??? Follow the C++ parser rather than using the
6097 lex_untranslated_string kludge. */
6098 parser
->lex_untranslated_string
= true;
6101 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6104 str
= c_parser_asm_string_literal (parser
);
6105 if (str
== NULL_TREE
)
6106 goto error_close_paren
;
6109 outputs
= NULL_TREE
;
6111 clobbers
= NULL_TREE
;
6114 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6117 /* Parse each colon-delimited section of operands. */
6118 nsections
= 3 + is_goto
;
6119 for (section
= 0; section
< nsections
; ++section
)
6121 if (!c_parser_require (parser
, CPP_COLON
,
6124 : "expected %<:%> or %<)%>"))
6125 goto error_close_paren
;
6127 /* Once past any colon, we're no longer a simple asm. */
6130 if ((!c_parser_next_token_is (parser
, CPP_COLON
)
6131 && !c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
6136 /* For asm goto, we don't allow output operands, but reserve
6137 the slot for a future extension that does allow them. */
6139 outputs
= c_parser_asm_operands (parser
);
6142 inputs
= c_parser_asm_operands (parser
);
6145 clobbers
= c_parser_asm_clobbers (parser
);
6148 labels
= c_parser_asm_goto_operands (parser
);
6154 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
) && !is_goto
)
6159 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6161 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6165 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
6166 c_parser_skip_to_end_of_block_or_statement (parser
);
6168 ret
= build_asm_stmt (quals
, build_asm_expr (asm_loc
, str
, outputs
, inputs
,
6169 clobbers
, labels
, simple
));
6172 parser
->lex_untranslated_string
= false;
6176 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6180 /* Parse asm operands, a GNU extension.
6184 asm-operands , asm-operand
6187 asm-string-literal ( expression )
6188 [ identifier ] asm-string-literal ( expression )
6192 c_parser_asm_operands (c_parser
*parser
)
6194 tree list
= NULL_TREE
;
6199 if (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
6201 c_parser_consume_token (parser
);
6202 if (c_parser_next_token_is (parser
, CPP_NAME
))
6204 tree id
= c_parser_peek_token (parser
)->value
;
6205 c_parser_consume_token (parser
);
6206 name
= build_string (IDENTIFIER_LENGTH (id
),
6207 IDENTIFIER_POINTER (id
));
6211 c_parser_error (parser
, "expected identifier");
6212 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
6215 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
6220 str
= c_parser_asm_string_literal (parser
);
6221 if (str
== NULL_TREE
)
6223 parser
->lex_untranslated_string
= false;
6224 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
6226 parser
->lex_untranslated_string
= true;
6229 expr
= c_parser_expression (parser
);
6230 mark_exp_read (expr
.value
);
6231 parser
->lex_untranslated_string
= true;
6232 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
6234 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
6237 list
= chainon (list
, build_tree_list (build_tree_list (name
, str
),
6239 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6240 c_parser_consume_token (parser
);
6247 /* Parse asm clobbers, a GNU extension.
6251 asm-clobbers , asm-string-literal
6255 c_parser_asm_clobbers (c_parser
*parser
)
6257 tree list
= NULL_TREE
;
6260 tree str
= c_parser_asm_string_literal (parser
);
6262 list
= tree_cons (NULL_TREE
, str
, list
);
6265 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6266 c_parser_consume_token (parser
);
6273 /* Parse asm goto labels, a GNU extension.
6277 asm-goto-operands , identifier
6281 c_parser_asm_goto_operands (c_parser
*parser
)
6283 tree list
= NULL_TREE
;
6288 if (c_parser_next_token_is (parser
, CPP_NAME
))
6290 c_token
*tok
= c_parser_peek_token (parser
);
6292 label
= lookup_label_for_goto (tok
->location
, name
);
6293 c_parser_consume_token (parser
);
6294 TREE_USED (label
) = 1;
6298 c_parser_error (parser
, "expected identifier");
6302 name
= build_string (IDENTIFIER_LENGTH (name
),
6303 IDENTIFIER_POINTER (name
));
6304 list
= tree_cons (name
, label
, list
);
6305 if (c_parser_next_token_is (parser
, CPP_COMMA
))
6306 c_parser_consume_token (parser
);
6308 return nreverse (list
);
6312 /* Parse an expression other than a compound expression; that is, an
6313 assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not
6314 NULL then it is an Objective-C message expression which is the
6315 primary-expression starting the expression as an initializer.
6317 assignment-expression:
6318 conditional-expression
6319 unary-expression assignment-operator assignment-expression
6321 assignment-operator: one of
6322 = *= /= %= += -= <<= >>= &= ^= |=
6324 In GNU C we accept any conditional expression on the LHS and
6325 diagnose the invalid lvalue rather than producing a syntax
6328 static struct c_expr
6329 c_parser_expr_no_commas (c_parser
*parser
, struct c_expr
*after
,
6330 tree omp_atomic_lhs
)
6332 struct c_expr lhs
, rhs
, ret
;
6333 enum tree_code code
;
6334 location_t op_location
, exp_location
;
6335 gcc_assert (!after
|| c_dialect_objc ());
6336 lhs
= c_parser_conditional_expression (parser
, after
, omp_atomic_lhs
);
6337 op_location
= c_parser_peek_token (parser
)->location
;
6338 switch (c_parser_peek_token (parser
)->type
)
6347 code
= TRUNC_DIV_EXPR
;
6350 code
= TRUNC_MOD_EXPR
;
6365 code
= BIT_AND_EXPR
;
6368 code
= BIT_XOR_EXPR
;
6371 code
= BIT_IOR_EXPR
;
6376 c_parser_consume_token (parser
);
6377 exp_location
= c_parser_peek_token (parser
)->location
;
6378 rhs
= c_parser_expr_no_commas (parser
, NULL
);
6379 rhs
= convert_lvalue_to_rvalue (exp_location
, rhs
, true, true);
6381 ret
.value
= build_modify_expr (op_location
, lhs
.value
, lhs
.original_type
,
6382 code
, exp_location
, rhs
.value
,
6384 set_c_expr_source_range (&ret
, lhs
.get_start (), rhs
.get_finish ());
6385 if (code
== NOP_EXPR
)
6386 ret
.original_code
= MODIFY_EXPR
;
6389 TREE_NO_WARNING (ret
.value
) = 1;
6390 ret
.original_code
= ERROR_MARK
;
6392 ret
.original_type
= NULL
;
6396 /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER
6397 is not NULL then it is an Objective-C message expression which is
6398 the primary-expression starting the expression as an initializer.
6400 conditional-expression:
6401 logical-OR-expression
6402 logical-OR-expression ? expression : conditional-expression
6406 conditional-expression:
6407 logical-OR-expression ? : conditional-expression
6410 static struct c_expr
6411 c_parser_conditional_expression (c_parser
*parser
, struct c_expr
*after
,
6412 tree omp_atomic_lhs
)
6414 struct c_expr cond
, exp1
, exp2
, ret
;
6415 location_t start
, cond_loc
, colon_loc
, middle_loc
;
6417 gcc_assert (!after
|| c_dialect_objc ());
6419 cond
= c_parser_binary_expression (parser
, after
, omp_atomic_lhs
);
6421 if (c_parser_next_token_is_not (parser
, CPP_QUERY
))
6423 if (cond
.value
!= error_mark_node
)
6424 start
= cond
.get_start ();
6426 start
= UNKNOWN_LOCATION
;
6427 cond_loc
= c_parser_peek_token (parser
)->location
;
6428 cond
= convert_lvalue_to_rvalue (cond_loc
, cond
, true, true);
6429 c_parser_consume_token (parser
);
6430 if (c_parser_next_token_is (parser
, CPP_COLON
))
6432 tree eptype
= NULL_TREE
;
6434 middle_loc
= c_parser_peek_token (parser
)->location
;
6435 pedwarn (middle_loc
, OPT_Wpedantic
,
6436 "ISO C forbids omitting the middle term of a ?: expression");
6437 if (TREE_CODE (cond
.value
) == EXCESS_PRECISION_EXPR
)
6439 eptype
= TREE_TYPE (cond
.value
);
6440 cond
.value
= TREE_OPERAND (cond
.value
, 0);
6442 tree e
= cond
.value
;
6443 while (TREE_CODE (e
) == COMPOUND_EXPR
)
6444 e
= TREE_OPERAND (e
, 1);
6445 warn_for_omitted_condop (middle_loc
, e
);
6446 /* Make sure first operand is calculated only once. */
6447 exp1
.value
= c_save_expr (default_conversion (cond
.value
));
6449 exp1
.value
= build1 (EXCESS_PRECISION_EXPR
, eptype
, exp1
.value
);
6450 exp1
.original_type
= NULL
;
6451 cond
.value
= c_objc_common_truthvalue_conversion (cond_loc
, exp1
.value
);
6452 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_true_node
;
6457 = c_objc_common_truthvalue_conversion
6458 (cond_loc
, default_conversion (cond
.value
));
6459 c_inhibit_evaluation_warnings
+= cond
.value
== truthvalue_false_node
;
6460 exp1
= c_parser_expression_conv (parser
);
6461 mark_exp_read (exp1
.value
);
6462 c_inhibit_evaluation_warnings
+=
6463 ((cond
.value
== truthvalue_true_node
)
6464 - (cond
.value
== truthvalue_false_node
));
6467 colon_loc
= c_parser_peek_token (parser
)->location
;
6468 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
6470 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6471 ret
.value
= error_mark_node
;
6472 ret
.original_code
= ERROR_MARK
;
6473 ret
.original_type
= NULL
;
6477 location_t exp2_loc
= c_parser_peek_token (parser
)->location
;
6478 exp2
= c_parser_conditional_expression (parser
, NULL
, NULL_TREE
);
6479 exp2
= convert_lvalue_to_rvalue (exp2_loc
, exp2
, true, true);
6481 c_inhibit_evaluation_warnings
-= cond
.value
== truthvalue_true_node
;
6482 ret
.value
= build_conditional_expr (colon_loc
, cond
.value
,
6483 cond
.original_code
== C_MAYBE_CONST_EXPR
,
6484 exp1
.value
, exp1
.original_type
,
6485 exp2
.value
, exp2
.original_type
);
6486 ret
.original_code
= ERROR_MARK
;
6487 if (exp1
.value
== error_mark_node
|| exp2
.value
== error_mark_node
)
6488 ret
.original_type
= NULL
;
6493 /* If both sides are enum type, the default conversion will have
6494 made the type of the result be an integer type. We want to
6495 remember the enum types we started with. */
6496 t1
= exp1
.original_type
? exp1
.original_type
: TREE_TYPE (exp1
.value
);
6497 t2
= exp2
.original_type
? exp2
.original_type
: TREE_TYPE (exp2
.value
);
6498 ret
.original_type
= ((t1
!= error_mark_node
6499 && t2
!= error_mark_node
6500 && (TYPE_MAIN_VARIANT (t1
)
6501 == TYPE_MAIN_VARIANT (t2
)))
6505 set_c_expr_source_range (&ret
, start
, exp2
.get_finish ());
6509 /* Parse a binary expression; that is, a logical-OR-expression (C90
6510 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is
6511 an Objective-C message expression which is the primary-expression
6512 starting the expression as an initializer.
6514 OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic,
6515 when it should be the unfolded lhs. In a valid OpenMP source,
6516 one of the operands of the toplevel binary expression must be equal
6517 to it. In that case, just return a build2 created binary operation
6518 rather than result of parser_build_binary_op.
6520 multiplicative-expression:
6522 multiplicative-expression * cast-expression
6523 multiplicative-expression / cast-expression
6524 multiplicative-expression % cast-expression
6526 additive-expression:
6527 multiplicative-expression
6528 additive-expression + multiplicative-expression
6529 additive-expression - multiplicative-expression
6533 shift-expression << additive-expression
6534 shift-expression >> additive-expression
6536 relational-expression:
6538 relational-expression < shift-expression
6539 relational-expression > shift-expression
6540 relational-expression <= shift-expression
6541 relational-expression >= shift-expression
6543 equality-expression:
6544 relational-expression
6545 equality-expression == relational-expression
6546 equality-expression != relational-expression
6550 AND-expression & equality-expression
6552 exclusive-OR-expression:
6554 exclusive-OR-expression ^ AND-expression
6556 inclusive-OR-expression:
6557 exclusive-OR-expression
6558 inclusive-OR-expression | exclusive-OR-expression
6560 logical-AND-expression:
6561 inclusive-OR-expression
6562 logical-AND-expression && inclusive-OR-expression
6564 logical-OR-expression:
6565 logical-AND-expression
6566 logical-OR-expression || logical-AND-expression
6569 static struct c_expr
6570 c_parser_binary_expression (c_parser
*parser
, struct c_expr
*after
,
6571 tree omp_atomic_lhs
)
6573 /* A binary expression is parsed using operator-precedence parsing,
6574 with the operands being cast expressions. All the binary
6575 operators are left-associative. Thus a binary expression is of
6578 E0 op1 E1 op2 E2 ...
6580 which we represent on a stack. On the stack, the precedence
6581 levels are strictly increasing. When a new operator is
6582 encountered of higher precedence than that at the top of the
6583 stack, it is pushed; its LHS is the top expression, and its RHS
6584 is everything parsed until it is popped. When a new operator is
6585 encountered with precedence less than or equal to that at the top
6586 of the stack, triples E[i-1] op[i] E[i] are popped and replaced
6587 by the result of the operation until the operator at the top of
6588 the stack has lower precedence than the new operator or there is
6589 only one element on the stack; then the top expression is the LHS
6590 of the new operator. In the case of logical AND and OR
6591 expressions, we also need to adjust c_inhibit_evaluation_warnings
6592 as appropriate when the operators are pushed and popped. */
6595 /* The expression at this stack level. */
6597 /* The precedence of the operator on its left, PREC_NONE at the
6598 bottom of the stack. */
6599 enum c_parser_prec prec
;
6600 /* The operation on its left. */
6602 /* The source location of this operation. */
6606 /* Location of the binary operator. */
6607 location_t binary_loc
= UNKNOWN_LOCATION
; /* Quiet warning. */
6610 switch (stack[sp].op) \
6612 case TRUTH_ANDIF_EXPR: \
6613 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6614 == truthvalue_false_node); \
6616 case TRUTH_ORIF_EXPR: \
6617 c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
6618 == truthvalue_true_node); \
6623 stack[sp - 1].expr \
6624 = convert_lvalue_to_rvalue (stack[sp - 1].loc, \
6625 stack[sp - 1].expr, true, true); \
6627 = convert_lvalue_to_rvalue (stack[sp].loc, \
6628 stack[sp].expr, true, true); \
6629 if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \
6630 && c_parser_peek_token (parser)->type == CPP_SEMICOLON \
6631 && ((1 << stack[sp].prec) \
6632 & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \
6633 | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \
6634 && stack[sp].op != TRUNC_MOD_EXPR \
6635 && stack[0].expr.value != error_mark_node \
6636 && stack[1].expr.value != error_mark_node \
6637 && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \
6638 || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \
6639 stack[0].expr.value \
6640 = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \
6641 stack[0].expr.value, stack[1].expr.value); \
6643 stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \
6645 stack[sp - 1].expr, \
6649 gcc_assert (!after
|| c_dialect_objc ());
6650 stack
[0].loc
= c_parser_peek_token (parser
)->location
;
6651 stack
[0].expr
= c_parser_cast_expression (parser
, after
);
6652 stack
[0].prec
= PREC_NONE
;
6656 enum c_parser_prec oprec
;
6657 enum tree_code ocode
;
6658 source_range src_range
;
6661 switch (c_parser_peek_token (parser
)->type
)
6669 ocode
= TRUNC_DIV_EXPR
;
6673 ocode
= TRUNC_MOD_EXPR
;
6685 ocode
= LSHIFT_EXPR
;
6689 ocode
= RSHIFT_EXPR
;
6703 case CPP_GREATER_EQ
:
6716 oprec
= PREC_BITAND
;
6717 ocode
= BIT_AND_EXPR
;
6720 oprec
= PREC_BITXOR
;
6721 ocode
= BIT_XOR_EXPR
;
6725 ocode
= BIT_IOR_EXPR
;
6728 oprec
= PREC_LOGAND
;
6729 ocode
= TRUTH_ANDIF_EXPR
;
6733 ocode
= TRUTH_ORIF_EXPR
;
6736 /* Not a binary operator, so end of the binary
6740 binary_loc
= c_parser_peek_token (parser
)->location
;
6741 while (oprec
<= stack
[sp
].prec
)
6743 c_parser_consume_token (parser
);
6746 case TRUTH_ANDIF_EXPR
:
6747 src_range
= stack
[sp
].expr
.src_range
;
6749 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6750 stack
[sp
].expr
, true, true);
6751 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6752 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6753 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6754 == truthvalue_false_node
);
6755 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
6757 case TRUTH_ORIF_EXPR
:
6758 src_range
= stack
[sp
].expr
.src_range
;
6760 = convert_lvalue_to_rvalue (stack
[sp
].loc
,
6761 stack
[sp
].expr
, true, true);
6762 stack
[sp
].expr
.value
= c_objc_common_truthvalue_conversion
6763 (stack
[sp
].loc
, default_conversion (stack
[sp
].expr
.value
));
6764 c_inhibit_evaluation_warnings
+= (stack
[sp
].expr
.value
6765 == truthvalue_true_node
);
6766 set_c_expr_source_range (&stack
[sp
].expr
, src_range
);
6772 stack
[sp
].loc
= binary_loc
;
6773 stack
[sp
].expr
= c_parser_cast_expression (parser
, NULL
);
6774 stack
[sp
].prec
= oprec
;
6775 stack
[sp
].op
= ocode
;
6780 return stack
[0].expr
;
6784 /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not
6785 NULL then it is an Objective-C message expression which is the
6786 primary-expression starting the expression as an initializer.
6790 ( type-name ) unary-expression
6793 static struct c_expr
6794 c_parser_cast_expression (c_parser
*parser
, struct c_expr
*after
)
6796 location_t cast_loc
= c_parser_peek_token (parser
)->location
;
6797 gcc_assert (!after
|| c_dialect_objc ());
6799 return c_parser_postfix_expression_after_primary (parser
,
6801 /* If the expression begins with a parenthesized type name, it may
6802 be either a cast or a compound literal; we need to see whether
6803 the next character is '{' to tell the difference. If not, it is
6804 an unary expression. Full detection of unknown typenames here
6805 would require a 3-token lookahead. */
6806 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
6807 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
6809 struct c_type_name
*type_name
;
6812 c_parser_consume_token (parser
);
6813 type_name
= c_parser_type_name (parser
);
6814 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
6815 if (type_name
== NULL
)
6817 ret
.value
= error_mark_node
;
6818 ret
.original_code
= ERROR_MARK
;
6819 ret
.original_type
= NULL
;
6823 /* Save casted types in the function's used types hash table. */
6824 used_types_insert (type_name
->specs
->type
);
6826 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
6827 return c_parser_postfix_expression_after_paren_type (parser
, type_name
,
6830 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
6831 expr
= c_parser_cast_expression (parser
, NULL
);
6832 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, true);
6834 ret
.value
= c_cast_expr (cast_loc
, type_name
, expr
.value
);
6835 if (ret
.value
&& expr
.value
)
6836 set_c_expr_source_range (&ret
, cast_loc
, expr
.get_finish ());
6837 ret
.original_code
= ERROR_MARK
;
6838 ret
.original_type
= NULL
;
6842 return c_parser_unary_expression (parser
);
6845 /* Parse an unary expression (C90 6.3.3, C99 6.5.3).
6851 unary-operator cast-expression
6852 sizeof unary-expression
6853 sizeof ( type-name )
6855 unary-operator: one of
6861 __alignof__ unary-expression
6862 __alignof__ ( type-name )
6865 (C11 permits _Alignof with type names only.)
6867 unary-operator: one of
6868 __extension__ __real__ __imag__
6870 Transactional Memory:
6873 transaction-expression
6875 In addition, the GNU syntax treats ++ and -- as unary operators, so
6876 they may be applied to cast expressions with errors for non-lvalues
6879 static struct c_expr
6880 c_parser_unary_expression (c_parser
*parser
)
6883 struct c_expr ret
, op
;
6884 location_t op_loc
= c_parser_peek_token (parser
)->location
;
6887 ret
.original_code
= ERROR_MARK
;
6888 ret
.original_type
= NULL
;
6889 switch (c_parser_peek_token (parser
)->type
)
6892 c_parser_consume_token (parser
);
6893 exp_loc
= c_parser_peek_token (parser
)->location
;
6894 op
= c_parser_cast_expression (parser
, NULL
);
6896 /* If there is array notations in op, we expand them. */
6897 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6898 return fix_array_notation_expr (exp_loc
, PREINCREMENT_EXPR
, op
);
6901 op
= default_function_array_read_conversion (exp_loc
, op
);
6902 return parser_build_unary_op (op_loc
, PREINCREMENT_EXPR
, op
);
6904 case CPP_MINUS_MINUS
:
6905 c_parser_consume_token (parser
);
6906 exp_loc
= c_parser_peek_token (parser
)->location
;
6907 op
= c_parser_cast_expression (parser
, NULL
);
6909 /* If there is array notations in op, we expand them. */
6910 if (flag_cilkplus
&& TREE_CODE (op
.value
) == ARRAY_NOTATION_REF
)
6911 return fix_array_notation_expr (exp_loc
, PREDECREMENT_EXPR
, op
);
6914 op
= default_function_array_read_conversion (exp_loc
, op
);
6915 return parser_build_unary_op (op_loc
, PREDECREMENT_EXPR
, op
);
6918 c_parser_consume_token (parser
);
6919 op
= c_parser_cast_expression (parser
, NULL
);
6920 mark_exp_read (op
.value
);
6921 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
6924 c_parser_consume_token (parser
);
6925 exp_loc
= c_parser_peek_token (parser
)->location
;
6926 op
= c_parser_cast_expression (parser
, NULL
);
6927 finish
= op
.get_finish ();
6928 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6929 location_t combined_loc
= make_location (op_loc
, op_loc
, finish
);
6930 ret
.value
= build_indirect_ref (combined_loc
, op
.value
, RO_UNARY_STAR
);
6931 ret
.src_range
.m_start
= op_loc
;
6932 ret
.src_range
.m_finish
= finish
;
6936 if (!c_dialect_objc () && !in_system_header_at (input_location
))
6939 "traditional C rejects the unary plus operator");
6940 c_parser_consume_token (parser
);
6941 exp_loc
= c_parser_peek_token (parser
)->location
;
6942 op
= c_parser_cast_expression (parser
, NULL
);
6943 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6944 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
6946 c_parser_consume_token (parser
);
6947 exp_loc
= c_parser_peek_token (parser
)->location
;
6948 op
= c_parser_cast_expression (parser
, NULL
);
6949 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6950 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
6952 c_parser_consume_token (parser
);
6953 exp_loc
= c_parser_peek_token (parser
)->location
;
6954 op
= c_parser_cast_expression (parser
, NULL
);
6955 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6956 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
6958 c_parser_consume_token (parser
);
6959 exp_loc
= c_parser_peek_token (parser
)->location
;
6960 op
= c_parser_cast_expression (parser
, NULL
);
6961 op
= convert_lvalue_to_rvalue (exp_loc
, op
, true, true);
6962 return parser_build_unary_op (op_loc
, TRUTH_NOT_EXPR
, op
);
6964 /* Refer to the address of a label as a pointer. */
6965 c_parser_consume_token (parser
);
6966 if (c_parser_next_token_is (parser
, CPP_NAME
))
6968 ret
.value
= finish_label_address_expr
6969 (c_parser_peek_token (parser
)->value
, op_loc
);
6970 set_c_expr_source_range (&ret
, op_loc
,
6971 c_parser_peek_token (parser
)->get_finish ());
6972 c_parser_consume_token (parser
);
6976 c_parser_error (parser
, "expected identifier");
6977 ret
.value
= error_mark_node
;
6981 switch (c_parser_peek_token (parser
)->keyword
)
6984 return c_parser_sizeof_expression (parser
);
6986 return c_parser_alignof_expression (parser
);
6988 c_parser_consume_token (parser
);
6989 ext
= disable_extension_diagnostics ();
6990 ret
= c_parser_cast_expression (parser
, NULL
);
6991 restore_extension_diagnostics (ext
);
6994 c_parser_consume_token (parser
);
6995 exp_loc
= c_parser_peek_token (parser
)->location
;
6996 op
= c_parser_cast_expression (parser
, NULL
);
6997 op
= default_function_array_conversion (exp_loc
, op
);
6998 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
7000 c_parser_consume_token (parser
);
7001 exp_loc
= c_parser_peek_token (parser
)->location
;
7002 op
= c_parser_cast_expression (parser
, NULL
);
7003 op
= default_function_array_conversion (exp_loc
, op
);
7004 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
7005 case RID_TRANSACTION_ATOMIC
:
7006 case RID_TRANSACTION_RELAXED
:
7007 return c_parser_transaction_expression (parser
,
7008 c_parser_peek_token (parser
)->keyword
);
7010 return c_parser_postfix_expression (parser
);
7013 return c_parser_postfix_expression (parser
);
7017 /* Parse a sizeof expression. */
7019 static struct c_expr
7020 c_parser_sizeof_expression (c_parser
*parser
)
7023 struct c_expr result
;
7024 location_t expr_loc
;
7025 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_SIZEOF
));
7028 location_t finish
= UNKNOWN_LOCATION
;
7030 start
= c_parser_peek_token (parser
)->location
;
7032 c_parser_consume_token (parser
);
7033 c_inhibit_evaluation_warnings
++;
7035 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7036 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7038 /* Either sizeof ( type-name ) or sizeof unary-expression
7039 starting with a compound literal. */
7040 struct c_type_name
*type_name
;
7041 c_parser_consume_token (parser
);
7042 expr_loc
= c_parser_peek_token (parser
)->location
;
7043 type_name
= c_parser_type_name (parser
);
7044 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7045 finish
= parser
->tokens_buf
[0].location
;
7046 if (type_name
== NULL
)
7049 c_inhibit_evaluation_warnings
--;
7051 ret
.value
= error_mark_node
;
7052 ret
.original_code
= ERROR_MARK
;
7053 ret
.original_type
= NULL
;
7056 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7058 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7061 finish
= expr
.get_finish ();
7064 /* sizeof ( type-name ). */
7065 c_inhibit_evaluation_warnings
--;
7067 result
= c_expr_sizeof_type (expr_loc
, type_name
);
7071 expr_loc
= c_parser_peek_token (parser
)->location
;
7072 expr
= c_parser_unary_expression (parser
);
7073 finish
= expr
.get_finish ();
7075 c_inhibit_evaluation_warnings
--;
7077 mark_exp_read (expr
.value
);
7078 if (TREE_CODE (expr
.value
) == COMPONENT_REF
7079 && DECL_C_BIT_FIELD (TREE_OPERAND (expr
.value
, 1)))
7080 error_at (expr_loc
, "%<sizeof%> applied to a bit-field");
7081 result
= c_expr_sizeof_expr (expr_loc
, expr
);
7083 if (finish
!= UNKNOWN_LOCATION
)
7084 set_c_expr_source_range (&result
, start
, finish
);
7088 /* Parse an alignof expression. */
7090 static struct c_expr
7091 c_parser_alignof_expression (c_parser
*parser
)
7094 location_t start_loc
= c_parser_peek_token (parser
)->location
;
7096 tree alignof_spelling
= c_parser_peek_token (parser
)->value
;
7097 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_ALIGNOF
));
7098 bool is_c11_alignof
= strcmp (IDENTIFIER_POINTER (alignof_spelling
),
7100 /* A diagnostic is not required for the use of this identifier in
7101 the implementation namespace; only diagnose it for the C11
7102 spelling because of existing code using the other spellings. */
7106 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C99 does not support %qE",
7109 pedwarn_c99 (start_loc
, OPT_Wpedantic
, "ISO C90 does not support %qE",
7112 c_parser_consume_token (parser
);
7113 c_inhibit_evaluation_warnings
++;
7115 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
7116 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7118 /* Either __alignof__ ( type-name ) or __alignof__
7119 unary-expression starting with a compound literal. */
7121 struct c_type_name
*type_name
;
7123 c_parser_consume_token (parser
);
7124 loc
= c_parser_peek_token (parser
)->location
;
7125 type_name
= c_parser_type_name (parser
);
7126 end_loc
= c_parser_peek_token (parser
)->location
;
7127 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
7128 if (type_name
== NULL
)
7131 c_inhibit_evaluation_warnings
--;
7133 ret
.value
= error_mark_node
;
7134 ret
.original_code
= ERROR_MARK
;
7135 ret
.original_type
= NULL
;
7138 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
7140 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7145 /* alignof ( type-name ). */
7146 c_inhibit_evaluation_warnings
--;
7148 ret
.value
= c_sizeof_or_alignof_type (loc
, groktypename (type_name
,
7150 false, is_c11_alignof
, 1);
7151 ret
.original_code
= ERROR_MARK
;
7152 ret
.original_type
= NULL
;
7153 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7159 expr
= c_parser_unary_expression (parser
);
7160 end_loc
= expr
.src_range
.m_finish
;
7162 mark_exp_read (expr
.value
);
7163 c_inhibit_evaluation_warnings
--;
7167 OPT_Wpedantic
, "ISO C does not allow %<%E (expression)%>",
7169 ret
.value
= c_alignof_expr (start_loc
, expr
.value
);
7170 ret
.original_code
= ERROR_MARK
;
7171 ret
.original_type
= NULL
;
7172 set_c_expr_source_range (&ret
, start_loc
, end_loc
);
7177 /* Helper function to read arguments of builtins which are interfaces
7178 for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and
7179 others. The name of the builtin is passed using BNAME parameter.
7180 Function returns true if there were no errors while parsing and
7181 stores the arguments in CEXPR_LIST. If it returns true,
7182 *OUT_CLOSE_PAREN_LOC is written to with the location of the closing
7185 c_parser_get_builtin_args (c_parser
*parser
, const char *bname
,
7186 vec
<c_expr_t
, va_gc
> **ret_cexpr_list
,
7188 location_t
*out_close_paren_loc
)
7190 location_t loc
= c_parser_peek_token (parser
)->location
;
7191 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7193 bool saved_force_folding_builtin_constant_p
;
7195 *ret_cexpr_list
= NULL
;
7196 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
7198 error_at (loc
, "cannot take address of %qs", bname
);
7202 c_parser_consume_token (parser
);
7204 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
7206 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7207 c_parser_consume_token (parser
);
7211 saved_force_folding_builtin_constant_p
7212 = force_folding_builtin_constant_p
;
7213 force_folding_builtin_constant_p
|= choose_expr_p
;
7214 expr
= c_parser_expr_no_commas (parser
, NULL
);
7215 force_folding_builtin_constant_p
7216 = saved_force_folding_builtin_constant_p
;
7217 vec_alloc (cexpr_list
, 1);
7218 vec_safe_push (cexpr_list
, expr
);
7219 while (c_parser_next_token_is (parser
, CPP_COMMA
))
7221 c_parser_consume_token (parser
);
7222 expr
= c_parser_expr_no_commas (parser
, NULL
);
7223 vec_safe_push (cexpr_list
, expr
);
7226 *out_close_paren_loc
= c_parser_peek_token (parser
)->location
;
7227 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7230 *ret_cexpr_list
= cexpr_list
;
7234 /* This represents a single generic-association. */
7236 struct c_generic_association
7238 /* The location of the starting token of the type. */
7239 location_t type_location
;
7240 /* The association's type, or NULL_TREE for 'default'. */
7242 /* The association's expression. */
7243 struct c_expr expression
;
7246 /* Parse a generic-selection. (C11 6.5.1.1).
7249 _Generic ( assignment-expression , generic-assoc-list )
7253 generic-assoc-list , generic-association
7255 generic-association:
7256 type-name : assignment-expression
7257 default : assignment-expression
7260 static struct c_expr
7261 c_parser_generic_selection (c_parser
*parser
)
7263 struct c_expr selector
, error_expr
;
7265 struct c_generic_association matched_assoc
;
7266 bool match_found
= false;
7267 location_t generic_loc
, selector_loc
;
7269 error_expr
.original_code
= ERROR_MARK
;
7270 error_expr
.original_type
= NULL
;
7271 error_expr
.set_error ();
7272 matched_assoc
.type_location
= UNKNOWN_LOCATION
;
7273 matched_assoc
.type
= NULL_TREE
;
7274 matched_assoc
.expression
= error_expr
;
7276 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_GENERIC
));
7277 generic_loc
= c_parser_peek_token (parser
)->location
;
7278 c_parser_consume_token (parser
);
7280 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7281 "ISO C99 does not support %<_Generic%>");
7283 pedwarn_c99 (generic_loc
, OPT_Wpedantic
,
7284 "ISO C90 does not support %<_Generic%>");
7286 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7289 c_inhibit_evaluation_warnings
++;
7290 selector_loc
= c_parser_peek_token (parser
)->location
;
7291 selector
= c_parser_expr_no_commas (parser
, NULL
);
7292 selector
= default_function_array_conversion (selector_loc
, selector
);
7293 c_inhibit_evaluation_warnings
--;
7295 if (selector
.value
== error_mark_node
)
7297 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7300 selector_type
= TREE_TYPE (selector
.value
);
7301 /* In ISO C terms, rvalues (including the controlling expression of
7302 _Generic) do not have qualified types. */
7303 if (TREE_CODE (selector_type
) != ARRAY_TYPE
)
7304 selector_type
= TYPE_MAIN_VARIANT (selector_type
);
7305 /* In ISO C terms, _Noreturn is not part of the type of expressions
7306 such as &abort, but in GCC it is represented internally as a type
7308 if (FUNCTION_POINTER_TYPE_P (selector_type
)
7309 && TYPE_QUALS (TREE_TYPE (selector_type
)) != TYPE_UNQUALIFIED
)
7311 = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type
)));
7313 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7315 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7319 auto_vec
<c_generic_association
> associations
;
7322 struct c_generic_association assoc
, *iter
;
7324 c_token
*token
= c_parser_peek_token (parser
);
7326 assoc
.type_location
= token
->location
;
7327 if (token
->type
== CPP_KEYWORD
&& token
->keyword
== RID_DEFAULT
)
7329 c_parser_consume_token (parser
);
7330 assoc
.type
= NULL_TREE
;
7334 struct c_type_name
*type_name
;
7336 type_name
= c_parser_type_name (parser
);
7337 if (type_name
== NULL
)
7339 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7342 assoc
.type
= groktypename (type_name
, NULL
, NULL
);
7343 if (assoc
.type
== error_mark_node
)
7345 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7349 if (TREE_CODE (assoc
.type
) == FUNCTION_TYPE
)
7350 error_at (assoc
.type_location
,
7351 "%<_Generic%> association has function type");
7352 else if (!COMPLETE_TYPE_P (assoc
.type
))
7353 error_at (assoc
.type_location
,
7354 "%<_Generic%> association has incomplete type");
7356 if (variably_modified_type_p (assoc
.type
, NULL_TREE
))
7357 error_at (assoc
.type_location
,
7358 "%<_Generic%> association has "
7359 "variable length type");
7362 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
7364 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7368 assoc
.expression
= c_parser_expr_no_commas (parser
, NULL
);
7369 if (assoc
.expression
.value
== error_mark_node
)
7371 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7375 for (ix
= 0; associations
.iterate (ix
, &iter
); ++ix
)
7377 if (assoc
.type
== NULL_TREE
)
7379 if (iter
->type
== NULL_TREE
)
7381 error_at (assoc
.type_location
,
7382 "duplicate %<default%> case in %<_Generic%>");
7383 inform (iter
->type_location
, "original %<default%> is here");
7386 else if (iter
->type
!= NULL_TREE
)
7388 if (comptypes (assoc
.type
, iter
->type
))
7390 error_at (assoc
.type_location
,
7391 "%<_Generic%> specifies two compatible types");
7392 inform (iter
->type_location
, "compatible type is here");
7397 if (assoc
.type
== NULL_TREE
)
7401 matched_assoc
= assoc
;
7405 else if (comptypes (assoc
.type
, selector_type
))
7407 if (!match_found
|| matched_assoc
.type
== NULL_TREE
)
7409 matched_assoc
= assoc
;
7414 error_at (assoc
.type_location
,
7415 "%<_Generic> selector matches multiple associations");
7416 inform (matched_assoc
.type_location
,
7417 "other match is here");
7421 associations
.safe_push (assoc
);
7423 if (c_parser_peek_token (parser
)->type
!= CPP_COMMA
)
7425 c_parser_consume_token (parser
);
7428 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
7430 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7436 error_at (selector_loc
, "%<_Generic%> selector of type %qT is not "
7437 "compatible with any association",
7442 return matched_assoc
.expression
;
7445 /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2).
7449 postfix-expression [ expression ]
7450 postfix-expression ( argument-expression-list[opt] )
7451 postfix-expression . identifier
7452 postfix-expression -> identifier
7453 postfix-expression ++
7454 postfix-expression --
7455 ( type-name ) { initializer-list }
7456 ( type-name ) { initializer-list , }
7458 argument-expression-list:
7460 argument-expression-list , argument-expression
7473 (treated as a keyword in GNU C)
7476 ( compound-statement )
7477 __builtin_va_arg ( assignment-expression , type-name )
7478 __builtin_offsetof ( type-name , offsetof-member-designator )
7479 __builtin_choose_expr ( assignment-expression ,
7480 assignment-expression ,
7481 assignment-expression )
7482 __builtin_types_compatible_p ( type-name , type-name )
7483 __builtin_complex ( assignment-expression , assignment-expression )
7484 __builtin_shuffle ( assignment-expression , assignment-expression )
7485 __builtin_shuffle ( assignment-expression ,
7486 assignment-expression ,
7487 assignment-expression, )
7489 offsetof-member-designator:
7491 offsetof-member-designator . identifier
7492 offsetof-member-designator [ expression ]
7497 [ objc-receiver objc-message-args ]
7498 @selector ( objc-selector-arg )
7499 @protocol ( identifier )
7500 @encode ( type-name )
7502 Classname . identifier
7505 static struct c_expr
7506 c_parser_postfix_expression (c_parser
*parser
)
7508 struct c_expr expr
, e1
;
7509 struct c_type_name
*t1
, *t2
;
7510 location_t loc
= c_parser_peek_token (parser
)->location
;;
7511 source_range tok_range
= c_parser_peek_token (parser
)->get_range ();
7512 expr
.original_code
= ERROR_MARK
;
7513 expr
.original_type
= NULL
;
7514 switch (c_parser_peek_token (parser
)->type
)
7517 expr
.value
= c_parser_peek_token (parser
)->value
;
7518 set_c_expr_source_range (&expr
, tok_range
);
7519 loc
= c_parser_peek_token (parser
)->location
;
7520 c_parser_consume_token (parser
);
7521 if (TREE_CODE (expr
.value
) == FIXED_CST
7522 && !targetm
.fixed_point_supported_p ())
7524 error_at (loc
, "fixed-point types not supported for this target");
7525 expr
.value
= error_mark_node
;
7532 expr
.value
= c_parser_peek_token (parser
)->value
;
7533 set_c_expr_source_range (&expr
, tok_range
);
7534 c_parser_consume_token (parser
);
7540 case CPP_UTF8STRING
:
7541 expr
.value
= c_parser_peek_token (parser
)->value
;
7542 set_c_expr_source_range (&expr
, tok_range
);
7543 expr
.original_code
= STRING_CST
;
7544 c_parser_consume_token (parser
);
7546 case CPP_OBJC_STRING
:
7547 gcc_assert (c_dialect_objc ());
7549 = objc_build_string_object (c_parser_peek_token (parser
)->value
);
7550 set_c_expr_source_range (&expr
, tok_range
);
7551 c_parser_consume_token (parser
);
7554 switch (c_parser_peek_token (parser
)->id_kind
)
7558 tree id
= c_parser_peek_token (parser
)->value
;
7559 c_parser_consume_token (parser
);
7560 expr
.value
= build_external_ref (loc
, id
,
7561 (c_parser_peek_token (parser
)->type
7563 &expr
.original_type
);
7564 set_c_expr_source_range (&expr
, tok_range
);
7567 case C_ID_CLASSNAME
:
7569 /* Here we parse the Objective-C 2.0 Class.name dot
7571 tree class_name
= c_parser_peek_token (parser
)->value
;
7573 c_parser_consume_token (parser
);
7574 gcc_assert (c_dialect_objc ());
7575 if (!c_parser_require (parser
, CPP_DOT
, "expected %<.%>"))
7580 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
7582 c_parser_error (parser
, "expected identifier");
7586 c_token
*component_tok
= c_parser_peek_token (parser
);
7587 component
= component_tok
->value
;
7588 location_t end_loc
= component_tok
->get_finish ();
7589 c_parser_consume_token (parser
);
7590 expr
.value
= objc_build_class_component_ref (class_name
,
7592 set_c_expr_source_range (&expr
, loc
, end_loc
);
7596 c_parser_error (parser
, "expected expression");
7601 case CPP_OPEN_PAREN
:
7602 /* A parenthesized expression, statement expression or compound
7604 if (c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_BRACE
)
7606 /* A statement expression. */
7608 location_t brace_loc
;
7609 c_parser_consume_token (parser
);
7610 brace_loc
= c_parser_peek_token (parser
)->location
;
7611 c_parser_consume_token (parser
);
7612 if (!building_stmt_list_p ())
7614 error_at (loc
, "braced-group within expression allowed "
7615 "only inside a function");
7616 parser
->error
= true;
7617 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
7618 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7622 stmt
= c_begin_stmt_expr ();
7623 c_parser_compound_statement_nostart (parser
);
7624 location_t close_loc
= c_parser_peek_token (parser
)->location
;
7625 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7627 pedwarn (loc
, OPT_Wpedantic
,
7628 "ISO C forbids braced-groups within expressions");
7629 expr
.value
= c_finish_stmt_expr (brace_loc
, stmt
);
7630 set_c_expr_source_range (&expr
, loc
, close_loc
);
7631 mark_exp_read (expr
.value
);
7633 else if (c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
7635 /* A compound literal. ??? Can we actually get here rather
7636 than going directly to
7637 c_parser_postfix_expression_after_paren_type from
7640 struct c_type_name
*type_name
;
7641 c_parser_consume_token (parser
);
7642 loc
= c_parser_peek_token (parser
)->location
;
7643 type_name
= c_parser_type_name (parser
);
7644 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7646 if (type_name
== NULL
)
7651 expr
= c_parser_postfix_expression_after_paren_type (parser
,
7657 /* A parenthesized expression. */
7658 location_t loc_open_paren
= c_parser_peek_token (parser
)->location
;
7659 c_parser_consume_token (parser
);
7660 expr
= c_parser_expression (parser
);
7661 if (TREE_CODE (expr
.value
) == MODIFY_EXPR
)
7662 TREE_NO_WARNING (expr
.value
) = 1;
7663 if (expr
.original_code
!= C_MAYBE_CONST_EXPR
)
7664 expr
.original_code
= ERROR_MARK
;
7665 /* Don't change EXPR.ORIGINAL_TYPE. */
7666 location_t loc_close_paren
= c_parser_peek_token (parser
)->location
;
7667 set_c_expr_source_range (&expr
, loc_open_paren
, loc_close_paren
);
7668 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7673 switch (c_parser_peek_token (parser
)->keyword
)
7675 case RID_FUNCTION_NAME
:
7676 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7677 "%<__FUNCTION__%> predefined identifier");
7678 expr
.value
= fname_decl (loc
,
7679 c_parser_peek_token (parser
)->keyword
,
7680 c_parser_peek_token (parser
)->value
);
7681 set_c_expr_source_range (&expr
, loc
, loc
);
7682 c_parser_consume_token (parser
);
7684 case RID_PRETTY_FUNCTION_NAME
:
7685 pedwarn (loc
, OPT_Wpedantic
, "ISO C does not support "
7686 "%<__PRETTY_FUNCTION__%> predefined identifier");
7687 expr
.value
= fname_decl (loc
,
7688 c_parser_peek_token (parser
)->keyword
,
7689 c_parser_peek_token (parser
)->value
);
7690 set_c_expr_source_range (&expr
, loc
, loc
);
7691 c_parser_consume_token (parser
);
7693 case RID_C99_FUNCTION_NAME
:
7694 pedwarn_c90 (loc
, OPT_Wpedantic
, "ISO C90 does not support "
7695 "%<__func__%> predefined identifier");
7696 expr
.value
= fname_decl (loc
,
7697 c_parser_peek_token (parser
)->keyword
,
7698 c_parser_peek_token (parser
)->value
);
7699 set_c_expr_source_range (&expr
, loc
, loc
);
7700 c_parser_consume_token (parser
);
7704 location_t start_loc
= loc
;
7705 c_parser_consume_token (parser
);
7706 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7711 e1
= c_parser_expr_no_commas (parser
, NULL
);
7712 mark_exp_read (e1
.value
);
7713 e1
.value
= c_fully_fold (e1
.value
, false, NULL
);
7714 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7716 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7720 loc
= c_parser_peek_token (parser
)->location
;
7721 t1
= c_parser_type_name (parser
);
7722 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
7723 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7731 tree type_expr
= NULL_TREE
;
7732 expr
.value
= c_build_va_arg (start_loc
, e1
.value
, loc
,
7733 groktypename (t1
, &type_expr
, NULL
));
7736 expr
.value
= build2 (C_MAYBE_CONST_EXPR
,
7737 TREE_TYPE (expr
.value
), type_expr
,
7739 C_MAYBE_CONST_EXPR_NON_CONST (expr
.value
) = true;
7741 set_c_expr_source_range (&expr
, start_loc
, end_loc
);
7746 c_parser_consume_token (parser
);
7747 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7752 t1
= c_parser_type_name (parser
);
7754 parser
->error
= true;
7755 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7756 gcc_assert (parser
->error
);
7759 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7765 tree type
= groktypename (t1
, NULL
, NULL
);
7767 if (type
== error_mark_node
)
7768 offsetof_ref
= error_mark_node
;
7771 offsetof_ref
= build1 (INDIRECT_REF
, type
, null_pointer_node
);
7772 SET_EXPR_LOCATION (offsetof_ref
, loc
);
7774 /* Parse the second argument to __builtin_offsetof. We
7775 must have one identifier, and beyond that we want to
7776 accept sub structure and sub array references. */
7777 if (c_parser_next_token_is (parser
, CPP_NAME
))
7779 c_token
*comp_tok
= c_parser_peek_token (parser
);
7780 offsetof_ref
= build_component_ref
7781 (loc
, offsetof_ref
, comp_tok
->value
, comp_tok
->location
);
7782 c_parser_consume_token (parser
);
7783 while (c_parser_next_token_is (parser
, CPP_DOT
)
7784 || c_parser_next_token_is (parser
,
7786 || c_parser_next_token_is (parser
,
7789 if (c_parser_next_token_is (parser
, CPP_DEREF
))
7791 loc
= c_parser_peek_token (parser
)->location
;
7792 offsetof_ref
= build_array_ref (loc
,
7797 else if (c_parser_next_token_is (parser
, CPP_DOT
))
7800 c_parser_consume_token (parser
);
7801 if (c_parser_next_token_is_not (parser
,
7804 c_parser_error (parser
, "expected identifier");
7807 c_token
*comp_tok
= c_parser_peek_token (parser
);
7808 offsetof_ref
= build_component_ref
7809 (loc
, offsetof_ref
, comp_tok
->value
,
7810 comp_tok
->location
);
7811 c_parser_consume_token (parser
);
7817 loc
= c_parser_peek_token (parser
)->location
;
7818 c_parser_consume_token (parser
);
7819 ce
= c_parser_expression (parser
);
7820 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
7822 idx
= c_fully_fold (idx
, false, NULL
);
7823 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
7825 offsetof_ref
= build_array_ref (loc
, offsetof_ref
, idx
);
7830 c_parser_error (parser
, "expected identifier");
7831 location_t end_loc
= c_parser_peek_token (parser
)->get_finish ();
7832 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7834 expr
.value
= fold_offsetof (offsetof_ref
);
7835 set_c_expr_source_range (&expr
, loc
, end_loc
);
7838 case RID_CHOOSE_EXPR
:
7840 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7841 c_expr_t
*e1_p
, *e2_p
, *e3_p
;
7843 location_t close_paren_loc
;
7845 c_parser_consume_token (parser
);
7846 if (!c_parser_get_builtin_args (parser
,
7847 "__builtin_choose_expr",
7855 if (vec_safe_length (cexpr_list
) != 3)
7857 error_at (loc
, "wrong number of arguments to "
7858 "%<__builtin_choose_expr%>");
7863 e1_p
= &(*cexpr_list
)[0];
7864 e2_p
= &(*cexpr_list
)[1];
7865 e3_p
= &(*cexpr_list
)[2];
7868 mark_exp_read (e2_p
->value
);
7869 mark_exp_read (e3_p
->value
);
7870 if (TREE_CODE (c
) != INTEGER_CST
7871 || !INTEGRAL_TYPE_P (TREE_TYPE (c
)))
7873 "first argument to %<__builtin_choose_expr%> not"
7875 constant_expression_warning (c
);
7876 expr
= integer_zerop (c
) ? *e3_p
: *e2_p
;
7877 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
7880 case RID_TYPES_COMPATIBLE_P
:
7881 c_parser_consume_token (parser
);
7882 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
7887 t1
= c_parser_type_name (parser
);
7893 if (!c_parser_require (parser
, CPP_COMMA
, "expected %<,%>"))
7895 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
7899 t2
= c_parser_type_name (parser
);
7906 location_t close_paren_loc
= c_parser_peek_token (parser
)->location
;
7907 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
7910 e1
= groktypename (t1
, NULL
, NULL
);
7911 e2
= groktypename (t2
, NULL
, NULL
);
7912 if (e1
== error_mark_node
|| e2
== error_mark_node
)
7918 e1
= TYPE_MAIN_VARIANT (e1
);
7919 e2
= TYPE_MAIN_VARIANT (e2
);
7922 = comptypes (e1
, e2
) ? integer_one_node
: integer_zero_node
;
7923 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
7926 case RID_BUILTIN_CALL_WITH_STATIC_CHAIN
:
7928 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7931 location_t close_paren_loc
;
7933 c_parser_consume_token (parser
);
7934 if (!c_parser_get_builtin_args (parser
,
7935 "__builtin_call_with_static_chain",
7942 if (vec_safe_length (cexpr_list
) != 2)
7944 error_at (loc
, "wrong number of arguments to "
7945 "%<__builtin_call_with_static_chain%>");
7950 expr
= (*cexpr_list
)[0];
7951 e2_p
= &(*cexpr_list
)[1];
7952 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
7953 chain_value
= e2_p
->value
;
7954 mark_exp_read (chain_value
);
7956 if (TREE_CODE (expr
.value
) != CALL_EXPR
)
7957 error_at (loc
, "first argument to "
7958 "%<__builtin_call_with_static_chain%> "
7959 "must be a call expression");
7960 else if (TREE_CODE (TREE_TYPE (chain_value
)) != POINTER_TYPE
)
7961 error_at (loc
, "second argument to "
7962 "%<__builtin_call_with_static_chain%> "
7963 "must be a pointer type");
7965 CALL_EXPR_STATIC_CHAIN (expr
.value
) = chain_value
;
7966 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
7969 case RID_BUILTIN_COMPLEX
:
7971 vec
<c_expr_t
, va_gc
> *cexpr_list
;
7972 c_expr_t
*e1_p
, *e2_p
;
7973 location_t close_paren_loc
;
7975 c_parser_consume_token (parser
);
7976 if (!c_parser_get_builtin_args (parser
,
7977 "__builtin_complex",
7985 if (vec_safe_length (cexpr_list
) != 2)
7987 error_at (loc
, "wrong number of arguments to "
7988 "%<__builtin_complex%>");
7993 e1_p
= &(*cexpr_list
)[0];
7994 e2_p
= &(*cexpr_list
)[1];
7996 *e1_p
= convert_lvalue_to_rvalue (loc
, *e1_p
, true, true);
7997 if (TREE_CODE (e1_p
->value
) == EXCESS_PRECISION_EXPR
)
7998 e1_p
->value
= convert (TREE_TYPE (e1_p
->value
),
7999 TREE_OPERAND (e1_p
->value
, 0));
8000 *e2_p
= convert_lvalue_to_rvalue (loc
, *e2_p
, true, true);
8001 if (TREE_CODE (e2_p
->value
) == EXCESS_PRECISION_EXPR
)
8002 e2_p
->value
= convert (TREE_TYPE (e2_p
->value
),
8003 TREE_OPERAND (e2_p
->value
, 0));
8004 if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8005 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p
->value
))
8006 || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
))
8007 || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p
->value
)))
8009 error_at (loc
, "%<__builtin_complex%> operand "
8010 "not of real binary floating-point type");
8014 if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p
->value
))
8015 != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p
->value
)))
8018 "%<__builtin_complex%> operands of different types");
8022 pedwarn_c90 (loc
, OPT_Wpedantic
,
8023 "ISO C90 does not support complex types");
8024 expr
.value
= build2_loc (loc
, COMPLEX_EXPR
,
8027 (TREE_TYPE (e1_p
->value
))),
8028 e1_p
->value
, e2_p
->value
);
8029 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8032 case RID_BUILTIN_SHUFFLE
:
8034 vec
<c_expr_t
, va_gc
> *cexpr_list
;
8037 location_t close_paren_loc
;
8039 c_parser_consume_token (parser
);
8040 if (!c_parser_get_builtin_args (parser
,
8041 "__builtin_shuffle",
8049 FOR_EACH_VEC_SAFE_ELT (cexpr_list
, i
, p
)
8050 *p
= convert_lvalue_to_rvalue (loc
, *p
, true, true);
8052 if (vec_safe_length (cexpr_list
) == 2)
8054 c_build_vec_perm_expr
8055 (loc
, (*cexpr_list
)[0].value
,
8056 NULL_TREE
, (*cexpr_list
)[1].value
);
8058 else if (vec_safe_length (cexpr_list
) == 3)
8060 c_build_vec_perm_expr
8061 (loc
, (*cexpr_list
)[0].value
,
8062 (*cexpr_list
)[1].value
,
8063 (*cexpr_list
)[2].value
);
8066 error_at (loc
, "wrong number of arguments to "
8067 "%<__builtin_shuffle%>");
8070 set_c_expr_source_range (&expr
, loc
, close_paren_loc
);
8073 case RID_AT_SELECTOR
:
8074 gcc_assert (c_dialect_objc ());
8075 c_parser_consume_token (parser
);
8076 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8082 tree sel
= c_parser_objc_selector_arg (parser
);
8083 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8084 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8086 expr
.value
= objc_build_selector_expr (loc
, sel
);
8087 set_c_expr_source_range (&expr
, loc
, close_loc
);
8090 case RID_AT_PROTOCOL
:
8091 gcc_assert (c_dialect_objc ());
8092 c_parser_consume_token (parser
);
8093 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8098 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8100 c_parser_error (parser
, "expected identifier");
8101 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8106 tree id
= c_parser_peek_token (parser
)->value
;
8107 c_parser_consume_token (parser
);
8108 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8109 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8111 expr
.value
= objc_build_protocol_expr (id
);
8112 set_c_expr_source_range (&expr
, loc
, close_loc
);
8116 /* Extension to support C-structures in the archiver. */
8117 gcc_assert (c_dialect_objc ());
8118 c_parser_consume_token (parser
);
8119 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
8124 t1
= c_parser_type_name (parser
);
8128 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8132 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8133 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8135 tree type
= groktypename (t1
, NULL
, NULL
);
8136 expr
.value
= objc_build_encode_expr (type
);
8137 set_c_expr_source_range (&expr
, loc
, close_loc
);
8141 expr
= c_parser_generic_selection (parser
);
8143 case RID_CILK_SPAWN
:
8144 c_parser_consume_token (parser
);
8147 error_at (loc
, "-fcilkplus must be enabled to use "
8149 expr
= c_parser_cast_expression (parser
, NULL
);
8152 else if (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
8154 error_at (loc
, "consecutive %<_Cilk_spawn%> keywords "
8155 "are not permitted");
8156 /* Now flush out all the _Cilk_spawns. */
8157 while (c_parser_peek_token (parser
)->keyword
== RID_CILK_SPAWN
)
8158 c_parser_consume_token (parser
);
8159 expr
= c_parser_cast_expression (parser
, NULL
);
8163 expr
= c_parser_cast_expression (parser
, NULL
);
8164 expr
.value
= build_cilk_spawn (loc
, expr
.value
);
8168 c_parser_error (parser
, "expected expression");
8173 case CPP_OPEN_SQUARE
:
8174 if (c_dialect_objc ())
8176 tree receiver
, args
;
8177 c_parser_consume_token (parser
);
8178 receiver
= c_parser_objc_receiver (parser
);
8179 args
= c_parser_objc_message_args (parser
);
8180 location_t close_loc
= c_parser_peek_token (parser
)->location
;
8181 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8183 expr
.value
= objc_build_message_expr (receiver
, args
);
8184 set_c_expr_source_range (&expr
, loc
, close_loc
);
8187 /* Else fall through to report error. */
8190 c_parser_error (parser
, "expected expression");
8194 return c_parser_postfix_expression_after_primary
8195 (parser
, EXPR_LOC_OR_LOC (expr
.value
, loc
), expr
);
8198 /* Parse a postfix expression after a parenthesized type name: the
8199 brace-enclosed initializer of a compound literal, possibly followed
8200 by some postfix operators. This is separate because it is not
8201 possible to tell until after the type name whether a cast
8202 expression has a cast or a compound literal, or whether the operand
8203 of sizeof is a parenthesized type name or starts with a compound
8204 literal. TYPE_LOC is the location where TYPE_NAME starts--the
8205 location of the first token after the parentheses around the type
8208 static struct c_expr
8209 c_parser_postfix_expression_after_paren_type (c_parser
*parser
,
8210 struct c_type_name
*type_name
,
8211 location_t type_loc
)
8217 location_t start_loc
;
8218 tree type_expr
= NULL_TREE
;
8219 bool type_expr_const
= true;
8220 check_compound_literal_type (type_loc
, type_name
);
8221 start_init (NULL_TREE
, NULL
, 0);
8222 type
= groktypename (type_name
, &type_expr
, &type_expr_const
);
8223 start_loc
= c_parser_peek_token (parser
)->location
;
8224 if (type
!= error_mark_node
&& C_TYPE_VARIABLE_SIZE (type
))
8226 error_at (type_loc
, "compound literal has variable size");
8227 type
= error_mark_node
;
8229 init
= c_parser_braced_init (parser
, type
, false, NULL
);
8231 maybe_warn_string_init (type_loc
, type
, init
);
8233 if (type
!= error_mark_node
8234 && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type
))
8235 && current_function_decl
)
8237 error ("compound literal qualified by address-space qualifier");
8238 type
= error_mark_node
;
8241 pedwarn_c90 (start_loc
, OPT_Wpedantic
, "ISO C90 forbids compound literals");
8242 non_const
= ((init
.value
&& TREE_CODE (init
.value
) == CONSTRUCTOR
)
8243 ? CONSTRUCTOR_NON_CONST (init
.value
)
8244 : init
.original_code
== C_MAYBE_CONST_EXPR
);
8245 non_const
|= !type_expr_const
;
8246 expr
.value
= build_compound_literal (start_loc
, type
, init
.value
, non_const
);
8247 set_c_expr_source_range (&expr
, init
.src_range
);
8248 expr
.original_code
= ERROR_MARK
;
8249 expr
.original_type
= NULL
;
8250 if (type
!= error_mark_node
8251 && expr
.value
!= error_mark_node
8254 if (TREE_CODE (expr
.value
) == C_MAYBE_CONST_EXPR
)
8256 gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr
.value
) == NULL_TREE
);
8257 C_MAYBE_CONST_EXPR_PRE (expr
.value
) = type_expr
;
8261 gcc_assert (!non_const
);
8262 expr
.value
= build2 (C_MAYBE_CONST_EXPR
, type
,
8263 type_expr
, expr
.value
);
8266 return c_parser_postfix_expression_after_primary (parser
, start_loc
, expr
);
8269 /* Callback function for sizeof_pointer_memaccess_warning to compare
8273 sizeof_ptr_memacc_comptypes (tree type1
, tree type2
)
8275 return comptypes (type1
, type2
) == 1;
8278 /* Parse a postfix expression after the initial primary or compound
8279 literal; that is, parse a series of postfix operators.
8281 EXPR_LOC is the location of the primary expression. */
8283 static struct c_expr
8284 c_parser_postfix_expression_after_primary (c_parser
*parser
,
8285 location_t expr_loc
,
8288 struct c_expr orig_expr
;
8290 location_t sizeof_arg_loc
[3], comp_loc
;
8292 unsigned int literal_zero_mask
;
8294 vec
<tree
, va_gc
> *exprlist
;
8295 vec
<tree
, va_gc
> *origtypes
= NULL
;
8296 vec
<location_t
> arg_loc
= vNULL
;
8302 location_t op_loc
= c_parser_peek_token (parser
)->location
;
8303 switch (c_parser_peek_token (parser
)->type
)
8305 case CPP_OPEN_SQUARE
:
8306 /* Array reference. */
8307 c_parser_consume_token (parser
);
8309 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
8310 /* If we are here, then we have something like this:
8313 expr
.value
= c_parser_array_notation (expr_loc
, parser
, NULL_TREE
,
8317 idx
= c_parser_expression (parser
).value
;
8318 /* Here we have 3 options:
8319 1. Array [EXPR] -- Normal Array call.
8320 2. Array [EXPR : EXPR] -- Array notation without stride.
8321 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride.
8323 For 1, we just handle it just like a normal array expression.
8324 For 2 and 3 we handle it like we handle array notations. The
8325 idx value we have above becomes the initial/start index.
8328 && c_parser_peek_token (parser
)->type
== CPP_COLON
)
8329 expr
.value
= c_parser_array_notation (expr_loc
, parser
, idx
,
8333 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
,
8335 start
= expr
.get_start ();
8336 finish
= parser
->tokens_buf
[0].location
;
8337 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
8338 set_c_expr_source_range (&expr
, start
, finish
);
8341 expr
.original_code
= ERROR_MARK
;
8342 expr
.original_type
= NULL
;
8344 case CPP_OPEN_PAREN
:
8345 /* Function call. */
8346 c_parser_consume_token (parser
);
8347 for (i
= 0; i
< 3; i
++)
8349 sizeof_arg
[i
] = NULL_TREE
;
8350 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
8352 literal_zero_mask
= 0;
8353 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8356 exprlist
= c_parser_expr_list (parser
, true, false, &origtypes
,
8357 sizeof_arg_loc
, sizeof_arg
,
8358 &arg_loc
, &literal_zero_mask
);
8359 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
8362 mark_exp_read (expr
.value
);
8363 if (warn_sizeof_pointer_memaccess
)
8364 sizeof_pointer_memaccess_warning (sizeof_arg_loc
,
8365 expr
.value
, exprlist
,
8367 sizeof_ptr_memacc_comptypes
);
8368 if (TREE_CODE (expr
.value
) == FUNCTION_DECL
8369 && DECL_BUILT_IN_CLASS (expr
.value
) == BUILT_IN_NORMAL
8370 && DECL_FUNCTION_CODE (expr
.value
) == BUILT_IN_MEMSET
8371 && vec_safe_length (exprlist
) == 3)
8373 tree arg0
= (*exprlist
)[0];
8374 tree arg2
= (*exprlist
)[2];
8375 warn_for_memset (expr_loc
, arg0
, arg2
, literal_zero_mask
);
8378 if (TREE_CODE (expr
.value
) == FUNCTION_DECL
&& warn_restrict
)
8382 FOR_EACH_VEC_SAFE_ELT (exprlist
, i
, arg
)
8383 TREE_VISITED (arg
) = 0;
8385 unsigned param_pos
= 0;
8386 function_args_iterator iter
;
8388 FOREACH_FUNCTION_ARGS (TREE_TYPE (expr
.value
), t
, iter
)
8390 if (POINTER_TYPE_P (t
) && TYPE_RESTRICT (t
)
8391 && !TYPE_READONLY (TREE_TYPE (t
)))
8392 warn_for_restrict (param_pos
, exprlist
);
8396 FOR_EACH_VEC_SAFE_ELT (exprlist
, i
, arg
)
8397 TREE_VISITED (arg
) = 0;
8400 start
= expr
.get_start ();
8401 finish
= parser
->tokens_buf
[0].get_finish ();
8403 = c_build_function_call_vec (expr_loc
, arg_loc
, expr
.value
,
8404 exprlist
, origtypes
);
8405 set_c_expr_source_range (&expr
, start
, finish
);
8407 expr
.original_code
= ERROR_MARK
;
8408 if (TREE_CODE (expr
.value
) == INTEGER_CST
8409 && TREE_CODE (orig_expr
.value
) == FUNCTION_DECL
8410 && DECL_BUILT_IN_CLASS (orig_expr
.value
) == BUILT_IN_NORMAL
8411 && DECL_FUNCTION_CODE (orig_expr
.value
) == BUILT_IN_CONSTANT_P
)
8412 expr
.original_code
= C_MAYBE_CONST_EXPR
;
8413 expr
.original_type
= NULL
;
8416 release_tree_vector (exprlist
);
8417 release_tree_vector (origtypes
);
8422 /* Structure element reference. */
8423 c_parser_consume_token (parser
);
8424 expr
= default_function_array_conversion (expr_loc
, expr
);
8425 if (c_parser_next_token_is (parser
, CPP_NAME
))
8427 c_token
*comp_tok
= c_parser_peek_token (parser
);
8428 ident
= comp_tok
->value
;
8429 comp_loc
= comp_tok
->location
;
8433 c_parser_error (parser
, "expected identifier");
8435 expr
.original_code
= ERROR_MARK
;
8436 expr
.original_type
= NULL
;
8439 start
= expr
.get_start ();
8440 finish
= c_parser_peek_token (parser
)->get_finish ();
8441 c_parser_consume_token (parser
);
8442 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
,
8444 set_c_expr_source_range (&expr
, start
, finish
);
8445 expr
.original_code
= ERROR_MARK
;
8446 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8447 expr
.original_type
= NULL
;
8450 /* Remember the original type of a bitfield. */
8451 tree field
= TREE_OPERAND (expr
.value
, 1);
8452 if (TREE_CODE (field
) != FIELD_DECL
)
8453 expr
.original_type
= NULL
;
8455 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8459 /* Structure element reference. */
8460 c_parser_consume_token (parser
);
8461 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, true, false);
8462 if (c_parser_next_token_is (parser
, CPP_NAME
))
8464 c_token
*comp_tok
= c_parser_peek_token (parser
);
8465 ident
= comp_tok
->value
;
8466 comp_loc
= comp_tok
->location
;
8470 c_parser_error (parser
, "expected identifier");
8472 expr
.original_code
= ERROR_MARK
;
8473 expr
.original_type
= NULL
;
8476 start
= expr
.get_start ();
8477 finish
= c_parser_peek_token (parser
)->get_finish ();
8478 c_parser_consume_token (parser
);
8479 expr
.value
= build_component_ref (op_loc
,
8480 build_indirect_ref (op_loc
,
8484 set_c_expr_source_range (&expr
, start
, finish
);
8485 expr
.original_code
= ERROR_MARK
;
8486 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
8487 expr
.original_type
= NULL
;
8490 /* Remember the original type of a bitfield. */
8491 tree field
= TREE_OPERAND (expr
.value
, 1);
8492 if (TREE_CODE (field
) != FIELD_DECL
)
8493 expr
.original_type
= NULL
;
8495 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
8499 /* Postincrement. */
8500 start
= expr
.get_start ();
8501 finish
= c_parser_peek_token (parser
)->get_finish ();
8502 c_parser_consume_token (parser
);
8503 /* If the expressions have array notations, we expand them. */
8505 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8506 expr
= fix_array_notation_expr (expr_loc
, POSTINCREMENT_EXPR
, expr
);
8509 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8510 expr
.value
= build_unary_op (op_loc
, POSTINCREMENT_EXPR
,
8513 set_c_expr_source_range (&expr
, start
, finish
);
8514 expr
.original_code
= ERROR_MARK
;
8515 expr
.original_type
= NULL
;
8517 case CPP_MINUS_MINUS
:
8518 /* Postdecrement. */
8519 start
= expr
.get_start ();
8520 finish
= c_parser_peek_token (parser
)->get_finish ();
8521 c_parser_consume_token (parser
);
8522 /* If the expressions have array notations, we expand them. */
8524 && TREE_CODE (expr
.value
) == ARRAY_NOTATION_REF
)
8525 expr
= fix_array_notation_expr (expr_loc
, POSTDECREMENT_EXPR
, expr
);
8528 expr
= default_function_array_read_conversion (expr_loc
, expr
);
8529 expr
.value
= build_unary_op (op_loc
, POSTDECREMENT_EXPR
,
8532 set_c_expr_source_range (&expr
, start
, finish
);
8533 expr
.original_code
= ERROR_MARK
;
8534 expr
.original_type
= NULL
;
8542 /* Parse an expression (C90 6.3.17, C99 6.5.17).
8545 assignment-expression
8546 expression , assignment-expression
8549 static struct c_expr
8550 c_parser_expression (c_parser
*parser
)
8552 location_t tloc
= c_parser_peek_token (parser
)->location
;
8554 expr
= c_parser_expr_no_commas (parser
, NULL
);
8555 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8556 expr
= convert_lvalue_to_rvalue (tloc
, expr
, true, false);
8557 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8561 location_t loc
= c_parser_peek_token (parser
)->location
;
8562 location_t expr_loc
;
8563 c_parser_consume_token (parser
);
8564 expr_loc
= c_parser_peek_token (parser
)->location
;
8565 lhsval
= expr
.value
;
8566 while (TREE_CODE (lhsval
) == COMPOUND_EXPR
)
8567 lhsval
= TREE_OPERAND (lhsval
, 1);
8568 if (DECL_P (lhsval
) || handled_component_p (lhsval
))
8569 mark_exp_read (lhsval
);
8570 next
= c_parser_expr_no_commas (parser
, NULL
);
8571 next
= convert_lvalue_to_rvalue (expr_loc
, next
, true, false);
8572 expr
.value
= build_compound_expr (loc
, expr
.value
, next
.value
);
8573 expr
.original_code
= COMPOUND_EXPR
;
8574 expr
.original_type
= next
.original_type
;
8579 /* Parse an expression and convert functions or arrays to pointers and
8580 lvalues to rvalues. */
8582 static struct c_expr
8583 c_parser_expression_conv (c_parser
*parser
)
8586 location_t loc
= c_parser_peek_token (parser
)->location
;
8587 expr
= c_parser_expression (parser
);
8588 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, false);
8592 /* Helper function of c_parser_expr_list. Check if IDXth (0 based)
8593 argument is a literal zero alone and if so, set it in literal_zero_mask. */
8596 c_parser_check_literal_zero (c_parser
*parser
, unsigned *literal_zero_mask
,
8599 if (idx
>= HOST_BITS_PER_INT
)
8602 c_token
*tok
= c_parser_peek_token (parser
);
8610 /* If a parameter is literal zero alone, remember it
8611 for -Wmemset-transposed-args warning. */
8612 if (integer_zerop (tok
->value
)
8613 && !TREE_OVERFLOW (tok
->value
)
8614 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
8615 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
8616 *literal_zero_mask
|= 1U << idx
;
8622 /* Parse a non-empty list of expressions. If CONVERT_P, convert
8623 functions and arrays to pointers and lvalues to rvalues. If
8624 FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the
8625 locations of function arguments into this vector.
8628 assignment-expression
8629 nonempty-expr-list , assignment-expression
8632 static vec
<tree
, va_gc
> *
8633 c_parser_expr_list (c_parser
*parser
, bool convert_p
, bool fold_p
,
8634 vec
<tree
, va_gc
> **p_orig_types
,
8635 location_t
*sizeof_arg_loc
, tree
*sizeof_arg
,
8636 vec
<location_t
> *locations
,
8637 unsigned int *literal_zero_mask
)
8639 vec
<tree
, va_gc
> *ret
;
8640 vec
<tree
, va_gc
> *orig_types
;
8642 location_t loc
= c_parser_peek_token (parser
)->location
;
8643 location_t cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8644 unsigned int idx
= 0;
8646 ret
= make_tree_vector ();
8647 if (p_orig_types
== NULL
)
8650 orig_types
= make_tree_vector ();
8652 if (sizeof_arg
!= NULL
8653 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8654 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8655 if (literal_zero_mask
)
8656 c_parser_check_literal_zero (parser
, literal_zero_mask
, 0);
8657 expr
= c_parser_expr_no_commas (parser
, NULL
);
8659 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8661 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8662 ret
->quick_push (expr
.value
);
8664 orig_types
->quick_push (expr
.original_type
);
8666 locations
->safe_push (loc
);
8667 if (sizeof_arg
!= NULL
8668 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8669 && expr
.original_code
== SIZEOF_EXPR
)
8671 sizeof_arg
[0] = c_last_sizeof_arg
;
8672 sizeof_arg_loc
[0] = cur_sizeof_arg_loc
;
8674 while (c_parser_next_token_is (parser
, CPP_COMMA
))
8676 c_parser_consume_token (parser
);
8677 loc
= c_parser_peek_token (parser
)->location
;
8678 if (sizeof_arg
!= NULL
8679 && c_parser_next_token_is_keyword (parser
, RID_SIZEOF
))
8680 cur_sizeof_arg_loc
= c_parser_peek_2nd_token (parser
)->location
;
8682 cur_sizeof_arg_loc
= UNKNOWN_LOCATION
;
8683 if (literal_zero_mask
)
8684 c_parser_check_literal_zero (parser
, literal_zero_mask
, idx
+ 1);
8685 expr
= c_parser_expr_no_commas (parser
, NULL
);
8687 expr
= convert_lvalue_to_rvalue (loc
, expr
, true, true);
8689 expr
.value
= c_fully_fold (expr
.value
, false, NULL
);
8690 vec_safe_push (ret
, expr
.value
);
8692 vec_safe_push (orig_types
, expr
.original_type
);
8694 locations
->safe_push (loc
);
8696 && sizeof_arg
!= NULL
8697 && cur_sizeof_arg_loc
!= UNKNOWN_LOCATION
8698 && expr
.original_code
== SIZEOF_EXPR
)
8700 sizeof_arg
[idx
] = c_last_sizeof_arg
;
8701 sizeof_arg_loc
[idx
] = cur_sizeof_arg_loc
;
8705 *p_orig_types
= orig_types
;
8709 /* Parse Objective-C-specific constructs. */
8711 /* Parse an objc-class-definition.
8713 objc-class-definition:
8714 @interface identifier objc-superclass[opt] objc-protocol-refs[opt]
8715 objc-class-instance-variables[opt] objc-methodprotolist @end
8716 @implementation identifier objc-superclass[opt]
8717 objc-class-instance-variables[opt]
8718 @interface identifier ( identifier ) objc-protocol-refs[opt]
8719 objc-methodprotolist @end
8720 @interface identifier ( ) objc-protocol-refs[opt]
8721 objc-methodprotolist @end
8722 @implementation identifier ( identifier )
8727 "@interface identifier (" must start "@interface identifier (
8728 identifier ) ...": objc-methodprotolist in the first production may
8729 not start with a parenthesized identifier as a declarator of a data
8730 definition with no declaration specifiers if the objc-superclass,
8731 objc-protocol-refs and objc-class-instance-variables are omitted. */
8734 c_parser_objc_class_definition (c_parser
*parser
, tree attributes
)
8739 if (c_parser_next_token_is_keyword (parser
, RID_AT_INTERFACE
))
8741 else if (c_parser_next_token_is_keyword (parser
, RID_AT_IMPLEMENTATION
))
8746 c_parser_consume_token (parser
);
8747 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8749 c_parser_error (parser
, "expected identifier");
8752 id1
= c_parser_peek_token (parser
)->value
;
8753 c_parser_consume_token (parser
);
8754 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
8756 /* We have a category or class extension. */
8758 tree proto
= NULL_TREE
;
8759 c_parser_consume_token (parser
);
8760 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8762 if (iface_p
&& c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
8764 /* We have a class extension. */
8769 c_parser_error (parser
, "expected identifier or %<)%>");
8770 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
8776 id2
= c_parser_peek_token (parser
)->value
;
8777 c_parser_consume_token (parser
);
8779 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
8782 objc_start_category_implementation (id1
, id2
);
8785 if (c_parser_next_token_is (parser
, CPP_LESS
))
8786 proto
= c_parser_objc_protocol_refs (parser
);
8787 objc_start_category_interface (id1
, id2
, proto
, attributes
);
8788 c_parser_objc_methodprotolist (parser
);
8789 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8790 objc_finish_interface ();
8793 if (c_parser_next_token_is (parser
, CPP_COLON
))
8795 c_parser_consume_token (parser
);
8796 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8798 c_parser_error (parser
, "expected identifier");
8801 superclass
= c_parser_peek_token (parser
)->value
;
8802 c_parser_consume_token (parser
);
8805 superclass
= NULL_TREE
;
8808 tree proto
= NULL_TREE
;
8809 if (c_parser_next_token_is (parser
, CPP_LESS
))
8810 proto
= c_parser_objc_protocol_refs (parser
);
8811 objc_start_class_interface (id1
, superclass
, proto
, attributes
);
8814 objc_start_class_implementation (id1
, superclass
);
8815 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
8816 c_parser_objc_class_instance_variables (parser
);
8819 objc_continue_interface ();
8820 c_parser_objc_methodprotolist (parser
);
8821 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
8822 objc_finish_interface ();
8826 objc_continue_implementation ();
8831 /* Parse objc-class-instance-variables.
8833 objc-class-instance-variables:
8834 { objc-instance-variable-decl-list[opt] }
8836 objc-instance-variable-decl-list:
8837 objc-visibility-spec
8838 objc-instance-variable-decl ;
8840 objc-instance-variable-decl-list objc-visibility-spec
8841 objc-instance-variable-decl-list objc-instance-variable-decl ;
8842 objc-instance-variable-decl-list ;
8844 objc-visibility-spec:
8849 objc-instance-variable-decl:
8854 c_parser_objc_class_instance_variables (c_parser
*parser
)
8856 gcc_assert (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
));
8857 c_parser_consume_token (parser
);
8858 while (c_parser_next_token_is_not (parser
, CPP_EOF
))
8861 /* Parse any stray semicolon. */
8862 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
8864 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
8866 c_parser_consume_token (parser
);
8869 /* Stop if at the end of the instance variables. */
8870 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
8872 c_parser_consume_token (parser
);
8875 /* Parse any objc-visibility-spec. */
8876 if (c_parser_next_token_is_keyword (parser
, RID_AT_PRIVATE
))
8878 c_parser_consume_token (parser
);
8879 objc_set_visibility (OBJC_IVAR_VIS_PRIVATE
);
8882 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROTECTED
))
8884 c_parser_consume_token (parser
);
8885 objc_set_visibility (OBJC_IVAR_VIS_PROTECTED
);
8888 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PUBLIC
))
8890 c_parser_consume_token (parser
);
8891 objc_set_visibility (OBJC_IVAR_VIS_PUBLIC
);
8894 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PACKAGE
))
8896 c_parser_consume_token (parser
);
8897 objc_set_visibility (OBJC_IVAR_VIS_PACKAGE
);
8900 else if (c_parser_next_token_is (parser
, CPP_PRAGMA
))
8902 c_parser_pragma (parser
, pragma_external
, NULL
);
8906 /* Parse some comma-separated declarations. */
8907 decls
= c_parser_struct_declaration (parser
);
8910 /* There is a syntax error. We want to skip the offending
8911 tokens up to the next ';' (included) or '}'
8914 /* First, skip manually a ')' or ']'. This is because they
8915 reduce the nesting level, so c_parser_skip_until_found()
8916 wouldn't be able to skip past them. */
8917 c_token
*token
= c_parser_peek_token (parser
);
8918 if (token
->type
== CPP_CLOSE_PAREN
|| token
->type
== CPP_CLOSE_SQUARE
)
8919 c_parser_consume_token (parser
);
8921 /* Then, do the standard skipping. */
8922 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8924 /* We hopefully recovered. Start normal parsing again. */
8925 parser
->error
= false;
8930 /* Comma-separated instance variables are chained together
8931 in reverse order; add them one by one. */
8932 tree ivar
= nreverse (decls
);
8933 for (; ivar
; ivar
= DECL_CHAIN (ivar
))
8934 objc_add_instance_variable (copy_node (ivar
));
8936 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8940 /* Parse an objc-class-declaration.
8942 objc-class-declaration:
8943 @class identifier-list ;
8947 c_parser_objc_class_declaration (c_parser
*parser
)
8949 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_CLASS
));
8950 c_parser_consume_token (parser
);
8951 /* Any identifiers, including those declared as type names, are OK
8956 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8958 c_parser_error (parser
, "expected identifier");
8959 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8960 parser
->error
= false;
8963 id
= c_parser_peek_token (parser
)->value
;
8964 objc_declare_class (id
);
8965 c_parser_consume_token (parser
);
8966 if (c_parser_next_token_is (parser
, CPP_COMMA
))
8967 c_parser_consume_token (parser
);
8971 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
8974 /* Parse an objc-alias-declaration.
8976 objc-alias-declaration:
8977 @compatibility_alias identifier identifier ;
8981 c_parser_objc_alias_declaration (c_parser
*parser
)
8984 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_ALIAS
));
8985 c_parser_consume_token (parser
);
8986 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8988 c_parser_error (parser
, "expected identifier");
8989 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
8992 id1
= c_parser_peek_token (parser
)->value
;
8993 c_parser_consume_token (parser
);
8994 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
8996 c_parser_error (parser
, "expected identifier");
8997 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9000 id2
= c_parser_peek_token (parser
)->value
;
9001 c_parser_consume_token (parser
);
9002 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9003 objc_declare_alias (id1
, id2
);
9006 /* Parse an objc-protocol-definition.
9008 objc-protocol-definition:
9009 @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end
9010 @protocol identifier-list ;
9012 "@protocol identifier ;" should be resolved as "@protocol
9013 identifier-list ;": objc-methodprotolist may not start with a
9014 semicolon in the first alternative if objc-protocol-refs are
9018 c_parser_objc_protocol_definition (c_parser
*parser
, tree attributes
)
9020 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROTOCOL
));
9022 c_parser_consume_token (parser
);
9023 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9025 c_parser_error (parser
, "expected identifier");
9028 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
9029 || c_parser_peek_2nd_token (parser
)->type
== CPP_SEMICOLON
)
9031 /* Any identifiers, including those declared as type names, are
9036 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9038 c_parser_error (parser
, "expected identifier");
9041 id
= c_parser_peek_token (parser
)->value
;
9042 objc_declare_protocol (id
, attributes
);
9043 c_parser_consume_token (parser
);
9044 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9045 c_parser_consume_token (parser
);
9049 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9053 tree id
= c_parser_peek_token (parser
)->value
;
9054 tree proto
= NULL_TREE
;
9055 c_parser_consume_token (parser
);
9056 if (c_parser_next_token_is (parser
, CPP_LESS
))
9057 proto
= c_parser_objc_protocol_refs (parser
);
9058 parser
->objc_pq_context
= true;
9059 objc_start_protocol (id
, proto
, attributes
);
9060 c_parser_objc_methodprotolist (parser
);
9061 c_parser_require_keyword (parser
, RID_AT_END
, "expected %<@end%>");
9062 parser
->objc_pq_context
= false;
9063 objc_finish_interface ();
9067 /* Parse an objc-method-type.
9073 Return true if it is a class method (+) and false if it is
9074 an instance method (-).
9077 c_parser_objc_method_type (c_parser
*parser
)
9079 switch (c_parser_peek_token (parser
)->type
)
9082 c_parser_consume_token (parser
);
9085 c_parser_consume_token (parser
);
9092 /* Parse an objc-method-definition.
9094 objc-method-definition:
9095 objc-method-type objc-method-decl ;[opt] compound-statement
9099 c_parser_objc_method_definition (c_parser
*parser
)
9101 bool is_class_method
= c_parser_objc_method_type (parser
);
9102 tree decl
, attributes
= NULL_TREE
, expr
= NULL_TREE
;
9103 parser
->objc_pq_context
= true;
9104 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9106 if (decl
== error_mark_node
)
9107 return; /* Bail here. */
9109 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9111 c_parser_consume_token (parser
);
9112 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9113 "extra semicolon in method definition specified");
9116 if (!c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9118 c_parser_error (parser
, "expected %<{%>");
9122 parser
->objc_pq_context
= false;
9123 if (objc_start_method_definition (is_class_method
, decl
, attributes
, expr
))
9125 add_stmt (c_parser_compound_statement (parser
));
9126 objc_finish_method_definition (current_function_decl
);
9130 /* This code is executed when we find a method definition
9131 outside of an @implementation context (or invalid for other
9132 reasons). Parse the method (to keep going) but do not emit
9135 c_parser_compound_statement (parser
);
9139 /* Parse an objc-methodprotolist.
9141 objc-methodprotolist:
9143 objc-methodprotolist objc-methodproto
9144 objc-methodprotolist declaration
9145 objc-methodprotolist ;
9149 The declaration is a data definition, which may be missing
9150 declaration specifiers under the same rules and diagnostics as
9151 other data definitions outside functions, and the stray semicolon
9152 is diagnosed the same way as a stray semicolon outside a
9156 c_parser_objc_methodprotolist (c_parser
*parser
)
9160 /* The list is terminated by @end. */
9161 switch (c_parser_peek_token (parser
)->type
)
9164 pedwarn (c_parser_peek_token (parser
)->location
, OPT_Wpedantic
,
9165 "ISO C does not allow extra %<;%> outside of a function");
9166 c_parser_consume_token (parser
);
9170 c_parser_objc_methodproto (parser
);
9173 c_parser_pragma (parser
, pragma_external
, NULL
);
9178 if (c_parser_next_token_is_keyword (parser
, RID_AT_END
))
9180 else if (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
))
9181 c_parser_objc_at_property_declaration (parser
);
9182 else if (c_parser_next_token_is_keyword (parser
, RID_AT_OPTIONAL
))
9184 objc_set_method_opt (true);
9185 c_parser_consume_token (parser
);
9187 else if (c_parser_next_token_is_keyword (parser
, RID_AT_REQUIRED
))
9189 objc_set_method_opt (false);
9190 c_parser_consume_token (parser
);
9193 c_parser_declaration_or_fndef (parser
, false, false, true,
9194 false, true, NULL
, vNULL
);
9200 /* Parse an objc-methodproto.
9203 objc-method-type objc-method-decl ;
9207 c_parser_objc_methodproto (c_parser
*parser
)
9209 bool is_class_method
= c_parser_objc_method_type (parser
);
9210 tree decl
, attributes
= NULL_TREE
;
9212 /* Remember protocol qualifiers in prototypes. */
9213 parser
->objc_pq_context
= true;
9214 decl
= c_parser_objc_method_decl (parser
, is_class_method
, &attributes
,
9216 /* Forget protocol qualifiers now. */
9217 parser
->objc_pq_context
= false;
9219 /* Do not allow the presence of attributes to hide an erroneous
9220 method implementation in the interface section. */
9221 if (!c_parser_next_token_is (parser
, CPP_SEMICOLON
))
9223 c_parser_error (parser
, "expected %<;%>");
9227 if (decl
!= error_mark_node
)
9228 objc_add_method_declaration (is_class_method
, decl
, attributes
);
9230 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
9233 /* If we are at a position that method attributes may be present, check that
9234 there are not any parsed already (a syntax error) and then collect any
9235 specified at the current location. Finally, if new attributes were present,
9236 check that the next token is legal ( ';' for decls and '{' for defs). */
9239 c_parser_objc_maybe_method_attributes (c_parser
* parser
, tree
* attributes
)
9244 c_parser_error (parser
,
9245 "method attributes must be specified at the end only");
9246 *attributes
= NULL_TREE
;
9250 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
9251 *attributes
= c_parser_attributes (parser
);
9253 /* If there were no attributes here, just report any earlier error. */
9254 if (*attributes
== NULL_TREE
|| bad
)
9257 /* If the attributes are followed by a ; or {, then just report any earlier
9259 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
9260 || c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
9263 /* We've got attributes, but not at the end. */
9264 c_parser_error (parser
,
9265 "expected %<;%> or %<{%> after method attribute definition");
9269 /* Parse an objc-method-decl.
9272 ( objc-type-name ) objc-selector
9274 ( objc-type-name ) objc-keyword-selector objc-optparmlist
9275 objc-keyword-selector objc-optparmlist
9278 objc-keyword-selector:
9280 objc-keyword-selector objc-keyword-decl
9283 objc-selector : ( objc-type-name ) identifier
9284 objc-selector : identifier
9285 : ( objc-type-name ) identifier
9289 objc-optparms objc-optellipsis
9293 objc-opt-parms , parameter-declaration
9301 c_parser_objc_method_decl (c_parser
*parser
, bool is_class_method
,
9302 tree
*attributes
, tree
*expr
)
9304 tree type
= NULL_TREE
;
9306 tree parms
= NULL_TREE
;
9307 bool ellipsis
= false;
9308 bool attr_err
= false;
9310 *attributes
= NULL_TREE
;
9311 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9313 c_parser_consume_token (parser
);
9314 type
= c_parser_objc_type_name (parser
);
9315 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9317 sel
= c_parser_objc_selector (parser
);
9318 /* If there is no selector, or a colon follows, we have an
9319 objc-keyword-selector. If there is a selector, and a colon does
9320 not follow, that selector ends the objc-method-decl. */
9321 if (!sel
|| c_parser_next_token_is (parser
, CPP_COLON
))
9324 tree list
= NULL_TREE
;
9327 tree atype
= NULL_TREE
, id
, keyworddecl
;
9328 tree param_attr
= NULL_TREE
;
9329 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9331 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9333 c_parser_consume_token (parser
);
9334 atype
= c_parser_objc_type_name (parser
);
9335 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
9338 /* New ObjC allows attributes on method parameters. */
9339 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
9340 param_attr
= c_parser_attributes (parser
);
9341 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9343 c_parser_error (parser
, "expected identifier");
9344 return error_mark_node
;
9346 id
= c_parser_peek_token (parser
)->value
;
9347 c_parser_consume_token (parser
);
9348 keyworddecl
= objc_build_keyword_decl (tsel
, atype
, id
, param_attr
);
9349 list
= chainon (list
, keyworddecl
);
9350 tsel
= c_parser_objc_selector (parser
);
9351 if (!tsel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9355 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
9357 /* Parse the optional parameter list. Optional Objective-C
9358 method parameters follow the C syntax, and may include '...'
9359 to denote a variable number of arguments. */
9360 parms
= make_node (TREE_LIST
);
9361 while (c_parser_next_token_is (parser
, CPP_COMMA
))
9363 struct c_parm
*parm
;
9364 c_parser_consume_token (parser
);
9365 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9368 c_parser_consume_token (parser
);
9369 attr_err
|= c_parser_objc_maybe_method_attributes
9370 (parser
, attributes
) ;
9373 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9376 parms
= chainon (parms
,
9377 build_tree_list (NULL_TREE
, grokparm (parm
, expr
)));
9382 attr_err
|= c_parser_objc_maybe_method_attributes (parser
, attributes
) ;
9386 c_parser_error (parser
, "objective-c method declaration is expected");
9387 return error_mark_node
;
9391 return error_mark_node
;
9393 return objc_build_method_signature (is_class_method
, type
, sel
, parms
, ellipsis
);
9396 /* Parse an objc-type-name.
9399 objc-type-qualifiers[opt] type-name
9400 objc-type-qualifiers[opt]
9402 objc-type-qualifiers:
9404 objc-type-qualifiers objc-type-qualifier
9406 objc-type-qualifier: one of
9407 in out inout bycopy byref oneway
9411 c_parser_objc_type_name (c_parser
*parser
)
9413 tree quals
= NULL_TREE
;
9414 struct c_type_name
*type_name
= NULL
;
9415 tree type
= NULL_TREE
;
9418 c_token
*token
= c_parser_peek_token (parser
);
9419 if (token
->type
== CPP_KEYWORD
9420 && (token
->keyword
== RID_IN
9421 || token
->keyword
== RID_OUT
9422 || token
->keyword
== RID_INOUT
9423 || token
->keyword
== RID_BYCOPY
9424 || token
->keyword
== RID_BYREF
9425 || token
->keyword
== RID_ONEWAY
))
9427 quals
= chainon (build_tree_list (NULL_TREE
, token
->value
), quals
);
9428 c_parser_consume_token (parser
);
9433 if (c_parser_next_tokens_start_typename (parser
, cla_prefer_type
))
9434 type_name
= c_parser_type_name (parser
);
9436 type
= groktypename (type_name
, NULL
, NULL
);
9438 /* If the type is unknown, and error has already been produced and
9439 we need to recover from the error. In that case, use NULL_TREE
9440 for the type, as if no type had been specified; this will use the
9441 default type ('id') which is good for error recovery. */
9442 if (type
== error_mark_node
)
9445 return build_tree_list (quals
, type
);
9448 /* Parse objc-protocol-refs.
9455 c_parser_objc_protocol_refs (c_parser
*parser
)
9457 tree list
= NULL_TREE
;
9458 gcc_assert (c_parser_next_token_is (parser
, CPP_LESS
));
9459 c_parser_consume_token (parser
);
9460 /* Any identifiers, including those declared as type names, are OK
9465 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9467 c_parser_error (parser
, "expected identifier");
9470 id
= c_parser_peek_token (parser
)->value
;
9471 list
= chainon (list
, build_tree_list (NULL_TREE
, id
));
9472 c_parser_consume_token (parser
);
9473 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9474 c_parser_consume_token (parser
);
9478 c_parser_require (parser
, CPP_GREATER
, "expected %<>%>");
9482 /* Parse an objc-try-catch-finally-statement.
9484 objc-try-catch-finally-statement:
9485 @try compound-statement objc-catch-list[opt]
9486 @try compound-statement objc-catch-list[opt] @finally compound-statement
9489 @catch ( objc-catch-parameter-declaration ) compound-statement
9490 objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement
9492 objc-catch-parameter-declaration:
9493 parameter-declaration
9496 where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS.
9498 PS: This function is identical to cp_parser_objc_try_catch_finally_statement
9499 for C++. Keep them in sync. */
9502 c_parser_objc_try_catch_finally_statement (c_parser
*parser
)
9504 location_t location
;
9507 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_TRY
));
9508 c_parser_consume_token (parser
);
9509 location
= c_parser_peek_token (parser
)->location
;
9510 objc_maybe_warn_exceptions (location
);
9511 stmt
= c_parser_compound_statement (parser
);
9512 objc_begin_try_stmt (location
, stmt
);
9514 while (c_parser_next_token_is_keyword (parser
, RID_AT_CATCH
))
9516 struct c_parm
*parm
;
9517 tree parameter_declaration
= error_mark_node
;
9518 bool seen_open_paren
= false;
9520 c_parser_consume_token (parser
);
9521 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9522 seen_open_paren
= true;
9523 if (c_parser_next_token_is (parser
, CPP_ELLIPSIS
))
9525 /* We have "@catch (...)" (where the '...' are literally
9526 what is in the code). Skip the '...'.
9527 parameter_declaration is set to NULL_TREE, and
9528 objc_being_catch_clauses() knows that that means
9530 c_parser_consume_token (parser
);
9531 parameter_declaration
= NULL_TREE
;
9535 /* We have "@catch (NSException *exception)" or something
9536 like that. Parse the parameter declaration. */
9537 parm
= c_parser_parameter_declaration (parser
, NULL_TREE
);
9539 parameter_declaration
= error_mark_node
;
9541 parameter_declaration
= grokparm (parm
, NULL
);
9543 if (seen_open_paren
)
9544 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9547 /* If there was no open parenthesis, we are recovering from
9548 an error, and we are trying to figure out what mistake
9549 the user has made. */
9551 /* If there is an immediate closing parenthesis, the user
9552 probably forgot the opening one (ie, they typed "@catch
9553 NSException *e)". Parse the closing parenthesis and keep
9555 if (c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
9556 c_parser_consume_token (parser
);
9558 /* If these is no immediate closing parenthesis, the user
9559 probably doesn't know that parenthesis are required at
9560 all (ie, they typed "@catch NSException *e"). So, just
9561 forget about the closing parenthesis and keep going. */
9563 objc_begin_catch_clause (parameter_declaration
);
9564 if (c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
9565 c_parser_compound_statement_nostart (parser
);
9566 objc_finish_catch_clause ();
9568 if (c_parser_next_token_is_keyword (parser
, RID_AT_FINALLY
))
9570 c_parser_consume_token (parser
);
9571 location
= c_parser_peek_token (parser
)->location
;
9572 stmt
= c_parser_compound_statement (parser
);
9573 objc_build_finally_clause (location
, stmt
);
9575 objc_finish_try_stmt ();
9578 /* Parse an objc-synchronized-statement.
9580 objc-synchronized-statement:
9581 @synchronized ( expression ) compound-statement
9585 c_parser_objc_synchronized_statement (c_parser
*parser
)
9589 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNCHRONIZED
));
9590 c_parser_consume_token (parser
);
9591 loc
= c_parser_peek_token (parser
)->location
;
9592 objc_maybe_warn_exceptions (loc
);
9593 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
9595 struct c_expr ce
= c_parser_expression (parser
);
9596 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9598 expr
= c_fully_fold (expr
, false, NULL
);
9599 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9602 expr
= error_mark_node
;
9603 stmt
= c_parser_compound_statement (parser
);
9604 objc_build_synchronized (loc
, expr
, stmt
);
9607 /* Parse an objc-selector; return NULL_TREE without an error if the
9608 next token is not an objc-selector.
9613 enum struct union if else while do for switch case default
9614 break continue return goto asm sizeof typeof __alignof
9615 unsigned long const short volatile signed restrict _Complex
9616 in out inout bycopy byref oneway int char float double void _Bool
9619 ??? Why this selection of keywords but not, for example, storage
9620 class specifiers? */
9623 c_parser_objc_selector (c_parser
*parser
)
9625 c_token
*token
= c_parser_peek_token (parser
);
9626 tree value
= token
->value
;
9627 if (token
->type
== CPP_NAME
)
9629 c_parser_consume_token (parser
);
9632 if (token
->type
!= CPP_KEYWORD
)
9634 switch (token
->keyword
)
9682 c_parser_consume_token (parser
);
9689 /* Parse an objc-selector-arg.
9693 objc-keywordname-list
9695 objc-keywordname-list:
9697 objc-keywordname-list objc-keywordname
9705 c_parser_objc_selector_arg (c_parser
*parser
)
9707 tree sel
= c_parser_objc_selector (parser
);
9708 tree list
= NULL_TREE
;
9709 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9713 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9715 list
= chainon (list
, build_tree_list (sel
, NULL_TREE
));
9716 sel
= c_parser_objc_selector (parser
);
9717 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9723 /* Parse an objc-receiver.
9732 c_parser_objc_receiver (c_parser
*parser
)
9734 location_t loc
= c_parser_peek_token (parser
)->location
;
9736 if (c_parser_peek_token (parser
)->type
== CPP_NAME
9737 && (c_parser_peek_token (parser
)->id_kind
== C_ID_TYPENAME
9738 || c_parser_peek_token (parser
)->id_kind
== C_ID_CLASSNAME
))
9740 tree id
= c_parser_peek_token (parser
)->value
;
9741 c_parser_consume_token (parser
);
9742 return objc_get_class_reference (id
);
9744 struct c_expr ce
= c_parser_expression (parser
);
9745 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
9746 return c_fully_fold (ce
.value
, false, NULL
);
9749 /* Parse objc-message-args.
9753 objc-keywordarg-list
9755 objc-keywordarg-list:
9757 objc-keywordarg-list objc-keywordarg
9760 objc-selector : objc-keywordexpr
9765 c_parser_objc_message_args (c_parser
*parser
)
9767 tree sel
= c_parser_objc_selector (parser
);
9768 tree list
= NULL_TREE
;
9769 if (sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9774 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
9775 return error_mark_node
;
9776 keywordexpr
= c_parser_objc_keywordexpr (parser
);
9777 list
= chainon (list
, build_tree_list (sel
, keywordexpr
));
9778 sel
= c_parser_objc_selector (parser
);
9779 if (!sel
&& c_parser_next_token_is_not (parser
, CPP_COLON
))
9785 /* Parse an objc-keywordexpr.
9792 c_parser_objc_keywordexpr (c_parser
*parser
)
9795 vec
<tree
, va_gc
> *expr_list
= c_parser_expr_list (parser
, true, true,
9796 NULL
, NULL
, NULL
, NULL
);
9797 if (vec_safe_length (expr_list
) == 1)
9799 /* Just return the expression, remove a level of
9801 ret
= (*expr_list
)[0];
9805 /* We have a comma expression, we will collapse later. */
9806 ret
= build_tree_list_vec (expr_list
);
9808 release_tree_vector (expr_list
);
9812 /* A check, needed in several places, that ObjC interface, implementation or
9813 method definitions are not prefixed by incorrect items. */
9815 c_parser_objc_diagnose_bad_element_prefix (c_parser
*parser
,
9816 struct c_declspecs
*specs
)
9818 if (!specs
->declspecs_seen_p
|| specs
->non_sc_seen_p
9819 || specs
->typespec_kind
!= ctsk_none
)
9821 c_parser_error (parser
,
9822 "no type or storage class may be specified here,");
9823 c_parser_skip_to_end_of_block_or_statement (parser
);
9829 /* Parse an Objective-C @property declaration. The syntax is:
9831 objc-property-declaration:
9832 '@property' objc-property-attributes[opt] struct-declaration ;
9834 objc-property-attributes:
9835 '(' objc-property-attribute-list ')'
9837 objc-property-attribute-list:
9838 objc-property-attribute
9839 objc-property-attribute-list, objc-property-attribute
9841 objc-property-attribute
9842 'getter' = identifier
9843 'setter' = identifier
9852 @property NSString *name;
9853 @property (readonly) id object;
9854 @property (retain, nonatomic, getter=getTheName) id name;
9855 @property int a, b, c;
9857 PS: This function is identical to cp_parser_objc_at_propery_declaration
9858 for C++. Keep them in sync. */
9860 c_parser_objc_at_property_declaration (c_parser
*parser
)
9862 /* The following variables hold the attributes of the properties as
9863 parsed. They are 'false' or 'NULL_TREE' if the attribute was not
9864 seen. When we see an attribute, we set them to 'true' (if they
9865 are boolean properties) or to the identifier (if they have an
9866 argument, ie, for getter and setter). Note that here we only
9867 parse the list of attributes, check the syntax and accumulate the
9868 attributes that we find. objc_add_property_declaration() will
9869 then process the information. */
9870 bool property_assign
= false;
9871 bool property_copy
= false;
9872 tree property_getter_ident
= NULL_TREE
;
9873 bool property_nonatomic
= false;
9874 bool property_readonly
= false;
9875 bool property_readwrite
= false;
9876 bool property_retain
= false;
9877 tree property_setter_ident
= NULL_TREE
;
9879 /* 'properties' is the list of properties that we read. Usually a
9880 single one, but maybe more (eg, in "@property int a, b, c;" there
9885 loc
= c_parser_peek_token (parser
)->location
;
9886 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_PROPERTY
));
9888 c_parser_consume_token (parser
); /* Eat '@property'. */
9890 /* Parse the optional attribute list... */
9891 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
9894 c_parser_consume_token (parser
);
9896 /* Property attribute keywords are valid now. */
9897 parser
->objc_property_attr_context
= true;
9901 bool syntax_error
= false;
9902 c_token
*token
= c_parser_peek_token (parser
);
9905 if (token
->type
!= CPP_KEYWORD
)
9907 if (token
->type
== CPP_CLOSE_PAREN
)
9908 c_parser_error (parser
, "expected identifier");
9911 c_parser_consume_token (parser
);
9912 c_parser_error (parser
, "unknown property attribute");
9916 keyword
= token
->keyword
;
9917 c_parser_consume_token (parser
);
9920 case RID_ASSIGN
: property_assign
= true; break;
9921 case RID_COPY
: property_copy
= true; break;
9922 case RID_NONATOMIC
: property_nonatomic
= true; break;
9923 case RID_READONLY
: property_readonly
= true; break;
9924 case RID_READWRITE
: property_readwrite
= true; break;
9925 case RID_RETAIN
: property_retain
= true; break;
9929 if (c_parser_next_token_is_not (parser
, CPP_EQ
))
9931 if (keyword
== RID_GETTER
)
9932 c_parser_error (parser
,
9933 "missing %<=%> (after %<getter%> attribute)");
9935 c_parser_error (parser
,
9936 "missing %<=%> (after %<setter%> attribute)");
9937 syntax_error
= true;
9940 c_parser_consume_token (parser
); /* eat the = */
9941 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
9943 c_parser_error (parser
, "expected identifier");
9944 syntax_error
= true;
9947 if (keyword
== RID_SETTER
)
9949 if (property_setter_ident
!= NULL_TREE
)
9950 c_parser_error (parser
, "the %<setter%> attribute may only be specified once");
9952 property_setter_ident
= c_parser_peek_token (parser
)->value
;
9953 c_parser_consume_token (parser
);
9954 if (c_parser_next_token_is_not (parser
, CPP_COLON
))
9955 c_parser_error (parser
, "setter name must terminate with %<:%>");
9957 c_parser_consume_token (parser
);
9961 if (property_getter_ident
!= NULL_TREE
)
9962 c_parser_error (parser
, "the %<getter%> attribute may only be specified once");
9964 property_getter_ident
= c_parser_peek_token (parser
)->value
;
9965 c_parser_consume_token (parser
);
9969 c_parser_error (parser
, "unknown property attribute");
9970 syntax_error
= true;
9977 if (c_parser_next_token_is (parser
, CPP_COMMA
))
9978 c_parser_consume_token (parser
);
9982 parser
->objc_property_attr_context
= false;
9983 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
9985 /* ... and the property declaration(s). */
9986 properties
= c_parser_struct_declaration (parser
);
9988 if (properties
== error_mark_node
)
9990 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
9991 parser
->error
= false;
9995 if (properties
== NULL_TREE
)
9996 c_parser_error (parser
, "expected identifier");
9999 /* Comma-separated properties are chained together in
10000 reverse order; add them one by one. */
10001 properties
= nreverse (properties
);
10003 for (; properties
; properties
= TREE_CHAIN (properties
))
10004 objc_add_property_declaration (loc
, copy_node (properties
),
10005 property_readonly
, property_readwrite
,
10006 property_assign
, property_retain
,
10007 property_copy
, property_nonatomic
,
10008 property_getter_ident
, property_setter_ident
);
10011 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10012 parser
->error
= false;
10015 /* Parse an Objective-C @synthesize declaration. The syntax is:
10017 objc-synthesize-declaration:
10018 @synthesize objc-synthesize-identifier-list ;
10020 objc-synthesize-identifier-list:
10021 objc-synthesize-identifier
10022 objc-synthesize-identifier-list, objc-synthesize-identifier
10024 objc-synthesize-identifier
10026 identifier = identifier
10029 @synthesize MyProperty;
10030 @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty;
10032 PS: This function is identical to cp_parser_objc_at_synthesize_declaration
10033 for C++. Keep them in sync.
10036 c_parser_objc_at_synthesize_declaration (c_parser
*parser
)
10038 tree list
= NULL_TREE
;
10040 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_SYNTHESIZE
));
10041 loc
= c_parser_peek_token (parser
)->location
;
10043 c_parser_consume_token (parser
);
10046 tree property
, ivar
;
10047 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10049 c_parser_error (parser
, "expected identifier");
10050 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10051 /* Once we find the semicolon, we can resume normal parsing.
10052 We have to reset parser->error manually because
10053 c_parser_skip_until_found() won't reset it for us if the
10054 next token is precisely a semicolon. */
10055 parser
->error
= false;
10058 property
= c_parser_peek_token (parser
)->value
;
10059 c_parser_consume_token (parser
);
10060 if (c_parser_next_token_is (parser
, CPP_EQ
))
10062 c_parser_consume_token (parser
);
10063 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10065 c_parser_error (parser
, "expected identifier");
10066 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10067 parser
->error
= false;
10070 ivar
= c_parser_peek_token (parser
)->value
;
10071 c_parser_consume_token (parser
);
10075 list
= chainon (list
, build_tree_list (ivar
, property
));
10076 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10077 c_parser_consume_token (parser
);
10081 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10082 objc_add_synthesize_declaration (loc
, list
);
10085 /* Parse an Objective-C @dynamic declaration. The syntax is:
10087 objc-dynamic-declaration:
10088 @dynamic identifier-list ;
10091 @dynamic MyProperty;
10092 @dynamic MyProperty, AnotherProperty;
10094 PS: This function is identical to cp_parser_objc_at_dynamic_declaration
10095 for C++. Keep them in sync.
10098 c_parser_objc_at_dynamic_declaration (c_parser
*parser
)
10100 tree list
= NULL_TREE
;
10102 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_AT_DYNAMIC
));
10103 loc
= c_parser_peek_token (parser
)->location
;
10105 c_parser_consume_token (parser
);
10109 if (c_parser_next_token_is_not (parser
, CPP_NAME
))
10111 c_parser_error (parser
, "expected identifier");
10112 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
10113 parser
->error
= false;
10116 property
= c_parser_peek_token (parser
)->value
;
10117 list
= chainon (list
, build_tree_list (NULL_TREE
, property
));
10118 c_parser_consume_token (parser
);
10119 if (c_parser_next_token_is (parser
, CPP_COMMA
))
10120 c_parser_consume_token (parser
);
10124 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
10125 objc_add_dynamic_declaration (loc
, list
);
10129 /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore
10130 should be considered, statements. ALLOW_STMT is true if we're within
10131 the context of a function and such pragmas are to be allowed. Returns
10132 true if we actually parsed such a pragma. */
10135 c_parser_pragma (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
10139 id
= c_parser_peek_token (parser
)->pragma_kind
;
10140 gcc_assert (id
!= PRAGMA_NONE
);
10144 case PRAGMA_OACC_DECLARE
:
10145 c_parser_oacc_declare (parser
);
10148 case PRAGMA_OACC_ENTER_DATA
:
10149 if (context
!= pragma_compound
)
10151 if (context
== pragma_stmt
)
10152 c_parser_error (parser
, "%<#pragma acc enter data%> may only be "
10153 "used in compound statements");
10156 c_parser_oacc_enter_exit_data (parser
, true);
10159 case PRAGMA_OACC_EXIT_DATA
:
10160 if (context
!= pragma_compound
)
10162 if (context
== pragma_stmt
)
10163 c_parser_error (parser
, "%<#pragma acc exit data%> may only be "
10164 "used in compound statements");
10167 c_parser_oacc_enter_exit_data (parser
, false);
10170 case PRAGMA_OACC_ROUTINE
:
10171 if (context
!= pragma_external
)
10173 error_at (c_parser_peek_token (parser
)->location
,
10174 "%<#pragma acc routine%> must be at file scope");
10175 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10178 c_parser_oacc_routine (parser
, context
);
10181 case PRAGMA_OACC_UPDATE
:
10182 if (context
!= pragma_compound
)
10184 if (context
== pragma_stmt
)
10185 c_parser_error (parser
, "%<#pragma acc update%> may only be "
10186 "used in compound statements");
10189 c_parser_oacc_update (parser
);
10192 case PRAGMA_OMP_BARRIER
:
10193 if (context
!= pragma_compound
)
10195 if (context
== pragma_stmt
)
10196 c_parser_error (parser
, "%<#pragma omp barrier%> may only be "
10197 "used in compound statements");
10200 c_parser_omp_barrier (parser
);
10203 case PRAGMA_OMP_FLUSH
:
10204 if (context
!= pragma_compound
)
10206 if (context
== pragma_stmt
)
10207 c_parser_error (parser
, "%<#pragma omp flush%> may only be "
10208 "used in compound statements");
10211 c_parser_omp_flush (parser
);
10214 case PRAGMA_OMP_TASKWAIT
:
10215 if (context
!= pragma_compound
)
10217 if (context
== pragma_stmt
)
10218 c_parser_error (parser
, "%<#pragma omp taskwait%> may only be "
10219 "used in compound statements");
10222 c_parser_omp_taskwait (parser
);
10225 case PRAGMA_OMP_TASKYIELD
:
10226 if (context
!= pragma_compound
)
10228 if (context
== pragma_stmt
)
10229 c_parser_error (parser
, "%<#pragma omp taskyield%> may only be "
10230 "used in compound statements");
10233 c_parser_omp_taskyield (parser
);
10236 case PRAGMA_OMP_CANCEL
:
10237 if (context
!= pragma_compound
)
10239 if (context
== pragma_stmt
)
10240 c_parser_error (parser
, "%<#pragma omp cancel%> may only be "
10241 "used in compound statements");
10244 c_parser_omp_cancel (parser
);
10247 case PRAGMA_OMP_CANCELLATION_POINT
:
10248 c_parser_omp_cancellation_point (parser
, context
);
10251 case PRAGMA_OMP_THREADPRIVATE
:
10252 c_parser_omp_threadprivate (parser
);
10255 case PRAGMA_OMP_TARGET
:
10256 return c_parser_omp_target (parser
, context
, if_p
);
10258 case PRAGMA_OMP_END_DECLARE_TARGET
:
10259 c_parser_omp_end_declare_target (parser
);
10262 case PRAGMA_OMP_SECTION
:
10263 error_at (c_parser_peek_token (parser
)->location
,
10264 "%<#pragma omp section%> may only be used in "
10265 "%<#pragma omp sections%> construct");
10266 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10269 case PRAGMA_OMP_DECLARE
:
10270 c_parser_omp_declare (parser
, context
);
10273 case PRAGMA_OMP_ORDERED
:
10274 return c_parser_omp_ordered (parser
, context
, if_p
);
10277 c_parser_consume_pragma (parser
);
10278 c_parser_skip_to_pragma_eol (parser
);
10279 if (!c_parser_next_token_is_keyword (parser
, RID_FOR
)
10280 && !c_parser_next_token_is_keyword (parser
, RID_WHILE
)
10281 && !c_parser_next_token_is_keyword (parser
, RID_DO
))
10283 c_parser_error (parser
, "for, while or do statement expected");
10286 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10287 c_parser_for_statement (parser
, true, if_p
);
10288 else if (c_parser_next_token_is_keyword (parser
, RID_WHILE
))
10289 c_parser_while_statement (parser
, true, if_p
);
10291 c_parser_do_statement (parser
, true);
10294 case PRAGMA_GCC_PCH_PREPROCESS
:
10295 c_parser_error (parser
, "%<#pragma GCC pch_preprocess%> must be first");
10296 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10299 case PRAGMA_CILK_SIMD
:
10300 if (!c_parser_cilk_verify_simd (parser
, context
))
10302 c_parser_consume_pragma (parser
);
10303 c_parser_cilk_simd (parser
, if_p
);
10305 case PRAGMA_CILK_GRAINSIZE
:
10306 if (!flag_cilkplus
)
10308 warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not"
10310 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10313 if (context
== pragma_external
)
10315 error_at (c_parser_peek_token (parser
)->location
,
10316 "%<#pragma grainsize%> must be inside a function");
10317 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10320 c_parser_cilk_grainsize (parser
, if_p
);
10323 case PRAGMA_OACC_WAIT
:
10324 if (context
!= pragma_compound
)
10326 if (context
== pragma_stmt
)
10327 c_parser_error (parser
, "%<#pragma acc enter data%> may only be "
10328 "used in compound statements");
10331 /* FALL THROUGH. */
10334 if (id
< PRAGMA_FIRST_EXTERNAL
)
10336 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
10339 c_parser_error (parser
, "expected declaration specifiers");
10340 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
10343 c_parser_omp_construct (parser
, if_p
);
10349 c_parser_consume_pragma (parser
);
10350 c_invoke_pragma_handler (id
);
10352 /* Skip to EOL, but suppress any error message. Those will have been
10353 generated by the handler routine through calling error, as opposed
10354 to calling c_parser_error. */
10355 parser
->error
= true;
10356 c_parser_skip_to_pragma_eol (parser
);
10361 /* The interface the pragma parsers have to the lexer. */
10364 pragma_lex (tree
*value
, location_t
*loc
)
10366 c_token
*tok
= c_parser_peek_token (the_parser
);
10367 enum cpp_ttype ret
= tok
->type
;
10369 *value
= tok
->value
;
10371 *loc
= tok
->location
;
10373 if (ret
== CPP_PRAGMA_EOL
|| ret
== CPP_EOF
)
10377 if (ret
== CPP_KEYWORD
)
10379 c_parser_consume_token (the_parser
);
10386 c_parser_pragma_pch_preprocess (c_parser
*parser
)
10390 c_parser_consume_pragma (parser
);
10391 if (c_parser_next_token_is (parser
, CPP_STRING
))
10393 name
= c_parser_peek_token (parser
)->value
;
10394 c_parser_consume_token (parser
);
10397 c_parser_error (parser
, "expected string literal");
10398 c_parser_skip_to_pragma_eol (parser
);
10401 c_common_pch_pragma (parse_in
, TREE_STRING_POINTER (name
));
10404 /* OpenACC and OpenMP parsing routines. */
10406 /* Returns name of the next clause.
10407 If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and
10408 the token is not consumed. Otherwise appropriate pragma_omp_clause is
10409 returned and the token is consumed. */
10411 static pragma_omp_clause
10412 c_parser_omp_clause_name (c_parser
*parser
)
10414 pragma_omp_clause result
= PRAGMA_OMP_CLAUSE_NONE
;
10416 if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
10417 result
= PRAGMA_OACC_CLAUSE_AUTO
;
10418 else if (c_parser_next_token_is_keyword (parser
, RID_IF
))
10419 result
= PRAGMA_OMP_CLAUSE_IF
;
10420 else if (c_parser_next_token_is_keyword (parser
, RID_DEFAULT
))
10421 result
= PRAGMA_OMP_CLAUSE_DEFAULT
;
10422 else if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
10423 result
= PRAGMA_OMP_CLAUSE_FOR
;
10424 else if (c_parser_next_token_is (parser
, CPP_NAME
))
10426 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
10431 if (!strcmp ("aligned", p
))
10432 result
= PRAGMA_OMP_CLAUSE_ALIGNED
;
10433 else if (!strcmp ("async", p
))
10434 result
= PRAGMA_OACC_CLAUSE_ASYNC
;
10437 if (!strcmp ("collapse", p
))
10438 result
= PRAGMA_OMP_CLAUSE_COLLAPSE
;
10439 else if (!strcmp ("copy", p
))
10440 result
= PRAGMA_OACC_CLAUSE_COPY
;
10441 else if (!strcmp ("copyin", p
))
10442 result
= PRAGMA_OMP_CLAUSE_COPYIN
;
10443 else if (!strcmp ("copyout", p
))
10444 result
= PRAGMA_OACC_CLAUSE_COPYOUT
;
10445 else if (!strcmp ("copyprivate", p
))
10446 result
= PRAGMA_OMP_CLAUSE_COPYPRIVATE
;
10447 else if (!strcmp ("create", p
))
10448 result
= PRAGMA_OACC_CLAUSE_CREATE
;
10451 if (!strcmp ("defaultmap", p
))
10452 result
= PRAGMA_OMP_CLAUSE_DEFAULTMAP
;
10453 else if (!strcmp ("delete", p
))
10454 result
= PRAGMA_OACC_CLAUSE_DELETE
;
10455 else if (!strcmp ("depend", p
))
10456 result
= PRAGMA_OMP_CLAUSE_DEPEND
;
10457 else if (!strcmp ("device", p
))
10458 result
= PRAGMA_OMP_CLAUSE_DEVICE
;
10459 else if (!strcmp ("deviceptr", p
))
10460 result
= PRAGMA_OACC_CLAUSE_DEVICEPTR
;
10461 else if (!strcmp ("device_resident", p
))
10462 result
= PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
;
10463 else if (!strcmp ("dist_schedule", p
))
10464 result
= PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
;
10467 if (!strcmp ("final", p
))
10468 result
= PRAGMA_OMP_CLAUSE_FINAL
;
10469 else if (!strcmp ("firstprivate", p
))
10470 result
= PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
;
10471 else if (!strcmp ("from", p
))
10472 result
= PRAGMA_OMP_CLAUSE_FROM
;
10475 if (!strcmp ("gang", p
))
10476 result
= PRAGMA_OACC_CLAUSE_GANG
;
10477 else if (!strcmp ("grainsize", p
))
10478 result
= PRAGMA_OMP_CLAUSE_GRAINSIZE
;
10481 if (!strcmp ("hint", p
))
10482 result
= PRAGMA_OMP_CLAUSE_HINT
;
10483 else if (!strcmp ("host", p
))
10484 result
= PRAGMA_OACC_CLAUSE_HOST
;
10487 if (!strcmp ("inbranch", p
))
10488 result
= PRAGMA_OMP_CLAUSE_INBRANCH
;
10489 else if (!strcmp ("independent", p
))
10490 result
= PRAGMA_OACC_CLAUSE_INDEPENDENT
;
10491 else if (!strcmp ("is_device_ptr", p
))
10492 result
= PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
;
10495 if (!strcmp ("lastprivate", p
))
10496 result
= PRAGMA_OMP_CLAUSE_LASTPRIVATE
;
10497 else if (!strcmp ("linear", p
))
10498 result
= PRAGMA_OMP_CLAUSE_LINEAR
;
10499 else if (!strcmp ("link", p
))
10500 result
= PRAGMA_OMP_CLAUSE_LINK
;
10503 if (!strcmp ("map", p
))
10504 result
= PRAGMA_OMP_CLAUSE_MAP
;
10505 else if (!strcmp ("mergeable", p
))
10506 result
= PRAGMA_OMP_CLAUSE_MERGEABLE
;
10507 else if (flag_cilkplus
&& !strcmp ("mask", p
))
10508 result
= PRAGMA_CILK_CLAUSE_MASK
;
10511 if (!strcmp ("nogroup", p
))
10512 result
= PRAGMA_OMP_CLAUSE_NOGROUP
;
10513 else if (!strcmp ("notinbranch", p
))
10514 result
= PRAGMA_OMP_CLAUSE_NOTINBRANCH
;
10515 else if (!strcmp ("nowait", p
))
10516 result
= PRAGMA_OMP_CLAUSE_NOWAIT
;
10517 else if (!strcmp ("num_gangs", p
))
10518 result
= PRAGMA_OACC_CLAUSE_NUM_GANGS
;
10519 else if (!strcmp ("num_tasks", p
))
10520 result
= PRAGMA_OMP_CLAUSE_NUM_TASKS
;
10521 else if (!strcmp ("num_teams", p
))
10522 result
= PRAGMA_OMP_CLAUSE_NUM_TEAMS
;
10523 else if (!strcmp ("num_threads", p
))
10524 result
= PRAGMA_OMP_CLAUSE_NUM_THREADS
;
10525 else if (!strcmp ("num_workers", p
))
10526 result
= PRAGMA_OACC_CLAUSE_NUM_WORKERS
;
10527 else if (flag_cilkplus
&& !strcmp ("nomask", p
))
10528 result
= PRAGMA_CILK_CLAUSE_NOMASK
;
10531 if (!strcmp ("ordered", p
))
10532 result
= PRAGMA_OMP_CLAUSE_ORDERED
;
10535 if (!strcmp ("parallel", p
))
10536 result
= PRAGMA_OMP_CLAUSE_PARALLEL
;
10537 else if (!strcmp ("present", p
))
10538 result
= PRAGMA_OACC_CLAUSE_PRESENT
;
10539 else if (!strcmp ("present_or_copy", p
)
10540 || !strcmp ("pcopy", p
))
10541 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
;
10542 else if (!strcmp ("present_or_copyin", p
)
10543 || !strcmp ("pcopyin", p
))
10544 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
;
10545 else if (!strcmp ("present_or_copyout", p
)
10546 || !strcmp ("pcopyout", p
))
10547 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
;
10548 else if (!strcmp ("present_or_create", p
)
10549 || !strcmp ("pcreate", p
))
10550 result
= PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
;
10551 else if (!strcmp ("priority", p
))
10552 result
= PRAGMA_OMP_CLAUSE_PRIORITY
;
10553 else if (!strcmp ("private", p
))
10554 result
= PRAGMA_OMP_CLAUSE_PRIVATE
;
10555 else if (!strcmp ("proc_bind", p
))
10556 result
= PRAGMA_OMP_CLAUSE_PROC_BIND
;
10559 if (!strcmp ("reduction", p
))
10560 result
= PRAGMA_OMP_CLAUSE_REDUCTION
;
10563 if (!strcmp ("safelen", p
))
10564 result
= PRAGMA_OMP_CLAUSE_SAFELEN
;
10565 else if (!strcmp ("schedule", p
))
10566 result
= PRAGMA_OMP_CLAUSE_SCHEDULE
;
10567 else if (!strcmp ("sections", p
))
10568 result
= PRAGMA_OMP_CLAUSE_SECTIONS
;
10569 else if (!strcmp ("seq", p
))
10570 result
= PRAGMA_OACC_CLAUSE_SEQ
;
10571 else if (!strcmp ("shared", p
))
10572 result
= PRAGMA_OMP_CLAUSE_SHARED
;
10573 else if (!strcmp ("simd", p
))
10574 result
= PRAGMA_OMP_CLAUSE_SIMD
;
10575 else if (!strcmp ("simdlen", p
))
10576 result
= PRAGMA_OMP_CLAUSE_SIMDLEN
;
10577 else if (!strcmp ("self", p
))
10578 result
= PRAGMA_OACC_CLAUSE_SELF
;
10581 if (!strcmp ("taskgroup", p
))
10582 result
= PRAGMA_OMP_CLAUSE_TASKGROUP
;
10583 else if (!strcmp ("thread_limit", p
))
10584 result
= PRAGMA_OMP_CLAUSE_THREAD_LIMIT
;
10585 else if (!strcmp ("threads", p
))
10586 result
= PRAGMA_OMP_CLAUSE_THREADS
;
10587 else if (!strcmp ("tile", p
))
10588 result
= PRAGMA_OACC_CLAUSE_TILE
;
10589 else if (!strcmp ("to", p
))
10590 result
= PRAGMA_OMP_CLAUSE_TO
;
10593 if (!strcmp ("uniform", p
))
10594 result
= PRAGMA_OMP_CLAUSE_UNIFORM
;
10595 else if (!strcmp ("untied", p
))
10596 result
= PRAGMA_OMP_CLAUSE_UNTIED
;
10597 else if (!strcmp ("use_device", p
))
10598 result
= PRAGMA_OACC_CLAUSE_USE_DEVICE
;
10599 else if (!strcmp ("use_device_ptr", p
))
10600 result
= PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
;
10603 if (!strcmp ("vector", p
))
10604 result
= PRAGMA_OACC_CLAUSE_VECTOR
;
10605 else if (!strcmp ("vector_length", p
))
10606 result
= PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
;
10607 else if (flag_cilkplus
&& !strcmp ("vectorlength", p
))
10608 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
10611 if (!strcmp ("wait", p
))
10612 result
= PRAGMA_OACC_CLAUSE_WAIT
;
10613 else if (!strcmp ("worker", p
))
10614 result
= PRAGMA_OACC_CLAUSE_WORKER
;
10619 if (result
!= PRAGMA_OMP_CLAUSE_NONE
)
10620 c_parser_consume_token (parser
);
10625 /* Validate that a clause of the given type does not already exist. */
10628 check_no_duplicate_clause (tree clauses
, enum omp_clause_code code
,
10633 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10634 if (OMP_CLAUSE_CODE (c
) == code
)
10636 location_t loc
= OMP_CLAUSE_LOCATION (c
);
10637 error_at (loc
, "too many %qs clauses", name
);
10643 Parse wait clause or wait directive parameters. */
10646 c_parser_oacc_wait_list (c_parser
*parser
, location_t clause_loc
, tree list
)
10648 vec
<tree
, va_gc
> *args
;
10651 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10654 args
= c_parser_expr_list (parser
, false, true, NULL
, NULL
, NULL
, NULL
);
10656 if (args
->length () == 0)
10658 c_parser_error (parser
, "expected integer expression before ')'");
10659 release_tree_vector (args
);
10663 args_tree
= build_tree_list_vec (args
);
10665 for (t
= args_tree
; t
; t
= TREE_CHAIN (t
))
10667 tree targ
= TREE_VALUE (t
);
10669 if (targ
!= error_mark_node
)
10671 if (!INTEGRAL_TYPE_P (TREE_TYPE (targ
)))
10673 c_parser_error (parser
, "expression must be integral");
10674 targ
= error_mark_node
;
10678 tree c
= build_omp_clause (clause_loc
, OMP_CLAUSE_WAIT
);
10680 OMP_CLAUSE_DECL (c
) = targ
;
10681 OMP_CLAUSE_CHAIN (c
) = list
;
10687 release_tree_vector (args
);
10688 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10692 /* OpenACC 2.0, OpenMP 2.5:
10695 variable-list , identifier
10697 If KIND is nonzero, create the appropriate node and install the
10698 decl in OMP_CLAUSE_DECL and add the node to the head of the list.
10699 If KIND is nonzero, CLAUSE_LOC is the location of the clause.
10701 If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE;
10702 return the list created. */
10705 c_parser_omp_variable_list (c_parser
*parser
,
10706 location_t clause_loc
,
10707 enum omp_clause_code kind
, tree list
)
10709 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
10710 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
10711 c_parser_error (parser
, "expected identifier");
10713 while (c_parser_next_token_is (parser
, CPP_NAME
)
10714 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
10716 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
10718 if (t
== NULL_TREE
)
10720 undeclared_variable (c_parser_peek_token (parser
)->location
,
10721 c_parser_peek_token (parser
)->value
);
10722 t
= error_mark_node
;
10725 c_parser_consume_token (parser
);
10727 if (t
== error_mark_node
)
10729 else if (kind
!= 0)
10733 case OMP_CLAUSE__CACHE_
:
10734 /* The OpenACC cache directive explicitly only allows "array
10735 elements or subarrays". */
10736 if (c_parser_peek_token (parser
)->type
!= CPP_OPEN_SQUARE
)
10738 c_parser_error (parser
, "expected %<[%>");
10739 t
= error_mark_node
;
10743 case OMP_CLAUSE_MAP
:
10744 case OMP_CLAUSE_FROM
:
10745 case OMP_CLAUSE_TO
:
10746 while (c_parser_next_token_is (parser
, CPP_DOT
))
10748 location_t op_loc
= c_parser_peek_token (parser
)->location
;
10749 c_parser_consume_token (parser
);
10750 if (!c_parser_next_token_is (parser
, CPP_NAME
))
10752 c_parser_error (parser
, "expected identifier");
10753 t
= error_mark_node
;
10757 c_token
*comp_tok
= c_parser_peek_token (parser
);
10758 tree ident
= comp_tok
->value
;
10759 location_t comp_loc
= comp_tok
->location
;
10760 c_parser_consume_token (parser
);
10761 t
= build_component_ref (op_loc
, t
, ident
, comp_loc
);
10764 case OMP_CLAUSE_DEPEND
:
10765 case OMP_CLAUSE_REDUCTION
:
10766 while (c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
10768 tree low_bound
= NULL_TREE
, length
= NULL_TREE
;
10770 c_parser_consume_token (parser
);
10771 if (!c_parser_next_token_is (parser
, CPP_COLON
))
10773 location_t expr_loc
10774 = c_parser_peek_token (parser
)->location
;
10775 c_expr expr
= c_parser_expression (parser
);
10776 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
10778 low_bound
= expr
.value
;
10780 if (c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10781 length
= integer_one_node
;
10784 /* Look for `:'. */
10785 if (!c_parser_require (parser
, CPP_COLON
,
10788 t
= error_mark_node
;
10791 if (!c_parser_next_token_is (parser
, CPP_CLOSE_SQUARE
))
10793 location_t expr_loc
10794 = c_parser_peek_token (parser
)->location
;
10795 c_expr expr
= c_parser_expression (parser
);
10796 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
,
10798 length
= expr
.value
;
10801 /* Look for the closing `]'. */
10802 if (!c_parser_require (parser
, CPP_CLOSE_SQUARE
,
10805 t
= error_mark_node
;
10809 t
= tree_cons (low_bound
, length
, t
);
10816 if (t
!= error_mark_node
)
10818 tree u
= build_omp_clause (clause_loc
, kind
);
10819 OMP_CLAUSE_DECL (u
) = t
;
10820 OMP_CLAUSE_CHAIN (u
) = list
;
10825 list
= tree_cons (t
, NULL_TREE
, list
);
10827 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
10830 c_parser_consume_token (parser
);
10836 /* Similarly, but expect leading and trailing parenthesis. This is a very
10837 common case for OpenACC and OpenMP clauses. */
10840 c_parser_omp_var_list_parens (c_parser
*parser
, enum omp_clause_code kind
,
10843 /* The clauses location. */
10844 location_t loc
= c_parser_peek_token (parser
)->location
;
10846 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10848 list
= c_parser_omp_variable_list (parser
, loc
, kind
, list
);
10849 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10855 copy ( variable-list )
10856 copyin ( variable-list )
10857 copyout ( variable-list )
10858 create ( variable-list )
10859 delete ( variable-list )
10860 present ( variable-list )
10861 present_or_copy ( variable-list )
10862 pcopy ( variable-list )
10863 present_or_copyin ( variable-list )
10864 pcopyin ( variable-list )
10865 present_or_copyout ( variable-list )
10866 pcopyout ( variable-list )
10867 present_or_create ( variable-list )
10868 pcreate ( variable-list ) */
10871 c_parser_oacc_data_clause (c_parser
*parser
, pragma_omp_clause c_kind
,
10874 enum gomp_map_kind kind
;
10877 case PRAGMA_OACC_CLAUSE_COPY
:
10878 kind
= GOMP_MAP_FORCE_TOFROM
;
10880 case PRAGMA_OACC_CLAUSE_COPYIN
:
10881 kind
= GOMP_MAP_FORCE_TO
;
10883 case PRAGMA_OACC_CLAUSE_COPYOUT
:
10884 kind
= GOMP_MAP_FORCE_FROM
;
10886 case PRAGMA_OACC_CLAUSE_CREATE
:
10887 kind
= GOMP_MAP_FORCE_ALLOC
;
10889 case PRAGMA_OACC_CLAUSE_DELETE
:
10890 kind
= GOMP_MAP_DELETE
;
10892 case PRAGMA_OACC_CLAUSE_DEVICE
:
10893 kind
= GOMP_MAP_FORCE_TO
;
10895 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
10896 kind
= GOMP_MAP_DEVICE_RESIDENT
;
10898 case PRAGMA_OACC_CLAUSE_HOST
:
10899 case PRAGMA_OACC_CLAUSE_SELF
:
10900 kind
= GOMP_MAP_FORCE_FROM
;
10902 case PRAGMA_OACC_CLAUSE_LINK
:
10903 kind
= GOMP_MAP_LINK
;
10905 case PRAGMA_OACC_CLAUSE_PRESENT
:
10906 kind
= GOMP_MAP_FORCE_PRESENT
;
10908 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
10909 kind
= GOMP_MAP_TOFROM
;
10911 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
10912 kind
= GOMP_MAP_TO
;
10914 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
10915 kind
= GOMP_MAP_FROM
;
10917 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
10918 kind
= GOMP_MAP_ALLOC
;
10921 gcc_unreachable ();
10924 nl
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_MAP
, list
);
10926 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
10927 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
10933 deviceptr ( variable-list ) */
10936 c_parser_oacc_data_clause_deviceptr (c_parser
*parser
, tree list
)
10938 location_t loc
= c_parser_peek_token (parser
)->location
;
10941 /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic
10942 c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR,
10943 variable-list must only allow for pointer variables. */
10944 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
10945 for (t
= vars
; t
&& t
; t
= TREE_CHAIN (t
))
10947 tree v
= TREE_PURPOSE (t
);
10949 /* FIXME diagnostics: Ideally we should keep individual
10950 locations for all the variables in the var list to make the
10951 following errors more precise. Perhaps
10952 c_parser_omp_var_list_parens() should construct a list of
10953 locations to go along with the var list. */
10955 if (!VAR_P (v
) && TREE_CODE (v
) != PARM_DECL
)
10956 error_at (loc
, "%qD is not a variable", v
);
10957 else if (TREE_TYPE (v
) == error_mark_node
)
10959 else if (!POINTER_TYPE_P (TREE_TYPE (v
)))
10960 error_at (loc
, "%qD is not a pointer variable", v
);
10962 tree u
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10963 OMP_CLAUSE_SET_MAP_KIND (u
, GOMP_MAP_FORCE_DEVICEPTR
);
10964 OMP_CLAUSE_DECL (u
) = v
;
10965 OMP_CLAUSE_CHAIN (u
) = list
;
10972 /* OpenACC 2.0, OpenMP 3.0:
10973 collapse ( constant-expression ) */
10976 c_parser_omp_clause_collapse (c_parser
*parser
, tree list
)
10978 tree c
, num
= error_mark_node
;
10982 check_no_duplicate_clause (list
, OMP_CLAUSE_COLLAPSE
, "collapse");
10984 loc
= c_parser_peek_token (parser
)->location
;
10985 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
10987 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
10988 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
10990 if (num
== error_mark_node
)
10992 mark_exp_read (num
);
10993 num
= c_fully_fold (num
, false, NULL
);
10994 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
10995 || !tree_fits_shwi_p (num
)
10996 || (n
= tree_to_shwi (num
)) <= 0
11000 "collapse argument needs positive constant integer expression");
11003 c
= build_omp_clause (loc
, OMP_CLAUSE_COLLAPSE
);
11004 OMP_CLAUSE_COLLAPSE_EXPR (c
) = num
;
11005 OMP_CLAUSE_CHAIN (c
) = list
;
11010 copyin ( variable-list ) */
11013 c_parser_omp_clause_copyin (c_parser
*parser
, tree list
)
11015 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYIN
, list
);
11019 copyprivate ( variable-list ) */
11022 c_parser_omp_clause_copyprivate (c_parser
*parser
, tree list
)
11024 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_COPYPRIVATE
, list
);
11028 default ( shared | none )
11034 c_parser_omp_clause_default (c_parser
*parser
, tree list
, bool is_oacc
)
11036 enum omp_clause_default_kind kind
= OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
11037 location_t loc
= c_parser_peek_token (parser
)->location
;
11040 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11042 if (c_parser_next_token_is (parser
, CPP_NAME
))
11044 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11049 if (strcmp ("none", p
) != 0)
11051 kind
= OMP_CLAUSE_DEFAULT_NONE
;
11055 if (strcmp ("shared", p
) != 0 || is_oacc
)
11057 kind
= OMP_CLAUSE_DEFAULT_SHARED
;
11064 c_parser_consume_token (parser
);
11070 c_parser_error (parser
, "expected %<none%>");
11072 c_parser_error (parser
, "expected %<none%> or %<shared%>");
11074 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11076 if (kind
== OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
11079 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULT
, "default");
11080 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULT
);
11081 OMP_CLAUSE_CHAIN (c
) = list
;
11082 OMP_CLAUSE_DEFAULT_KIND (c
) = kind
;
11088 firstprivate ( variable-list ) */
11091 c_parser_omp_clause_firstprivate (c_parser
*parser
, tree list
)
11093 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FIRSTPRIVATE
, list
);
11097 final ( expression ) */
11100 c_parser_omp_clause_final (c_parser
*parser
, tree list
)
11102 location_t loc
= c_parser_peek_token (parser
)->location
;
11103 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11105 tree t
= c_parser_paren_condition (parser
);
11108 check_no_duplicate_clause (list
, OMP_CLAUSE_FINAL
, "final");
11110 c
= build_omp_clause (loc
, OMP_CLAUSE_FINAL
);
11111 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
11112 OMP_CLAUSE_CHAIN (c
) = list
;
11116 c_parser_error (parser
, "expected %<(%>");
11121 /* OpenACC, OpenMP 2.5:
11125 if ( directive-name-modifier : expression )
11127 directive-name-modifier:
11128 parallel | task | taskloop | target data | target | target update
11129 | target enter data | target exit data */
11132 c_parser_omp_clause_if (c_parser
*parser
, tree list
, bool is_omp
)
11134 location_t location
= c_parser_peek_token (parser
)->location
;
11135 enum tree_code if_modifier
= ERROR_MARK
;
11137 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11140 if (is_omp
&& c_parser_next_token_is (parser
, CPP_NAME
))
11142 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11144 if (strcmp (p
, "parallel") == 0)
11145 if_modifier
= OMP_PARALLEL
;
11146 else if (strcmp (p
, "task") == 0)
11147 if_modifier
= OMP_TASK
;
11148 else if (strcmp (p
, "taskloop") == 0)
11149 if_modifier
= OMP_TASKLOOP
;
11150 else if (strcmp (p
, "target") == 0)
11152 if_modifier
= OMP_TARGET
;
11153 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11155 p
= IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser
)->value
);
11156 if (strcmp ("data", p
) == 0)
11157 if_modifier
= OMP_TARGET_DATA
;
11158 else if (strcmp ("update", p
) == 0)
11159 if_modifier
= OMP_TARGET_UPDATE
;
11160 else if (strcmp ("enter", p
) == 0)
11161 if_modifier
= OMP_TARGET_ENTER_DATA
;
11162 else if (strcmp ("exit", p
) == 0)
11163 if_modifier
= OMP_TARGET_EXIT_DATA
;
11164 if (if_modifier
!= OMP_TARGET
)
11167 c_parser_consume_token (parser
);
11171 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
11172 error_at (loc
, "expected %<data%>, %<update%>, %<enter%> "
11174 if_modifier
= ERROR_MARK
;
11176 if (if_modifier
== OMP_TARGET_ENTER_DATA
11177 || if_modifier
== OMP_TARGET_EXIT_DATA
)
11179 if (c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
11181 p
= IDENTIFIER_POINTER
11182 (c_parser_peek_2nd_token (parser
)->value
);
11183 if (strcmp ("data", p
) == 0)
11187 c_parser_consume_token (parser
);
11191 = c_parser_peek_2nd_token (parser
)->location
;
11192 error_at (loc
, "expected %<data%>");
11193 if_modifier
= ERROR_MARK
;
11198 if (if_modifier
!= ERROR_MARK
)
11200 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11202 c_parser_consume_token (parser
);
11203 c_parser_consume_token (parser
);
11209 location_t loc
= c_parser_peek_2nd_token (parser
)->location
;
11210 error_at (loc
, "expected %<:%>");
11212 if_modifier
= ERROR_MARK
;
11217 tree t
= c_parser_condition (parser
), c
;
11218 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11220 for (c
= list
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11221 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IF
)
11223 if (if_modifier
!= ERROR_MARK
11224 && OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
11226 const char *p
= NULL
;
11227 switch (if_modifier
)
11229 case OMP_PARALLEL
: p
= "parallel"; break;
11230 case OMP_TASK
: p
= "task"; break;
11231 case OMP_TASKLOOP
: p
= "taskloop"; break;
11232 case OMP_TARGET_DATA
: p
= "target data"; break;
11233 case OMP_TARGET
: p
= "target"; break;
11234 case OMP_TARGET_UPDATE
: p
= "target update"; break;
11235 case OMP_TARGET_ENTER_DATA
: p
= "enter data"; break;
11236 case OMP_TARGET_EXIT_DATA
: p
= "exit data"; break;
11237 default: gcc_unreachable ();
11239 error_at (location
, "too many %<if%> clauses with %qs modifier",
11243 else if (OMP_CLAUSE_IF_MODIFIER (c
) == if_modifier
)
11246 error_at (location
, "too many %<if%> clauses");
11248 error_at (location
, "too many %<if%> clauses without modifier");
11251 else if (if_modifier
== ERROR_MARK
11252 || OMP_CLAUSE_IF_MODIFIER (c
) == ERROR_MARK
)
11254 error_at (location
, "if any %<if%> clause has modifier, then all "
11255 "%<if%> clauses have to use modifier");
11260 c
= build_omp_clause (location
, OMP_CLAUSE_IF
);
11261 OMP_CLAUSE_IF_MODIFIER (c
) = if_modifier
;
11262 OMP_CLAUSE_IF_EXPR (c
) = t
;
11263 OMP_CLAUSE_CHAIN (c
) = list
;
11268 lastprivate ( variable-list ) */
11271 c_parser_omp_clause_lastprivate (c_parser
*parser
, tree list
)
11273 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LASTPRIVATE
, list
);
11280 c_parser_omp_clause_mergeable (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11284 /* FIXME: Should we allow duplicates? */
11285 check_no_duplicate_clause (list
, OMP_CLAUSE_MERGEABLE
, "mergeable");
11287 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
11288 OMP_CLAUSE_MERGEABLE
);
11289 OMP_CLAUSE_CHAIN (c
) = list
;
11298 c_parser_omp_clause_nowait (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
11301 location_t loc
= c_parser_peek_token (parser
)->location
;
11303 check_no_duplicate_clause (list
, OMP_CLAUSE_NOWAIT
, "nowait");
11305 c
= build_omp_clause (loc
, OMP_CLAUSE_NOWAIT
);
11306 OMP_CLAUSE_CHAIN (c
) = list
;
11311 num_gangs ( expression ) */
11314 c_parser_omp_clause_num_gangs (c_parser
*parser
, tree list
)
11316 location_t num_gangs_loc
= c_parser_peek_token (parser
)->location
;
11317 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11319 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11320 c_expr expr
= c_parser_expression (parser
);
11321 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11322 tree c
, t
= expr
.value
;
11323 t
= c_fully_fold (t
, false, NULL
);
11325 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11327 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11329 c_parser_error (parser
, "expected integer expression");
11333 /* Attempt to statically determine when the number isn't positive. */
11334 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11335 build_int_cst (TREE_TYPE (t
), 0));
11336 protected_set_expr_location (c
, expr_loc
);
11337 if (c
== boolean_true_node
)
11339 warning_at (expr_loc
, 0,
11340 "%<num_gangs%> value must be positive");
11341 t
= integer_one_node
;
11344 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_GANGS
, "num_gangs");
11346 c
= build_omp_clause (num_gangs_loc
, OMP_CLAUSE_NUM_GANGS
);
11347 OMP_CLAUSE_NUM_GANGS_EXPR (c
) = t
;
11348 OMP_CLAUSE_CHAIN (c
) = list
;
11356 num_threads ( expression ) */
11359 c_parser_omp_clause_num_threads (c_parser
*parser
, tree list
)
11361 location_t num_threads_loc
= c_parser_peek_token (parser
)->location
;
11362 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11364 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11365 c_expr expr
= c_parser_expression (parser
);
11366 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11367 tree c
, t
= expr
.value
;
11368 t
= c_fully_fold (t
, false, NULL
);
11370 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11372 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11374 c_parser_error (parser
, "expected integer expression");
11378 /* Attempt to statically determine when the number isn't positive. */
11379 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11380 build_int_cst (TREE_TYPE (t
), 0));
11381 protected_set_expr_location (c
, expr_loc
);
11382 if (c
== boolean_true_node
)
11384 warning_at (expr_loc
, 0,
11385 "%<num_threads%> value must be positive");
11386 t
= integer_one_node
;
11389 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_THREADS
, "num_threads");
11391 c
= build_omp_clause (num_threads_loc
, OMP_CLAUSE_NUM_THREADS
);
11392 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
11393 OMP_CLAUSE_CHAIN (c
) = list
;
11401 num_tasks ( expression ) */
11404 c_parser_omp_clause_num_tasks (c_parser
*parser
, tree list
)
11406 location_t num_tasks_loc
= c_parser_peek_token (parser
)->location
;
11407 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11409 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11410 c_expr expr
= c_parser_expression (parser
);
11411 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11412 tree c
, t
= expr
.value
;
11413 t
= c_fully_fold (t
, false, NULL
);
11415 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11417 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11419 c_parser_error (parser
, "expected integer expression");
11423 /* Attempt to statically determine when the number isn't positive. */
11424 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11425 build_int_cst (TREE_TYPE (t
), 0));
11426 if (CAN_HAVE_LOCATION_P (c
))
11427 SET_EXPR_LOCATION (c
, expr_loc
);
11428 if (c
== boolean_true_node
)
11430 warning_at (expr_loc
, 0, "%<num_tasks%> value must be positive");
11431 t
= integer_one_node
;
11434 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TASKS
, "num_tasks");
11436 c
= build_omp_clause (num_tasks_loc
, OMP_CLAUSE_NUM_TASKS
);
11437 OMP_CLAUSE_NUM_TASKS_EXPR (c
) = t
;
11438 OMP_CLAUSE_CHAIN (c
) = list
;
11446 grainsize ( expression ) */
11449 c_parser_omp_clause_grainsize (c_parser
*parser
, tree list
)
11451 location_t grainsize_loc
= c_parser_peek_token (parser
)->location
;
11452 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11454 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11455 c_expr expr
= c_parser_expression (parser
);
11456 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11457 tree c
, t
= expr
.value
;
11458 t
= c_fully_fold (t
, false, NULL
);
11460 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11462 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11464 c_parser_error (parser
, "expected integer expression");
11468 /* Attempt to statically determine when the number isn't positive. */
11469 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11470 build_int_cst (TREE_TYPE (t
), 0));
11471 if (CAN_HAVE_LOCATION_P (c
))
11472 SET_EXPR_LOCATION (c
, expr_loc
);
11473 if (c
== boolean_true_node
)
11475 warning_at (expr_loc
, 0, "%<grainsize%> value must be positive");
11476 t
= integer_one_node
;
11479 check_no_duplicate_clause (list
, OMP_CLAUSE_GRAINSIZE
, "grainsize");
11481 c
= build_omp_clause (grainsize_loc
, OMP_CLAUSE_GRAINSIZE
);
11482 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
11483 OMP_CLAUSE_CHAIN (c
) = list
;
11491 priority ( expression ) */
11494 c_parser_omp_clause_priority (c_parser
*parser
, tree list
)
11496 location_t priority_loc
= c_parser_peek_token (parser
)->location
;
11497 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11499 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11500 c_expr expr
= c_parser_expression (parser
);
11501 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11502 tree c
, t
= expr
.value
;
11503 t
= c_fully_fold (t
, false, NULL
);
11505 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11507 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11509 c_parser_error (parser
, "expected integer expression");
11513 /* Attempt to statically determine when the number isn't
11515 c
= fold_build2_loc (expr_loc
, LT_EXPR
, boolean_type_node
, t
,
11516 build_int_cst (TREE_TYPE (t
), 0));
11517 if (CAN_HAVE_LOCATION_P (c
))
11518 SET_EXPR_LOCATION (c
, expr_loc
);
11519 if (c
== boolean_true_node
)
11521 warning_at (expr_loc
, 0, "%<priority%> value must be non-negative");
11522 t
= integer_one_node
;
11525 check_no_duplicate_clause (list
, OMP_CLAUSE_PRIORITY
, "priority");
11527 c
= build_omp_clause (priority_loc
, OMP_CLAUSE_PRIORITY
);
11528 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
11529 OMP_CLAUSE_CHAIN (c
) = list
;
11537 hint ( expression ) */
11540 c_parser_omp_clause_hint (c_parser
*parser
, tree list
)
11542 location_t hint_loc
= c_parser_peek_token (parser
)->location
;
11543 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11545 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11546 c_expr expr
= c_parser_expression (parser
);
11547 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11548 tree c
, t
= expr
.value
;
11549 t
= c_fully_fold (t
, false, NULL
);
11551 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11553 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11555 c_parser_error (parser
, "expected integer expression");
11559 check_no_duplicate_clause (list
, OMP_CLAUSE_HINT
, "hint");
11561 c
= build_omp_clause (hint_loc
, OMP_CLAUSE_HINT
);
11562 OMP_CLAUSE_HINT_EXPR (c
) = t
;
11563 OMP_CLAUSE_CHAIN (c
) = list
;
11571 defaultmap ( tofrom : scalar ) */
11574 c_parser_omp_clause_defaultmap (c_parser
*parser
, tree list
)
11576 location_t loc
= c_parser_peek_token (parser
)->location
;
11580 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11582 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11584 c_parser_error (parser
, "expected %<tofrom%>");
11587 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11588 if (strcmp (p
, "tofrom") != 0)
11590 c_parser_error (parser
, "expected %<tofrom%>");
11593 c_parser_consume_token (parser
);
11594 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11596 if (!c_parser_next_token_is (parser
, CPP_NAME
))
11598 c_parser_error (parser
, "expected %<scalar%>");
11601 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
11602 if (strcmp (p
, "scalar") != 0)
11604 c_parser_error (parser
, "expected %<scalar%>");
11607 c_parser_consume_token (parser
);
11608 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11609 check_no_duplicate_clause (list
, OMP_CLAUSE_DEFAULTMAP
, "defaultmap");
11610 c
= build_omp_clause (loc
, OMP_CLAUSE_DEFAULTMAP
);
11611 OMP_CLAUSE_CHAIN (c
) = list
;
11615 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11620 use_device ( variable-list )
11623 use_device_ptr ( variable-list ) */
11626 c_parser_omp_clause_use_device_ptr (c_parser
*parser
, tree list
)
11628 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_USE_DEVICE_PTR
,
11633 is_device_ptr ( variable-list ) */
11636 c_parser_omp_clause_is_device_ptr (c_parser
*parser
, tree list
)
11638 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_IS_DEVICE_PTR
, list
);
11642 num_workers ( expression ) */
11645 c_parser_omp_clause_num_workers (c_parser
*parser
, tree list
)
11647 location_t num_workers_loc
= c_parser_peek_token (parser
)->location
;
11648 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11650 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11651 c_expr expr
= c_parser_expression (parser
);
11652 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
11653 tree c
, t
= expr
.value
;
11654 t
= c_fully_fold (t
, false, NULL
);
11656 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11658 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11660 c_parser_error (parser
, "expected integer expression");
11664 /* Attempt to statically determine when the number isn't positive. */
11665 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
11666 build_int_cst (TREE_TYPE (t
), 0));
11667 protected_set_expr_location (c
, expr_loc
);
11668 if (c
== boolean_true_node
)
11670 warning_at (expr_loc
, 0,
11671 "%<num_workers%> value must be positive");
11672 t
= integer_one_node
;
11675 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_WORKERS
, "num_workers");
11677 c
= build_omp_clause (num_workers_loc
, OMP_CLAUSE_NUM_WORKERS
);
11678 OMP_CLAUSE_NUM_WORKERS_EXPR (c
) = t
;
11679 OMP_CLAUSE_CHAIN (c
) = list
;
11688 gang [( gang-arg-list )]
11689 worker [( [num:] int-expr )]
11690 vector [( [length:] int-expr )]
11692 where gang-arg is one of:
11697 and size-expr may be:
11704 c_parser_oacc_shape_clause (c_parser
*parser
, omp_clause_code kind
,
11705 const char *str
, tree list
)
11707 const char *id
= "num";
11708 tree ops
[2] = { NULL_TREE
, NULL_TREE
}, c
;
11709 location_t loc
= c_parser_peek_token (parser
)->location
;
11711 if (kind
== OMP_CLAUSE_VECTOR
)
11714 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11716 c_parser_consume_token (parser
);
11720 c_token
*next
= c_parser_peek_token (parser
);
11723 /* Gang static argument. */
11724 if (kind
== OMP_CLAUSE_GANG
11725 && c_parser_next_token_is_keyword (parser
, RID_STATIC
))
11727 c_parser_consume_token (parser
);
11729 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
11730 goto cleanup_error
;
11733 if (ops
[idx
] != NULL_TREE
)
11735 c_parser_error (parser
, "too many %<static%> arguments");
11736 goto cleanup_error
;
11739 /* Check for the '*' argument. */
11740 if (c_parser_next_token_is (parser
, CPP_MULT
)
11741 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
11742 || c_parser_peek_2nd_token (parser
)->type
11743 == CPP_CLOSE_PAREN
))
11745 c_parser_consume_token (parser
);
11746 ops
[idx
] = integer_minus_one_node
;
11748 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11750 c_parser_consume_token (parser
);
11757 /* Worker num: argument and vector length: arguments. */
11758 else if (c_parser_next_token_is (parser
, CPP_NAME
)
11759 && strcmp (id
, IDENTIFIER_POINTER (next
->value
)) == 0
11760 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
11762 c_parser_consume_token (parser
); /* id */
11763 c_parser_consume_token (parser
); /* ':' */
11766 /* Now collect the actual argument. */
11767 if (ops
[idx
] != NULL_TREE
)
11769 c_parser_error (parser
, "unexpected argument");
11770 goto cleanup_error
;
11773 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
11774 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
11775 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
11776 tree expr
= cexpr
.value
;
11777 if (expr
== error_mark_node
)
11778 goto cleanup_error
;
11780 expr
= c_fully_fold (expr
, false, NULL
);
11782 /* Attempt to statically determine when the number isn't a
11783 positive integer. */
11785 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
11787 c_parser_error (parser
, "expected integer expression");
11791 tree c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
11792 build_int_cst (TREE_TYPE (expr
), 0));
11793 if (c
== boolean_true_node
)
11795 warning_at (loc
, 0,
11796 "%<%s%> value must be positive", str
);
11797 expr
= integer_one_node
;
11802 if (kind
== OMP_CLAUSE_GANG
11803 && c_parser_next_token_is (parser
, CPP_COMMA
))
11805 c_parser_consume_token (parser
);
11812 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
11813 goto cleanup_error
;
11816 check_no_duplicate_clause (list
, kind
, str
);
11818 c
= build_omp_clause (loc
, kind
);
11821 OMP_CLAUSE_OPERAND (c
, 1) = ops
[1];
11823 OMP_CLAUSE_OPERAND (c
, 0) = ops
[0];
11824 OMP_CLAUSE_CHAIN (c
) = list
;
11829 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
11840 c_parser_oacc_simple_clause (c_parser
*parser
, enum omp_clause_code code
,
11843 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
11845 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
11846 OMP_CLAUSE_CHAIN (c
) = list
;
11852 async [( int-expr )] */
11855 c_parser_oacc_clause_async (c_parser
*parser
, tree list
)
11858 location_t loc
= c_parser_peek_token (parser
)->location
;
11860 t
= build_int_cst (integer_type_node
, GOMP_ASYNC_NOVAL
);
11862 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
11864 c_parser_consume_token (parser
);
11866 t
= c_parser_expression (parser
).value
;
11867 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
11868 c_parser_error (parser
, "expected integer expression");
11869 else if (t
== error_mark_node
11870 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
11874 t
= c_fully_fold (t
, false, NULL
);
11876 check_no_duplicate_clause (list
, OMP_CLAUSE_ASYNC
, "async");
11878 c
= build_omp_clause (loc
, OMP_CLAUSE_ASYNC
);
11879 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
11880 OMP_CLAUSE_CHAIN (c
) = list
;
11887 tile ( size-expr-list ) */
11890 c_parser_oacc_clause_tile (c_parser
*parser
, tree list
)
11892 tree c
, expr
= error_mark_node
;
11893 location_t loc
, expr_loc
;
11894 tree tile
= NULL_TREE
;
11896 check_no_duplicate_clause (list
, OMP_CLAUSE_TILE
, "tile");
11898 loc
= c_parser_peek_token (parser
)->location
;
11899 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
11904 if (c_parser_next_token_is (parser
, CPP_MULT
)
11905 && (c_parser_peek_2nd_token (parser
)->type
== CPP_COMMA
11906 || c_parser_peek_2nd_token (parser
)->type
== CPP_CLOSE_PAREN
))
11908 c_parser_consume_token (parser
);
11909 expr
= integer_minus_one_node
;
11913 expr_loc
= c_parser_peek_token (parser
)->location
;
11914 c_expr cexpr
= c_parser_expr_no_commas (parser
, NULL
);
11915 cexpr
= convert_lvalue_to_rvalue (expr_loc
, cexpr
, false, true);
11916 expr
= cexpr
.value
;
11918 if (expr
== error_mark_node
)
11920 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
11925 if (!INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
11927 c_parser_error (parser
, "%<tile%> value must be integral");
11931 expr
= c_fully_fold (expr
, false, NULL
);
11933 /* Attempt to statically determine when expr isn't positive. */
11934 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, expr
,
11935 build_int_cst (TREE_TYPE (expr
), 0));
11936 protected_set_expr_location (c
, expr_loc
);
11937 if (c
== boolean_true_node
)
11939 warning_at (expr_loc
, 0,"%<tile%> value must be positive");
11940 expr
= integer_one_node
;
11944 tile
= tree_cons (NULL_TREE
, expr
, tile
);
11945 if (c_parser_next_token_is (parser
, CPP_COMMA
))
11946 c_parser_consume_token (parser
);
11948 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
));
11950 /* Consume the trailing ')'. */
11951 c_parser_consume_token (parser
);
11953 c
= build_omp_clause (loc
, OMP_CLAUSE_TILE
);
11954 tile
= nreverse (tile
);
11955 OMP_CLAUSE_TILE_LIST (c
) = tile
;
11956 OMP_CLAUSE_CHAIN (c
) = list
;
11961 wait ( int-expr-list ) */
11964 c_parser_oacc_clause_wait (c_parser
*parser
, tree list
)
11966 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
11968 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
11969 list
= c_parser_oacc_wait_list (parser
, clause_loc
, list
);
11978 ordered ( constant-expression ) */
11981 c_parser_omp_clause_ordered (c_parser
*parser
, tree list
)
11983 check_no_duplicate_clause (list
, OMP_CLAUSE_ORDERED
, "ordered");
11985 tree c
, num
= NULL_TREE
;
11987 location_t loc
= c_parser_peek_token (parser
)->location
;
11988 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
11990 c_parser_consume_token (parser
);
11991 num
= c_parser_expr_no_commas (parser
, NULL
).value
;
11992 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
11994 if (num
== error_mark_node
)
11998 mark_exp_read (num
);
11999 num
= c_fully_fold (num
, false, NULL
);
12000 if (!INTEGRAL_TYPE_P (TREE_TYPE (num
))
12001 || !tree_fits_shwi_p (num
)
12002 || (n
= tree_to_shwi (num
)) <= 0
12005 error_at (loc
, "ordered argument needs positive "
12006 "constant integer expression");
12010 c
= build_omp_clause (loc
, OMP_CLAUSE_ORDERED
);
12011 OMP_CLAUSE_ORDERED_EXPR (c
) = num
;
12012 OMP_CLAUSE_CHAIN (c
) = list
;
12017 private ( variable-list ) */
12020 c_parser_omp_clause_private (c_parser
*parser
, tree list
)
12022 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_PRIVATE
, list
);
12026 reduction ( reduction-operator : variable-list )
12028 reduction-operator:
12029 One of: + * - & ^ | && ||
12033 reduction-operator:
12034 One of: + * - & ^ | && || max min
12038 reduction-operator:
12039 One of: + * - & ^ | && ||
12043 c_parser_omp_clause_reduction (c_parser
*parser
, tree list
)
12045 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12046 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12048 enum tree_code code
= ERROR_MARK
;
12049 tree reduc_id
= NULL_TREE
;
12051 switch (c_parser_peek_token (parser
)->type
)
12063 code
= BIT_AND_EXPR
;
12066 code
= BIT_XOR_EXPR
;
12069 code
= BIT_IOR_EXPR
;
12072 code
= TRUTH_ANDIF_EXPR
;
12075 code
= TRUTH_ORIF_EXPR
;
12080 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12081 if (strcmp (p
, "min") == 0)
12086 if (strcmp (p
, "max") == 0)
12091 reduc_id
= c_parser_peek_token (parser
)->value
;
12095 c_parser_error (parser
,
12096 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
12097 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or %<max%>");
12098 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12101 c_parser_consume_token (parser
);
12102 reduc_id
= c_omp_reduction_id (code
, reduc_id
);
12103 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12107 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12108 OMP_CLAUSE_REDUCTION
, list
);
12109 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12111 tree d
= OMP_CLAUSE_DECL (c
), type
;
12112 if (TREE_CODE (d
) != TREE_LIST
)
12113 type
= TREE_TYPE (d
);
12118 for (t
= d
; TREE_CODE (t
) == TREE_LIST
; t
= TREE_CHAIN (t
))
12120 type
= TREE_TYPE (t
);
12123 if (TREE_CODE (type
) != POINTER_TYPE
12124 && TREE_CODE (type
) != ARRAY_TYPE
)
12126 type
= TREE_TYPE (type
);
12130 while (TREE_CODE (type
) == ARRAY_TYPE
)
12131 type
= TREE_TYPE (type
);
12132 OMP_CLAUSE_REDUCTION_CODE (c
) = code
;
12133 if (code
== ERROR_MARK
12134 || !(INTEGRAL_TYPE_P (type
)
12135 || TREE_CODE (type
) == REAL_TYPE
12136 || TREE_CODE (type
) == COMPLEX_TYPE
))
12137 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
)
12138 = c_omp_reduction_lookup (reduc_id
,
12139 TYPE_MAIN_VARIANT (type
));
12144 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12150 schedule ( schedule-kind )
12151 schedule ( schedule-kind , expression )
12154 static | dynamic | guided | runtime | auto
12157 schedule ( schedule-modifier : schedule-kind )
12158 schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression )
12166 c_parser_omp_clause_schedule (c_parser
*parser
, tree list
)
12169 location_t loc
= c_parser_peek_token (parser
)->location
;
12170 int modifiers
= 0, nmodifiers
= 0;
12172 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12175 c
= build_omp_clause (loc
, OMP_CLAUSE_SCHEDULE
);
12177 while (c_parser_next_token_is (parser
, CPP_NAME
))
12179 tree kind
= c_parser_peek_token (parser
)->value
;
12180 const char *p
= IDENTIFIER_POINTER (kind
);
12181 if (strcmp ("simd", p
) == 0)
12182 OMP_CLAUSE_SCHEDULE_SIMD (c
) = 1;
12183 else if (strcmp ("monotonic", p
) == 0)
12184 modifiers
|= OMP_CLAUSE_SCHEDULE_MONOTONIC
;
12185 else if (strcmp ("nonmonotonic", p
) == 0)
12186 modifiers
|= OMP_CLAUSE_SCHEDULE_NONMONOTONIC
;
12189 c_parser_consume_token (parser
);
12190 if (nmodifiers
++ == 0
12191 && c_parser_next_token_is (parser
, CPP_COMMA
))
12192 c_parser_consume_token (parser
);
12195 c_parser_require (parser
, CPP_COLON
, "expected %<:%>");
12200 if ((modifiers
& (OMP_CLAUSE_SCHEDULE_MONOTONIC
12201 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12202 == (OMP_CLAUSE_SCHEDULE_MONOTONIC
12203 | OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
12205 error_at (loc
, "both %<monotonic%> and %<nonmonotonic%> modifiers "
12210 if (c_parser_next_token_is (parser
, CPP_NAME
))
12212 tree kind
= c_parser_peek_token (parser
)->value
;
12213 const char *p
= IDENTIFIER_POINTER (kind
);
12218 if (strcmp ("dynamic", p
) != 0)
12220 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_DYNAMIC
;
12224 if (strcmp ("guided", p
) != 0)
12226 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_GUIDED
;
12230 if (strcmp ("runtime", p
) != 0)
12232 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_RUNTIME
;
12239 else if (c_parser_next_token_is_keyword (parser
, RID_STATIC
))
12240 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_STATIC
;
12241 else if (c_parser_next_token_is_keyword (parser
, RID_AUTO
))
12242 OMP_CLAUSE_SCHEDULE_KIND (c
) = OMP_CLAUSE_SCHEDULE_AUTO
;
12246 c_parser_consume_token (parser
);
12247 if (c_parser_next_token_is (parser
, CPP_COMMA
))
12250 c_parser_consume_token (parser
);
12252 here
= c_parser_peek_token (parser
)->location
;
12253 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12254 expr
= convert_lvalue_to_rvalue (here
, expr
, false, true);
12256 t
= c_fully_fold (t
, false, NULL
);
12258 if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_RUNTIME
)
12259 error_at (here
, "schedule %<runtime%> does not take "
12260 "a %<chunk_size%> parameter");
12261 else if (OMP_CLAUSE_SCHEDULE_KIND (c
) == OMP_CLAUSE_SCHEDULE_AUTO
)
12263 "schedule %<auto%> does not take "
12264 "a %<chunk_size%> parameter");
12265 else if (TREE_CODE (TREE_TYPE (t
)) == INTEGER_TYPE
)
12267 /* Attempt to statically determine when the number isn't
12269 tree s
= fold_build2_loc (loc
, LE_EXPR
, boolean_type_node
, t
,
12270 build_int_cst (TREE_TYPE (t
), 0));
12271 protected_set_expr_location (s
, loc
);
12272 if (s
== boolean_true_node
)
12274 warning_at (loc
, 0,
12275 "chunk size value must be positive");
12276 t
= integer_one_node
;
12278 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
12281 c_parser_error (parser
, "expected integer expression");
12283 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12286 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12287 "expected %<,%> or %<)%>");
12289 OMP_CLAUSE_SCHEDULE_KIND (c
)
12290 = (enum omp_clause_schedule_kind
)
12291 (OMP_CLAUSE_SCHEDULE_KIND (c
) | modifiers
);
12293 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
12294 OMP_CLAUSE_CHAIN (c
) = list
;
12298 c_parser_error (parser
, "invalid schedule kind");
12299 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, 0);
12304 shared ( variable-list ) */
12307 c_parser_omp_clause_shared (c_parser
*parser
, tree list
)
12309 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_SHARED
, list
);
12316 c_parser_omp_clause_untied (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12320 /* FIXME: Should we allow duplicates? */
12321 check_no_duplicate_clause (list
, OMP_CLAUSE_UNTIED
, "untied");
12323 c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12324 OMP_CLAUSE_UNTIED
);
12325 OMP_CLAUSE_CHAIN (c
) = list
;
12331 vector_length ( expression ) */
12334 c_parser_omp_clause_vector_length (c_parser
*parser
, tree list
)
12336 location_t vector_length_loc
= c_parser_peek_token (parser
)->location
;
12337 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12339 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12340 c_expr expr
= c_parser_expression (parser
);
12341 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12342 tree c
, t
= expr
.value
;
12343 t
= c_fully_fold (t
, false, NULL
);
12345 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12347 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12349 c_parser_error (parser
, "expected integer expression");
12353 /* Attempt to statically determine when the number isn't positive. */
12354 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12355 build_int_cst (TREE_TYPE (t
), 0));
12356 protected_set_expr_location (c
, expr_loc
);
12357 if (c
== boolean_true_node
)
12359 warning_at (expr_loc
, 0,
12360 "%<vector_length%> value must be positive");
12361 t
= integer_one_node
;
12364 check_no_duplicate_clause (list
, OMP_CLAUSE_VECTOR_LENGTH
, "vector_length");
12366 c
= build_omp_clause (vector_length_loc
, OMP_CLAUSE_VECTOR_LENGTH
);
12367 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c
) = t
;
12368 OMP_CLAUSE_CHAIN (c
) = list
;
12380 c_parser_omp_clause_branch (c_parser
*parser ATTRIBUTE_UNUSED
,
12381 enum omp_clause_code code
, tree list
)
12383 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12385 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12386 OMP_CLAUSE_CHAIN (c
) = list
;
12398 c_parser_omp_clause_cancelkind (c_parser
*parser ATTRIBUTE_UNUSED
,
12399 enum omp_clause_code code
, tree list
)
12401 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12402 OMP_CLAUSE_CHAIN (c
) = list
;
12411 c_parser_omp_clause_nogroup (c_parser
*parser ATTRIBUTE_UNUSED
, tree list
)
12413 check_no_duplicate_clause (list
, OMP_CLAUSE_NOGROUP
, "nogroup");
12414 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
,
12415 OMP_CLAUSE_NOGROUP
);
12416 OMP_CLAUSE_CHAIN (c
) = list
;
12425 c_parser_omp_clause_orderedkind (c_parser
*parser ATTRIBUTE_UNUSED
,
12426 enum omp_clause_code code
, tree list
)
12428 check_no_duplicate_clause (list
, code
, omp_clause_code_name
[code
]);
12429 tree c
= build_omp_clause (c_parser_peek_token (parser
)->location
, code
);
12430 OMP_CLAUSE_CHAIN (c
) = list
;
12435 num_teams ( expression ) */
12438 c_parser_omp_clause_num_teams (c_parser
*parser
, tree list
)
12440 location_t num_teams_loc
= c_parser_peek_token (parser
)->location
;
12441 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12443 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12444 c_expr expr
= c_parser_expression (parser
);
12445 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12446 tree c
, t
= expr
.value
;
12447 t
= c_fully_fold (t
, false, NULL
);
12449 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12451 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12453 c_parser_error (parser
, "expected integer expression");
12457 /* Attempt to statically determine when the number isn't positive. */
12458 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12459 build_int_cst (TREE_TYPE (t
), 0));
12460 protected_set_expr_location (c
, expr_loc
);
12461 if (c
== boolean_true_node
)
12463 warning_at (expr_loc
, 0, "%<num_teams%> value must be positive");
12464 t
= integer_one_node
;
12467 check_no_duplicate_clause (list
, OMP_CLAUSE_NUM_TEAMS
, "num_teams");
12469 c
= build_omp_clause (num_teams_loc
, OMP_CLAUSE_NUM_TEAMS
);
12470 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
12471 OMP_CLAUSE_CHAIN (c
) = list
;
12479 thread_limit ( expression ) */
12482 c_parser_omp_clause_thread_limit (c_parser
*parser
, tree list
)
12484 location_t num_thread_limit_loc
= c_parser_peek_token (parser
)->location
;
12485 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12487 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12488 c_expr expr
= c_parser_expression (parser
);
12489 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12490 tree c
, t
= expr
.value
;
12491 t
= c_fully_fold (t
, false, NULL
);
12493 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12495 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
12497 c_parser_error (parser
, "expected integer expression");
12501 /* Attempt to statically determine when the number isn't positive. */
12502 c
= fold_build2_loc (expr_loc
, LE_EXPR
, boolean_type_node
, t
,
12503 build_int_cst (TREE_TYPE (t
), 0));
12504 protected_set_expr_location (c
, expr_loc
);
12505 if (c
== boolean_true_node
)
12507 warning_at (expr_loc
, 0, "%<thread_limit%> value must be positive");
12508 t
= integer_one_node
;
12511 check_no_duplicate_clause (list
, OMP_CLAUSE_THREAD_LIMIT
,
12514 c
= build_omp_clause (num_thread_limit_loc
, OMP_CLAUSE_THREAD_LIMIT
);
12515 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
12516 OMP_CLAUSE_CHAIN (c
) = list
;
12524 aligned ( variable-list )
12525 aligned ( variable-list : constant-expression ) */
12528 c_parser_omp_clause_aligned (c_parser
*parser
, tree list
)
12530 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12533 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12536 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12537 OMP_CLAUSE_ALIGNED
, list
);
12539 if (c_parser_next_token_is (parser
, CPP_COLON
))
12541 c_parser_consume_token (parser
);
12542 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12543 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12544 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12545 tree alignment
= expr
.value
;
12546 alignment
= c_fully_fold (alignment
, false, NULL
);
12547 if (TREE_CODE (alignment
) != INTEGER_CST
12548 || !INTEGRAL_TYPE_P (TREE_TYPE (alignment
))
12549 || tree_int_cst_sgn (alignment
) != 1)
12551 error_at (clause_loc
, "%<aligned%> clause alignment expression must "
12552 "be positive constant integer expression");
12553 alignment
= NULL_TREE
;
12556 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12557 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = alignment
;
12560 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12565 linear ( variable-list )
12566 linear ( variable-list : expression )
12569 linear ( modifier ( variable-list ) )
12570 linear ( modifier ( variable-list ) : expression ) */
12573 c_parser_omp_clause_linear (c_parser
*parser
, tree list
, bool is_cilk_simd_fn
)
12575 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12577 enum omp_clause_linear_kind kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
12579 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12582 if (!is_cilk_simd_fn
12583 && c_parser_next_token_is (parser
, CPP_NAME
))
12585 c_token
*tok
= c_parser_peek_token (parser
);
12586 const char *p
= IDENTIFIER_POINTER (tok
->value
);
12587 if (strcmp ("val", p
) == 0)
12588 kind
= OMP_CLAUSE_LINEAR_VAL
;
12589 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
)
12590 kind
= OMP_CLAUSE_LINEAR_DEFAULT
;
12591 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
12593 c_parser_consume_token (parser
);
12594 c_parser_consume_token (parser
);
12598 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12599 OMP_CLAUSE_LINEAR
, list
);
12601 if (kind
!= OMP_CLAUSE_LINEAR_DEFAULT
)
12602 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12604 if (c_parser_next_token_is (parser
, CPP_COLON
))
12606 c_parser_consume_token (parser
);
12607 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12608 c_expr expr
= c_parser_expression (parser
);
12609 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12611 step
= c_fully_fold (step
, false, NULL
);
12612 if (is_cilk_simd_fn
&& TREE_CODE (step
) == PARM_DECL
)
12614 sorry ("using parameters for %<linear%> step is not supported yet");
12615 step
= integer_one_node
;
12617 if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
12619 error_at (clause_loc
, "%<linear%> clause step expression must "
12621 step
= integer_one_node
;
12626 step
= integer_one_node
;
12628 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12630 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
12631 OMP_CLAUSE_LINEAR_KIND (c
) = kind
;
12634 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12639 safelen ( constant-expression ) */
12642 c_parser_omp_clause_safelen (c_parser
*parser
, tree list
)
12644 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12647 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12650 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12651 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12652 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12654 t
= c_fully_fold (t
, false, NULL
);
12655 if (TREE_CODE (t
) != INTEGER_CST
12656 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
12657 || tree_int_cst_sgn (t
) != 1)
12659 error_at (clause_loc
, "%<safelen%> clause expression must "
12660 "be positive constant integer expression");
12664 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12665 if (t
== NULL_TREE
|| t
== error_mark_node
)
12668 check_no_duplicate_clause (list
, OMP_CLAUSE_SAFELEN
, "safelen");
12670 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SAFELEN
);
12671 OMP_CLAUSE_SAFELEN_EXPR (c
) = t
;
12672 OMP_CLAUSE_CHAIN (c
) = list
;
12677 simdlen ( constant-expression ) */
12680 c_parser_omp_clause_simdlen (c_parser
*parser
, tree list
)
12682 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12685 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12688 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
12689 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
12690 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
12692 t
= c_fully_fold (t
, false, NULL
);
12693 if (TREE_CODE (t
) != INTEGER_CST
12694 || !INTEGRAL_TYPE_P (TREE_TYPE (t
))
12695 || tree_int_cst_sgn (t
) != 1)
12697 error_at (clause_loc
, "%<simdlen%> clause expression must "
12698 "be positive constant integer expression");
12702 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12703 if (t
== NULL_TREE
|| t
== error_mark_node
)
12706 check_no_duplicate_clause (list
, OMP_CLAUSE_SIMDLEN
, "simdlen");
12708 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_SIMDLEN
);
12709 OMP_CLAUSE_SIMDLEN_EXPR (c
) = t
;
12710 OMP_CLAUSE_CHAIN (c
) = list
;
12716 identifier [+/- integer]
12717 vec , identifier [+/- integer]
12721 c_parser_omp_clause_depend_sink (c_parser
*parser
, location_t clause_loc
,
12725 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
12726 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
12728 c_parser_error (parser
, "expected identifier");
12732 while (c_parser_next_token_is (parser
, CPP_NAME
)
12733 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
12735 tree t
= lookup_name (c_parser_peek_token (parser
)->value
);
12736 tree addend
= NULL
;
12738 if (t
== NULL_TREE
)
12740 undeclared_variable (c_parser_peek_token (parser
)->location
,
12741 c_parser_peek_token (parser
)->value
);
12742 t
= error_mark_node
;
12745 c_parser_consume_token (parser
);
12748 if (c_parser_next_token_is (parser
, CPP_MINUS
))
12750 else if (!c_parser_next_token_is (parser
, CPP_PLUS
))
12752 addend
= integer_zero_node
;
12754 goto add_to_vector
;
12756 c_parser_consume_token (parser
);
12758 if (c_parser_next_token_is_not (parser
, CPP_NUMBER
))
12760 c_parser_error (parser
, "expected integer");
12764 addend
= c_parser_peek_token (parser
)->value
;
12765 if (TREE_CODE (addend
) != INTEGER_CST
)
12767 c_parser_error (parser
, "expected integer");
12770 c_parser_consume_token (parser
);
12773 if (t
!= error_mark_node
)
12775 vec
= tree_cons (addend
, t
, vec
);
12777 OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec
) = 1;
12780 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
12783 c_parser_consume_token (parser
);
12786 if (vec
== NULL_TREE
)
12789 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
12790 OMP_CLAUSE_DEPEND_KIND (u
) = OMP_CLAUSE_DEPEND_SINK
;
12791 OMP_CLAUSE_DECL (u
) = nreverse (vec
);
12792 OMP_CLAUSE_CHAIN (u
) = list
;
12797 depend ( depend-kind: variable-list )
12805 depend ( sink : vec ) */
12808 c_parser_omp_clause_depend (c_parser
*parser
, tree list
)
12810 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12811 enum omp_clause_depend_kind kind
= OMP_CLAUSE_DEPEND_INOUT
;
12814 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12817 if (c_parser_next_token_is (parser
, CPP_NAME
))
12819 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12820 if (strcmp ("in", p
) == 0)
12821 kind
= OMP_CLAUSE_DEPEND_IN
;
12822 else if (strcmp ("inout", p
) == 0)
12823 kind
= OMP_CLAUSE_DEPEND_INOUT
;
12824 else if (strcmp ("out", p
) == 0)
12825 kind
= OMP_CLAUSE_DEPEND_OUT
;
12826 else if (strcmp ("source", p
) == 0)
12827 kind
= OMP_CLAUSE_DEPEND_SOURCE
;
12828 else if (strcmp ("sink", p
) == 0)
12829 kind
= OMP_CLAUSE_DEPEND_SINK
;
12836 c_parser_consume_token (parser
);
12838 if (kind
== OMP_CLAUSE_DEPEND_SOURCE
)
12840 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEPEND
);
12841 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
12842 OMP_CLAUSE_DECL (c
) = NULL_TREE
;
12843 OMP_CLAUSE_CHAIN (c
) = list
;
12844 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12848 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
12851 if (kind
== OMP_CLAUSE_DEPEND_SINK
)
12852 nl
= c_parser_omp_clause_depend_sink (parser
, clause_loc
, list
);
12855 nl
= c_parser_omp_variable_list (parser
, clause_loc
,
12856 OMP_CLAUSE_DEPEND
, list
);
12858 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12859 OMP_CLAUSE_DEPEND_KIND (c
) = kind
;
12862 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12866 c_parser_error (parser
, "invalid depend kind");
12868 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12873 map ( map-kind: variable-list )
12874 map ( variable-list )
12877 alloc | to | from | tofrom
12881 alloc | to | from | tofrom | release | delete
12883 map ( always [,] map-kind: variable-list ) */
12886 c_parser_omp_clause_map (c_parser
*parser
, tree list
)
12888 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
12889 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
12891 enum c_id_kind always_id_kind
= C_ID_NONE
;
12892 location_t always_loc
= UNKNOWN_LOCATION
;
12893 tree always_id
= NULL_TREE
;
12896 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
12899 if (c_parser_next_token_is (parser
, CPP_NAME
))
12901 c_token
*tok
= c_parser_peek_token (parser
);
12902 const char *p
= IDENTIFIER_POINTER (tok
->value
);
12903 always_id_kind
= tok
->id_kind
;
12904 always_loc
= tok
->location
;
12905 always_id
= tok
->value
;
12906 if (strcmp ("always", p
) == 0)
12908 c_token
*sectok
= c_parser_peek_2nd_token (parser
);
12909 if (sectok
->type
== CPP_COMMA
)
12911 c_parser_consume_token (parser
);
12912 c_parser_consume_token (parser
);
12915 else if (sectok
->type
== CPP_NAME
)
12917 p
= IDENTIFIER_POINTER (sectok
->value
);
12918 if (strcmp ("alloc", p
) == 0
12919 || strcmp ("to", p
) == 0
12920 || strcmp ("from", p
) == 0
12921 || strcmp ("tofrom", p
) == 0
12922 || strcmp ("release", p
) == 0
12923 || strcmp ("delete", p
) == 0)
12925 c_parser_consume_token (parser
);
12932 if (c_parser_next_token_is (parser
, CPP_NAME
)
12933 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
12935 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
12936 if (strcmp ("alloc", p
) == 0)
12937 kind
= GOMP_MAP_ALLOC
;
12938 else if (strcmp ("to", p
) == 0)
12939 kind
= always
? GOMP_MAP_ALWAYS_TO
: GOMP_MAP_TO
;
12940 else if (strcmp ("from", p
) == 0)
12941 kind
= always
? GOMP_MAP_ALWAYS_FROM
: GOMP_MAP_FROM
;
12942 else if (strcmp ("tofrom", p
) == 0)
12943 kind
= always
? GOMP_MAP_ALWAYS_TOFROM
: GOMP_MAP_TOFROM
;
12944 else if (strcmp ("release", p
) == 0)
12945 kind
= GOMP_MAP_RELEASE
;
12946 else if (strcmp ("delete", p
) == 0)
12947 kind
= GOMP_MAP_DELETE
;
12950 c_parser_error (parser
, "invalid map kind");
12951 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
12955 c_parser_consume_token (parser
);
12956 c_parser_consume_token (parser
);
12960 if (always_id_kind
!= C_ID_ID
)
12962 c_parser_error (parser
, "expected identifier");
12963 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12967 tree t
= lookup_name (always_id
);
12968 if (t
== NULL_TREE
)
12970 undeclared_variable (always_loc
, always_id
);
12971 t
= error_mark_node
;
12973 if (t
!= error_mark_node
)
12975 tree u
= build_omp_clause (clause_loc
, OMP_CLAUSE_MAP
);
12976 OMP_CLAUSE_DECL (u
) = t
;
12977 OMP_CLAUSE_CHAIN (u
) = list
;
12978 OMP_CLAUSE_SET_MAP_KIND (u
, kind
);
12983 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12988 nl
= c_parser_omp_variable_list (parser
, clause_loc
, OMP_CLAUSE_MAP
, list
);
12990 for (c
= nl
; c
!= list
; c
= OMP_CLAUSE_CHAIN (c
))
12991 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
12993 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
12998 device ( expression ) */
13001 c_parser_omp_clause_device (c_parser
*parser
, tree list
)
13003 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13004 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13006 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13007 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13008 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13009 tree c
, t
= expr
.value
;
13010 t
= c_fully_fold (t
, false, NULL
);
13012 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13014 if (!INTEGRAL_TYPE_P (TREE_TYPE (t
)))
13016 c_parser_error (parser
, "expected integer expression");
13020 check_no_duplicate_clause (list
, OMP_CLAUSE_DEVICE
, "device");
13022 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_DEVICE
);
13023 OMP_CLAUSE_DEVICE_ID (c
) = t
;
13024 OMP_CLAUSE_CHAIN (c
) = list
;
13032 dist_schedule ( static )
13033 dist_schedule ( static , expression ) */
13036 c_parser_omp_clause_dist_schedule (c_parser
*parser
, tree list
)
13038 tree c
, t
= NULL_TREE
;
13039 location_t loc
= c_parser_peek_token (parser
)->location
;
13041 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13044 if (!c_parser_next_token_is_keyword (parser
, RID_STATIC
))
13046 c_parser_error (parser
, "invalid dist_schedule kind");
13047 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13052 c_parser_consume_token (parser
);
13053 if (c_parser_next_token_is (parser
, CPP_COMMA
))
13055 c_parser_consume_token (parser
);
13057 location_t expr_loc
= c_parser_peek_token (parser
)->location
;
13058 c_expr expr
= c_parser_expr_no_commas (parser
, NULL
);
13059 expr
= convert_lvalue_to_rvalue (expr_loc
, expr
, false, true);
13061 t
= c_fully_fold (t
, false, NULL
);
13062 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13065 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
13066 "expected %<,%> or %<)%>");
13068 check_no_duplicate_clause (list
, OMP_CLAUSE_SCHEDULE
, "schedule");
13069 if (t
== error_mark_node
)
13072 c
= build_omp_clause (loc
, OMP_CLAUSE_DIST_SCHEDULE
);
13073 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
13074 OMP_CLAUSE_CHAIN (c
) = list
;
13079 proc_bind ( proc-bind-kind )
13082 master | close | spread */
13085 c_parser_omp_clause_proc_bind (c_parser
*parser
, tree list
)
13087 location_t clause_loc
= c_parser_peek_token (parser
)->location
;
13088 enum omp_clause_proc_bind_kind kind
;
13091 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13094 if (c_parser_next_token_is (parser
, CPP_NAME
))
13096 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13097 if (strcmp ("master", p
) == 0)
13098 kind
= OMP_CLAUSE_PROC_BIND_MASTER
;
13099 else if (strcmp ("close", p
) == 0)
13100 kind
= OMP_CLAUSE_PROC_BIND_CLOSE
;
13101 else if (strcmp ("spread", p
) == 0)
13102 kind
= OMP_CLAUSE_PROC_BIND_SPREAD
;
13109 c_parser_consume_token (parser
);
13110 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13111 c
= build_omp_clause (clause_loc
, OMP_CLAUSE_PROC_BIND
);
13112 OMP_CLAUSE_PROC_BIND_KIND (c
) = kind
;
13113 OMP_CLAUSE_CHAIN (c
) = list
;
13117 c_parser_error (parser
, "invalid proc_bind kind");
13118 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13123 to ( variable-list ) */
13126 c_parser_omp_clause_to (c_parser
*parser
, tree list
)
13128 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO
, list
);
13132 from ( variable-list ) */
13135 c_parser_omp_clause_from (c_parser
*parser
, tree list
)
13137 return c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_FROM
, list
);
13141 uniform ( variable-list ) */
13144 c_parser_omp_clause_uniform (c_parser
*parser
, tree list
)
13146 /* The clauses location. */
13147 location_t loc
= c_parser_peek_token (parser
)->location
;
13149 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
13151 list
= c_parser_omp_variable_list (parser
, loc
, OMP_CLAUSE_UNIFORM
,
13153 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
13158 /* Parse all OpenACC clauses. The set clauses allowed by the directive
13159 is a bitmask in MASK. Return the list of clauses found. */
13162 c_parser_oacc_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
13163 const char *where
, bool finish_p
= true)
13165 tree clauses
= NULL
;
13168 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13171 pragma_omp_clause c_kind
;
13172 const char *c_name
;
13173 tree prev
= clauses
;
13175 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
13176 c_parser_consume_token (parser
);
13178 here
= c_parser_peek_token (parser
)->location
;
13179 c_kind
= c_parser_omp_clause_name (parser
);
13183 case PRAGMA_OACC_CLAUSE_ASYNC
:
13184 clauses
= c_parser_oacc_clause_async (parser
, clauses
);
13187 case PRAGMA_OACC_CLAUSE_AUTO
:
13188 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_AUTO
,
13192 case PRAGMA_OACC_CLAUSE_COLLAPSE
:
13193 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
13194 c_name
= "collapse";
13196 case PRAGMA_OACC_CLAUSE_COPY
:
13197 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13200 case PRAGMA_OACC_CLAUSE_COPYIN
:
13201 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13204 case PRAGMA_OACC_CLAUSE_COPYOUT
:
13205 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13206 c_name
= "copyout";
13208 case PRAGMA_OACC_CLAUSE_CREATE
:
13209 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13212 case PRAGMA_OACC_CLAUSE_DELETE
:
13213 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13216 case PRAGMA_OMP_CLAUSE_DEFAULT
:
13217 clauses
= c_parser_omp_clause_default (parser
, clauses
, true);
13218 c_name
= "default";
13220 case PRAGMA_OACC_CLAUSE_DEVICE
:
13221 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13224 case PRAGMA_OACC_CLAUSE_DEVICEPTR
:
13225 clauses
= c_parser_oacc_data_clause_deviceptr (parser
, clauses
);
13226 c_name
= "deviceptr";
13228 case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT
:
13229 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13230 c_name
= "device_resident";
13232 case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE
:
13233 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13234 c_name
= "firstprivate";
13236 case PRAGMA_OACC_CLAUSE_GANG
:
13238 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_GANG
,
13241 case PRAGMA_OACC_CLAUSE_HOST
:
13242 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13245 case PRAGMA_OACC_CLAUSE_IF
:
13246 clauses
= c_parser_omp_clause_if (parser
, clauses
, false);
13249 case PRAGMA_OACC_CLAUSE_INDEPENDENT
:
13250 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_INDEPENDENT
,
13252 c_name
= "independent";
13254 case PRAGMA_OACC_CLAUSE_LINK
:
13255 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13258 case PRAGMA_OACC_CLAUSE_NUM_GANGS
:
13259 clauses
= c_parser_omp_clause_num_gangs (parser
, clauses
);
13260 c_name
= "num_gangs";
13262 case PRAGMA_OACC_CLAUSE_NUM_WORKERS
:
13263 clauses
= c_parser_omp_clause_num_workers (parser
, clauses
);
13264 c_name
= "num_workers";
13266 case PRAGMA_OACC_CLAUSE_PRESENT
:
13267 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13268 c_name
= "present";
13270 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY
:
13271 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13272 c_name
= "present_or_copy";
13274 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN
:
13275 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13276 c_name
= "present_or_copyin";
13278 case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT
:
13279 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13280 c_name
= "present_or_copyout";
13282 case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE
:
13283 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13284 c_name
= "present_or_create";
13286 case PRAGMA_OACC_CLAUSE_PRIVATE
:
13287 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13288 c_name
= "private";
13290 case PRAGMA_OACC_CLAUSE_REDUCTION
:
13291 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13292 c_name
= "reduction";
13294 case PRAGMA_OACC_CLAUSE_SELF
:
13295 clauses
= c_parser_oacc_data_clause (parser
, c_kind
, clauses
);
13298 case PRAGMA_OACC_CLAUSE_SEQ
:
13299 clauses
= c_parser_oacc_simple_clause (parser
, OMP_CLAUSE_SEQ
,
13303 case PRAGMA_OACC_CLAUSE_TILE
:
13304 clauses
= c_parser_oacc_clause_tile (parser
, clauses
);
13307 case PRAGMA_OACC_CLAUSE_USE_DEVICE
:
13308 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
13309 c_name
= "use_device";
13311 case PRAGMA_OACC_CLAUSE_VECTOR
:
13313 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_VECTOR
,
13316 case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH
:
13317 clauses
= c_parser_omp_clause_vector_length (parser
, clauses
);
13318 c_name
= "vector_length";
13320 case PRAGMA_OACC_CLAUSE_WAIT
:
13321 clauses
= c_parser_oacc_clause_wait (parser
, clauses
);
13324 case PRAGMA_OACC_CLAUSE_WORKER
:
13326 clauses
= c_parser_oacc_shape_clause (parser
, OMP_CLAUSE_WORKER
,
13330 c_parser_error (parser
, "expected %<#pragma acc%> clause");
13336 if (((mask
>> c_kind
) & 1) == 0)
13338 /* Remove the invalid clause(s) from the list to avoid
13339 confusing the rest of the compiler. */
13341 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
13346 c_parser_skip_to_pragma_eol (parser
);
13349 return c_finish_omp_clauses (clauses
, C_ORT_ACC
);
13354 /* Parse all OpenMP clauses. The set clauses allowed by the directive
13355 is a bitmask in MASK. Return the list of clauses found. */
13358 c_parser_omp_all_clauses (c_parser
*parser
, omp_clause_mask mask
,
13359 const char *where
, bool finish_p
= true)
13361 tree clauses
= NULL
;
13362 bool first
= true, cilk_simd_fn
= false;
13364 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
13367 pragma_omp_clause c_kind
;
13368 const char *c_name
;
13369 tree prev
= clauses
;
13371 if (!first
&& c_parser_next_token_is (parser
, CPP_COMMA
))
13372 c_parser_consume_token (parser
);
13374 here
= c_parser_peek_token (parser
)->location
;
13375 c_kind
= c_parser_omp_clause_name (parser
);
13379 case PRAGMA_OMP_CLAUSE_COLLAPSE
:
13380 clauses
= c_parser_omp_clause_collapse (parser
, clauses
);
13381 c_name
= "collapse";
13383 case PRAGMA_OMP_CLAUSE_COPYIN
:
13384 clauses
= c_parser_omp_clause_copyin (parser
, clauses
);
13387 case PRAGMA_OMP_CLAUSE_COPYPRIVATE
:
13388 clauses
= c_parser_omp_clause_copyprivate (parser
, clauses
);
13389 c_name
= "copyprivate";
13391 case PRAGMA_OMP_CLAUSE_DEFAULT
:
13392 clauses
= c_parser_omp_clause_default (parser
, clauses
, false);
13393 c_name
= "default";
13395 case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE
:
13396 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
13397 c_name
= "firstprivate";
13399 case PRAGMA_OMP_CLAUSE_FINAL
:
13400 clauses
= c_parser_omp_clause_final (parser
, clauses
);
13403 case PRAGMA_OMP_CLAUSE_GRAINSIZE
:
13404 clauses
= c_parser_omp_clause_grainsize (parser
, clauses
);
13405 c_name
= "grainsize";
13407 case PRAGMA_OMP_CLAUSE_HINT
:
13408 clauses
= c_parser_omp_clause_hint (parser
, clauses
);
13411 case PRAGMA_OMP_CLAUSE_DEFAULTMAP
:
13412 clauses
= c_parser_omp_clause_defaultmap (parser
, clauses
);
13413 c_name
= "defaultmap";
13415 case PRAGMA_OMP_CLAUSE_IF
:
13416 clauses
= c_parser_omp_clause_if (parser
, clauses
, true);
13419 case PRAGMA_OMP_CLAUSE_LASTPRIVATE
:
13420 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
13421 c_name
= "lastprivate";
13423 case PRAGMA_OMP_CLAUSE_MERGEABLE
:
13424 clauses
= c_parser_omp_clause_mergeable (parser
, clauses
);
13425 c_name
= "mergeable";
13427 case PRAGMA_OMP_CLAUSE_NOWAIT
:
13428 clauses
= c_parser_omp_clause_nowait (parser
, clauses
);
13431 case PRAGMA_OMP_CLAUSE_NUM_TASKS
:
13432 clauses
= c_parser_omp_clause_num_tasks (parser
, clauses
);
13433 c_name
= "num_tasks";
13435 case PRAGMA_OMP_CLAUSE_NUM_THREADS
:
13436 clauses
= c_parser_omp_clause_num_threads (parser
, clauses
);
13437 c_name
= "num_threads";
13439 case PRAGMA_OMP_CLAUSE_ORDERED
:
13440 clauses
= c_parser_omp_clause_ordered (parser
, clauses
);
13441 c_name
= "ordered";
13443 case PRAGMA_OMP_CLAUSE_PRIORITY
:
13444 clauses
= c_parser_omp_clause_priority (parser
, clauses
);
13445 c_name
= "priority";
13447 case PRAGMA_OMP_CLAUSE_PRIVATE
:
13448 clauses
= c_parser_omp_clause_private (parser
, clauses
);
13449 c_name
= "private";
13451 case PRAGMA_OMP_CLAUSE_REDUCTION
:
13452 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
13453 c_name
= "reduction";
13455 case PRAGMA_OMP_CLAUSE_SCHEDULE
:
13456 clauses
= c_parser_omp_clause_schedule (parser
, clauses
);
13457 c_name
= "schedule";
13459 case PRAGMA_OMP_CLAUSE_SHARED
:
13460 clauses
= c_parser_omp_clause_shared (parser
, clauses
);
13463 case PRAGMA_OMP_CLAUSE_UNTIED
:
13464 clauses
= c_parser_omp_clause_untied (parser
, clauses
);
13467 case PRAGMA_OMP_CLAUSE_INBRANCH
:
13468 case PRAGMA_CILK_CLAUSE_MASK
:
13469 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_INBRANCH
,
13471 c_name
= "inbranch";
13473 case PRAGMA_OMP_CLAUSE_NOTINBRANCH
:
13474 case PRAGMA_CILK_CLAUSE_NOMASK
:
13475 clauses
= c_parser_omp_clause_branch (parser
, OMP_CLAUSE_NOTINBRANCH
,
13477 c_name
= "notinbranch";
13479 case PRAGMA_OMP_CLAUSE_PARALLEL
:
13481 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_PARALLEL
,
13483 c_name
= "parallel";
13487 error_at (here
, "%qs must be the first clause of %qs",
13492 case PRAGMA_OMP_CLAUSE_FOR
:
13494 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_FOR
,
13498 goto clause_not_first
;
13500 case PRAGMA_OMP_CLAUSE_SECTIONS
:
13502 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_SECTIONS
,
13504 c_name
= "sections";
13506 goto clause_not_first
;
13508 case PRAGMA_OMP_CLAUSE_TASKGROUP
:
13510 = c_parser_omp_clause_cancelkind (parser
, OMP_CLAUSE_TASKGROUP
,
13512 c_name
= "taskgroup";
13514 goto clause_not_first
;
13516 case PRAGMA_OMP_CLAUSE_LINK
:
13518 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_LINK
, clauses
);
13521 case PRAGMA_OMP_CLAUSE_TO
:
13522 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINK
)) != 0)
13524 = c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
13527 clauses
= c_parser_omp_clause_to (parser
, clauses
);
13530 case PRAGMA_OMP_CLAUSE_FROM
:
13531 clauses
= c_parser_omp_clause_from (parser
, clauses
);
13534 case PRAGMA_OMP_CLAUSE_UNIFORM
:
13535 clauses
= c_parser_omp_clause_uniform (parser
, clauses
);
13536 c_name
= "uniform";
13538 case PRAGMA_OMP_CLAUSE_NUM_TEAMS
:
13539 clauses
= c_parser_omp_clause_num_teams (parser
, clauses
);
13540 c_name
= "num_teams";
13542 case PRAGMA_OMP_CLAUSE_THREAD_LIMIT
:
13543 clauses
= c_parser_omp_clause_thread_limit (parser
, clauses
);
13544 c_name
= "thread_limit";
13546 case PRAGMA_OMP_CLAUSE_ALIGNED
:
13547 clauses
= c_parser_omp_clause_aligned (parser
, clauses
);
13548 c_name
= "aligned";
13550 case PRAGMA_OMP_CLAUSE_LINEAR
:
13551 if (((mask
>> PRAGMA_CILK_CLAUSE_VECTORLENGTH
) & 1) != 0)
13552 cilk_simd_fn
= true;
13553 clauses
= c_parser_omp_clause_linear (parser
, clauses
, cilk_simd_fn
);
13556 case PRAGMA_OMP_CLAUSE_DEPEND
:
13557 clauses
= c_parser_omp_clause_depend (parser
, clauses
);
13560 case PRAGMA_OMP_CLAUSE_MAP
:
13561 clauses
= c_parser_omp_clause_map (parser
, clauses
);
13564 case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR
:
13565 clauses
= c_parser_omp_clause_use_device_ptr (parser
, clauses
);
13566 c_name
= "use_device_ptr";
13568 case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR
:
13569 clauses
= c_parser_omp_clause_is_device_ptr (parser
, clauses
);
13570 c_name
= "is_device_ptr";
13572 case PRAGMA_OMP_CLAUSE_DEVICE
:
13573 clauses
= c_parser_omp_clause_device (parser
, clauses
);
13576 case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
:
13577 clauses
= c_parser_omp_clause_dist_schedule (parser
, clauses
);
13578 c_name
= "dist_schedule";
13580 case PRAGMA_OMP_CLAUSE_PROC_BIND
:
13581 clauses
= c_parser_omp_clause_proc_bind (parser
, clauses
);
13582 c_name
= "proc_bind";
13584 case PRAGMA_OMP_CLAUSE_SAFELEN
:
13585 clauses
= c_parser_omp_clause_safelen (parser
, clauses
);
13586 c_name
= "safelen";
13588 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
13589 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, true);
13590 c_name
= "simdlen";
13592 case PRAGMA_OMP_CLAUSE_SIMDLEN
:
13593 clauses
= c_parser_omp_clause_simdlen (parser
, clauses
);
13594 c_name
= "simdlen";
13596 case PRAGMA_OMP_CLAUSE_NOGROUP
:
13597 clauses
= c_parser_omp_clause_nogroup (parser
, clauses
);
13598 c_name
= "nogroup";
13600 case PRAGMA_OMP_CLAUSE_THREADS
:
13602 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_THREADS
,
13604 c_name
= "threads";
13606 case PRAGMA_OMP_CLAUSE_SIMD
:
13608 = c_parser_omp_clause_orderedkind (parser
, OMP_CLAUSE_SIMD
,
13613 c_parser_error (parser
, "expected %<#pragma omp%> clause");
13619 if (((mask
>> c_kind
) & 1) == 0)
13621 /* Remove the invalid clause(s) from the list to avoid
13622 confusing the rest of the compiler. */
13624 error_at (here
, "%qs is not valid for %qs", c_name
, where
);
13629 c_parser_skip_to_pragma_eol (parser
);
13633 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_UNIFORM
)) != 0)
13634 return c_finish_omp_clauses (clauses
, C_ORT_OMP_DECLARE_SIMD
);
13635 return c_finish_omp_clauses (clauses
, C_ORT_OMP
);
13641 /* OpenACC 2.0, OpenMP 2.5:
13645 In practice, we're also interested in adding the statement to an
13646 outer node. So it is convenient if we work around the fact that
13647 c_parser_statement calls add_stmt. */
13650 c_parser_omp_structured_block (c_parser
*parser
, bool *if_p
)
13652 tree stmt
= push_stmt_list ();
13653 c_parser_statement (parser
, if_p
);
13654 return pop_stmt_list (stmt
);
13658 # pragma acc cache (variable-list) new-line
13660 LOC is the location of the #pragma token.
13664 c_parser_oacc_cache (location_t loc
, c_parser
*parser
)
13666 tree stmt
, clauses
;
13668 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE__CACHE_
, NULL
);
13669 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
13671 c_parser_skip_to_pragma_eol (parser
);
13673 stmt
= make_node (OACC_CACHE
);
13674 TREE_TYPE (stmt
) = void_type_node
;
13675 OACC_CACHE_CLAUSES (stmt
) = clauses
;
13676 SET_EXPR_LOCATION (stmt
, loc
);
13683 # pragma acc data oacc-data-clause[optseq] new-line
13686 LOC is the location of the #pragma token.
13689 #define OACC_DATA_CLAUSE_MASK \
13690 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13691 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13692 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13693 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13694 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13695 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13696 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13697 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13698 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13699 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13700 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
13703 c_parser_oacc_data (location_t loc
, c_parser
*parser
, bool *if_p
)
13705 tree stmt
, clauses
, block
;
13707 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DATA_CLAUSE_MASK
,
13708 "#pragma acc data");
13710 block
= c_begin_omp_parallel ();
13711 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
13713 stmt
= c_finish_oacc_data (loc
, clauses
, block
);
13719 # pragma acc declare oacc-data-clause[optseq] new-line
13722 #define OACC_DECLARE_CLAUSE_MASK \
13723 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
13724 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13725 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13726 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13727 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
13728 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \
13729 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \
13730 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
13731 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
13732 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13733 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
13734 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) )
13737 c_parser_oacc_declare (c_parser
*parser
)
13739 location_t pragma_loc
= c_parser_peek_token (parser
)->location
;
13740 tree clauses
, stmt
, t
, decl
;
13742 bool error
= false;
13744 c_parser_consume_pragma (parser
);
13746 clauses
= c_parser_oacc_all_clauses (parser
, OACC_DECLARE_CLAUSE_MASK
,
13747 "#pragma acc declare");
13750 error_at (pragma_loc
,
13751 "no valid clauses specified in %<#pragma acc declare%>");
13755 for (t
= clauses
; t
; t
= OMP_CLAUSE_CHAIN (t
))
13757 location_t loc
= OMP_CLAUSE_LOCATION (t
);
13758 decl
= OMP_CLAUSE_DECL (t
);
13759 if (!DECL_P (decl
))
13761 error_at (loc
, "array section in %<#pragma acc declare%>");
13766 switch (OMP_CLAUSE_MAP_KIND (t
))
13768 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
13769 case GOMP_MAP_FORCE_ALLOC
:
13770 case GOMP_MAP_FORCE_TO
:
13771 case GOMP_MAP_FORCE_DEVICEPTR
:
13772 case GOMP_MAP_DEVICE_RESIDENT
:
13775 case GOMP_MAP_LINK
:
13776 if (!global_bindings_p ()
13777 && (TREE_STATIC (decl
)
13778 || !DECL_EXTERNAL (decl
)))
13781 "%qD must be a global variable in"
13782 "%<#pragma acc declare link%>",
13790 if (global_bindings_p ())
13792 error_at (loc
, "invalid OpenACC clause at file scope");
13796 if (DECL_EXTERNAL (decl
))
13799 "invalid use of %<extern%> variable %qD "
13800 "in %<#pragma acc declare%>", decl
);
13804 else if (TREE_PUBLIC (decl
))
13807 "invalid use of %<global%> variable %qD "
13808 "in %<#pragma acc declare%>", decl
);
13815 if (lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl
))
13816 || lookup_attribute ("omp declare target link",
13817 DECL_ATTRIBUTES (decl
)))
13819 error_at (loc
, "variable %qD used more than once with "
13820 "%<#pragma acc declare%>", decl
);
13829 if (OMP_CLAUSE_MAP_KIND (t
) == GOMP_MAP_LINK
)
13830 id
= get_identifier ("omp declare target link");
13832 id
= get_identifier ("omp declare target");
13834 DECL_ATTRIBUTES (decl
)
13835 = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (decl
));
13837 if (global_bindings_p ())
13839 symtab_node
*node
= symtab_node::get (decl
);
13842 node
->offloadable
= 1;
13843 if (ENABLE_OFFLOADING
)
13845 g
->have_offload
= true;
13846 if (is_a
<varpool_node
*> (node
))
13847 vec_safe_push (offload_vars
, decl
);
13854 if (error
|| global_bindings_p ())
13857 stmt
= make_node (OACC_DECLARE
);
13858 TREE_TYPE (stmt
) = void_type_node
;
13859 OACC_DECLARE_CLAUSES (stmt
) = clauses
;
13860 SET_EXPR_LOCATION (stmt
, pragma_loc
);
13868 # pragma acc enter data oacc-enter-data-clause[optseq] new-line
13872 # pragma acc exit data oacc-exit-data-clause[optseq] new-line
13875 LOC is the location of the #pragma token.
13878 #define OACC_ENTER_DATA_CLAUSE_MASK \
13879 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13880 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13881 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
13882 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
13883 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
13884 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
13885 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13887 #define OACC_EXIT_DATA_CLAUSE_MASK \
13888 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
13889 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
13890 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
13891 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \
13892 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
13895 c_parser_oacc_enter_exit_data (c_parser
*parser
, bool enter
)
13897 location_t loc
= c_parser_peek_token (parser
)->location
;
13898 tree clauses
, stmt
;
13899 const char *p
= "";
13901 c_parser_consume_pragma (parser
);
13903 if (c_parser_next_token_is (parser
, CPP_NAME
))
13905 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
13906 c_parser_consume_token (parser
);
13909 if (strcmp (p
, "data") != 0)
13911 error_at (loc
, enter
13912 ? "expected %<data%> after %<#pragma acc enter%>"
13913 : "expected %<data%> after %<#pragma acc exit%>");
13914 parser
->error
= true;
13915 c_parser_skip_to_pragma_eol (parser
);
13920 clauses
= c_parser_oacc_all_clauses (parser
, OACC_ENTER_DATA_CLAUSE_MASK
,
13921 "#pragma acc enter data");
13923 clauses
= c_parser_oacc_all_clauses (parser
, OACC_EXIT_DATA_CLAUSE_MASK
,
13924 "#pragma acc exit data");
13926 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
13928 error_at (loc
, enter
13929 ? "%<#pragma acc enter data%> has no data movement clause"
13930 : "%<#pragma acc exit data%> has no data movement clause");
13934 stmt
= enter
? make_node (OACC_ENTER_DATA
) : make_node (OACC_EXIT_DATA
);
13935 TREE_TYPE (stmt
) = void_type_node
;
13936 OMP_STANDALONE_CLAUSES (stmt
) = clauses
;
13937 SET_EXPR_LOCATION (stmt
, loc
);
13943 # pragma acc host_data oacc-data-clause[optseq] new-line
13947 #define OACC_HOST_DATA_CLAUSE_MASK \
13948 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) )
13951 c_parser_oacc_host_data (location_t loc
, c_parser
*parser
, bool *if_p
)
13953 tree stmt
, clauses
, block
;
13955 clauses
= c_parser_oacc_all_clauses (parser
, OACC_HOST_DATA_CLAUSE_MASK
,
13956 "#pragma acc host_data");
13958 block
= c_begin_omp_parallel ();
13959 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
13960 stmt
= c_finish_oacc_host_data (loc
, clauses
, block
);
13967 # pragma acc loop oacc-loop-clause[optseq] new-line
13970 LOC is the location of the #pragma token.
13973 #define OACC_LOOP_CLAUSE_MASK \
13974 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \
13975 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \
13976 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
13977 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
13978 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
13979 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
13980 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \
13981 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \
13982 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \
13983 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) )
13985 c_parser_oacc_loop (location_t loc
, c_parser
*parser
, char *p_name
,
13986 omp_clause_mask mask
, tree
*cclauses
, bool *if_p
)
13988 bool is_parallel
= ((mask
>> PRAGMA_OACC_CLAUSE_REDUCTION
) & 1) == 1;
13990 strcat (p_name
, " loop");
13991 mask
|= OACC_LOOP_CLAUSE_MASK
;
13993 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
,
13997 clauses
= c_oacc_split_loop_clauses (clauses
, cclauses
, is_parallel
);
13999 *cclauses
= c_finish_omp_clauses (*cclauses
, C_ORT_ACC
);
14001 clauses
= c_finish_omp_clauses (clauses
, C_ORT_ACC
);
14004 tree block
= c_begin_compound_stmt (true);
14005 tree stmt
= c_parser_omp_for_loop (loc
, parser
, OACC_LOOP
, clauses
, NULL
,
14007 block
= c_end_compound_stmt (loc
, block
, true);
14014 # pragma acc kernels oacc-kernels-clause[optseq] new-line
14019 # pragma acc parallel oacc-parallel-clause[optseq] new-line
14022 LOC is the location of the #pragma token.
14025 #define OACC_KERNELS_CLAUSE_MASK \
14026 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14027 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \
14028 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \
14029 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \
14030 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \
14031 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \
14032 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \
14033 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14034 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14035 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14036 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14037 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14038 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14039 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14041 #define OACC_PARALLEL_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_PRIVATE) \
14051 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \
14052 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \
14053 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \
14054 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \
14055 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \
14056 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \
14057 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \
14058 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \
14059 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \
14060 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \
14061 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14064 c_parser_oacc_kernels_parallel (location_t loc
, c_parser
*parser
,
14065 enum pragma_kind p_kind
, char *p_name
,
14068 omp_clause_mask mask
;
14069 enum tree_code code
;
14072 case PRAGMA_OACC_KERNELS
:
14073 strcat (p_name
, " kernels");
14074 mask
= OACC_KERNELS_CLAUSE_MASK
;
14075 code
= OACC_KERNELS
;
14077 case PRAGMA_OACC_PARALLEL
:
14078 strcat (p_name
, " parallel");
14079 mask
= OACC_PARALLEL_CLAUSE_MASK
;
14080 code
= OACC_PARALLEL
;
14083 gcc_unreachable ();
14086 if (c_parser_next_token_is (parser
, CPP_NAME
))
14088 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14089 if (strcmp (p
, "loop") == 0)
14091 c_parser_consume_token (parser
);
14092 tree block
= c_begin_omp_parallel ();
14094 c_parser_oacc_loop (loc
, parser
, p_name
, mask
, &clauses
, if_p
);
14095 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14099 tree clauses
= c_parser_oacc_all_clauses (parser
, mask
, p_name
);
14101 tree block
= c_begin_omp_parallel ();
14102 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
14104 return c_finish_omp_construct (loc
, code
, block
, clauses
);
14108 # pragma acc routine oacc-routine-clause[optseq] new-line
14109 function-definition
14111 # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line
14114 #define OACC_ROUTINE_CLAUSE_MASK \
14115 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \
14116 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \
14117 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \
14118 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) )
14120 /* Parse an OpenACC routine directive. For named directives, we apply
14121 immediately to the named function. For unnamed ones we then parse
14122 a declaration or definition, which must be for a function. */
14125 c_parser_oacc_routine (c_parser
*parser
, enum pragma_context context
)
14127 gcc_checking_assert (context
== pragma_external
);
14129 oacc_routine_data data
;
14130 data
.error_seen
= false;
14131 data
.fndecl_seen
= false;
14132 data
.clauses
= NULL_TREE
;
14133 data
.loc
= c_parser_peek_token (parser
)->location
;
14135 c_parser_consume_pragma (parser
);
14137 /* Look for optional '( name )'. */
14138 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14140 c_parser_consume_token (parser
); /* '(' */
14142 tree decl
= NULL_TREE
;
14143 c_token
*name_token
= c_parser_peek_token (parser
);
14144 location_t name_loc
= name_token
->location
;
14145 if (name_token
->type
== CPP_NAME
14146 && (name_token
->id_kind
== C_ID_ID
14147 || name_token
->id_kind
== C_ID_TYPENAME
))
14149 decl
= lookup_name (name_token
->value
);
14151 error_at (name_loc
,
14152 "%qE has not been declared", name_token
->value
);
14153 c_parser_consume_token (parser
);
14156 c_parser_error (parser
, "expected function name");
14159 || !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
14161 c_parser_skip_to_pragma_eol (parser
, false);
14166 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
14167 "#pragma acc routine");
14169 if (TREE_CODE (decl
) != FUNCTION_DECL
)
14171 error_at (name_loc
, "%qD does not refer to a function", decl
);
14175 c_finish_oacc_routine (&data
, decl
, false);
14177 else /* No optional '( name )'. */
14180 = c_parser_oacc_all_clauses (parser
, OACC_ROUTINE_CLAUSE_MASK
,
14181 "#pragma acc routine");
14183 /* Emit a helpful diagnostic if there's another pragma following this
14184 one. Also don't allow a static assertion declaration, as in the
14185 following we'll just parse a *single* "declaration or function
14186 definition", and the static assertion counts an one. */
14187 if (c_parser_next_token_is (parser
, CPP_PRAGMA
)
14188 || c_parser_next_token_is_keyword (parser
, RID_STATIC_ASSERT
))
14190 error_at (data
.loc
,
14191 "%<#pragma acc routine%> not immediately followed by"
14192 " function declaration or definition");
14193 /* ..., and then just keep going. */
14197 /* We only have to consider the pragma_external case here. */
14198 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14199 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
14201 int ext
= disable_extension_diagnostics ();
14203 c_parser_consume_token (parser
);
14204 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
14205 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
14206 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14207 NULL
, vNULL
, &data
);
14208 restore_extension_diagnostics (ext
);
14211 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
14212 NULL
, vNULL
, &data
);
14216 /* Finalize an OpenACC routine pragma, applying it to FNDECL.
14217 IS_DEFN is true if we're applying it to the definition. */
14220 c_finish_oacc_routine (struct oacc_routine_data
*data
, tree fndecl
,
14223 /* Keep going if we're in error reporting mode. */
14224 if (data
->error_seen
14225 || fndecl
== error_mark_node
)
14228 if (data
->fndecl_seen
)
14230 error_at (data
->loc
,
14231 "%<#pragma acc routine%> not immediately followed by"
14232 " a single function declaration or definition");
14233 data
->error_seen
= true;
14236 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
14238 error_at (data
->loc
,
14239 "%<#pragma acc routine%> not immediately followed by"
14240 " function declaration or definition");
14241 data
->error_seen
= true;
14245 if (oacc_get_fn_attrib (fndecl
))
14247 error_at (data
->loc
,
14248 "%<#pragma acc routine%> already applied to %qD", fndecl
);
14249 data
->error_seen
= true;
14253 if (TREE_USED (fndecl
) || (!is_defn
&& DECL_SAVED_TREE (fndecl
)))
14255 error_at (data
->loc
,
14256 "%<#pragma acc routine%> must be applied before %s",
14257 TREE_USED (fndecl
) ? "use" : "definition");
14258 data
->error_seen
= true;
14262 /* Process the routine's dimension clauses. */
14263 tree dims
= oacc_build_routine_dims (data
->clauses
);
14264 oacc_replace_fn_attrib (fndecl
, dims
);
14266 /* Add an "omp declare target" attribute. */
14267 DECL_ATTRIBUTES (fndecl
)
14268 = tree_cons (get_identifier ("omp declare target"),
14269 NULL_TREE
, DECL_ATTRIBUTES (fndecl
));
14271 /* Remember that we've used this "#pragma acc routine". */
14272 data
->fndecl_seen
= true;
14276 # pragma acc update oacc-update-clause[optseq] new-line
14279 #define OACC_UPDATE_CLAUSE_MASK \
14280 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \
14281 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \
14282 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \
14283 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \
14284 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \
14285 | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) )
14288 c_parser_oacc_update (c_parser
*parser
)
14290 location_t loc
= c_parser_peek_token (parser
)->location
;
14292 c_parser_consume_pragma (parser
);
14294 tree clauses
= c_parser_oacc_all_clauses (parser
, OACC_UPDATE_CLAUSE_MASK
,
14295 "#pragma acc update");
14296 if (omp_find_clause (clauses
, OMP_CLAUSE_MAP
) == NULL_TREE
)
14299 "%<#pragma acc update%> must contain at least one "
14300 "%<device%> or %<host%> or %<self%> clause");
14307 tree stmt
= make_node (OACC_UPDATE
);
14308 TREE_TYPE (stmt
) = void_type_node
;
14309 OACC_UPDATE_CLAUSES (stmt
) = clauses
;
14310 SET_EXPR_LOCATION (stmt
, loc
);
14315 # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line
14317 LOC is the location of the #pragma token.
14320 #define OACC_WAIT_CLAUSE_MASK \
14321 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) )
14324 c_parser_oacc_wait (location_t loc
, c_parser
*parser
, char *p_name
)
14326 tree clauses
, list
= NULL_TREE
, stmt
= NULL_TREE
;
14328 if (c_parser_peek_token (parser
)->type
== CPP_OPEN_PAREN
)
14329 list
= c_parser_oacc_wait_list (parser
, loc
, list
);
14331 strcpy (p_name
, " wait");
14332 clauses
= c_parser_oacc_all_clauses (parser
, OACC_WAIT_CLAUSE_MASK
, p_name
);
14333 stmt
= c_finish_oacc_wait (loc
, list
, clauses
);
14340 # pragma omp atomic new-line
14344 x binop= expr | x++ | ++x | x-- | --x
14346 +, *, -, /, &, ^, |, <<, >>
14348 where x is an lvalue expression with scalar type.
14351 # pragma omp atomic new-line
14354 # pragma omp atomic read new-line
14357 # pragma omp atomic write new-line
14360 # pragma omp atomic update new-line
14363 # pragma omp atomic capture new-line
14366 # pragma omp atomic capture new-line
14374 expression-stmt | x = x binop expr
14376 v = expression-stmt
14378 { v = x; update-stmt; } | { update-stmt; v = x; }
14382 expression-stmt | x = x binop expr | x = expr binop x
14386 { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; }
14388 where x and v are lvalue expressions with scalar type.
14390 LOC is the location of the #pragma token. */
14393 c_parser_omp_atomic (location_t loc
, c_parser
*parser
)
14395 tree lhs
= NULL_TREE
, rhs
= NULL_TREE
, v
= NULL_TREE
;
14396 tree lhs1
= NULL_TREE
, rhs1
= NULL_TREE
;
14397 tree stmt
, orig_lhs
, unfolded_lhs
= NULL_TREE
, unfolded_lhs1
= NULL_TREE
;
14398 enum tree_code code
= OMP_ATOMIC
, opcode
= NOP_EXPR
;
14399 struct c_expr expr
;
14401 bool structured_block
= false;
14402 bool swapped
= false;
14403 bool seq_cst
= false;
14406 if (c_parser_next_token_is (parser
, CPP_NAME
))
14408 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14409 if (!strcmp (p
, "seq_cst"))
14412 c_parser_consume_token (parser
);
14413 if (c_parser_next_token_is (parser
, CPP_COMMA
)
14414 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
14415 c_parser_consume_token (parser
);
14418 if (c_parser_next_token_is (parser
, CPP_NAME
))
14420 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14422 if (!strcmp (p
, "read"))
14423 code
= OMP_ATOMIC_READ
;
14424 else if (!strcmp (p
, "write"))
14426 else if (!strcmp (p
, "update"))
14428 else if (!strcmp (p
, "capture"))
14429 code
= OMP_ATOMIC_CAPTURE_NEW
;
14433 c_parser_consume_token (parser
);
14437 if (c_parser_next_token_is (parser
, CPP_COMMA
)
14438 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
)
14439 c_parser_consume_token (parser
);
14441 if (c_parser_next_token_is (parser
, CPP_NAME
))
14444 = IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
14445 if (!strcmp (p
, "seq_cst"))
14448 c_parser_consume_token (parser
);
14452 c_parser_skip_to_pragma_eol (parser
);
14456 case OMP_ATOMIC_READ
:
14457 case NOP_EXPR
: /* atomic write */
14458 v
= c_parser_cast_expression (parser
, NULL
).value
;
14459 non_lvalue_p
= !lvalue_p (v
);
14460 v
= c_fully_fold (v
, false, NULL
);
14461 if (v
== error_mark_node
)
14464 v
= non_lvalue (v
);
14465 loc
= c_parser_peek_token (parser
)->location
;
14466 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14468 if (code
== NOP_EXPR
)
14470 lhs
= c_parser_expression (parser
).value
;
14471 lhs
= c_fully_fold (lhs
, false, NULL
);
14472 if (lhs
== error_mark_node
)
14477 lhs
= c_parser_cast_expression (parser
, NULL
).value
;
14478 non_lvalue_p
= !lvalue_p (lhs
);
14479 lhs
= c_fully_fold (lhs
, false, NULL
);
14480 if (lhs
== error_mark_node
)
14483 lhs
= non_lvalue (lhs
);
14485 if (code
== NOP_EXPR
)
14487 /* atomic write is represented by OMP_ATOMIC with NOP_EXPR
14495 case OMP_ATOMIC_CAPTURE_NEW
:
14496 if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
14498 c_parser_consume_token (parser
);
14499 structured_block
= true;
14503 v
= c_parser_cast_expression (parser
, NULL
).value
;
14504 non_lvalue_p
= !lvalue_p (v
);
14505 v
= c_fully_fold (v
, false, NULL
);
14506 if (v
== error_mark_node
)
14509 v
= non_lvalue (v
);
14510 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14518 /* For structured_block case we don't know yet whether
14519 old or new x should be captured. */
14521 eloc
= c_parser_peek_token (parser
)->location
;
14522 expr
= c_parser_cast_expression (parser
, NULL
);
14524 expr
= default_function_array_conversion (eloc
, expr
);
14525 unfolded_lhs
= expr
.value
;
14526 lhs
= c_fully_fold (lhs
, false, NULL
);
14528 switch (TREE_CODE (lhs
))
14532 c_parser_skip_to_end_of_block_or_statement (parser
);
14533 if (structured_block
)
14535 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
14536 c_parser_consume_token (parser
);
14537 else if (code
== OMP_ATOMIC_CAPTURE_NEW
)
14539 c_parser_skip_to_end_of_block_or_statement (parser
);
14540 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
14541 c_parser_consume_token (parser
);
14546 case POSTINCREMENT_EXPR
:
14547 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
14548 code
= OMP_ATOMIC_CAPTURE_OLD
;
14550 case PREINCREMENT_EXPR
:
14551 lhs
= TREE_OPERAND (lhs
, 0);
14552 unfolded_lhs
= NULL_TREE
;
14553 opcode
= PLUS_EXPR
;
14554 rhs
= integer_one_node
;
14557 case POSTDECREMENT_EXPR
:
14558 if (code
== OMP_ATOMIC_CAPTURE_NEW
&& !structured_block
)
14559 code
= OMP_ATOMIC_CAPTURE_OLD
;
14561 case PREDECREMENT_EXPR
:
14562 lhs
= TREE_OPERAND (lhs
, 0);
14563 unfolded_lhs
= NULL_TREE
;
14564 opcode
= MINUS_EXPR
;
14565 rhs
= integer_one_node
;
14568 case COMPOUND_EXPR
:
14569 if (TREE_CODE (TREE_OPERAND (lhs
, 0)) == SAVE_EXPR
14570 && TREE_CODE (TREE_OPERAND (lhs
, 1)) == COMPOUND_EXPR
14571 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0)) == MODIFY_EXPR
14572 && TREE_OPERAND (TREE_OPERAND (lhs
, 1), 1) == TREE_OPERAND (lhs
, 0)
14573 && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND
14574 (TREE_OPERAND (lhs
, 1), 0), 0)))
14576 /* Undo effects of boolean_increment for post {in,de}crement. */
14577 lhs
= TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0);
14580 if (TREE_CODE (lhs
) == MODIFY_EXPR
14581 && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs
, 0))) == BOOLEAN_TYPE
)
14583 /* Undo effects of boolean_increment. */
14584 if (integer_onep (TREE_OPERAND (lhs
, 1)))
14586 /* This is pre or post increment. */
14587 rhs
= TREE_OPERAND (lhs
, 1);
14588 lhs
= TREE_OPERAND (lhs
, 0);
14589 unfolded_lhs
= NULL_TREE
;
14591 if (code
== OMP_ATOMIC_CAPTURE_NEW
14592 && !structured_block
14593 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
14594 code
= OMP_ATOMIC_CAPTURE_OLD
;
14597 if (TREE_CODE (TREE_OPERAND (lhs
, 1)) == TRUTH_NOT_EXPR
14598 && TREE_OPERAND (lhs
, 0)
14599 == TREE_OPERAND (TREE_OPERAND (lhs
, 1), 0))
14601 /* This is pre or post decrement. */
14602 rhs
= TREE_OPERAND (lhs
, 1);
14603 lhs
= TREE_OPERAND (lhs
, 0);
14604 unfolded_lhs
= NULL_TREE
;
14606 if (code
== OMP_ATOMIC_CAPTURE_NEW
14607 && !structured_block
14608 && TREE_CODE (orig_lhs
) == COMPOUND_EXPR
)
14609 code
= OMP_ATOMIC_CAPTURE_OLD
;
14615 if (!lvalue_p (unfolded_lhs
))
14616 lhs
= non_lvalue (lhs
);
14617 switch (c_parser_peek_token (parser
)->type
)
14620 opcode
= MULT_EXPR
;
14623 opcode
= TRUNC_DIV_EXPR
;
14626 opcode
= PLUS_EXPR
;
14629 opcode
= MINUS_EXPR
;
14631 case CPP_LSHIFT_EQ
:
14632 opcode
= LSHIFT_EXPR
;
14634 case CPP_RSHIFT_EQ
:
14635 opcode
= RSHIFT_EXPR
;
14638 opcode
= BIT_AND_EXPR
;
14641 opcode
= BIT_IOR_EXPR
;
14644 opcode
= BIT_XOR_EXPR
;
14647 c_parser_consume_token (parser
);
14648 eloc
= c_parser_peek_token (parser
)->location
;
14649 expr
= c_parser_expr_no_commas (parser
, NULL
, unfolded_lhs
);
14651 switch (TREE_CODE (rhs1
))
14654 case TRUNC_DIV_EXPR
:
14663 if (c_tree_equal (TREE_OPERAND (rhs1
, 0), unfolded_lhs
))
14665 opcode
= TREE_CODE (rhs1
);
14666 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
14667 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
14670 if (c_tree_equal (TREE_OPERAND (rhs1
, 1), unfolded_lhs
))
14672 opcode
= TREE_CODE (rhs1
);
14673 rhs
= c_fully_fold (TREE_OPERAND (rhs1
, 0), false, NULL
);
14674 rhs1
= c_fully_fold (TREE_OPERAND (rhs1
, 1), false, NULL
);
14675 swapped
= !commutative_tree_code (opcode
);
14684 if (c_parser_peek_token (parser
)->type
== CPP_SEMICOLON
)
14686 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
14688 code
= OMP_ATOMIC_CAPTURE_OLD
;
14691 expr
= default_function_array_read_conversion (eloc
, expr
);
14692 unfolded_lhs1
= expr
.value
;
14693 lhs1
= c_fully_fold (unfolded_lhs1
, false, NULL
);
14695 c_parser_consume_token (parser
);
14698 if (structured_block
)
14701 expr
= default_function_array_read_conversion (eloc
, expr
);
14702 rhs
= c_fully_fold (expr
.value
, false, NULL
);
14707 c_parser_error (parser
, "invalid form of %<#pragma omp atomic%>");
14710 c_parser_error (parser
,
14711 "invalid operator for %<#pragma omp atomic%>");
14715 /* Arrange to pass the location of the assignment operator to
14716 c_finish_omp_atomic. */
14717 loc
= c_parser_peek_token (parser
)->location
;
14718 c_parser_consume_token (parser
);
14719 eloc
= c_parser_peek_token (parser
)->location
;
14720 expr
= c_parser_expression (parser
);
14721 expr
= default_function_array_read_conversion (eloc
, expr
);
14723 rhs
= c_fully_fold (rhs
, false, NULL
);
14727 if (structured_block
&& code
== OMP_ATOMIC_CAPTURE_NEW
)
14729 if (!c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
14731 v
= c_parser_cast_expression (parser
, NULL
).value
;
14732 non_lvalue_p
= !lvalue_p (v
);
14733 v
= c_fully_fold (v
, false, NULL
);
14734 if (v
== error_mark_node
)
14737 v
= non_lvalue (v
);
14738 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
14740 eloc
= c_parser_peek_token (parser
)->location
;
14741 expr
= c_parser_cast_expression (parser
, NULL
);
14743 expr
= default_function_array_read_conversion (eloc
, expr
);
14744 unfolded_lhs1
= expr
.value
;
14745 lhs1
= c_fully_fold (lhs1
, false, NULL
);
14746 if (lhs1
== error_mark_node
)
14748 if (!lvalue_p (unfolded_lhs1
))
14749 lhs1
= non_lvalue (lhs1
);
14751 if (structured_block
)
14753 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14754 c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>");
14757 if (unfolded_lhs
&& unfolded_lhs1
14758 && !c_tree_equal (unfolded_lhs
, unfolded_lhs1
))
14760 error ("%<#pragma omp atomic capture%> uses two different "
14761 "expressions for memory");
14762 stmt
= error_mark_node
;
14765 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
, v
, lhs1
, rhs1
,
14767 if (stmt
!= error_mark_node
)
14770 if (!structured_block
)
14771 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14776 # pragma omp barrier new-line
14780 c_parser_omp_barrier (c_parser
*parser
)
14782 location_t loc
= c_parser_peek_token (parser
)->location
;
14783 c_parser_consume_pragma (parser
);
14784 c_parser_skip_to_pragma_eol (parser
);
14786 c_finish_omp_barrier (loc
);
14790 # pragma omp critical [(name)] new-line
14794 # pragma omp critical [(name) [hint(expression)]] new-line
14796 LOC is the location of the #pragma itself. */
14798 #define OMP_CRITICAL_CLAUSE_MASK \
14799 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) )
14802 c_parser_omp_critical (location_t loc
, c_parser
*parser
, bool *if_p
)
14804 tree stmt
, name
= NULL_TREE
, clauses
= NULL_TREE
;
14806 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14808 c_parser_consume_token (parser
);
14809 if (c_parser_next_token_is (parser
, CPP_NAME
))
14811 name
= c_parser_peek_token (parser
)->value
;
14812 c_parser_consume_token (parser
);
14813 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
14816 c_parser_error (parser
, "expected identifier");
14818 clauses
= c_parser_omp_all_clauses (parser
,
14819 OMP_CRITICAL_CLAUSE_MASK
,
14820 "#pragma omp critical");
14824 if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14825 c_parser_error (parser
, "expected %<(%> or end of line");
14826 c_parser_skip_to_pragma_eol (parser
);
14829 stmt
= c_parser_omp_structured_block (parser
, if_p
);
14830 return c_finish_omp_critical (loc
, stmt
, name
, clauses
);
14834 # pragma omp flush flush-vars[opt] new-line
14837 ( variable-list ) */
14840 c_parser_omp_flush (c_parser
*parser
)
14842 location_t loc
= c_parser_peek_token (parser
)->location
;
14843 c_parser_consume_pragma (parser
);
14844 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
14845 c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
14846 else if (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
14847 c_parser_error (parser
, "expected %<(%> or end of line");
14848 c_parser_skip_to_pragma_eol (parser
);
14850 c_finish_omp_flush (loc
);
14853 /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP.
14854 The real trick here is to determine the loop control variable early
14855 so that we can push a new decl if necessary to make it private.
14856 LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp",
14860 c_parser_omp_for_loop (location_t loc
, c_parser
*parser
, enum tree_code code
,
14861 tree clauses
, tree
*cclauses
, bool *if_p
)
14863 tree decl
, cond
, incr
, save_break
, save_cont
, body
, init
, stmt
, cl
;
14864 tree declv
, condv
, incrv
, initv
, ret
= NULL_TREE
;
14865 tree pre_body
= NULL_TREE
, this_pre_body
;
14866 tree ordered_cl
= NULL_TREE
;
14867 bool fail
= false, open_brace_parsed
= false;
14868 int i
, collapse
= 1, ordered
= 0, count
, nbraces
= 0;
14869 location_t for_loc
;
14870 vec
<tree
, va_gc
> *for_block
= make_tree_vector ();
14872 for (cl
= clauses
; cl
; cl
= OMP_CLAUSE_CHAIN (cl
))
14873 if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_COLLAPSE
)
14874 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl
));
14875 else if (OMP_CLAUSE_CODE (cl
) == OMP_CLAUSE_ORDERED
14876 && OMP_CLAUSE_ORDERED_EXPR (cl
))
14879 ordered
= tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl
));
14882 if (ordered
&& ordered
< collapse
)
14884 error_at (OMP_CLAUSE_LOCATION (ordered_cl
),
14885 "%<ordered%> clause parameter is less than %<collapse%>");
14886 OMP_CLAUSE_ORDERED_EXPR (ordered_cl
)
14887 = build_int_cst (NULL_TREE
, collapse
);
14888 ordered
= collapse
;
14892 for (tree
*pc
= &clauses
; *pc
; )
14893 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_LINEAR
)
14895 error_at (OMP_CLAUSE_LOCATION (*pc
),
14896 "%<linear%> clause may not be specified together "
14897 "with %<ordered%> clause with a parameter");
14898 *pc
= OMP_CLAUSE_CHAIN (*pc
);
14901 pc
= &OMP_CLAUSE_CHAIN (*pc
);
14904 gcc_assert (collapse
>= 1 && ordered
>= 0);
14905 count
= ordered
? ordered
: collapse
;
14907 declv
= make_tree_vec (count
);
14908 initv
= make_tree_vec (count
);
14909 condv
= make_tree_vec (count
);
14910 incrv
= make_tree_vec (count
);
14912 if (code
!= CILK_FOR
14913 && !c_parser_next_token_is_keyword (parser
, RID_FOR
))
14915 c_parser_error (parser
, "for statement expected");
14918 if (code
== CILK_FOR
14919 && !c_parser_next_token_is_keyword (parser
, RID_CILK_FOR
))
14921 c_parser_error (parser
, "_Cilk_for statement expected");
14924 for_loc
= c_parser_peek_token (parser
)->location
;
14925 c_parser_consume_token (parser
);
14927 for (i
= 0; i
< count
; i
++)
14929 int bracecount
= 0;
14931 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
14934 /* Parse the initialization declaration or expression. */
14935 if (c_parser_next_tokens_start_declaration (parser
))
14938 vec_safe_push (for_block
, c_begin_compound_stmt (true));
14939 this_pre_body
= push_stmt_list ();
14940 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
14944 this_pre_body
= pop_stmt_list (this_pre_body
);
14948 pre_body
= push_stmt_list ();
14950 add_stmt (this_pre_body
);
14951 pre_body
= pop_stmt_list (pre_body
);
14954 pre_body
= this_pre_body
;
14956 decl
= check_for_loop_decls (for_loc
, flag_isoc99
);
14959 if (DECL_INITIAL (decl
) == error_mark_node
)
14960 decl
= error_mark_node
;
14963 else if (c_parser_next_token_is (parser
, CPP_NAME
)
14964 && c_parser_peek_2nd_token (parser
)->type
== CPP_EQ
)
14966 struct c_expr decl_exp
;
14967 struct c_expr init_exp
;
14968 location_t init_loc
;
14970 decl_exp
= c_parser_postfix_expression (parser
);
14971 decl
= decl_exp
.value
;
14973 c_parser_require (parser
, CPP_EQ
, "expected %<=%>");
14975 init_loc
= c_parser_peek_token (parser
)->location
;
14976 init_exp
= c_parser_expr_no_commas (parser
, NULL
);
14977 init_exp
= default_function_array_read_conversion (init_loc
,
14979 init
= build_modify_expr (init_loc
, decl
, decl_exp
.original_type
,
14980 NOP_EXPR
, init_loc
, init_exp
.value
,
14981 init_exp
.original_type
);
14982 init
= c_process_expr_stmt (init_loc
, init
);
14984 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
14989 c_parser_error (parser
,
14990 "expected iteration declaration or initialization");
14991 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
14997 /* Parse the loop condition. */
14999 if (c_parser_next_token_is_not (parser
, CPP_SEMICOLON
))
15001 location_t cond_loc
= c_parser_peek_token (parser
)->location
;
15002 struct c_expr cond_expr
15003 = c_parser_binary_expression (parser
, NULL
, NULL_TREE
);
15005 cond
= cond_expr
.value
;
15006 cond
= c_objc_common_truthvalue_conversion (cond_loc
, cond
);
15007 cond
= c_fully_fold (cond
, false, NULL
);
15008 switch (cond_expr
.original_code
)
15016 if (code
== CILK_SIMD
|| code
== CILK_FOR
)
15020 /* Can't be cond = error_mark_node, because we want to preserve
15021 the location until c_finish_omp_for. */
15022 cond
= build1 (NOP_EXPR
, boolean_type_node
, error_mark_node
);
15025 protected_set_expr_location (cond
, cond_loc
);
15027 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, "expected %<;%>");
15029 /* Parse the increment expression. */
15031 if (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
15033 location_t incr_loc
= c_parser_peek_token (parser
)->location
;
15035 incr
= c_process_expr_stmt (incr_loc
,
15036 c_parser_expression (parser
).value
);
15038 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
15040 if (decl
== NULL
|| decl
== error_mark_node
|| init
== error_mark_node
)
15044 TREE_VEC_ELT (declv
, i
) = decl
;
15045 TREE_VEC_ELT (initv
, i
) = init
;
15046 TREE_VEC_ELT (condv
, i
) = cond
;
15047 TREE_VEC_ELT (incrv
, i
) = incr
;
15051 if (i
== count
- 1)
15054 /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed
15055 in between the collapsed for loops to be still considered perfectly
15056 nested. Hopefully the final version clarifies this.
15057 For now handle (multiple) {'s and empty statements. */
15060 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
15062 c_parser_consume_token (parser
);
15065 else if (c_parser_next_token_is (parser
, CPP_OPEN_BRACE
))
15067 c_parser_consume_token (parser
);
15070 else if (bracecount
15071 && c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15072 c_parser_consume_token (parser
);
15075 c_parser_error (parser
, "not enough perfectly nested loops");
15078 open_brace_parsed
= true;
15088 nbraces
+= bracecount
;
15094 save_break
= c_break_label
;
15095 if (code
== CILK_SIMD
)
15096 c_break_label
= build_int_cst (size_type_node
, 2);
15098 c_break_label
= size_one_node
;
15099 save_cont
= c_cont_label
;
15100 c_cont_label
= NULL_TREE
;
15101 body
= push_stmt_list ();
15103 if (open_brace_parsed
)
15105 location_t here
= c_parser_peek_token (parser
)->location
;
15106 stmt
= c_begin_compound_stmt (true);
15107 c_parser_compound_statement_nostart (parser
);
15108 add_stmt (c_end_compound_stmt (here
, stmt
, true));
15111 add_stmt (c_parser_c99_block_statement (parser
, if_p
));
15114 tree t
= build1 (LABEL_EXPR
, void_type_node
, c_cont_label
);
15115 SET_EXPR_LOCATION (t
, loc
);
15119 body
= pop_stmt_list (body
);
15120 c_break_label
= save_break
;
15121 c_cont_label
= save_cont
;
15125 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15127 c_parser_consume_token (parser
);
15130 else if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
15131 c_parser_consume_token (parser
);
15134 c_parser_error (parser
, "collapsed loops not perfectly nested");
15137 location_t here
= c_parser_peek_token (parser
)->location
;
15138 stmt
= c_begin_compound_stmt (true);
15140 c_parser_compound_statement_nostart (parser
);
15141 body
= c_end_compound_stmt (here
, stmt
, true);
15148 /* Only bother calling c_finish_omp_for if we haven't already generated
15149 an error from the initialization parsing. */
15152 stmt
= c_finish_omp_for (loc
, code
, declv
, NULL
, initv
, condv
,
15153 incrv
, body
, pre_body
);
15155 /* Check for iterators appearing in lb, b or incr expressions. */
15156 if (stmt
&& !c_omp_check_loop_iv (stmt
, declv
, NULL
))
15163 if (cclauses
!= NULL
15164 && cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
] != NULL
)
15167 for (c
= &cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
]; *c
; )
15168 if (OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_FIRSTPRIVATE
15169 && OMP_CLAUSE_CODE (*c
) != OMP_CLAUSE_LASTPRIVATE
)
15170 c
= &OMP_CLAUSE_CHAIN (*c
);
15173 for (i
= 0; i
< count
; i
++)
15174 if (TREE_VEC_ELT (declv
, i
) == OMP_CLAUSE_DECL (*c
))
15177 c
= &OMP_CLAUSE_CHAIN (*c
);
15178 else if (OMP_CLAUSE_CODE (*c
) == OMP_CLAUSE_FIRSTPRIVATE
)
15181 "iteration variable %qD should not be firstprivate",
15182 OMP_CLAUSE_DECL (*c
));
15183 *c
= OMP_CLAUSE_CHAIN (*c
);
15187 /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */
15189 *c
= OMP_CLAUSE_CHAIN (*c
);
15190 if (code
== OMP_SIMD
)
15192 OMP_CLAUSE_CHAIN (l
)
15193 = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15194 cclauses
[C_OMP_CLAUSE_SPLIT_FOR
] = l
;
15198 OMP_CLAUSE_CHAIN (l
) = clauses
;
15204 OMP_FOR_CLAUSES (stmt
) = clauses
;
15209 while (!for_block
->is_empty ())
15211 /* FIXME diagnostics: LOC below should be the actual location of
15212 this particular for block. We need to build a list of
15213 locations to go along with FOR_BLOCK. */
15214 stmt
= c_end_compound_stmt (loc
, for_block
->pop (), true);
15217 release_tree_vector (for_block
);
15221 /* Helper function for OpenMP parsing, split clauses and call
15222 finish_omp_clauses on each of the set of clauses afterwards. */
15225 omp_split_clauses (location_t loc
, enum tree_code code
,
15226 omp_clause_mask mask
, tree clauses
, tree
*cclauses
)
15229 c_omp_split_clauses (loc
, code
, mask
, clauses
, cclauses
);
15230 for (i
= 0; i
< C_OMP_CLAUSE_SPLIT_COUNT
; i
++)
15232 cclauses
[i
] = c_finish_omp_clauses (cclauses
[i
], C_ORT_OMP
);
15236 #pragma omp simd simd-clause[optseq] new-line
15239 LOC is the location of the #pragma token.
15242 #define OMP_SIMD_CLAUSE_MASK \
15243 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \
15244 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
15245 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15246 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
15247 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15248 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15249 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15250 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15253 c_parser_omp_simd (location_t loc
, c_parser
*parser
,
15254 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15257 tree block
, clauses
, ret
;
15259 strcat (p_name
, " simd");
15260 mask
|= OMP_SIMD_CLAUSE_MASK
;
15262 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15265 omp_split_clauses (loc
, OMP_SIMD
, mask
, clauses
, cclauses
);
15266 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SIMD
];
15267 tree c
= omp_find_clause (cclauses
[C_OMP_CLAUSE_SPLIT_FOR
],
15268 OMP_CLAUSE_ORDERED
);
15269 if (c
&& OMP_CLAUSE_ORDERED_EXPR (c
))
15271 error_at (OMP_CLAUSE_LOCATION (c
),
15272 "%<ordered%> clause with parameter may not be specified "
15273 "on %qs construct", p_name
);
15274 OMP_CLAUSE_ORDERED_EXPR (c
) = NULL_TREE
;
15278 block
= c_begin_compound_stmt (true);
15279 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_SIMD
, clauses
, cclauses
, if_p
);
15280 block
= c_end_compound_stmt (loc
, block
, true);
15287 #pragma omp for for-clause[optseq] new-line
15291 #pragma omp for simd for-simd-clause[optseq] new-line
15294 LOC is the location of the #pragma token.
15297 #define OMP_FOR_CLAUSE_MASK \
15298 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15299 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15300 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15301 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
15302 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15303 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \
15304 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \
15305 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
15306 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15309 c_parser_omp_for (location_t loc
, c_parser
*parser
,
15310 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15313 tree block
, clauses
, ret
;
15315 strcat (p_name
, " for");
15316 mask
|= OMP_FOR_CLAUSE_MASK
;
15317 /* parallel for{, simd} disallows nowait clause, but for
15318 target {teams distribute ,}parallel for{, simd} it should be accepted. */
15319 if (cclauses
&& (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) == 0)
15320 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
15321 /* Composite distribute parallel for{, simd} disallows ordered clause. */
15322 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15323 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_ORDERED
);
15325 if (c_parser_next_token_is (parser
, CPP_NAME
))
15327 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15329 if (strcmp (p
, "simd") == 0)
15331 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15332 if (cclauses
== NULL
)
15333 cclauses
= cclauses_buf
;
15335 c_parser_consume_token (parser
);
15336 if (!flag_openmp
) /* flag_openmp_simd */
15337 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
15339 block
= c_begin_compound_stmt (true);
15340 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15341 block
= c_end_compound_stmt (loc
, block
, true);
15342 if (ret
== NULL_TREE
)
15344 ret
= make_node (OMP_FOR
);
15345 TREE_TYPE (ret
) = void_type_node
;
15346 OMP_FOR_BODY (ret
) = block
;
15347 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15348 SET_EXPR_LOCATION (ret
, loc
);
15353 if (!flag_openmp
) /* flag_openmp_simd */
15355 c_parser_skip_to_pragma_eol (parser
, false);
15359 /* Composite distribute parallel for disallows linear clause. */
15360 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15361 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_LINEAR
);
15363 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15366 omp_split_clauses (loc
, OMP_FOR
, mask
, clauses
, cclauses
);
15367 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_FOR
];
15370 block
= c_begin_compound_stmt (true);
15371 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_FOR
, clauses
, cclauses
, if_p
);
15372 block
= c_end_compound_stmt (loc
, block
, true);
15379 # pragma omp master new-line
15382 LOC is the location of the #pragma token.
15386 c_parser_omp_master (location_t loc
, c_parser
*parser
, bool *if_p
)
15388 c_parser_skip_to_pragma_eol (parser
);
15389 return c_finish_omp_master (loc
, c_parser_omp_structured_block (parser
,
15394 # pragma omp ordered new-line
15398 # pragma omp ordered ordered-clauses new-line
15401 # pragma omp ordered depend-clauses new-line */
15403 #define OMP_ORDERED_CLAUSE_MASK \
15404 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \
15405 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD))
15407 #define OMP_ORDERED_DEPEND_CLAUSE_MASK \
15408 (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND)
15411 c_parser_omp_ordered (c_parser
*parser
, enum pragma_context context
,
15414 location_t loc
= c_parser_peek_token (parser
)->location
;
15415 c_parser_consume_pragma (parser
);
15417 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
15419 c_parser_error (parser
, "expected declaration specifiers");
15420 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
15424 if (c_parser_next_token_is (parser
, CPP_NAME
))
15426 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15428 if (!strcmp ("depend", p
))
15430 if (context
== pragma_stmt
)
15433 "%<#pragma omp ordered%> with %<depend> clause may "
15434 "only be used in compound statements");
15435 c_parser_skip_to_pragma_eol (parser
, false);
15440 = c_parser_omp_all_clauses (parser
,
15441 OMP_ORDERED_DEPEND_CLAUSE_MASK
,
15442 "#pragma omp ordered");
15443 c_finish_omp_ordered (loc
, clauses
, NULL_TREE
);
15448 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_ORDERED_CLAUSE_MASK
,
15449 "#pragma omp ordered");
15450 c_finish_omp_ordered (loc
, clauses
,
15451 c_parser_omp_structured_block (parser
, if_p
));
15458 { section-sequence }
15461 section-directive[opt] structured-block
15462 section-sequence section-directive structured-block
15464 SECTIONS_LOC is the location of the #pragma omp sections. */
15467 c_parser_omp_sections_scope (location_t sections_loc
, c_parser
*parser
)
15469 tree stmt
, substmt
;
15470 bool error_suppress
= false;
15473 loc
= c_parser_peek_token (parser
)->location
;
15474 if (!c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
15476 /* Avoid skipping until the end of the block. */
15477 parser
->error
= false;
15481 stmt
= push_stmt_list ();
15483 if (c_parser_peek_token (parser
)->pragma_kind
!= PRAGMA_OMP_SECTION
)
15485 substmt
= c_parser_omp_structured_block (parser
, NULL
);
15486 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
15487 SET_EXPR_LOCATION (substmt
, loc
);
15488 add_stmt (substmt
);
15493 if (c_parser_next_token_is (parser
, CPP_CLOSE_BRACE
))
15495 if (c_parser_next_token_is (parser
, CPP_EOF
))
15498 loc
= c_parser_peek_token (parser
)->location
;
15499 if (c_parser_peek_token (parser
)->pragma_kind
== PRAGMA_OMP_SECTION
)
15501 c_parser_consume_pragma (parser
);
15502 c_parser_skip_to_pragma_eol (parser
);
15503 error_suppress
= false;
15505 else if (!error_suppress
)
15507 error_at (loc
, "expected %<#pragma omp section%> or %<}%>");
15508 error_suppress
= true;
15511 substmt
= c_parser_omp_structured_block (parser
, NULL
);
15512 substmt
= build1 (OMP_SECTION
, void_type_node
, substmt
);
15513 SET_EXPR_LOCATION (substmt
, loc
);
15514 add_stmt (substmt
);
15516 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
,
15517 "expected %<#pragma omp section%> or %<}%>");
15519 substmt
= pop_stmt_list (stmt
);
15521 stmt
= make_node (OMP_SECTIONS
);
15522 SET_EXPR_LOCATION (stmt
, sections_loc
);
15523 TREE_TYPE (stmt
) = void_type_node
;
15524 OMP_SECTIONS_BODY (stmt
) = substmt
;
15526 return add_stmt (stmt
);
15530 # pragma omp sections sections-clause[optseq] newline
15533 LOC is the location of the #pragma token.
15536 #define OMP_SECTIONS_CLAUSE_MASK \
15537 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15538 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15539 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15540 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15541 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15544 c_parser_omp_sections (location_t loc
, c_parser
*parser
,
15545 char *p_name
, omp_clause_mask mask
, tree
*cclauses
)
15547 tree block
, clauses
, ret
;
15549 strcat (p_name
, " sections");
15550 mask
|= OMP_SECTIONS_CLAUSE_MASK
;
15552 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_NOWAIT
);
15554 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15557 omp_split_clauses (loc
, OMP_SECTIONS
, mask
, clauses
, cclauses
);
15558 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_SECTIONS
];
15561 block
= c_begin_compound_stmt (true);
15562 ret
= c_parser_omp_sections_scope (loc
, parser
);
15564 OMP_SECTIONS_CLAUSES (ret
) = clauses
;
15565 block
= c_end_compound_stmt (loc
, block
, true);
15572 # pragma omp parallel parallel-clause[optseq] new-line
15574 # pragma omp parallel for parallel-for-clause[optseq] new-line
15576 # pragma omp parallel sections parallel-sections-clause[optseq] new-line
15580 # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line
15583 LOC is the location of the #pragma token.
15586 #define OMP_PARALLEL_CLAUSE_MASK \
15587 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15588 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15589 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15590 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
15591 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15592 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \
15593 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15594 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \
15595 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND))
15598 c_parser_omp_parallel (location_t loc
, c_parser
*parser
,
15599 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15602 tree stmt
, clauses
, block
;
15604 strcat (p_name
, " parallel");
15605 mask
|= OMP_PARALLEL_CLAUSE_MASK
;
15606 /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */
15607 if ((mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_MAP
)) != 0
15608 && (mask
& (OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) == 0)
15609 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_COPYIN
);
15611 if (c_parser_next_token_is_keyword (parser
, RID_FOR
))
15613 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15614 if (cclauses
== NULL
)
15615 cclauses
= cclauses_buf
;
15617 c_parser_consume_token (parser
);
15618 if (!flag_openmp
) /* flag_openmp_simd */
15619 return c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15620 block
= c_begin_omp_parallel ();
15621 tree ret
= c_parser_omp_for (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
15623 = c_finish_omp_parallel (loc
, cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
15625 if (ret
== NULL_TREE
)
15627 OMP_PARALLEL_COMBINED (stmt
) = 1;
15630 /* When combined with distribute, parallel has to be followed by for.
15631 #pragma omp target parallel is allowed though. */
15633 && (mask
& (OMP_CLAUSE_MASK_1
15634 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE
)) != 0)
15636 error_at (loc
, "expected %<for%> after %qs", p_name
);
15637 c_parser_skip_to_pragma_eol (parser
);
15640 else if (!flag_openmp
) /* flag_openmp_simd */
15642 c_parser_skip_to_pragma_eol (parser
, false);
15645 else if (cclauses
== NULL
&& c_parser_next_token_is (parser
, CPP_NAME
))
15647 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15648 if (strcmp (p
, "sections") == 0)
15650 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15651 if (cclauses
== NULL
)
15652 cclauses
= cclauses_buf
;
15654 c_parser_consume_token (parser
);
15655 block
= c_begin_omp_parallel ();
15656 c_parser_omp_sections (loc
, parser
, p_name
, mask
, cclauses
);
15657 stmt
= c_finish_omp_parallel (loc
,
15658 cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
],
15660 OMP_PARALLEL_COMBINED (stmt
) = 1;
15665 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15668 omp_split_clauses (loc
, OMP_PARALLEL
, mask
, clauses
, cclauses
);
15669 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_PARALLEL
];
15672 block
= c_begin_omp_parallel ();
15673 c_parser_statement (parser
, if_p
);
15674 stmt
= c_finish_omp_parallel (loc
, clauses
, block
);
15680 # pragma omp single single-clause[optseq] new-line
15683 LOC is the location of the #pragma.
15686 #define OMP_SINGLE_CLAUSE_MASK \
15687 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15688 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15689 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \
15690 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
15693 c_parser_omp_single (location_t loc
, c_parser
*parser
, bool *if_p
)
15695 tree stmt
= make_node (OMP_SINGLE
);
15696 SET_EXPR_LOCATION (stmt
, loc
);
15697 TREE_TYPE (stmt
) = void_type_node
;
15699 OMP_SINGLE_CLAUSES (stmt
)
15700 = c_parser_omp_all_clauses (parser
, OMP_SINGLE_CLAUSE_MASK
,
15701 "#pragma omp single");
15702 OMP_SINGLE_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
15704 return add_stmt (stmt
);
15708 # pragma omp task task-clause[optseq] new-line
15710 LOC is the location of the #pragma.
15713 #define OMP_TASK_CLAUSE_MASK \
15714 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
15715 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
15716 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
15717 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15718 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15719 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15720 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
15721 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
15722 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
15723 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
15726 c_parser_omp_task (location_t loc
, c_parser
*parser
, bool *if_p
)
15728 tree clauses
, block
;
15730 clauses
= c_parser_omp_all_clauses (parser
, OMP_TASK_CLAUSE_MASK
,
15731 "#pragma omp task");
15733 block
= c_begin_omp_task ();
15734 c_parser_statement (parser
, if_p
);
15735 return c_finish_omp_task (loc
, clauses
, block
);
15739 # pragma omp taskwait new-line
15743 c_parser_omp_taskwait (c_parser
*parser
)
15745 location_t loc
= c_parser_peek_token (parser
)->location
;
15746 c_parser_consume_pragma (parser
);
15747 c_parser_skip_to_pragma_eol (parser
);
15749 c_finish_omp_taskwait (loc
);
15753 # pragma omp taskyield new-line
15757 c_parser_omp_taskyield (c_parser
*parser
)
15759 location_t loc
= c_parser_peek_token (parser
)->location
;
15760 c_parser_consume_pragma (parser
);
15761 c_parser_skip_to_pragma_eol (parser
);
15763 c_finish_omp_taskyield (loc
);
15767 # pragma omp taskgroup new-line
15771 c_parser_omp_taskgroup (c_parser
*parser
, bool *if_p
)
15773 location_t loc
= c_parser_peek_token (parser
)->location
;
15774 c_parser_skip_to_pragma_eol (parser
);
15775 return c_finish_omp_taskgroup (loc
, c_parser_omp_structured_block (parser
,
15780 # pragma omp cancel cancel-clause[optseq] new-line
15782 LOC is the location of the #pragma.
15785 #define OMP_CANCEL_CLAUSE_MASK \
15786 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
15787 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
15788 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
15789 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \
15790 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF))
15793 c_parser_omp_cancel (c_parser
*parser
)
15795 location_t loc
= c_parser_peek_token (parser
)->location
;
15797 c_parser_consume_pragma (parser
);
15798 tree clauses
= c_parser_omp_all_clauses (parser
, OMP_CANCEL_CLAUSE_MASK
,
15799 "#pragma omp cancel");
15801 c_finish_omp_cancel (loc
, clauses
);
15805 # pragma omp cancellation point cancelpt-clause[optseq] new-line
15807 LOC is the location of the #pragma.
15810 #define OMP_CANCELLATION_POINT_CLAUSE_MASK \
15811 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \
15812 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \
15813 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \
15814 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP))
15817 c_parser_omp_cancellation_point (c_parser
*parser
, enum pragma_context context
)
15819 location_t loc
= c_parser_peek_token (parser
)->location
;
15821 bool point_seen
= false;
15823 c_parser_consume_pragma (parser
);
15824 if (c_parser_next_token_is (parser
, CPP_NAME
))
15826 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15827 if (strcmp (p
, "point") == 0)
15829 c_parser_consume_token (parser
);
15835 c_parser_error (parser
, "expected %<point%>");
15836 c_parser_skip_to_pragma_eol (parser
);
15840 if (context
!= pragma_compound
)
15842 if (context
== pragma_stmt
)
15843 error_at (loc
, "%<#pragma omp cancellation point%> may only be used in"
15844 " compound statements");
15846 c_parser_error (parser
, "expected declaration specifiers");
15847 c_parser_skip_to_pragma_eol (parser
, false);
15852 = c_parser_omp_all_clauses (parser
, OMP_CANCELLATION_POINT_CLAUSE_MASK
,
15853 "#pragma omp cancellation point");
15855 c_finish_omp_cancellation_point (loc
, clauses
);
15859 #pragma omp distribute distribute-clause[optseq] new-line
15862 #define OMP_DISTRIBUTE_CLAUSE_MASK \
15863 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15864 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15865 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
15866 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\
15867 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE))
15870 c_parser_omp_distribute (location_t loc
, c_parser
*parser
,
15871 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15874 tree clauses
, block
, ret
;
15876 strcat (p_name
, " distribute");
15877 mask
|= OMP_DISTRIBUTE_CLAUSE_MASK
;
15879 if (c_parser_next_token_is (parser
, CPP_NAME
))
15881 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15883 bool parallel
= false;
15885 if (strcmp (p
, "simd") == 0)
15888 parallel
= strcmp (p
, "parallel") == 0;
15889 if (parallel
|| simd
)
15891 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15892 if (cclauses
== NULL
)
15893 cclauses
= cclauses_buf
;
15894 c_parser_consume_token (parser
);
15895 if (!flag_openmp
) /* flag_openmp_simd */
15898 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
15901 return c_parser_omp_parallel (loc
, parser
, p_name
, mask
,
15904 block
= c_begin_compound_stmt (true);
15906 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
15909 ret
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, cclauses
,
15911 block
= c_end_compound_stmt (loc
, block
, true);
15914 ret
= make_node (OMP_DISTRIBUTE
);
15915 TREE_TYPE (ret
) = void_type_node
;
15916 OMP_FOR_BODY (ret
) = block
;
15917 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
15918 SET_EXPR_LOCATION (ret
, loc
);
15923 if (!flag_openmp
) /* flag_openmp_simd */
15925 c_parser_skip_to_pragma_eol (parser
, false);
15929 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
15932 omp_split_clauses (loc
, OMP_DISTRIBUTE
, mask
, clauses
, cclauses
);
15933 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_DISTRIBUTE
];
15936 block
= c_begin_compound_stmt (true);
15937 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_DISTRIBUTE
, clauses
, NULL
,
15939 block
= c_end_compound_stmt (loc
, block
, true);
15946 # pragma omp teams teams-clause[optseq] new-line
15947 structured-block */
15949 #define OMP_TEAMS_CLAUSE_MASK \
15950 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
15951 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
15952 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
15953 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \
15954 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \
15955 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \
15956 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT))
15959 c_parser_omp_teams (location_t loc
, c_parser
*parser
,
15960 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
15963 tree clauses
, block
, ret
;
15965 strcat (p_name
, " teams");
15966 mask
|= OMP_TEAMS_CLAUSE_MASK
;
15968 if (c_parser_next_token_is (parser
, CPP_NAME
))
15970 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
15971 if (strcmp (p
, "distribute") == 0)
15973 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
15974 if (cclauses
== NULL
)
15975 cclauses
= cclauses_buf
;
15977 c_parser_consume_token (parser
);
15978 if (!flag_openmp
) /* flag_openmp_simd */
15979 return c_parser_omp_distribute (loc
, parser
, p_name
, mask
,
15981 block
= c_begin_compound_stmt (true);
15982 ret
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, cclauses
,
15984 block
= c_end_compound_stmt (loc
, block
, true);
15987 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
15988 ret
= make_node (OMP_TEAMS
);
15989 TREE_TYPE (ret
) = void_type_node
;
15990 OMP_TEAMS_CLAUSES (ret
) = clauses
;
15991 OMP_TEAMS_BODY (ret
) = block
;
15992 OMP_TEAMS_COMBINED (ret
) = 1;
15993 return add_stmt (ret
);
15996 if (!flag_openmp
) /* flag_openmp_simd */
15998 c_parser_skip_to_pragma_eol (parser
, false);
16002 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
16005 omp_split_clauses (loc
, OMP_TEAMS
, mask
, clauses
, cclauses
);
16006 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16009 tree stmt
= make_node (OMP_TEAMS
);
16010 TREE_TYPE (stmt
) = void_type_node
;
16011 OMP_TEAMS_CLAUSES (stmt
) = clauses
;
16012 OMP_TEAMS_BODY (stmt
) = c_parser_omp_structured_block (parser
, if_p
);
16014 return add_stmt (stmt
);
16018 # pragma omp target data target-data-clause[optseq] new-line
16019 structured-block */
16021 #define OMP_TARGET_DATA_CLAUSE_MASK \
16022 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16023 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16024 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16025 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR))
16028 c_parser_omp_target_data (location_t loc
, c_parser
*parser
, bool *if_p
)
16031 = c_parser_omp_all_clauses (parser
, OMP_TARGET_DATA_CLAUSE_MASK
,
16032 "#pragma omp target data");
16034 for (tree
*pc
= &clauses
; *pc
;)
16036 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16037 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16040 case GOMP_MAP_ALWAYS_TO
:
16041 case GOMP_MAP_FROM
:
16042 case GOMP_MAP_ALWAYS_FROM
:
16043 case GOMP_MAP_TOFROM
:
16044 case GOMP_MAP_ALWAYS_TOFROM
:
16045 case GOMP_MAP_ALLOC
:
16048 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16049 case GOMP_MAP_ALWAYS_POINTER
:
16053 error_at (OMP_CLAUSE_LOCATION (*pc
),
16054 "%<#pragma omp target data%> with map-type other "
16055 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16056 "on %<map%> clause");
16057 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16060 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16067 "%<#pragma omp target data%> must contain at least "
16068 "one %<map%> clause");
16072 tree stmt
= make_node (OMP_TARGET_DATA
);
16073 TREE_TYPE (stmt
) = void_type_node
;
16074 OMP_TARGET_DATA_CLAUSES (stmt
) = clauses
;
16075 keep_next_level ();
16076 tree block
= c_begin_compound_stmt (true);
16077 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
16078 OMP_TARGET_DATA_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
16080 SET_EXPR_LOCATION (stmt
, loc
);
16081 return add_stmt (stmt
);
16085 # pragma omp target update target-update-clause[optseq] new-line */
16087 #define OMP_TARGET_UPDATE_CLAUSE_MASK \
16088 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \
16089 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16090 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16091 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16092 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16093 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16096 c_parser_omp_target_update (location_t loc
, c_parser
*parser
,
16097 enum pragma_context context
)
16099 if (context
== pragma_stmt
)
16102 "%<#pragma omp target update%> may only be "
16103 "used in compound statements");
16104 c_parser_skip_to_pragma_eol (parser
, false);
16109 = c_parser_omp_all_clauses (parser
, OMP_TARGET_UPDATE_CLAUSE_MASK
,
16110 "#pragma omp target update");
16111 if (omp_find_clause (clauses
, OMP_CLAUSE_TO
) == NULL_TREE
16112 && omp_find_clause (clauses
, OMP_CLAUSE_FROM
) == NULL_TREE
)
16115 "%<#pragma omp target update%> must contain at least one "
16116 "%<from%> or %<to%> clauses");
16120 tree stmt
= make_node (OMP_TARGET_UPDATE
);
16121 TREE_TYPE (stmt
) = void_type_node
;
16122 OMP_TARGET_UPDATE_CLAUSES (stmt
) = clauses
;
16123 SET_EXPR_LOCATION (stmt
, loc
);
16129 # pragma omp target enter data target-data-clause[optseq] new-line */
16131 #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \
16132 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16133 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16134 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16135 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16136 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16139 c_parser_omp_target_enter_data (location_t loc
, c_parser
*parser
,
16140 enum pragma_context context
)
16142 bool data_seen
= false;
16143 if (c_parser_next_token_is (parser
, CPP_NAME
))
16145 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16146 if (strcmp (p
, "data") == 0)
16148 c_parser_consume_token (parser
);
16154 c_parser_error (parser
, "expected %<data%>");
16155 c_parser_skip_to_pragma_eol (parser
);
16159 if (context
== pragma_stmt
)
16162 "%<#pragma omp target enter data%> may only be "
16163 "used in compound statements");
16164 c_parser_skip_to_pragma_eol (parser
, false);
16169 = c_parser_omp_all_clauses (parser
, OMP_TARGET_ENTER_DATA_CLAUSE_MASK
,
16170 "#pragma omp target enter data");
16172 for (tree
*pc
= &clauses
; *pc
;)
16174 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16175 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16178 case GOMP_MAP_ALWAYS_TO
:
16179 case GOMP_MAP_ALLOC
:
16182 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16183 case GOMP_MAP_ALWAYS_POINTER
:
16187 error_at (OMP_CLAUSE_LOCATION (*pc
),
16188 "%<#pragma omp target enter data%> with map-type other "
16189 "than %<to%> or %<alloc%> on %<map%> clause");
16190 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16193 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16200 "%<#pragma omp target enter data%> must contain at least "
16201 "one %<map%> clause");
16205 tree stmt
= make_node (OMP_TARGET_ENTER_DATA
);
16206 TREE_TYPE (stmt
) = void_type_node
;
16207 OMP_TARGET_ENTER_DATA_CLAUSES (stmt
) = clauses
;
16208 SET_EXPR_LOCATION (stmt
, loc
);
16214 # pragma omp target exit data target-data-clause[optseq] new-line */
16216 #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \
16217 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16218 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16219 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16220 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16221 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT))
16224 c_parser_omp_target_exit_data (location_t loc
, c_parser
*parser
,
16225 enum pragma_context context
)
16227 bool data_seen
= false;
16228 if (c_parser_next_token_is (parser
, CPP_NAME
))
16230 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16231 if (strcmp (p
, "data") == 0)
16233 c_parser_consume_token (parser
);
16239 c_parser_error (parser
, "expected %<data%>");
16240 c_parser_skip_to_pragma_eol (parser
);
16244 if (context
== pragma_stmt
)
16247 "%<#pragma omp target exit data%> may only be "
16248 "used in compound statements");
16249 c_parser_skip_to_pragma_eol (parser
, false);
16254 = c_parser_omp_all_clauses (parser
, OMP_TARGET_EXIT_DATA_CLAUSE_MASK
,
16255 "#pragma omp target exit data");
16258 for (tree
*pc
= &clauses
; *pc
;)
16260 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16261 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16263 case GOMP_MAP_FROM
:
16264 case GOMP_MAP_ALWAYS_FROM
:
16265 case GOMP_MAP_RELEASE
:
16266 case GOMP_MAP_DELETE
:
16269 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16270 case GOMP_MAP_ALWAYS_POINTER
:
16274 error_at (OMP_CLAUSE_LOCATION (*pc
),
16275 "%<#pragma omp target exit data%> with map-type other "
16276 "than %<from%>, %<release> or %<delete%> on %<map%>"
16278 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16281 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16288 "%<#pragma omp target exit data%> must contain at least one "
16293 tree stmt
= make_node (OMP_TARGET_EXIT_DATA
);
16294 TREE_TYPE (stmt
) = void_type_node
;
16295 OMP_TARGET_EXIT_DATA_CLAUSES (stmt
) = clauses
;
16296 SET_EXPR_LOCATION (stmt
, loc
);
16302 # pragma omp target target-clause[optseq] new-line
16303 structured-block */
16305 #define OMP_TARGET_CLAUSE_MASK \
16306 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \
16307 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \
16308 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
16309 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \
16310 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \
16311 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
16312 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
16313 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \
16314 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR))
16317 c_parser_omp_target (c_parser
*parser
, enum pragma_context context
, bool *if_p
)
16319 location_t loc
= c_parser_peek_token (parser
)->location
;
16320 c_parser_consume_pragma (parser
);
16321 tree
*pc
= NULL
, stmt
, block
;
16323 if (context
!= pragma_stmt
&& context
!= pragma_compound
)
16325 c_parser_error (parser
, "expected declaration specifiers");
16326 c_parser_skip_to_pragma_eol (parser
);
16330 if (c_parser_next_token_is (parser
, CPP_NAME
))
16332 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16333 enum tree_code ccode
= ERROR_MARK
;
16335 if (strcmp (p
, "teams") == 0)
16337 else if (strcmp (p
, "parallel") == 0)
16338 ccode
= OMP_PARALLEL
;
16339 else if (strcmp (p
, "simd") == 0)
16341 if (ccode
!= ERROR_MARK
)
16343 tree cclauses
[C_OMP_CLAUSE_SPLIT_COUNT
];
16344 char p_name
[sizeof ("#pragma omp target teams distribute "
16345 "parallel for simd")];
16347 c_parser_consume_token (parser
);
16348 strcpy (p_name
, "#pragma omp target");
16349 if (!flag_openmp
) /* flag_openmp_simd */
16355 stmt
= c_parser_omp_teams (loc
, parser
, p_name
,
16356 OMP_TARGET_CLAUSE_MASK
,
16360 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
,
16361 OMP_TARGET_CLAUSE_MASK
,
16365 stmt
= c_parser_omp_simd (loc
, parser
, p_name
,
16366 OMP_TARGET_CLAUSE_MASK
,
16370 gcc_unreachable ();
16372 return stmt
!= NULL_TREE
;
16374 keep_next_level ();
16375 tree block
= c_begin_compound_stmt (true), ret
;
16379 ret
= c_parser_omp_teams (loc
, parser
, p_name
,
16380 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16384 ret
= c_parser_omp_parallel (loc
, parser
, p_name
,
16385 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16389 ret
= c_parser_omp_simd (loc
, parser
, p_name
,
16390 OMP_TARGET_CLAUSE_MASK
, cclauses
,
16394 gcc_unreachable ();
16396 block
= c_end_compound_stmt (loc
, block
, true);
16397 if (ret
== NULL_TREE
)
16399 if (ccode
== OMP_TEAMS
)
16401 /* For combined target teams, ensure the num_teams and
16402 thread_limit clause expressions are evaluated on the host,
16403 before entering the target construct. */
16405 for (c
= cclauses
[C_OMP_CLAUSE_SPLIT_TEAMS
];
16406 c
; c
= OMP_CLAUSE_CHAIN (c
))
16407 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
16408 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_THREAD_LIMIT
)
16409 && TREE_CODE (OMP_CLAUSE_OPERAND (c
, 0)) != INTEGER_CST
)
16411 tree expr
= OMP_CLAUSE_OPERAND (c
, 0);
16412 tree tmp
= create_tmp_var_raw (TREE_TYPE (expr
));
16413 expr
= build4 (TARGET_EXPR
, TREE_TYPE (expr
), tmp
,
16414 expr
, NULL_TREE
, NULL_TREE
);
16416 OMP_CLAUSE_OPERAND (c
, 0) = expr
;
16417 tree tc
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
16418 OMP_CLAUSE_FIRSTPRIVATE
);
16419 OMP_CLAUSE_DECL (tc
) = tmp
;
16420 OMP_CLAUSE_CHAIN (tc
)
16421 = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
16422 cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
] = tc
;
16425 tree stmt
= make_node (OMP_TARGET
);
16426 TREE_TYPE (stmt
) = void_type_node
;
16427 OMP_TARGET_CLAUSES (stmt
) = cclauses
[C_OMP_CLAUSE_SPLIT_TARGET
];
16428 OMP_TARGET_BODY (stmt
) = block
;
16429 OMP_TARGET_COMBINED (stmt
) = 1;
16431 pc
= &OMP_TARGET_CLAUSES (stmt
);
16432 goto check_clauses
;
16434 else if (!flag_openmp
) /* flag_openmp_simd */
16436 c_parser_skip_to_pragma_eol (parser
, false);
16439 else if (strcmp (p
, "data") == 0)
16441 c_parser_consume_token (parser
);
16442 c_parser_omp_target_data (loc
, parser
, if_p
);
16445 else if (strcmp (p
, "enter") == 0)
16447 c_parser_consume_token (parser
);
16448 c_parser_omp_target_enter_data (loc
, parser
, context
);
16451 else if (strcmp (p
, "exit") == 0)
16453 c_parser_consume_token (parser
);
16454 c_parser_omp_target_exit_data (loc
, parser
, context
);
16457 else if (strcmp (p
, "update") == 0)
16459 c_parser_consume_token (parser
);
16460 return c_parser_omp_target_update (loc
, parser
, context
);
16464 stmt
= make_node (OMP_TARGET
);
16465 TREE_TYPE (stmt
) = void_type_node
;
16467 OMP_TARGET_CLAUSES (stmt
)
16468 = c_parser_omp_all_clauses (parser
, OMP_TARGET_CLAUSE_MASK
,
16469 "#pragma omp target");
16470 pc
= &OMP_TARGET_CLAUSES (stmt
);
16471 keep_next_level ();
16472 block
= c_begin_compound_stmt (true);
16473 add_stmt (c_parser_omp_structured_block (parser
, if_p
));
16474 OMP_TARGET_BODY (stmt
) = c_end_compound_stmt (loc
, block
, true);
16476 SET_EXPR_LOCATION (stmt
, loc
);
16482 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_MAP
)
16483 switch (OMP_CLAUSE_MAP_KIND (*pc
))
16486 case GOMP_MAP_ALWAYS_TO
:
16487 case GOMP_MAP_FROM
:
16488 case GOMP_MAP_ALWAYS_FROM
:
16489 case GOMP_MAP_TOFROM
:
16490 case GOMP_MAP_ALWAYS_TOFROM
:
16491 case GOMP_MAP_ALLOC
:
16492 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
16493 case GOMP_MAP_ALWAYS_POINTER
:
16496 error_at (OMP_CLAUSE_LOCATION (*pc
),
16497 "%<#pragma omp target%> with map-type other "
16498 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
16499 "on %<map%> clause");
16500 *pc
= OMP_CLAUSE_CHAIN (*pc
);
16503 pc
= &OMP_CLAUSE_CHAIN (*pc
);
16509 # pragma omp declare simd declare-simd-clauses[optseq] new-line */
16511 #define OMP_DECLARE_SIMD_CLAUSE_MASK \
16512 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \
16513 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \
16514 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \
16515 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \
16516 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \
16517 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH))
16520 c_parser_omp_declare_simd (c_parser
*parser
, enum pragma_context context
)
16522 auto_vec
<c_token
> clauses
;
16523 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16525 c_token
*token
= c_parser_peek_token (parser
);
16526 if (token
->type
== CPP_EOF
)
16528 c_parser_skip_to_pragma_eol (parser
);
16531 clauses
.safe_push (*token
);
16532 c_parser_consume_token (parser
);
16534 clauses
.safe_push (*c_parser_peek_token (parser
));
16535 c_parser_skip_to_pragma_eol (parser
);
16537 while (c_parser_next_token_is (parser
, CPP_PRAGMA
))
16539 if (c_parser_peek_token (parser
)->pragma_kind
16540 != PRAGMA_OMP_DECLARE
16541 || c_parser_peek_2nd_token (parser
)->type
!= CPP_NAME
16542 || strcmp (IDENTIFIER_POINTER
16543 (c_parser_peek_2nd_token (parser
)->value
),
16546 c_parser_error (parser
,
16547 "%<#pragma omp declare simd%> must be followed by "
16548 "function declaration or definition or another "
16549 "%<#pragma omp declare simd%>");
16552 c_parser_consume_pragma (parser
);
16553 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
16555 c_token
*token
= c_parser_peek_token (parser
);
16556 if (token
->type
== CPP_EOF
)
16558 c_parser_skip_to_pragma_eol (parser
);
16561 clauses
.safe_push (*token
);
16562 c_parser_consume_token (parser
);
16564 clauses
.safe_push (*c_parser_peek_token (parser
));
16565 c_parser_skip_to_pragma_eol (parser
);
16568 /* Make sure nothing tries to read past the end of the tokens. */
16570 memset (&eof_token
, 0, sizeof (eof_token
));
16571 eof_token
.type
= CPP_EOF
;
16572 clauses
.safe_push (eof_token
);
16573 clauses
.safe_push (eof_token
);
16577 case pragma_external
:
16578 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16579 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
16581 int ext
= disable_extension_diagnostics ();
16583 c_parser_consume_token (parser
);
16584 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16585 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
16586 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
16588 restore_extension_diagnostics (ext
);
16591 c_parser_declaration_or_fndef (parser
, true, true, true, false, true,
16594 case pragma_struct
:
16596 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
16597 "function declaration or definition");
16599 case pragma_compound
:
16601 if (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16602 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
)
16604 int ext
= disable_extension_diagnostics ();
16606 c_parser_consume_token (parser
);
16607 while (c_parser_next_token_is (parser
, CPP_KEYWORD
)
16608 && c_parser_peek_token (parser
)->keyword
== RID_EXTENSION
);
16609 if (c_parser_next_tokens_start_declaration (parser
))
16611 c_parser_declaration_or_fndef (parser
, true, true, true, true,
16612 true, NULL
, clauses
);
16613 restore_extension_diagnostics (ext
);
16616 restore_extension_diagnostics (ext
);
16618 else if (c_parser_next_tokens_start_declaration (parser
))
16620 c_parser_declaration_or_fndef (parser
, true, true, true, true, true,
16624 c_parser_error (parser
, "%<#pragma omp declare simd%> must be followed by "
16625 "function declaration or definition");
16628 gcc_unreachable ();
16632 /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed,
16633 and put that into "omp declare simd" attribute. */
16636 c_finish_omp_declare_simd (c_parser
*parser
, tree fndecl
, tree parms
,
16637 vec
<c_token
> clauses
)
16640 && (clauses
.exists ()
16641 || lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl
)))
16642 && !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16644 error ("%<#pragma omp declare simd%> or %<simd%> attribute cannot be "
16645 "used in the same function marked as a Cilk Plus SIMD-enabled "
16647 vec_free (parser
->cilk_simd_fn_tokens
);
16651 /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates
16652 error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd
16653 has already processed the tokens. */
16654 if (clauses
.exists () && clauses
[0].type
== CPP_EOF
)
16656 if (fndecl
== NULL_TREE
|| TREE_CODE (fndecl
) != FUNCTION_DECL
)
16658 error ("%<#pragma omp declare simd%> not immediately followed by "
16659 "a function declaration or definition");
16660 clauses
[0].type
= CPP_EOF
;
16663 if (clauses
.exists () && clauses
[0].type
!= CPP_NAME
)
16665 error_at (DECL_SOURCE_LOCATION (fndecl
),
16666 "%<#pragma omp declare simd%> not immediately followed by "
16667 "a single function declaration or definition");
16668 clauses
[0].type
= CPP_EOF
;
16672 if (parms
== NULL_TREE
)
16673 parms
= DECL_ARGUMENTS (fndecl
);
16675 unsigned int tokens_avail
= parser
->tokens_avail
;
16676 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
16677 bool is_cilkplus_cilk_simd_fn
= false;
16679 if (flag_cilkplus
&& !vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16681 parser
->tokens
= parser
->cilk_simd_fn_tokens
->address ();
16682 parser
->tokens_avail
= vec_safe_length (parser
->cilk_simd_fn_tokens
);
16683 is_cilkplus_cilk_simd_fn
= true;
16685 if (lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl
)) != NULL
)
16687 error_at (DECL_SOURCE_LOCATION (fndecl
),
16688 "%<__simd__%> attribute cannot be used in the same "
16689 "function marked as a Cilk Plus SIMD-enabled function");
16690 vec_free (parser
->cilk_simd_fn_tokens
);
16697 parser
->tokens
= clauses
.address ();
16698 parser
->tokens_avail
= clauses
.length ();
16701 /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */
16702 while (parser
->tokens_avail
> 3)
16704 c_token
*token
= c_parser_peek_token (parser
);
16705 if (!is_cilkplus_cilk_simd_fn
)
16706 gcc_assert (token
->type
== CPP_NAME
16707 && strcmp (IDENTIFIER_POINTER (token
->value
), "simd") == 0);
16709 gcc_assert (token
->type
== CPP_NAME
16710 && is_cilkplus_vector_p (token
->value
));
16711 c_parser_consume_token (parser
);
16712 parser
->in_pragma
= true;
16714 tree c
= NULL_TREE
;
16715 if (is_cilkplus_cilk_simd_fn
)
16716 c
= c_parser_omp_all_clauses (parser
, CILK_SIMD_FN_CLAUSE_MASK
,
16717 "SIMD-enabled functions attribute");
16719 c
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_SIMD_CLAUSE_MASK
,
16720 "#pragma omp declare simd");
16721 c
= c_omp_declare_simd_clauses_to_numbers (parms
, c
);
16722 if (c
!= NULL_TREE
)
16723 c
= tree_cons (NULL_TREE
, c
, NULL_TREE
);
16724 if (is_cilkplus_cilk_simd_fn
)
16726 tree k
= build_tree_list (get_identifier ("cilk simd function"),
16728 TREE_CHAIN (k
) = DECL_ATTRIBUTES (fndecl
);
16729 DECL_ATTRIBUTES (fndecl
) = k
;
16731 c
= build_tree_list (get_identifier ("omp declare simd"), c
);
16732 TREE_CHAIN (c
) = DECL_ATTRIBUTES (fndecl
);
16733 DECL_ATTRIBUTES (fndecl
) = c
;
16736 parser
->tokens
= &parser
->tokens_buf
[0];
16737 parser
->tokens_avail
= tokens_avail
;
16738 if (clauses
.exists ())
16739 clauses
[0].type
= CPP_PRAGMA
;
16741 if (!vec_safe_is_empty (parser
->cilk_simd_fn_tokens
))
16742 vec_free (parser
->cilk_simd_fn_tokens
);
16747 # pragma omp declare target new-line
16748 declarations and definitions
16749 # pragma omp end declare target new-line
16752 # pragma omp declare target ( extended-list ) new-line
16754 # pragma omp declare target declare-target-clauses[seq] new-line */
16756 #define OMP_DECLARE_TARGET_CLAUSE_MASK \
16757 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \
16758 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK))
16761 c_parser_omp_declare_target (c_parser
*parser
)
16763 location_t loc
= c_parser_peek_token (parser
)->location
;
16764 tree clauses
= NULL_TREE
;
16765 if (c_parser_next_token_is (parser
, CPP_NAME
))
16766 clauses
= c_parser_omp_all_clauses (parser
, OMP_DECLARE_TARGET_CLAUSE_MASK
,
16767 "#pragma omp declare target");
16768 else if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
16770 clauses
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_TO_DECLARE
,
16772 clauses
= c_finish_omp_clauses (clauses
, C_ORT_OMP
);
16773 c_parser_skip_to_pragma_eol (parser
);
16777 c_parser_skip_to_pragma_eol (parser
);
16778 current_omp_declare_target_attribute
++;
16781 if (current_omp_declare_target_attribute
)
16782 error_at (loc
, "%<#pragma omp declare target%> with clauses in between "
16783 "%<#pragma omp declare target%> without clauses and "
16784 "%<#pragma omp end declare target%>");
16785 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
16787 tree t
= OMP_CLAUSE_DECL (c
), id
;
16788 tree at1
= lookup_attribute ("omp declare target", DECL_ATTRIBUTES (t
));
16789 tree at2
= lookup_attribute ("omp declare target link",
16790 DECL_ATTRIBUTES (t
));
16791 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINK
)
16793 id
= get_identifier ("omp declare target link");
16794 std::swap (at1
, at2
);
16797 id
= get_identifier ("omp declare target");
16800 error_at (OMP_CLAUSE_LOCATION (c
),
16801 "%qD specified both in declare target %<link%> and %<to%>"
16807 symtab_node
*node
= symtab_node::get (t
);
16808 DECL_ATTRIBUTES (t
) = tree_cons (id
, NULL_TREE
, DECL_ATTRIBUTES (t
));
16811 node
->offloadable
= 1;
16812 if (ENABLE_OFFLOADING
)
16814 g
->have_offload
= true;
16815 if (is_a
<varpool_node
*> (node
))
16816 vec_safe_push (offload_vars
, t
);
16824 c_parser_omp_end_declare_target (c_parser
*parser
)
16826 location_t loc
= c_parser_peek_token (parser
)->location
;
16827 c_parser_consume_pragma (parser
);
16828 if (c_parser_next_token_is (parser
, CPP_NAME
)
16829 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
16832 c_parser_consume_token (parser
);
16833 if (c_parser_next_token_is (parser
, CPP_NAME
)
16834 && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
),
16836 c_parser_consume_token (parser
);
16839 c_parser_error (parser
, "expected %<target%>");
16840 c_parser_skip_to_pragma_eol (parser
);
16846 c_parser_error (parser
, "expected %<declare%>");
16847 c_parser_skip_to_pragma_eol (parser
);
16850 c_parser_skip_to_pragma_eol (parser
);
16851 if (!current_omp_declare_target_attribute
)
16852 error_at (loc
, "%<#pragma omp end declare target%> without corresponding "
16853 "%<#pragma omp declare target%>");
16855 current_omp_declare_target_attribute
--;
16860 #pragma omp declare reduction (reduction-id : typename-list : expression) \
16861 initializer-clause[opt] new-line
16863 initializer-clause:
16864 initializer (omp_priv = initializer)
16865 initializer (function-name (argument-list)) */
16868 c_parser_omp_declare_reduction (c_parser
*parser
, enum pragma_context context
)
16870 unsigned int tokens_avail
= 0, i
;
16871 vec
<tree
> types
= vNULL
;
16872 vec
<c_token
> clauses
= vNULL
;
16873 enum tree_code reduc_code
= ERROR_MARK
;
16874 tree reduc_id
= NULL_TREE
;
16876 location_t rloc
= c_parser_peek_token (parser
)->location
;
16878 if (context
== pragma_struct
|| context
== pragma_param
)
16880 error ("%<#pragma omp declare reduction%> not at file or block scope");
16884 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
16887 switch (c_parser_peek_token (parser
)->type
)
16890 reduc_code
= PLUS_EXPR
;
16893 reduc_code
= MULT_EXPR
;
16896 reduc_code
= MINUS_EXPR
;
16899 reduc_code
= BIT_AND_EXPR
;
16902 reduc_code
= BIT_XOR_EXPR
;
16905 reduc_code
= BIT_IOR_EXPR
;
16908 reduc_code
= TRUTH_ANDIF_EXPR
;
16911 reduc_code
= TRUTH_ORIF_EXPR
;
16915 p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
16916 if (strcmp (p
, "min") == 0)
16918 reduc_code
= MIN_EXPR
;
16921 if (strcmp (p
, "max") == 0)
16923 reduc_code
= MAX_EXPR
;
16926 reduc_id
= c_parser_peek_token (parser
)->value
;
16929 c_parser_error (parser
,
16930 "expected %<+%>, %<*%>, %<-%>, %<&%>, "
16931 "%<^%>, %<|%>, %<&&%>, %<||%>, %<min%> or identifier");
16935 tree orig_reduc_id
, reduc_decl
;
16936 orig_reduc_id
= reduc_id
;
16937 reduc_id
= c_omp_reduction_id (reduc_code
, reduc_id
);
16938 reduc_decl
= c_omp_reduction_decl (reduc_id
);
16939 c_parser_consume_token (parser
);
16941 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
16946 location_t loc
= c_parser_peek_token (parser
)->location
;
16947 struct c_type_name
*ctype
= c_parser_type_name (parser
);
16950 type
= groktypename (ctype
, NULL
, NULL
);
16951 if (type
== error_mark_node
)
16953 else if ((INTEGRAL_TYPE_P (type
)
16954 || TREE_CODE (type
) == REAL_TYPE
16955 || TREE_CODE (type
) == COMPLEX_TYPE
)
16956 && orig_reduc_id
== NULL_TREE
)
16957 error_at (loc
, "predeclared arithmetic type in "
16958 "%<#pragma omp declare reduction%>");
16959 else if (TREE_CODE (type
) == FUNCTION_TYPE
16960 || TREE_CODE (type
) == ARRAY_TYPE
)
16961 error_at (loc
, "function or array type in "
16962 "%<#pragma omp declare reduction%>");
16963 else if (TYPE_ATOMIC (type
))
16964 error_at (loc
, "%<_Atomic%> qualified type in "
16965 "%<#pragma omp declare reduction%>");
16966 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
16967 error_at (loc
, "const, volatile or restrict qualified type in "
16968 "%<#pragma omp declare reduction%>");
16972 for (t
= DECL_INITIAL (reduc_decl
); t
; t
= TREE_CHAIN (t
))
16973 if (comptypes (TREE_PURPOSE (t
), type
))
16975 error_at (loc
, "redeclaration of %qs "
16976 "%<#pragma omp declare reduction%> for "
16978 IDENTIFIER_POINTER (reduc_id
)
16979 + sizeof ("omp declare reduction ") - 1,
16982 = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t
),
16984 error_at (ploc
, "previous %<#pragma omp declare "
16988 if (t
== NULL_TREE
)
16989 types
.safe_push (type
);
16991 if (c_parser_next_token_is (parser
, CPP_COMMA
))
16992 c_parser_consume_token (parser
);
17000 if (!c_parser_require (parser
, CPP_COLON
, "expected %<:%>")
17001 || types
.is_empty ())
17004 clauses
.release ();
17008 c_token
*token
= c_parser_peek_token (parser
);
17009 if (token
->type
== CPP_EOF
|| token
->type
== CPP_PRAGMA_EOL
)
17011 c_parser_consume_token (parser
);
17013 c_parser_skip_to_pragma_eol (parser
);
17017 if (types
.length () > 1)
17019 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17021 c_token
*token
= c_parser_peek_token (parser
);
17022 if (token
->type
== CPP_EOF
)
17024 clauses
.safe_push (*token
);
17025 c_parser_consume_token (parser
);
17027 clauses
.safe_push (*c_parser_peek_token (parser
));
17028 c_parser_skip_to_pragma_eol (parser
);
17030 /* Make sure nothing tries to read past the end of the tokens. */
17032 memset (&eof_token
, 0, sizeof (eof_token
));
17033 eof_token
.type
= CPP_EOF
;
17034 clauses
.safe_push (eof_token
);
17035 clauses
.safe_push (eof_token
);
17038 int errs
= errorcount
;
17039 FOR_EACH_VEC_ELT (types
, i
, type
)
17041 tokens_avail
= parser
->tokens_avail
;
17042 gcc_assert (parser
->tokens
== &parser
->tokens_buf
[0]);
17043 if (!clauses
.is_empty ())
17045 parser
->tokens
= clauses
.address ();
17046 parser
->tokens_avail
= clauses
.length ();
17047 parser
->in_pragma
= true;
17050 bool nested
= current_function_decl
!= NULL_TREE
;
17052 c_push_function_context ();
17053 tree fndecl
= build_decl (BUILTINS_LOCATION
, FUNCTION_DECL
,
17054 reduc_id
, default_function_type
);
17055 current_function_decl
= fndecl
;
17056 allocate_struct_function (fndecl
, true);
17058 tree stmt
= push_stmt_list ();
17059 /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't
17060 warn about these. */
17061 tree omp_out
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17062 get_identifier ("omp_out"), type
);
17063 DECL_ARTIFICIAL (omp_out
) = 1;
17064 DECL_CONTEXT (omp_out
) = fndecl
;
17065 pushdecl (omp_out
);
17066 tree omp_in
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17067 get_identifier ("omp_in"), type
);
17068 DECL_ARTIFICIAL (omp_in
) = 1;
17069 DECL_CONTEXT (omp_in
) = fndecl
;
17071 struct c_expr combiner
= c_parser_expression (parser
);
17072 struct c_expr initializer
;
17073 tree omp_priv
= NULL_TREE
, omp_orig
= NULL_TREE
;
17075 initializer
.value
= error_mark_node
;
17076 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17078 else if (c_parser_next_token_is (parser
, CPP_NAME
)
17079 && strcmp (IDENTIFIER_POINTER
17080 (c_parser_peek_token (parser
)->value
),
17081 "initializer") == 0)
17083 c_parser_consume_token (parser
);
17086 omp_priv
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17087 get_identifier ("omp_priv"), type
);
17088 DECL_ARTIFICIAL (omp_priv
) = 1;
17089 DECL_INITIAL (omp_priv
) = error_mark_node
;
17090 DECL_CONTEXT (omp_priv
) = fndecl
;
17091 pushdecl (omp_priv
);
17092 omp_orig
= build_decl (BUILTINS_LOCATION
, VAR_DECL
,
17093 get_identifier ("omp_orig"), type
);
17094 DECL_ARTIFICIAL (omp_orig
) = 1;
17095 DECL_CONTEXT (omp_orig
) = fndecl
;
17096 pushdecl (omp_orig
);
17097 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17099 else if (!c_parser_next_token_is (parser
, CPP_NAME
))
17101 c_parser_error (parser
, "expected %<omp_priv%> or "
17105 else if (strcmp (IDENTIFIER_POINTER
17106 (c_parser_peek_token (parser
)->value
),
17109 if (c_parser_peek_2nd_token (parser
)->type
!= CPP_OPEN_PAREN
17110 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
17112 c_parser_error (parser
, "expected function-name %<(%>");
17116 initializer
= c_parser_postfix_expression (parser
);
17117 if (initializer
.value
17118 && TREE_CODE (initializer
.value
) == CALL_EXPR
)
17121 tree c
= initializer
.value
;
17122 for (j
= 0; j
< call_expr_nargs (c
); j
++)
17124 tree a
= CALL_EXPR_ARG (c
, j
);
17126 if (TREE_CODE (a
) == ADDR_EXPR
17127 && TREE_OPERAND (a
, 0) == omp_priv
)
17130 if (j
== call_expr_nargs (c
))
17131 error ("one of the initializer call arguments should be "
17137 c_parser_consume_token (parser
);
17138 if (!c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
17142 tree st
= push_stmt_list ();
17143 start_init (omp_priv
, NULL_TREE
, 0);
17144 location_t loc
= c_parser_peek_token (parser
)->location
;
17145 struct c_expr init
= c_parser_initializer (parser
);
17147 finish_decl (omp_priv
, loc
, init
.value
,
17148 init
.original_type
, NULL_TREE
);
17149 pop_stmt_list (st
);
17153 && !c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
17159 c_parser_skip_to_pragma_eol (parser
);
17161 tree t
= tree_cons (type
, make_tree_vec (omp_priv
? 6 : 3),
17162 DECL_INITIAL (reduc_decl
));
17163 DECL_INITIAL (reduc_decl
) = t
;
17164 DECL_SOURCE_LOCATION (omp_out
) = rloc
;
17165 TREE_VEC_ELT (TREE_VALUE (t
), 0) = omp_out
;
17166 TREE_VEC_ELT (TREE_VALUE (t
), 1) = omp_in
;
17167 TREE_VEC_ELT (TREE_VALUE (t
), 2) = combiner
.value
;
17168 walk_tree (&combiner
.value
, c_check_omp_declare_reduction_r
,
17169 &TREE_VEC_ELT (TREE_VALUE (t
), 0), NULL
);
17172 DECL_SOURCE_LOCATION (omp_priv
) = rloc
;
17173 TREE_VEC_ELT (TREE_VALUE (t
), 3) = omp_priv
;
17174 TREE_VEC_ELT (TREE_VALUE (t
), 4) = omp_orig
;
17175 TREE_VEC_ELT (TREE_VALUE (t
), 5) = initializer
.value
;
17176 walk_tree (&initializer
.value
, c_check_omp_declare_reduction_r
,
17177 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17178 walk_tree (&DECL_INITIAL (omp_priv
),
17179 c_check_omp_declare_reduction_r
,
17180 &TREE_VEC_ELT (TREE_VALUE (t
), 3), NULL
);
17184 pop_stmt_list (stmt
);
17186 if (cfun
->language
!= NULL
)
17188 ggc_free (cfun
->language
);
17189 cfun
->language
= NULL
;
17192 current_function_decl
= NULL_TREE
;
17194 c_pop_function_context ();
17196 if (!clauses
.is_empty ())
17198 parser
->tokens
= &parser
->tokens_buf
[0];
17199 parser
->tokens_avail
= tokens_avail
;
17203 if (errs
!= errorcount
)
17207 clauses
.release ();
17213 #pragma omp declare simd declare-simd-clauses[optseq] new-line
17214 #pragma omp declare reduction (reduction-id : typename-list : expression) \
17215 initializer-clause[opt] new-line
17216 #pragma omp declare target new-line */
17219 c_parser_omp_declare (c_parser
*parser
, enum pragma_context context
)
17221 c_parser_consume_pragma (parser
);
17222 if (c_parser_next_token_is (parser
, CPP_NAME
))
17224 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17225 if (strcmp (p
, "simd") == 0)
17227 /* c_parser_consume_token (parser); done in
17228 c_parser_omp_declare_simd. */
17229 c_parser_omp_declare_simd (parser
, context
);
17232 if (strcmp (p
, "reduction") == 0)
17234 c_parser_consume_token (parser
);
17235 c_parser_omp_declare_reduction (parser
, context
);
17238 if (!flag_openmp
) /* flag_openmp_simd */
17240 c_parser_skip_to_pragma_eol (parser
, false);
17243 if (strcmp (p
, "target") == 0)
17245 c_parser_consume_token (parser
);
17246 c_parser_omp_declare_target (parser
);
17251 c_parser_error (parser
, "expected %<simd%> or %<reduction%> "
17253 c_parser_skip_to_pragma_eol (parser
);
17257 #pragma omp taskloop taskloop-clause[optseq] new-line
17260 #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line
17263 #define OMP_TASKLOOP_CLAUSE_MASK \
17264 ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \
17265 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \
17266 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \
17267 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \
17268 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \
17269 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \
17270 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \
17271 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \
17272 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \
17273 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \
17274 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \
17275 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \
17276 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \
17277 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY))
17280 c_parser_omp_taskloop (location_t loc
, c_parser
*parser
,
17281 char *p_name
, omp_clause_mask mask
, tree
*cclauses
,
17284 tree clauses
, block
, ret
;
17286 strcat (p_name
, " taskloop");
17287 mask
|= OMP_TASKLOOP_CLAUSE_MASK
;
17289 if (c_parser_next_token_is (parser
, CPP_NAME
))
17291 const char *p
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
17293 if (strcmp (p
, "simd") == 0)
17295 tree cclauses_buf
[C_OMP_CLAUSE_SPLIT_COUNT
];
17296 if (cclauses
== NULL
)
17297 cclauses
= cclauses_buf
;
17298 mask
&= ~(OMP_CLAUSE_MASK_1
<< PRAGMA_OMP_CLAUSE_REDUCTION
);
17299 c_parser_consume_token (parser
);
17300 if (!flag_openmp
) /* flag_openmp_simd */
17301 return c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
,
17303 block
= c_begin_compound_stmt (true);
17304 ret
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, cclauses
, if_p
);
17305 block
= c_end_compound_stmt (loc
, block
, true);
17308 ret
= make_node (OMP_TASKLOOP
);
17309 TREE_TYPE (ret
) = void_type_node
;
17310 OMP_FOR_BODY (ret
) = block
;
17311 OMP_FOR_CLAUSES (ret
) = cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
17312 SET_EXPR_LOCATION (ret
, loc
);
17317 if (!flag_openmp
) /* flag_openmp_simd */
17319 c_parser_skip_to_pragma_eol (parser
, false);
17323 clauses
= c_parser_omp_all_clauses (parser
, mask
, p_name
, cclauses
== NULL
);
17326 omp_split_clauses (loc
, OMP_TASKLOOP
, mask
, clauses
, cclauses
);
17327 clauses
= cclauses
[C_OMP_CLAUSE_SPLIT_TASKLOOP
];
17330 block
= c_begin_compound_stmt (true);
17331 ret
= c_parser_omp_for_loop (loc
, parser
, OMP_TASKLOOP
, clauses
, NULL
, if_p
);
17332 block
= c_end_compound_stmt (loc
, block
, true);
17338 /* Main entry point to parsing most OpenMP pragmas. */
17341 c_parser_omp_construct (c_parser
*parser
, bool *if_p
)
17343 enum pragma_kind p_kind
;
17346 char p_name
[sizeof "#pragma omp teams distribute parallel for simd"];
17347 omp_clause_mask
mask (0);
17349 loc
= c_parser_peek_token (parser
)->location
;
17350 p_kind
= c_parser_peek_token (parser
)->pragma_kind
;
17351 c_parser_consume_pragma (parser
);
17355 case PRAGMA_OACC_ATOMIC
:
17356 c_parser_omp_atomic (loc
, parser
);
17358 case PRAGMA_OACC_CACHE
:
17359 strcpy (p_name
, "#pragma acc");
17360 stmt
= c_parser_oacc_cache (loc
, parser
);
17362 case PRAGMA_OACC_DATA
:
17363 stmt
= c_parser_oacc_data (loc
, parser
, if_p
);
17365 case PRAGMA_OACC_HOST_DATA
:
17366 stmt
= c_parser_oacc_host_data (loc
, parser
, if_p
);
17368 case PRAGMA_OACC_KERNELS
:
17369 case PRAGMA_OACC_PARALLEL
:
17370 strcpy (p_name
, "#pragma acc");
17371 stmt
= c_parser_oacc_kernels_parallel (loc
, parser
, p_kind
, p_name
,
17374 case PRAGMA_OACC_LOOP
:
17375 strcpy (p_name
, "#pragma acc");
17376 stmt
= c_parser_oacc_loop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17378 case PRAGMA_OACC_WAIT
:
17379 strcpy (p_name
, "#pragma wait");
17380 stmt
= c_parser_oacc_wait (loc
, parser
, p_name
);
17382 case PRAGMA_OMP_ATOMIC
:
17383 c_parser_omp_atomic (loc
, parser
);
17385 case PRAGMA_OMP_CRITICAL
:
17386 stmt
= c_parser_omp_critical (loc
, parser
, if_p
);
17388 case PRAGMA_OMP_DISTRIBUTE
:
17389 strcpy (p_name
, "#pragma omp");
17390 stmt
= c_parser_omp_distribute (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17392 case PRAGMA_OMP_FOR
:
17393 strcpy (p_name
, "#pragma omp");
17394 stmt
= c_parser_omp_for (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17396 case PRAGMA_OMP_MASTER
:
17397 stmt
= c_parser_omp_master (loc
, parser
, if_p
);
17399 case PRAGMA_OMP_PARALLEL
:
17400 strcpy (p_name
, "#pragma omp");
17401 stmt
= c_parser_omp_parallel (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17403 case PRAGMA_OMP_SECTIONS
:
17404 strcpy (p_name
, "#pragma omp");
17405 stmt
= c_parser_omp_sections (loc
, parser
, p_name
, mask
, NULL
);
17407 case PRAGMA_OMP_SIMD
:
17408 strcpy (p_name
, "#pragma omp");
17409 stmt
= c_parser_omp_simd (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17411 case PRAGMA_OMP_SINGLE
:
17412 stmt
= c_parser_omp_single (loc
, parser
, if_p
);
17414 case PRAGMA_OMP_TASK
:
17415 stmt
= c_parser_omp_task (loc
, parser
, if_p
);
17417 case PRAGMA_OMP_TASKGROUP
:
17418 stmt
= c_parser_omp_taskgroup (parser
, if_p
);
17420 case PRAGMA_OMP_TASKLOOP
:
17421 strcpy (p_name
, "#pragma omp");
17422 stmt
= c_parser_omp_taskloop (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17424 case PRAGMA_OMP_TEAMS
:
17425 strcpy (p_name
, "#pragma omp");
17426 stmt
= c_parser_omp_teams (loc
, parser
, p_name
, mask
, NULL
, if_p
);
17429 gcc_unreachable ();
17433 gcc_assert (EXPR_LOCATION (stmt
) != UNKNOWN_LOCATION
);
17438 # pragma omp threadprivate (variable-list) */
17441 c_parser_omp_threadprivate (c_parser
*parser
)
17446 c_parser_consume_pragma (parser
);
17447 loc
= c_parser_peek_token (parser
)->location
;
17448 vars
= c_parser_omp_var_list_parens (parser
, OMP_CLAUSE_ERROR
, NULL
);
17450 /* Mark every variable in VARS to be assigned thread local storage. */
17451 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
17453 tree v
= TREE_PURPOSE (t
);
17455 /* FIXME diagnostics: Ideally we should keep individual
17456 locations for all the variables in the var list to make the
17457 following errors more precise. Perhaps
17458 c_parser_omp_var_list_parens() should construct a list of
17459 locations to go along with the var list. */
17461 /* If V had already been marked threadprivate, it doesn't matter
17462 whether it had been used prior to this point. */
17464 error_at (loc
, "%qD is not a variable", v
);
17465 else if (TREE_USED (v
) && !C_DECL_THREADPRIVATE_P (v
))
17466 error_at (loc
, "%qE declared %<threadprivate%> after first use", v
);
17467 else if (! is_global_var (v
))
17468 error_at (loc
, "automatic variable %qE cannot be %<threadprivate%>", v
);
17469 else if (TREE_TYPE (v
) == error_mark_node
)
17471 else if (! COMPLETE_TYPE_P (TREE_TYPE (v
)))
17472 error_at (loc
, "%<threadprivate%> %qE has incomplete type", v
);
17475 if (! DECL_THREAD_LOCAL_P (v
))
17477 set_decl_tls_model (v
, decl_default_tls_model (v
));
17478 /* If rtl has been already set for this var, call
17479 make_decl_rtl once again, so that encode_section_info
17480 has a chance to look at the new decl flags. */
17481 if (DECL_RTL_SET_P (v
))
17484 C_DECL_THREADPRIVATE_P (v
) = 1;
17488 c_parser_skip_to_pragma_eol (parser
);
17491 /* Cilk Plus <#pragma simd> parsing routines. */
17493 /* Helper function for c_parser_pragma. Perform some sanity checking
17494 for <#pragma simd> constructs. Returns FALSE if there was a
17498 c_parser_cilk_verify_simd (c_parser
*parser
,
17499 enum pragma_context context
)
17501 if (!flag_cilkplus
)
17503 warning (0, "pragma simd ignored because -fcilkplus is not enabled");
17504 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
17507 if (context
== pragma_external
)
17509 c_parser_error (parser
,"pragma simd must be inside a function");
17510 c_parser_skip_until_found (parser
, CPP_PRAGMA_EOL
, NULL
);
17517 This function is shared by SIMD-enabled functions and #pragma simd.
17518 If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and
17519 CLAUSES is unused. The main purpose of this function is to parse a
17520 vectorlength attribute or clause and check for parse errors.
17521 When IS_SIMD_FN is true then the function is merely caching the tokens
17522 in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token
17523 cache is cleared since there is no reason to continue.
17525 vectorlength ( constant-expression ) */
17528 c_parser_cilk_clause_vectorlength (c_parser
*parser
, tree clauses
,
17532 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SIMDLEN
, "vectorlength");
17534 /* The vectorlength clause behaves exactly like OpenMP's safelen
17535 clause. Represent it in OpenMP terms. */
17536 check_no_duplicate_clause (clauses
, OMP_CLAUSE_SAFELEN
, "vectorlength");
17538 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17541 location_t loc
= c_parser_peek_token (parser
)->location
;
17542 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
17543 expr
= c_fully_fold (expr
, false, NULL
);
17545 /* If expr is an error_mark_node then the above function would have
17546 emitted an error. No reason to do it twice. */
17547 if (expr
== error_mark_node
)
17549 else if (!TREE_TYPE (expr
)
17550 || !TREE_CONSTANT (expr
)
17551 || !INTEGRAL_TYPE_P (TREE_TYPE (expr
)))
17553 error_at (loc
, "vectorlength must be an integer constant");
17554 else if (wi::exact_log2 (expr
) == -1)
17555 error_at (loc
, "vectorlength must be a power of 2");
17560 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SIMDLEN
);
17561 OMP_CLAUSE_SIMDLEN_EXPR (u
) = expr
;
17562 OMP_CLAUSE_CHAIN (u
) = clauses
;
17567 tree u
= build_omp_clause (loc
, OMP_CLAUSE_SAFELEN
);
17568 OMP_CLAUSE_SAFELEN_EXPR (u
) = expr
;
17569 OMP_CLAUSE_CHAIN (u
) = clauses
;
17574 c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
17580 linear ( simd-linear-variable-list )
17582 simd-linear-variable-list:
17583 simd-linear-variable
17584 simd-linear-variable-list , simd-linear-variable
17586 simd-linear-variable:
17588 id-expression : simd-linear-step
17591 conditional-expression */
17594 c_parser_cilk_clause_linear (c_parser
*parser
, tree clauses
)
17596 if (!c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
17599 location_t loc
= c_parser_peek_token (parser
)->location
;
17601 if (c_parser_next_token_is_not (parser
, CPP_NAME
)
17602 || c_parser_peek_token (parser
)->id_kind
!= C_ID_ID
)
17603 c_parser_error (parser
, "expected identifier");
17605 while (c_parser_next_token_is (parser
, CPP_NAME
)
17606 && c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
17608 tree var
= lookup_name (c_parser_peek_token (parser
)->value
);
17612 undeclared_variable (c_parser_peek_token (parser
)->location
,
17613 c_parser_peek_token (parser
)->value
);
17614 c_parser_consume_token (parser
);
17616 else if (var
== error_mark_node
)
17617 c_parser_consume_token (parser
);
17620 tree step
= integer_one_node
;
17622 /* Parse the linear step if present. */
17623 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
17625 c_parser_consume_token (parser
);
17626 c_parser_consume_token (parser
);
17628 tree expr
= c_parser_expr_no_commas (parser
, NULL
).value
;
17629 expr
= c_fully_fold (expr
, false, NULL
);
17631 if (TREE_TYPE (expr
)
17632 && INTEGRAL_TYPE_P (TREE_TYPE (expr
))
17633 && (TREE_CONSTANT (expr
)
17637 c_parser_error (parser
,
17638 "step size must be an integer constant "
17639 "expression or an integer variable");
17642 c_parser_consume_token (parser
);
17644 /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */
17645 tree u
= build_omp_clause (loc
, OMP_CLAUSE_LINEAR
);
17646 OMP_CLAUSE_DECL (u
) = var
;
17647 OMP_CLAUSE_LINEAR_STEP (u
) = step
;
17648 OMP_CLAUSE_CHAIN (u
) = clauses
;
17652 if (c_parser_next_token_is_not (parser
, CPP_COMMA
))
17655 c_parser_consume_token (parser
);
17658 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
17663 /* Returns the name of the next clause. If the clause is not
17664 recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is
17665 not consumed. Otherwise, the appropriate pragma_simd_clause is
17666 returned and the token is consumed. */
17668 static pragma_omp_clause
17669 c_parser_cilk_clause_name (c_parser
*parser
)
17671 pragma_omp_clause result
;
17672 c_token
*token
= c_parser_peek_token (parser
);
17674 if (!token
->value
|| token
->type
!= CPP_NAME
)
17675 return PRAGMA_CILK_CLAUSE_NONE
;
17677 const char *p
= IDENTIFIER_POINTER (token
->value
);
17679 if (!strcmp (p
, "vectorlength"))
17680 result
= PRAGMA_CILK_CLAUSE_VECTORLENGTH
;
17681 else if (!strcmp (p
, "linear"))
17682 result
= PRAGMA_CILK_CLAUSE_LINEAR
;
17683 else if (!strcmp (p
, "private"))
17684 result
= PRAGMA_CILK_CLAUSE_PRIVATE
;
17685 else if (!strcmp (p
, "firstprivate"))
17686 result
= PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
;
17687 else if (!strcmp (p
, "lastprivate"))
17688 result
= PRAGMA_CILK_CLAUSE_LASTPRIVATE
;
17689 else if (!strcmp (p
, "reduction"))
17690 result
= PRAGMA_CILK_CLAUSE_REDUCTION
;
17692 return PRAGMA_CILK_CLAUSE_NONE
;
17694 c_parser_consume_token (parser
);
17698 /* Parse all #<pragma simd> clauses. Return the list of clauses
17702 c_parser_cilk_all_clauses (c_parser
*parser
)
17704 tree clauses
= NULL
;
17706 while (c_parser_next_token_is_not (parser
, CPP_PRAGMA_EOL
))
17708 pragma_omp_clause c_kind
;
17710 c_kind
= c_parser_cilk_clause_name (parser
);
17714 case PRAGMA_CILK_CLAUSE_VECTORLENGTH
:
17715 clauses
= c_parser_cilk_clause_vectorlength (parser
, clauses
, false);
17717 case PRAGMA_CILK_CLAUSE_LINEAR
:
17718 clauses
= c_parser_cilk_clause_linear (parser
, clauses
);
17720 case PRAGMA_CILK_CLAUSE_PRIVATE
:
17721 /* Use the OpenMP counterpart. */
17722 clauses
= c_parser_omp_clause_private (parser
, clauses
);
17724 case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE
:
17725 /* Use the OpenMP counterpart. */
17726 clauses
= c_parser_omp_clause_firstprivate (parser
, clauses
);
17728 case PRAGMA_CILK_CLAUSE_LASTPRIVATE
:
17729 /* Use the OpenMP counterpart. */
17730 clauses
= c_parser_omp_clause_lastprivate (parser
, clauses
);
17732 case PRAGMA_CILK_CLAUSE_REDUCTION
:
17733 /* Use the OpenMP counterpart. */
17734 clauses
= c_parser_omp_clause_reduction (parser
, clauses
);
17737 c_parser_error (parser
, "expected %<#pragma simd%> clause");
17743 c_parser_skip_to_pragma_eol (parser
);
17744 return c_finish_omp_clauses (clauses
, C_ORT_CILK
);
17747 /* This function helps parse the grainsize pragma for a _Cilk_for statement.
17748 Here is the correct syntax of this pragma:
17749 #pragma cilk grainsize = <EXP>
17753 c_parser_cilk_grainsize (c_parser
*parser
, bool *if_p
)
17755 extern tree
convert_to_integer (tree
, tree
);
17757 /* consume the 'grainsize' keyword. */
17758 c_parser_consume_pragma (parser
);
17760 if (c_parser_require (parser
, CPP_EQ
, "expected %<=%>") != 0)
17762 struct c_expr g_expr
= c_parser_binary_expression (parser
, NULL
, NULL
);
17763 if (g_expr
.value
== error_mark_node
)
17765 c_parser_skip_to_pragma_eol (parser
);
17768 tree grain
= convert_to_integer (long_integer_type_node
,
17769 c_fully_fold (g_expr
.value
, false,
17771 c_parser_skip_to_pragma_eol (parser
);
17772 c_token
*token
= c_parser_peek_token (parser
);
17773 if (token
&& token
->type
== CPP_KEYWORD
17774 && token
->keyword
== RID_CILK_FOR
)
17776 if (grain
== NULL_TREE
|| grain
== error_mark_node
)
17777 grain
= integer_zero_node
;
17778 c_parser_cilk_for (parser
, grain
, if_p
);
17781 warning (0, "%<#pragma cilk grainsize%> is not followed by "
17785 c_parser_skip_to_pragma_eol (parser
);
17788 /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */
17791 c_parser_cilk_simd (c_parser
*parser
, bool *if_p
)
17793 tree clauses
= c_parser_cilk_all_clauses (parser
);
17794 tree block
= c_begin_compound_stmt (true);
17795 location_t loc
= c_parser_peek_token (parser
)->location
;
17796 c_parser_omp_for_loop (loc
, parser
, CILK_SIMD
, clauses
, NULL
, if_p
);
17797 block
= c_end_compound_stmt (loc
, block
, true);
17801 /* Create an artificial decl with TYPE and emit initialization of it with
17805 c_get_temp_regvar (tree type
, tree init
)
17807 location_t loc
= EXPR_LOCATION (init
);
17808 tree decl
= build_decl (loc
, VAR_DECL
, NULL_TREE
, type
);
17809 DECL_ARTIFICIAL (decl
) = 1;
17810 DECL_IGNORED_P (decl
) = 1;
17812 tree t
= build2 (INIT_EXPR
, type
, decl
, init
);
17817 /* Main entry point for parsing Cilk Plus _Cilk_for loops.
17818 GRAIN is the grain value passed in through pragma or 0. */
17821 c_parser_cilk_for (c_parser
*parser
, tree grain
, bool *if_p
)
17823 tree clauses
= build_omp_clause (EXPR_LOCATION (grain
), OMP_CLAUSE_SCHEDULE
);
17824 OMP_CLAUSE_SCHEDULE_KIND (clauses
) = OMP_CLAUSE_SCHEDULE_CILKFOR
;
17825 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses
) = grain
;
17826 clauses
= c_finish_omp_clauses (clauses
, C_ORT_CILK
);
17828 tree block
= c_begin_compound_stmt (true);
17829 tree sb
= push_stmt_list ();
17830 location_t loc
= c_parser_peek_token (parser
)->location
;
17831 tree omp_for
= c_parser_omp_for_loop (loc
, parser
, CILK_FOR
, clauses
, NULL
,
17833 sb
= pop_stmt_list (sb
);
17837 tree omp_par
= make_node (OMP_PARALLEL
);
17838 TREE_TYPE (omp_par
) = void_type_node
;
17839 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
17840 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
17841 TREE_SIDE_EFFECTS (bind
) = 1;
17842 BIND_EXPR_BODY (bind
) = sb
;
17843 OMP_PARALLEL_BODY (omp_par
) = bind
;
17844 if (OMP_FOR_PRE_BODY (omp_for
))
17846 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
17847 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
17849 tree init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
17850 tree decl
= TREE_OPERAND (init
, 0);
17851 tree cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
17852 tree incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
17853 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
= NULL_TREE
;
17854 if (TREE_CODE (t
) != INTEGER_CST
)
17856 TREE_OPERAND (cond
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
17857 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
17858 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
17859 OMP_CLAUSE_CHAIN (c
) = clauses
;
17862 if (TREE_CODE (incr
) == MODIFY_EXPR
)
17864 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
17865 if (TREE_CODE (t
) != INTEGER_CST
)
17867 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
17868 = c_get_temp_regvar (TREE_TYPE (t
), t
);
17869 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
17870 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
17871 OMP_CLAUSE_CHAIN (c
) = clauses
;
17875 t
= TREE_OPERAND (init
, 1);
17876 if (TREE_CODE (t
) != INTEGER_CST
)
17878 TREE_OPERAND (init
, 1) = c_get_temp_regvar (TREE_TYPE (t
), t
);
17879 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
17880 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
17881 OMP_CLAUSE_CHAIN (c
) = clauses
;
17884 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
17885 OMP_CLAUSE_DECL (c
) = decl
;
17886 OMP_CLAUSE_CHAIN (c
) = clauses
;
17888 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
17889 OMP_CLAUSE_OPERAND (c
, 0)
17890 = cilk_for_number_of_iterations (omp_for
);
17891 OMP_CLAUSE_CHAIN (c
) = clauses
;
17892 OMP_PARALLEL_CLAUSES (omp_par
) = c_finish_omp_clauses (c
, C_ORT_CILK
);
17893 add_stmt (omp_par
);
17896 block
= c_end_compound_stmt (loc
, block
, true);
17901 /* Parse a transaction attribute (GCC Extension).
17903 transaction-attribute:
17907 The transactional memory language description is written for C++,
17908 and uses the C++0x attribute syntax. For compatibility, allow the
17909 bracket style for transactions in C as well. */
17912 c_parser_transaction_attributes (c_parser
*parser
)
17914 tree attr_name
, attr
= NULL
;
17916 if (c_parser_next_token_is_keyword (parser
, RID_ATTRIBUTE
))
17917 return c_parser_attributes (parser
);
17919 if (!c_parser_next_token_is (parser
, CPP_OPEN_SQUARE
))
17921 c_parser_consume_token (parser
);
17922 if (!c_parser_require (parser
, CPP_OPEN_SQUARE
, "expected %<[%>"))
17925 attr_name
= c_parser_attribute_any_word (parser
);
17928 c_parser_consume_token (parser
);
17929 attr
= build_tree_list (attr_name
, NULL_TREE
);
17932 c_parser_error (parser
, "expected identifier");
17934 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
17936 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
17940 /* Parse a __transaction_atomic or __transaction_relaxed statement
17943 transaction-statement:
17944 __transaction_atomic transaction-attribute[opt] compound-statement
17945 __transaction_relaxed compound-statement
17947 Note that the only valid attribute is: "outer".
17951 c_parser_transaction (c_parser
*parser
, enum rid keyword
)
17953 unsigned int old_in
= parser
->in_transaction
;
17954 unsigned int this_in
= 1, new_in
;
17955 location_t loc
= c_parser_peek_token (parser
)->location
;
17958 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
17959 || keyword
== RID_TRANSACTION_RELAXED
)
17960 && c_parser_next_token_is_keyword (parser
, keyword
));
17961 c_parser_consume_token (parser
);
17963 if (keyword
== RID_TRANSACTION_RELAXED
)
17964 this_in
|= TM_STMT_ATTR_RELAXED
;
17967 attrs
= c_parser_transaction_attributes (parser
);
17969 this_in
|= parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
);
17972 /* Keep track if we're in the lexical scope of an outer transaction. */
17973 new_in
= this_in
| (old_in
& TM_STMT_ATTR_OUTER
);
17975 parser
->in_transaction
= new_in
;
17976 stmt
= c_parser_compound_statement (parser
);
17977 parser
->in_transaction
= old_in
;
17980 stmt
= c_finish_transaction (loc
, stmt
, this_in
);
17982 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
17983 "%<__transaction_atomic%> without transactional memory support enabled"
17984 : "%<__transaction_relaxed %> "
17985 "without transactional memory support enabled"));
17990 /* Parse a __transaction_atomic or __transaction_relaxed expression
17993 transaction-expression:
17994 __transaction_atomic ( expression )
17995 __transaction_relaxed ( expression )
17998 static struct c_expr
17999 c_parser_transaction_expression (c_parser
*parser
, enum rid keyword
)
18002 unsigned int old_in
= parser
->in_transaction
;
18003 unsigned int this_in
= 1;
18004 location_t loc
= c_parser_peek_token (parser
)->location
;
18007 gcc_assert ((keyword
== RID_TRANSACTION_ATOMIC
18008 || keyword
== RID_TRANSACTION_RELAXED
)
18009 && c_parser_next_token_is_keyword (parser
, keyword
));
18010 c_parser_consume_token (parser
);
18012 if (keyword
== RID_TRANSACTION_RELAXED
)
18013 this_in
|= TM_STMT_ATTR_RELAXED
;
18016 attrs
= c_parser_transaction_attributes (parser
);
18018 this_in
|= parse_tm_stmt_attr (attrs
, 0);
18021 parser
->in_transaction
= this_in
;
18022 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
18024 tree expr
= c_parser_expression (parser
).value
;
18025 ret
.original_type
= TREE_TYPE (expr
);
18026 ret
.value
= build1 (TRANSACTION_EXPR
, ret
.original_type
, expr
);
18027 if (this_in
& TM_STMT_ATTR_RELAXED
)
18028 TRANSACTION_EXPR_RELAXED (ret
.value
) = 1;
18029 SET_EXPR_LOCATION (ret
.value
, loc
);
18030 ret
.original_code
= TRANSACTION_EXPR
;
18031 if (!c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
18033 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, NULL
);
18040 ret
.value
= error_mark_node
;
18041 ret
.original_code
= ERROR_MARK
;
18042 ret
.original_type
= NULL
;
18044 parser
->in_transaction
= old_in
;
18047 error_at (loc
, (keyword
== RID_TRANSACTION_ATOMIC
?
18048 "%<__transaction_atomic%> without transactional memory support enabled"
18049 : "%<__transaction_relaxed %> "
18050 "without transactional memory support enabled"));
18052 set_c_expr_source_range (&ret
, loc
, loc
);
18057 /* Parse a __transaction_cancel statement (GCC Extension).
18059 transaction-cancel-statement:
18060 __transaction_cancel transaction-attribute[opt] ;
18062 Note that the only valid attribute is "outer".
18066 c_parser_transaction_cancel (c_parser
*parser
)
18068 location_t loc
= c_parser_peek_token (parser
)->location
;
18070 bool is_outer
= false;
18072 gcc_assert (c_parser_next_token_is_keyword (parser
, RID_TRANSACTION_CANCEL
));
18073 c_parser_consume_token (parser
);
18075 attrs
= c_parser_transaction_attributes (parser
);
18077 is_outer
= (parse_tm_stmt_attr (attrs
, TM_STMT_ATTR_OUTER
) != 0);
18081 error_at (loc
, "%<__transaction_cancel%> without "
18082 "transactional memory support enabled");
18085 else if (parser
->in_transaction
& TM_STMT_ATTR_RELAXED
)
18087 error_at (loc
, "%<__transaction_cancel%> within a "
18088 "%<__transaction_relaxed%>");
18093 if ((parser
->in_transaction
& TM_STMT_ATTR_OUTER
) == 0
18094 && !is_tm_may_cancel_outer (current_function_decl
))
18096 error_at (loc
, "outer %<__transaction_cancel%> not "
18097 "within outer %<__transaction_atomic%>");
18098 error_at (loc
, " or a %<transaction_may_cancel_outer%> function");
18102 else if (parser
->in_transaction
== 0)
18104 error_at (loc
, "%<__transaction_cancel%> not within "
18105 "%<__transaction_atomic%>");
18109 return add_stmt (build_tm_abort_call (loc
, is_outer
));
18112 return build1 (NOP_EXPR
, void_type_node
, error_mark_node
);
18115 /* Parse a single source file. */
18118 c_parse_file (void)
18120 /* Use local storage to begin. If the first token is a pragma, parse it.
18121 If it is #pragma GCC pch_preprocess, then this will load a PCH file
18122 which will cause garbage collection. */
18125 memset (&tparser
, 0, sizeof tparser
);
18126 tparser
.tokens
= &tparser
.tokens_buf
[0];
18127 the_parser
= &tparser
;
18129 if (c_parser_peek_token (&tparser
)->pragma_kind
== PRAGMA_GCC_PCH_PREPROCESS
)
18130 c_parser_pragma_pch_preprocess (&tparser
);
18132 the_parser
= ggc_alloc
<c_parser
> ();
18133 *the_parser
= tparser
;
18134 if (tparser
.tokens
== &tparser
.tokens_buf
[0])
18135 the_parser
->tokens
= &the_parser
->tokens_buf
[0];
18137 /* Initialize EH, if we've been told to do so. */
18138 if (flag_exceptions
)
18139 using_eh_for_cleanups ();
18141 c_parser_translation_unit (the_parser
);
18145 /* This function parses Cilk Plus array notation. The starting index is
18146 passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The
18147 return value of this function is a tree_node called VALUE_TREE of type
18148 ARRAY_NOTATION_REF. */
18151 c_parser_array_notation (location_t loc
, c_parser
*parser
, tree initial_index
,
18154 c_token
*token
= NULL
;
18155 tree start_index
= NULL_TREE
, end_index
= NULL_TREE
, stride
= NULL_TREE
;
18156 tree value_tree
= NULL_TREE
, type
= NULL_TREE
, array_type
= NULL_TREE
;
18157 tree array_type_domain
= NULL_TREE
;
18159 if (array_value
== error_mark_node
|| initial_index
== error_mark_node
)
18161 /* No need to continue. If either of these 2 were true, then an error
18162 must be emitted already. Thus, no need to emit them twice. */
18163 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18164 return error_mark_node
;
18167 array_type
= TREE_TYPE (array_value
);
18168 gcc_assert (array_type
);
18169 if (TREE_CODE (array_type
) != ARRAY_TYPE
18170 && TREE_CODE (array_type
) != POINTER_TYPE
)
18172 error_at (loc
, "base of array section must be pointer or array type");
18173 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18174 return error_mark_node
;
18176 type
= TREE_TYPE (array_type
);
18177 token
= c_parser_peek_token (parser
);
18179 if (token
->type
== CPP_EOF
)
18181 c_parser_error (parser
, "expected %<:%> or numeral");
18184 else if (token
->type
== CPP_COLON
)
18186 if (!initial_index
)
18188 /* If we are here, then we have a case like this A[:]. */
18189 c_parser_consume_token (parser
);
18190 if (TREE_CODE (array_type
) == POINTER_TYPE
)
18192 error_at (loc
, "start-index and length fields necessary for "
18193 "using array notations in pointers");
18194 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18195 return error_mark_node
;
18197 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
18199 error_at (loc
, "array notations cannot be used with function "
18201 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18202 return error_mark_node
;
18204 array_type_domain
= TYPE_DOMAIN (array_type
);
18206 if (!array_type_domain
)
18208 error_at (loc
, "start-index and length fields necessary for "
18209 "using array notations in dimensionless arrays");
18210 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18211 return error_mark_node
;
18214 start_index
= TYPE_MINVAL (array_type_domain
);
18215 start_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
,
18217 if (!TYPE_MAXVAL (array_type_domain
)
18218 || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain
)))
18220 error_at (loc
, "start-index and length fields necessary for "
18221 "using array notations in variable-length arrays");
18222 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18223 return error_mark_node
;
18225 end_index
= TYPE_MAXVAL (array_type_domain
);
18226 end_index
= fold_build2 (PLUS_EXPR
, TREE_TYPE (end_index
),
18227 end_index
, integer_one_node
);
18228 end_index
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, end_index
);
18229 stride
= build_int_cst (integer_type_node
, 1);
18230 stride
= fold_build1 (CONVERT_EXPR
, ptrdiff_type_node
, stride
);
18232 else if (initial_index
!= error_mark_node
)
18234 /* If we are here, then there should be 2 possibilities:
18235 1. Array [EXPR : EXPR]
18236 2. Array [EXPR : EXPR : EXPR]
18238 start_index
= initial_index
;
18240 if (TREE_CODE (array_type
) == FUNCTION_TYPE
)
18242 error_at (loc
, "array notations cannot be used with function "
18244 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
18245 return error_mark_node
;
18247 c_parser_consume_token (parser
); /* consume the ':' */
18248 struct c_expr ce
= c_parser_expression (parser
);
18249 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
18250 end_index
= ce
.value
;
18251 if (!end_index
|| end_index
== error_mark_node
)
18253 c_parser_skip_to_end_of_block_or_statement (parser
);
18254 return error_mark_node
;
18256 if (c_parser_peek_token (parser
)->type
== CPP_COLON
)
18258 c_parser_consume_token (parser
);
18259 ce
= c_parser_expression (parser
);
18260 ce
= convert_lvalue_to_rvalue (loc
, ce
, false, false);
18262 if (!stride
|| stride
== error_mark_node
)
18264 c_parser_skip_to_end_of_block_or_statement (parser
);
18265 return error_mark_node
;
18270 c_parser_error (parser
, "expected array notation expression");
18273 c_parser_error (parser
, "expected array notation expression");
18275 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>");
18277 value_tree
= build_array_notation_ref (loc
, array_value
, start_index
,
18278 end_index
, stride
, type
);
18279 if (value_tree
!= error_mark_node
)
18280 SET_EXPR_LOCATION (value_tree
, loc
);
18284 #include "gt-c-c-parser.h"