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


jsm@polyomino.org.uk (Joseph S. Myers)  wrote on 02.01.04 in <Pine.LNX.4.58.0401020136480.18607@digraph.polyomino.org.uk>:

> On Thu, 2 Jan 2004, Gabriel Dos Reis wrote:
>
> > Not really.  As Joseph pointed out earlier, if you save the pointer
> > value in an array of unsigned char and latter do bits compare, you can
> > safely determine whether realloc returns the same pointer or not.
> >
> > I don't know how that affect the design of the aliasing algorithm in
> > the compiler though.
>
> Probably the fact that this involves taking the address of copies of the
> pointer should inhibit alias analysis about where those pointer objects
> might point to.  If not, it ought to (a pointer can become based on
> another one through bitwise examination and comparison, not just through
> direct copies) though the exact rules may depend on the resolution of the
> referenced DR.  In any case this is not realloc specific (the same
> problems with bit-representations can arise with freed pointers and
> malloc, etc.).

Note that the compiler may not know that the address of a different  
variable containing the pointer value is taken in a different function:

char ps[sizeof(void *)];

void save_pointer(void *p)
{
  memcpy(ps, &p, sizeof(p));
}

void my_function(void)
{
   my_type *q;
   ....
   save_pointer(q);
   q = realloc(q, 2*sizeof(*q));
   ...
}


MfG Kai


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