Fix warnings from latest GCC

Message ID 201610102216.u9AMGhpL024615@sellcey-thinkpad.caveonetworks.com
State New
Headers show

Commit Message

Steve Ellcey Oct. 10, 2016, 10:16 p.m.
I was building the top-of-tree glibc with the top-of-tree GCC and ran into
some new GCC errors.

../sysdeps/ieee754/dbl-64/e_pow.c: In function ‘checkint’:
../sysdeps/ieee754/dbl-64/e_pow.c:469:13: error: << in boolean context, did you mean '<' ? [-Werror=int-in-bool-context]
       if (n << (k - 20))
           ~~^~~~~~~~~~~
../sysdeps/ieee754/dbl-64/e_pow.c:471:17: error: << in boolean context, did you mean '<' ? [-Werror=int-in-bool-context]
       return (n << (k - 21)) ? -1 : 1;
              ~~~^~~~~~~~~~~~
../sysdeps/ieee754/dbl-64/e_pow.c:477:9: error: << in boolean context, did you mean '<' ? [-Werror=int-in-bool-context]
   if (m << (k + 12))
       ~~^~~~~~~~~~~
../sysdeps/ieee754/dbl-64/e_pow.c:479:13: error: << in boolean context, did you mean '<' ? [-Werror=int-in-bool-context]
   return (m << (k + 11)) ? -1 : 1;
          ~~~^~~~~~~~~~~~
cc1: all warnings being treated as errors

The easiest fix seems to be to add explicit '!= 0' to these lines.  I did this
and verified that the generated code (on aarch64) is identical.  

OK to checkin?

Steve Ellcey
sellcey@caviumnetworks.com (previously sellcey@imgtec.com)


	* e_pow.c (checkint) Make conditions explicitly boolean.

Comments

Joseph Myers Oct. 10, 2016, 10:25 p.m. | #1
On Mon, 10 Oct 2016, Steve Ellcey wrote:

> The easiest fix seems to be to add explicit '!= 0' to these lines.  I did this
> and verified that the generated code (on aarch64) is identical.  
> 
> OK to checkin?

OK (this accords with the glibc rule that such implicit boolean 
conversions should be avoided).

Patch

diff --git a/sysdeps/ieee754/dbl-64/e_pow.c b/sysdeps/ieee754/dbl-64/e_pow.c
index 663fa39..bd758b5 100644
--- a/sysdeps/ieee754/dbl-64/e_pow.c
+++ b/sysdeps/ieee754/dbl-64/e_pow.c
@@ -466,15 +466,15 @@  checkint (double x)
     return (n & 1) ? -1 : 1;	/* odd or even */
   if (k > 20)
     {
-      if (n << (k - 20))
+      if (n << (k - 20) != 0)
 	return 0;		/* if not integer */
-      return (n << (k - 21)) ? -1 : 1;
+      return (n << (k - 21) != 0) ? -1 : 1;
     }
   if (n)
     return 0;			/*if  not integer */
   if (k == 20)
     return (m & 1) ? -1 : 1;
-  if (m << (k + 12))
+  if (m << (k + 12) != 0)
     return 0;
-  return (m << (k + 11)) ? -1 : 1;
+  return (m << (k + 11) != 0) ? -1 : 1;
 }