I'm experimenting with the gimple plugin infrastructure and I'm having trouble instrumenting code in a way that is compatible with the optimizer. Here's a simple example that is intended to insert the function call "__memcheck_register_argv(argc, argv)" at the beginning of main. The code runs during pass_plugin_gimple (which comes right after pass_apply_inline in passes.c) and works great with -O0, but causes the compiler to crash with -O1 or higher.

-------------------------------------
tree argv_registrar_type;
tree argv_registrar;
tree argv_registrar_call;

argv_registrar_type = build_function_type_list (void_type_node,
                                                integer_type_node,
                                                build_pointer_type
                                                (build_pointer_type
                                                 (char_type_node)),
                                                NULL_TREE);
argv_registrar = build_fn_decl ("__memcheck_register_argv",
                                argv_registrar_type);
argv_registrar_call = build_call_expr (argv_registrar, 2,
                                       DECL_ARGUMENTS (cfun->decl),
                                       TREE_CHAIN (DECL_ARGUMENTS
                                                   (cfun->decl)));
bsi_insert_before (&iter, argv_registrar_call, BSI_SAME_STMT);
---------------------------------------

With -O1, I get the compiler failure

---------------
test.c: In function 'main':
test.c:2: error: expected an SSA_NAME object
test.c:2: error: in statement
__memcheck_register_argv (argc, argv);
test.c:2: internal compiler error: verify_ssa failed
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
----------------

when attempting to compile the code

-----------------
int main(int argc, char **argv)
{
  return 0;
}
-----------------


I've tried all kinds of combinations of gimplify_stmt, update_ssa, etc., but I just can't figure our the "correct" way to insert a function call into the gimple tree. Any help would be greatly appreciated!

Best,
Rob

Reply via email to