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 224523858D20 for ; Mon, 1 Apr 2024 22:15:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 224523858D20 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 224523858D20 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=1712009747; cv=none; b=o8jynwRd9RT/A7S/2Y4SwOZzz4h3guM7QK7To9LzrY7cS2laMnJK4pTeOebSu/uyk+30JSl7zCn0dDvM8XbAFHGMpykvhQDxOc5q1mONL31Q+kwFD0JdUpYKoqoBmytAzHoD/uA2HYLVfy1DjVJvud986H6XLNmNAWikVjRinng= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712009747; c=relaxed/simple; bh=axugGLi9x2K4N8cexrIyEyKpMSuiFPHGc9HWUeYE5vs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=eC5UGOS7nOXZ1DgOzossM4eGzqajcyjUvm+rFbT9ie1L3IzIzlWHcTaP858F1iVwdAC6Oxi63JE6ysUq0P7hFUyRXErvoP8DhYR3UJk4uID2hDDpOyUIWvwrrPNTJaguCgE0lqA45q6FhFDB7nyg1ox/Dj2zrq1dTwGfGVLv9ys= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712009744; 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=T4Av+lH41OiVf2j+mT6+rwrRUb7jlDqrIn7SiAKdIDWdkDe8inKxOdUqV6mZJqYjuHZUSM O3f/Hj+PLdWE7nkyVY8dCW7bu/92ldqK31AmTbNztFMvze0FmIfi9FOhCr04338ifdGYqq PGbDPoO++qbt9UMYjf1mg0UQbt8AVNw= Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-37-TULThKfgPqWQcuTGfJcRHA-1; Mon, 01 Apr 2024 18:15:43 -0400 X-MC-Unique: TULThKfgPqWQcuTGfJcRHA-1 Received: by mail-ot1-f69.google.com with SMTP id 46e09a7af769-6e6a35be1b0so5476608a34.0 for ; Mon, 01 Apr 2024 15:15:43 -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=ezWgyFv6d5wrcsCf4IZJJDj4DYNtEBlq9ORkjpeCnHzlzugxJm5q58gtnL0cSxIah/ Tmn6ivLJhUBJl27Xw2Mukj1fzz99KaXP3dB52fsCNurkWuvH6NEPBwro8v/7pL7Vt3va QmxzuLrcBtftKrwm+lGvww6nc1NZukD8k5/qNI4g7T3NVhAWkAGWyD/CWQjf5UArw4kp sI3dXmoK5Y3kz4yNvAZpcG3o2qXoRqcqaRgOJhU1mgfr12mn9m0saa7Nam14RsmM2ero yKMk8Fn3HhmCn0PqmZK9YC2Sk3R34rexAy1Ad3ERzVXqEwpZbDyJ3hjCVfi8JxA0TC9W 2YnQ== X-Gm-Message-State: AOJu0YxBi1VdkrCaO1kVQ1qtVevNx93cAcqMZbx8O1IxdLsTLU0dym+N SfpuQtCN/4YQSS9YEtROy1wKusZamH9WvktsdpCmfQWdjF9hg2TAQwwTPYfpJPo49CEn7NvDwqC Qf/rIKJDKtI6z0SsYk3OO1V/q8tiJ9LwShcKkSTPT/EiWp11AXWVf X-Received: by 2002:a9d:5d09:0:b0:6e6:c69c:9ff9 with SMTP id b9-20020a9d5d09000000b006e6c69c9ff9mr10643042oti.3.1712009742676; 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.6 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: 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 -- 2.44.0.448.gc2cbfbd2e2