2 Copyright (C) 2016-2018 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"
58 /* Gimple parsing functions. */
59 static bool c_parser_gimple_compound_statement (c_parser
*, gimple_seq
*);
60 static void c_parser_gimple_label (c_parser
*, gimple_seq
*);
61 static void c_parser_gimple_statement (c_parser
*, gimple_seq
*);
62 static struct c_expr
c_parser_gimple_binary_expression (c_parser
*);
63 static struct c_expr
c_parser_gimple_unary_expression (c_parser
*);
64 static struct c_expr
c_parser_gimple_postfix_expression (c_parser
*);
65 static struct c_expr
c_parser_gimple_postfix_expression_after_primary (c_parser
*,
68 static void c_parser_gimple_declaration (c_parser
*);
69 static void c_parser_gimple_goto_stmt (location_t
, tree
, gimple_seq
*);
70 static void c_parser_gimple_if_stmt (c_parser
*, gimple_seq
*);
71 static void c_parser_gimple_switch_stmt (c_parser
*, gimple_seq
*);
72 static void c_parser_gimple_return_stmt (c_parser
*, gimple_seq
*);
73 static void c_finish_gimple_return (location_t
, tree
);
74 static tree
c_parser_gimple_paren_condition (c_parser
*);
75 static void c_parser_gimple_expr_list (c_parser
*, vec
<tree
> *);
78 /* Parse the body of a function declaration marked with "__GIMPLE". */
81 c_parser_parse_gimple_body (c_parser
*parser
)
83 gimple_seq seq
= NULL
;
84 gimple_seq body
= NULL
;
85 tree stmt
= push_stmt_list ();
87 location_t loc1
= c_parser_peek_token (parser
)->location
;
91 if (! c_parser_gimple_compound_statement (parser
, &seq
))
93 gimple
*ret
= gimple_build_return (NULL
);
94 gimple_seq_add_stmt (&seq
, ret
);
97 tree block
= pop_scope ();
98 stmt
= pop_stmt_list (stmt
);
99 stmt
= c_build_bind_expr (loc1
, block
, stmt
);
101 block
= DECL_INITIAL (current_function_decl
);
102 BLOCK_SUBBLOCKS (block
) = NULL_TREE
;
103 BLOCK_CHAIN (block
) = NULL_TREE
;
104 TREE_ASM_WRITTEN (block
) = 1;
106 gbind
*bind_stmt
= gimple_build_bind (BIND_EXPR_VARS (stmt
), NULL
,
107 BIND_EXPR_BLOCK (stmt
));
108 gimple_bind_set_body (bind_stmt
, seq
);
109 gimple_seq_add_stmt (&body
, bind_stmt
);
110 gimple_set_body (current_function_decl
, body
);
112 /* While we have SSA names in the IL we do not have a CFG built yet
113 and PHIs are represented using a PHI internal function. We do
114 have lowered control flow and exception handling (well, we do not
115 have parser support for EH yet). But as we still have BINDs
116 we have to go through lowering again. */
117 cfun
->curr_properties
= PROP_gimple_any
;
119 dump_function (TDI_gimple
, current_function_decl
);
122 /* Parse a compound statement in gimple function body.
126 gimple-declaration-statement
128 gimple-switch-statement
129 gimple-labeled-statement
130 gimple-expression-statement
131 gimple-goto-statement
133 gimple-return-statement
137 c_parser_gimple_compound_statement (c_parser
*parser
, gimple_seq
*seq
)
139 bool return_p
= false;
141 if (! c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
144 /* A compund statement starts with optional declarations. */
145 while (c_parser_next_tokens_start_declaration (parser
))
147 c_parser_gimple_declaration (parser
);
148 if (! c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
152 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
154 if (c_parser_error (parser
))
156 c_parser_skip_until_found (parser
, CPP_CLOSE_BRACE
, NULL
);
159 else if (c_parser_next_token_is (parser
, CPP_EOF
))
161 c_parser_error (parser
, "expected declaration or statement");
165 switch (c_parser_peek_token (parser
)->type
)
168 switch (c_parser_peek_token (parser
)->keyword
)
171 c_parser_gimple_if_stmt (parser
, seq
);
174 c_parser_gimple_switch_stmt (parser
, seq
);
178 location_t loc
= c_parser_peek_token (parser
)->location
;
179 c_parser_consume_token (parser
);
180 if (c_parser_next_token_is (parser
, CPP_NAME
))
182 c_parser_gimple_goto_stmt (loc
,
186 c_parser_consume_token (parser
);
187 if (! c_parser_require (parser
, CPP_SEMICOLON
,
195 c_parser_gimple_return_stmt (parser
, seq
);
196 if (! c_parser_require (parser
, CPP_SEMICOLON
,
205 if (c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
207 c_parser_gimple_label (parser
, seq
);
215 location_t loc
= c_parser_peek_token (parser
)->location
;
216 c_parser_consume_token (parser
);
217 gimple
*nop
= gimple_build_nop ();
218 gimple_set_location (nop
, loc
);
219 gimple_seq_add_stmt (seq
, nop
);
225 c_parser_gimple_statement (parser
, seq
);
226 if (! c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
227 c_parser_skip_until_found (parser
, CPP_SEMICOLON
, NULL
);
230 c_parser_consume_token (parser
);
234 /* Parse a gimple statement.
237 gimple-call-expression
238 gimple-assign-statement
241 gimple-assign-statement:
242 gimple-unary-expression = gimple-assign-rhs
245 gimple-cast-expression
246 gimple-unary-expression
247 gimple-binary-expression
248 gimple-call-expression
250 gimple-phi-statement:
251 identifier = __PHI ( label : gimple_primary-expression, ... )
254 gimple-primary-expression ( argument-list )
256 gimple-cast-expression:
257 ( type-name ) gimple-primary-expression
262 c_parser_gimple_statement (c_parser
*parser
, gimple_seq
*seq
)
264 struct c_expr lhs
, rhs
;
265 gimple
*assign
= NULL
;
267 tree arg
= NULL_TREE
;
268 auto_vec
<tree
> vargs
;
270 lhs
= c_parser_gimple_unary_expression (parser
);
271 loc
= EXPR_LOCATION (lhs
.value
);
274 /* GIMPLE call statement without LHS. */
275 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
)
276 && TREE_CODE (lhs
.value
) == CALL_EXPR
)
279 call
= gimple_build_call_from_tree (lhs
.value
, NULL
);
280 gimple_seq_add_stmt (seq
, call
);
281 gimple_set_location (call
, loc
);
285 /* All following cases are statements with LHS. */
286 if (! c_parser_require (parser
, CPP_EQ
, "expected %<=%>"))
289 /* Cast expression. */
290 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
291 && c_token_starts_typename (c_parser_peek_2nd_token (parser
)))
293 c_parser_consume_token (parser
);
294 struct c_type_name
*type_name
= c_parser_type_name (parser
);
295 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
, "expected %<)%>");
296 if (type_name
== NULL
)
298 /* ??? The actual type used in the cast expression is ignored as
299 in GIMPLE it is encoded by the type of the LHS. */
300 rhs
= c_parser_gimple_postfix_expression (parser
);
301 if (lhs
.value
!= error_mark_node
302 && rhs
.value
!= error_mark_node
)
304 enum tree_code code
= NOP_EXPR
;
305 if (VECTOR_TYPE_P (TREE_TYPE (lhs
.value
)))
307 code
= VIEW_CONVERT_EXPR
;
308 rhs
.value
= build1 (VIEW_CONVERT_EXPR
,
309 TREE_TYPE (lhs
.value
), rhs
.value
);
311 else if (FLOAT_TYPE_P (TREE_TYPE (lhs
.value
))
312 && ! FLOAT_TYPE_P (TREE_TYPE (rhs
.value
)))
314 else if (! FLOAT_TYPE_P (TREE_TYPE (lhs
.value
))
315 && FLOAT_TYPE_P (TREE_TYPE (rhs
.value
)))
316 code
= FIX_TRUNC_EXPR
;
317 assign
= gimple_build_assign (lhs
.value
, code
, rhs
.value
);
318 gimple_seq_add_stmt (seq
, assign
);
319 gimple_set_location (assign
, loc
);
324 /* Unary expression. */
325 switch (c_parser_peek_token (parser
)->type
)
329 tree id
= c_parser_peek_token (parser
)->value
;
330 if (strcmp (IDENTIFIER_POINTER (id
), "__ABS") == 0)
331 goto build_unary_expr
;
335 if (c_parser_peek_token (parser
)->keyword
!= RID_REALPART
336 && c_parser_peek_token (parser
)->keyword
!= RID_IMAGPART
)
344 case CPP_MULT
: /* pointer deref */
346 rhs
= c_parser_gimple_unary_expression (parser
);
347 if (rhs
.value
!= error_mark_node
)
349 assign
= gimple_build_assign (lhs
.value
, rhs
.value
);
350 gimple_set_location (assign
, loc
);
351 gimple_seq_add_stmt (seq
, assign
);
358 /* GIMPLE PHI statement. */
359 if (c_parser_next_token_is_keyword (parser
, RID_PHI
))
361 c_parser_consume_token (parser
);
363 if (! c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
366 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
367 c_parser_consume_token (parser
);
369 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_PAREN
))
371 if (c_parser_next_token_is (parser
, CPP_NAME
)
372 && c_parser_peek_2nd_token (parser
)->type
== CPP_COLON
)
374 arg
= lookup_label_for_goto (loc
,
375 c_parser_peek_token (parser
)->value
);
376 c_parser_consume_token (parser
);
378 if (c_parser_next_token_is (parser
, CPP_COLON
))
379 c_parser_consume_token (parser
);
380 vargs
.safe_push (arg
);
382 else if (c_parser_next_token_is (parser
, CPP_COMMA
))
383 c_parser_consume_token (parser
);
386 arg
= c_parser_gimple_unary_expression (parser
).value
;
387 vargs
.safe_push (arg
);
391 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
394 /* Build internal function for PHI. */
395 gcall
*call_stmt
= gimple_build_call_internal_vec (IFN_PHI
, vargs
);
396 gimple_call_set_lhs (call_stmt
, lhs
.value
);
397 gimple_set_location (call_stmt
, UNKNOWN_LOCATION
);
398 gimple_seq_add_stmt (seq
, call_stmt
);
402 /* GIMPLE call with lhs. */
403 if (c_parser_next_token_is (parser
, CPP_NAME
)
404 && c_parser_peek_2nd_token (parser
)->type
== CPP_OPEN_PAREN
405 && lookup_name (c_parser_peek_token (parser
)->value
))
407 rhs
= c_parser_gimple_unary_expression (parser
);
408 if (rhs
.value
!= error_mark_node
)
410 gimple
*call
= gimple_build_call_from_tree (rhs
.value
, NULL
);
411 gimple_call_set_lhs (call
, lhs
.value
);
412 gimple_seq_add_stmt (seq
, call
);
413 gimple_set_location (call
, loc
);
418 rhs
= c_parser_gimple_binary_expression (parser
);
419 if (lhs
.value
!= error_mark_node
420 && rhs
.value
!= error_mark_node
)
422 /* If we parsed a comparison and the next token is a '?' then
423 parse a conditional expression. */
424 if (COMPARISON_CLASS_P (rhs
.value
)
425 && c_parser_next_token_is (parser
, CPP_QUERY
))
427 struct c_expr trueval
, falseval
;
428 c_parser_consume_token (parser
);
429 trueval
= c_parser_gimple_postfix_expression (parser
);
430 falseval
.set_error ();
431 if (c_parser_require (parser
, CPP_COLON
, "expected %<:%>"))
432 falseval
= c_parser_gimple_postfix_expression (parser
);
433 if (trueval
.value
== error_mark_node
434 || falseval
.value
== error_mark_node
)
436 rhs
.value
= build3_loc (loc
, COND_EXPR
, TREE_TYPE (trueval
.value
),
437 rhs
.value
, trueval
.value
, falseval
.value
);
439 assign
= gimple_build_assign (lhs
.value
, rhs
.value
);
440 gimple_seq_add_stmt (seq
, assign
);
441 gimple_set_location (assign
, loc
);
446 /* Parse gimple binary expr.
448 gimple-binary-expression:
449 gimple-unary-expression * gimple-unary-expression
450 gimple-unary-expression / gimple-unary-expression
451 gimple-unary-expression % gimple-unary-expression
452 gimple-unary-expression + gimple-unary-expression
453 gimple-unary-expression - gimple-unary-expression
454 gimple-unary-expression << gimple-unary-expression
455 gimple-unary-expression >> gimple-unary-expression
456 gimple-unary-expression < gimple-unary-expression
457 gimple-unary-expression > gimple-unary-expression
458 gimple-unary-expression <= gimple-unary-expression
459 gimple-unary-expression >= gimple-unary-expression
460 gimple-unary-expression == gimple-unary-expression
461 gimple-unary-expression != gimple-unary-expression
462 gimple-unary-expression & gimple-unary-expression
463 gimple-unary-expression ^ gimple-unary-expression
464 gimple-unary-expression | gimple-unary-expression
469 c_parser_gimple_binary_expression (c_parser
*parser
)
471 /* Location of the binary operator. */
472 struct c_expr ret
, lhs
, rhs
;
473 enum tree_code code
= ERROR_MARK
;
475 lhs
= c_parser_gimple_postfix_expression (parser
);
476 if (c_parser_error (parser
))
478 tree ret_type
= TREE_TYPE (lhs
.value
);
479 switch (c_parser_peek_token (parser
)->type
)
485 code
= TRUNC_DIV_EXPR
;
488 code
= TRUNC_MOD_EXPR
;
491 if (POINTER_TYPE_P (TREE_TYPE (lhs
.value
)))
492 code
= POINTER_PLUS_EXPR
;
507 ret_type
= boolean_type_node
;
511 ret_type
= boolean_type_node
;
515 ret_type
= boolean_type_node
;
519 ret_type
= boolean_type_node
;
523 ret_type
= boolean_type_node
;
527 ret_type
= boolean_type_node
;
539 c_parser_error (parser
, "%<&&%> not valid in GIMPLE");
542 c_parser_error (parser
, "%<||%> not valid in GIMPLE");
545 /* Not a binary expression. */
548 location_t ret_loc
= c_parser_peek_token (parser
)->location
;
549 c_parser_consume_token (parser
);
550 rhs
= c_parser_gimple_postfix_expression (parser
);
551 if (lhs
.value
!= error_mark_node
&& rhs
.value
!= error_mark_node
)
552 ret
.value
= build2_loc (ret_loc
, code
, ret_type
, lhs
.value
, rhs
.value
);
556 /* Parse gimple unary expression.
558 gimple-unary-expression:
559 gimple-postfix-expression
560 unary-operator gimple-postfix-expression
562 unary-operator: one of
567 c_parser_gimple_unary_expression (c_parser
*parser
)
569 struct c_expr ret
, op
;
570 location_t op_loc
= c_parser_peek_token (parser
)->location
;
573 switch (c_parser_peek_token (parser
)->type
)
576 c_parser_consume_token (parser
);
577 op
= c_parser_gimple_postfix_expression (parser
);
578 mark_exp_read (op
.value
);
579 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
582 c_parser_consume_token (parser
);
583 op
= c_parser_gimple_postfix_expression (parser
);
584 if (op
.value
== error_mark_node
)
586 if (! POINTER_TYPE_P (TREE_TYPE (op
.value
)))
588 error_at (op_loc
, "expected pointer as argument of unary %<*%>");
591 finish
= op
.get_finish ();
592 location_t combined_loc
= make_location (op_loc
, op_loc
, finish
);
593 ret
.value
= build_simple_mem_ref_loc (combined_loc
, op
.value
);
594 TREE_SIDE_EFFECTS (ret
.value
)
595 = TREE_THIS_VOLATILE (ret
.value
)
596 = TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (op
.value
)));
597 ret
.src_range
.m_start
= op_loc
;
598 ret
.src_range
.m_finish
= finish
;
602 c_parser_consume_token (parser
);
603 op
= c_parser_gimple_postfix_expression (parser
);
604 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
606 c_parser_consume_token (parser
);
607 op
= c_parser_gimple_postfix_expression (parser
);
608 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
610 c_parser_consume_token (parser
);
611 op
= c_parser_gimple_postfix_expression (parser
);
612 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
614 c_parser_error (parser
, "%<!%> not valid in GIMPLE");
617 switch (c_parser_peek_token (parser
)->keyword
)
620 c_parser_consume_token (parser
);
621 op
= c_parser_gimple_postfix_expression (parser
);
622 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
624 c_parser_consume_token (parser
);
625 op
= c_parser_gimple_postfix_expression (parser
);
626 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
628 return c_parser_gimple_postfix_expression (parser
);
632 tree id
= c_parser_peek_token (parser
)->value
;
633 if (strcmp (IDENTIFIER_POINTER (id
), "__ABS") == 0)
635 c_parser_consume_token (parser
);
636 op
= c_parser_gimple_postfix_expression (parser
);
637 return parser_build_unary_op (op_loc
, ABS_EXPR
, op
);
640 return c_parser_gimple_postfix_expression (parser
);
643 return c_parser_gimple_postfix_expression (parser
);
647 /* Decompose ID into base name (ID until ver_offset) and VERSION. Return
648 true if ID matches a SSA name. */
651 c_parser_parse_ssa_name_id (tree id
, unsigned *version
, unsigned *ver_offset
)
653 const char *token
= IDENTIFIER_POINTER (id
);
654 const char *var_version
= strrchr (token
, '_');
658 *ver_offset
= var_version
- token
;
659 for (const char *p
= var_version
+ 1; *p
; ++p
)
662 *version
= atoi (var_version
+ 1);
666 /* Get at the actual SSA name ID with VERSION starting at VER_OFFSET.
667 TYPE is the type if the SSA name is being declared. */
670 c_parser_parse_ssa_name (c_parser
*parser
,
671 tree id
, tree type
, unsigned version
,
674 tree name
= NULL_TREE
;
675 const char *token
= IDENTIFIER_POINTER (id
);
679 /* Anonymous unnamed SSA name. */
680 if (version
< num_ssa_names
)
681 name
= ssa_name (version
);
686 c_parser_error (parser
, "SSA name undeclared");
687 return error_mark_node
;
689 name
= make_ssa_name_fn (cfun
, type
, NULL
, version
);
694 if (version
< num_ssa_names
)
695 name
= ssa_name (version
);
698 /* Separate var name from version. */
699 char *var_name
= XNEWVEC (char, ver_offset
+ 1);
700 memcpy (var_name
, token
, ver_offset
);
701 var_name
[ver_offset
] = '\0';
702 /* lookup for parent decl. */
703 id
= get_identifier (var_name
);
704 tree parent
= lookup_name (id
);
705 XDELETEVEC (var_name
);
706 if (! parent
|| parent
== error_mark_node
)
708 c_parser_error (parser
, "base variable or SSA name undeclared");
709 return error_mark_node
;
712 || TREE_CODE (parent
) == PARM_DECL
713 || TREE_CODE (parent
) == RESULT_DECL
))
715 error ("invalid base %qE for SSA name", parent
);
716 return error_mark_node
;
718 if (VECTOR_TYPE_P (TREE_TYPE (parent
))
719 || TREE_CODE (TREE_TYPE (parent
)) == COMPLEX_TYPE
)
720 DECL_GIMPLE_REG_P (parent
) = 1;
721 name
= make_ssa_name_fn (cfun
, parent
,
722 gimple_build_nop (), version
);
729 /* Parse gimple postfix expression.
731 gimple-postfix-expression:
732 gimple-primary-expression
733 gimple-primary-xpression [ gimple-primary-expression ]
734 gimple-primary-expression ( gimple-argument-expression-list[opt] )
735 postfix-expression . identifier
736 postfix-expression -> identifier
738 gimple-argument-expression-list:
739 gimple-unary-expression
740 gimple-argument-expression-list , gimple-unary-expression
742 gimple-primary-expression:
750 c_parser_gimple_postfix_expression (c_parser
*parser
)
752 location_t loc
= c_parser_peek_token (parser
)->location
;
753 source_range tok_range
= c_parser_peek_token (parser
)->get_range ();
756 switch (c_parser_peek_token (parser
)->type
)
759 expr
.value
= c_parser_peek_token (parser
)->value
;
760 set_c_expr_source_range (&expr
, tok_range
);
761 loc
= c_parser_peek_token (parser
)->location
;
762 c_parser_consume_token (parser
);
768 expr
.value
= c_parser_peek_token (parser
)->value
;
769 set_c_expr_source_range (&expr
, tok_range
);
770 c_parser_consume_token (parser
);
777 expr
.value
= c_parser_peek_token (parser
)->value
;
778 set_c_expr_source_range (&expr
, tok_range
);
779 expr
.original_code
= STRING_CST
;
780 c_parser_consume_token (parser
);
783 if (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
785 tree id
= c_parser_peek_token (parser
)->value
;
786 if (strcmp (IDENTIFIER_POINTER (id
), "__MEM") == 0)
788 /* __MEM '<' type-name [ ',' number ] '>'
789 '(' [ '(' type-name ')' ] unary-expression
790 [ '+' number ] ')' */
791 location_t loc
= c_parser_peek_token (parser
)->location
;
792 c_parser_consume_token (parser
);
793 struct c_type_name
*type_name
= NULL
;
794 tree alignment
= NULL_TREE
;
795 if (c_parser_require (parser
, CPP_LESS
, "expected %<<%>"))
797 type_name
= c_parser_type_name (parser
);
798 /* Optional alignment. */
799 if (c_parser_next_token_is (parser
, CPP_COMMA
))
801 c_parser_consume_token (parser
);
803 = c_parser_gimple_postfix_expression (parser
).value
;
805 c_parser_skip_until_found (parser
,
806 CPP_GREATER
, "expected %<>%>");
809 ptr
.value
= error_mark_node
;
810 tree alias_off
= NULL_TREE
;
811 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
813 tree alias_type
= NULL_TREE
;
814 /* Optional alias-type cast. */
815 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
817 c_parser_consume_token (parser
);
818 struct c_type_name
*alias_type_name
819 = c_parser_type_name (parser
);
820 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
825 alias_type
= groktypename (alias_type_name
,
829 ptr
= c_parser_gimple_unary_expression (parser
);
830 if (ptr
.value
== error_mark_node
831 || ! POINTER_TYPE_P (TREE_TYPE (ptr
.value
)))
833 if (ptr
.value
!= error_mark_node
)
834 error_at (ptr
.get_start (),
835 "invalid type of %<__MEM%> operand");
836 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
841 alias_type
= TREE_TYPE (ptr
.value
);
842 /* Optional constant offset. */
843 if (c_parser_next_token_is (parser
, CPP_PLUS
))
845 c_parser_consume_token (parser
);
847 = c_parser_gimple_postfix_expression (parser
).value
;
848 alias_off
= fold_convert (alias_type
, alias_off
);
851 alias_off
= build_int_cst (alias_type
, 0);
852 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
855 if (! type_name
|| c_parser_error (parser
))
857 c_parser_set_error (parser
, false);
860 tree tem
= NULL_TREE
;
861 tree type
= groktypename (type_name
, &tem
, NULL
);
863 type
= build_aligned_type (type
, tree_to_uhwi (alignment
));
864 expr
.value
= build2_loc (loc
, MEM_REF
,
865 type
, ptr
.value
, alias_off
);
868 else if (strcmp (IDENTIFIER_POINTER (id
), "_Literal") == 0)
870 /* _Literal '(' type-name ')' [ '-' ] constant */
871 c_parser_consume_token (parser
);
872 tree type
= NULL_TREE
;
873 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
875 struct c_type_name
*type_name
= c_parser_type_name (parser
);
878 type
= groktypename (type_name
, &tem
, NULL
);
879 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
883 if ((neg_p
= c_parser_next_token_is (parser
, CPP_MINUS
)))
884 c_parser_consume_token (parser
);
885 tree val
= c_parser_gimple_postfix_expression (parser
).value
;
888 || val
== error_mark_node
889 || ! CONSTANT_CLASS_P (val
))
891 c_parser_error (parser
, "invalid _Literal");
896 val
= const_unop (NEGATE_EXPR
, TREE_TYPE (val
), val
);
899 c_parser_error (parser
, "invalid _Literal");
903 expr
.value
= fold_convert (type
, val
);
906 else if (strcmp (IDENTIFIER_POINTER (id
), "__FMA") == 0)
908 c_parser_consume_token (parser
);
911 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
913 c_parser_gimple_expr_list (parser
, &args
);
914 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
917 if (args
.length () != 3)
919 error_at (loc
, "invalid number of operands to __FMA");
920 expr
.value
= error_mark_node
;
923 expr
.value
= build3_loc (loc
, FMA_EXPR
, TREE_TYPE (args
[0]),
924 args
[0], args
[1], args
[2]);
929 unsigned version
, ver_offset
;
930 if (! lookup_name (id
)
931 && c_parser_parse_ssa_name_id (id
, &version
, &ver_offset
))
933 c_parser_consume_token (parser
);
934 expr
.value
= c_parser_parse_ssa_name (parser
, id
, NULL_TREE
,
935 version
, ver_offset
);
936 if (expr
.value
== error_mark_node
)
938 set_c_expr_source_range (&expr
, tok_range
);
939 /* For default definition SSA names. */
940 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
941 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
944 (c_parser_peek_2nd_token (parser
)->value
)) == 0
945 && c_parser_peek_nth_token (parser
, 3)->type
== CPP_CLOSE_PAREN
)
947 c_parser_consume_token (parser
);
948 c_parser_consume_token (parser
);
949 c_parser_consume_token (parser
);
950 if (! SSA_NAME_IS_DEFAULT_DEF (expr
.value
))
952 if (!SSA_NAME_VAR (expr
.value
))
954 error_at (loc
, "anonymous SSA name cannot have"
955 " default definition");
956 expr
.value
= error_mark_node
;
959 set_ssa_default_def (cfun
, SSA_NAME_VAR (expr
.value
),
961 SSA_NAME_DEF_STMT (expr
.value
) = gimple_build_nop ();
967 c_parser_consume_token (parser
);
969 = build_external_ref (loc
, id
,
970 (c_parser_peek_token (parser
)->type
971 == CPP_OPEN_PAREN
), &expr
.original_type
);
972 set_c_expr_source_range (&expr
, tok_range
);
978 c_parser_error (parser
, "expected expression");
984 c_parser_error (parser
, "expected expression");
988 return c_parser_gimple_postfix_expression_after_primary
989 (parser
, EXPR_LOC_OR_LOC (expr
.value
, loc
), expr
);
992 /* Parse a gimple postfix expression after the initial primary or compound
996 c_parser_gimple_postfix_expression_after_primary (c_parser
*parser
,
1003 location_t comp_loc
;
1007 location_t op_loc
= c_parser_peek_token (parser
)->location
;
1008 switch (c_parser_peek_token (parser
)->type
)
1010 case CPP_OPEN_SQUARE
:
1012 c_parser_consume_token (parser
);
1013 tree idx
= c_parser_gimple_unary_expression (parser
).value
;
1015 if (! c_parser_require (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>"))
1017 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
1021 start
= expr
.get_start ();
1022 finish
= c_parser_tokens_buf (parser
, 0)->location
;
1023 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
1024 set_c_expr_source_range (&expr
, start
, finish
);
1026 expr
.original_code
= ERROR_MARK
;
1027 expr
.original_type
= NULL
;
1030 case CPP_OPEN_PAREN
:
1032 /* Function call. */
1033 c_parser_consume_token (parser
);
1034 auto_vec
<tree
> exprlist
;
1035 if (! c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
1036 c_parser_gimple_expr_list (parser
, &exprlist
);
1037 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1039 expr
.value
= build_call_array_loc
1040 (expr_loc
, TREE_TYPE (TREE_TYPE (expr
.value
)),
1041 expr
.value
, exprlist
.length (), exprlist
.address ());
1042 expr
.original_code
= ERROR_MARK
;
1043 expr
.original_type
= NULL
;
1048 /* Structure element reference. */
1049 c_parser_consume_token (parser
);
1050 if (c_parser_next_token_is (parser
, CPP_NAME
))
1052 c_token
*comp_tok
= c_parser_peek_token (parser
);
1053 ident
= comp_tok
->value
;
1054 comp_loc
= comp_tok
->location
;
1058 c_parser_error (parser
, "expected identifier");
1060 expr
.original_code
= ERROR_MARK
;
1061 expr
.original_type
= NULL
;
1064 start
= expr
.get_start ();
1065 finish
= c_parser_peek_token (parser
)->get_finish ();
1066 c_parser_consume_token (parser
);
1067 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
,
1069 set_c_expr_source_range (&expr
, start
, finish
);
1070 expr
.original_code
= ERROR_MARK
;
1071 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
1072 expr
.original_type
= NULL
;
1075 /* Remember the original type of a bitfield. */
1076 tree field
= TREE_OPERAND (expr
.value
, 1);
1077 if (TREE_CODE (field
) != FIELD_DECL
)
1078 expr
.original_type
= NULL
;
1080 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
1086 /* Structure element reference. */
1087 c_parser_consume_token (parser
);
1088 if (c_parser_next_token_is (parser
, CPP_NAME
))
1090 c_token
*comp_tok
= c_parser_peek_token (parser
);
1091 ident
= comp_tok
->value
;
1092 comp_loc
= comp_tok
->location
;
1096 c_parser_error (parser
, "expected identifier");
1098 expr
.original_code
= ERROR_MARK
;
1099 expr
.original_type
= NULL
;
1102 start
= expr
.get_start ();
1103 finish
= c_parser_peek_token (parser
)->get_finish ();
1104 c_parser_consume_token (parser
);
1105 expr
.value
= build_component_ref (op_loc
,
1106 build_simple_mem_ref_loc
1107 (op_loc
, expr
.value
),
1109 set_c_expr_source_range (&expr
, start
, finish
);
1110 expr
.original_code
= ERROR_MARK
;
1111 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
1112 expr
.original_type
= NULL
;
1115 /* Remember the original type of a bitfield. */
1116 tree field
= TREE_OPERAND (expr
.value
, 1);
1117 if (TREE_CODE (field
) != FIELD_DECL
)
1118 expr
.original_type
= NULL
;
1120 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
1130 /* Parse expression list.
1133 gimple-unary-expression
1134 gimple-expr-list , gimple-unary-expression
1139 c_parser_gimple_expr_list (c_parser
*parser
, vec
<tree
> *ret
)
1143 expr
= c_parser_gimple_unary_expression (parser
);
1144 ret
->safe_push (expr
.value
);
1145 while (c_parser_next_token_is (parser
, CPP_COMMA
))
1147 c_parser_consume_token (parser
);
1148 expr
= c_parser_gimple_unary_expression (parser
);
1149 ret
->safe_push (expr
.value
);
1153 /* Parse gimple label.
1157 case constant-expression :
1163 c_parser_gimple_label (c_parser
*parser
, gimple_seq
*seq
)
1165 tree name
= c_parser_peek_token (parser
)->value
;
1166 location_t loc1
= c_parser_peek_token (parser
)->location
;
1167 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
1168 c_parser_consume_token (parser
);
1169 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
1170 c_parser_consume_token (parser
);
1171 tree label
= define_label (loc1
, name
);
1172 gimple_seq_add_stmt (seq
, gimple_build_label (label
));
1176 /* Parse gimple/RTL pass list.
1178 gimple-or-rtl-pass-list:
1179 startwith("pass-name")
1183 c_parser_gimple_or_rtl_pass_list (c_parser
*parser
)
1187 /* Accept __GIMPLE/__RTL. */
1188 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
1190 c_parser_consume_token (parser
);
1192 if (c_parser_next_token_is (parser
, CPP_NAME
))
1194 const char *op
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
1195 c_parser_consume_token (parser
);
1196 if (! strcmp (op
, "startwith"))
1198 if (! c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1200 if (c_parser_next_token_is_not (parser
, CPP_STRING
))
1202 error_at (c_parser_peek_token (parser
)->location
,
1203 "expected pass name");
1206 pass
= xstrdup (TREE_STRING_POINTER
1207 (c_parser_peek_token (parser
)->value
));
1208 c_parser_consume_token (parser
);
1209 if (! c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
1214 error_at (c_parser_peek_token (parser
)->location
,
1215 "invalid operation");
1220 if (! c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
1226 /* Parse gimple local declaration.
1228 declaration-specifiers:
1229 storage-class-specifier declaration-specifiers[opt]
1230 type-specifier declaration-specifiers[opt]
1231 type-qualifier declaration-specifiers[opt]
1232 function-specifier declaration-specifiers[opt]
1233 alignment-specifier declaration-specifiers[opt]
1235 storage-class-specifier:
1259 address-space-qualifier
1265 c_parser_gimple_declaration (c_parser
*parser
)
1267 struct c_declarator
*declarator
;
1268 struct c_declspecs
*specs
= build_null_declspecs ();
1269 c_parser_declspecs (parser
, specs
, true, true, true,
1270 true, true, cla_nonabstract_decl
);
1271 finish_declspecs (specs
);
1273 /* Provide better error recovery. Note that a type name here is usually
1274 better diagnosed as a redeclaration. */
1275 if (c_parser_next_token_starts_declspecs (parser
)
1276 && ! c_parser_next_token_is (parser
, CPP_NAME
))
1278 c_parser_error (parser
, "expected %<;%>");
1279 c_parser_set_error (parser
, false);
1284 declarator
= c_parser_declarator (parser
,
1285 specs
->typespec_kind
!= ctsk_none
,
1286 C_DTR_NORMAL
, &dummy
);
1288 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1290 /* Handle SSA name decls specially, they do not go into the identifier
1291 table but we simply build the SSA name for later lookup. */
1292 unsigned version
, ver_offset
;
1293 if (declarator
->kind
== cdk_id
1294 && is_gimple_reg_type (specs
->type
)
1295 && c_parser_parse_ssa_name_id (declarator
->u
.id
,
1296 &version
, &ver_offset
)
1297 /* The following restricts it to unnamed anonymous SSA names
1298 which fails parsing of named ones in dumps (we could
1299 decide to not dump their name for -gimple). */
1301 c_parser_parse_ssa_name (parser
, declarator
->u
.id
, specs
->type
,
1302 version
, ver_offset
);
1305 tree postfix_attrs
= NULL_TREE
;
1306 tree all_prefix_attrs
= specs
->attrs
;
1307 specs
->attrs
= NULL
;
1308 tree decl
= start_decl (declarator
, specs
, false,
1309 chainon (postfix_attrs
, all_prefix_attrs
));
1311 finish_decl (decl
, UNKNOWN_LOCATION
, NULL_TREE
, NULL_TREE
,
1317 c_parser_error (parser
, "expected %<;%>");
1322 /* Parse gimple goto statement. */
1325 c_parser_gimple_goto_stmt (location_t loc
, tree label
, gimple_seq
*seq
)
1327 tree decl
= lookup_label_for_goto (loc
, label
);
1328 gimple_seq_add_stmt (seq
, gimple_build_goto (decl
));
1332 /* Parse a parenthesized condition.
1334 ( gimple-binary-expression ) */
1337 c_parser_gimple_paren_condition (c_parser
*parser
)
1339 if (! c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1340 return error_mark_node
;
1341 tree cond
= c_parser_gimple_binary_expression (parser
).value
;
1342 if (! c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
1343 return error_mark_node
;
1347 /* Parse gimple if-else statement.
1350 if ( gimple-binary-expression ) gimple-goto-statement
1351 if ( gimple-binary-expression ) gimple-goto-statement \
1352 else gimple-goto-statement
1356 c_parser_gimple_if_stmt (c_parser
*parser
, gimple_seq
*seq
)
1358 tree t_label
, f_label
, label
;
1360 c_parser_consume_token (parser
);
1361 tree cond
= c_parser_gimple_paren_condition (parser
);
1363 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
1365 loc
= c_parser_peek_token (parser
)->location
;
1366 c_parser_consume_token (parser
);
1367 if (! c_parser_next_token_is (parser
, CPP_NAME
))
1369 c_parser_error (parser
, "expected label");
1372 label
= c_parser_peek_token (parser
)->value
;
1373 c_parser_consume_token (parser
);
1374 t_label
= lookup_label_for_goto (loc
, label
);
1375 if (! c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1380 c_parser_error (parser
, "expected goto expression");
1384 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
1385 c_parser_consume_token (parser
);
1388 c_parser_error (parser
, "expected else statement");
1392 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
1394 loc
= c_parser_peek_token (parser
)->location
;
1395 c_parser_consume_token (parser
);
1396 if (! c_parser_next_token_is (parser
, CPP_NAME
))
1398 c_parser_error (parser
, "expected label");
1401 label
= c_parser_peek_token (parser
)->value
;
1402 f_label
= lookup_label_for_goto (loc
, label
);
1403 c_parser_consume_token (parser
);
1404 if (! c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1409 c_parser_error (parser
, "expected goto expression");
1413 if (cond
!= error_mark_node
)
1414 gimple_seq_add_stmt (seq
, gimple_build_cond_from_tree (cond
, t_label
,
1418 /* Parse gimple switch-statement.
1420 gimple-switch-statement:
1421 switch (gimple-postfix-expression) gimple-case-statement
1423 gimple-case-statement:
1424 gimple-case-statement
1425 gimple-label-statement : gimple-goto-statment
1429 c_parser_gimple_switch_stmt (c_parser
*parser
, gimple_seq
*seq
)
1432 tree case_label
, label
;
1433 auto_vec
<tree
> labels
;
1434 tree default_label
= NULL_TREE
;
1435 gimple_seq switch_body
= NULL
;
1436 c_parser_consume_token (parser
);
1438 if (! c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1440 cond_expr
= c_parser_gimple_postfix_expression (parser
);
1441 if (! c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
1444 if (! c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
1447 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
1449 if (c_parser_next_token_is (parser
, CPP_EOF
))
1451 c_parser_error (parser
, "expected statement");
1455 switch (c_parser_peek_token (parser
)->keyword
)
1460 location_t loc
= c_parser_peek_token (parser
)->location
;
1461 c_parser_consume_token (parser
);
1463 if (c_parser_next_token_is (parser
, CPP_NAME
)
1464 || c_parser_peek_token (parser
)->type
== CPP_NUMBER
)
1465 exp1
= c_parser_gimple_postfix_expression (parser
);
1468 c_parser_error (parser
, "expected expression");
1472 if (c_parser_next_token_is (parser
, CPP_COLON
))
1474 c_parser_consume_token (parser
);
1475 if (c_parser_next_token_is (parser
, CPP_NAME
))
1477 label
= c_parser_peek_token (parser
)->value
;
1478 c_parser_consume_token (parser
);
1479 tree decl
= lookup_label_for_goto (loc
, label
);
1480 case_label
= build_case_label (exp1
.value
, NULL_TREE
,
1482 labels
.safe_push (case_label
);
1483 if (! c_parser_require (parser
, CPP_SEMICOLON
,
1487 else if (! c_parser_require (parser
, CPP_NAME
,
1491 else if (! c_parser_require (parser
, CPP_SEMICOLON
,
1498 location_t loc
= c_parser_peek_token (parser
)->location
;
1499 c_parser_consume_token (parser
);
1500 if (c_parser_next_token_is (parser
, CPP_COLON
))
1502 c_parser_consume_token (parser
);
1503 if (c_parser_next_token_is (parser
, CPP_NAME
))
1505 label
= c_parser_peek_token (parser
)->value
;
1506 c_parser_consume_token (parser
);
1507 tree decl
= lookup_label_for_goto (loc
, label
);
1508 default_label
= build_case_label (NULL_TREE
, NULL_TREE
,
1510 if (! c_parser_require (parser
, CPP_SEMICOLON
,
1514 else if (! c_parser_require (parser
, CPP_NAME
,
1518 else if (! c_parser_require (parser
, CPP_SEMICOLON
,
1525 location_t loc
= c_parser_peek_token (parser
)->location
;
1526 c_parser_consume_token (parser
);
1527 if (c_parser_next_token_is (parser
, CPP_NAME
))
1529 c_parser_gimple_goto_stmt (loc
,
1533 c_parser_consume_token (parser
);
1534 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1535 c_parser_consume_token (parser
);
1538 c_parser_error (parser
, "expected semicolon");
1542 else if (! c_parser_require (parser
, CPP_NAME
,
1548 c_parser_error (parser
, "expected case label or goto statement");
1553 if (! c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>"))
1556 if (cond_expr
.value
!= error_mark_node
)
1558 gimple_seq_add_stmt (seq
, gimple_build_switch (cond_expr
.value
,
1559 default_label
, labels
));
1560 gimple_seq_add_seq (seq
, switch_body
);
1564 /* Parse gimple return statement. */
1567 c_parser_gimple_return_stmt (c_parser
*parser
, gimple_seq
*seq
)
1569 location_t loc
= c_parser_peek_token (parser
)->location
;
1571 c_parser_consume_token (parser
);
1572 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1574 c_finish_gimple_return (loc
, NULL_TREE
);
1575 ret
= gimple_build_return (NULL
);
1576 gimple_seq_add_stmt (seq
, ret
);
1580 location_t xloc
= c_parser_peek_token (parser
)->location
;
1581 c_expr expr
= c_parser_gimple_unary_expression (parser
);
1582 if (expr
.value
!= error_mark_node
)
1584 c_finish_gimple_return (xloc
, expr
.value
);
1585 ret
= gimple_build_return (expr
.value
);
1586 gimple_seq_add_stmt (seq
, ret
);
1591 /* Support function for c_parser_gimple_return_stmt. */
1594 c_finish_gimple_return (location_t loc
, tree retval
)
1596 tree valtype
= TREE_TYPE (TREE_TYPE (current_function_decl
));
1598 /* Use the expansion point to handle cases such as returning NULL
1599 in a function returning void. */
1600 source_location xloc
= expansion_point_location_if_in_system_header (loc
);
1602 if (TREE_THIS_VOLATILE (current_function_decl
))
1603 warning_at (xloc
, 0,
1604 "function declared %<noreturn%> has a %<return%> statement");
1607 current_function_returns_null
= 1;
1608 else if (valtype
== 0 || TREE_CODE (valtype
) == VOID_TYPE
)
1610 current_function_returns_null
= 1;
1611 if (TREE_CODE (TREE_TYPE (retval
)) != VOID_TYPE
)
1614 (xloc
, "%<return%> with a value, in function returning void");
1615 inform (DECL_SOURCE_LOCATION (current_function_decl
),
1619 else if (TREE_CODE (valtype
) != TREE_CODE (TREE_TYPE (retval
)))
1622 (xloc
, "invalid conversion in return statement");
1623 inform (DECL_SOURCE_LOCATION (current_function_decl
),