git: 64dab63f3b3b - main - LinuxKPI: Use negative bit field size to trigger BUILD_BUG_ON_ZERO

From: Vladimir Kondratyev <wulf_at_FreeBSD.org>
Date: Mon, 10 Jan 2022 19:50:53 UTC
The branch main has been updated by wulf:

URL: https://cgit.FreeBSD.org/src/commit/?id=64dab63f3b3b6c6a1f8a92f43bed0aa28319d627

commit 64dab63f3b3b6c6a1f8a92f43bed0aa28319d627
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2021-12-25 18:42:15 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2022-01-10 19:49:38 +0000

    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
---
 sys/compat/linuxkpi/common/include/linux/kernel.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/kernel.h b/sys/compat/linuxkpi/common/include/linux/kernel.h
index 419dae214396..a84f577dd912 100644
--- a/sys/compat/linuxkpi/common/include/linux/kernel.h
+++ b/sys/compat/linuxkpi/common/include/linux/kernel.h
@@ -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 {				\