From patchwork Fri Jan 20 14:06:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 46350 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp216687wrn; Fri, 20 Jan 2023 06:06:53 -0800 (PST) X-Google-Smtp-Source: AMrXdXvwOSzhHVMXY01CN8F1vjir1qHKDyRptkZznEeFO6Fow0gFaULqf3BFZjbB5kCpdSEmoFBB X-Received: by 2002:a17:906:dfda:b0:871:e9a0:ebaa with SMTP id jt26-20020a170906dfda00b00871e9a0ebaamr16154018ejc.31.1674223612830; Fri, 20 Jan 2023 06:06:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674223612; cv=none; d=google.com; s=arc-20160816; b=tMceAGONIzqrLDLAlprzWoq2WZ7uoRtTsOPpK5y79KPl2lWwnj7AU7JzswKLWUpu4/ uIZUd+RjRG9/U8k7lINu7Hgfqc93KT8m0M/PVdItwkYc0QlMwj+9BuqbI5UpYfanMR6C yB0AoSDyDlcsn4AzVw0bisKe0K3ngw+F85mIEc37vuVheWOpNZ+JDZWyg776tsfbX82B UTL+jP+xFNhIfpmB2hoWWWExxse+OWdZ4lWqRKcBur/1p4dzxo52wF0M7PouJP3Urrmm 2ShW4SkNd5W//NDKw9L0nNo/ljNd7ZgxqIdIsJurkeIxPL8oW0OwgtgElobM88h5OoiR ddjA== 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:message-id :user-agent:subject:to:date:mime-version:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=GqNIkP1I6aXxxXVo0//zOyJl7vsyPJZYphy6sVzkQHQ=; b=0oL1ec6uCjA89riwz3UUFNvP2bEZR7ip1A2IFLPDnvc2Qg2BrV7A4s97IB2nNJdLbB jLFSdfjzLWOfgYKXInERDviwBpXw/xtcDT1ZRmFMbofHR7f06DNm7nXgZjb6xJNuHNht UMavcAIZKwq/oXzbuClKjn+iUFgYntz3gtbHQNXTIST5e0BcbWJ4kJpbw+f3MeS8vI6d R6CsI5AV32euWWUZGiy3AYhJFhJppkY7H4DfN2gte1pspkxsvOjsa4msk1jLNzisgnix GeP0UKNJuvpNGlGLiCyhwcsFWSu3lx44qSIFp72UzJGfWcnnUasQXkRZ8I5MEcxea7VL oFoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jMPf8Jbo; 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=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id jg6-20020a170907970600b008776a7302e8si6743938ejc.143.2023.01.20.06.06.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jan 2023 06:06:52 -0800 (PST) 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=@gcc.gnu.org header.s=default header.b=jMPf8Jbo; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BE4863858D33 for ; Fri, 20 Jan 2023 14:06:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE4863858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674223611; bh=GqNIkP1I6aXxxXVo0//zOyJl7vsyPJZYphy6sVzkQHQ=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jMPf8JbodU+6JAD+hm9InL1x9K6oy5wpc4g23imWL7sWkm4uUva7hZPEJZv1s/tao FL1Z/pZVXyJhX/sgb6a9kbM/BxHfR9RPi8fXfiuCdNAZVY5IeaF2bia+jfZ+n9cYiL IWlsyIR/5xHb6NkZdwcrzfhbPl5li8cPRZVFY0YY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from devianza.investici.org (devianza.investici.org [198.167.222.108]) by sourceware.org (Postfix) with ESMTPS id C39773858D20 for ; Fri, 20 Jan 2023 14:06:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C39773858D20 Received: from 1.mail-backend.investici.org (unknown [10.0.0.11]) by devianza.investici.org (Postfix) with ESMTP id 4Nz1Vx3Tbpz6vH6 for ; Fri, 20 Jan 2023 14:06:01 +0000 (UTC) Received: from 1.webmail.investici.org (localhost [127.0.0.1]) (Authenticated sender: i.nixman@autistici.org) by 1.mail-backend.investici.org (Postfix) with ESMTPA id 4Nz1Vx2k96z5y5V for ; Fri, 20 Jan 2023 14:06:01 +0000 (UTC) MIME-Version: 1.0 Date: Fri, 20 Jan 2023 14:06:01 +0000 To: Gcc Patches Subject: libquadmath fix for 94756 and 87204 User-Agent: Roundcube Webmail Message-ID: <0e5ef1d5ce3e47e8431450ae8383a342@autistici.org> X-Sender: i.nixman@autistici.org X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, 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 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: "i.nixman--- via Gcc-patches" From: "Li, Pan2 via Gcc-patches" Reply-To: i.nixman@autistici.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?1755550698724941649?= X-GMAIL-MSGID: =?utf-8?q?1755550698724941649?= hello, I have fixed: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94756 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87204 tested on i686-mingw-w64, x86_64-mingw-w64, and for i686 and x86_64 linux. could anyone check and apply please? best! diff --git a/libquadmath/printf/gmp-impl.h b/libquadmath/printf/gmp-impl.h index 94d88efc57f..af0719321dc 100644 --- a/libquadmath/printf/gmp-impl.h +++ b/libquadmath/printf/gmp-impl.h @@ -33,15 +33,30 @@ MA 02111-1307, USA. */ #define MAX(h,i) ((h) > (i) ? (h) : (i)) #endif -#define BITS_PER_MP_LIMB (__SIZEOF_LONG__ * __CHAR_BIT__) -#define BYTES_PER_MP_LIMB (BITS_PER_MP_LIMB / __CHAR_BIT__) -typedef unsigned long int mp_limb_t; -typedef long int mp_limb_signed_t; +#ifdef __MINGW32__ + /* for MinGW targets the Microsoft ABI requires that `long` + types will always have 32 bit, because of that we will use + `int32_t` for 32-bit builds and `int64_t` for 64-bit builds */ +# if __x86_64__ + typedef long long int mp_limb_signed_t; + typedef unsigned long long int mp_limb_t; +# define BITS_PER_MP_LIMB (__SIZEOF_LONG_LONG__ * __CHAR_BIT__) +# else // !__x86_64__ + typedef long int mp_limb_signed_t; + typedef unsigned long int mp_limb_t; +# define BITS_PER_MP_LIMB (__SIZEOF_LONG__ * __CHAR_BIT__) +# endif // __x86_64__ +#else // !__MINGW32__ + typedef long int mp_limb_signed_t; + typedef unsigned long int mp_limb_t; +# define BITS_PER_MP_LIMB (__SIZEOF_LONG__ * __CHAR_BIT__) +#endif // __MINGW32__ -typedef mp_limb_t * mp_ptr; -typedef const mp_limb_t * mp_srcptr; -typedef long int mp_size_t; -typedef long int mp_exp_t; +#define BYTES_PER_MP_LIMB (BITS_PER_MP_LIMB / __CHAR_BIT__) +typedef long int mp_size_t; +typedef long int mp_exp_t; +typedef mp_limb_t *mp_ptr; +typedef const mp_limb_t *mp_srcptr; /* Define stuff for longlong.h. */ typedef unsigned int UQItype __attribute__ ((mode (QI))); diff --git a/libquadmath/strtod/strtod_l.c b/libquadmath/strtod/strtod_l.c index 0b0e85a3cf7..6790124e6fc 100644 --- a/libquadmath/strtod/strtod_l.c +++ b/libquadmath/strtod/strtod_l.c @@ -200,7 +200,7 @@ round_and_return (mp_limb_t *retval, intmax_t exponent, int negative, round_limb = retval[RETURN_LIMB_SIZE - 1]; round_bit = (MANT_DIG - 1) % BITS_PER_MP_LIMB; - for (i = 0; i < RETURN_LIMB_SIZE; ++i) + for (i = 0; i < RETURN_LIMB_SIZE - 1; ++i) more_bits |= retval[i] != 0; MPN_ZERO (retval, RETURN_LIMB_SIZE); } @@ -215,9 +215,14 @@ round_and_return (mp_limb_t *retval, intmax_t exponent, int negative, more_bits |= ((round_limb & ((((mp_limb_t) 1) << round_bit) - 1)) != 0); - (void) mpn_rshift (retval, &retval[shift / BITS_PER_MP_LIMB], - RETURN_LIMB_SIZE - (shift / BITS_PER_MP_LIMB), - shift % BITS_PER_MP_LIMB); + /* mpn_rshift requires 0 < shift < BITS_PER_MP_LIMB. */ + if ((shift % BITS_PER_MP_LIMB) != 0) + (void) mpn_rshift (retval, &retval[shift / BITS_PER_MP_LIMB], + RETURN_LIMB_SIZE - (shift / BITS_PER_MP_LIMB), + shift % BITS_PER_MP_LIMB); + else + for (i = 0; i < RETURN_LIMB_SIZE - (shift / BITS_PER_MP_LIMB); i++) + retval[i] = retval[i + (shift / BITS_PER_MP_LIMB)]; MPN_ZERO (&retval[RETURN_LIMB_SIZE - (shift / BITS_PER_MP_LIMB)], shift / BITS_PER_MP_LIMB); } @@ -276,7 +281,7 @@ round_and_return (mp_limb_t *retval, intmax_t exponent, int negative, } } - if (exponent > MAX_EXP) + if (exponent >= MAX_EXP) goto overflow; #ifdef HAVE_FENV_H @@ -308,7 +313,7 @@ round_and_return (mp_limb_t *retval, intmax_t exponent, int negative, } #endif - if (exponent > MAX_EXP) + if (exponent >= MAX_EXP) overflow: return overflow_value (negative); @@ -688,7 +693,7 @@ ____STRTOF_INTERNAL (nptr, endptr, group) if (endptr != NULL) *endptr = (STRING_TYPE *) cp; - return retval; + return negative ? -retval : retval; } /* It is really a text we do not recognize. */ @@ -1193,7 +1198,7 @@ ____STRTOF_INTERNAL (nptr, endptr, group) if (__builtin_expect (exponent > MAX_10_EXP + 1 - (intmax_t) int_no, 0)) return overflow_value (negative); - if (__builtin_expect (exponent < MIN_10_EXP - (DIG + 1), 0)) + if (__builtin_expect (exponent < MIN_10_EXP - (DIG + 2), 0)) return underflow_value (negative); if (int_no > 0) @@ -1360,7 +1365,7 @@ ____STRTOF_INTERNAL (nptr, endptr, group) assert (dig_no > int_no && exponent <= 0 - && exponent >= MIN_10_EXP - (DIG + 1)); + && exponent >= MIN_10_EXP - (DIG + 2)); /* We need to compute MANT_DIG - BITS fractional bits that lie within the mantissa of the result, the following bit for @@ -1651,8 +1656,8 @@ ____STRTOF_INTERNAL (nptr, endptr, group) d1 = den[densize - 2]; /* The division does not work if the upper limb of the two-limb - numerator is greater than the denominator. */ - if (mpn_cmp (num, &den[densize - numsize], numsize) > 0) + numerator is greater or equal to than the denominator. */ + if (mpn_cmp (num, &den[densize - numsize], numsize) >= 0) num[numsize++] = 0; if (numsize < densize) @@ -1761,7 +1766,7 @@ ____STRTOF_INTERNAL (nptr, endptr, group) got_limb; } - for (i = densize; num[i] == 0 && i >= 0; --i) + for (i = densize; i >= 0 && num[i] == 0; --i) ; return round_and_return (retval, exponent - 1, negative, quot, BITS_PER_MP_LIMB - 1 - used,