This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [question] replacing called function by gimple_call_set_fndecl doesn't actually take effect


On Fri, Jan 5, 2018 at 5:57 AM, Tong Zhou <zt9465@gmail.com> wrote:
> Hi,
>
> I am new to gcc and was trying to implement a gimple pass today. One thing
> I tried to do was to make a call_stat that originally calls malloc call
> another function like new_malloc. I used gimple_call_set_fndecl and also
> did update_stmt (although I don't know exactly what it does). But the final
> assembly code still calls the old function. The relevant code is as follows:
>
> ------------------------------------
>   tree malloc_fn_type
>       = build_function_type_list (void_type_node, size_type_node,
> NULL_TREE);
>   tree new_malloc = build_fn_decl("new_malloc", malloc_fn_type);
>
>   struct cgraph_node *alloc_node = my_get_malloc_node();
>   struct cgraph_edge *edge = NULL;
>   struct cgraph_node *caller = NULL;
>
>   for (edge = alloc_node->callers; edge; edge = edge->next_caller)
>   {
>     gimple callStmt = edge->call_stmt;
>     gimple_call_set_fndecl(callStmt, new_malloc);
>     update_stmt (callStmt);
>   }
> ------------------------------------
>
> The callee was indeed the new_malloc when I use debug_gimple_stmt to print
> the call_stmt out, but the generated assembly code or dumped gimble file
> still use the old malloc. Thanks in advance!

I would guess the cgraph is stale at the point you modify it (the
edge->call_stmt).
This part of the callgraph isn't really kept up-to-date.

Richard.

> Thanks,
> Tong


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]