From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 395983857C6C; Wed, 9 Sep 2020 21:50:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 395983857C6C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1599688242; bh=Di+zGAqmFMiEyQFKKiEs3Lh/j9e1NijNiyXARb+WbYw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=xUh+k1UiaYYbMfjNwBXTU3pMicXCDV+MT6K3j05zHRPTHXeCVumPTAHy8ZytBpuef QRLIuh9rYOg5d/NZymya5Julv61rqsJMJrXuFLJv54aXcd52i30uzC0QfsWmAV8SzJ C1d9T/Ogp8NRB8ZdtVrIqsFF0xTyeO7ddswgMp18= From: "dmalcolm at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/94355] support for C++ new expression Date: Wed, 09 Sep 2020 21:50:42 +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: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dmalcolm at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED 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: Wed, 09 Sep 2020 21:50:42 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94355 --- Comment #4 from David Malcolm --- (In reply to Ivan Sorokin from comment #0) > At the moment static analyzer warns about leaked malloc. It would be great > if C++ new expression were also supported. >=20 > Example: >=20 > void f() > { > char* p =3D new char; > } >=20 > Expected diagnostic: >=20 > warning: leak of 'p' [CWE-401] [-Wanalyzer-malloc-leak] >=20 > 3 | char* p =3D new char; Actual diagnostic with commit r11-3090-g1690a839cff2e0276017a013419d81d675bbf69d: demo.cc: In function =E2=80=98void f()=E2=80=99: demo.cc:4:1: warning: leak of =E2=80=98p=E2=80=99 [CWE-401] [-Wanalyzer-mal= loc-leak] 4 | } | ^ =E2=80=98void f()=E2=80=99: events 1-2 | | 3 | char* p =3D new char; | | ^~~~ | | | | | (1) allocated here | 4 | } | | ~=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 | | | | | (2) =E2=80=98p=E2=80=99 leaks here; was allocated at (1) | where the diagnostic's location is at the point where "p" goes out of scope= .=20 There's an argument that it would be better emitting it at the "new".=