LinuxKPI: Use negative bit field size to trigger BUILD_BUG_ON_ZERO

compile time assertion on non-NULL pointers. Tests conducted show that
_Static_assert, negative array size method and current code does not
handle pointers well enough. Bit field method solves this problem.

This change is derrived from Linux implementation of BUILD_BUG_ON_ZERO.

MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D33674
This commit is contained in:
Vladimir Kondratyev 2021-12-25 21:42:15 +03:00
parent 307f78f3ed
commit 64dab63f3b

View File

@ -109,9 +109,7 @@
#define BUILD_BUG_ON_MSG(x, msg) BUILD_BUG_ON(x)
#define BUILD_BUG_ON_NOT_POWER_OF_2(x) BUILD_BUG_ON(!powerof2(x))
#define BUILD_BUG_ON_INVALID(expr) while (0) { (void)(expr); }
extern const volatile int lkpi_build_bug_on_zero;
#define BUILD_BUG_ON_ZERO(x) ((x) ? lkpi_build_bug_on_zero : 0)
#define BUILD_BUG_ON_ZERO(x) ((int)sizeof(struct { int:-((x) != 0); }))
#define BUG() panic("BUG at %s:%d", __FILE__, __LINE__)
#define BUG_ON(cond) do { \