This is the mail archive of the glibc-cvs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[glibc] math: Replace const attribute with pure in totalorder* functions


https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=ab41100bab128fa98258aafbb0ab1622884cec4c

commit ab41100bab128fa98258aafbb0ab1622884cec4c
Author: Gabriel F. T. Gomes <gabrielftg@linux.ibm.com>
Date:   Wed Sep 4 13:36:23 2019 -0300

    math: Replace const attribute with pure in totalorder* functions
    
    Since the commit
    
    commit 42760d764649ad82f5fe45a26cbdf2c2500409f7
    Author: Joseph Myers <joseph@codesourcery.com>
    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.

Diff:
---
 ChangeLog             | 5 +++++
 math/bits/mathcalls.h | 7 ++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 68aa879..8fb6171 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2019-09-05  Gabriel F. T. Gomes  <gabrielftg@linux.ibm.com>
+
+	* math/bits/mathcalls.h (totalorder, totalordermag): Replace
+	const attribute with pure attribute.
+
 2019-09-04  Lukasz Majewski <lukma@denx.de>
 
 	* sysdeps/unix/sysv/linux/kernel-features.h
diff --git a/math/bits/mathcalls.h b/math/bits/mathcalls.h
index 66832c7..94690c3 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));


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]