Re: Null pointer check elimination

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 03/08/11 22:23, richardcavell@xxxxxxxx wrote:
> 
> foo (char *x)
> {
>  char ret = *x;
> 
>  if (x)
>    com();
>  else
>    bar();
>  return ret;
> }
> 
>> It is expected that the compiler will eliminate the pointer check with 
> the option '-fdelete-null-pointer-checks' or with >the option -O2, -O3,
> or -Os.
> 
> Hang on, why would it eliminate the null pointer check, if the null
> pointer check is in the source code?  Are you assuming that the compiler
> knows for certain that x is non zero when it compiles the function?
X was dereferenced in the initialization of ret.  Dereferencing NULL is
not a ANSI/ISO confirming program and the compiler is free to optimize
away any checks of X against NULL that are dominated by the dereference
of X.

jeff
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJNdxFIAAoJEBRtltQi2kC7SWIIAKPE/8CH70og472RvWy5oACZ
FyjxiYyPJJqwpd1TPwap0eAjrEPubXwTWCo3RDpfFlAeDTR5kTWrZVjh2isqgdsd
zYQwwvLDtQXCgBNBocEzRU+1ldXrq3evW92KndxueWG/e3QvCHYHrJD+Alg4jPZt
brHLFq5ElscxCcaRxeXpgl3zRZ9KwdgDST7zciBMFlwCknAKpQROg9iYAH7W6TL0
/DDjjyHL+BG4Xw4I3E1aYyDQbf4jE32TufFpXIcqDVh8MolmuE3ziijmwmYcDXxj
1QB2HWnFTsDEj6O7UuX4eomuczRfsfTFfmxro5SXToaWzabFW55KZrXlmEd9xtE=
=QFJH
-----END PGP SIGNATURE-----


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux