summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJett Rink <jettrink@chromium.org>2019-12-04 11:27:46 -0700
committerCommit Bot <commit-bot@chromium.org>2020-12-30 07:16:28 +0000
commitc15c9fffa70d180c74c28a3682b9ec2f17841153 (patch)
tree07457dc49b70e2451c365bb62fd1b4566ad828a4
parentc75e57fc181f29deb819c0ff4d7ba38d7202c83b (diff)
downloadchrome-ec-c15c9fffa70d180c74c28a3682b9ec2f17841153.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> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2607027 Tested-by: Chen-Tsung Hsieh <chentsung@chromium.org> Reviewed-by: Chen-Tsung Hsieh <chentsung@chromium.org> Commit-Queue: Chen-Tsung Hsieh <chentsung@chromium.org>
-rw-r--r--include/compile_time_macros.h10
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