This is the mail archive of the gcc-bugs@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]

[Bug other/32771] Fixincludes should fix realloc in <stdlib.h> in glibc



------- Comment #2 from rguenth at gcc dot gnu dot org  2007-07-16 08:40 -------
Note that sticking attribute realloc on realloc might just work because realloc
takes the old memory pointer as argument which makes it

  1) escape
  2) potentially read from / written to

So we only can manage to trick the compiler into mis-using the alias
information
it creates by making the program undefined like so:

#include <stdlib.h>

int foo()
{
  int *p, *q;
  p = malloc (4);
  q = realloc (p, 4);
  *q = 1;
  *p = 0;
  return *q;
}

where the compiler happily decides to return 1.

So basically, realloc acts as a barrier for stores and loads to/from the
old memory at the moment and the result is assigned a new nothing-aliasing
memory tag.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32771


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