Patches to fix a few Clang warnings

Hans Wennborg hwennborg at google.com
Wed Nov 12 02:42:39 UTC 2014


Hello,

I compiled GMP with Clang on x86_64 Linux the other day and saw a few
warnings. Most of them seem benign, but I figured I might as well send
patches for the few things I noticed:

assert_fix.diff - This looks like it could be a bug, but I don't know
the code well enough to tell.

parenthesis.diff - This is benign, but silences the warning.

printf_fix.diff - I guess this is a matter of taste, but I find using
the ternary operator a little more clear.

Thanks,
Hans
-------------- next part --------------
# HG changeset patch
# User Hans Wennborg <hwennborg at google.com>
# Date 1415759488 28800
#      Tue Nov 11 18:31:28 2014 -0800
# Node ID a19bec2ed434f1370f4d2dbd243a9dc49e9c35df
# Parent  a09d9fc0a987286c1d61c5c8f94cff3c03156b71
Fix operator precedence in ASSERT

Clang was warning about | having lower precedence than ==.

diff -r a09d9fc0a987 -r a19bec2ed434 mpn/generic/toom_interpolate_8pts.c
--- a/mpn/generic/toom_interpolate_8pts.c	Tue Nov 11 18:17:19 2014 -0800
+++ b/mpn/generic/toom_interpolate_8pts.c	Tue Nov 11 18:31:28 2014 -0800
@@ -208,5 +208,5 @@
   if (LIKELY(spt != n))
     MPN_INCR_U (pp + 8*n, spt - n, cy + r3[3*n]);
   else
-    ASSERT (r3[3*n] | cy == 0);
+    ASSERT ((r3[3*n] | cy) == 0);
 }
-------------- next part --------------
# HG changeset patch
# User Hans Wennborg <hwennborg at google.com>
# Date 1415759614 28800
#      Tue Nov 11 18:33:34 2014 -0800
# Node ID f8dffbab350b61f2dbb9f085b6f1946a4b1b53f4
# Parent  a19bec2ed434f1370f4d2dbd243a9dc49e9c35df
Insert parentheses around & expressions within | expressions.

This silences a Clang warning.

diff -r a19bec2ed434 -r f8dffbab350b mpn/generic/div_qr_2.c
--- a/mpn/generic/div_qr_2.c	Tue Nov 11 18:31:28 2014 -0800
+++ b/mpn/generic/div_qr_2.c	Tue Nov 11 18:33:34 2014 -0800
@@ -152,7 +152,7 @@
 									\
     sub_ddmmss (r1, r0, n1, n0, _t1, _t0);				\
 									\
-    _mask = -(mp_limb_t) (r1 >= _q1 & (r1 > _q1 | r0 >= _q0));  /* (r1,r0) >= (q1,q0) */  \
+    _mask = -(mp_limb_t) ((r1 >= _q1) & (r1 > _q1 | r0 >= _q0));  /* (r1,r0) >= (q1,q0) */  \
     add_ssaaaa (r1, r0, r1, r0, d1 & _mask, d0 & _mask);		\
     sub_ddmmss (_q3, _q2, _q3, _q2, CNST_LIMB(0), -_mask);		\
 									\
diff -r a19bec2ed434 -r f8dffbab350b mpn/generic/toom44_mul.c
--- a/mpn/generic/toom44_mul.c	Tue Nov 11 18:31:28 2014 -0800
+++ b/mpn/generic/toom44_mul.c	Tue Nov 11 18:33:34 2014 -0800
@@ -217,9 +217,9 @@
   TOOM44_MUL_N_REC (vh, apx, bpx, n + 1, tp);	/* vh,  2n+1 limbs */
 
   /* Compute apx = a0 + a1 + a2 + a3 and amx = a0 - a1 + a2 - a3.  */
-  flags = (enum toom7_flags) (flags | toom7_w3_neg & mpn_toom_eval_dgr3_pm1 (apx, amx, ap, n, s, tp));
+  flags = (enum toom7_flags) (flags | (toom7_w3_neg & mpn_toom_eval_dgr3_pm1 (apx, amx, ap, n, s, tp)));
 
-  /* Compute bpx = b0 + b1 + b2 + b3 bnd bmx = b0 - b1 + b2 - b3.  */
+  /* Compute bpx = b0 + b1 + b2 + b3 and bmx = b0 - b1 + b2 - b3.  */
   flags = (enum toom7_flags) (flags ^ toom7_w3_neg & mpn_toom_eval_dgr3_pm1 (bpx, bmx, bp, n, t, tp));
 
   TOOM44_MUL_N_REC (vm1, amx, bmx, n + 1, tp);	/* vm1,  2n+1 limbs */
diff -r a19bec2ed434 -r f8dffbab350b mpn/generic/toom53_mul.c
--- a/mpn/generic/toom53_mul.c	Tue Nov 11 18:31:28 2014 -0800
+++ b/mpn/generic/toom53_mul.c	Tue Nov 11 18:33:34 2014 -0800
@@ -111,7 +111,7 @@
   flags = (enum toom7_flags) (toom7_w3_neg & mpn_toom_eval_pm1 (as1, asm1, 4, ap, n, s, gp));
 
   /* Compute as2 and asm2. */
-  flags = (enum toom7_flags) (flags | toom7_w1_neg & mpn_toom_eval_pm2 (as2, asm2, 4, ap, n, s, gp));
+  flags = (enum toom7_flags) (flags | (toom7_w1_neg & mpn_toom_eval_pm2 (as2, asm2, 4, ap, n, s, gp)));
 
   /* Compute ash = 16 a0 + 8 a1 + 4 a2 + 2 a3 + a4
      = 2*(2*(2*(2*a0 + a1) + a2) + a3) + a4  */
diff -r a19bec2ed434 -r f8dffbab350b mpn/generic/toom62_mul.c
--- a/mpn/generic/toom62_mul.c	Tue Nov 11 18:31:28 2014 -0800
+++ b/mpn/generic/toom62_mul.c	Tue Nov 11 18:33:34 2014 -0800
@@ -111,7 +111,7 @@
   aflags = (enum toom7_flags) (toom7_w3_neg & mpn_toom_eval_pm1 (as1, asm1, 5, ap, n, s, gp));
 
   /* Compute as2 and asm2. */
-  aflags = (enum toom7_flags) (aflags | toom7_w1_neg & mpn_toom_eval_pm2 (as2, asm2, 5, ap, n, s, gp));
+  aflags = (enum toom7_flags) (aflags | (toom7_w1_neg & mpn_toom_eval_pm2 (as2, asm2, 5, ap, n, s, gp)));
 
   /* Compute ash = 32 a0 + 16 a1 + 8 a2 + 4 a3 + 2 a4 + a5
      = 2*(2*(2*(2*(2*a0 + a1) + a2) + a3) + a4) + a5  */
-------------- next part --------------
# HG changeset patch
# User Hans Wennborg <hwennborg at google.com>
# Date 1415758639 28800
#      Tue Nov 11 18:17:19 2014 -0800
# Node ID a09d9fc0a987286c1d61c5c8f94cff3c03156b71
# Parent  b7561e428ff18d410c4a5a9a6c78dbb1634d20b7
Simplify conditional printing of whitespace.

Clang was warning about passing a non-const format string to printf.
Using the ternary operator seems like a more explicit way of selecting
between printing a space or not.

diff -r b7561e428ff1 -r a09d9fc0a987 tests/mpn/t-bdiv.c
--- a/tests/mpn/t-bdiv.c	Mon Nov 10 00:55:28 2014 +0100
+++ b/tests/mpn/t-bdiv.c	Tue Nov 11 18:17:19 2014 -0800
@@ -40,7 +40,7 @@
       for (i = 3; i >= 0; i--)
 	{
 	  printf ("%0*lx", (int) (2 * sizeof (mp_limb_t)), p[i]);
-	  printf (" " + (i == 0));
+	  printf (i == 0 ? "" : " ");
 	}
     }
   else
@@ -48,7 +48,7 @@
       for (i = n - 1; i >= 0; i--)
 	{
 	  printf ("%0*lx", (int) (2 * sizeof (mp_limb_t)), p[i]);
-	  printf (" " + (i == 0));
+	  printf (i == 0 ? "" : " ");
 	}
     }
   puts ("");
diff -r b7561e428ff1 -r a09d9fc0a987 tests/mpn/t-div.c
--- a/tests/mpn/t-div.c	Mon Nov 10 00:55:28 2014 +0100
+++ b/tests/mpn/t-div.c	Tue Nov 11 18:17:19 2014 -0800
@@ -40,7 +40,7 @@
       for (i = 3; i >= 0; i--)
 	{
 	  printf ("%0*lx", (int) (2 * sizeof (mp_limb_t)), p[i]);
-	  printf (" " + (i == 0));
+	  printf (i == 0 ? "" : " ");
 	}
     }
   else
@@ -48,7 +48,7 @@
       for (i = n - 1; i >= 0; i--)
 	{
 	  printf ("%0*lx", (int) (2 * sizeof (mp_limb_t)), p[i]);
-	  printf (" " + (i == 0));
+	  printf (i == 0 ? "" : " ");
 	}
     }
   puts ("");


More information about the gmp-devel mailing list