]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix tgmath.h totalorder, totalordermag return type (bug 21687).
authorJoseph Myers <joseph@codesourcery.com>
Wed, 28 Jun 2017 16:31:10 +0000 (16:31 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Wed, 28 Jun 2017 16:31:10 +0000 (16:31 +0000)
The tgmath.h totalorder and totalordermag macros wrongly return a
floating-point type.  They should return int, like the underlying
functions.  This patch fixes them accordingly, updating tests
including enabling tests of those functions from gen-tgmath-tests.py.

Tested for x86_64.

[BZ #21687]
* math/tgmath.h (__TGMATH_BINARY_REAL_RET_ONLY): New macro.
(totalorder): Use it.
(totalordermag): Likewise.
* math/gen-tgmath-tests.py (Tests.add_all_tests): Enable tests of
totalorder and totalordermag.
* math/test-tgmath.c (F(compile_test)): Do not call totalorder or
totalordermag in arguments of calls to those functions.
(NCALLS): Change to 134.

ChangeLog
math/gen-tgmath-tests.py
math/test-tgmath.c
math/tgmath.h

index a19836348084b0d54166336b1cb745c79ec0a431..1d11b9c23f5252040a49c3062cb4d661b634d565 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2017-06-28  Joseph Myers  <joseph@codesourcery.com>
 
+       [BZ #21687]
+       * math/tgmath.h (__TGMATH_BINARY_REAL_RET_ONLY): New macro.
+       (totalorder): Use it.
+       (totalordermag): Likewise.
+       * math/gen-tgmath-tests.py (Tests.add_all_tests): Enable tests of
+       totalorder and totalordermag.
+       * math/test-tgmath.c (F(compile_test)): Do not call totalorder or
+       totalordermag in arguments of calls to those functions.
+       (NCALLS): Change to 134.
+
        * math/tgmath.h (__TGMATH_UNARY_REAL_RET_ONLY): Do not take or
        cast to return type argument.
        (__TGMATH_TERNARY_FIRST_REAL_RET_ONLY): Likewise.
index 3dbd8745c52a574cd034ef1ea9fc0c4477b5d462..db6553e8dcbeea3d34ffc0e1181fd63e177316c7 100755 (executable)
@@ -549,8 +549,8 @@ class Tests(object):
         self.add_tests('fromfpx', 'intmax_t', ['r', 'int', 'unsigned int'])
         self.add_tests('ufromfp', 'uintmax_t', ['r', 'int', 'unsigned int'])
         self.add_tests('ufromfpx', 'uintmax_t', ['r', 'int', 'unsigned int'])
-        #self.add_tests('totalorder', 'int', ['r', 'r'])
-        #self.add_tests('totalordermag', 'int', ['r', 'r'])
+        self.add_tests('totalorder', 'int', ['r', 'r'])
+        self.add_tests('totalordermag', 'int', ['r', 'r'])
         # The functions that round their result to a narrower type,
         # and the associated type-generic macros, are not yet
         # supported by this script or by glibc.
index dc24cd64f5c0c1ea7e8b5e0ef947446b125ee7f5..0f3e2e535edd169a5614fc8293f2ec675eeea106 100644 (file)
@@ -52,7 +52,7 @@ int count_cdouble;
 int count_cfloat;
 int count_cldouble;
 
-#define NCALLS     138
+#define NCALLS     134
 #define NCALLS_INT 4
 #define NCCALLS    47
 
@@ -295,8 +295,8 @@ F(compile_test) (void)
   b = fmaxmag (fmaxmag (a, x), fmaxmag (c, b));
   a = fminmag (fminmag (x, a), fminmag (c, b));
   b = fma (sin (a), sin (x), sin (c));
-  a = totalorder (totalorder (x, b), totalorder (c, x));
-  b = totalordermag (totalordermag (x, a), totalordermag (c, x));
+  a = totalorder (x, b);
+  b = totalordermag (x, a);
 
 #ifdef TEST_INT
   a = atan2 (i, b);
index a70dfe1f472f9899cbeb703c565cf6eb32968d7a..a0da1041422bb9c03b34f82083d504b970a03aee 100644 (file)
                                   + (__tgmath_real_type (Val2)) 0))          \
                       Fct##f (Val1, Val2)))
 
+# define __TGMATH_BINARY_REAL_RET_ONLY(Val1, Val2, Fct) \
+     (__extension__ (((sizeof (Val1) > sizeof (double)                       \
+                      || sizeof (Val2) > sizeof (double))                    \
+                     && __builtin_classify_type ((Val1) + (Val2)) == 8)      \
+                    ? __tgml(Fct) (Val1, Val2)                               \
+                    : (sizeof (Val1) == sizeof (double)                      \
+                       || sizeof (Val2) == sizeof (double)                   \
+                       || __builtin_classify_type (Val1) != 8                \
+                       || __builtin_classify_type (Val2) != 8)               \
+                    ? Fct (Val1, Val2)                                       \
+                    : Fct##f (Val1, Val2)))
+
 # define __TGMATH_TERNARY_FIRST_SECOND_REAL_ONLY(Val1, Val2, Val3, Fct) \
      (__extension__ (((sizeof (Val1) > sizeof (double)                       \
                       || sizeof (Val2) > sizeof (double))                    \
 # define fminmag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, fminmag)
 
 /* Total order operation.  */
-# define totalorder(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, \
-                                                          totalorder)
+# define totalorder(Val1, Val2)                                        \
+  __TGMATH_BINARY_REAL_RET_ONLY (Val1, Val2, totalorder)
 
 /* Total order operation on absolute values.  */
-# define totalordermag(Val1, Val2) __TGMATH_BINARY_REAL_ONLY (Val1, Val2, \
-                                                             totalordermag)
+# define totalordermag(Val1, Val2)                             \
+  __TGMATH_BINARY_REAL_RET_ONLY (Val1, Val2, totalordermag)
 #endif