https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61236
--- Comment #11 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Jakub Jelinek from comment #10) > If you believe the nonnull attribute on qsort is incorrect, then you should > report that as glibc bug, not gcc bug, the prototype is provided by glibc. > The more aggressive GCC optimization is documented e.g. in > https://gcc.gnu.org/gcc-4.9/porting_to.html > plus we hope to add -fsanitize=undefined instrumentation for this in the > upcoming GCC version, so you find it out more easily. It is not incorrect as the C standard says this about qsort: nmemb can have the value zero on a call to that function; the comparison function is not called, a search finds no matching element, and sorting performs no rearrangement. Pointer arguments on such a call shall still have valid values, as described in 7.1.4. POSIX 2008 defers to the C standard now so this is neither a glibc or a GCC bug in the end.