Cleanup VERIFY() macros (#17163)

- Fix VERIFY3B() when given non-boolean values.
 - Map EQUIV() into VERIFY3B(,==,) as equivalent.
 - Tune messages for better readability and to closer match source
code for easier search.  Unify user-space messages with kernel.
 - Tune printed types and remove %px outside of Linux kernel.

Signed-off-by:	Alexander Motin <mav@FreeBSD.org>
Sponsored by:	iXsystems, Inc.
Reviewed-by: @ImAwsumm
Reviewed-by: Rob Norris <robn@despairlabs.com>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
This commit is contained in:
Alexander Motin
2025-04-16 12:01:32 -04:00
committed by GitHub
parent 131df3bbf2
commit 4866c2fabf
3 changed files with 89 additions and 114 deletions
+29 -42
View File
@@ -112,14 +112,13 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
} while (0)
#define VERIFY3B(LEFT, OP, RIGHT) do { \
const boolean_t _verify3_left = (boolean_t)(LEFT); \
const boolean_t _verify3_right = (boolean_t)(RIGHT); \
const boolean_t _verify3_left = (boolean_t)!!(LEFT); \
const boolean_t _verify3_right = (boolean_t)!!(RIGHT); \
if (unlikely(!(_verify3_left OP _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
"VERIFY3B(" #LEFT ", " #OP ", " #RIGHT ") " \
"failed (%d " #OP " %d)\n", \
(boolean_t)_verify3_left, \
(boolean_t)_verify3_right); \
_verify3_left, _verify3_right); \
} while (0)
#define VERIFY3S(LEFT, OP, RIGHT) do { \
@@ -127,7 +126,7 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
const int64_t _verify3_right = (int64_t)(RIGHT); \
if (unlikely(!(_verify3_left OP _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
"VERIFY3S(" #LEFT ", " #OP ", " #RIGHT ") " \
"failed (%lld " #OP " %lld)\n", \
(long long)_verify3_left, \
(long long)_verify3_right); \
@@ -138,7 +137,7 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
const uint64_t _verify3_right = (uint64_t)(RIGHT); \
if (unlikely(!(_verify3_left OP _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
"VERIFY3U(" #LEFT ", " #OP ", " #RIGHT ") " \
"failed (%llu " #OP " %llu)\n", \
(unsigned long long)_verify3_left, \
(unsigned long long)_verify3_right); \
@@ -149,8 +148,8 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
const uintptr_t _verify3_right = (uintptr_t)(RIGHT); \
if (unlikely(!(_verify3_left OP _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
"failed (%px " #OP " %px)\n", \
"VERIFY3P(" #LEFT ", " #OP ", " #RIGHT ") " \
"failed (%p " #OP " %p)\n", \
(void *)_verify3_left, \
(void *)_verify3_right); \
} while (0)
@@ -159,8 +158,7 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
const int64_t _verify0_right = (int64_t)(RIGHT); \
if (unlikely(!(0 == _verify0_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY0(" #RIGHT ") " \
"failed (0 == %lld)\n", \
"VERIFY0(" #RIGHT ") failed (%lld)\n", \
(long long)_verify0_right); \
} while (0)
@@ -168,8 +166,7 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
const uintptr_t _verify0_right = (uintptr_t)(RIGHT); \
if (unlikely(!(0 == _verify0_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY0P(" #RIGHT ") " \
"failed (NULL == %px)\n", \
"VERIFY0P(" #RIGHT ") failed (%p)\n", \
(void *)_verify0_right); \
} while (0)
@@ -182,14 +179,13 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
*/
#define VERIFY3BF(LEFT, OP, RIGHT, STR, ...) do { \
const boolean_t _verify3_left = (boolean_t)(LEFT); \
const boolean_t _verify3_right = (boolean_t)(RIGHT); \
const boolean_t _verify3_left = (boolean_t)!!(LEFT); \
const boolean_t _verify3_right = (boolean_t)!!(RIGHT); \
if (unlikely(!(_verify3_left OP _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
"VERIFY3B(" #LEFT ", " #OP ", " #RIGHT ") " \
"failed (%d " #OP " %d) " STR "\n", \
(boolean_t)(_verify3_left), \
(boolean_t)(_verify3_right), \
_verify3_left, _verify3_right, \
__VA_ARGS__); \
} while (0)
@@ -198,10 +194,9 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
const int64_t _verify3_right = (int64_t)(RIGHT); \
if (unlikely(!(_verify3_left OP _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
"VERIFY3S(" #LEFT ", " #OP ", " #RIGHT ") " \
"failed (%lld " #OP " %lld) " STR "\n", \
(long long)(_verify3_left), \
(long long)(_verify3_right), \
(long long)_verify3_left, (long long)_verify3_right,\
__VA_ARGS__); \
} while (0)
@@ -210,10 +205,10 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
const uint64_t _verify3_right = (uint64_t)(RIGHT); \
if (unlikely(!(_verify3_left OP _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
"VERIFY3U(" #LEFT ", " #OP ", " #RIGHT ") " \
"failed (%llu " #OP " %llu) " STR "\n", \
(unsigned long long)(_verify3_left), \
(unsigned long long)(_verify3_right), \
(unsigned long long)_verify3_left, \
(unsigned long long)_verify3_right, \
__VA_ARGS__); \
} while (0)
@@ -222,32 +217,27 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
const uintptr_t _verify3_right = (uintptr_t)(RIGHT); \
if (unlikely(!(_verify3_left OP _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
"failed (%px " #OP " %px) " STR "\n", \
(void *) (_verify3_left), \
(void *) (_verify3_right), \
"VERIFY3P(" #LEFT ", " #OP ", " #RIGHT ") " \
"failed (%p " #OP " %p) " STR "\n", \
(void *)_verify3_left, (void *)_verify3_right, \
__VA_ARGS__); \
} while (0)
#define VERIFY0PF(RIGHT, STR, ...) do { \
const uintptr_t _verify3_left = (uintptr_t)(0); \
const uintptr_t _verify3_right = (uintptr_t)(RIGHT); \
if (unlikely(!(_verify3_left == _verify3_right))) \
if (unlikely(!(0 == _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY0(0 == " #RIGHT ") " \
"failed (0 == %px) " STR "\n", \
(long long) (_verify3_right), \
"VERIFY0P(" #RIGHT ") failed (%p) " STR "\n", \
(void *)_verify3_right, \
__VA_ARGS__); \
} while (0)
#define VERIFY0F(RIGHT, STR, ...) do { \
const int64_t _verify3_left = (int64_t)(0); \
const int64_t _verify3_right = (int64_t)(RIGHT); \
if (unlikely(!(_verify3_left == _verify3_right))) \
if (unlikely(!(0 == _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY0(0 == " #RIGHT ") " \
"failed (0 == %lld) " STR "\n", \
(long long) (_verify3_right), \
"VERIFY0(" #RIGHT ") failed (%lld) " STR "\n", \
(long long)_verify3_right, \
__VA_ARGS__); \
} while (0)
@@ -256,10 +246,7 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
spl_assert("(" #A ") implies (" #B ")", \
__FILE__, __FUNCTION__, __LINE__)))
#define VERIFY_EQUIV(A, B) \
((void)(likely(!!(A) == !!(B)) || \
spl_assert("(" #A ") is equivalent to (" #B ")", \
__FILE__, __FUNCTION__, __LINE__)))
#define VERIFY_EQUIV(A, B) VERIFY3B(A, ==, B)
/*
* Debugging disabled (--disable-debug)
+27 -40
View File
@@ -116,14 +116,13 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
} while (0)
#define VERIFY3B(LEFT, OP, RIGHT) do { \
const boolean_t _verify3_left = (boolean_t)(LEFT); \
const boolean_t _verify3_right = (boolean_t)(RIGHT); \
const boolean_t _verify3_left = (boolean_t)!!(LEFT); \
const boolean_t _verify3_right = (boolean_t)!!(RIGHT); \
if (unlikely(!(_verify3_left OP _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
"VERIFY3B(" #LEFT ", " #OP ", " #RIGHT ") " \
"failed (%d " #OP " %d)\n", \
(boolean_t)_verify3_left, \
(boolean_t)_verify3_right); \
_verify3_left, _verify3_right); \
} while (0)
#define VERIFY3S(LEFT, OP, RIGHT) do { \
@@ -131,7 +130,7 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
const int64_t _verify3_right = (int64_t)(RIGHT); \
if (unlikely(!(_verify3_left OP _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
"VERIFY3S(" #LEFT ", " #OP ", " #RIGHT ") " \
"failed (%lld " #OP " %lld)\n", \
(long long)_verify3_left, \
(long long)_verify3_right); \
@@ -142,7 +141,7 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
const uint64_t _verify3_right = (uint64_t)(RIGHT); \
if (unlikely(!(_verify3_left OP _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
"VERIFY3U(" #LEFT ", " #OP ", " #RIGHT ") " \
"failed (%llu " #OP " %llu)\n", \
(unsigned long long)_verify3_left, \
(unsigned long long)_verify3_right); \
@@ -153,7 +152,7 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
const uintptr_t _verify3_right = (uintptr_t)(RIGHT); \
if (unlikely(!(_verify3_left OP _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
"VERIFY3P(" #LEFT ", " #OP ", " #RIGHT ") " \
"failed (%px " #OP " %px)\n", \
(void *)_verify3_left, \
(void *)_verify3_right); \
@@ -163,8 +162,7 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
const int64_t _verify0_right = (int64_t)(RIGHT); \
if (unlikely(!(0 == _verify0_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY0(" #RIGHT ") " \
"failed (0 == %lld)\n", \
"VERIFY0(" #RIGHT ") failed (%lld)\n", \
(long long)_verify0_right); \
} while (0)
@@ -172,8 +170,7 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
const uintptr_t _verify0_right = (uintptr_t)(RIGHT); \
if (unlikely(!(0 == _verify0_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY0P(" #RIGHT ") " \
"failed (NULL == %px)\n", \
"VERIFY0P(" #RIGHT ") failed (%px)\n", \
(void *)_verify0_right); \
} while (0)
@@ -186,14 +183,13 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
*/
#define VERIFY3BF(LEFT, OP, RIGHT, STR, ...) do { \
const boolean_t _verify3_left = (boolean_t)(LEFT); \
const boolean_t _verify3_right = (boolean_t)(RIGHT); \
const boolean_t _verify3_left = (boolean_t)!!(LEFT); \
const boolean_t _verify3_right = (boolean_t)!!(RIGHT); \
if (unlikely(!(_verify3_left OP _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
"VERIFY3B(" #LEFT ", " #OP ", " #RIGHT ") " \
"failed (%d " #OP " %d) " STR "\n", \
(boolean_t)(_verify3_left), \
(boolean_t)(_verify3_right), \
_verify3_left, _verify3_right, \
__VA_ARGS__); \
} while (0)
@@ -202,10 +198,9 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
const int64_t _verify3_right = (int64_t)(RIGHT); \
if (unlikely(!(_verify3_left OP _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
"VERIFY3S(" #LEFT ", " #OP ", " #RIGHT ") " \
"failed (%lld " #OP " %lld) " STR "\n", \
(long long)(_verify3_left), \
(long long)(_verify3_right), \
(long long)_verify3_left, (long long)_verify3_right,\
__VA_ARGS__); \
} while (0)
@@ -214,10 +209,10 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
const uint64_t _verify3_right = (uint64_t)(RIGHT); \
if (unlikely(!(_verify3_left OP _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
"VERIFY3U(" #LEFT ", " #OP ", " #RIGHT ") " \
"failed (%llu " #OP " %llu) " STR "\n", \
(unsigned long long)(_verify3_left), \
(unsigned long long)(_verify3_right), \
(unsigned long long)_verify3_left, \
(unsigned long long)_verify3_right, \
__VA_ARGS__); \
} while (0)
@@ -226,32 +221,27 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
const uintptr_t _verify3_right = (uintptr_t)(RIGHT); \
if (unlikely(!(_verify3_left OP _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY3(" #LEFT " " #OP " " #RIGHT ") " \
"VERIFY3P(" #LEFT ", " #OP ", " #RIGHT ") " \
"failed (%px " #OP " %px) " STR "\n", \
(void *) (_verify3_left), \
(void *) (_verify3_right), \
(void *)_verify3_left, (void *)_verify3_right, \
__VA_ARGS__); \
} while (0)
#define VERIFY0PF(RIGHT, STR, ...) do { \
const uintptr_t _verify3_left = (uintptr_t)(0); \
const uintptr_t _verify3_right = (uintptr_t)(RIGHT); \
if (unlikely(!(_verify3_left == _verify3_right))) \
if (unlikely(!(0 == _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY0(0 == " #RIGHT ") " \
"failed (0 == %px) " STR "\n", \
(long long) (_verify3_right), \
"VERIFY0P(" #RIGHT ") failed (%px) " STR "\n", \
(void *)_verify3_right, \
__VA_ARGS__); \
} while (0)
#define VERIFY0F(RIGHT, STR, ...) do { \
const int64_t _verify3_left = (int64_t)(0); \
const int64_t _verify3_right = (int64_t)(RIGHT); \
if (unlikely(!(_verify3_left == _verify3_right))) \
if (unlikely(!(0 == _verify3_right))) \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
"VERIFY0(0 == " #RIGHT ") " \
"failed (0 == %lld) " STR "\n", \
(long long) (_verify3_right), \
"VERIFY0(" #RIGHT ") failed (%lld) " STR "\n", \
(long long)_verify3_right, \
__VA_ARGS__); \
} while (0)
@@ -260,10 +250,7 @@ spl_assert(const char *buf, const char *file, const char *func, int line)
spl_assert("(" #A ") implies (" #B ")", \
__FILE__, __FUNCTION__, __LINE__)))
#define VERIFY_EQUIV(A, B) \
((void)(likely(!!(A) == !!(B)) || \
spl_assert("(" #A ") is equivalent to (" #B ")", \
__FILE__, __FUNCTION__, __LINE__)))
#define VERIFY_EQUIV(A, B) VERIFY3B(A, ==, B)
/*
* Debugging disabled (--disable-debug)