Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Usually, when one marks an argument as nonnull via a function attribute, one wants NULL checks to be removed.


There's two similar but distinct function attributes for nullability. One affects codegen, one affects diagnostics only.


Which are those? I only know about nonnull, nonnull_if_nonzero and returns_nonnull:

https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attribute...


Irrelevant, 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!


That 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: