This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Removal of useless null pointer checks
- To: law at cygnus dot com
- Subject: Re: Removal of useless null pointer checks
- From: John Vickers <John dot Vickers at PaceMicro dot com>
- Date: Tue, 21 Sep 1999 12:45:29 +0100
- CC: gcc-patches at gcc dot gnu dot org
- Organization: Pace Microtechnology PLC
- References: <1171.937835736@upchuck.cygnus.com>
Jeffrey A Law wrote:
>
> I know I've mentioned this little optimizer a few times, but I just haven't
> had time to contribute it.
>
> It is sometimes possible to use global dataflow analysis to determine that
> a particular pointer can not be null at a given null pointer check.
>
> In particular if all paths to a null pointer check use the same pointer to
> do a memory load/store, then we know that the pointer must not be null
> (otherwise the memory reference would have faulted).
The machine might not have an MMU, or any other means of causing a fault.
Some unfortunate machines require writeable memory or have I/O at
or very near address zero.
There's also the weird possibility of handling the fault & continuing.
OTOH, in standards terms, it seems that dereferencing a null pointer
gives undefined behaviour.
I guess this optimisation won't cause as much grief as the
strict-aliasing stuff...
Linux kernel traps null pointers, yes ?
Regards,
John.