This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: arm-eabi-gcc with -O2 is wrong code output.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]