http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54954
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|INVALID |WORKSFORME --- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> --- I said it works for me because it works with -fno-builtin-malloc. Andrew, you are wrong - the malloc attribute itself does not tell us that the malloc call may not clobber global memory. I've massaged the testcase to build w/o warnings: m.c: #include <string.h> #include <stdio.h> void *__libc_malloc(size_t size); void *malloc(size_t size) { increment_count(); return (void*)__libc_malloc(size); } t.c: #include <assert.h> #include <stdlib.h> #include <stdio.h> static int count = 0; void increment_count(void) { count++; } int main (void) { char *ptr; count = 0; ptr = malloc(1); assert(ptr); assert(count); printf("%p\n", ptr); free(ptr); return 0; } rguenther@murzim:/tmp> /space/rguenther/install/gcc-4.7.0/bin/gcc -o t t.c m.c -O2 -fno-builtin-malloc rguenther@murzim:/tmp> ./t 0x1127010 rguenther@murzim:/tmp> /space/rguenther/install/gcc-4.7.0/bin/gcc -o t t.c m.c -O2 rguenther@murzim:/tmp> ./t t: t.c:18: main: Assertion `count' failed. Aborted Works with all GCC versions I tried. I tried on x86_64-linux (just in case RTL optimizers break this in which case the target architecture may be important).