From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 145D0385040A; Thu, 22 Jul 2021 21:14:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 145D0385040A From: "navarre.gcc.bugs at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/94355] support for C++ new expression Date: Thu, 22 Jul 2021 21:14:43 +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: navarre.gcc.bugs at gmail dot com 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: cc 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: Thu, 22 Jul 2021 21:14:45 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94355 William Navarre changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |navarre.gcc.bugs at gmail = dot com --- Comment #8 from William Navarre --- It seems that `operator new` is generally not supposed to return NULL -- std::bad_alloc() is supposed to be thrown instead.=20 I made that change on my build (see below). I think that treating new's res= ult as never-null is probably the correct thing to do most of the time, but two considerations:=20 1) The case of allocating a zero-length array.=20 2) The case that a project has replaced `operator new.` (See "global replacements" at https://en.cppreference.com/w/cpp/memory/new/operator_new)= .=20 Apparently projects can replace `operator new` (see "global replacements" at https://en.cppreference.com/w/cpp/memory/new/operator_new). It's not clear= =20 --- a/gcc-11.1.0/gcc/analyzer/sm-malloc.cc +++ b/gcc-11.1.0.navarre/gcc/analyzer/sm-malloc.cc @@ -1527,9 +1527,9 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, } if (is_named_call_p (callee_fndecl, "operator new", call, 1)) - on_allocator_call (sm_ctxt, call, &m_scalar_delete); + on_allocator_call (sm_ctxt, call, &m_scalar_delete, true); else if (is_named_call_p (callee_fndecl, "operator new []", call, 1= )) - on_allocator_call (sm_ctxt, call, &m_vector_delete); + on_allocator_call (sm_ctxt, call, &m_vector_delete, true); else if (is_named_call_p (callee_fndecl, "operator delete", call, 1) || is_named_call_p (callee_fndecl, "operator delete", call, 2)) {=