public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* GCC 3.4 optimisation of if (&ptr == NULL)
@ 2003-12-04  1:44 John Neil
  2003-12-04  1:51 ` Andrew Pinski
  2003-12-04  2:36 ` Richard Henderson
  0 siblings, 2 replies; 3+ messages in thread
From: John Neil @ 2003-12-04  1:44 UTC (permalink / raw)
  To: gcc

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




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: GCC 3.4 optimisation of if (&ptr == NULL)
  2003-12-04  1:44 GCC 3.4 optimisation of if (&ptr == NULL) John Neil
@ 2003-12-04  1:51 ` Andrew Pinski
  2003-12-04  2:36 ` Richard Henderson
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Pinski @ 2003-12-04  1:51 UTC (permalink / raw)
  To: John Neil; +Cc: gcc, Andrew Pinski


On Dec 3, 2003, at 17:30, John Neil wrote:

> 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;


What you want is to mark the variable as weak otherwise GCC assumes the 
address is not
0.

Thanks,
Andrew Pinski

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: GCC 3.4 optimisation of if (&ptr == NULL)
  2003-12-04  1:44 GCC 3.4 optimisation of if (&ptr == NULL) John Neil
  2003-12-04  1:51 ` Andrew Pinski
@ 2003-12-04  2:36 ` Richard Henderson
  1 sibling, 0 replies; 3+ messages in thread
From: Richard Henderson @ 2003-12-04  2:36 UTC (permalink / raw)
  To: John Neil; +Cc: gcc

On Thu, Dec 04, 2003 at 09:30:01AM +0800, John Neil wrote:
> extern void* g_ptr; 

If you want &g_ptr to be 0, then g_ptr must be declared weak.

> however in the embedded environment this technique is used to pass
> information from the linker file to the C application..

Ug.  There are much better ways to accomplish this.


r~

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-12-04  1:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-04  1:44 GCC 3.4 optimisation of if (&ptr == NULL) John Neil
2003-12-04  1:51 ` Andrew Pinski
2003-12-04  2:36 ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).