https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108893

--- Comment #10 from Jonny Grant <jg at jguk dot org> ---
(In reply to Andrew Pinski from comment #9)
> (In reply to Jonny Grant from comment #8)
> > So the caveat is this issue (2). I can't use attribute nonnull due to these
> > optimizations that cannot be disabled.
> 
> But you declare that argument cannot be null. So why keep around a check for
> it being null. The nonnull attribute is basically saying there is a
> requirement for it being nonnull no matter what. It basically says if a null
> is passed undefined behavior happens.

My concern would be when building a library, the nullptr checks might be
removed by the optimizer, and then when linked a nullptr could slip through if
they called functions indirectly (ie. not via a header with the same attribute
nonnull)

I would rather avoid undefined behavior nullptr dereference SEGV, as safety
critical software. For instance such functions could check parameters and
return -1 if a nullptr is present. So application can handle it, log an issue
etc

So, I'm adding -fno-delete-null-pointer-checks to my builds as I didn't realise
that was on already in -O3.

Reply via email to