public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c/98541] New: warning with -Wnonnull for array parameter with bound > 0 @ 2021-01-05 16:12 muecker at gwdg dot de 2021-01-06 18:08 ` [Bug c/98541] " msebor at gcc dot gnu.org ` (4 more replies) 0 siblings, 5 replies; 6+ messages in thread From: muecker at gwdg dot de @ 2021-01-05 16:12 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98541 Bug ID: 98541 Summary: warning with -Wnonnull for array parameter with bound > 0 Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: muecker at gwdg dot de Target Milestone: --- In the example void foo(int n, double x[n]); void f(void) { foo(1, 0); } there is a warning x.c: In function ‘f’: x.c:7:9: warning: argument 1 of variable length array ‘double[n]’ is null but the corresponding bound argument 2 value is 1 [-Wnonnull] 7 | foo(1, 0); | ^~~~~~~~~ x.c:3:6: note: in a call to function ‘foo’ 3 | void foo(int n, double x[n]); | ^~~ But the bound > 0 does not imply that 'x' is not NULL. (static would imply this). There is also no warning with a constant bound > 0. Passing NULL is useful for optional arguments and when the bound is shared between different parameters, it can not be passed as zero. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/98541] warning with -Wnonnull for array parameter with bound > 0 2021-01-05 16:12 [Bug c/98541] New: warning with -Wnonnull for array parameter with bound > 0 muecker at gwdg dot de @ 2021-01-06 18:08 ` msebor at gcc dot gnu.org 2021-01-06 18:12 ` msebor at gcc dot gnu.org ` (3 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: msebor at gcc dot gnu.org @ 2021-01-06 18:08 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98541 Martin Sebor <msebor at gcc dot gnu.org> 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 <msebor at gcc dot gnu.org> --- 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. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/98541] warning with -Wnonnull for array parameter with bound > 0 2021-01-05 16:12 [Bug c/98541] New: warning with -Wnonnull for array parameter with bound > 0 muecker at gwdg dot de 2021-01-06 18:08 ` [Bug c/98541] " msebor at gcc dot gnu.org @ 2021-01-06 18:12 ` msebor at gcc dot gnu.org 2021-01-06 19:06 ` muecker at gwdg dot de ` (2 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: msebor at gcc dot gnu.org @ 2021-01-06 18:12 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98541 --- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> --- (In reply to Martin Sebor from comment #1) > and necessary to prevent this use case. I mean: ...to prevent invalidating it. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/98541] warning with -Wnonnull for array parameter with bound > 0 2021-01-05 16:12 [Bug c/98541] New: warning with -Wnonnull for array parameter with bound > 0 muecker at gwdg dot de 2021-01-06 18:08 ` [Bug c/98541] " msebor at gcc dot gnu.org 2021-01-06 18:12 ` msebor at gcc dot gnu.org @ 2021-01-06 19:06 ` muecker at gwdg dot de 2023-11-03 22:21 ` cvs-commit at gcc dot gnu.org 2023-11-04 10:01 ` uecker at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: muecker at gwdg dot de @ 2021-01-06 19:06 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98541 --- Comment #3 from Martin Uecker <muecker at gwdg dot de> --- 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. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/98541] warning with -Wnonnull for array parameter with bound > 0 2021-01-05 16:12 [Bug c/98541] New: warning with -Wnonnull for array parameter with bound > 0 muecker at gwdg dot de ` (2 preceding siblings ...) 2021-01-06 19:06 ` muecker at gwdg dot de @ 2023-11-03 22:21 ` cvs-commit at gcc dot gnu.org 2023-11-04 10:01 ` uecker at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: cvs-commit at gcc dot gnu.org @ 2023-11-03 22:21 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98541 --- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Martin Uecker <uecker@gcc.gnu.org>: https://gcc.gnu.org/g:6e9ee44d96e5bda8808dd9d8ccf58d2525383f6b commit r14-5115-g6e9ee44d96e5bda8808dd9d8ccf58d2525383f6b Author: Martin Uecker <uecker@tugraz.at> 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. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/98541] warning with -Wnonnull for array parameter with bound > 0 2021-01-05 16:12 [Bug c/98541] New: warning with -Wnonnull for array parameter with bound > 0 muecker at gwdg dot de ` (3 preceding siblings ...) 2023-11-03 22:21 ` cvs-commit at gcc dot gnu.org @ 2023-11-04 10:01 ` uecker at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: uecker at gcc dot gnu.org @ 2023-11-04 10:01 UTC (permalink / raw) To: 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. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-11-04 10:01 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-01-05 16:12 [Bug c/98541] New: warning with -Wnonnull for array parameter with bound > 0 muecker at gwdg dot de 2021-01-06 18:08 ` [Bug c/98541] " msebor at gcc dot gnu.org 2021-01-06 18:12 ` msebor at gcc dot gnu.org 2021-01-06 19:06 ` muecker at gwdg dot de 2023-11-03 22:21 ` cvs-commit at gcc dot gnu.org 2023-11-04 10:01 ` uecker at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).