From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DC6323858431; Wed, 12 Apr 2023 10:29:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC6323858431 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681295381; bh=CCe7KuO5A3S0uptTQ1rnbB/lHl744Vyyj+vU0t85wDU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=E/hiD/slmaD/H8ppoQuOBS0/Qx9Fns9Ij5YuNqJgWaFktbnxKtkleKPL+QZ0+XBw8 u44Piyhk1wx6iqeaaSYwRolPT1adRWBrCXpxZoS5rWgkxDZQsFlCDc1h9RwlucUJzM hqFFuZaiVWCPiMdRAaDfG2dHPcE0karxx1g0vsc8= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/109442] Dead local copy of std::vector not removed from function Date: Wed, 12 Apr 2023 10:29:41 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: REOPENED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned 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=3D109442 --- Comment #10 from Jonathan Wakely --- (In reply to Richard Biener from comment #9) > Yep, looking at that link this is exactly what would be needed. Note > that in the middle-end we already see the calls to > DECL_IS_REPLACEABLE_OPERATOR_NEW_P and replaceable operator delete. We > just restrict all optimizations to calls emitted from new/delete expressi= ons. > I'm not sure the clang builtin is exactly providing the new/delete > expression semantics resolving to replaceable operator new/delete or if > there's other details. That is, I'm curious whether __builtin_operator_n= ew > provides more guarantees than a new/delete expression - the builtin seman= tics > isn't very well defined unfortunately. It might be safer to go our own > way here. I would prefer if we don't deviate, and get Clang to clarify things instead= of reinventing something that looks similar but isn't. > I suppose the standard library could as well use malloc/free? No. std::allocator is required to use operator new and operator delete to obtain memory, but it's unspecified when or how often it calls them. So it'= s OK to call them once at startup to obtain ALL THE MEMORY that any std::allocat= or will ever need for the duration of the program, or to merge allocations, or= to elide them completely. But it's not OK to use malloc. std::allocator::allocate says: "The storage for the array is obtained by calling ::operator new (17.6.3), = but it is unspecified when or how often this function is called."=