------- Comment #2 from zilvinas dot valinskas at gmail dot com 2010-06-16 10:29 ------- I don't agree. This is an optimizer bug ("dead code elimination" don't know much of GCC). Consider that there is a function like this:
$ cat ptr.h struct a { char b[100]; int a; }; $ cat ptr.c $ cat ptr.c #include <stdio.h> #include "ptr.h" int main(int argc, char *argv[]) { struct a *a = NULL; function(a); return 0; } $ cat func.c #include <stdio.h> #include "ptr.h" void function(struct a *a) { void *ptr; if (&a->b) puts("ok, not null #1"); if (&a->b == NULL) puts("ok, null ? #1"); ptr = &a->b; if (ptr) puts("ok, not null #2"); if (ptr == NULL) puts("ok, null ? #2"); } $ gcc ptr.c func.c -o ptr $ ./ptr $ ./ptr ok, not null #1 ok, null ? #1 ok, null ? #2 Still the same problem (maybe not a problem). But how does GCC is able to tell that in this particular case func() is invoked with a NULL pointer as parameter (not valid pointer) and eliminates code just like that ??? Mind you this code is an approximation of bug I was tracking not so long time ago. -- zilvinas dot valinskas at gmail dot com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |UNCONFIRMED Resolution|INVALID | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44555