{"id":2226662,"url":"http://patchwork.ozlabs.org/api/covers/2226662/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/cover/bmm.hhunvhjcqm.gcc.gcc-TEST.peppe.41.1.0@forge-stage.sourceware.org/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<bmm.hhunvhjcqm.gcc.gcc-TEST.peppe.41.1.0@forge-stage.sourceware.org>","list_archive_url":null,"date":"2026-04-22T18:03:44","name":"[v1,0/1] WIP: libstdc++: use is_virtual_base_of in std::weak_ptr operations","submitter":{"id":93222,"url":"http://patchwork.ozlabs.org/api/people/93222/?format=json","name":"peppe via Sourceware Forge","email":"forge-bot+peppe@forge-stage.sourceware.org"},"mbox":"http://patchwork.ozlabs.org/project/gcc/cover/bmm.hhunvhjcqm.gcc.gcc-TEST.peppe.41.1.0@forge-stage.sourceware.org/mbox/","series":[{"id":501065,"url":"http://patchwork.ozlabs.org/api/series/501065/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=501065","date":"2026-04-22T18:03:44","name":"WIP: libstdc++: use is_virtual_base_of in std::weak_ptr operations","version":1,"mbox":"http://patchwork.ozlabs.org/series/501065/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/covers/2226662/comments/","headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org; dmarc=none (p=none dis=none)\n header.from=forge-stage.sourceware.org","sourceware.org;\n spf=pass smtp.mailfrom=forge-stage.sourceware.org","server2.sourceware.org;\n arc=none smtp.remote-ip=38.145.34.39"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g16gk0m1nz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 04:09:38 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 48DEB4BB5931\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 18:09:36 +0000 (GMT)","from forge-stage.sourceware.org (vm08.sourceware.org [38.145.34.39])\n by sourceware.org (Postfix) with ESMTPS id 167664BBC0C8\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 18:05:21 +0000 (GMT)","from forge-stage.sourceware.org (localhost [IPv6:::1])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256)\n (No client certificate requested)\n by forge-stage.sourceware.org (Postfix) with ESMTPS id DFCB0433C8\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 18:05:06 +0000 (UTC)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 48DEB4BB5931","OpenDKIM Filter v2.11.0 sourceware.org 167664BBC0C8"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 167664BBC0C8","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 167664BBC0C8","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776881121; cv=none;\n b=gtDZ7Ee9ahX1Vf+I32t8YECHZ/oOjS1Zm/dLnytJElv7lBxMHdLNTkEBvwS/OpXqoQbRpGR24dugjh0UCJQpb3+x4tlgZyRJZPp/401zzvDvtjG3WoTXxz4iv+IvvIEbkp5AJ6xj0srMnjz2UZzOgx9m7i4w/k2EIPcj9ju3DJg=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776881121; c=relaxed/simple;\n bh=p6qOatHITsV4MbDq6QMy6CdQp91mQov3Cq11UGJhzhQ=;\n h=From:Date:Subject:To:Message-ID;\n b=k0SszkuXT9MH0peVM5mG4AOYSx1ZfgWUb7iwxlLNp51IxEDO9q+ut5CTd8XwYqQqlK+xUzffQt4JkHCOAC1V87m5DZINnB/KxvVnomrAGtHCltrFgNd9zEcnyR1plTIeMR/V53HPqAs2NeY922JaNdsRJZ4Q92oqEr7ir7NnfEk=","ARC-Authentication-Results":"i=1; server2.sourceware.org","From":"peppe via Sourceware Forge <forge-bot+peppe@forge-stage.sourceware.org>","Date":"Wed, 22 Apr 2026 18:03:44 +0000","Subject":"[PATCH v1 0/1] WIP: libstdc++: use is_virtual_base_of in\n std::weak_ptr operations","To":"gcc-patches mailing list <gcc-patches@gcc.gnu.org>","Message-ID":"\n <bmm.hhunvhjcqm.gcc.gcc-TEST.peppe.41.1.0@forge-stage.sourceware.org>","X-Mailer":"batrachomyomachia","X-Pull-Request-Organization":"gcc","X-Pull-Request-Repository":"gcc-TEST","X-Pull-Request":"https://forge.sourceware.org/gcc/gcc-TEST/pulls/41","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Reply-To":"gcc-patches mailing list <gcc-patches@gcc.gnu.org>,\n peppe@noreply.localhost","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"Hi gcc-patches mailing list,\npeppe via Sourceware Forge <forge-bot+peppe@forge-stage.sourceware.org> has requested that the following forgejo pull request\nbe published on the mailing list.\n\nCreated on: 2025-03-08 14:30:33+00:00\nLatest update: 2026-02-27 08:00:29+00:00\nChanges: 2 changed files, 125 additions, 7 deletions\nHead revision: peppe/gcc-TEST ref weak_ptr_virtual_base_optimize commit a081ba7fda52fe2a74923166a4e97976292a9155\nBase revision: gcc/gcc-TEST ref trunk commit 01044e0ee27093a3990996578b15f6ab69ed3395 r16-1114-g01044e0ee27093\nMerge base: 01044e0ee27093a3990996578b15f6ab69ed3395\nFull diff url: https://forge.sourceware.org/gcc/gcc-TEST/pulls/41.diff\nDiscussion:  https://forge.sourceware.org/gcc/gcc-TEST/pulls/41\nRequested Reviewers:\n\nConverting a `weak_ptr<Derived>` to a `weak_ptr<Base>` requires calling\nlock() on the source object in the general case.\n\nAlthough the source `weak_ptr<Derived>` does contain a raw pointer to\nDerived, we can't just get it and (up)cast it to Base, as that will\ndereference the pointer in case Base is a virtual base class of Derived.\n\nWe don't know if the managed object is still alive, and therefore if\nthis operation is safe to do; we therefore temporarily lock() the source\nweak_ptr, do the cast using the resulting shared_ptr, and then discard\nthis shared_ptr. Simply checking the strong counter isn't sufficient,\nbecause if multiple threads are involved then we'd have a race / TOCTOU\nproblem; the object may get destroyed after we check the strong counter\nand before we cast the pointer.\n\nHowever lock() is not necessary if we know that Base is *not* a virtual\nbase class of Derived; in this case we can avoid the relatively\nexpensive call to lock() and just cast the pointer. This commit uses\nthe newly added builtin to detect this case and optimize std::weak_ptr's\nconverting constructors and assignment operations.\n\n```\nlibstdc++-v3/ChangeLog:\n\n\t* include/bits/shared_ptr_base.h (__weak_ptr): Avoid calling\n\tlock() when converting or assigning a weak_ptr<Derived> to\n\ta weak_ptr<Base> in case Base is not a virtual base of Derived.\n\tThis logic is centralized in _S_safe_upcast, called by the\n\tvarious converting constructors/assignment operators.\n\t(_S_safe_upcast): New helper function.\n\t* testsuite/20_util/weak_ptr/cons/virtual_bases.cc: New test.\n```\n\n\nChanged files:\n- A: libstdc++-v3/testsuite/20_util/weak_ptr/cons/virtual_bases.cc\n- M: libstdc++-v3/include/bits/shared_ptr_base.h\n\n\nGiuseppe D'Angelo (1):\n  libstdc++: optimize weak_ptr converting constructor/assignment\n\n libstdc++-v3/include/bits/shared_ptr_base.h   | 52 ++++++++++--\n .../20_util/weak_ptr/cons/virtual_bases.cc    | 80 +++++++++++++++++++\n 2 files changed, 125 insertions(+), 7 deletions(-)\n create mode 100644 libstdc++-v3/testsuite/20_util/weak_ptr/cons/virtual_bases.cc"}