From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C88C43858D38; Sun, 25 Jun 2023 09:58:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C88C43858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687687120; bh=5enc7tHOfevyrk+BxfNAO1WA7XyuG4lpSR7RhudCkyg=; h=From:To:Subject:Date:From; b=goS7Zqy4+O6r0G5vNPdSitLbYPhd3No4m3nc1jfkV01EA4QDSzyRke74qQmrzamz1 zKnSILym4UqdbMB50b6IL8UxCY+xQyaR7M8d8OaV/h/WZozXDXIxnAr05fqEx+BCL0 beifZ9dV7OWFFph64NWNn5drzctP31bHeivp8RpE= From: "lsof at mailbox dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/110402] New: Bogus -Waddress warning that pointer comparison is always true Date: Sun, 25 Jun 2023 09:58:39 +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: 13.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: lsof at mailbox dot 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 attachments.created 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110402 Bug ID: 110402 Summary: Bogus -Waddress warning that pointer comparison is always true Product: gcc Version: 13.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: lsof at mailbox dot org Target Milestone: --- Created attachment 55398 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D55398&action=3Dedit testcase In the following testcase: struct m { float *v; int t; }; _Bool chk(struct m *m, int key) { return (m->t =3D key) < 0 ? 0 : &m->v[key]; } /* a comma expression can suppress it */ _Bool chk2(struct m *m, int key) { return (m->t =3D key, m->t < 0 ? 0 : &m->v[key]); } /* however, this does NOT warn */ _Bool chk3(struct m *m, int key) { return (m->t =3D key) < 0 ? &m->v[key] : &m->v[key]; } gcc -Waddress gives this warning: x.c: In function =E2=80=98chk=E2=80=99: x.c:4:5: warning: the comparison will always evaluate as =E2=80=98true=E2= =80=99 for the pointer operand in =E2=80=98m->v + (sizetype)((long unsigned int)key * 4)=E2=80=99 = must not be NULL [-Waddress] 4 | return key < 0 ? 0 : &m->v[key]; | ^~~~~~ In particular the second function does not produce the warning (correctly),= but the third function for which the warning actually applies does not give a warning.=