From patchwork Mon Apr 1 22:15:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1918577 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Uy4or5UN; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V7lht5WrWz1yY4 for ; Tue, 2 Apr 2024 09:16:12 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 31C2D3858C50 for ; Mon, 1 Apr 2024 22:16:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 510373858D28 for ; Mon, 1 Apr 2024 22:15:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 510373858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 510373858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712009748; cv=none; b=liug6bcXzUFRAnZG0e2UA6VaZt6Dlca9B8GXQn4JGVGDmCg5N55KEoxtP5zC5PU339/snu7hXoV2jo1zfFgMuMZQn1poUCSaNUfn2jPm5oCuBJE6sPP+lC3fociNEMTIiWrK2RhXBQFN5DA+2ZsZbeVbVnannsylU4Hm7Cz9KjU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712009748; c=relaxed/simple; bh=axugGLi9x2K4N8cexrIyEyKpMSuiFPHGc9HWUeYE5vs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=EG6eUTMN0rncV38x0Xv37tT1UXZKXQuhMgGLnE1JIevTFu740T9sqUEm+0M/UFHRb/VTeQxg0rGiqOVoKEGDZgR0IJ/VfIPwvgpEmCdl/K6zzf4IFwa/UfIzbD+HrNpx0uy8ZJCyM5P/thrGaXg+Vew6wq6ICMuDYCEy63tpdfo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712009746; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gu3U0vyk3Qy3VhjAaCY6/ANOyXG76tPJdZnj+36NIZs=; b=Uy4or5UNJtU9Z9LGWzFYXzRlTvPbCWukR18AjwfQDMgIAaljiX8NQTdHybKSAKdEywPfN3 +XW449+4C/ytLpMQmJ5s8lxxn5yHHypzZF5SUdm4i1Yd49auEFDJOiXgp9d14M1ht01uQh cOeG/7Gz7VD674qPL32OrPEFAPbON/Q= Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-570-0Z224pGSM76oI433M7PoGQ-1; Mon, 01 Apr 2024 18:15:44 -0400 X-MC-Unique: 0Z224pGSM76oI433M7PoGQ-1 Received: by mail-ot1-f72.google.com with SMTP id 46e09a7af769-6e67fa991f1so5539102a34.2 for ; Mon, 01 Apr 2024 15:15:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712009742; x=1712614542; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gu3U0vyk3Qy3VhjAaCY6/ANOyXG76tPJdZnj+36NIZs=; b=iGwdwHAU7sCSp5qASuf3AuCvkxTMj8VQviVzA7vF6qjRkRNlzvtwx6YwYo6Ir6tbfO dHVTH12hCaA8/0/K+0y0P1yMkPHz40cixz1M9p5pzLix5UhfNvW4DeqafloLQlzapkba ez/3MAMAxDJThudfPnecuvOISji94eE9l5Cfc+Q+3dQlOypAKj6x9NDyssKVirpSmtJa f2ovFKhs7kUBooWyr/79QJgV5RFwsuH4tv/ZkcvzyJacTU/sI+3aB1OIBsK86CAO2y4j 2N2MxkPn0TPML2UEYbgsi1ajpViJAlEAtIJlTTmDyhIXuIFJR4jcEzwShipeMYo5wukg 4yOw== X-Gm-Message-State: AOJu0YzIshMUVzWq/tTL5Spsl/Shq2V1GnO/2ylX5mkup/dM/p6JpG+D L1dmvjYTXYdEDthS6NrZ5L1OiXtoKSUcnwGP7+Ff4w6NL+Yk6K1fqkT9eSkQHv3BEkA2DmE/cSg TodoZ8IP7UpJj3bfestTDfLjSQjczhSmqK0mZN/xm42zaJti7f79Ksb1gog3yIwG7qeI5AoSkbk KiwhIn1RYSoLyzBb/d+DieTsAEas/EzcMm8tqg X-Received: by 2002:a9d:5d09:0:b0:6e6:c69c:9ff9 with SMTP id b9-20020a9d5d09000000b006e6c69c9ff9mr10643043oti.3.1712009742709; Mon, 01 Apr 2024 15:15:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG1GWi62GrtxNQyVIbXpRkwRby1OyeYA15TWqd2MOc9TRx960g2ATcPzqeVDl0AY1SSQr8oww== X-Received: by 2002:a9d:5d09:0:b0:6e6:c69c:9ff9 with SMTP id b9-20020a9d5d09000000b006e6c69c9ff9mr10643027oti.3.1712009742365; Mon, 01 Apr 2024 15:15:42 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id oo14-20020a056214450e00b00690c9256676sm4919780qvb.49.2024.04.01.15.15.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 15:15:41 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH] libstdc++: Allow adjacent __maybe_present_t to overlap Date: Mon, 1 Apr 2024 18:15:39 -0400 Message-ID: <20240401221539.842841-1-ppalka@redhat.com> X-Mailer: git-send-email 2.44.0.448.gc2cbfbd2e2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- Currently __maybe_present_t maps to the same empty class type independent of T. This is suboptimal because it means adjacent __maybe_present_t members with the [[no_unique_address]] attribute can't overlap even if the conditionally present types are different. This patch fixes this by turning this empty class type into a template parameterized by the conditionally present type, so that [[no_unique_address]] __maybe_present_t _M_a; [[no_unique_address]] __maybe_present_t _M_b; now overlap if T and U are different. This patch goes a step further and also adds an optional integer discriminator parameter to allow for overlapping when T and U are the same. libstdc++-v3/ChangeLog: * include/std/ranges (ranges::__detail::_Empty): Rename to ... (ranges::__detail::_Absent): ... this. Turn into a template parameterized by the absent type _Tp and discriminator _Disc. (ranges::__detail::__maybe_present_t): Add an optional discriminator parameter. (slide_view::_M_cached_begin): Pass a discriminator argument to __maybe_present_t. (slide_view::_M_cached_end): Likewise. * testsuite/std/ranges/adaptors/sizeof.cc: Verify the size of slide_view is 3 instead 4 pointers. --- libstdc++-v3/include/std/ranges | 13 ++++++++----- .../testsuite/std/ranges/adaptors/sizeof.cc | 4 ++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 7d739852677..afce818376b 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -886,14 +886,17 @@ namespace views namespace __detail { - struct _Empty { }; + template + struct _Absent { }; // Alias for a type that is conditionally present // (and is an empty type otherwise). // Data members using this alias should use [[no_unique_address]] so that // they take no space when not needed. - template - using __maybe_present_t = __conditional_t<_Present, _Tp, _Empty>; + // The optional template parameter _Disc is for discriminating two otherwise + // equivalent absent types so that even they can overlap. + template + using __maybe_present_t = __conditional_t<_Present, _Tp, _Absent<_Tp, _Disc>>; // Alias for a type that is conditionally const. template @@ -6553,10 +6556,10 @@ namespace views::__adaptor range_difference_t<_Vp> _M_n; [[no_unique_address]] __detail::__maybe_present_t<__detail::__slide_caches_first<_Vp>, - __detail::_CachedPosition<_Vp>> _M_cached_begin; + __detail::_CachedPosition<_Vp>, 0> _M_cached_begin; [[no_unique_address]] __detail::__maybe_present_t<__detail::__slide_caches_last<_Vp>, - __detail::_CachedPosition<_Vp>> _M_cached_end; + __detail::_CachedPosition<_Vp>, 1> _M_cached_end; template class _Iterator; class _Sentinel; diff --git a/libstdc++-v3/testsuite/std/ranges/adaptors/sizeof.cc b/libstdc++-v3/testsuite/std/ranges/adaptors/sizeof.cc index 12a9da3181d..08c01704d10 100644 --- a/libstdc++-v3/testsuite/std/ranges/adaptors/sizeof.cc +++ b/libstdc++-v3/testsuite/std/ranges/adaptors/sizeof.cc @@ -49,3 +49,7 @@ static_assert(sizeof(ranges::lazy_split_view) == 4*ptr); static_assert (sizeof(ranges::reverse_view>) == 3*ptr); + +#if __cpp_lib_ranges_slide +static_assert(sizeof(ranges::slide_view) == 3*ptr); +#endif