This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/44555] Pointer evalutions, is that expected ?
- From: "zilvinas dot valinskas at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Jun 2010 10:29:07 -0000
- Subject: [Bug c/44555] Pointer evalutions, is that expected ?
- References: <bug-44555-19333@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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