From patchwork Thu Sep 5 15:01:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Gabriel F. T. Gomes" X-Patchwork-Id: 34394 Received: (qmail 85390 invoked by alias); 5 Sep 2019 15:01:29 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 85272 invoked by uid 89); 5 Sep 2019 15:01:28 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=pure X-HELO: smtpout1.mo528.mail-out.ovh.net Date: Thu, 5 Sep 2019 12:01:11 -0300 From: "Gabriel F. T. Gomes" To: Joseph Myers CC: Subject: Re: [PATCH] math: Remove const attribute from totalorder* functions Message-ID: <20190905120111.033fe60c@tereshkova> In-Reply-To: References: <20190904172219.15244-1-gabriel@inconstante.net.br> MIME-Version: 1.0 X-Ovh-Tracer-Id: 2540030193167093485 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduvddrudejjedgjeejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm Hi, Joseph, On Wed, 04 Sep 2019, Joseph Myers wrote: >This is OK, but it would be better to replace it with __attribute_pure__ >(the patch with that replacement is also OK, if it works). Good point! I made this change, tested and pushed the following patch. Thanks! Gabriel From ab41100bab128fa98258aafbb0ab1622884cec4c Mon Sep 17 00:00:00 2001 From: "Gabriel F. T. Gomes" Date: Wed, 4 Sep 2019 13:36:23 -0300 Subject: [PATCH] math: Replace const attribute with pure in totalorder* functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the commit commit 42760d764649ad82f5fe45a26cbdf2c2500409f7 Author: Joseph Myers Date: Thu Aug 15 15:18:34 2019 +0000 Make totalorder and totalordermag functions take pointer arguments. the test case math/test-totalorderl-ldbl-128ibm fails on every input pair, when compiled with -O2, which is the case for glibc test suite. Debugging showed that the test case is passing arguments incorrectly to totalorderl. This can also be inferred by the fact that compiling the test case with -O0 hides the bug. The documentation for the const attribute in GCC manual reads: Note that a function that has pointer arguments and examines the data pointed to must not be declared const if the pointed-to data might change between successive invocations of the function. In general, since a function cannot distinguish data that might change from data that cannot, const functions should never take pointer or, in C++, reference arguments. Likewise, a function that calls a non-const function usually must not be const itself. Since the pointed-to data is likely to be changed by user code between invocations of totalorder*, this patch removes the const attribute from the declarations of all totalorder functions, replacing it with the pure attribute, as suggested in the manual: The pure attribute imposes similar but looser restrictions on a function’s definition than the const attribute: pure allows the function to read any non-volatile memory, even if it changes in between successive invocations of the function. Tested for powerpc64le and x86_64. --- ChangeLog | 5 +++++ math/bits/mathcalls.h | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 68aa879048..8fb6171ce5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2019-09-05 Gabriel F. T. Gomes + + * math/bits/mathcalls.h (totalorder, totalordermag): Replace + const attribute with pure attribute. + 2019-09-04 Lukasz Majewski * sysdeps/unix/sysv/linux/kernel-features.h diff --git a/math/bits/mathcalls.h b/math/bits/mathcalls.h index 66832c7827..94690c3b42 100644 --- a/math/bits/mathcalls.h +++ b/math/bits/mathcalls.h @@ -373,13 +373,14 @@ __MATHDECL_1 (int, canonicalize,, (_Mdouble_ *__cx, const _Mdouble_ *__x)); #if __GLIBC_USE (IEC_60559_BFP_EXT) || __MATH_DECLARING_FLOATN /* Total order operation. */ -__MATHDECL_1 (int, totalorder,, (const _Mdouble_ *__x, const _Mdouble_ *__y)) - __attribute__ ((__const__)); +__MATHDECL_1 (int, totalorder,, (const _Mdouble_ *__x, + const _Mdouble_ *__y)) + __attribute__ ((__pure__)); /* Total order operation on absolute values. */ __MATHDECL_1 (int, totalordermag,, (const _Mdouble_ *__x, const _Mdouble_ *__y)) - __attribute__ ((__const__)); + __attribute__ ((__pure__)); /* Get NaN payload. */ __MATHCALL (getpayload,, (const _Mdouble_ *__x));