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"
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
);
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
);
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 assign
= gimple_build_assign (lhs
.value
, rhs
.value
);
423 gimple_seq_add_stmt (seq
, assign
);
424 gimple_set_location (assign
, loc
);
429 /* Parse gimple binary expr.
431 gimple-binary-expression:
432 gimple-unary-expression * gimple-unary-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
452 c_parser_gimple_binary_expression (c_parser
*parser
)
454 /* Location of the binary operator. */
455 struct c_expr ret
, lhs
, rhs
;
456 enum tree_code code
= ERROR_MARK
;
458 lhs
= c_parser_gimple_postfix_expression (parser
);
459 if (c_parser_error (parser
))
461 tree ret_type
= TREE_TYPE (lhs
.value
);
462 switch (c_parser_peek_token (parser
)->type
)
468 code
= TRUNC_DIV_EXPR
;
471 code
= TRUNC_MOD_EXPR
;
474 if (POINTER_TYPE_P (TREE_TYPE (lhs
.value
)))
475 code
= POINTER_PLUS_EXPR
;
490 ret_type
= boolean_type_node
;
494 ret_type
= boolean_type_node
;
498 ret_type
= boolean_type_node
;
502 ret_type
= boolean_type_node
;
506 ret_type
= boolean_type_node
;
510 ret_type
= boolean_type_node
;
522 c_parser_error (parser
, "%<&&%> not valid in GIMPLE");
525 c_parser_error (parser
, "%<||%> not valid in GIMPLE");
528 /* Not a binary expression. */
531 location_t ret_loc
= c_parser_peek_token (parser
)->location
;
532 c_parser_consume_token (parser
);
533 rhs
= c_parser_gimple_postfix_expression (parser
);
534 if (lhs
.value
!= error_mark_node
&& rhs
.value
!= error_mark_node
)
535 ret
.value
= build2_loc (ret_loc
, code
, ret_type
, lhs
.value
, rhs
.value
);
539 /* Parse gimple unary expression.
541 gimple-unary-expression:
542 gimple-postfix-expression
543 unary-operator gimple-postfix-expression
545 unary-operator: one of
550 c_parser_gimple_unary_expression (c_parser
*parser
)
552 struct c_expr ret
, op
;
553 location_t op_loc
= c_parser_peek_token (parser
)->location
;
556 switch (c_parser_peek_token (parser
)->type
)
559 c_parser_consume_token (parser
);
560 op
= c_parser_gimple_postfix_expression (parser
);
561 mark_exp_read (op
.value
);
562 return parser_build_unary_op (op_loc
, ADDR_EXPR
, op
);
565 c_parser_consume_token (parser
);
566 op
= c_parser_gimple_postfix_expression (parser
);
567 if (op
.value
== error_mark_node
)
569 if (! POINTER_TYPE_P (TREE_TYPE (op
.value
)))
571 error_at (op_loc
, "expected pointer as argument of unary %<*%>");
574 finish
= op
.get_finish ();
575 location_t combined_loc
= make_location (op_loc
, op_loc
, finish
);
576 ret
.value
= build_simple_mem_ref_loc (combined_loc
, op
.value
);
577 TREE_SIDE_EFFECTS (ret
.value
)
578 = TREE_THIS_VOLATILE (ret
.value
)
579 = TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (op
.value
)));
580 ret
.src_range
.m_start
= op_loc
;
581 ret
.src_range
.m_finish
= finish
;
585 c_parser_consume_token (parser
);
586 op
= c_parser_gimple_postfix_expression (parser
);
587 return parser_build_unary_op (op_loc
, CONVERT_EXPR
, op
);
589 c_parser_consume_token (parser
);
590 op
= c_parser_gimple_postfix_expression (parser
);
591 return parser_build_unary_op (op_loc
, NEGATE_EXPR
, op
);
593 c_parser_consume_token (parser
);
594 op
= c_parser_gimple_postfix_expression (parser
);
595 return parser_build_unary_op (op_loc
, BIT_NOT_EXPR
, op
);
597 c_parser_error (parser
, "%<!%> not valid in GIMPLE");
600 switch (c_parser_peek_token (parser
)->keyword
)
603 c_parser_consume_token (parser
);
604 op
= c_parser_gimple_postfix_expression (parser
);
605 return parser_build_unary_op (op_loc
, REALPART_EXPR
, op
);
607 c_parser_consume_token (parser
);
608 op
= c_parser_gimple_postfix_expression (parser
);
609 return parser_build_unary_op (op_loc
, IMAGPART_EXPR
, op
);
611 return c_parser_gimple_postfix_expression (parser
);
615 tree id
= c_parser_peek_token (parser
)->value
;
616 if (strcmp (IDENTIFIER_POINTER (id
), "__ABS") == 0)
618 c_parser_consume_token (parser
);
619 op
= c_parser_gimple_postfix_expression (parser
);
620 return parser_build_unary_op (op_loc
, ABS_EXPR
, op
);
623 return c_parser_gimple_postfix_expression (parser
);
626 return c_parser_gimple_postfix_expression (parser
);
630 /* Decompose ID into base name (ID until ver_offset) and VERSION. Return
631 true if ID matches a SSA name. */
634 c_parser_parse_ssa_name_id (tree id
, unsigned *version
, unsigned *ver_offset
)
636 const char *token
= IDENTIFIER_POINTER (id
);
637 const char *var_version
= strrchr (token
, '_');
641 *ver_offset
= var_version
- token
;
642 for (const char *p
= var_version
+ 1; *p
; ++p
)
645 *version
= atoi (var_version
+ 1);
649 /* Get at the actual SSA name ID with VERSION starting at VER_OFFSET.
650 TYPE is the type if the SSA name is being declared. */
653 c_parser_parse_ssa_name (c_parser
*parser
,
654 tree id
, tree type
, unsigned version
,
657 tree name
= NULL_TREE
;
658 const char *token
= IDENTIFIER_POINTER (id
);
662 /* Anonymous unnamed SSA name. */
663 if (version
< num_ssa_names
)
664 name
= ssa_name (version
);
669 c_parser_error (parser
, "SSA name undeclared");
670 return error_mark_node
;
672 name
= make_ssa_name_fn (cfun
, type
, NULL
, version
);
677 if (version
< num_ssa_names
)
678 name
= ssa_name (version
);
681 /* Separate var name from version. */
682 char *var_name
= XNEWVEC (char, ver_offset
+ 1);
683 memcpy (var_name
, token
, ver_offset
);
684 var_name
[ver_offset
] = '\0';
685 /* lookup for parent decl. */
686 id
= get_identifier (var_name
);
687 tree parent
= lookup_name (id
);
688 XDELETEVEC (var_name
);
689 if (! parent
|| parent
== error_mark_node
)
691 c_parser_error (parser
, "base variable or SSA name undeclared");
692 return error_mark_node
;
695 || TREE_CODE (parent
) == PARM_DECL
696 || TREE_CODE (parent
) == RESULT_DECL
))
698 error ("invalid base %qE for SSA name", parent
);
699 return error_mark_node
;
701 if (VECTOR_TYPE_P (TREE_TYPE (parent
))
702 || TREE_CODE (TREE_TYPE (parent
)) == COMPLEX_TYPE
)
703 DECL_GIMPLE_REG_P (parent
) = 1;
704 name
= make_ssa_name_fn (cfun
, parent
,
705 gimple_build_nop (), version
);
712 /* Parse gimple postfix expression.
714 gimple-postfix-expression:
715 gimple-primary-expression
716 gimple-primary-xpression [ gimple-primary-expression ]
717 gimple-primary-expression ( gimple-argument-expression-list[opt] )
718 postfix-expression . identifier
719 postfix-expression -> identifier
721 gimple-argument-expression-list:
722 gimple-unary-expression
723 gimple-argument-expression-list , gimple-unary-expression
725 gimple-primary-expression:
733 c_parser_gimple_postfix_expression (c_parser
*parser
)
735 location_t loc
= c_parser_peek_token (parser
)->location
;
736 source_range tok_range
= c_parser_peek_token (parser
)->get_range ();
739 switch (c_parser_peek_token (parser
)->type
)
742 expr
.value
= c_parser_peek_token (parser
)->value
;
743 set_c_expr_source_range (&expr
, tok_range
);
744 loc
= c_parser_peek_token (parser
)->location
;
745 c_parser_consume_token (parser
);
751 expr
.value
= c_parser_peek_token (parser
)->value
;
752 set_c_expr_source_range (&expr
, tok_range
);
753 c_parser_consume_token (parser
);
760 expr
.value
= c_parser_peek_token (parser
)->value
;
761 set_c_expr_source_range (&expr
, tok_range
);
762 expr
.original_code
= STRING_CST
;
763 c_parser_consume_token (parser
);
766 if (c_parser_peek_token (parser
)->id_kind
== C_ID_ID
)
768 tree id
= c_parser_peek_token (parser
)->value
;
769 if (strcmp (IDENTIFIER_POINTER (id
), "__MEM") == 0)
771 /* __MEM '<' type-name [ ',' number ] '>'
772 '(' [ '(' type-name ')' ] unary-expression
773 [ '+' number ] ')' */
774 location_t loc
= c_parser_peek_token (parser
)->location
;
775 c_parser_consume_token (parser
);
776 struct c_type_name
*type_name
= NULL
;
777 tree alignment
= NULL_TREE
;
778 if (c_parser_require (parser
, CPP_LESS
, "expected %<<%>"))
780 type_name
= c_parser_type_name (parser
);
781 /* Optional alignment. */
782 if (c_parser_next_token_is (parser
, CPP_COMMA
))
784 c_parser_consume_token (parser
);
786 = c_parser_gimple_postfix_expression (parser
).value
;
788 c_parser_skip_until_found (parser
,
789 CPP_GREATER
, "expected %<>%>");
792 ptr
.value
= error_mark_node
;
793 tree alias_off
= NULL_TREE
;
794 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
796 tree alias_type
= NULL_TREE
;
797 /* Optional alias-type cast. */
798 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
))
800 c_parser_consume_token (parser
);
801 struct c_type_name
*alias_type_name
802 = c_parser_type_name (parser
);
803 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
808 alias_type
= groktypename (alias_type_name
,
812 ptr
= c_parser_gimple_unary_expression (parser
);
813 if (ptr
.value
== error_mark_node
814 || ! POINTER_TYPE_P (TREE_TYPE (ptr
.value
)))
816 if (ptr
.value
!= error_mark_node
)
817 error_at (ptr
.get_start (),
818 "invalid type of %<__MEM%> operand");
819 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
824 alias_type
= TREE_TYPE (ptr
.value
);
825 /* Optional constant offset. */
826 if (c_parser_next_token_is (parser
, CPP_PLUS
))
828 c_parser_consume_token (parser
);
830 = c_parser_gimple_postfix_expression (parser
).value
;
831 alias_off
= fold_convert (alias_type
, alias_off
);
834 alias_off
= build_int_cst (alias_type
, 0);
835 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
838 if (! type_name
|| c_parser_error (parser
))
840 c_parser_set_error (parser
, false);
843 tree tem
= NULL_TREE
;
844 tree type
= groktypename (type_name
, &tem
, NULL
);
846 type
= build_aligned_type (type
, tree_to_uhwi (alignment
));
847 expr
.value
= build2_loc (loc
, MEM_REF
,
848 type
, ptr
.value
, alias_off
);
851 else if (strcmp (IDENTIFIER_POINTER (id
), "_Literal") == 0)
853 /* _Literal '(' type-name ')' [ '-' ] constant */
854 c_parser_consume_token (parser
);
855 tree type
= NULL_TREE
;
856 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
858 struct c_type_name
*type_name
= c_parser_type_name (parser
);
861 type
= groktypename (type_name
, &tem
, NULL
);
862 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
866 if ((neg_p
= c_parser_next_token_is (parser
, CPP_MINUS
)))
867 c_parser_consume_token (parser
);
868 tree val
= c_parser_gimple_postfix_expression (parser
).value
;
871 || val
== error_mark_node
872 || ! CONSTANT_CLASS_P (val
))
874 c_parser_error (parser
, "invalid _Literal");
879 val
= const_unop (NEGATE_EXPR
, TREE_TYPE (val
), val
);
882 c_parser_error (parser
, "invalid _Literal");
886 expr
.value
= fold_convert (type
, val
);
889 else if (strcmp (IDENTIFIER_POINTER (id
), "__FMA") == 0)
891 c_parser_consume_token (parser
);
894 if (c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
896 c_parser_gimple_expr_list (parser
, &args
);
897 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
900 if (args
.length () != 3)
902 error_at (loc
, "invalid number of operands to __FMA");
903 expr
.value
= error_mark_node
;
906 expr
.value
= build3_loc (loc
, FMA_EXPR
, TREE_TYPE (args
[0]),
907 args
[0], args
[1], args
[2]);
912 unsigned version
, ver_offset
;
913 if (! lookup_name (id
)
914 && c_parser_parse_ssa_name_id (id
, &version
, &ver_offset
))
916 c_parser_consume_token (parser
);
917 expr
.value
= c_parser_parse_ssa_name (parser
, id
, NULL_TREE
,
918 version
, ver_offset
);
919 if (expr
.value
== error_mark_node
)
921 set_c_expr_source_range (&expr
, tok_range
);
922 /* For default definition SSA names. */
923 if (c_parser_next_token_is (parser
, CPP_OPEN_PAREN
)
924 && c_parser_peek_2nd_token (parser
)->type
== CPP_NAME
927 (c_parser_peek_2nd_token (parser
)->value
)) == 0
928 && c_parser_peek_nth_token (parser
, 3)->type
== CPP_CLOSE_PAREN
)
930 c_parser_consume_token (parser
);
931 c_parser_consume_token (parser
);
932 c_parser_consume_token (parser
);
933 if (! SSA_NAME_IS_DEFAULT_DEF (expr
.value
))
935 if (!SSA_NAME_VAR (expr
.value
))
937 error_at (loc
, "anonymous SSA name cannot have"
938 " default definition");
939 expr
.value
= error_mark_node
;
942 set_ssa_default_def (cfun
, SSA_NAME_VAR (expr
.value
),
944 SSA_NAME_DEF_STMT (expr
.value
) = gimple_build_nop ();
950 c_parser_consume_token (parser
);
952 = build_external_ref (loc
, id
,
953 (c_parser_peek_token (parser
)->type
954 == CPP_OPEN_PAREN
), &expr
.original_type
);
955 set_c_expr_source_range (&expr
, tok_range
);
961 c_parser_error (parser
, "expected expression");
967 c_parser_error (parser
, "expected expression");
971 return c_parser_gimple_postfix_expression_after_primary
972 (parser
, EXPR_LOC_OR_LOC (expr
.value
, loc
), expr
);
975 /* Parse a gimple postfix expression after the initial primary or compound
979 c_parser_gimple_postfix_expression_after_primary (c_parser
*parser
,
990 location_t op_loc
= c_parser_peek_token (parser
)->location
;
991 switch (c_parser_peek_token (parser
)->type
)
993 case CPP_OPEN_SQUARE
:
995 c_parser_consume_token (parser
);
996 tree idx
= c_parser_gimple_unary_expression (parser
).value
;
998 if (! c_parser_require (parser
, CPP_CLOSE_SQUARE
, "expected %<]%>"))
1000 c_parser_skip_until_found (parser
, CPP_CLOSE_SQUARE
, NULL
);
1004 start
= expr
.get_start ();
1005 finish
= c_parser_tokens_buf (parser
, 0)->location
;
1006 expr
.value
= build_array_ref (op_loc
, expr
.value
, idx
);
1007 set_c_expr_source_range (&expr
, start
, finish
);
1009 expr
.original_code
= ERROR_MARK
;
1010 expr
.original_type
= NULL
;
1013 case CPP_OPEN_PAREN
:
1015 /* Function call. */
1016 c_parser_consume_token (parser
);
1017 auto_vec
<tree
> exprlist
;
1018 if (! c_parser_next_token_is (parser
, CPP_CLOSE_PAREN
))
1019 c_parser_gimple_expr_list (parser
, &exprlist
);
1020 c_parser_skip_until_found (parser
, CPP_CLOSE_PAREN
,
1022 expr
.value
= build_call_array_loc
1023 (expr_loc
, TREE_TYPE (TREE_TYPE (expr
.value
)),
1024 expr
.value
, exprlist
.length (), exprlist
.address ());
1025 expr
.original_code
= ERROR_MARK
;
1026 expr
.original_type
= NULL
;
1031 /* Structure element reference. */
1032 c_parser_consume_token (parser
);
1033 if (c_parser_next_token_is (parser
, CPP_NAME
))
1035 c_token
*comp_tok
= c_parser_peek_token (parser
);
1036 ident
= comp_tok
->value
;
1037 comp_loc
= comp_tok
->location
;
1041 c_parser_error (parser
, "expected identifier");
1043 expr
.original_code
= ERROR_MARK
;
1044 expr
.original_type
= NULL
;
1047 start
= expr
.get_start ();
1048 finish
= c_parser_peek_token (parser
)->get_finish ();
1049 c_parser_consume_token (parser
);
1050 expr
.value
= build_component_ref (op_loc
, expr
.value
, ident
,
1052 set_c_expr_source_range (&expr
, start
, finish
);
1053 expr
.original_code
= ERROR_MARK
;
1054 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
1055 expr
.original_type
= NULL
;
1058 /* Remember the original type of a bitfield. */
1059 tree field
= TREE_OPERAND (expr
.value
, 1);
1060 if (TREE_CODE (field
) != FIELD_DECL
)
1061 expr
.original_type
= NULL
;
1063 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
1069 /* Structure element reference. */
1070 c_parser_consume_token (parser
);
1071 if (c_parser_next_token_is (parser
, CPP_NAME
))
1073 c_token
*comp_tok
= c_parser_peek_token (parser
);
1074 ident
= comp_tok
->value
;
1075 comp_loc
= comp_tok
->location
;
1079 c_parser_error (parser
, "expected identifier");
1081 expr
.original_code
= ERROR_MARK
;
1082 expr
.original_type
= NULL
;
1085 start
= expr
.get_start ();
1086 finish
= c_parser_peek_token (parser
)->get_finish ();
1087 c_parser_consume_token (parser
);
1088 expr
.value
= build_component_ref (op_loc
,
1089 build_simple_mem_ref_loc
1090 (op_loc
, expr
.value
),
1092 set_c_expr_source_range (&expr
, start
, finish
);
1093 expr
.original_code
= ERROR_MARK
;
1094 if (TREE_CODE (expr
.value
) != COMPONENT_REF
)
1095 expr
.original_type
= NULL
;
1098 /* Remember the original type of a bitfield. */
1099 tree field
= TREE_OPERAND (expr
.value
, 1);
1100 if (TREE_CODE (field
) != FIELD_DECL
)
1101 expr
.original_type
= NULL
;
1103 expr
.original_type
= DECL_BIT_FIELD_TYPE (field
);
1113 /* Parse expression list.
1116 gimple-unary-expression
1117 gimple-expr-list , gimple-unary-expression
1122 c_parser_gimple_expr_list (c_parser
*parser
, vec
<tree
> *ret
)
1126 expr
= c_parser_gimple_unary_expression (parser
);
1127 ret
->safe_push (expr
.value
);
1128 while (c_parser_next_token_is (parser
, CPP_COMMA
))
1130 c_parser_consume_token (parser
);
1131 expr
= c_parser_gimple_unary_expression (parser
);
1132 ret
->safe_push (expr
.value
);
1136 /* Parse gimple label.
1140 case constant-expression :
1146 c_parser_gimple_label (c_parser
*parser
, gimple_seq
*seq
)
1148 tree name
= c_parser_peek_token (parser
)->value
;
1149 location_t loc1
= c_parser_peek_token (parser
)->location
;
1150 gcc_assert (c_parser_next_token_is (parser
, CPP_NAME
));
1151 c_parser_consume_token (parser
);
1152 gcc_assert (c_parser_next_token_is (parser
, CPP_COLON
));
1153 c_parser_consume_token (parser
);
1154 tree label
= define_label (loc1
, name
);
1155 gimple_seq_add_stmt (seq
, gimple_build_label (label
));
1159 /* Parse gimple/RTL pass list.
1161 gimple-or-rtl-pass-list:
1162 startwith("pass-name")
1166 c_parser_gimple_or_rtl_pass_list (c_parser
*parser
)
1170 /* Accept __GIMPLE/__RTL. */
1171 if (c_parser_next_token_is_not (parser
, CPP_OPEN_PAREN
))
1173 c_parser_consume_token (parser
);
1175 if (c_parser_next_token_is (parser
, CPP_NAME
))
1177 const char *op
= IDENTIFIER_POINTER (c_parser_peek_token (parser
)->value
);
1178 c_parser_consume_token (parser
);
1179 if (! strcmp (op
, "startwith"))
1181 if (! c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1183 if (c_parser_next_token_is_not (parser
, CPP_STRING
))
1185 error_at (c_parser_peek_token (parser
)->location
,
1186 "expected pass name");
1189 pass
= xstrdup (TREE_STRING_POINTER
1190 (c_parser_peek_token (parser
)->value
));
1191 c_parser_consume_token (parser
);
1192 if (! c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
1197 error_at (c_parser_peek_token (parser
)->location
,
1198 "invalid operation");
1203 if (! c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
1209 /* Parse gimple local declaration.
1211 declaration-specifiers:
1212 storage-class-specifier declaration-specifiers[opt]
1213 type-specifier declaration-specifiers[opt]
1214 type-qualifier declaration-specifiers[opt]
1215 function-specifier declaration-specifiers[opt]
1216 alignment-specifier declaration-specifiers[opt]
1218 storage-class-specifier:
1242 address-space-qualifier
1248 c_parser_gimple_declaration (c_parser
*parser
)
1250 struct c_declarator
*declarator
;
1251 struct c_declspecs
*specs
= build_null_declspecs ();
1252 c_parser_declspecs (parser
, specs
, true, true, true,
1253 true, true, cla_nonabstract_decl
);
1254 finish_declspecs (specs
);
1256 /* Provide better error recovery. Note that a type name here is usually
1257 better diagnosed as a redeclaration. */
1258 if (c_parser_next_token_starts_declspecs (parser
)
1259 && ! c_parser_next_token_is (parser
, CPP_NAME
))
1261 c_parser_error (parser
, "expected %<;%>");
1262 c_parser_set_error (parser
, false);
1267 declarator
= c_parser_declarator (parser
,
1268 specs
->typespec_kind
!= ctsk_none
,
1269 C_DTR_NORMAL
, &dummy
);
1271 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1273 /* Handle SSA name decls specially, they do not go into the identifier
1274 table but we simply build the SSA name for later lookup. */
1275 unsigned version
, ver_offset
;
1276 if (declarator
->kind
== cdk_id
1277 && is_gimple_reg_type (specs
->type
)
1278 && c_parser_parse_ssa_name_id (declarator
->u
.id
,
1279 &version
, &ver_offset
)
1280 /* The following restricts it to unnamed anonymous SSA names
1281 which fails parsing of named ones in dumps (we could
1282 decide to not dump their name for -gimple). */
1284 c_parser_parse_ssa_name (parser
, declarator
->u
.id
, specs
->type
,
1285 version
, ver_offset
);
1288 tree postfix_attrs
= NULL_TREE
;
1289 tree all_prefix_attrs
= specs
->attrs
;
1290 specs
->attrs
= NULL
;
1291 tree decl
= start_decl (declarator
, specs
, false,
1292 chainon (postfix_attrs
, all_prefix_attrs
));
1294 finish_decl (decl
, UNKNOWN_LOCATION
, NULL_TREE
, NULL_TREE
,
1300 c_parser_error (parser
, "expected %<;%>");
1305 /* Parse gimple goto statement. */
1308 c_parser_gimple_goto_stmt (location_t loc
, tree label
, gimple_seq
*seq
)
1310 tree decl
= lookup_label_for_goto (loc
, label
);
1311 gimple_seq_add_stmt (seq
, gimple_build_goto (decl
));
1315 /* Parse a parenthesized condition.
1317 ( gimple-binary-expression ) */
1320 c_parser_gimple_paren_condition (c_parser
*parser
)
1322 if (! c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1323 return error_mark_node
;
1324 tree cond
= c_parser_gimple_binary_expression (parser
).value
;
1325 if (! c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
1326 return error_mark_node
;
1330 /* Parse gimple if-else statement.
1333 if ( gimple-binary-expression ) gimple-goto-statement
1334 if ( gimple-binary-expression ) gimple-goto-statement \
1335 else gimple-goto-statement
1339 c_parser_gimple_if_stmt (c_parser
*parser
, gimple_seq
*seq
)
1341 tree t_label
, f_label
, label
;
1343 c_parser_consume_token (parser
);
1344 tree cond
= c_parser_gimple_paren_condition (parser
);
1346 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
1348 loc
= c_parser_peek_token (parser
)->location
;
1349 c_parser_consume_token (parser
);
1350 if (! c_parser_next_token_is (parser
, CPP_NAME
))
1352 c_parser_error (parser
, "expected label");
1355 label
= c_parser_peek_token (parser
)->value
;
1356 c_parser_consume_token (parser
);
1357 t_label
= lookup_label_for_goto (loc
, label
);
1358 if (! c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1363 c_parser_error (parser
, "expected goto expression");
1367 if (c_parser_next_token_is_keyword (parser
, RID_ELSE
))
1368 c_parser_consume_token (parser
);
1371 c_parser_error (parser
, "expected else statement");
1375 if (c_parser_next_token_is_keyword (parser
, RID_GOTO
))
1377 loc
= c_parser_peek_token (parser
)->location
;
1378 c_parser_consume_token (parser
);
1379 if (! c_parser_next_token_is (parser
, CPP_NAME
))
1381 c_parser_error (parser
, "expected label");
1384 label
= c_parser_peek_token (parser
)->value
;
1385 f_label
= lookup_label_for_goto (loc
, label
);
1386 c_parser_consume_token (parser
);
1387 if (! c_parser_require (parser
, CPP_SEMICOLON
, "expected %<;%>"))
1392 c_parser_error (parser
, "expected goto expression");
1396 if (cond
!= error_mark_node
)
1397 gimple_seq_add_stmt (seq
, gimple_build_cond_from_tree (cond
, t_label
,
1401 /* Parse gimple switch-statement.
1403 gimple-switch-statement:
1404 switch (gimple-postfix-expression) gimple-case-statement
1406 gimple-case-statement:
1407 gimple-case-statement
1408 gimple-label-statement : gimple-goto-statment
1412 c_parser_gimple_switch_stmt (c_parser
*parser
, gimple_seq
*seq
)
1415 tree case_label
, label
;
1416 auto_vec
<tree
> labels
;
1417 tree default_label
= NULL_TREE
;
1418 gimple_seq switch_body
= NULL
;
1419 c_parser_consume_token (parser
);
1421 if (! c_parser_require (parser
, CPP_OPEN_PAREN
, "expected %<(%>"))
1423 cond_expr
= c_parser_gimple_postfix_expression (parser
);
1424 if (! c_parser_require (parser
, CPP_CLOSE_PAREN
, "expected %<)%>"))
1427 if (! c_parser_require (parser
, CPP_OPEN_BRACE
, "expected %<{%>"))
1430 while (c_parser_next_token_is_not (parser
, CPP_CLOSE_BRACE
))
1432 if (c_parser_next_token_is (parser
, CPP_EOF
))
1434 c_parser_error (parser
, "expected statement");
1438 switch (c_parser_peek_token (parser
)->keyword
)
1443 location_t loc
= c_parser_peek_token (parser
)->location
;
1444 c_parser_consume_token (parser
);
1446 if (c_parser_next_token_is (parser
, CPP_NAME
)
1447 || c_parser_peek_token (parser
)->type
== CPP_NUMBER
)
1448 exp1
= c_parser_gimple_postfix_expression (parser
);
1451 c_parser_error (parser
, "expected expression");
1455 if (c_parser_next_token_is (parser
, CPP_COLON
))
1457 c_parser_consume_token (parser
);
1458 if (c_parser_next_token_is (parser
, CPP_NAME
))
1460 label
= c_parser_peek_token (parser
)->value
;
1461 c_parser_consume_token (parser
);
1462 tree decl
= lookup_label_for_goto (loc
, label
);
1463 case_label
= build_case_label (exp1
.value
, NULL_TREE
,
1465 labels
.safe_push (case_label
);
1466 if (! c_parser_require (parser
, CPP_SEMICOLON
,
1470 else if (! c_parser_require (parser
, CPP_NAME
,
1474 else if (! c_parser_require (parser
, CPP_SEMICOLON
,
1481 location_t loc
= c_parser_peek_token (parser
)->location
;
1482 c_parser_consume_token (parser
);
1483 if (c_parser_next_token_is (parser
, CPP_COLON
))
1485 c_parser_consume_token (parser
);
1486 if (c_parser_next_token_is (parser
, CPP_NAME
))
1488 label
= c_parser_peek_token (parser
)->value
;
1489 c_parser_consume_token (parser
);
1490 tree decl
= lookup_label_for_goto (loc
, label
);
1491 default_label
= build_case_label (NULL_TREE
, NULL_TREE
,
1493 if (! c_parser_require (parser
, CPP_SEMICOLON
,
1497 else if (! c_parser_require (parser
, CPP_NAME
,
1501 else if (! c_parser_require (parser
, CPP_SEMICOLON
,
1508 location_t loc
= c_parser_peek_token (parser
)->location
;
1509 c_parser_consume_token (parser
);
1510 if (c_parser_next_token_is (parser
, CPP_NAME
))
1512 c_parser_gimple_goto_stmt (loc
,
1516 c_parser_consume_token (parser
);
1517 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1518 c_parser_consume_token (parser
);
1521 c_parser_error (parser
, "expected semicolon");
1525 else if (! c_parser_require (parser
, CPP_NAME
,
1531 c_parser_error (parser
, "expected case label or goto statement");
1536 if (! c_parser_require (parser
, CPP_CLOSE_BRACE
, "expected %<}%>"))
1539 if (cond_expr
.value
!= error_mark_node
)
1541 gimple_seq_add_stmt (seq
, gimple_build_switch (cond_expr
.value
,
1542 default_label
, labels
));
1543 gimple_seq_add_seq (seq
, switch_body
);
1547 /* Parse gimple return statement. */
1550 c_parser_gimple_return_stmt (c_parser
*parser
, gimple_seq
*seq
)
1552 location_t loc
= c_parser_peek_token (parser
)->location
;
1554 c_parser_consume_token (parser
);
1555 if (c_parser_next_token_is (parser
, CPP_SEMICOLON
))
1557 c_finish_gimple_return (loc
, NULL_TREE
);
1558 ret
= gimple_build_return (NULL
);
1559 gimple_seq_add_stmt (seq
, ret
);
1563 location_t xloc
= c_parser_peek_token (parser
)->location
;
1564 c_expr expr
= c_parser_gimple_unary_expression (parser
);
1565 if (expr
.value
!= error_mark_node
)
1567 c_finish_gimple_return (xloc
, expr
.value
);
1568 ret
= gimple_build_return (expr
.value
);
1569 gimple_seq_add_stmt (seq
, ret
);
1574 /* Support function for c_parser_gimple_return_stmt. */
1577 c_finish_gimple_return (location_t loc
, tree retval
)
1579 tree valtype
= TREE_TYPE (TREE_TYPE (current_function_decl
));
1581 /* Use the expansion point to handle cases such as returning NULL
1582 in a function returning void. */
1583 source_location xloc
= expansion_point_location_if_in_system_header (loc
);
1585 if (TREE_THIS_VOLATILE (current_function_decl
))
1586 warning_at (xloc
, 0,
1587 "function declared %<noreturn%> has a %<return%> statement");
1590 current_function_returns_null
= 1;
1591 else if (valtype
== 0 || TREE_CODE (valtype
) == VOID_TYPE
)
1593 current_function_returns_null
= 1;
1594 if (TREE_CODE (TREE_TYPE (retval
)) != VOID_TYPE
)
1597 (xloc
, "%<return%> with a value, in function returning void");
1598 inform (DECL_SOURCE_LOCATION (current_function_decl
),
1602 else if (TREE_CODE (valtype
) != TREE_CODE (TREE_TYPE (retval
)))
1605 (xloc
, "invalid conversion in return statement");
1606 inform (DECL_SOURCE_LOCATION (current_function_decl
),