public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/102103] New: missing warning for arrays Date: Fri, 27 Aug 2021 19:21:37 +0000 [thread overview] Message-ID: <bug-102103-4@http.gcc.gnu.org/bugzilla/> (raw) 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.
next reply other threads:[~2021-08-27 19:21 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-08-27 19:21 msebor at gcc dot gnu.org [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-102103-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).