From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 007813858287; Sat, 2 Jul 2022 10:07:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 007813858287 From: "dmalcolm at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/106000] RFE: -fanalyzer should complain about memory accesses that are definitely out-of-bounds Date: Sat, 02 Jul 2022 10:07:56 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: analyzer X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dmalcolm at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: dmalcolm at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: 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: Sat, 02 Jul 2022 10:07:57 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106000 --- Comment #4 from David Malcolm --- For example, the "classic test" referred to in section 1.2 of https://open-std.org/JTC1/SC22/WG14/www/docs/n3005.pdf has: #include #include int y=3D2, x=3D1; int main() { int *p =3D &x + 1; int *q =3D &y; printf("Addresses: p=3D%p q=3D%p\n" ,(void*)p,(void*)q); if (memcmp(&p, &q, sizeof(p)) =3D=3D 0) { *p =3D 11; // does this have undefined behaviour? printf("x=3D%d y=3D%d *p=3D%d *q=3D%d\n",x,y,*p,*q); } } where N3005 notes that "the mere formation of the &x+1 one-past pointer is explicitly permitted by the ISO standard". I think -fanalyzer ought to complain with an definite-out-of-bounds warning= at the *p dereference: assuming sizeof(int) =3D=3D 4, we'd have a decl_region = of size 4, where only bytes 0 to 3 are validly accessible, whereas here the code attempts to accessing bytes 4-7 of the decl_region for x, which is out-of-bounds. (I think the memcpy result would be a conjured_svalue, and hence we would consider both true and false out-edges after the test; if the user is relyi= ng on the two vars to be next to each other in memory we ought to be warning t= hem about that)=