This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: malloc attributes and realloc


Gabriel Dos Reis wrote:
> 
> Robert Dewar <dewar@gnat.com> writes:
> 
> | I definitely think that in the case
> | of malloc, we should take the viewpoint that if a pointer
> | has been freed, any reference to it is plain wrong.
> 
> We're in violent agreement here.

Yep.  I *think* we all pretty much agree that we are in roughly
three camps vis-a-vis realloc:

1.  realloc is not malloc-like in that if it returns the original
    pointer, then old aliases are still be valid.  If the "standard"
    says otherwise, then the standard is in error and should be fixed.

2.  The standardizers did what they explicitly intended to do and
    programmers must re-set their aliasing pointers after a realloc,
    even if the returned address is unchanged.  That said, common
    practice is to skip the extra work and the marginal optimizations
    possible are definitely not worth the disruption that would be
    caused by presuming that realloc returns a non-aliasable pointer.

3.  The standardizers did what they explicitly intended to do and
    programmers must re-set their aliasing pointers after a realloc,
    period.  If -O2 wrecks such a program, then too bad.

None of these is directly addressable by GCC.  I believe #1 needs
to be addressed by The Open Group, #2 can be implemented by the
libc folks regardless of any decision by The Open Group, and #3
is a poor choice.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]