[Bug c/100404] New: Unable to disable removal of null pointer checks for nonnull function arguments
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100404 Bug ID: 100404 Summary: Unable to disable removal of null pointer checks for nonnull function arguments Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: gccgc at bithub dot de Target Milestone: --- Based on the documentation of the "nonnull" function attribute "-fno-delete-null-pointer-checks" may be used to disable compiler optimizations based on the knowledge that a function argument cannot be null ([1]). However, on GCC 10.2 with optimization level 1 (and also on earlier versions with optimization level 2) the NULL check is eliminated from the following sample program: int __attribute__ ((nonnull)) isnull(char *ptr) { if (ptr == 0) return 0; return 1; } int main(void) { return isnull(0); } Compiling this sample without optimizations and "-fdelete-null-pointer-checks" does not eliminate the check so the optimization seems to be triggered by another optimization. [1] https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-nonnull-function-attribute
[Bug tree-optimization/100404] Unable to disable removal of null pointer checks for nonnull function arguments
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100404 Philip Lorenz changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |INVALID --- Comment #5 from Philip Lorenz --- I understand that the issue seems odd at first so let me provide some additional background on how I encountered this issue: I was analysing a segmentation fault in pseudo's [1] statx() wrapper function which was caused by the elimination of the null pointer check before dereferencing of its "path" parameter for a comparison. GCC removed this check as glibc marks statx's() pointer arguments as nonnull. However, the statx() man page explicitly mentions that null arguments trigger yield a EFAULT which is used by the Rust standard library implementation to determine support of the statx() on the host machine. I erroneously assumed that the "-fno-delete-null-pointer-checks" option may be used to disable this behaviour but I understand that this isn't actually the case so if there is no way to disable the optimization I'll work around the optimization by moving access to the pointers into a (non-inlinable) helper function instead. [1] http://git.yoctoproject.org/cgit/cgit.cgi/pseudo/