From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by sourceware.org (Postfix) with ESMTPS id 009373858421 for ; Sun, 21 Aug 2022 19:24:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 009373858421 Received: from mail-oo1-f71.google.com (mail-oo1-f71.google.com [209.85.161.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 5397A3F805 for ; Sun, 21 Aug 2022 19:24:54 +0000 (UTC) Received: by mail-oo1-f71.google.com with SMTP id k4-20020a4a3104000000b0044607fa7d05so4820444ooa.21 for ; Sun, 21 Aug 2022 12:24:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc; bh=YfRndyRJ0gz7A3PcSiSeptcw1jUo7lui+UUgiRZlpsI=; b=dBEgcMGg8veykS7P1LPFAMdfdcKHDG9Vj7fpGiwISV+1HuK93w3gf/yxCK8oSD0U3Y teyIWNl8uaX7QWJDSVPD5T83jaz0r+o4YemUfBlI3FDDNULS6SnpJhRco87LiW3Dq5e8 Mct45PrdSV8lkP09R5bqGkEV888YuhaSNRj4npWxfynLBW29j+JYL2GIROXZ6pQDIVIY 7fuXy28DO7svDg+PTWnw+2A5tvnwZer7SkaRozdgLuh52Wz/Ng7AL8vN59k90Dcq+MCn 03ZlZ5MbydlJkFH6sZTuY08BsHpQ6H+LbF7LMPyz6cgYbwFmNI90aPZXed0saQV7kShW aC0w== X-Gm-Message-State: ACgBeo2dUFOj40JnL1EBJmfzpsCt30KVFVvh6MhTk7I5A/Iov99fught hE0LnN+Pot9EhxDewAj5t63sHUj5MDwCwccI4aaB0DRFc+ihD3biZbeaxAlZLNAzVJfL1kpC5iJ Nw8JkDk6rP4caDwnxSQ1QINzD9KbfFV2Yb1YhsENZFiCKtqy9lEoCiQ== X-Received: by 2002:a05:6870:b520:b0:11d:5228:d87c with SMTP id v32-20020a056870b52000b0011d5228d87cmr1060042oap.13.1661109892495; Sun, 21 Aug 2022 12:24:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR6IFHURuMUYjw4ogcBGRR/mv8mWydAX1s9aq252QsIcFyJ8IBYbSALttVvvLOaOmpZsTiiLe1rRBwoNrAfWJsI= X-Received: by 2002:a05:6870:b520:b0:11d:5228:d87c with SMTP id v32-20020a056870b52000b0011d5228d87cmr1060037oap.13.1661109892257; Sun, 21 Aug 2022 12:24:52 -0700 (PDT) MIME-Version: 1.0 References: <20220821104446.46521-1-michael.hudson@canonical.com> In-Reply-To: <20220821104446.46521-1-michael.hudson@canonical.com> From: Michael Hudson-Doyle Date: Mon, 22 Aug 2022 07:24:41 +1200 Message-ID: Subject: Re: [PATCH] Avoid undefined behaviour in ibm128 implementation of llroundl To: libc-alpha@sourceware.org X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HTML_MESSAGE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Aug 2022 19:24:57 -0000 Disregard this, I hadn't run all the tests I thought I had, sorry about that. On Sun, 21 Aug 2022 at 22:45, Michael Hudson-Doyle < michael.hudson@canonical.com> wrote: > Detecting an overflow edge case depended on signed overflow of a long > long. Replace the signed long long with unsigned and cast it back to > unsigned before comparisons (which is implementation defined behaviour, > but I guess glibc does not support any one's complement > architectures...). > > BZ #29488 > --- > sysdeps/ieee754/ldbl-128ibm/s_llroundl.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/sysdeps/ieee754/ldbl-128ibm/s_llroundl.c > b/sysdeps/ieee754/ldbl-128ibm/s_llroundl.c > index d85154e73a..e8117bfc2b 100644 > --- a/sysdeps/ieee754/ldbl-128ibm/s_llroundl.c > +++ b/sysdeps/ieee754/ldbl-128ibm/s_llroundl.c > @@ -28,7 +28,8 @@ long long > __llroundl (long double x) > { > double xh, xl; > - long long res, hi, lo; > + unsigned long long res; > + long long hi, lo; > > ldbl_unpack (x, &xh, &xl); > > @@ -69,7 +70,7 @@ __llroundl (long double x) > res = hi + lo; > > /* This is just sign(hi) == sign(lo) && sign(res) != sign(hi). */ > - if (__glibc_unlikely (((~(hi ^ lo) & (res ^ hi)) < 0))) > + if (__glibc_unlikely (((~(hi ^ lo) & (((long long)res) ^ hi)) < 0))) > goto overflow; > > xh -= lo; > @@ -95,7 +96,7 @@ __llroundl (long double x) > res -= 1; > } > > - if (__glibc_unlikely (((~(hi ^ (res - hi)) & (res ^ hi)) < 0))) > + if (__glibc_unlikely (((~(hi ^ (((long long)res) - hi)) & (((long > long)res) ^ hi)) < 0))) > goto overflow; > > return res; > -- > 2.34.1 > >