From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 79C823858C74 for ; Tue, 2 Apr 2024 09:17:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 79C823858C74 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 79C823858C74 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712049468; cv=none; b=M7YauhuPn41bFjZcSGNWYRoVvaZMY5pEtWwpKYAacB6EittjyBXqQs+Ris9/p/lAxrqMPmDI4xVXl7BKFHzyfQSfaz00OS54PoHPAFC05+IMhY9MvPHJTLS5QoipGG447kJi+1CIUy9KeudVVPcBD45kxRhtAlrBXEiMUBrMiJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712049468; c=relaxed/simple; bh=r0v2r6mKv0eiaOe/Sq8tkihoVOCMXFrom8dzN5dgjM0=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=ZoqUeSGwI3VTMC57wK/UFDRPkLbVBw0/BCSmbu5igvQoo8aswPLSmheu0NNt2FQNV6HvWsz0PtwbFdobrA3hy2SmD+Vn2f7KCiCxVbxhvKsLYMFIZl0UyrLq7Xr7J8hR9VSl9Iws6e1MXPD5ZjUdOH1iX2rOpf7T6V+HrwTv8BE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712049465; 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: in-reply-to:in-reply-to:references:references; bh=ZIZ7eYk6pdI5xZbO8AzBsMI6WmcxOV78EtuxKfnWVdE=; b=O3zGfT+xwiNPtO96bPAusPcFh8HP0ieCsMUdG6QfV9xES9uwu3m0MZnU3IZXRHWy+xf6mB cZYflcUEMU3y28uULZRbofklXumJ9j3wQsX8FI6tD5hrANWjsq0YLUo0frk3nxK46ZAxS8 yGeOG3Nu4OpNKKCPBkWiNIOwWjwrpMQ= Received: from mail-yw1-f200.google.com (mail-yw1-f200.google.com [209.85.128.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-383-4ujDJ-MDOd-ZZzwmjyS-Hw-1; Tue, 02 Apr 2024 05:17:44 -0400 X-MC-Unique: 4ujDJ-MDOd-ZZzwmjyS-Hw-1 Received: by mail-yw1-f200.google.com with SMTP id 00721157ae682-60a4ee41269so89973247b3.0 for ; Tue, 02 Apr 2024 02:17:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712049463; x=1712654263; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZIZ7eYk6pdI5xZbO8AzBsMI6WmcxOV78EtuxKfnWVdE=; b=tgHEoTfGtz1ie31DFLoB2zkGrF2OKTwlnw6xZoRH9mvMilLxGfO0UF0PMj2AdWW86l SLOqOzPmzKzCKJ4/+8Ao+mZG+QLqqlQyPo2qe9kzJIbiw4GuI4/YfcrZKLefGn6KR0K3 BQX9ZqZZZyVYFoJn5XMBcxo9h9DUmd8KDoMBoAMMlZOp3X7tL5E3KexvhnLY+bOqUfaP /chAtG/fUND6+6KO0UlJEQysqJbueAOQL2ugA+T5pQD3yoxf+y865OXka1INioQJ/BGK MIjhKZb2WrgT/qCDoz1eUN0SlqohpuQk2rxylC9frt0X6P8gnB8s+9G3HuAHUjE8GOwW 129A== X-Gm-Message-State: AOJu0YyrRoS6pTgkEJISss71sbCLqxUjBQ4Ko9w0p1LTpcusVvjhtEf4 NnjBJZ+DUgDJypMzJJ9RAw7oLrQ/sRf82dFPA2LZZR1WNRZN/F0Cuakg0+nZ9MO60rUVajpj4uk tEP/rVb1b3msPAQ5nJ9w+ceinR7NQQ1jS7M8TUN7v5L2xsu/1FVmmzSFVIvp06SMJA/MQgjETgR o3Q3+lF/tSxIT6Oh9zTuHRaZ+/pISpGQ== X-Received: by 2002:a25:ae8a:0:b0:dc7:8c3a:4e42 with SMTP id b10-20020a25ae8a000000b00dc78c3a4e42mr10013073ybj.30.1712049463495; Tue, 02 Apr 2024 02:17:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMh7/csbokxQAQWKxF6FQTCNZhaFiZvX9ytD78bhC34Z5kdmb0qMIBzTG1szGp0f56tRZARqnsjc6rRjZXibQ= X-Received: by 2002:a25:ae8a:0:b0:dc7:8c3a:4e42 with SMTP id b10-20020a25ae8a000000b00dc78c3a4e42mr10013062ybj.30.1712049463224; Tue, 02 Apr 2024 02:17:43 -0700 (PDT) MIME-Version: 1.0 References: <20240401221539.842841-1-ppalka@redhat.com> In-Reply-To: <20240401221539.842841-1-ppalka@redhat.com> From: Jonathan Wakely Date: Tue, 2 Apr 2024 09:17:27 +0000 Message-ID: Subject: Re: [PATCH] libstdc++: Allow adjacent __maybe_present_t to overlap To: Patrick Palka Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-12.4 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,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, 1 Apr 2024 at 23:16, Patrick Palka wrote: > > Tested on x86_64-pc-linux-gnu, does this look OK for trunk? This is a layout change for some specializations of slide_view, but better to do that now than change it between gcc 14 and 15. 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 > -- > 2.44.0.448.gc2cbfbd2e2 >