3 ms·
Usually, when one marks an argument as nonnull via a function attribute, one wants NULL checks to be removed.
by ryao 2y ago
Usually, when one marks an argument as nonnull via a function attribute, one wants NULL checks to be removed.
- ndesaulniers 2y agoThere's two similar but distinct function attributes for nullability. One affects codegen, one affects diagnostics only.
- ryao 2y agoWhich are those? I only know about nonnull, nonnull_if_nonzero and returns_nonnull: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attribute...
- AceJohnny2 2y agoIrrelevant, because delete-null-pointer-checks happens even in absence of nonnull function attribute, see GP's godbolt link, and the documentation that omits any reference to that function attribute. That's what makes it dangerous!
- ryao 2y agoThat is a side effect of passing the pointer as a function parameter marked nonnull. It implies that the pointer is nonnull and any NULL checks against it can be removed. Pass it to a normal function and you will not see the NULL check removed.