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


Daniel Berlin <dberlin@dberlin.org> writes:

| On Jan 1, 2004, at 10:31 AM, Jeff Sturm wrote:
| 
| > On Thu, 1 Jan 2004, Joseph S. Myers wrote:
| >> Can __attribute__((__malloc__)) safely be used on realloc-type
| >> functions?
| >
| > My non-expert understanding is "no"...
| >
| >> /* Reallocate memory without fail.  This works like xmalloc.  Note,
| >>    realloc type functions are not suitable for attribute malloc since
| >>    they may return the same address across multiple calls. */
| >
| > This comment is misleading.  The pointer address returned by a
| > malloc-type
| > function isn't significant to alias analysis.
| 
| This isn't true.
| It's quite significant, because it means it can't be the same pointer
| as before.

Well, technically, it could be as hinted by the standard:

       [#4] The realloc function  returns  a  pointer  to  the  new
       object  (which  may  have the same value as a pointer to the
       old object), or a null pointer if the new object  could  not
       be allocated.

| At least, that's what all the points-to analysis algorithms i'm aware
| of expect from a "heap allocation function".

-- Gaby


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