From patchwork Fri Oct 13 23:32:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Brock X-Patchwork-Id: 152867 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2232795vqb; Fri, 13 Oct 2023 17:37:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEqfy/hPxjVYFAlirdN3hc+zU+i4A3+nhMmq0S3N0ZGmWOni/5Bl7s7GduZMDiXqFaUiNiL X-Received: by 2002:ac8:7d56:0:b0:417:985f:d1f3 with SMTP id h22-20020ac87d56000000b00417985fd1f3mr36125211qtb.54.1697243835688; Fri, 13 Oct 2023 17:37:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697243835; cv=pass; d=google.com; s=arc-20160816; b=04tP/OfKqcT5c5JQADf+7NCE6gcNoUMwCvNza9S56rSj3CRG/ab/KKB0UeADSq0PDh e5bXrCRJwV0KOEvr1ArKmuZpxLC9MR/g0U7qLExTeuQvSgUiKHLkvTxIUVd+b/Q43Jwr Yk1mv2nR4w5Thl4S5XaVqCJ8/R4yk3508XnwDnEj6SucJFZUpGnitQA4+TpiO+6byheD UiqOK5+DfqADI+UYwRoKWYj9dXs2vQFLq4Sz1x3cMe/sXjJXsdjeBKBYOzsozOCOJZVc 41r4ZyTVFnMyjB6XUeo4D2lX6HbrAME36yPODuEu9u5qS8489AFzuMhKpT1uInkjgSCy 7n3Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:subject:message-id:date :from:mime-version:dkim-signature:dmarc-filter:arc-filter :delivered-to; bh=XyStzg7HivlG9fM5oh1u3XBBPwpTmMSOVRzyT41m8+w=; fh=tWtX2nBowArQFpO5tL5gtY10/+xKa8dUFoy2HZVoc4M=; b=fW8fhP1ho0fcXB7GwcN4YfhfjWCK1WfFhrZdANfHbaAAP+qeAS+qZxgVwfy3LXudyr 3f/ZGrNNA1ZbnPAvMOsvfUZcszqv9W+G7vY/fHDpiqgLTFljCoaRt+sXdrDzRp8dJWg5 3Eh1RyuQE+ppYwgJ3UbzMjZqYnFTZEGtAXwaXjiDqLnjw7IFD8xnmj9l9hyu2QHOtLUn OnlYfHeCHBTy0qp0V+NnUkW1KeYL9Eg+upqQQvdupsDjOSrxnKSOvdX2TSdPQMgjyaYZ hSbzAknKL/fUsJOW6dprDTy3RrTdhNDhFPbXhdwPXa7QWTbzEZPmABYP9fESFZRYrBBp jJfA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cs.berkeley.edu header.s=google header.b=dEEUKMLx; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cs.berkeley.edu Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id f18-20020ac87f12000000b004198efe4596si2075831qtk.70.2023.10.13.17.37.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 17:37:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@cs.berkeley.edu header.s=google header.b=dEEUKMLx; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cs.berkeley.edu Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B52D2385734F for ; Fri, 13 Oct 2023 23:33:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by sourceware.org (Postfix) with ESMTPS id 401603858D28 for ; Fri, 13 Oct 2023 23:33:11 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 401603858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::729 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697239993; cv=none; b=jUnW+j4ie4lgyeL7EGH0RmxhKxN21BLhKoRqvQGFRfVkFjcYM7NzPLCEXghnZnqd7cuiTMpYnezNrcHm8h2OzLORFXCoJIrgTV3s2mRH98W3d29s13hi1aPJmSuFb3wGsGyG7ko/Eqv9JzeXq4KCWaD/B/nY03fUmunsHm3Zh5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697239993; c=relaxed/simple; bh=DT0WMzN08IxKPj5h3kHcPLMwTNoqJOkreGiTrMT4qmA=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=oZazPdniZo4Io+S1ZPf4gLd/Y9UhcNW8SU8dYP42uraoq+Vabf/k+7gD+5DIm3th1QC2NTVL3SrCstBMqgYqkbGOABnpuM6ODsh2DS+LX0AZslYg0xyFJyFOlf+pNCSEiNEIRQJ+CpaBP0GJ9eI1fWDeiZ1FzlMJ96BUbjqchus= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 401603858D28 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=cs.berkeley.edu Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=berkeley.edu Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-775810b032aso168204285a.1 for ; Fri, 13 Oct 2023 16:33:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.berkeley.edu; s=google; t=1697239990; x=1697844790; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=XyStzg7HivlG9fM5oh1u3XBBPwpTmMSOVRzyT41m8+w=; b=dEEUKMLxkQk+SZrqG97xckXsb4wDqyqNdMcnQJrRVxczcXIUujcbTB0+JdEZ2LjVS1 o2Wib/vbaLnPgpbK1DzEYbsnfexLpk6NHx5+76NIQLNrNTu12y4YP4jh9FqZkS4AEVsT PnGihL7Ut409xezJrxToKYw9RBRJo4tdLV/2eSJbrNPBswDZeEApKWkQSx2UFSTtrVwQ vGCa96OuaDx8HG5OT1x1Yd0nX7tBndEr7YhutI2r6+1H5UC2tmTSAYRN4YeAg1usrATd vwZEj5SPf/pnJt0Chi6sfuGS22JTO7Fxtb1JmidZ/0RPDl3HaqyDe5d8WDz7px2tF8eM O3aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697239990; x=1697844790; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=XyStzg7HivlG9fM5oh1u3XBBPwpTmMSOVRzyT41m8+w=; b=PUC7DDoSnxdf3nPCpZhFWDnc2ap41kaZs2F99rkbFxYv73AM4LZIAG/Qp1th/u6xTl sZUJiS9zEEYERC29OS5602DXpnK0R2iiaDYQZRMCyjtip4WNSOUQcAEZII481oCHxEP1 N/PJVlvNGWm4E6nr3c9yURtqek8cC2Rm0NkyO+4RJtBAU1ekpeys5QOyi8qfOJS9DGvT HdZGcfQxcQfuJvCrt2Dv+9wmG27Ix2SYTov2IRdP/ac8Tl2x27VFLadj+AWlsokgPSU1 pjuf0lBOElvBlxgXDza102vmedT2pKwAgZDDctVVsMWYKUGkSz7XW152Rtq0owUpuBwM ujBw== X-Gm-Message-State: AOJu0YzazmrE5Z6D41u1lCAFIMDF4z8yvScDQ7/KkjOSquuvGlrchjBD pVDh0YePIQuRC7V+fZH0iUGjaoI/7zbhu3fNMA+3ITTqcN3/Zjsn1A== X-Received: by 2002:a05:620a:45a5:b0:774:5ab:d032 with SMTP id bp37-20020a05620a45a500b0077405abd032mr37033683qkb.23.1697239989672; Fri, 13 Oct 2023 16:33:09 -0700 (PDT) MIME-Version: 1.0 From: Benjamin Brock Date: Fri, 13 Oct 2023 16:32:59 -0700 Message-ID: Subject: [PATCH] libstdc++: Workaround for LLVM-61763 in ranges To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, TXREP, T_SPF_PERMERROR autolearn=ham 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779689152167590327 X-GMAIL-MSGID: 1779689152167590327 This is my first time submitting a patch, so my apologies if I'm submitting incorrectly or missing something. 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. 2023-10-13 Benjamin Brock libstdc++-v3/ChangeLog: * include/std/ranges: implement workaround for LLVM-61763 in zip_view and adjacency_view Signed-off-by: Benjamin Brock --- 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...>> 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, range_reference_t<_Wp>>> friend class adjacent_transform_view; +#endif public: using iterator_category = input_iterator_tag; 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>...> _M_current;