This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug other/32771] Fixincludes should fix realloc in <stdlib.h> in glibc
- From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Jul 2007 08:40:10 -0000
- Subject: [Bug other/32771] Fixincludes should fix realloc in <stdlib.h> in glibc
- References: <bug-32771-682@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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