From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 79A073858D34; Fri, 27 Aug 2021 19:21:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 79A073858D34 From: "msebor at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Aug 2021 19:21:38 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102103 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=3D/dev/stdout z.c void f (void) {=20 int i; if (&i =3D=3D 0) // -Waddress (good) __builtin_abort (); } void g (void) { int a[1]; if (a =3D=3D 0) // missing warning __builtin_abort (); } void h (void) { int a[1][2]; if (a[0] =3D=3D 0) // missing warning __builtin_abort (); } z.c: In function =E2=80=98f=E2=80=99: z.c:4:10: warning: the comparison will always evaluate as =E2=80=98false=E2= =80=99 for the address of =E2=80=98i=E2=80=99 will never be NULL [-Waddress] 4 | if (&i =3D=3D 0) // -Waddress (good) | ^~ ;; Function f (f, funcdef_no=3D0, decl_uid=3D1943, cgraph_uid=3D1, symbol_o= rder=3D0) void f () { int i; : i =3D{v} {CLOBBER}; return; } ;; Function g (g, funcdef_no=3D1, decl_uid=3D1947, cgraph_uid=3D2, symbol_o= rder=3D1) void g () { int a[1]; : a =3D{v} {CLOBBER}; return; } ;; Function h (h, funcdef_no=3D2, decl_uid=3D1951, cgraph_uid=3D3, symbol_o= rder=3D2) void h () { int a[1][2]; : a =3D{v} {CLOBBER}; return; } Clang diagnoses both the one in f() and in g() (but not the one in h()). G= CC 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.=