In this patch I am trying to parse gimple call. But I am getting weird gimple dump for that.
for this testcase: int __GIMPLE() bar() { int a; a = a + 1; return a; } void __GIMPLE() foo() { int b; b = bar(); } I am getting ssa dump as: /* Function bar (bar, funcdef_no=0, decl_uid=1744, cgraph_uid=0, symbol_order=0)*/ int bar () { struct FRAME.bar FRAME.0; int a; void * D_1754; void * _3; bb_2: _3 = __builtin_dwarf_cfa (0); FRAME.0.FRAME_BASE.PARENT = _3; a_6 = a_5(D) + 1; return a_6; } /* Function foo (foo, funcdef_no=1, decl_uid=1747, cgraph_uid=1, symbol_order=1)*/ void foo () { int b; bb_2: b_3 = bar (); return; } On 9 August 2016 at 14:37, Richard Biener <richard.guent...@gmail.com> wrote: > On Sun, Aug 7, 2016 at 3:19 PM, Prasad Ghangal <prasad.ghan...@gmail.com> > wrote: >> On 4 August 2016 at 18:29, Richard Biener <richard.guent...@gmail.com> wrote: >>> On Thu, Aug 4, 2016 at 1:31 PM, Prasad Ghangal <prasad.ghan...@gmail.com> >>> wrote: >>>> On 2 August 2016 at 14:29, Richard Biener <richard.guent...@gmail.com> >>>> wrote: >>>>> On Mon, Aug 1, 2016 at 4:52 PM, Prasad Ghangal <prasad.ghan...@gmail.com> >>>>> wrote: >>>>>> Hi, >>>>>> >>>>>> I am trying to replace c_parser_paren_condition (parser) in >>>>>> c_parser_gimple_if_stmt by c_parser_gimple_paren_condition (parser) as >>>>>> described in the patch >>>>>> >>>>>> I am trying test case >>>>>> void __GIMPLE () foo () >>>>>> { >>>>>> int a; >>>>>> bb_2: >>>>>> if (a == 2) >>>>>> goto bb_3; >>>>>> else >>>>>> goto bb_4; >>>>>> bb_3: >>>>>> a_2 = 4; >>>>>> bb_4: >>>>>> return; >>>>>> } >>>>>> >>>>>> but it fails to parse gimple expression and produces error as >>>>>> /home/prasad/test3.c: In function ‘foo’: >>>>>> /home/prasad/test3.c:1:18: error: invalid operands in gimple comparison >>>>>> void __GIMPLE () foo () >>>>>> ^~~ >>>>>> if (<<< Unknown tree: c_maybe_const_expr >>>>>> >>>>>> a >>> == 2) goto bb_3; else goto bb_4; >>>>>> /home/prasad/test3.c:1:18: internal compiler error: verify_gimple failed >>>>>> >>>>>> I failed to debug where it is setting to C_MAYBE_CONST_EXPR >>>>> >>>>> It's in parsing the binary expression. Btw, you don't need >>>>> lvalue_to_rvalue >>>>> conversion or truthvalue conversion - source that would require this would >>>>> not be valid GIMPLE. Let me try to debug: >>>>> >>>>> >>>>> (gdb) p debug_tree (cond.value) >>>>> <eq_expr 0x7ffff6997960 >>>>> type <integer_type 0x7ffff688b7e0 int public SI >>>>> size <integer_cst 0x7ffff6887ee8 constant 32> >>>>> unit size <integer_cst 0x7ffff6887f00 constant 4> >>>>> align 32 symtab 0 alias set -1 canonical type 0x7ffff688b7e0 >>>>> precision 32 min <integer_cst 0x7ffff6887ea0 -2147483648> max >>>>> <integer_cst 0x7ffff6887eb8 2147483647> >>>>> pointer_to_this <pointer_type 0x7ffff68a5930>> >>>>> >>>>> arg 0 <c_maybe_const_expr 0x7ffff6997938 type <integer_type >>>>> 0x7ffff688b7e0 int> >>>>> >>>>> arg 1 <var_decl 0x7ffff7fefcf0 a type <integer_type >>>>> 0x7ffff688b7e0 int> >>>>> used SI file t.c line 3 col 7 size <integer_cst >>>>> 0x7ffff6887ee8 32> unit size <integer_cst 0x7ffff6887f00 4> >>>>> align 32 context <function_decl 0x7ffff699c500 foo>>> >>>>> arg 1 <integer_cst 0x7ffff68a4318 type <integer_type >>>>> 0x7ffff688b7e0 int> constant 2> >>>>> t.c:5:9 start: t.c:5:7 finish: t.c:5:12> >>>>> $5 = void >>>>> (gdb) b ggc-page.c:1444 if result == 0x7ffff6997938 >>>>> Breakpoint 6 at 0x8a0d3e: file >>>>> /space/rguenther/src/gcc_gimple_fe/gcc/ggc-page.c, line 1444. >>>>> (gdb) run >>>>> >>>>> Breakpoint 6, ggc_internal_alloc (size=40, f=0x0, s=0, n=1) >>>>> at /space/rguenther/src/gcc_gimple_fe/gcc/ggc-page.c:1444 >>>>> 1444 return result; >>>>> (gdb) fin (a few times) >>>>> Run till exit from #0 0x00000000011821b7 in build2_stat ( >>>>> code=C_MAYBE_CONST_EXPR, tt=<integer_type 0x7ffff688b7e0 int>, >>>>> arg0=<tree 0x0>, arg1=<var_decl 0x7ffff7fefcf0 a>) >>>>> at /space/rguenther/src/gcc_gimple_fe/gcc/tree.c:4466 >>>>> 0x000000000081d263 in c_wrap_maybe_const (expr=<var_decl 0x7ffff7fefcf0 >>>>> a>, >>>>> non_const=false) >>>>> at /space/rguenther/src/gcc_gimple_fe/gcc/c-family/c-common.c:4359 >>>>> 4359 expr = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr), NULL, >>>>> expr); >>>>> Value returned is $11 = (tree_node *) 0x7ffff6997938 >>>>> (gdb) up >>>>> #1 0x00000000007b8e81 in build_binary_op (location=176833, code=EQ_EXPR, >>>>> orig_op0=<var_decl 0x7ffff7fefcf0 a>, >>>>> orig_op1=<integer_cst 0x7ffff68a4318>, convert_p=1) >>>>> at /space/rguenther/src/gcc_gimple_fe/gcc/c/c-typeck.c:11549 >>>>> 11549 op0 = c_wrap_maybe_const (op0, >>>>> !op0_maybe_const); >>>>> >>>>> and this is guarded by !in_late_binary_op (which also seems to guard >>>>> folding). >>>>> So I suggest to somewhere at the start of parsing to set >>>>> in_late_binary_op to >>>>> true for -fgimple. Not sure if it works for everything, but you >>>>> should have accumulated >>>>> quite some tests for -fgimple in the testsuite to make sure it doesn't >>>>> regress anything. >>>>> >>>> I did bootstrap build for the trunk and testing is in progress. How >>>> can I test with -fgimple flag enabled? >>> >>> You can do >>> >>> make check-gcc RUNTESTFLAGS="--target_board=unix/-fgimple" >>> >>> Richard. >>> >> I was comparing result from latest commit and "gcc initial version". I >> found most of the testcases failed due to modified gimple dump. > > Good, that's expected. Can you wrap up as for how is the status on > the project schedule? As said, adding more testcases would be good > for the SSA parsing feature. A big part missing is now is parsing of > function calls? > > Thanks, > Richard. > >> >> Thanks, >> Prasad >> >>>> >>>> Thanks, >>>> Prasad >>>>> The following works for me: >>>>> >>>>> diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c >>>>> index 70800a2..c8c087a 100644 >>>>> --- a/gcc/c/c-parser.c >>>>> +++ b/gcc/c/c-parser.c >>>>> @@ -2158,7 +2159,10 @@ c_parser_declaration_or_fndef (c_parser >>>>> *parser, bool fndef_ok, >>>>> >>>>> if (gimple_body_p && flag_gimple) >>>>> { >>>>> + bool saved = in_late_binary_op; >>>>> + in_late_binary_op = true; >>>>> c_parser_parse_gimple_body (parser); >>>>> + in_late_binary_op = saved; >>>>> cgraph_node::finalize_function (current_function_decl, false); >>>>> timevar_pop (tv); >>>>> return; >>>>> >>>>> >>>>> Richard. >>>>> >>>>>> >>>>>> Thanks, >>>>>> Prasad
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 95615bc..e88b2a8 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -1415,6 +1415,7 @@ static c_expr c_parser_gimple_binary_expression (c_parser *, enum tree_code *); static c_expr c_parser_gimple_unary_expression (c_parser *); static struct c_expr c_parser_gimple_postfix_expression (c_parser *); static struct c_expr c_parser_gimple_postfix_expression_after_primary (c_parser *, + location_t, struct c_expr); static void c_parser_gimple_pass_list (c_parser *, opt_pass **, bool *); static opt_pass *c_parser_gimple_pass_list_params (c_parser *, opt_pass **); @@ -18406,6 +18407,19 @@ c_parser_gimple_expression (c_parser *parser, gimple_seq *seq) return; } + + if (c_parser_next_token_is (parser, CPP_NAME) && + c_parser_peek_2nd_token (parser)->type == CPP_OPEN_PAREN) + { + gimple *call; + rhs = c_parser_gimple_unary_expression (parser); + call = gimple_build_call_from_tree (rhs.value); + gimple_call_set_lhs (call, lhs.value); + gimple_seq_add_stmt (seq, call); + gimple_set_location (call, loc); + return; + } + exp_location = c_parser_peek_token (parser)->location; rhs = c_parser_gimple_binary_expression (parser, &subcode); rhs = convert_lvalue_to_rvalue (exp_location, rhs, true, true); @@ -18810,38 +18824,115 @@ c_parser_gimple_postfix_expression (c_parser *parser) break; } return c_parser_gimple_postfix_expression_after_primary - (parser, expr); + (parser, EXPR_LOC_OR_LOC (expr.value, loc), expr); } /* Parse postfix expression after the primary literal */ static struct c_expr c_parser_gimple_postfix_expression_after_primary (c_parser *parser, - struct c_expr expr) + location_t expr_loc, + struct c_expr expr) { + struct c_expr orig_expr; tree idx; + location_t sizeof_arg_loc[3]; + tree sizeof_arg[3]; + unsigned int literal_zero_mask; + unsigned int i; + vec<tree, va_gc> *exprlist; + vec<tree, va_gc> *origtypes = NULL; + vec<location_t> arg_loc = vNULL; location_t start; location_t finish; - location_t op_loc = c_parser_peek_token (parser)->location; - if (c_parser_peek_token (parser)->type == CPP_OPEN_SQUARE) + while (true) { - c_parser_consume_token (parser); - idx = c_parser_gimple_unary_expression (parser).value; - if (!c_parser_require (parser, CPP_CLOSE_SQUARE, "expected %<]%>")) - goto out; - start = expr.get_start (); - finish = parser->tokens_buf[0].location; - expr.value = build_array_ref (op_loc, expr.value, idx); - set_c_expr_source_range (&expr, start, finish); + location_t op_loc = c_parser_peek_token (parser)->location; + + switch (c_parser_peek_token (parser)->type) + { + case CPP_OPEN_SQUARE: + { + c_parser_consume_token (parser); + idx = c_parser_gimple_unary_expression (parser).value; + + if (!c_parser_require (parser, CPP_CLOSE_SQUARE, "expected %<]%>")) + break; + + start = expr.get_start (); + finish = parser->tokens_buf[0].location; + expr.value = build_array_ref (op_loc, expr.value, idx); + set_c_expr_source_range (&expr, start, finish); + + expr.original_code = ERROR_MARK; + expr.original_type = NULL; + break; + } + case CPP_OPEN_PAREN: + { + /* Function call. */ + c_parser_consume_token (parser); + for (i = 0; i < 3; i++) + { + sizeof_arg[i] = NULL_TREE; + sizeof_arg_loc[i] = UNKNOWN_LOCATION; + } + literal_zero_mask = 0; + if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) + exprlist = NULL; + else + exprlist = c_parser_expr_list (parser, true, false, &origtypes, + sizeof_arg_loc, sizeof_arg, + &arg_loc, &literal_zero_mask); + c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, + "expected %<)%>"); + orig_expr = expr; + mark_exp_read (expr.value); + if (warn_sizeof_pointer_memaccess) + sizeof_pointer_memaccess_warning (sizeof_arg_loc, + expr.value, exprlist, + sizeof_arg, + sizeof_ptr_memacc_comptypes); + if (TREE_CODE (expr.value) == FUNCTION_DECL + && DECL_BUILT_IN_CLASS (expr.value) == BUILT_IN_NORMAL + && DECL_FUNCTION_CODE (expr.value) == BUILT_IN_MEMSET + && vec_safe_length (exprlist) == 3) + { + tree arg0 = (*exprlist)[0]; + tree arg2 = (*exprlist)[2]; + warn_for_memset (expr_loc, arg0, arg2, literal_zero_mask); + } + + start = expr.get_start (); + finish = parser->tokens_buf[0].get_finish (); + expr.value + = c_build_function_call_vec (expr_loc, arg_loc, expr.value, + exprlist, origtypes); + set_c_expr_source_range (&expr, start, finish); + + expr.original_code = ERROR_MARK; + if (TREE_CODE (expr.value) == INTEGER_CST + && TREE_CODE (orig_expr.value) == FUNCTION_DECL + && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL + && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P) + expr.original_code = C_MAYBE_CONST_EXPR; + expr.original_type = NULL; + if (exprlist) + { + release_tree_vector (exprlist); + release_tree_vector (origtypes); + } + arg_loc.release (); + break; + default: + return expr; + + } + } } - expr.original_code = ERROR_MARK; - expr.original_type = NULL; - out: - return expr; } - /* Parse gimple label */ static void