git: ef743744f0f4 - stable/13 - LinuxKPI: Use negative bit field size to trigger BUILD_BUG_ON_ZERO

From: Vladimir Kondratyev <wulf_at_FreeBSD.org>
Date: Sat, 22 Jan 2022 19:36:40 UTC
The branch stable/13 has been updated by wulf:

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

commit ef743744f0f4e06956fb785ed16cdc547758fefb
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2021-12-25 18:42:15 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2022-01-22 19:34: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
    
    (cherry picked from commit 64dab63f3b3b6c6a1f8a92f43bed0aa28319d627)
---
 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 75e274205259..58581ebe9101 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 {				\