2 Copyright (C) 2016-2017 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
27 #include "stringpool.h"
30 #include "stor-layout.h"
32 #include "trans-mem.h"
33 #include "c-family/c-pragma.h"
35 #include "c-family/c-objc.h"
38 #include "gomp-constants.h"
39 #include "c-family/c-indentation.h"
40 #include "gimple-expr.h"
42 #include "gcc-rich-location.h"
45 #include "tree-pass.h"
46 #include "tree-pretty-print.h"
48 #include "basic-block.h"
50 #include "gimple-pretty-print.h"
52 #include "pass_manager.h"
53 #include "tree-ssanames.h"
54 #include "gimple-ssa.h"
56 #include "tree-dump.h"
59 /* Gimple parsing functions. */
60 static bool c_parser_gimple_compound_statement (c_parser
*, gimple_seq
*);
61 static void c_parser_gimple_label (c_parser
*, gimple_seq
*);
62 static void c_parser_gimple_statement (c_parser
*, gimple_seq
*);
63 static struct c_expr
c_parser_gimple_binary_expression (c_parser
*);
64 static struct c_expr
c_parser_gimple_unary_expression (c_parser
*);
65 static struct c_expr
c_parser_gimple_postfix_expression (c_parser
*);
66 static struct c_expr
c_parser_gimple_postfix_expression_after_primary (c_parser
*,
69 static void c_parser_gimple_declaration (c_parser
*);
70 static void c_parser_gimple_goto_stmt (location_t
, tree
, gimple_seq
*);
71 static void c_parser_gimple_if_stmt (c_parser
*, gimple_seq
*);
72 static void c_parser_gimple_switch_stmt (c_parser
*, gimple_seq
*);
73 static void c_parser_gimple_return_stmt (c_parser
*, gimple_seq
*);
74 static void c_finish_gimple_return (location_t
, tree
);
75 static tree
c_parser_gimple_paren_condition (c_parser
*);
76 static void c_parser_gimple_expr_list (c_parser
*, vec
<tree
> *);
79 /* Parse the body of a function declaration marked with "__GIMPLE". */
82 c_parser_parse_gimple_body (c_parser
*parser
)
84 gimple_seq seq
= NULL
;
85 gimple_seq body
= NULL
;
86 tree stmt
= push_stmt_list ();
88 location_t loc1
= c_parser_peek_token (parser
)->location
;
92 if (! c_parser_gimple_compound_statement (parser
, &seq
))
94 gimple
*ret
= gimple_build_return (NULL
);
95 gimple_seq_add_stmt (&seq
, ret
);
98 tree block
= pop_scope ();
99 stmt
= pop_stmt_list (stmt
);
100 stmt
= c_build_bind_expr (loc1
, block
, stmt
);
102 block
= DECL_INITIAL (current_function_decl
);
103 BLOCK_SUBBLOCKS (block
) = NULL_TREE
;
104 BLOCK_CHAIN (block
) = NULL_TREE
;
105 TREE_ASM_WRITTEN (block
) = 1;
107 gbind
*bind_stmt
= gimple_build_bind (BIND_EXPR_VARS (stmt
), NULL
,
108 BIND_EXPR_BLOCK (stmt
));
109 gimple_bind_set_body (bind_stmt
, seq
);
110 gimple_seq_add_stmt (&body
, bind_stmt
);
111 gimple_set_body (current_function_decl
, body
);
113 /* While we have SSA names in the IL we do not have a CFG built yet
114 and PHIs are represented using a PHI internal function. We do
115 have lowered control flow and exception handling (well, we do not
116 have parser support for EH yet). But as we still have BINDs
117 we have to go through lowering again. */
118 cfun
->curr_properties
= PROP_gimple_any
;
120 dump_function (TDI_generic
, current_function_decl
);
123 /* Parse a compound statement in gimple function body.
127 gimple-declaration-statement
129 gimple-switch-statement
130 gimple-labeled-statement
131 gimple-expression-statement
132 gimple-goto-statement
134 gimple-return-statement
138 c_parser_gimple_compound_statement (c_parser
*parser
, gimple_seq
*seq
)
140 bool return_p
= false;
142 if (! c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
145 /* A compund statement starts with optional declarations. */
146 while (c_parser_next_tokens_start_declaration (parser
))
148 c_parser_gimple_declaration (parser
);
149 if (! c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
153 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
155 if (c_parser_error (parser
))
157 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
160 else if (c_parser_next_token_is (parser
, CPP_EOF
))
162 c_parser_error (parser
, "expected declaration or statement");
166 switch (c_parser_peek_token (parser
)->type
)
169 switch (c_parser_peek_token (parser
)->keyword
)
172 c_parser_gimple_if_stmt (parser
, seq
);
175 c_parser_gimple_switch_stmt (parser
, seq
);
179 location_t loc
= c_parser_peek_token (parser
)->location
;
180 c_parser_consume_token (parser
);
181 if (c_parser_next_token_is (parser
, CPP_NAME
))
183 c_parser_gimple_goto_stmt (loc
,
187 c_parser_consume_token (parser
);
188 if (! c_parser_require (parser
, CPP_SEMICOLON
,
196 c_parser_gimple_return_stmt (parser
, seq
);
197 if (! c_parser_require (parser
, CPP_SEMICOLON
,
206 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
208 c_parser_gimple_label (parser
, seq
);
216 location_t loc
= c_parser_peek_token (parser
)->location
;
217 c_parser_consume_token (parser
);
218 gimple
*nop
= gimple_build_nop ();
219 gimple_set_location (nop
, loc
);
220 gimple_seq_add_stmt (seq
, nop
);
226 c_parser_gimple_statement (parser
, seq
);
227 if (! c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
228 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
231 c_parser_consume_token (parser
);
235 /* Parse a gimple statement.
238 gimple-call-expression
239 gimple-assign-statement
242 gimple-assign-statement:
243 gimple-unary-expression = gimple-assign-rhs
246 gimple-cast-expression
247 gimple-unary-expression
248 gimple-binary-expression
249 gimple-call-expression
251 gimple-phi-statement:
252 identifier = __PHI ( label : gimple_primary-expression, ... )
255 gimple-primary-expression ( argument-list )
257 gimple-cast-expression:
258 ( type-name ) gimple-primary-expression
263 c_parser_gimple_statement (c_parser
*parser
, gimple_seq
*seq
)
265 struct c_expr lhs
, rhs
;
266 gimple
*assign
= NULL
;
268 tree arg
= NULL_TREE
;
269 auto_vec
<tree
> vargs
;
271 lhs
= c_parser_gimple_unary_expression (parser
);
272 loc
= EXPR_LOCATION (lhs
.value
);
275 /* GIMPLE call statement without LHS. */
276 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
277 && TREE_CODE (lhs
.value
) == CALL_EXPR
)
280 call
= gimple_build_call_from_tree (lhs
.value
);
281 gimple_seq_add_stmt (seq
, call
);
282 gimple_set_location (call
, loc
);
286 /* All following cases are statements with LHS. */
287 if (! c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
290 /* Cast expression. */
291 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
292 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
294 c_parser_consume_token (parser
);
295 struct c_type_name
*type_name
= c_parser_type_name (parser
);
296 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
297 if (type_name
== NULL
)
299 /* ??? The actual type used in the cast expression is ignored as
300 in GIMPLE it is encoded by the type of the LHS. */
301 rhs
= c_parser_gimple_postfix_expression (parser
);
302 if (lhs
.value
!= error_mark_node
303 && rhs
.value
!= error_mark_node
)
305 enum tree_code code
= NOP_EXPR
;
306 if (VECTOR_TYPE_P (TREE_TYPE (lhs
.value
)))
308 code
= VIEW_CONVERT_EXPR
;
309 rhs
.value
= build1 (VIEW_CONVERT_EXPR
,
310 TREE_TYPE (lhs
.value
), rhs
.value
);
312 else if (FLOAT_TYPE_P (TREE_TYPE (lhs
.value
))
313 && ! FLOAT_TYPE_P (TREE_TYPE (rhs
.value
)))
315 else if (! FLOAT_TYPE_P (TREE_TYPE (lhs
.value
))
316 && FLOAT_TYPE_P (TREE_TYPE (rhs
.value
)))
317 code
= FIX_TRUNC_EXPR
;
318 assign
= gimple_build_assign (lhs
.value
, code
, rhs
.value
);
319 gimple_seq_add_stmt (seq
, assign
);
320 gimple_set_location (assign
, loc
);
325 /* Unary expression. */
326 switch (c_parser_peek_token (parser
)->type
)
330 tree id
= c_parser_peek_token (parser
)->value
;
331 if (strcmp (IDENTIFIER_POINTER (id
), "__ABS") == 0)
332 goto build_unary_expr
;
336 if (c_parser_peek_token (parser
)->keyword
!= RID_REALPART
337 && c_parser_peek_token (parser
)->keyword
!= RID_IMAGPART
)
345 case CPP_MULT
: /* pointer deref */
347 rhs
= c_parser_gimple_unary_expression (parser
);
348 if (rhs
.value
!= error_mark_node
)
350 assign
= gimple_build_assign (lhs
.value
, rhs
.value
);
351 gimple_set_location (assign
, loc
);
352 gimple_seq_add_stmt (seq
, assign
);
359 /* GIMPLE PHI statement. */
360 if (c_parser_next_token_is_keyword (parser
, RID_PHI
))
362 c_parser_consume_token (parser
);
364 if (! c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
367 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
368 c_parser_consume_token (parser
);
370 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
372 if (c_parser_next_token_is (parser
, CPP_NAME
)
373 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
375 arg
= lookup_label_for_goto (loc
,
376 c_parser_peek_token (parser
)->value
);
377 c_parser_consume_token (parser
);
379 if (c_parser_next_token_is (parser
, CPP_COLON
))
380 c_parser_consume_token (parser
);
381 vargs
.safe_push (arg
);
383 else if (c_parser_next_token_is (parser
, CPP_COMMA
))
384 c_parser_consume_token (parser
);
387 arg
= c_parser_gimple_unary_expression (parser
).value
;
388 vargs
.safe_push (arg
);
392 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
395 /* Build internal function for PHI. */
396 gcall
*call_stmt
= gimple_build_call_internal_vec (IFN_PHI
, vargs
);
397 gimple_call_set_lhs (call_stmt
, lhs
.value
);
398 gimple_set_location (call_stmt
, UNKNOWN_LOCATION
);
399 gimple_seq_add_stmt (seq
, call_stmt
);
403 /* GIMPLE call with lhs. */
404 if (c_parser_next_token_is (parser
, CPP_NAME
)
405 && c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_PAREN
406 && lookup_name (c_parser_peek_token (parser
)->value
))
408 rhs
= c_parser_gimple_unary_expression (parser
);
409 if (rhs
.value
!= error_mark_node
)
411 gimple
*call
= gimple_build_call_from_tree (rhs
.value
);
412 gimple_call_set_lhs (call
, lhs
.value
);
413 gimple_seq_add_stmt (seq
, call
);
414 gimple_set_location (call
, loc
);
419 rhs
= c_parser_gimple_binary_expression (parser
);
420 if (lhs
.value
!= error_mark_node
421 && rhs
.value
!= error_mark_node
)
423 assign
= gimple_build_assign (lhs
.value
, rhs
.value
);
424 gimple_seq_add_stmt (seq
, assign
);
425 gimple_set_location (assign
, loc
);
430 /* Parse gimple binary expr.
432 gimple-binary-expression:
433 gimple-unary-expression * gimple-unary-expression
434 gimple-unary-expression / gimple-unary-expression
435 gimple-unary-expression % gimple-unary-expression
436 gimple-unary-expression + gimple-unary-expression
437 gimple-unary-expression - gimple-unary-expression
438 gimple-unary-expression << gimple-unary-expression
439 gimple-unary-expression >> gimple-unary-expression
440 gimple-unary-expression < gimple-unary-expression
441 gimple-unary-expression > gimple-unary-expression
442 gimple-unary-expression <= gimple-unary-expression
443 gimple-unary-expression >= gimple-unary-expression
444 gimple-unary-expression == gimple-unary-expression
445 gimple-unary-expression != gimple-unary-expression
446 gimple-unary-expression & gimple-unary-expression
447 gimple-unary-expression ^ gimple-unary-expression
448 gimple-unary-expression | gimple-unary-expression
453 c_parser_gimple_binary_expression (c_parser
*parser
)
455 /* Location of the binary operator. */
456 struct c_expr ret
, lhs
, rhs
;
457 enum tree_code code
= ERROR_MARK
;
459 lhs
= c_parser_gimple_postfix_expression (parser
);
460 if (c_parser_error (parser
))
462 tree ret_type
= TREE_TYPE (lhs
.value
);
463 switch (c_parser_peek_token (parser
)->type
)
469 code
= TRUNC_DIV_EXPR
;
472 code
= TRUNC_MOD_EXPR
;
475 if (POINTER_TYPE_P (TREE_TYPE (lhs
.value
)))
476 code
= POINTER_PLUS_EXPR
;
491 ret_type
= boolean_type_node
;
495 ret_type
= boolean_type_node
;
499 ret_type
= boolean_type_node
;
503 ret_type
= boolean_type_node
;
507 ret_type
= boolean_type_node
;
511 ret_type
= boolean_type_node
;
523 c_parser_error (parser
, "%<&&%> not valid in GIMPLE");
526 c_parser_error (parser
, "%<||%> not valid in GIMPLE");
529 /* Not a binary expression. */
532 location_t ret_loc
= c_parser_peek_token (parser
)->location
;
533 c_parser_consume_token (parser
);
534 rhs
= c_parser_gimple_postfix_expression (parser
);
535 if (lhs
.value
!= error_mark_node
&& rhs
.value
!= error_mark_node
)
536 ret
.value
= build2_loc (ret_loc
, code
, ret_type
, lhs
.value
, rhs
.value
);
540 /* Parse gimple unary expression.
542 gimple-unary-expression:
543 gimple-postfix-expression
544 unary-operator gimple-postfix-expression
546 unary-operator: one of
551 c_parser_gimple_unary_expression (c_parser
*parser
)
553 struct c_expr ret
, op
;
554 location_t op_loc
= c_parser_peek_token (parser
)->location
;
557 switch (c_parser_peek_token (parser
)->type
)
560 c_parser_consume_token (parser
);
561 op
= c_parser_gimple_postfix_expression (parser
);
562 mark_exp_read (op
.value
);
563 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
566 c_parser_consume_token (parser
);
567 op
= c_parser_gimple_postfix_expression (parser
);
568 if (op
.value
== error_mark_node
)
570 finish
= op
.get_finish ();
571 location_t combined_loc
= make_location (op_loc
, op_loc
, finish
);
572 ret
.value
= build_simple_mem_ref_loc (combined_loc
, op
.value
);
573 TREE_SIDE_EFFECTS (ret
.value
)
574 = TREE_THIS_VOLATILE (ret
.value
)
575 = TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (op
.value
)));
576 ret
.src_range
.m_start
= op_loc
;
577 ret
.src_range
.m_finish
= finish
;
581 c_parser_consume_token (parser
);
582 op
= c_parser_gimple_postfix_expression (parser
);
583 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
585 c_parser_consume_token (parser
);
586 op
= c_parser_gimple_postfix_expression (parser
);
587 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
589 c_parser_consume_token (parser
);
590 op
= c_parser_gimple_postfix_expression (parser
);
591 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
593 c_parser_error (parser
, "%<!%> not valid in GIMPLE");
596 switch (c_parser_peek_token (parser
)->keyword
)
599 c_parser_consume_token (parser
);
600 op
= c_parser_gimple_postfix_expression (parser
);
601 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
603 c_parser_consume_token (parser
);
604 op
= c_parser_gimple_postfix_expression (parser
);
605 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
607 return c_parser_gimple_postfix_expression (parser
);
611 tree id
= c_parser_peek_token (parser
)->value
;
612 if (strcmp (IDENTIFIER_POINTER (id
), "__ABS") == 0)
614 c_parser_consume_token (parser
);
615 op
= c_parser_gimple_postfix_expression (parser
);
616 return parser_build_unary_op (op_loc
, ABS_EXPR
, op
);
619 return c_parser_gimple_postfix_expression (parser
);
622 return c_parser_gimple_postfix_expression (parser
);
626 /* Decompose ID into base name (ID until ver_offset) and VERSION. Return
627 true if ID matches a SSA name. */
630 c_parser_parse_ssa_name_id (tree id
, unsigned *version
, unsigned *ver_offset
)
632 const char *token
= IDENTIFIER_POINTER (id
);
633 const char *var_version
= strrchr (token
, '_');
637 *ver_offset
= var_version
- token
;
638 for (const char *p
= var_version
+ 1; *p
; ++p
)
641 *version
= atoi (var_version
+ 1);
645 /* Get at the actual SSA name ID with VERSION starting at VER_OFFSET.
646 TYPE is the type if the SSA name is being declared. */
649 c_parser_parse_ssa_name (c_parser
*parser
,
650 tree id
, tree type
, unsigned version
,
653 tree name
= NULL_TREE
;
654 const char *token
= IDENTIFIER_POINTER (id
);
658 /* Anonymous unnamed SSA name. */
659 if (version
< num_ssa_names
)
660 name
= ssa_name (version
);
665 c_parser_error (parser
, "SSA name undeclared");
666 return error_mark_node
;
668 name
= make_ssa_name_fn (cfun
, type
, NULL
, version
);
673 if (version
< num_ssa_names
)
674 name
= ssa_name (version
);
677 /* Separate var name from version. */
678 char *var_name
= XNEWVEC (char, ver_offset
+ 1);
679 memcpy (var_name
, token
, ver_offset
);
680 var_name
[ver_offset
] = '\0';
681 /* lookup for parent decl. */
682 id
= get_identifier (var_name
);
683 tree parent
= lookup_name (id
);
684 XDELETEVEC (var_name
);
685 if (! parent
|| parent
== error_mark_node
)
687 c_parser_error (parser
, "base variable or SSA name undeclared");
688 return error_mark_node
;
690 if (VECTOR_TYPE_P (TREE_TYPE (parent
))
691 || TREE_CODE (TREE_TYPE (parent
)) == COMPLEX_TYPE
)
692 DECL_GIMPLE_REG_P (parent
) = 1;
693 name
= make_ssa_name_fn (cfun
, parent
,
694 gimple_build_nop (), version
);
701 /* Parse gimple postfix expression.
703 gimple-postfix-expression:
704 gimple-primary-expression
705 gimple-primary-xpression [ gimple-primary-expression ]
706 gimple-primary-expression ( gimple-argument-expression-list[opt] )
707 postfix-expression . identifier
708 postfix-expression -> identifier
710 gimple-argument-expression-list:
711 gimple-unary-expression
712 gimple-argument-expression-list , gimple-unary-expression
714 gimple-primary-expression:
722 c_parser_gimple_postfix_expression (c_parser
*parser
)
724 location_t loc
= c_parser_peek_token (parser
)->location
;
725 source_range tok_range
= c_parser_peek_token (parser
)->get_range ();
728 switch (c_parser_peek_token (parser
)->type
)
731 expr
.value
= c_parser_peek_token (parser
)->value
;
732 set_c_expr_source_range (&expr
, tok_range
);
733 loc
= c_parser_peek_token (parser
)->location
;
734 c_parser_consume_token (parser
);
740 expr
.value
= c_parser_peek_token (parser
)->value
;
741 set_c_expr_source_range (&expr
, tok_range
);
742 c_parser_consume_token (parser
);
749 expr
.value
= c_parser_peek_token (parser
)->value
;
750 set_c_expr_source_range (&expr
, tok_range
);
751 expr
.original_code
= STRING_CST
;
752 c_parser_consume_token (parser
);
755 if (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
757 tree id
= c_parser_peek_token (parser
)->value
;
758 if (strcmp (IDENTIFIER_POINTER (id
), "__MEM") == 0)
760 /* __MEM '<' type-name [ ',' number ] '>'
761 '(' [ '(' type-name ')' ] unary-expression
762 [ '+' number ] ')' */
763 location_t loc
= c_parser_peek_token (parser
)->location
;
764 c_parser_consume_token (parser
);
765 struct c_type_name
*type_name
= NULL
;
766 tree alignment
= NULL_TREE
;
767 if (c_parser_require (parser
, CPP_LESS
, "expected %<<%>"))
769 type_name
= c_parser_type_name (parser
);
770 /* Optional alignment. */
771 if (c_parser_next_token_is (parser
, CPP_COMMA
))
773 c_parser_consume_token (parser
);
775 = c_parser_gimple_postfix_expression (parser
).value
;
777 c_parser_skip_until_found (parser
,
778 CPP_GREATER
, "expected %<>%>");
781 ptr
.value
= error_mark_node
;
782 tree alias_off
= NULL_TREE
;
783 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
785 tree alias_type
= NULL_TREE
;
786 /* Optional alias-type cast. */
787 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
789 c_parser_consume_token (parser
);
790 struct c_type_name
*alias_type_name
791 = c_parser_type_name (parser
);
792 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
797 alias_type
= groktypename (alias_type_name
,
801 ptr
= c_parser_gimple_unary_expression (parser
);
803 alias_type
= TREE_TYPE (ptr
.value
);
804 /* Optional constant offset. */
805 if (c_parser_next_token_is (parser
, CPP_PLUS
))
807 c_parser_consume_token (parser
);
809 = c_parser_gimple_postfix_expression (parser
).value
;
810 alias_off
= fold_convert (alias_type
, alias_off
);
813 alias_off
= build_int_cst (alias_type
, 0);
814 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
817 if (! type_name
|| c_parser_error (parser
))
819 c_parser_set_error (parser
, false);
822 tree tem
= NULL_TREE
;
823 tree type
= groktypename (type_name
, &tem
, NULL
);
825 type
= build_aligned_type (type
, tree_to_uhwi (alignment
));
826 expr
.value
= build2_loc (loc
, MEM_REF
,
827 type
, ptr
.value
, alias_off
);
830 else if (strcmp (IDENTIFIER_POINTER (id
), "_Literal") == 0)
832 /* _Literal '(' type-name ')' number */
833 c_parser_consume_token (parser
);
834 tree type
= NULL_TREE
;
835 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
837 struct c_type_name
*type_name
= c_parser_type_name (parser
);
840 type
= groktypename (type_name
, &tem
, NULL
);
841 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
844 tree val
= c_parser_gimple_postfix_expression (parser
).value
;
847 || val
== error_mark_node
848 || TREE_CODE (val
) != INTEGER_CST
)
850 c_parser_error (parser
, "invalid _Literal");
853 expr
.value
= fold_convert (type
, val
);
856 else if (strcmp (IDENTIFIER_POINTER (id
), "__FMA") == 0)
858 c_parser_consume_token (parser
);
861 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
863 c_parser_gimple_expr_list (parser
, &args
);
864 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
867 if (args
.length () != 3)
869 error_at (loc
, "invalid number of operands to __FMA");
870 expr
.value
= error_mark_node
;
873 expr
.value
= build3_loc (loc
, FMA_EXPR
, TREE_TYPE (args
[0]),
874 args
[0], args
[1], args
[2]);
879 unsigned version
, ver_offset
;
880 if (! lookup_name (id
)
881 && c_parser_parse_ssa_name_id (id
, &version
, &ver_offset
))
883 c_parser_consume_token (parser
);
884 expr
.value
= c_parser_parse_ssa_name (parser
, id
, NULL_TREE
,
885 version
, ver_offset
);
886 if (expr
.value
== error_mark_node
)
888 set_c_expr_source_range (&expr
, tok_range
);
889 /* For default definition SSA names. */
890 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
891 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
894 (c_parser_peek_2nd_token (parser
)->value
)) == 0
895 && c_parser_peek_nth_token (parser
, 3)->type
== CPP_CLOSE_PAREN
)
897 c_parser_consume_token (parser
);
898 c_parser_consume_token (parser
);
899 c_parser_consume_token (parser
);
900 if (! SSA_NAME_IS_DEFAULT_DEF (expr
.value
))
902 if (!SSA_NAME_VAR (expr
.value
))
904 error_at (loc
, "anonymous SSA name cannot have"
905 " default definition");
906 expr
.value
= error_mark_node
;
909 set_ssa_default_def (cfun
, SSA_NAME_VAR (expr
.value
),
911 SSA_NAME_DEF_STMT (expr
.value
) = gimple_build_nop ();
917 c_parser_consume_token (parser
);
919 = build_external_ref (loc
, id
,
920 (c_parser_peek_token (parser
)->type
921 == CPP_OPEN_PAREN
), &expr
.original_type
);
922 set_c_expr_source_range (&expr
, tok_range
);
928 c_parser_error (parser
, "expected expression");
934 c_parser_error (parser
, "expected expression");
938 return c_parser_gimple_postfix_expression_after_primary
939 (parser
, EXPR_LOC_OR_LOC (expr
.value
, loc
), expr
);
942 /* Parse a gimple postfix expression after the initial primary or compound
946 c_parser_gimple_postfix_expression_after_primary (c_parser
*parser
,
957 location_t op_loc
= c_parser_peek_token (parser
)->location
;
958 switch (c_parser_peek_token (parser
)->type
)
960 case CPP_OPEN_SQUARE
:
962 c_parser_consume_token (parser
);
963 tree idx
= c_parser_gimple_unary_expression (parser
).value
;
965 if (! c_parser_require (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>"))
967 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
971 start
= expr
.get_start ();
972 finish
= c_parser_tokens_buf (parser
, 0)->location
;
973 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
974 set_c_expr_source_range (&expr
, start
, finish
);
976 expr
.original_code
= ERROR_MARK
;
977 expr
.original_type
= NULL
;
983 c_parser_consume_token (parser
);
984 auto_vec
<tree
> exprlist
;
985 if (! c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
986 c_parser_gimple_expr_list (parser
, &exprlist
);
987 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
989 expr
.value
= build_call_array_loc
990 (expr_loc
, TREE_TYPE (TREE_TYPE (expr
.value
)),
991 expr
.value
, exprlist
.length (), exprlist
.address ());
992 expr
.original_code
= ERROR_MARK
;
993 expr
.original_type
= NULL
;
998 /* Structure element reference. */
999 c_parser_consume_token (parser
);
1000 if (c_parser_next_token_is (parser
, CPP_NAME
))
1002 c_token
*comp_tok
= c_parser_peek_token (parser
);
1003 ident
= comp_tok
->value
;
1004 comp_loc
= comp_tok
->location
;
1008 c_parser_error (parser
, "expected identifier");
1010 expr
.original_code
= ERROR_MARK
;
1011 expr
.original_type
= NULL
;
1014 start
= expr
.get_start ();
1015 finish
= c_parser_peek_token (parser
)->get_finish ();
1016 c_parser_consume_token (parser
);
1017 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
,
1019 set_c_expr_source_range (&expr
, start
, finish
);
1020 expr
.original_code
= ERROR_MARK
;
1021 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
1022 expr
.original_type
= NULL
;
1025 /* Remember the original type of a bitfield. */
1026 tree field
= TREE_OPERAND (expr
.value
, 1);
1027 if (TREE_CODE (field
) != FIELD_DECL
)
1028 expr
.original_type
= NULL
;
1030 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
1036 /* Structure element reference. */
1037 c_parser_consume_token (parser
);
1038 if (c_parser_next_token_is (parser
, CPP_NAME
))
1040 c_token
*comp_tok
= c_parser_peek_token (parser
);
1041 ident
= comp_tok
->value
;
1042 comp_loc
= comp_tok
->location
;
1046 c_parser_error (parser
, "expected identifier");
1048 expr
.original_code
= ERROR_MARK
;
1049 expr
.original_type
= NULL
;
1052 start
= expr
.get_start ();
1053 finish
= c_parser_peek_token (parser
)->get_finish ();
1054 c_parser_consume_token (parser
);
1055 expr
.value
= build_component_ref (op_loc
,
1056 build_simple_mem_ref_loc
1057 (op_loc
, expr
.value
),
1059 set_c_expr_source_range (&expr
, start
, finish
);
1060 expr
.original_code
= ERROR_MARK
;
1061 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
1062 expr
.original_type
= NULL
;
1065 /* Remember the original type of a bitfield. */
1066 tree field
= TREE_OPERAND (expr
.value
, 1);
1067 if (TREE_CODE (field
) != FIELD_DECL
)
1068 expr
.original_type
= NULL
;
1070 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
1080 /* Parse expression list.
1083 gimple-unary-expression
1084 gimple-expr-list , gimple-unary-expression
1089 c_parser_gimple_expr_list (c_parser
*parser
, vec
<tree
> *ret
)
1093 expr
= c_parser_gimple_unary_expression (parser
);
1094 ret
->safe_push (expr
.value
);
1095 while (c_parser_next_token_is (parser
, CPP_COMMA
))
1097 c_parser_consume_token (parser
);
1098 expr
= c_parser_gimple_unary_expression (parser
);
1099 ret
->safe_push (expr
.value
);
1103 /* Parse gimple label.
1107 case constant-expression :
1113 c_parser_gimple_label (c_parser
*parser
, gimple_seq
*seq
)
1115 tree name
= c_parser_peek_token (parser
)->value
;
1116 location_t loc1
= c_parser_peek_token (parser
)->location
;
1117 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
1118 c_parser_consume_token (parser
);
1119 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
1120 c_parser_consume_token (parser
);
1121 tree label
= define_label (loc1
, name
);
1122 gimple_seq_add_stmt (seq
, gimple_build_label (label
));
1126 /* Parse gimple/RTL pass list.
1128 gimple-or-rtl-pass-list:
1129 startwith("pass-name")
1133 c_parser_gimple_or_rtl_pass_list (c_parser
*parser
)
1137 /* Accept __GIMPLE/__RTL. */
1138 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
1140 c_parser_consume_token (parser
);
1142 if (c_parser_next_token_is (parser
, CPP_NAME
))
1144 const char *op
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
1145 c_parser_consume_token (parser
);
1146 if (! strcmp (op
, "startwith"))
1148 if (! c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1150 if (c_parser_next_token_is_not (parser
, CPP_STRING
))
1152 error_at (c_parser_peek_token (parser
)->location
,
1153 "expected pass name");
1156 pass
= xstrdup (TREE_STRING_POINTER
1157 (c_parser_peek_token (parser
)->value
));
1158 c_parser_consume_token (parser
);
1159 if (! c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
1164 error_at (c_parser_peek_token (parser
)->location
,
1165 "invalid operation");
1170 if (! c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
1176 /* Parse gimple local declaration.
1178 declaration-specifiers:
1179 storage-class-specifier declaration-specifiers[opt]
1180 type-specifier declaration-specifiers[opt]
1181 type-qualifier declaration-specifiers[opt]
1182 function-specifier declaration-specifiers[opt]
1183 alignment-specifier declaration-specifiers[opt]
1185 storage-class-specifier:
1209 address-space-qualifier
1215 c_parser_gimple_declaration (c_parser
*parser
)
1217 struct c_declarator
*declarator
;
1218 struct c_declspecs
*specs
= build_null_declspecs ();
1219 c_parser_declspecs (parser
, specs
, true, true, true,
1220 true, true, cla_nonabstract_decl
);
1221 finish_declspecs (specs
);
1223 /* Provide better error recovery. Note that a type name here is usually
1224 better diagnosed as a redeclaration. */
1225 if (c_parser_next_token_starts_declspecs (parser
)
1226 && ! c_parser_next_token_is (parser
, CPP_NAME
))
1228 c_parser_error (parser
, "expected %<;%>");
1229 c_parser_set_error (parser
, false);
1234 declarator
= c_parser_declarator (parser
,
1235 specs
->typespec_kind
!= ctsk_none
,
1236 C_DTR_NORMAL
, &dummy
);
1238 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1240 /* Handle SSA name decls specially, they do not go into the identifier
1241 table but we simply build the SSA name for later lookup. */
1242 unsigned version
, ver_offset
;
1243 if (declarator
->kind
== cdk_id
1244 && is_gimple_reg_type (specs
->type
)
1245 && c_parser_parse_ssa_name_id (declarator
->u
.id
,
1246 &version
, &ver_offset
)
1247 /* The following restricts it to unnamed anonymous SSA names
1248 which fails parsing of named ones in dumps (we could
1249 decide to not dump their name for -gimple). */
1251 c_parser_parse_ssa_name (parser
, declarator
->u
.id
, specs
->type
,
1252 version
, ver_offset
);
1255 tree postfix_attrs
= NULL_TREE
;
1256 tree all_prefix_attrs
= specs
->attrs
;
1257 specs
->attrs
= NULL
;
1258 tree decl
= start_decl (declarator
, specs
, false,
1259 chainon (postfix_attrs
, all_prefix_attrs
));
1261 finish_decl (decl
, UNKNOWN_LOCATION
, NULL_TREE
, NULL_TREE
,
1267 c_parser_error (parser
, "expected %<;%>");
1272 /* Parse gimple goto statement. */
1275 c_parser_gimple_goto_stmt (location_t loc
, tree label
, gimple_seq
*seq
)
1277 tree decl
= lookup_label_for_goto (loc
, label
);
1278 gimple_seq_add_stmt (seq
, gimple_build_goto (decl
));
1282 /* Parse a parenthesized condition.
1284 ( gimple-binary-expression ) */
1287 c_parser_gimple_paren_condition (c_parser
*parser
)
1289 if (! c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1290 return error_mark_node
;
1291 tree cond
= c_parser_gimple_binary_expression (parser
).value
;
1292 if (! c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
1293 return error_mark_node
;
1297 /* Parse gimple if-else statement.
1300 if ( gimple-binary-expression ) gimple-goto-statement
1301 if ( gimple-binary-expression ) gimple-goto-statement \
1302 else gimple-goto-statement
1306 c_parser_gimple_if_stmt (c_parser
*parser
, gimple_seq
*seq
)
1308 tree t_label
, f_label
, label
;
1310 c_parser_consume_token (parser
);
1311 tree cond
= c_parser_gimple_paren_condition (parser
);
1313 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
1315 loc
= c_parser_peek_token (parser
)->location
;
1316 c_parser_consume_token (parser
);
1317 label
= c_parser_peek_token (parser
)->value
;
1318 t_label
= lookup_label_for_goto (loc
, label
);
1319 c_parser_consume_token (parser
);
1320 if (! c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1325 c_parser_error (parser
, "expected goto expression");
1329 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
1330 c_parser_consume_token (parser
);
1333 c_parser_error (parser
, "expected else statement");
1337 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
1339 loc
= c_parser_peek_token (parser
)->location
;
1340 c_parser_consume_token (parser
);
1341 label
= c_parser_peek_token (parser
)->value
;
1342 f_label
= lookup_label_for_goto (loc
, label
);
1343 c_parser_consume_token (parser
);
1344 if (! c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1349 c_parser_error (parser
, "expected goto expression");
1353 if (cond
!= error_mark_node
)
1354 gimple_seq_add_stmt (seq
, gimple_build_cond_from_tree (cond
, t_label
,
1358 /* Parse gimple switch-statement.
1360 gimple-switch-statement:
1361 switch (gimple-postfix-expression) gimple-case-statement
1363 gimple-case-statement:
1364 gimple-case-statement
1365 gimple-label-statement : gimple-goto-statment
1369 c_parser_gimple_switch_stmt (c_parser
*parser
, gimple_seq
*seq
)
1372 tree case_label
, label
;
1373 auto_vec
<tree
> labels
;
1374 tree default_label
= NULL_TREE
;
1375 gimple_seq switch_body
= NULL
;
1376 c_parser_consume_token (parser
);
1378 if (! c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1380 cond_expr
= c_parser_gimple_postfix_expression (parser
);
1381 if (! c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
1384 if (! c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
1387 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
1389 if (c_parser_next_token_is (parser
, CPP_EOF
))
1391 c_parser_error (parser
, "expected statement");
1395 switch (c_parser_peek_token (parser
)->keyword
)
1400 location_t loc
= c_parser_peek_token (parser
)->location
;
1401 c_parser_consume_token (parser
);
1403 if (c_parser_next_token_is (parser
, CPP_NAME
)
1404 || c_parser_peek_token (parser
)->type
== CPP_NUMBER
)
1405 exp1
= c_parser_gimple_postfix_expression (parser
);
1408 c_parser_error (parser
, "expected expression");
1412 if (c_parser_next_token_is (parser
, CPP_COLON
))
1414 c_parser_consume_token (parser
);
1415 if (c_parser_next_token_is (parser
, CPP_NAME
))
1417 label
= c_parser_peek_token (parser
)->value
;
1418 c_parser_consume_token (parser
);
1419 tree decl
= lookup_label_for_goto (loc
, label
);
1420 case_label
= build_case_label (exp1
.value
, NULL_TREE
,
1422 labels
.safe_push (case_label
);
1423 if (! c_parser_require (parser
, CPP_SEMICOLON
,
1427 else if (! c_parser_require (parser
, CPP_NAME
,
1431 else if (! c_parser_require (parser
, CPP_SEMICOLON
,
1438 location_t loc
= c_parser_peek_token (parser
)->location
;
1439 c_parser_consume_token (parser
);
1440 if (c_parser_next_token_is (parser
, CPP_COLON
))
1442 c_parser_consume_token (parser
);
1443 if (c_parser_next_token_is (parser
, CPP_NAME
))
1445 label
= c_parser_peek_token (parser
)->value
;
1446 c_parser_consume_token (parser
);
1447 tree decl
= lookup_label_for_goto (loc
, label
);
1448 default_label
= build_case_label (NULL_TREE
, NULL_TREE
,
1450 if (! c_parser_require (parser
, CPP_SEMICOLON
,
1454 else if (! c_parser_require (parser
, CPP_NAME
,
1458 else if (! c_parser_require (parser
, CPP_SEMICOLON
,
1465 location_t loc
= c_parser_peek_token (parser
)->location
;
1466 c_parser_consume_token (parser
);
1467 if (c_parser_next_token_is (parser
, CPP_NAME
))
1469 c_parser_gimple_goto_stmt (loc
,
1473 c_parser_consume_token (parser
);
1474 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1475 c_parser_consume_token (parser
);
1478 c_parser_error (parser
, "expected semicolon");
1482 else if (! c_parser_require (parser
, CPP_NAME
,
1488 c_parser_error (parser
, "expected case label or goto statement");
1493 if (! c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>"))
1496 if (cond_expr
.value
!= error_mark_node
)
1498 gimple_seq_add_stmt (seq
, gimple_build_switch (cond_expr
.value
,
1499 default_label
, labels
));
1500 gimple_seq_add_seq (seq
, switch_body
);
1504 /* Parse gimple return statement. */
1507 c_parser_gimple_return_stmt (c_parser
*parser
, gimple_seq
*seq
)
1509 location_t loc
= c_parser_peek_token (parser
)->location
;
1511 c_parser_consume_token (parser
);
1512 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1514 c_finish_gimple_return (loc
, NULL_TREE
);
1515 ret
= gimple_build_return (NULL
);
1516 gimple_seq_add_stmt (seq
, ret
);
1520 location_t xloc
= c_parser_peek_token (parser
)->location
;
1521 c_expr expr
= c_parser_gimple_unary_expression (parser
);
1522 if (expr
.value
!= error_mark_node
)
1524 c_finish_gimple_return (xloc
, expr
.value
);
1525 ret
= gimple_build_return (expr
.value
);
1526 gimple_seq_add_stmt (seq
, ret
);
1531 /* Support function for c_parser_gimple_return_stmt. */
1534 c_finish_gimple_return (location_t loc
, tree retval
)
1536 tree valtype
= TREE_TYPE (TREE_TYPE (current_function_decl
));
1538 /* Use the expansion point to handle cases such as returning NULL
1539 in a function returning void. */
1540 source_location xloc
= expansion_point_location_if_in_system_header (loc
);
1542 if (TREE_THIS_VOLATILE (current_function_decl
))
1543 warning_at (xloc
, 0,
1544 "function declared %<noreturn%> has a %<return%> statement");
1547 current_function_returns_null
= 1;
1548 else if (valtype
== 0 || TREE_CODE (valtype
) == VOID_TYPE
)
1550 current_function_returns_null
= 1;
1551 if (TREE_CODE (TREE_TYPE (retval
)) != VOID_TYPE
)
1554 (xloc
, "%<return%> with a value, in function returning void");
1555 inform (DECL_SOURCE_LOCATION (current_function_decl
),
1559 else if (TREE_CODE (valtype
) != TREE_CODE (TREE_TYPE (retval
)))
1562 (xloc
, "invalid conversion in return statement");
1563 inform (DECL_SOURCE_LOCATION (current_function_decl
),