On Mon, May 13, 2019 at 10:36:00AM -0600, Martin Sebor wrote:
> On 5/11/19 5:33 PM, Marc Glisse wrote:
> > Hello,
> > 
> > this patch lets gcc know that if a pointer existed before the call to
> > malloc, the result of malloc cannot alias it. This is a bit ad hoc and
> > fragile. A small improvement would be, when the 2 statements are in the
> > same bb but in the wrong order, to check if there is any statement in
> > between that might prevent from reordering them. But that's more
> > complicated, and the patch as it is already does help.
> 
> I.e., given the description of attribute malloc:
> 
>   the pointer P returned by the function cannot alias any other
>   pointer valid when the function returns, and moreover no pointers
>   to valid objects occur in any storage addressed by P.
> 
> doesn't the same guarantee hold for other functions declared with
> the attribute (so that the same optimization could be applied to
> them as well)?

Doesn't realloc have also the malloc attribute, but the return value can
alias preexisting pointers (if no reallocation occurs, just the allocation
is extended)?

        Jakub

Reply via email to