From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BAE113858D28; Wed, 12 Apr 2023 10:13:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BAE113858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681294431; bh=Tn2vZnzMPQY0R66CFO0V/AEkpmiEcopcZ+JRBg6Yszg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=QoinDlhQn/KHYpV4lQ5ZqTaf9tDmc1IzM1A1AJTkwqcmTe3UcOW7Vn4vgBUbdE3ss +P0a34FjbXlQbe9+NwjWgTCijjyXVNMafBw9kSctcv7F6/TPy2OlrWCapU9aicIj+a nkmftIeYHBz0AAUMr6mdS+rTm2QabMAfZ6VyCOOk= 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:13:51 +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 #8 from Jonathan Wakely --- (In reply to Jonathan Wakely from comment #7) > I think it's valid in theory. I don't know if it's possible for GCC to do= it > in practice. There doesn't seem to be anything the library can do to help, > so WONTFIX. I think it's valid in theory because the implementation of std::vector is opaque. It's not required to actually call operator new and operator delete= to obtain its storage, and so if the library and compiler collaborate to provi= de storage some other way (e.g. using a stack buffer) then that's allowed. But in practice it's hard to do that. Maybe it could be done with a new __builtin_elidable_operator_new and __builtin_elidable_operator_delete pair that the library could use, or attributes like you suggested in comment 4. That would allow the library to= say "I'm calling operator new and operator delete because I need to obtain memo= ry, but **these particular invocations** are not required to be visible to the user, and therefore can be elided in the same way as new expressions and de= lete expressions". In fact Clang's __builtin_operator_new already has exactly those semantics: https://clang.llvm.org/docs/LanguageExtensions.html#builtin-operator-new-an= d-builtin-operator-delete And we already use those builtins if available, see PR 94295. So maybe what we need is to implement those.=