From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6DA9F3858D35; Wed, 26 Jul 2023 17:10:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6DA9F3858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690391450; bh=Yu8T/gtaarFkNW+QyCiTG6ykmZH1Jj4Sbt0lD7oeO3c=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YKNHDn0MDzLv2eBA9lue47Li7JUceM0bW/XaavKVYt+GyjUQf+1qjg/CFzxyD0MvQ 8FHzmn/dcxYmYkSo5Vc9OZK2IrdUi+jtVivxCaafTPUMQ7K1Fzzwf/15r1rxn8s6PL 8WdW50/0qk1ro9kA7PJQoR+TL3s5AH3mPw0vOU1E= From: "vultkayn at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/109365] Double delete yields -Wanalyzer-use-after-free instead of -Wanalyzer-double-free Date: Wed, 26 Jul 2023 17:10:46 +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: 13.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: vultkayn at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: vultkayn 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109365 --- Comment #6 from Benjamin Priour --- (In reply to David Malcolm from comment #5) > (In reply to Benjamin Priour from comment #4) > > (In reply to Benjamin Priour from comment #3) >=20 > Here's a link to the reproducer: > https://godbolt.org/z/Wa3fqjrTK > with the fields renamed to avoid reusing the name "a". >=20 >=20 > > [...snip...] > > >=20 > > >=20 > > > : > > > *a.0_11 =3D{v} {CLOBBER}; > > > operator delete (a.0_11, 8); > > > > > [...snip...]=20 > > > > > > Entry statement of bb3 is the one actually detected as > > > -Wanalyzer-double-free. > >=20 > > Given the above IPA, we cannot just ignore the assignment statement, as= it > > could really be an injurious statement, not just a pre-deallocation > > statement at it is now. >=20 > Ths assignment statement: > *a.0_11 =3D{v} {CLOBBER}; > is a "clobber", which is a special-case of assignment, generated by the > frontends when something is going out of scope, or becoming invalid. >=20 > We could potentially just special-case such ass >=20 Wouldn't considering "clobber" as a trigger for double-delete also lead to = many false positives ? I'm not yet 100% familiar with and when this "clobber" appears. [...snip...] > >=20 > > struct A > > { > > ... > > ~A() {} > > } > >=20 > > ... > >=20 > > : > > A::~A (a.0_12); > > operator delete (a.0_12, 8); > >=20=20 > >=20 > > The warnings stay the same, though it is now more reliable to check for= a > > destructor call, instead any random single assignment. >=20 > There's a sense in which it does make sense to complain about > use-after-delete in the destructor (when the destructor is non-empty): the > memory is being accessed after deletion. Maybe this case would make more > sense to the user? (albeit being rather verbose) I believe in the case of a non-empty destructor, "double-delete" would be m= ore on point than "use-after-delete", as ultimately the issue is the second cal= l to delete. "double-delete" immediately warns about the actual issue, whereas if the first "delete" is not as obvious as in the above test case, a "use-after-delete" might confuse the user. "use-after-delete" could mislead the user to believe there is something wro= ng with their destructor, although only their double delete is.=