From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5ACDE385742C; Wed, 27 Apr 2022 09:06:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5ACDE385742C From: "aldyh at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/105346] [11/12 Regression] -Wno-free-nonheap-object false positive (on Bison-generated grammar code) Date: Wed, 27 Apr 2022 09:06:13 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 11.2.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: aldyh at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.4 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: Wed, 27 Apr 2022 09:06:13 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105346 --- Comment #14 from Aldy Hernandez --- (In reply to Richard Biener from comment #13) > (In reply to Andrew Macleod from comment #11) > > (In reply to Richard Biener from comment #6) > >=20 > > >=20 > > > : > > > bufp_2 =3D &buf; > > > if (&buf !=3D bufp_2) > > > goto ; [INV] > > > else > > > goto ; [INV] > > >=20 > > > : > > > __builtin_free (bufp_2); > > >=20 > > > and for the stmt __builtin_free (bufp_2) I'd like to ask if we know > > > that bufp_2 is !=3D &buf (I'd expect a 'true' answer). I think the > > > relation oracle should be able to answer this but I can't find the > > > appropriate API to use for this? > >=20 > > - The relation oracle currently only works with ssa-names. > > - Ranger also doesn't currently track that sort of symbolic equivalence= with > > irange. > > - the VRP passes have a pointer tracking mechanism as part of the dom w= alk, > > and the call to rvrp_folder::value_of_expr (bufp_2) would give us &buf.= I > > also think we also would fold the stmt in VRP. This could in theory be > > extended to any pass doing a dom walk. however: > > - I believe the upcoming prange extension for pointer ranges in stage 1= will > > make this happen naturally with rangers query system. range_of_stmt ( if > > <..>) would then produce bool [0, 0]. I would also expect that prange = will > > have an easy way to ask what its base/equivalence(s) are. >=20 > OK, I was hoping I can so sth like >=20 > range_simplify_expr (NE_EXPR, bufp_2, &buf, at_free_stmt); >=20 > and then by means of the dominating if condition get a 'true'. Note the > diagnostic pass is not within a DOM walk so all I can use is an ad-hoc > query. I'm not looking to simplify the conditional itself as that won't > help me with the current pass structure. Hmmm, I suppose we could track inequality as well as equality in prange. In which case, we'd have: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D BB 2 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Imports: bufp_2 Exports: bufp_2 : bufp_2 =3D &buf; if (&buf !=3D bufp_2) goto ; [INV] else goto ; [INV] bufp_2 : [prange] char[20] * [1B, +INF] [PT &buf] 2->3 (T) bufp_2 : [prange] char[20] * [1B, +INF] [PT !&buf] 2->4 (F) bufp_2 : [prange] char[20] * [1B, +INF] [PT &buf] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D BB 3 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D bufp_2 [prange] char[20] * [1B, +INF] [PT !&buf] : free (bufp_2); Notice that the range of bufp_2 at free() is: bufp_2 [prange] char[20] * [1B, +INF] [PT !&buf] Whereas range_of_expr of &buf (anywhere) would be: [prange] char[20] * [1B, +INF] [PT &buf] The intersection of both is the empty set / UNDEFINED, and should be able to get that without dominance info. Would that help? Right now we're tracking equality, but it should be trivial to track non-equality by adjusting the op1_range range-op entries.=