On Sat, Aug 27, 2011 at 10:06 AM, Matt Davis <[email protected]> wrote:
> On Sat, Aug 27, 2011 at 09:27:49AM +0200, Richard Guenther wrote:
>> On Sat, Aug 27, 2011 at 4:47 AM, Matt Davis <[email protected]> wrote:
>> > Hello,
>> > I am having the compiler insert a call to a function which is defined
>> > inside
>> > another object file. However, during inline expansion via
>> > expand_call_inline(),
>> > the following assertion fails in tree-inline.c:
>> >>> 3775: edge = cgraph_edge (id->dst_node, stmt);
>> >>> 3776: gcc_checking_assert (cg_edge);
>> >
>> > cg_node comes back as being NULL since there is only one callee and no
>> > indirect
>> > calls, the function that has the inserted call is main(). Is there
>> > something I
>> > forgot to do after inserting the gimple call statement? This works fine
>> > without
>> > optimization.
>>
>> Dependent on where you do it you have to add/rebuild cgraph edges.
>
> Thanks Richard,
> I tired "rebuild_cgraph_edges()" before I sent the initial email.
> Unfortunately, when I call that function after I add the statement, in an IPA
> pass, the resulting binary does not link, as it does not seem able to resolve
> the symbol to the callee. Maybe providing more context would help make more
> sense. insert_func_call inserts the call by adding a new gimple call
> statement.
> I've done this tons of times before, but it seems with -O the callgraph isn't
> happy.
If you are doing this from an IPA pass you have to add the edge manually using
update_edges_for_call_stmt.
>>> for (node=cgraph_nodes; node; node=node->next)
>>> {
>>> if (!(func = DECL_STRUCT_FUNCTION(node->decl)))
>>> continue;
>>>
>>> push_cfun(func);
>>> old_fn_decl = current_function_decl;
>>> current_function_decl = node->decl;
>>>
>>> insert_func_call(func);
>>>
>>> rebuild_cgraph_edges();
>>> current_function_decl = old_fn_decl;
>>> pop_cfun();
>>> }
>
> -Matt
>