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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|---                         |INVALID

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
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.

> When the compiler knows at that point that base (=x) is NULL as an
> argument to qsort(), why isn't it warning when the attribute expects it
> to be non-NULL, esp. as it is using this inferred decision to optimize
> code down below?

But the compiler doesn't know there that x is NULL.  The compiler sees a call
to a function which must not be called with NULL, and from that derives the
value range of x to be anything but NULL.  Instead of qsort consider here some
less controversial function, e.g. memcpy, where the standard is very clear that
memcpy (NULL, "", 0); or memcpy ("", NULL, 0); is invalid despite the length 0.

Reply via email to