From cd38fb1610fed57815b6bd3258fc04043460e7f8 Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Thu, 19 Mar 2020 15:59:14 +0100 Subject: [PATCH] Revert "toolchain: common: Merge build assert macros" This reverts commit 974aa3add44898cbcdba2f7db1ac8c64ca0ba670. Pull Request #23437 was merged by mistake with an invalid manifest. Signed-off-by: Carles Cufi --- doc/reference/kernel/other/fatal.rst | 22 ++++++++++++---------- include/toolchain/common.h | 10 ++++------ include/toolchain/gcc.h | 9 ++++----- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/doc/reference/kernel/other/fatal.rst b/doc/reference/kernel/other/fatal.rst index 8d58519d36f..a460646ad7c 100644 --- a/doc/reference/kernel/other/fatal.rst +++ b/doc/reference/kernel/other/fatal.rst @@ -123,8 +123,8 @@ Build Assertions Zephyr provides two macros for performing build-time assertion checks. These are evaluated completely at compile-time, and are always checked. -BUILD_ASSERT() --------------- +BUILD_ASSERT_MSG() +------------------ This has the same semantics as C's ``_Static_assert`` or C++'s ``static_assert``. If the evaluation fails, a build error will be generated by @@ -138,7 +138,8 @@ For example, suppose this check fails: .. code-block:: c - BUILD_ASSERT(FOO == 2000, "Invalid value of FOO"); + BUILD_ASSERT_MSG(FOO == 2000, + "Invalid value of FOO"); With GCC, the output resembles: @@ -146,16 +147,17 @@ With GCC, the output resembles: tests/kernel/fatal/src/main.c: In function 'test_main': include/toolchain/gcc.h:28:37: error: static assertion failed: "Invalid value of FOO" - #define BUILD_ASSERT(EXPR, MSG) _Static_assert(EXPR, "" MSG) - ^~~~~~~~~~~~~~ - tests/kernel/fatal/src/main.c:370:2: note: in expansion of macro 'BUILD_ASSERT' - BUILD_ASSERT(FOO == 2000, + #define BUILD_ASSERT_MSG(EXPR, MSG) _Static_assert(EXPR, MSG) + ^~~~~~~~~~~~~~ + tests/kernel/fatal/src/main.c:370:2: note: in expansion of macro 'BUILD_ASSERT_MSG' + BUILD_ASSERT_MSG(FOO == 2000, ^~~~~~~~~~~~~~~~ -BUILD_ASSERT_MSG() ------------------- +BUILD_ASSERT() +-------------- -This macro is identical to ``BUILD_ASSERT()``. Its use is deprecated. +This works just like ``BUILD_ASSERT_MSG()`` except there is no supplemental +message provided, and like ``__ASSERT_NO_MSG()`` its use is discouraged. Kernel Oops =========== diff --git a/include/toolchain/common.h b/include/toolchain/common.h index 1b4737af43c..331ed433be0 100644 --- a/include/toolchain/common.h +++ b/include/toolchain/common.h @@ -138,17 +138,15 @@ #define __subsystem #ifndef BUILD_ASSERT -/* Compile-time assertion that makes the build to fail. - * Common implementation swallows the message. - */ -#define BUILD_ASSERT(EXPR, MSG) \ +/* compile-time assertion that makes the build fail */ +#define BUILD_ASSERT(EXPR) \ enum _CONCAT(__build_assert_enum, __COUNTER__) { \ _CONCAT(__build_assert, __COUNTER__) = 1 / !!(EXPR) \ } #endif - #ifndef BUILD_ASSERT_MSG -#define BUILD_ASSERT_MSG(EXPR, MSG) __DEPRECATED_MACRO BUILD_ASSERT(EXPR, MSG) +/* build assertion with message -- common implementation swallows message. */ +#define BUILD_ASSERT_MSG(EXPR, MSG) BUILD_ASSERT(EXPR) #endif /* diff --git a/include/toolchain/gcc.h b/include/toolchain/gcc.h index e63d1e16b49..e413d89c043 100644 --- a/include/toolchain/gcc.h +++ b/include/toolchain/gcc.h @@ -50,17 +50,16 @@ /* C++11 has static_assert built in */ #ifdef __cplusplus -#define BUILD_ASSERT(EXPR, MSG...) static_assert(EXPR, "" MSG) -#define BUILD_ASSERT_MSG(EXPR, MSG) __DEPRECATED_MACRO BUILD_ASSERT(EXPR, MSG) - +#define BUILD_ASSERT(EXPR) static_assert(EXPR, "") +#define BUILD_ASSERT_MSG(EXPR, MSG) static_assert(EXPR, MSG) /* * GCC 4.6 and higher have the C11 _Static_assert built in, and its * output is easier to understand than the common BUILD_ASSERT macros. */ #elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || \ (__STDC_VERSION__) >= 201100 -#define BUILD_ASSERT(EXPR, MSG...) _Static_assert(EXPR, "" MSG) -#define BUILD_ASSERT_MSG(EXPR, MSG) __DEPRECATED_MACRO BUILD_ASSERT(EXPR, MSG) +#define BUILD_ASSERT(EXPR) _Static_assert(EXPR, "") +#define BUILD_ASSERT_MSG(EXPR, MSG) _Static_assert(EXPR, MSG) #endif #include