On Mon, 13 May 2019, 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)?
The patch tests DECL_IS_MALLOC, not BUILT_IN_MALLOC. From the failures I
got with earlier versions, that seems to include alloca at least, so I
would expect it also includes any function with the attribute.
--
Marc Glisse