From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E1474386F422; Sat, 11 May 2024 17:09:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E1474386F422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1715447379; bh=Tqc9nOK6ZA1KDneDtUcAr7yf/Vnfh53yiwNURaBcx7Q=; h=From:To:Subject:Date:From; b=Yt4cCQrpKCAO8A4VX+/hsjHo8mnI+9cNV7hqR9ghjZE5lP4xPBYQ8f62z4oqpsp5y CTGpKl78Z2rU5TK4OTEALdz+EgaxOkgznLwCaJmb5MGmFIpMHOjYFeXpRt0FCQ5/O+ wm3w945bWRXS9tANIvjJw8nMCb3KP8dkNmlsc6HY= From: "andrew.cooper3 at citrix dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/115044] New: -Wanalyzer-malloc-leak diagnostic in terminal path Date: Sat, 11 May 2024 17:09:39 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: analyzer X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: andrew.cooper3 at citrix dot com 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone 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=3D115044 Bug ID: 115044 Summary: -Wanalyzer-malloc-leak diagnostic in terminal path Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: analyzer Assignee: dmalcolm at gcc dot gnu.org Reporter: andrew.cooper3 at citrix dot com Target Milestone: --- I've been experimenting with -fanalyzer and attribute(malloc) in Xen. For a simple case, it reported: drivers/passthrough/x86/iommu.c: In function 'iommu_init_domid': ./include/xen/bug.h:141:13: warning: leak of '_xzalloc(4096, 8)' [CWE-401] [-Wanalyzer-malloc-leak] 141 | do { if ( unlikely(!(p)) ) assert_failed(#p); } while (0) | ^ drivers/passthrough/x86/iommu.c:551:9: note: in expansion of macro 'ASSERT' 551 | ASSERT(reserve > DOMID_MASK); | ^~~~~~ If I'm reading this correctly, it's saying that allocated memory is being leaked by ASSERT(). The whole function is: unsigned long *__init iommu_init_domid(domid_t reserve) { unsigned long *map; if ( !iommu_quarantine ) return ZERO_BLOCK_PTR; BUILD_BUG_ON(DOMID_MASK * 2U >=3D UINT16_MAX); map =3D xzalloc_array(unsigned long, BITS_TO_LONGS(UINT16_MAX - DOMID_M= ASK)); if ( map && reserve !=3D DOMID_INVALID ) { ASSERT(reserve > DOMID_MASK); __set_bit(reserve & DOMID_MASK, map); } return map; } but I can't seem to reproduce the -fanalyzer warning in a simpler example.= =20 Assuming it might be something to do with our implementation of ASSERT(), I reduced it to just do { if (!(x)) __builtin_trap(); } while ( 0 ) in place, and that still did reproduce the warning. So while the analyser is technically accurate (i.e. the memory is leaked wh= en we encounter a fatal path), I'm not sure it's a helpful diagnostic. Is there a reason why it's reported like this?=