From patchwork Wed Jul 19 20:43:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 122822 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2698382vqt; Wed, 19 Jul 2023 13:46:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlH3XaAZCLwg9CGSjM2zRKH/QYqYMNxjs1UcVRo+19fw202Yu43TNhe65S/tu6SwbA9KkH1K X-Received: by 2002:a05:6512:485e:b0:4f9:b649:23d2 with SMTP id ep30-20020a056512485e00b004f9b64923d2mr110268lfb.42.1689799585730; Wed, 19 Jul 2023 13:46:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689799585; cv=none; d=google.com; s=arc-20160816; b=m8ON+lzmgIDxaKUCaidZJtnMM4KmfDvsFo+PSihq6w9v5S+Re/hOrfoE6mAws9iuYY 57KUELZYGUnFWfGv0yMJ1bptW14ZPRvfbgDc04Ex02GpbE68+Kr8+BmGrCm2TXR+XLSu q3dbuWTNLYtL7ttNFksPcCHwQssorBBLRg2CD0Sqns/D33EFimWxN0fZqDWqFj81rtCp SZLd1ecZr45rnmEuQpWU3Aw1g6tpLyVHk4R8l68SIYg/Jbc2G0/nPo7oW2TqnFabBrOw UKGk/5C52PZXr18wfnerzg5qzmDT/2YWFx/q8afqE96e3a50l4hSwYSLeHUKmuZ095J9 s2pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=DNt635gk7fyR4++kmdzVFGtZrQFpKqPEk51mmadCaxg=; fh=G2E9y69Q8/x354J/q5iC4IcA3Toy5/oY+pWkuXA/CJM=; b=ZpQIDNYH6JJHrhzzptbQZLZdRxAMkOvfjekLuzlsKhLRmGkSaRYtBZd3TSqtxQnS4K v4FAhZUHVtgu8KyIBjtozXCMeTAffo68Ip24BGi451ab6B5shnnTPAgwlhlX3oWCnsWg ukwJBMWuiZovr0lx5KuMunlBjPMCNVFkuxrnhvRh1FMZ50gnbYW2n4FfzV/Z7+Ku0fqV X+htxccqasBP4DvOtgR62b2Skk3Fu0JmZb6to2p4QHd+jHOdSznmeyk6B+sZVixA0k9b kZe4usdbmP0Ib8Kxp2McV/wMr9D/03LJCC/hBbXY1aG0PKhrc8GjciEjGskcz8+BGNkz SQJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hN+ztKV4; 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f15-20020a05640214cf00b00518c6e070f8si3325680edx.663.2023.07.19.13.46.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 13:46:25 -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=hN+ztKV4; 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 8D6C4385AFBF for ; Wed, 19 Jul 2023 20:46:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D6C4385AFBF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689799570; bh=DNt635gk7fyR4++kmdzVFGtZrQFpKqPEk51mmadCaxg=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=hN+ztKV49eicc/5ni9wdDvc8ZSqoZquc0xniMjEHML3JLyrFC3yY6Q7grRAgWLGqD 1EKFbLLEf1JzFq5X5tdjSuO/Wq4prTX62wMJYzjb0C8qJN9BbX1eG4nLs9TUbke/r3 rE+v4ChMJtLHzK3UQucCJ2qAvhv+xmwm90bZF7IM= 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 0782D3858C2B for ; Wed, 19 Jul 2023 20:45:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0782D3858C2B Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-397-R0JzWmRuPEaiknauXf9XTg-1; Wed, 19 Jul 2023 16:45:23 -0400 X-MC-Unique: R0JzWmRuPEaiknauXf9XTg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1A3DD800962; Wed, 19 Jul 2023 20:45:23 +0000 (UTC) Received: from localhost (unknown [10.42.28.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id D13762166B25; Wed, 19 Jul 2023 20:45:22 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Patrick Palka Subject: [PATCH] libstdc++: Fix preprocessor conditions for std::from_chars [PR109921] Date: Wed, 19 Jul 2023 21:43:58 +0100 Message-ID: <20230719204522.2585813-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 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, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771883290241101382 X-GMAIL-MSGID: 1771883290241101382 I'm testing this patch for gcc-13 as a better fix for PR109921, without the breakage that r14-1431-g7037e7b6e4ac41 caused on trunk. If testing goes well I'll push this before the 13.2 release candidate. -- >8 -- We use the from_chars_strtod function with __strtof128 to read a _Float128 value, but from_chars_strtod is not defined unless uselocale is available. This can lead to compilation failures for some targets, because we try to define the _Float128 overload in terms of a non-existing from_chars_strtod function. Only try to use __strtof128 if uselocale is available and therefore we can use the from_chars_strtod function template. This is a simpler change than r14-1431-g7037e7b6e4ac41 on trunk, because that caused unwanted ABI regressions (PR libstdc++/110077). libstdc++-v3/ChangeLog: PR libstdc++/109921 * src/c++17/floating_from_chars.cc (USE_STRTOF128_FOR_FROM_CHARS): Only define when USE_STRTOD_FOR_FROM_CHARS is also defined. (USE_STRTOD_FOR_FROM_CHARS): Do not undefine when long double is binary64. (from_chars(const char*, const char*, double&, chars_format)): Check __LDBL_MANT_DIG__ == __DBL_MANT_DIG__ here. --- libstdc++-v3/src/c++17/floating_from_chars.cc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/src/c++17/floating_from_chars.cc b/libstdc++-v3/src/c++17/floating_from_chars.cc index 78b9d92cdc0..b3061bdca01 100644 --- a/libstdc++-v3/src/c++17/floating_from_chars.cc +++ b/libstdc++-v3/src/c++17/floating_from_chars.cc @@ -64,7 +64,7 @@ // strtold for __ieee128 extern "C" __ieee128 __strtoieee128(const char*, char**); #elif __FLT128_MANT_DIG__ == 113 && __LDBL_MANT_DIG__ != 113 \ - && defined(__GLIBC_PREREQ) + && defined(__GLIBC_PREREQ) && defined(USE_STRTOD_FOR_FROM_CHARS) #define USE_STRTOF128_FOR_FROM_CHARS 1 extern "C" _Float128 __strtof128(const char*, char**) __asm ("strtof128") @@ -77,10 +77,6 @@ extern "C" _Float128 __strtof128(const char*, char**) #if _GLIBCXX_FLOAT_IS_IEEE_BINARY32 && _GLIBCXX_DOUBLE_IS_IEEE_BINARY64 \ && __SIZE_WIDTH__ >= 32 # define USE_LIB_FAST_FLOAT 1 -# if __LDBL_MANT_DIG__ == __DBL_MANT_DIG__ -// No need to use strtold. -# undef USE_STRTOD_FOR_FROM_CHARS -# endif #endif #if USE_LIB_FAST_FLOAT @@ -1211,7 +1207,7 @@ from_chars_result from_chars(const char* first, const char* last, long double& value, chars_format fmt) noexcept { -#if ! USE_STRTOD_FOR_FROM_CHARS +#if __LDBL_MANT_DIG__ == __DBL_MANT_DIG__ || !defined USE_STRTOD_FOR_FROM_CHARS // Either long double is the same as double, or we can't use strtold. // In the latter case, this might give an incorrect result (e.g. values // out of range of double give an error, even if they fit in long double). @@ -1280,6 +1276,7 @@ _ZSt10from_charsPKcS0_RDF128_St12chars_format(const char* first, chars_format fmt) noexcept __attribute__((alias ("_ZSt10from_charsPKcS0_Ru9__ieee128St12chars_format"))); #elif defined(USE_STRTOF128_FOR_FROM_CHARS) +// Overload for _Float128 is not defined inline in , define it here. from_chars_result from_chars(const char* first, const char* last, _Float128& value, chars_format fmt) noexcept