diff options
author | Jett Rink <jettrink@chromium.org> | 2019-12-04 11:27:46 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-12-06 20:23:38 +0000 |
commit | 3bf671e1163cf4065b6bd7766bf8383e3dd2b381 (patch) | |
tree | 63b31081caefa91cf27ffb7a08cae96be7c1f57d /include/compile_time_macros.h | |
parent | 15eda17ccf3df7a8e600758fa7795dde9853800f (diff) | |
download | chrome-ec-3bf671e1163cf4065b6bd7766bf8383e3dd2b381.tar.gz |
build_assert: use _Static_assert
We have compiler support for _static_assert, so we should use it. Also
allow for an option message in BUILD_ASSERT that will display as a part
of the failure.
Here is an example of a compile failure with the optional message
...
CC RW/chip/npcx/gpio.o
CC RW/chip/npcx/header.o
In file included from include/common.h:13,
from include/adc.h:11,
from board/phaser/board.c:8:
include/compile_time_macros.h:13:2: error: static assertion failed:
"board/phaser/board.c:74: Size mismatch"
_Static_assert(cond, file ":" #line ": " msg)
...
BRANCH=none
BUG=none
TEST=verified by manually update BUILD_ASSERTS and viewing output.
Change-Id: I6421084868ea81be8b3fa6ad0613730f4e4e149b
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1950820
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'include/compile_time_macros.h')
-rw-r--r-- | include/compile_time_macros.h | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/include/compile_time_macros.h b/include/compile_time_macros.h index 8565a3605d..cdf8b1998b 100644 --- a/include/compile_time_macros.h +++ b/include/compile_time_macros.h @@ -9,11 +9,11 @@ #define __CROS_EC_COMPILE_TIME_MACROS_H /* Test an important condition at compile time, not run time */ -#define _BA1_(cond, line) \ - extern int __build_assertion_ ## line[1 - 2*!(cond)] \ - __attribute__ ((unused)) -#define _BA0_(c, x) _BA1_(c, x) -#define BUILD_ASSERT(cond) _BA0_(cond, __LINE__) +#define _BA1_(cond, file, line, msg) \ + _Static_assert(cond, file ":" #line ": " msg) +#define _BA0_(c, f, l, msg) _BA1_(c, f, l, msg) +/* Pass in an option message to display after condition */ +#define BUILD_ASSERT(cond, ...) _BA0_(cond, __FILE__, __LINE__, __VA_ARGS__) /* * Test an important condition inside code path at run time, taking advantage of |