[igt-dev] [PATCH i-g-t v2 01/21] lib: Introduce igt_assume()
Petri Latvala
petri.latvala at intel.com
Fri Jan 18 10:34:04 UTC 2019
igt_assume() is an assert-like macro that is used to give hints to
static analysis of code. If static analysis is not used (as detected
by STATIC_ANALYSIS_BUILD), igt_assume() expands to a no-op statement,
otherwise expands to an assert().
v2: Make sure the expression in igt_assume is still parsed without
static analysis. (Chris)
Signed-off-by: Petri Latvala <petri.latvala at intel.com>
Cc: Arkadiusz Hiler <arkadiusz.hiler at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
Cc: MichaĆ Winiarski <michal.winiarski at intel.com>
---
lib/igt_core.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/lib/igt_core.h b/lib/igt_core.h
index 6f8c3852..4fdac1b8 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -30,6 +30,7 @@
#ifndef IGT_CORE_H
#define IGT_CORE_H
+#include <assert.h>
#include <setjmp.h>
#include <stdbool.h>
#include <stdint.h>
@@ -54,6 +55,21 @@
#endif
#endif
+/**
+ * igt_assume:
+ * @expr: Condition to test
+ *
+ * An assert-like macro to be used for tautologies to give hints to
+ * static analysis of code. No-op if STATIC_ANALYSIS_BUILD is not
+ * defined, expands to an assert() if it is.
+ */
+#if STATIC_ANALYSIS_BUILD
+#define igt_assume(e) assert(e)
+#else
+/* Make sure the expression is still parsed even though it generates no code */
+#define igt_assume(e) ((void)(sizeof((long)(e))))
+#endif
+
extern const char* __igt_test_description __attribute__((weak));
extern bool __igt_plain_output;
extern char *igt_frame_dump_path;
--
2.19.1
More information about the igt-dev
mailing list