This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: arm-eabi-gcc with -O2 is wrong code output.
- From: Andrew Pinski <pinskia at gmail dot com>
- To: Ry deen <rydeen999 at yahoo dot co dot jp>
- Cc: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 7 Feb 2011 18:18:03 -0800
- Subject: Re: arm-eabi-gcc with -O2 is wrong code output.
- References: <20110208021106.58036.qmail@web2503.mail.tnz.yahoo.co.jp>
2011/2/7 Ry deen <rydeen999@yahoo.co.jp>:
> Hi all,
>
> The code that contains the code shown below is compiled
> with arm-eabi-gcc -O2.
> Â Â Â Âif((aaa_struct *)NULL == aaa) {
> Â Â Â Â Â Â Â Âprintf("1\n");
> Â Â Â Â}
> Â Â Â Âelse {
> Â Â Â Â Â Â Â Âprintf("2\n");
> Â Â Â Â}
>
> Â Â Â Âbbb = aaa->member1;
The output is correct because deferencing a NULL pointer is undefined.
GCC assumes after deferencing a pointer, the pointer will not be a
NULL pointer.
Use -fno-delete-null-pointer-checks if you don't want the compiler to
use this assumption (that is allowed by the C standard).
-- Pinski