Re: [PATCH] Use __attribute__((malloc)) for gcc 3.2

Andi Kleen
2002-09-30T00:24:22Z

On Mon, Sep 30, 2002 at 02:11:10AM +0200, David S. Miller wrote:
> From: Christoph Hellwig <hch@infradead.org>
> Date: Sun, 29 Sep 2002 18:26:43 +0100
>
> BTW, do you have any stats on the better optimization?
>
> Unlikely since we disable strict aliasing on the gcc command
> line which is why I think this suggested __malloc thing is
> utterly pointless.

My understanding of it is: Please correct me if I'm wrong [i haven't
verified this with tree dumps]

-fno-strict-aliasing tells each pointer that it can alias with everything
else (puts it in alias set 0)

__attribute__((malloc)) overwrites this so that the compiler knows that
this particular pointer that has been returned (puts it into an own
alias set again and overwrites the -fno-strict-aliasing default)

Another way to overwrite it would be restrict, but nobody uses that
currently. May make sense to add it to compile compiler version checked
macros too, so that it can be safely used.

Then it would be actually possible to write functions that get optimized
this way. I'm aware that the aliasing stuff mostly helps with array walks
and loops, which are not that common in the kernel, but it could be still
useful.

-Andi