This is the mail archive of the
mailing list for the GCC project.
Re: Can realloc be marked as a mallloc-like function?
On 7/18/07, Richard Guenther <firstname.lastname@example.org> wrote:
On 7/18/07, Richard Henderson <email@example.com> wrote:
> On Tue, Jul 17, 2007 at 09:53:30AM -0000, Wolfram Gloger wrote:
> > Surely you agree that in my second example, "*p = 0" _cannot_ be moved
> > after the call to destroy_something_and_allocate_anotherthing(p)?
> It can't be moved after, but it could be removed entirely as dead code.
> I don't think we have a pass that will do that presently, but I see no
> reason why it couldn't happen some day, more or less automatically, with
> a pass that analyzes lifetimes of dynamic allocations.
Currently, the only thing that does prevent this optimization is the fact
that passing p to realloc makes p escape and the memory pointed to
clobbered. But the alias analysis code already has special case code
that would prevent this from happening (just maybe not in all places right
now) - whether this is a good idea or not is another question.
We could use zdenek's builtin function table to mention which
arguments are not just written to, but *destroyed* for alias purposes,
and then just directly get that info into aliasing.
Boom, problem solved.