On Wed, 9 Feb 2022, Jakub Jelinek wrote:

> On Wed, Feb 09, 2022 at 10:03:02AM +0100, Richard Biener wrote:
> > I see there are still targets doing sth like
> > 
> > static void
> > msp430_option_override (void)
> > {
> >   /* The MSP430 architecture can safely dereference a NULL pointer.  In 
> > fact,
> >      there are memory mapped registers there.  */
> >   flag_delete_null_pointer_checks = 0;
> 
> Sure, that is the typical embedded target case.

Yes.

> And the user option is in case users are using a typically non-embedded
> target case in an embedded way, even on x86_64-linux one can mmap something
> at address 0 if one tweaks some kernel config parameters.
> 
> I guess I could change
> default_addr_space_zero_address_valid from return false; to
>   if (!flag_delete_null_pointer_checks)
>     return true;
>   if (folding_initializer)
>     return false;
>   if (current_function_decl
>       && sanitize_flags_p (SANITIZE_NULL | SANITIZE_NONNULL_ATTRIBUTE
>                          | SANITIZE_RETURNS_NONNULL_ATTRIBUTE,
>                          current_function_decl))
>     return true;
>   return false;
> and change the i386 one to also call the default version.

That does look like bogus abstraction though - I'd rather have
the target be specific w/o option checks and replace 
targetm.zero_addres_valid uses with a wrapper (like you do for
flag_delete_null_pointer_checks), if we think that the specific
query should be adjusted by sanitize flags (why?) or
folding_initializer (why?).

> Replacing all the flag_delete_null_pointer_checks uses
> with some wrappers around the target hook will be less fun, not sure if the
> pointer type will be always visible there...

I'd only replace target hook invocations.  Checking whether
NULL pointers are validly pointing to objects should be different
from checking whether optimization should remove checks for NULL.
That we overload -fno-delete-null-pointer-checks is a mistake
difficult to undo.  But at least making targets not set
that flag as we now have a proper target hook would be a good
start.

> > Did you replace all flag_delete_null_pointer_checks uses?
> 
> I did.

OK, just wanted to check.

> >  Can you rename the flag just to be sure?
> 
> Sure.

flag_internal_dnpc or so ;)

>       Jakub

Reply via email to