[Bug c/98541] warning with -Wnonnull for array parameter with bound > 0

2023-11-04 Thread uecker at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98541

uecker at gcc dot gnu.org changed:

   What|Removed |Added

  Known to fail||11.0
 Resolution|--- |FIXED
 Status|NEW |RESOLVED
   Target Milestone|--- |14.0
 CC||uecker at gcc dot gnu.org

--- Comment #5 from uecker at gcc dot gnu.org ---
Fixed on trunk.

[Bug c/98541] warning with -Wnonnull for array parameter with bound > 0

2023-11-03 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98541

--- Comment #4 from CVS Commits  ---
The master branch has been updated by Martin Uecker :

https://gcc.gnu.org/g:6e9ee44d96e5bda8808dd9d8ccf58d2525383f6b

commit r14-5115-g6e9ee44d96e5bda8808dd9d8ccf58d2525383f6b
Author: Martin Uecker 
Date:   Thu Apr 13 19:35:15 2023 +0200

Reduce false positives for -Wnonnull for VLA parameters [PR98541]

This patch limits the warning about NULL arguments to VLA
parameters declared [static n].

PR c/98541

gcc/
* gimple-ssa-warn-access.cc
(pass_waccess::maybe_check_access_sizes): For VLA bounds
in parameters, only warn about null pointers with 'static'.

gcc/testsuite:
* gcc.dg/Wnonnull-4.c: Adapt test.
* gcc.dg/Wstringop-overflow-40.c: Adapt test.

[Bug c/98541] warning with -Wnonnull for array parameter with bound > 0

2021-01-06 Thread muecker at gwdg dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98541

--- Comment #3 from Martin Uecker  ---

Having to set the length to 0 for NULL pointers is problematic also because
zero-sized array types are now allowed in ISO C.


On the other hand, an optional warning that warns for all parameters declared
as array which are NULL (fixed length and VLA) might be useful.

[Bug c/98541] warning with -Wnonnull for array parameter with bound > 0

2021-01-06 Thread msebor at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98541

--- Comment #2 from Martin Sebor  ---
(In reply to Martin Sebor from comment #1)
> and necessary to prevent this use case.

I mean: ...to prevent invalidating it.

[Bug c/98541] warning with -Wnonnull for array parameter with bound > 0

2021-01-06 Thread msebor at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98541

Martin Sebor  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
 Ever confirmed|0   |1
 CC||msebor at gcc dot gnu.org
   Last reconfirmed||2021-01-06

--- Comment #1 from Martin Sebor  ---
Both the warning in the VLA case and its absence in the ordinary case are by
design.

The VLA case gets a warning because it seems suspicious to specify a nonzero
number of elements for an array and then null as the array (the VLA parameter
can be null when the bound is zero).  But I didn't consider the shared bound
use case so I suppose the warning could be relaxed to accommodate it, and
either changed to rely on the [static] for the bound as you suggest or on the
VLA parameter declared with attribute nonnull.  I can't think of a use case
where the bound isn't shared and where setting it to nonzero and passing a null
pointer would not be a bug.

My rationale for not issuing a warning for ordinary arrays with constant bounds
is that those are commonly treated as "optional," and so there relying on some
additional notation ([static] or nonnull) seems appropriate and necessary to
prevent this use case.