From a9e2788ffe8f45c190ad442dda2e83e719cfb14f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Tue, 25 Jan 2022 02:05:42 +0100 Subject: [PATCH] libspl: cast to uintptr_t instead of !!ing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This led to these two warning types: debug.h:139:67: warning: the address of ‘ARC_anon’ will always evaluate as ‘true’ [-Waddress] 139 | #define ASSERT3P(x, y, z) ((void) sizeof (!!(x)), (void) sizeof (!!(z))) | ^ arc.c:1591:2: note: in expansion of macro ‘ASSERT3P’ 1591 | ASSERT3P(hdr->b_l1hdr.b_state, ==, arc_anon); | ^~~~~~~~ and arc.h:66:44: warning: ‘<<’ in boolean context, did you mean ‘<’? [-Wint-in-bool-context] 66 | #define HDR_GET_LSIZE(hdr) ((hdr)->b_lsize << SPA_MINBLOCKSHIFT) debug.h:138:46: note: in definition of macro ‘ASSERT3U’ 138 | #define ASSERT3U(x, y, z) ((void) sizeof (!!(x)), (void) sizeof (!!(z))) | ^ arc.c:1760:12: note: in expansion of macro ‘HDR_GET_LSIZE’ 1760 | ASSERT3U(HDR_GET_LSIZE(hdr), !=, 0); | ^~~~~~~~~~~~~ Reviewed-by: Brian Behlendorf Signed-off-by: Ahelenia Ziemiańska Closes #13009 --- include/os/freebsd/spl/sys/debug.h | 22 ++++++++++++++-------- include/os/linux/spl/sys/debug.h | 22 ++++++++++++++-------- lib/libspl/include/assert.h | 24 +++++++++++++++--------- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/include/os/freebsd/spl/sys/debug.h b/include/os/freebsd/spl/sys/debug.h index 6df76db7ea..c3d7a6e83f 100644 --- a/include/os/freebsd/spl/sys/debug.h +++ b/include/os/freebsd/spl/sys/debug.h @@ -133,14 +133,20 @@ void spl_dumpstack(void); */ #ifdef NDEBUG -#define ASSERT(x) ((void) sizeof (!!(x))) -#define ASSERT3B(x,y,z) ((void) sizeof (!!(x)), (void) sizeof (!!(z))) -#define ASSERT3S(x,y,z) ((void) sizeof (!!(x)), (void) sizeof (!!(z))) -#define ASSERT3U(x,y,z) ((void) sizeof (!!(x)), (void) sizeof (!!(z))) -#define ASSERT3P(x,y,z) ((void) sizeof (!!(x)), (void) sizeof (!!(z))) -#define ASSERT0(x) ((void) sizeof (!!(x))) -#define IMPLY(A, B) ((void) sizeof (!!(A)), (void) sizeof (!!(B))) -#define EQUIV(A, B) ((void) sizeof (!!(A)), (void) sizeof (!!(B))) +#define ASSERT(x) ((void) sizeof ((uintptr_t)(x))) +#define ASSERT3B(x, y, z) \ + ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z))) +#define ASSERT3S(x, y, z) \ + ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z))) +#define ASSERT3U(x, y, z) \ + ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z))) +#define ASSERT3P(x, y, z) \ + ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z))) +#define ASSERT0(x) ((void) sizeof ((uintptr_t)(x))) +#define IMPLY(A, B) \ + ((void) sizeof ((uintptr_t)(A)), (void) sizeof ((uintptr_t)(B))) +#define EQUIV(A, B) \ + ((void) sizeof ((uintptr_t)(A)), (void) sizeof ((uintptr_t)(B))) /* * Debugging enabled (--enable-debug) diff --git a/include/os/linux/spl/sys/debug.h b/include/os/linux/spl/sys/debug.h index 102fc640bf..e0ae7e2d6b 100644 --- a/include/os/linux/spl/sys/debug.h +++ b/include/os/linux/spl/sys/debug.h @@ -133,14 +133,20 @@ void spl_dumpstack(void); */ #ifdef NDEBUG -#define ASSERT(x) ((void) sizeof (!!(x))) -#define ASSERT3B(x,y,z) ((void) sizeof (!!(x)), (void) sizeof (!!(z))) -#define ASSERT3S(x,y,z) ((void) sizeof (!!(x)), (void) sizeof (!!(z))) -#define ASSERT3U(x,y,z) ((void) sizeof (!!(x)), (void) sizeof (!!(z))) -#define ASSERT3P(x,y,z) ((void) sizeof (!!(x)), (void) sizeof (!!(z))) -#define ASSERT0(x) ((void) sizeof (!!(x))) -#define IMPLY(A, B) ((void) sizeof (!!(A)), (void) sizeof (!!(B))) -#define EQUIV(A, B) ((void) sizeof (!!(A)), (void) sizeof (!!(B))) +#define ASSERT(x) ((void) sizeof ((uintptr_t)(x))) +#define ASSERT3B(x, y, z) \ + ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z))) +#define ASSERT3S(x, y, z) \ + ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z))) +#define ASSERT3U(x, y, z) \ + ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z))) +#define ASSERT3P(x, y, z) \ + ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z))) +#define ASSERT0(x) ((void) sizeof ((uintptr_t)(x))) +#define IMPLY(A, B) \ + ((void) sizeof ((uintptr_t)(A)), (void) sizeof ((uintptr_t)(B))) +#define EQUIV(A, B) \ + ((void) sizeof ((uintptr_t)(A)), (void) sizeof ((uintptr_t)(B))) /* * Debugging enabled (--enable-debug) diff --git a/lib/libspl/include/assert.h b/lib/libspl/include/assert.h index fadff14cce..e129ef7df9 100644 --- a/lib/libspl/include/assert.h +++ b/lib/libspl/include/assert.h @@ -120,15 +120,21 @@ do { \ __compile_time_assertion__ ## y[(x) ? 1 : -1] #ifdef NDEBUG -#define ASSERT3B(x, y, z) ((void) sizeof (!!(x)), (void) sizeof (!!(z))) -#define ASSERT3S(x, y, z) ((void) sizeof (!!(x)), (void) sizeof (!!(z))) -#define ASSERT3U(x, y, z) ((void) sizeof (!!(x)), (void) sizeof (!!(z))) -#define ASSERT3P(x, y, z) ((void) sizeof (!!(x)), (void) sizeof (!!(z))) -#define ASSERT0(x) ((void) sizeof (!!(x))) -#define ASSERT(x) ((void) sizeof (!!(x))) -#define assert(x) ((void) sizeof (!!(x))) -#define IMPLY(A, B) ((void) sizeof (!!(A)), (void) sizeof (!!(B))) -#define EQUIV(A, B) ((void) sizeof (!!(A)), (void) sizeof (!!(B))) +#define ASSERT3B(x, y, z) \ + ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z))) +#define ASSERT3S(x, y, z) \ + ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z))) +#define ASSERT3U(x, y, z) \ + ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z))) +#define ASSERT3P(x, y, z) \ + ((void) sizeof ((uintptr_t)(x)), (void) sizeof ((uintptr_t)(z))) +#define ASSERT0(x) ((void) sizeof ((uintptr_t)(x))) +#define ASSERT(x) ((void) sizeof ((uintptr_t)(x))) +#define assert(x) ((void) sizeof ((uintptr_t)(x))) +#define IMPLY(A, B) \ + ((void) sizeof ((uintptr_t)(A)), (void) sizeof ((uintptr_t)(B))) +#define EQUIV(A, B) \ + ((void) sizeof ((uintptr_t)(A)), (void) sizeof ((uintptr_t)(B))) #else #define ASSERT3B VERIFY3B #define ASSERT3S VERIFY3S