c - GCC plugin: copying function's arguments -



c - GCC plugin: copying function's arguments -

i develop gcc plugin instruments applications beingness compiled. applications written in c , built gcc 4.7 (4.8 , 4.9 option) on x86 linux system.

my plugin implements compilation pass placed after "ssa" standard pass , operates on gimple representation. among other things, need implement next cannot figure out how correctly.

when processing c function, need insert code @ origin copies arguments local variables create, future processing.

my first naive implementation looked follows:

tree p; gimple_seq seq = null; gimple_stmt_iterator gsi = gsi_start_bb(single_succ(entry_block_ptr)); (p = decl_arguments(current_function_decl); p; p = decl_chain(param)) { tree copy_par; copy_par = create_tmp_var(tree_type(p), null); add_referenced_var(copy_par); copy_par = make_ssa_name(copy_par, null); g = gimple_build_assign(copy_par, p); ssa_name_def_stmt(copy_par) = g; gimple_seq_add_stmt_without_update (&seq, g); ... // more processing here } ... gsi_insert_seq_before (&gsi, seq, gsi_same_stmt);

this way, however, invalid assignment of parameter declaration variable created according dump:

gimple_assign <parm_decl, d.2206_11, par, null>

d.2206_11 corresponds local variable created, par - argument of function want copy.

gcc crashes @ later pass result, trying process added statement. suppose because p not the variable holding value of respective argument a declaration of variable. way? , how variable?

i tried using gimple_build_assign_with_ops(nop_expr, copy_par, p, null_tree) instead of gimple_build_assign() did not either. gcc still crashes @ same place. can provide backtrace sense missing fundamental.

i looked @ traversal of trees starting type_arg_types (tree_type (current_function_decl)) , farther via tree_chain(...) seems give types of arguments rather respective variables.

so, question is, how add together copying of function's arguments properly.

note perhaps, done help of melt or gcc python plugin, in project, need perform transformations of code using gcc provides.

i found copying of arguments works gcc 4.8 , 4.9 not 4.7. here code works me (instrument_fentry() performs copying).

to avoid copies beingness removed @ later compile passes, made corresponding variables volatile.

in addition, if there no ssa_name default definition statement specified given parameter (see ssa_name_is_default_def()), added such ssa_names gimple_nops defining statements.

this has worked ok gcc 4.8 , 4.9 far, looks bug in gcc 4.7 or alter of rules between gcc 4.7 , 4.8. not pinpoint exact commit though.

c gcc plugins instrumentation

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -