From patchwork Mon Oct 17 16:26:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 3590 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1537657wrs; Mon, 17 Oct 2022 09:28:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4E6K+TXkSvlzURdADL10WNcjrnVwL4JLDTziyEF6gFKSDHjvC7kWYLbf25ziDDgDZl5nWB X-Received: by 2002:a17:907:7f91:b0:78e:2eb4:1fac with SMTP id qk17-20020a1709077f9100b0078e2eb41facmr9194336ejc.126.1666024114856; Mon, 17 Oct 2022 09:28:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666024114; cv=none; d=google.com; s=arc-20160816; b=sqYCbnXkpGXfs6jxpiXAckpK4AQkyYI97yWx8K3FJHtSvjTPlJChNqxoRbn5BZsPfT io3ryr9rnsCHxUS4EtpRNqgOy6C6tTbsa2kRQZ3ajPbb3n4FiEgaEjcwR7MEvtHl1+fZ Q1q0O2om+P4HrFgLQjHfVWU6IURPytkJe00ydTKfsuPiSjc6QCVKJWdsHqgNKGk9LCLc zhDAjBgU6IH87gi4P5WFNO9VctTXv2iaBxCkIlPxp98eAwL1sCOlwKNIMPq9H7E/M5HQ +GB7uAikWl/9HVDVE0vsYLqqMKI1LAASFGhyubsu3iej6RV9I2sDUMp1XPhK7jxW1JkA 0C8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=x0ALybbp1Ynhj6Aa9iCAeN+BNGCqQldkr5D7wgPVL+A=; b=g7mWnlCFEVaOqZoEx/M71lW6jy8WDY0cFd8HQWP5COUmMR26ni+gjpZjl7KTnTMNEF DvUeUhP6GFTe/YEHMWNyNViJv4JBXFR77nmHbRgQTAaylu2NOqnNCzLC3/Vka66u6msF QxF23AKr+i2ZYEs2MkQ2bieydM9im08vGzNbqwlSQQfdSSEKXjJBXkPAHVN9ZbRcXq0H o9wXvVp6r4kFHYqB4RDM8tsznmOQUbD2sXzmIV80xRSMRaiRk3DCD73OykIb0FegBJBp YlD+TZrqh1nZOLP6J9GYfjJEk2NfgqIvUdzjJ5x//ET/Kw3ckFf6oX4Btp54Y+Ro2pum Ci2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="laf/J+01"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n1-20020a1709062bc100b0077d26491a9csi8109158ejg.141.2022.10.17.09.28.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 09:28:34 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="laf/J+01"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 935413858413 for ; Mon, 17 Oct 2022 16:28:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 935413858413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666024113; bh=x0ALybbp1Ynhj6Aa9iCAeN+BNGCqQldkr5D7wgPVL+A=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=laf/J+01OxzxKLkapzyDg+/pSZ75z4gGGSiykecQLz4/0rZ+V18TBKE3N9GBdbBO3 ogbzaEAU1akosFB8HW7C935+nTZz3MpD+HP26zr+sPckOaBB1YRScg6zNZfG0DnsRn KWhS9mlpUUio/hDz/1r5TRdpOiETA4Ydjk3wmmH0= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 2CC173857825 for ; Mon, 17 Oct 2022 16:26:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2CC173857825 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-425-uRx-3rvOPeeg3KjMWNKyTg-1; Mon, 17 Oct 2022 12:26:38 -0400 X-MC-Unique: uRx-3rvOPeeg3KjMWNKyTg-1 Received: by mail-qt1-f197.google.com with SMTP id fy10-20020a05622a5a0a00b0039cd5097697so8037175qtb.7 for ; Mon, 17 Oct 2022 09:26:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=x0ALybbp1Ynhj6Aa9iCAeN+BNGCqQldkr5D7wgPVL+A=; b=aEkWbQVPVl/Uj05MAkRHfh1BxEmVq6Do1iZFeBx5qkJZiq6WvbDq6WF09Jutkg+2tN jahd4uD0mPMtV5feMdJ5gLzJY/B4RHE0lRZ04mXlPXWSn0RQVigCKKbT74IRs5I0yUxC BGxHnNugA31OH+OQswPgtmErTKCY7AoderkoVlUG/Jo+CjLCSMO6R1IHFgtApIYWGn8u 2btF9EW04E2WzH77H6XI4+W66JXtE3T6Erp9qhOVmFoxE/VgQenwBlm5S6fv2l3Fwopq QP5DFBm54cH8UqC0BkG0VNJmp9Z8BTB1RURwrTq5icazZrHgiv1XfK49IjSco5U9eM+h jEKg== X-Gm-Message-State: ACrzQf2Y65hj1hXbLRxet4O98ZrtN5yjw70cUOC0RxevZJSvlGuOJLcH XnaPT8N8HMpyjFX8jhDs2jUmYIcRgWuuuqSnqRgS42fnOVZe66v/M6ssQJPMxSuygFfZSiwolSV pxV6HtotcjcSN1dHUV3TP80mCDgaztrRJclgghVeD4ycqLIvvle/fGd9Yrl3hlsOQ1tg= X-Received: by 2002:a05:6214:c83:b0:4b1:8ea4:f3fb with SMTP id r3-20020a0562140c8300b004b18ea4f3fbmr9234891qvr.73.1666023997580; Mon, 17 Oct 2022 09:26:37 -0700 (PDT) X-Received: by 2002:a05:6214:c83:b0:4b1:8ea4:f3fb with SMTP id r3-20020a0562140c8300b004b18ea4f3fbmr9234863qvr.73.1666023997205; Mon, 17 Oct 2022 09:26:37 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id t1-20020ac86a01000000b00398946670f3sm176194qtr.1.2022.10.17.09.26.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 09:26:36 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Redefine __from_chars_alnum_to_val's table Date: Mon, 17 Oct 2022 12:26:32 -0400 Message-Id: <20221017162632.1085359-1-ppalka@redhat.com> X-Mailer: git-send-email 2.38.0.68.ge85701b4af MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.1 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_H2, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Cc: libstdc++@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746952902352347280?= X-GMAIL-MSGID: =?utf-8?q?1746952902352347280?= It looks like the constexpr commit r13-3313-g378a0f1840e694 caused some modules regressions: FAIL: g++.dg/modules/xtreme-header-4_b.C -std=c++2b (test for excess errors) FAIL: g++.dg/modules/xtreme-header_b.C -std=c++2b (test for excess errors) Like PR105297, the problem seems to be the local class from __from_chars_alnum_to_val ending up as the type of a namespace-scope entity (the variable template __detail::__table in this case). This patch works around this modules issue by using an ordinary class instead of a local class. Also, I suppose we might as well use a static data member to define the table once for all dialects instead of having to define it twice in C++23 mode, once as a static local variable (which isn't usable during constexpr evaluation) and again as a variable template (which is). Tested on x86_64-pc-linux-gnu, does this look OK for trunk? Diff generated with -w to ignore noisy whitespace changes. libstdc++-v3/ChangeLog: * include/std/charconv (__detail::__from_chars_alnum_to_val_table): Redefine as a class template containing type, value and _S_table members. Don't use a local class as the table type. (__detail::__table): Remove. (__detail::__from_chars_alnum_to_val): Adjust after the above. --- libstdc++-v3/include/std/charconv | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv index 7aefdd3298c..c157d4c74ab 100644 --- a/libstdc++-v3/include/std/charconv +++ b/libstdc++-v3/include/std/charconv @@ -413,14 +413,19 @@ namespace __detail return true; } + template + struct __from_chars_alnum_to_val_table + { + struct type { unsigned char __data[1u << __CHAR_BIT__] = {}; }; + // Construct and return a lookup table that maps 0-9, A-Z and a-z to their // corresponding base-36 value and maps all other characters to 127. - constexpr auto - __from_chars_alnum_to_val_table() + static constexpr type + _S_table() { constexpr unsigned char __lower_letters[27] = "abcdefghijklmnopqrstuvwxyz"; constexpr unsigned char __upper_letters[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - struct { unsigned char __data[1u << __CHAR_BIT__] = {}; } __table; + type __table; for (auto& __entry : __table.__data) __entry = 127; for (int __i = 0; __i < 10; ++__i) @@ -433,10 +438,11 @@ namespace __detail return __table; } -#if __cpp_lib_constexpr_charconv - template - inline constexpr auto __table = __from_chars_alnum_to_val_table(); -#endif + // This initializer is made superficially dependent in order + // to prevent the compiler from wastefully constructing the + // table ahead of time when it's not needed. + static constexpr type value = (_DecOnly, _S_table()); + }; // If _DecOnly is true: if the character is a decimal digit, then // return its corresponding base-10 value, otherwise return a value >= 127. @@ -449,16 +455,7 @@ namespace __detail if _GLIBCXX17_CONSTEXPR (_DecOnly) return static_cast(__c - '0'); else - { -#if __cpp_lib_constexpr_charconv - if (std::__is_constant_evaluated()) - return __table<_DecOnly>.__data[__c]; -#endif - // This initializer is deliberately made dependent in order to work - // around modules bug PR105322. - static constexpr auto __table = (_DecOnly, __from_chars_alnum_to_val_table()); - return __table.__data[__c]; - } + return __from_chars_alnum_to_val_table<_DecOnly>::value.__data[__c]; } /// std::from_chars implementation for integers in a power-of-two base.