From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 802653A5141B; Fri, 13 Nov 2020 14:46:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 802653A5141B From: "amacleod at redhat dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/78655] gcc doesn't exploit the fact that the result of pointer addition can not be nullptr Date: Fri, 13 Nov 2020 14:46:52 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 7.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: amacleod at redhat dot com X-Bugzilla-Status: NEW 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: cc attachments.created 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: Fri, 13 Nov 2020 14:46:52 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D78655 Andrew Macleod changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |amacleod at redhat dot com --- Comment #9 from Andrew Macleod --- Created attachment 49556 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D49556&action=3Dedit testcase (In reply to Marc Glisse from comment #8) > (just to put this somewhere) > We have multiple ways of doing pointer arithmetic in gcc. After the recent > patch, we know that g returns nonnull, but we don't know it for f. >=20 > struct A{int a,b;}; > int*f(A*p){return&p->b;} > int*g(A*p){return(int*)p+1;} I tweaked this and made a testcase out of it. I think it is correct?=20=20 We do know that both f and g are non-null now, as well as checks for when returning p->a for 0 offsets... So I think this is covered? Furthermore, bool f(int* a) { bool x =3D a =3D=3D nullptr; a +=3D 10; return x; } turns into a_1(D) int * VARYING : x_2 =3D a_1(D) =3D=3D 0B; a_3 =3D a_1(D) + 40; return x_2; a_3 : int * [1B, +INF] And from there, I don't see any way to determine that 'a_1' can't be nullpt= r.=20 we've lost whatever context nullptr is suppose to provide... its just a 0 n= ow. All we can see is that a_3 is non-null.=