From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id 6F7483858C2B; Sat, 14 Oct 2023 08:32:55 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6F7483858C2B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::630 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697272378; cv=none; b=LQKDNAfCyKoF0U1g9nLFK6xKrzB+7r9CtL6bJAc6CWhok6lQVBkjT5SuqzHDH9bf16eU+CNWF1jdjUqhDF8tdP892/GILRdRK7kM6VMG6qWD44gmTJoZj0BWaEj4udaQFalxsCe4kXuPkzg1Iad9Zk+Y09VUg20gtZin5ZFI3hY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697272378; c=relaxed/simple; bh=cZHB0Gt8bA/iwH7S1HVaWGrk9EFMqjr53fo/c0lXt+8=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=jAvnYQGMDdZK2uIhcYkbPT6FP8dnh8WIfWSSYYHq93UoIzSa2CHdMYXNX2y86Od1z2iJNxhR9Y2sTATWHGJ0jKhDUe7KDOIEoCaieMbfCdvS2p1XmV/Hfbz8Zo/cMuWjicUnpueBZYiYyv2H7uSPQK7I2Qo85jPbHwXmE7xVd9Y= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6F7483858C2B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-9b9a494cc59so432258166b.3; Sat, 14 Oct 2023 01:32:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697272374; x=1697877174; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=FjMrnxjcm6XgdmxL3y2W5Ms+LnE5k0jwxwymU8vdkVs=; b=ZsfIt8PjEkj00x3I8m9tKn73lxU9ApAE2+VnN8O5H2C/0WZRWXNAkcvXJA57+amvRm NR2foMiuuc0NErh4ZaViAaK7kW4uq3AZUm6P5QeAUJwkqnuV84ps6Cy1L5L/0lEjtOJS kVked8aU2w3taSTa8xtYfaiQEDHbfm8DqAmBo3HX20uwfnKjqK2qeLvm/37rQ4/QLAyl DOzmGA2WOJKSzS6oo/ytwZUGpB47uxFOWes6PhoU8LqUMEFkmvzjKEZv5eb8uS2UzU3r VV2ZkgpNMy0GpxFr1llxNXhKo2Tr8kl1Gqge9obXzrFc1nqdYWzZ7VFFSH0fFtBx5xF0 PunQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697272374; x=1697877174; 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=FjMrnxjcm6XgdmxL3y2W5Ms+LnE5k0jwxwymU8vdkVs=; b=ijAr78NIof0vTXkEX7Zl18qcMDHI8hD8KbSb5HhbPn33isaS7ZIUafGNAB6VAHJz++ ZdVlypch6qXhDsbXK1do1nTuwDU2sKAuDsdEsJ2iT5JG2q0+SK2Z7coe30t4Mq4nqRiU 7caGxN2JamftDVr1OKEetJZQud7ga3q05rjqty9+KU256dT/iVRzkLU+1UtI/fPs6Vns zzVWPX18XuLTgx0EpUfBsrHW3eNge3OnaxNYdeeb9y3Wb7mkYfpqv1+ZCiJQtk7PbmOD WMcuMxpf5CPm6e0e+IVjVwk7ilvzz8v0u2Q4eATUvD3l881Qh7Y73yd9XZv/s+gsPYuS FLnQ== X-Gm-Message-State: AOJu0YxT2x2/sIG69rTuiO8rcIf+z6Q04xWslzqCNj2/mORSJsD2K0mk X4vR2rTBO8tJqLnN8/mgDKGAQJid79U35Y7ozwByM6f/ X-Google-Smtp-Source: AGHT+IHNWEdCQVq9JCx7LK9agFQz/mod8JSFMbq/O4dJ/SRssVNN1EKFdk0q5tu3agMESII8o2UQd4Q2o/nXqjMt4VQ= X-Received: by 2002:a17:907:2d9e:b0:9be:839a:3372 with SMTP id gt30-20020a1709072d9e00b009be839a3372mr1182170ejc.59.1697272373867; Sat, 14 Oct 2023 01:32:53 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Sat, 14 Oct 2023 09:32:40 +0100 Message-ID: Subject: Re: [PATCH] libstdc++: Workaround for LLVM-61763 in ranges To: Benjamin Brock Cc: gcc-patches , "libstdc++" Content-Type: multipart/alternative; boundary="000000000000ee78b70607a904dd" X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,HTML_MESSAGE,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: --000000000000ee78b70607a904dd Content-Type: text/plain; charset="UTF-8" On Sat, 14 Oct 2023, 00:33 Benjamin Brock, wrote: > This is my first time submitting a patch, so my apologies if I'm > submitting incorrectly or missing something. > Thanks for contributing! I don't think this patch counts as legally significant, but if you contribute again in future you should be aware of https://gcc.gnu.org/contribute.html#legal and either complete the copyright assignment paperwork, or add a DCO sign-off to the commit message. > Clang is unable to compile parts of libstdc++'s ranges implementation > due to LLVM-61763, a Clang frontend compiler bug in handling the > declarations of constrained friends. The problem areas are zip_view, > zip_transform_view, and adjacent_transform_view. > > A simple ranges program like the following fails to compile using > Clang trunk and libstdc++. > > std::vector v = {1, 2, 3, 4}; > int sum = 0; > for (auto&& [i, j] : std::ranges::views::zip(v, v)) > sum += i * j; > > In file included from :1: > > /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/14.0.0/../../../../include/c++/14.0.0/ranges:4655:14: > error: type constraint differs in template redeclaration > 4655 | template > | ^ > . . . . . . > > Godbolt: https://godbolt.org/z/Ynbs15aGh > > This patch adds a small workaround that avoids declaring constrained > friends when compiling with Clang, instead making some members public. > MSVC's standard library has implemented a similar workaround. > > Scanning through libstdc++, there do appear to be other workarounds > for Clang, e.g. in complex and experimental/simd. Hopefully this kind > of workaround is acceptable---while the core issue is a Clang compiler > bug, it may take a while to fix, and it would be very useful for > libstdc++ ranges to work with Clang in the meantime. > Yes, this is ok because the hack is limited to __clang__. > 2023-10-13 Benjamin Brock > > libstdc++-v3/ChangeLog: > > * include/std/ranges: implement workaround for LLVM-61763 in > zip_view and adjacency_view > This should be a complete sentence, so capital letter and full stop. I can get this pushed to trunk and gcc-13 next week, thanks again for the patch. > --- > > diff --git a/libstdc++-v3/include/std/ranges > b/libstdc++-v3/include/std/ranges > index 1d529a886be..7893e3a84c9 100644 > --- a/libstdc++-v3/include/std/ranges > +++ b/libstdc++-v3/include/std/ranges > @@ -4632,6 +4632,9 @@ namespace views::__adaptor > class zip_view<_Vs...>::_Iterator > : public __detail::__zip_view_iter_cat<_Const, _Vs...> > { > +#ifdef __clang__ // LLVM-61763 workaround > + public: > +#endif > > __detail::__tuple_or_pair_t _Vs>>...> _M_current; > > constexpr explicit > @@ -4652,11 +4655,13 @@ namespace views::__adaptor > return input_iterator_tag{}; > } > > +#ifndef __clang__ // LLVM-61763 workaround > template > requires (view<_Ws> && ...) && (sizeof...(_Ws) > 0) && > is_object_v<_Fp> > && regular_invocable<_Fp&, range_reference_t<_Ws>...> > && std::__detail::__can_reference range_reference_t<_Ws>...>> > friend class zip_transform_view; > +#endif > > public: > // iterator_category defined in __zip_view_iter_cat > @@ -5327,6 +5332,9 @@ namespace views::__adaptor > template > class adjacent_view<_Vp, _Nm>::_Iterator > { > +#ifdef __clang__ // LLVM-61763 workaround > + public: > +#endif > using _Base = __detail::__maybe_const_t<_Const, _Vp>; > array, _Nm> _M_current = array, > _Nm>(); > > @@ -5367,12 +5375,14 @@ namespace views::__adaptor > > friend class adjacent_view; > > +#ifndef __clang__ // LLVM-61763 workaround > template > requires view<_Wp> && (_Mm > 0) && is_object_v<_Fp> > && regular_invocable<__detail::__unarize<_Fp&, _Mm>, > range_reference_t<_Wp>> > && > std::__detail::__can_reference _Mm>, > > range_reference_t<_Wp>>> > friend class adjacent_transform_view; > +#endif > > public: > using iterator_category = input_iterator_tag; > --000000000000ee78b70607a904dd--