diff mbox

Adjust 'malloc' attribute documentation to match implementation

Message ID alpine.LNX.2.00.1201090956060.4999@zhemvz.fhfr.qr
State New
Headers show

Commit Message

Richard Biener Jan. 9, 2012, 9:05 a.m. UTC
Since GCC 4.4 applying the malloc attribute to realloc-like
functions does not work under the documented constraints because
the contents of the memory pointed to are not properly transfered
from the realloc argument (or treated as pointing to anything,
like 4.3 behaved).

The following adjusts documentation to reflect implementation
reality (we do have an implementation detail that treats the
memory blob returned for non-builtins as pointing to any global
variable, but that is neither documented nor do I plan to do
so - I presume it is to allow allocation + initialization
routines to be marked with malloc, but even that area looks
susceptible to misinterpretation to me).

Any comments?

Thanks,
Richard.

2012-01-09  Richard Guenther  <rguenther@suse.de>

	* doc/extend.texi (malloc attribute): Adjust according to
	implementation.

Comments

Xinliang David Li Jan. 9, 2012, 11:27 p.m. UTC | #1
It looks non-ambiguous to me.

David

On Mon, Jan 9, 2012 at 1:05 AM, Richard Guenther <rguenther@suse.de> wrote:
>
> Since GCC 4.4 applying the malloc attribute to realloc-like
> functions does not work under the documented constraints because
> the contents of the memory pointed to are not properly transfered
> from the realloc argument (or treated as pointing to anything,
> like 4.3 behaved).
>
> The following adjusts documentation to reflect implementation
> reality (we do have an implementation detail that treats the
> memory blob returned for non-builtins as pointing to any global
> variable, but that is neither documented nor do I plan to do
> so - I presume it is to allow allocation + initialization
> routines to be marked with malloc, but even that area looks
> susceptible to misinterpretation to me).
>
> Any comments?
>
> Thanks,
> Richard.
>
> 2012-01-09  Richard Guenther  <rguenther@suse.de>
>
>        * doc/extend.texi (malloc attribute): Adjust according to
>        implementation.
>
> Index: gcc/doc/extend.texi
> ===================================================================
> --- gcc/doc/extend.texi (revision 183001)
> +++ gcc/doc/extend.texi (working copy)
> @@ -2771,13 +2771,12 @@ efficient @code{jal} instruction.
>  @cindex @code{malloc} attribute
>  The @code{malloc} attribute is used to tell the compiler that a function
>  may be treated as if any non-@code{NULL} pointer it returns cannot
> -alias any other pointer valid when the function returns.
> +alias any other pointer valid when the function returns and that the memory
> +has undefined content.
>  This will often improve optimization.
>  Standard functions with this property include @code{malloc} and
> -@code{calloc}.  @code{realloc}-like functions have this property as
> -long as the old pointer is never referred to (including comparing it
> -to the new pointer) after the function returns a non-@code{NULL}
> -value.
> +@code{calloc}.  @code{realloc}-like functions do not have this
> +property as the memory pointed to does not have undefined content.
>
>  @item mips16/nomips16
>  @cindex @code{mips16} attribute
Richard Biener Jan. 10, 2012, 9:31 a.m. UTC | #2
On Mon, 9 Jan 2012, Xinliang David Li wrote:

> It looks non-ambiguous to me.

The new proposed version or the old?

Richard.

> David
> 
> On Mon, Jan 9, 2012 at 1:05 AM, Richard Guenther <rguenther@suse.de> wrote:
> >
> > Since GCC 4.4 applying the malloc attribute to realloc-like
> > functions does not work under the documented constraints because
> > the contents of the memory pointed to are not properly transfered
> > from the realloc argument (or treated as pointing to anything,
> > like 4.3 behaved).
> >
> > The following adjusts documentation to reflect implementation
> > reality (we do have an implementation detail that treats the
> > memory blob returned for non-builtins as pointing to any global
> > variable, but that is neither documented nor do I plan to do
> > so - I presume it is to allow allocation + initialization
> > routines to be marked with malloc, but even that area looks
> > susceptible to misinterpretation to me).
> >
> > Any comments?
> >
> > Thanks,
> > Richard.
> >
> > 2012-01-09  Richard Guenther  <rguenther@suse.de>
> >
> >        * doc/extend.texi (malloc attribute): Adjust according to
> >        implementation.
> >
> > Index: gcc/doc/extend.texi
> > ===================================================================
> > --- gcc/doc/extend.texi (revision 183001)
> > +++ gcc/doc/extend.texi (working copy)
> > @@ -2771,13 +2771,12 @@ efficient @code{jal} instruction.
> >  @cindex @code{malloc} attribute
> >  The @code{malloc} attribute is used to tell the compiler that a function
> >  may be treated as if any non-@code{NULL} pointer it returns cannot
> > -alias any other pointer valid when the function returns.
> > +alias any other pointer valid when the function returns and that the memory
> > +has undefined content.
> >  This will often improve optimization.
> >  Standard functions with this property include @code{malloc} and
> > -@code{calloc}.  @code{realloc}-like functions have this property as
> > -long as the old pointer is never referred to (including comparing it
> > -to the new pointer) after the function returns a non-@code{NULL}
> > -value.
> > +@code{calloc}.  @code{realloc}-like functions do not have this
> > +property as the memory pointed to does not have undefined content.
> >
> >  @item mips16/nomips16
> >  @cindex @code{mips16} attribute
> 
>
Xinliang David Li Jan. 10, 2012, 5:21 p.m. UTC | #3
of course your new version.

thanks,

David

On Tue, Jan 10, 2012 at 1:31 AM, Richard Guenther <rguenther@suse.de> wrote:
> On Mon, 9 Jan 2012, Xinliang David Li wrote:
>
>> It looks non-ambiguous to me.
>
> The new proposed version or the old?
>
> Richard.
>
>> David
>>
>> On Mon, Jan 9, 2012 at 1:05 AM, Richard Guenther <rguenther@suse.de> wrote:
>> >
>> > Since GCC 4.4 applying the malloc attribute to realloc-like
>> > functions does not work under the documented constraints because
>> > the contents of the memory pointed to are not properly transfered
>> > from the realloc argument (or treated as pointing to anything,
>> > like 4.3 behaved).
>> >
>> > The following adjusts documentation to reflect implementation
>> > reality (we do have an implementation detail that treats the
>> > memory blob returned for non-builtins as pointing to any global
>> > variable, but that is neither documented nor do I plan to do
>> > so - I presume it is to allow allocation + initialization
>> > routines to be marked with malloc, but even that area looks
>> > susceptible to misinterpretation to me).
>> >
>> > Any comments?
>> >
>> > Thanks,
>> > Richard.
>> >
>> > 2012-01-09  Richard Guenther  <rguenther@suse.de>
>> >
>> >        * doc/extend.texi (malloc attribute): Adjust according to
>> >        implementation.
>> >
>> > Index: gcc/doc/extend.texi
>> > ===================================================================
>> > --- gcc/doc/extend.texi (revision 183001)
>> > +++ gcc/doc/extend.texi (working copy)
>> > @@ -2771,13 +2771,12 @@ efficient @code{jal} instruction.
>> >  @cindex @code{malloc} attribute
>> >  The @code{malloc} attribute is used to tell the compiler that a function
>> >  may be treated as if any non-@code{NULL} pointer it returns cannot
>> > -alias any other pointer valid when the function returns.
>> > +alias any other pointer valid when the function returns and that the memory
>> > +has undefined content.
>> >  This will often improve optimization.
>> >  Standard functions with this property include @code{malloc} and
>> > -@code{calloc}.  @code{realloc}-like functions have this property as
>> > -long as the old pointer is never referred to (including comparing it
>> > -to the new pointer) after the function returns a non-@code{NULL}
>> > -value.
>> > +@code{calloc}.  @code{realloc}-like functions do not have this
>> > +property as the memory pointed to does not have undefined content.
>> >
>> >  @item mips16/nomips16
>> >  @cindex @code{mips16} attribute
>>
>>
>
> --
> Richard Guenther <rguenther@suse.de>
> SUSE / SUSE Labs
> SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
> GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer
Richard Biener Jan. 11, 2012, 9:43 a.m. UTC | #4
On Tue, 10 Jan 2012, Xinliang David Li wrote:

> of course your new version.

I have installed it on the trunk.

Richard.

> thanks,
> 
> David
> 
> On Tue, Jan 10, 2012 at 1:31 AM, Richard Guenther <rguenther@suse.de> wrote:
> > On Mon, 9 Jan 2012, Xinliang David Li wrote:
> >
> >> It looks non-ambiguous to me.
> >
> > The new proposed version or the old?
> >
> > Richard.
> >
> >> David
> >>
> >> On Mon, Jan 9, 2012 at 1:05 AM, Richard Guenther <rguenther@suse.de> wrote:
> >> >
> >> > Since GCC 4.4 applying the malloc attribute to realloc-like
> >> > functions does not work under the documented constraints because
> >> > the contents of the memory pointed to are not properly transfered
> >> > from the realloc argument (or treated as pointing to anything,
> >> > like 4.3 behaved).
> >> >
> >> > The following adjusts documentation to reflect implementation
> >> > reality (we do have an implementation detail that treats the
> >> > memory blob returned for non-builtins as pointing to any global
> >> > variable, but that is neither documented nor do I plan to do
> >> > so - I presume it is to allow allocation + initialization
> >> > routines to be marked with malloc, but even that area looks
> >> > susceptible to misinterpretation to me).
> >> >
> >> > Any comments?
> >> >
> >> > Thanks,
> >> > Richard.
> >> >
> >> > 2012-01-09  Richard Guenther  <rguenther@suse.de>
> >> >
> >> >        * doc/extend.texi (malloc attribute): Adjust according to
> >> >        implementation.
> >> >
> >> > Index: gcc/doc/extend.texi
> >> > ===================================================================
> >> > --- gcc/doc/extend.texi (revision 183001)
> >> > +++ gcc/doc/extend.texi (working copy)
> >> > @@ -2771,13 +2771,12 @@ efficient @code{jal} instruction.
> >> >  @cindex @code{malloc} attribute
> >> >  The @code{malloc} attribute is used to tell the compiler that a function
> >> >  may be treated as if any non-@code{NULL} pointer it returns cannot
> >> > -alias any other pointer valid when the function returns.
> >> > +alias any other pointer valid when the function returns and that the memory
> >> > +has undefined content.
> >> >  This will often improve optimization.
> >> >  Standard functions with this property include @code{malloc} and
> >> > -@code{calloc}.  @code{realloc}-like functions have this property as
> >> > -long as the old pointer is never referred to (including comparing it
> >> > -to the new pointer) after the function returns a non-@code{NULL}
> >> > -value.
> >> > +@code{calloc}.  @code{realloc}-like functions do not have this
> >> > +property as the memory pointed to does not have undefined content.
> >> >
> >> >  @item mips16/nomips16
> >> >  @cindex @code{mips16} attribute
> >>
> >>
> >
> > --
> > Richard Guenther <rguenther@suse.de>
> > SUSE / SUSE Labs
> > SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
> > GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer
> 
>
diff mbox

Patch

Index: gcc/doc/extend.texi
===================================================================
--- gcc/doc/extend.texi	(revision 183001)
+++ gcc/doc/extend.texi	(working copy)
@@ -2771,13 +2771,12 @@  efficient @code{jal} instruction.
 @cindex @code{malloc} attribute
 The @code{malloc} attribute is used to tell the compiler that a function
 may be treated as if any non-@code{NULL} pointer it returns cannot
-alias any other pointer valid when the function returns.
+alias any other pointer valid when the function returns and that the memory
+has undefined content.
 This will often improve optimization.
 Standard functions with this property include @code{malloc} and
-@code{calloc}.  @code{realloc}-like functions have this property as
-long as the old pointer is never referred to (including comparing it
-to the new pointer) after the function returns a non-@code{NULL}
-value.
+@code{calloc}.  @code{realloc}-like functions do not have this
+property as the memory pointed to does not have undefined content.
 
 @item mips16/nomips16
 @cindex @code{mips16} attribute