On Thu, Jan 13, 2011 at 4:01 PM, Eugen Wagner
<wagner.eu...@googlemail.com> wrote:
> Hi,
> I have a problem with gimple_regimplify_operands() from gimplify.c ,
> which i execute from my custom plug-in-code. It could indicate a bug
> in this procedure.

This function isn't generic enough to handle full re-gimplification.
It was written for some specific use-cases and I would suggest
to not use it.

The simplest way to modify statements is to generate new
statements which compute the changed value into a register
and substiute that result into the operand you want to change.

Richard.

> I'm developing a GCC-plug-in, which does some instrumentation of
> C-programs on GIMPLE-Level.
> Among others, I'm inserting logging functions, which output the
> runtime-addresses of all in a function referenced variables.
> Since i have to build ADDR_EXPR nodes for all these variables, which
> invalidates some properties of GIMPLE,
> I run gimple_regimplify_operands() for all statements in each basic-block.
>
> My gimple_pass is inserted before the ssa-building pass.
> It works fine with all my test-cases which doesn't contain SWITCH-CASE
> constructs.
>
> If my test program contains SWITCH-CASE statements, the
> compile-process fails by executing gimple_regimplify_operands, called
> from my pass.
> I get an error like:
> main3.c: In function ‘main’:
> main3.c:24:1: internal compiler error: in gimplify_expr, at gimplify.c:7336
>
> In order to find an error, i removed all my passes, and installed only
> one pass, which runs regimplify_operands on NOT-instrumented GIMPLE.
> I got the same error.
> It indicates that either it is not allowed to run regimplify_operands
> at this place ( just before the "ssa"-building-pass) or there is a bug
> in this procedure.
>
> Could someone comment or say what I'm doing wrong?
>
> Regards,
> Eugen
>
> ------------------------------------------------------------
> My test_pass- procedure:
> static unsigned int
> execute_regimplify(void){
>  basic_block bb;
>  FOR_EACH_BB (bb)
>    {
>      gimple_stmt_iterator gsi;
>      gimple_seq seq = bb_seq(bb);
>
>      for (gsi = gsi_start(seq); !gsi_end_p(gsi); gsi_next(&gsi))
>        {
>          gimple stmt = gsi_stmt(gsi);
>          gimple_regimplify_operands(stmt, &gsi);
>        }
>    }
>  verify_stmts();
>  return 0;
> }
> ------------------------------------------------------------
> plugin-installation code:
> plugin_init()
> ...
>  pass_info.pass = &pass_test_regimplify.pass;
>  pass_info.reference_pass_name = "ssa";
>  pass_info.ref_pass_instance_number = 0;
>  pass_info.pos_op = PASS_POS_INSERT_BEFORE;
>  register_callback (plugin_info->base_name, PLUGIN_PASS_MANAGER_SETUP,
>      NULL, &pass_info);
> return 0;
> }
>
>
> struct gimple_opt_pass pass_test_regimplify =
>  {
>    { GIMPLE_PASS, "test_regimplify", /* name */
>    NULL,                               /* gate */
>    execute_regimplify,                 /* execute */
>    NULL,                               /* sub */
>    NULL,                               /* next */
>    0,                                  /* static_pass_number */
>    TV_NONE,                            /* tv_id */
>    PROP_cfg,                           /* properties_required */
>    0,                                  /* properties_provided */
>    0,                                  /* properties_destroyed */
>    0,                                  /* todo_flags_start */
>    0,                                  /* todo_flags_finish */
>    } };
> ------------------------------------------------------------
> the contents of main3.c:
> int main(int argc, char **args){
>  int a = 0;
>  int b = 3;
>  switch(b){
>  case 1:
>    a= 1;
>    break;
>  case 2:
>    a=2;
>    break;
>  default:
>   a=b;
>  }
>  return 0;
> }
> ------------------------------------------------------------------------------
> gdb's back-trace gives:
>
> #0  gimplify_expr (expr_p=0xb7ff5418, pre_p=0xbffff080,
> post_p=0xbfffecb4, gimple_test_f=0x82e7010 <is_gimple_val>,
>    fallback=<value optimized out>) at ../../gcc/gimplify.c:7336
> #1  0x08308f52 in gimplify_arg (arg_p=0xb7ff5418, pre_p=<value
> optimized out>, call_location=<value optimized out>)
>    at ../../gcc/gimplify.c:2216
> #2  0x08309161 in gimplify_call_expr (expr_p=<value optimized out>,
> pre_p=<value optimized out>,
>    want_value=<value optimized out>) at ../../gcc/gimplify.c:2361
> #3  0x0830189b in gimplify_expr (expr_p=0xb7f37f5c, pre_p=0xbffff080,
> post_p=0xbfffee64,
>    gimple_test_f=0x82e1a80 <is_gimple_stmt>, fallback=0) at
> ../../gcc/gimplify.c:6636
> #4  0x0830bafb in gimplify_stmt (stmt_p=0xb7f37f5c, seq_p=0xbffff080)
> at ../../gcc/gimplify.c:5277
> #5  0x083013b7 in gimplify_statement_list (expr_p=0xb7ebad0c,
> pre_p=0xbffff080, post_p=0xbfffef74,
>    gimple_test_f=0x82e1a80 <is_gimple_stmt>, fallback=0) at
> ../../gcc/gimplify.c:1383
> #6  gimplify_expr (expr_p=0xb7ebad0c, pre_p=0xbffff080,
> post_p=0xbfffef74, gimple_test_f=0x82e1a80 <is_gimple_stmt>,
>    fallback=0) at ../../gcc/gimplify.c:6982
> #7  0x0830bafb in gimplify_stmt (stmt_p=0xb7ebad0c, seq_p=0xbffff080)
> at ../../gcc/gimplify.c:5277
> #8  0x08302ce6 in gimplify_bind_expr (expr_p=0xb7f60fd8,
> pre_p=0xbffff138, post_p=0xbffff084,
>    gimple_test_f=0x82e1a80 <is_gimple_stmt>, fallback=0) at
> ../../gcc/gimplify.c:1128
> #9  gimplify_expr (expr_p=0xb7f60fd8, pre_p=0xbffff138,
> post_p=0xbffff084, gimple_test_f=0x82e1a80 <is_gimple_stmt>,
>    fallback=0) at ../../gcc/gimplify.c:6766
> #10 0x0830bafb in gimplify_stmt (stmt_p=0xb7f60fd8, seq_p=0xbffff138)
> at ../../gcc/gimplify.c:5277
> #11 0x0830bbe0 in gimplify_body (body_p=0xb7f60fd8, fndecl=0xb7f60f80,
> do_parms=1 '\001') at ../../gcc/gimplify.c:7578
> #12 0x0830c011 in gimplify_function_tree (fndecl=0xb7f60f80) at
> ../../gcc/gimplify.c:7674
> #13 0x08616398 in cgraph_analyze_function (node=0xb7f690b8) at
> ../../gcc/cgraphunit.c:873
> #14 0x086191f7 in cgraph_analyze_functions () at ../../gcc/cgraphunit.c:1008
> #15 0x0861a8a5 in cgraph_finalize_compilation_unit () at
> ../../gcc/cgraphunit.c:1113
> #16 0x080db74b in c_write_global_declarations () at ../../gcc/c-decl.c:9520
> #17 0x0842d68b in compile_file (argc=4, argv=0xbffff3f4) at
> ../../gcc/toplev.c:1065
> #18 do_compile (argc=4, argv=0xbffff3f4) at ../../gcc/toplev.c:2417
> #19 toplev_main (argc=4, argv=0xbffff3f4) at ../../gcc/toplev.c:2459
> #20 0x081645ab in main (argc=4, argv=0xbffff3f4) at ../../gcc/main.c:35
>

Reply via email to