This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
GCC 3.4 optimisation of if (&ptr == NULL)
- From: "John Neil" <jneil at atrove dot com>
- To: <gcc at gcc dot gnu dot org>
- Date: Thu, 4 Dec 2003 09:30:01 +0800
- Subject: GCC 3.4 optimisation of if (&ptr == NULL)
- Organization: Atrove Systems
I recently spent time upgrading my embedded application form gcc 3.2 to the
current cvs version of gcc 3.4. Whilst doing this I found that gcc 3.4 was
removing the "if (&ptr == NULL) as shown in the following test case
extern void* g_ptr;
int test()
{
if (&g_ptr == 0)
return 1;
else
return 0;
}
Always returns 0 which can be seen in the generated assembler
Generaged with (m68k-rtems-gcc).
NO_APP
.file "test.i"
.text
.align 2
.globl test
.type test, @function
test:
link.w %a6,#0
clr.l %d0
unlk %a6
rts
.size test, .-test
.ident "GCC: (GNU) 3.4 20031125 (experimental)"
Now I would agree normally that the address of a variable cannot be zero,
however in the embedded environment this technique is used to pass
information from the linker file to the C application, as was the case with
my application. In this case the address can indeed be zero. I tried
various different levels of optimization to no avail, so I was wondering if
anybody could shed some light on this change
Cheers
John