public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/102103] New: missing warning for arrays
@ 2021-08-27 19:21 msebor at gcc dot gnu.org
2021-08-27 19:23 ` [Bug c/102103] " pinskia at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-08-27 19:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102103
Bug ID: 102103
Summary: missing warning for arrays
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
GCC issues -Waddress only for the equality test in f() but not those in g() or
h(), even though all three evaluate to false (and even though GCC folds all
three to false even with no optimization). It would be helpful to diagnose all
three.
$ cat z.c && gcc -S -Wall -fdump-tree-optimized=/dev/stdout z.c
void f (void)
{
int i;
if (&i == 0) // -Waddress (good)
__builtin_abort ();
}
void g (void)
{
int a[1];
if (a == 0) // missing warning
__builtin_abort ();
}
void h (void)
{
int a[1][2];
if (a[0] == 0) // missing warning
__builtin_abort ();
}
z.c: In function ‘f’:
z.c:4:10: warning: the comparison will always evaluate as ‘false’ for the
address of ‘i’ will never be NULL [-Waddress]
4 | if (&i == 0) // -Waddress (good)
| ^~
;; Function f (f, funcdef_no=0, decl_uid=1943, cgraph_uid=1, symbol_order=0)
void f ()
{
int i;
<bb 2> :
i ={v} {CLOBBER};
return;
}
;; Function g (g, funcdef_no=1, decl_uid=1947, cgraph_uid=2, symbol_order=1)
void g ()
{
int a[1];
<bb 2> :
a ={v} {CLOBBER};
return;
}
;; Function h (h, funcdef_no=2, decl_uid=1951, cgraph_uid=3, symbol_order=2)
void h ()
{
int a[1][2];
<bb 2> :
a ={v} {CLOBBER};
return;
}
Clang diagnoses both the one in f() and in g() (but not the one in h()). GCC
4.4.7 does as well but the latter has been lost since GCC 4.5 (see
https://gcc.godbolt.org/z/8dbjxv89E) so technically this could be viewed as a
regression.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/102103] missing warning for arrays
2021-08-27 19:21 [Bug c/102103] New: missing warning for arrays msebor at gcc dot gnu.org
@ 2021-08-27 19:23 ` pinskia at gcc dot gnu.org
2021-08-30 23:00 ` [Bug c/102103] missing warning comparing array address to null msebor at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-27 19:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102103
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=33925
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Related to PR 33925.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/102103] missing warning comparing array address to null
2021-08-27 19:21 [Bug c/102103] New: missing warning for arrays msebor at gcc dot gnu.org
2021-08-27 19:23 ` [Bug c/102103] " pinskia at gcc dot gnu.org
@ 2021-08-30 23:00 ` msebor at gcc dot gnu.org
2021-09-01 2:22 ` msebor at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-08-30 23:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102103
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Ever confirmed|0 |1
Summary|missing warning for arrays |missing warning comparing
| |array address to null
Last reconfirmed| |2021-08-30
Assignee|unassigned at gcc dot gnu.org |msebor at gcc dot gnu.org
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/102103] missing warning comparing array address to null
2021-08-27 19:21 [Bug c/102103] New: missing warning for arrays msebor at gcc dot gnu.org
2021-08-27 19:23 ` [Bug c/102103] " pinskia at gcc dot gnu.org
2021-08-30 23:00 ` [Bug c/102103] missing warning comparing array address to null msebor at gcc dot gnu.org
@ 2021-09-01 2:22 ` msebor at gcc dot gnu.org
2021-10-01 17:57 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-09-01 2:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102103
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Patch: https://gcc.gnu.org/pipermail/gcc-patches/2021-September/578546.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/102103] missing warning comparing array address to null
2021-08-27 19:21 [Bug c/102103] New: missing warning for arrays msebor at gcc dot gnu.org
` (2 preceding siblings ...)
2021-09-01 2:22 ` msebor at gcc dot gnu.org
@ 2021-10-01 17:57 ` cvs-commit at gcc dot gnu.org
2021-10-01 18:00 ` msebor at gcc dot gnu.org
2021-10-02 9:10 ` egallager at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-01 17:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102103
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:
https://gcc.gnu.org/g:4dc7ce6fb3917958d1a6036d8acf2953b9c1b868
commit r12-4059-g4dc7ce6fb3917958d1a6036d8acf2953b9c1b868
Author: Martin Sebor <msebor@redhat.com>
Date: Fri Oct 1 11:50:25 2021 -0600
Enhance -Waddress to detect more suspicious expressions [PR102103].
Resolves:
PR c/102103 - missing warning comparing array address to null
gcc/ChangeLog:
PR c/102103
* doc/invoke.texi (-Waddress): Update.
* gengtype.c (write_types): Avoid -Waddress.
* poly-int.h (POLY_SET_COEFF): Avoid using null.
gcc/c-family/ChangeLog:
PR c/102103
* c-common.c (decl_with_nonnull_addr_p): Handle members.
Check and perform warning suppression.
(c_common_truthvalue_conversion): Enhance warning suppression.
gcc/c/ChangeLog:
PR c/102103
* c-typeck.c (maybe_warn_for_null_address): New function.
(build_binary_op): Call it.
gcc/cp/ChangeLog:
PR c/102103
* typeck.c (warn_for_null_address): Enhance.
(cp_build_binary_op): Call it also for member pointers.
gcc/fortran/ChangeLog:
PR c/102103
* array.c: Remove an unnecessary test.
* trans-array.c: Same.
gcc/testsuite/ChangeLog:
PR c/102103
* g++.dg/cpp0x/constexpr-array-ptr10.C: Suppress a valid warning.
* g++.dg/warn/Wreturn-local-addr-6.C: Correct a cast.
* gcc.dg/Waddress.c: Expect a warning.
* c-c++-common/Waddress-3.c: New test.
* c-c++-common/Waddress-4.c: New test.
* g++.dg/warn/Waddress-5.C: New test.
* g++.dg/warn/Waddress-6.C: New test.
* g++.dg/warn/pr101219.C: Expect a warning.
* gcc.dg/Waddress-3.c: New test.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/102103] missing warning comparing array address to null
2021-08-27 19:21 [Bug c/102103] New: missing warning for arrays msebor at gcc dot gnu.org
` (3 preceding siblings ...)
2021-10-01 17:57 ` cvs-commit at gcc dot gnu.org
@ 2021-10-01 18:00 ` msebor at gcc dot gnu.org
2021-10-02 9:10 ` egallager at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-10-01 18:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102103
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
Target Milestone|--- |12.0
--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
Done for GCC 12.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/102103] missing warning comparing array address to null
2021-08-27 19:21 [Bug c/102103] New: missing warning for arrays msebor at gcc dot gnu.org
` (4 preceding siblings ...)
2021-10-01 18:00 ` msebor at gcc dot gnu.org
@ 2021-10-02 9:10 ` egallager at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: egallager at gcc dot gnu.org @ 2021-10-02 9:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102103
Eric Gallager <egallager at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |egallager at gcc dot gnu.org
--- Comment #5 from Eric Gallager <egallager at gcc dot gnu.org> ---
This should probably get a note in gcc-12/changes.html IMO
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-10-02 9:10 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-27 19:21 [Bug c/102103] New: missing warning for arrays msebor at gcc dot gnu.org
2021-08-27 19:23 ` [Bug c/102103] " pinskia at gcc dot gnu.org
2021-08-30 23:00 ` [Bug c/102103] missing warning comparing array address to null msebor at gcc dot gnu.org
2021-09-01 2:22 ` msebor at gcc dot gnu.org
2021-10-01 17:57 ` cvs-commit at gcc dot gnu.org
2021-10-01 18:00 ` msebor at gcc dot gnu.org
2021-10-02 9:10 ` egallager 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).