Date: Sun, 18 Jul 2021 00:36:20 GMT From: "Bjoern A. Zeeb" <bz@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 14ff15e4c5bf - stable/13 - LinuxKPI: change BUILD_BUG_ON() Message-ID: <202107180036.16I0aK7h048982@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=14ff15e4c5bf92fcae4730dbf4ac23f9afbdee2d commit 14ff15e4c5bf92fcae4730dbf4ac23f9afbdee2d Author: Bjoern A. Zeeb <bz@FreeBSD.org> AuthorDate: 2021-05-24 18:26:41 +0000 Commit: Bjoern A. Zeeb <bz@FreeBSD.org> CommitDate: 2021-07-18 00:35:00 +0000 LinuxKPI: change BUILD_BUG_ON() BUILD_BUG_ON() can be used inside functions where the definition to CTASSERT() (_Static_assert()) seems to not work. Go back to an old-style CTASSERT() implementation but also add a variable dclaration to avoid "unsued typedef" errors and dummy-use the variable to avoid "unusued variable" errors. Given it is all self-contained in a block and not used outside this should be optimised away. Sponsored by: The FreeBSD Foundation Reviewed by: hselasky Differential Revision: https://reviews.freebsd.org/D30431 (cherry picked from commit 1082490cd867a4d443862523c37ce947735342d0) --- sys/compat/linuxkpi/common/include/linux/kernel.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/sys/compat/linuxkpi/common/include/linux/kernel.h b/sys/compat/linuxkpi/common/include/linux/kernel.h index 0ac0f9cc964c..aba5896111f7 100644 --- a/sys/compat/linuxkpi/common/include/linux/kernel.h +++ b/sys/compat/linuxkpi/common/include/linux/kernel.h @@ -89,8 +89,23 @@ #define S64_C(x) x ## LL #define U64_C(x) x ## ULL +/* + * BUILD_BUG_ON() can happen inside functions where _Static_assert() does not + * seem to work. Use old-schoold-ish CTASSERT from before commit + * a3085588a88fa58eb5b1eaae471999e1995a29cf but also make sure we do not + * end up with an unused typedef or variable. The compiler should optimise + * it away entirely. + */ +#define _O_CTASSERT(x) _O__CTASSERT(x, __LINE__) +#define _O__CTASSERT(x, y) _O___CTASSERT(x, y) +#define _O___CTASSERT(x, y) while (0) { \ + typedef char __assert_line_ ## y[(x) ? 1 : -1]; \ + __assert_line_ ## y _x; \ + _x[0] = '\0'; \ +} + #define BUILD_BUG() do { CTASSERT(0); } while (0) -#define BUILD_BUG_ON(x) CTASSERT(!(x)) +#define BUILD_BUG_ON(x) _O_CTASSERT(!(x)) #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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202107180036.16I0aK7h048982>