This is the mail archive of the gcc-patches@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]

Re: Removal of useless null pointer checks





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.


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