Mattias Engdegård reported that the Emacs master source currently generates the following warning when Emacs is built with mini-gmp.c under Clang 13:

In file included from /Users/mattias/emacs/lib/mini-gmp-gnulib.c:47:
/Users/mattias/emacs/lib/mini-gmp.c:1138:2: warning: unused variable '__cy' 
[-Wunused-variable]
        gmp_assert_nocarry (mpn_rshift (np, np, dn, shift));
        ^
/Users/mattias/emacs/lib/mini-gmp.c:91:15: note: expanded from macro 
'gmp_assert_nocarry'
    mp_limb_t __cy = (x);          \

The problem occurs because assert(X) does not evaluate X when NDEBUG is defined. Proposed patch attached.

Another advantage of this patch is that any messages generated by assertion failures are more informative.
diff -r d45103d658ca mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Wed Mar 30 23:16:18 2022 +0200
+++ b/mini-gmp/mini-gmp.c	Fri Apr 08 16:18:06 2022 -0700
@@ -87,10 +87,11 @@
 #define GMP_MPN_OVERLAP_P(xp, xsize, yp, ysize)				\
   ((xp) + (xsize) > (yp) && (yp) + (ysize) > (xp))
 
-#define gmp_assert_nocarry(x) do { \
-    mp_limb_t __cy = (x);	   \
-    assert (__cy == 0);		   \
-  } while (0)
+#ifdef NDEBUG
+# define gmp_assert_nocarry(x) ((void) (x))
+#else
+# define gmp_assert_nocarry(x) assert ((x) == 0)
+#endif
 
 #define gmp_clz(count, x) do {						\
     mp_limb_t __clz_x = (x);						\
_______________________________________________
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs

Reply via email to