diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2018-10-16 10:32:25 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-10-23 22:50:45 -0700 |
commit | f5d38b0ac1b64a03a23f5bf9bf938d679c33d0d4 (patch) | |
tree | a56cc57b26d0cc1b00ca1526289fb0421a45160b /include | |
parent | 75f7dca3c3d03527e23e9414d0dff85d63c6ea26 (diff) | |
download | chrome-ec-f5d38b0ac1b64a03a23f5bf9bf938d679c33d0d4.tar.gz |
ec: Add macro to check if constant index is too large
BUILD_ASSERT can only be used for declarative code, add a macro to check
if a condition resolved at build time is true or not.
Take advantage of compiler detection of division by zero error message.
[-Werror=div-by-zero]
BUG=none
BRANCH=eve,nocturne
TEST=compile, check error is detected when condition is not true.
Change-Id: I4ab1ad4ae516c00c9e30e778dd81f18893ef1673
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1283969
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/compile_time_macros.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/include/compile_time_macros.h b/include/compile_time_macros.h index 1cc41f4d0e..bf133d60f4 100644 --- a/include/compile_time_macros.h +++ b/include/compile_time_macros.h @@ -15,6 +15,12 @@ #define _BA0_(c, x) _BA1_(c, x) #define BUILD_ASSERT(cond) _BA0_(cond, __LINE__) +/* + * Test an important condition inside code path at run time, taking advantage of + * -Werror=div-by-zero. + */ +#define BUILD_CHECK_INLINE(value, cond_true) ((value) / (!!(cond_true))) + /* Number of elements in an array */ #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |