summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Rosenthal <jrosenth@chromium.org>2019-07-30 17:28:28 -0600
committerCommit Bot <commit-bot@chromium.org>2019-07-31 18:55:45 +0000
commit03ab9c1df5c16553b37288fea52911f7d8f62c38 (patch)
tree1d400cbb75a2ebe4577c0e91c2af516052e0655b
parent9dbf748033d8ce9f5038c9f98409abac50b3759d (diff)
downloadchrome-ec-03ab9c1df5c16553b37288fea52911f7d8f62c38.tar.gz
common: make IS_ENABLED sorta compatible with clang
Clang does not feature the error(...) attribute on functions, and apparently we use that compiler for the cr50 fuzz tests. Work around clang's limitations by removing the error(...) attribute when compiling with clang, allowing us to use IS_ENABLED in files that get compiled by the cr50 fuzz tests. BUG=chromium:989315 BRANCH=none TEST=make buildall -j TEST=IS_ENABLED works in system.c Change-Id: I15bf7a2d2854db12f8e00009afe39359cb6f5c19 Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1726948 Reviewed-by: Raul E Rangel <rrangel@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Raul E Rangel <rrangel@chromium.org>
-rw-r--r--include/common.h32
1 files changed, 22 insertions, 10 deletions
diff --git a/include/common.h b/include/common.h
index 9601ed4823..73e4a19abc 100644
--- a/include/common.h
+++ b/include/common.h
@@ -273,6 +273,18 @@ enum ec_error_list {
#define __fls(n) (31 - __builtin_clz(n))
/*
+ * Attribute for generating an error if a function is used.
+ *
+ * Clang does not have a function attribute to do this. Rely on linker
+ * errors. :(
+ */
+#ifdef __clang__
+#define __error(msg)
+#else
+#define __error(msg) __attribute__((error(msg)))
+#endif
+
+/*
* Getting something that works in C and CPP for an arg that may or may
* not be defined is tricky. Here, if we have "#define CONFIG_FOO"
* we match on the placeholder define, insert the "_, 1," for arg1 and generate
@@ -291,16 +303,16 @@ enum ec_error_list {
#define __ARG_PLACEHOLDER_ _, 1,
#define _config_enabled(cfg, value) \
__config_enabled(__ARG_PLACEHOLDER_##value, cfg, value)
-#define __config_enabled(arg1_or_junk, cfg, value) ___config_enabled( \
- arg1_or_junk _,\
- ({ \
- int __undefined = __builtin_strcmp(cfg, #value) == 0; \
- extern int IS_ENABLED_BAD_ARGS(void) __attribute__(( \
- error(cfg " must be <blank>, or not defined.")));\
- if (!__undefined) \
- IS_ENABLED_BAD_ARGS(); \
- 0; \
- }))
+#define __config_enabled(arg1_or_junk, cfg, value) \
+ ___config_enabled( \
+ arg1_or_junk _, ({ \
+ int __undefined = __builtin_strcmp(cfg, #value) == 0; \
+ extern int IS_ENABLED_BAD_ARGS(void) __error( \
+ cfg " must be <blank>, or not defined."); \
+ if (!__undefined) \
+ IS_ENABLED_BAD_ARGS(); \
+ 0; \
+ }))
#define ___config_enabled(__ignored, val, ...) val
/**