This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
danger: Global Null Pointer Test Elimination
- To: gcc at gcc dot gnu dot org
- Subject: danger: Global Null Pointer Test Elimination
- From: veksler at il dot ibm dot com
- Date: Thu, 23 Sep 1999 18:21:35 +0300
IMHO this is a dangerous optimization. Consider code written for systems that
have no MMU, and thus accessing the NULL address is perfectly valid. For
example, the old C64 had a CPU with a special memory mapped register at address
0.
You can argue that this optimization will be turned off for MMU-less
environments, but it will not be enough. Consider an emulator for MMU-less
system running on an MMU-able system, such as a DOS emulator on Linux. This
emulator can mmap page 0 to an actual memory region, in this case gcc will
generate invalid code. I can provide more examples to prove my point.
This optimization should not be activated for -O2 or less, and it should be
possible to turn it off for higher levels.
I did not verify it, but I hope that the optimization is not never performed for
volatile pointers.
Michael