From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21054 invoked by alias); 16 Jun 2010 10:29:20 -0000 Received: (qmail 20995 invoked by uid 48); 16 Jun 2010 10:29:07 -0000 Date: Wed, 16 Jun 2010 10:29:00 -0000 Message-ID: <20100616102907.20994.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug c/44555] Pointer evalutions, is that expected ? In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "zilvinas dot valinskas at gmail dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-06/txt/msg01687.txt.bz2 ------- 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 #include "ptr.h" int main(int argc, char *argv[]) { struct a *a = NULL; function(a); return 0; } $ cat func.c #include #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