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 8D919384D19A for ; Thu, 20 Oct 2022 12:01:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8D919384D19A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666267292; 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=12r50kynzoR9xJlAaIoDtH+wkhO7XLwX7tEQ6jPDI9s=; b=IicpIc3nqGsozZ4R8AMItgX9sooGrPSxm/veu2kdx0ldryUfcc2Yu5WY3ZMBSbjVxlzvtv eRM/vu49mzRzJRNtd66v+gSPnFCWrXzIPvMUd0yvrSkVHMsvP3hXqC+3Cw2b6INe+3H1uj zjQvmvXbvR6dDZGcg4UH2AcTgbMyepM= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-115-Err2UpnbPWuJKLodaCeoiw-1; Thu, 20 Oct 2022 08:01:30 -0400 X-MC-Unique: Err2UpnbPWuJKLodaCeoiw-1 Received: by mail-qk1-f200.google.com with SMTP id o13-20020a05620a2a0d00b006cf9085682dso16937139qkp.7 for ; Thu, 20 Oct 2022 05:01:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=12r50kynzoR9xJlAaIoDtH+wkhO7XLwX7tEQ6jPDI9s=; b=Afc6Zzou/sfCDtbdnCt3eS//D7p4+AkoRFJTnlmgujZIpg7W6qc2WPqzCas/PAEv7z BDPVY/VJSg5JjhBah8nFAQ/pI4QnoXam6/AmGR3x703ohKy1z4eYIIxtHfHzZRHfzU9U IDZ6KU89Xg413Ij2Wkn79pf3hgEmWBjP4Z1jThQarqqvyLr1OEDCWrGmf2UE0UpC5PNI vevvniMvAc6kc2cI6qw0y6AYTRPPE3NweX+42J7BVI7+39GbzDO89zsJIkkitP0Bg9Xz nwe1/DMseRq8gCs0vIKeEnGL0j/2GQsG/csO8ZdR2Yv5jAypRgIe/erVgYUZtRwcipfu Kf9w== X-Gm-Message-State: ACrzQf2CL+aZNH0se1Ubgp6x5LL08vgccB5T1kDmWO4ZH59FGoFxKKPQ 2ocatDzRmyQM5ncmekVn/YizsT7b1PXWksx/zU6OewJJaqZzBMlJEvwD4H0fSIBo2ijkO6F1wb5 4hqa72QlOKejj52FPtvAUyIgX10eRt1Y= X-Received: by 2002:a37:4454:0:b0:6e7:9bd0:bf53 with SMTP id r81-20020a374454000000b006e79bd0bf53mr8940130qka.616.1666267283304; Thu, 20 Oct 2022 05:01:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7LryGOwcBmmg36zSPMjCJIVkMDiOsJeAQNdvv0yFqSPV3obaLMUeY+QHOjftyudWD1yBRCZbZuzZa2VWBIqJA= X-Received: by 2002:a37:4454:0:b0:6e7:9bd0:bf53 with SMTP id r81-20020a374454000000b006e79bd0bf53mr8939579qka.616.1666267276518; Thu, 20 Oct 2022 05:01:16 -0700 (PDT) MIME-Version: 1.0 References: <20221017162632.1085359-1-ppalka@redhat.com> In-Reply-To: <20221017162632.1085359-1-ppalka@redhat.com> From: Jonathan Wakely Date: Thu, 20 Oct 2022 13:01:05 +0100 Message-ID: Subject: Re: [PATCH] libstdc++: Redefine __from_chars_alnum_to_val's table 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.7 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 List-Id: On Mon, 17 Oct 2022 at 17:27, Patrick Palka via Libstdc++ wrote: > > 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. OK, thanks. > > 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. > -- > 2.38.0.68.ge85701b4af >