summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2020-01-15 10:21:18 -0500
committerNick Mathewson <nickm@torproject.org>2020-01-15 10:21:18 -0500
commit5e27caa60c4ccf257c0dca64883cdf672d8d8ce4 (patch)
treedf049b9e3dfaf4a7d398aa56c127894e47d4e559 /src
parentd430b5a0749b4f1256b64e6d36ea684e9ba1cae8 (diff)
downloadtor-5e27caa60c4ccf257c0dca64883cdf672d8d8ce4.tar.gz
tor-5e27caa60c4ccf257c0dca64883cdf672d8d8ce4.zip
compat_compiler: add a macro to prevent coverity deadcode warnings.
The POSSIBLE(e) macro evaluates to the value of (e), but does so in a way that a static analyzer will not conclude that (e) is impossible. We can use this when we expect our regular compilers to eliminate deadcode, but we don't want coverity to complain about it. Part of a fix for 32960.
Diffstat (limited to 'src')
-rw-r--r--src/lib/cc/compat_compiler.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/lib/cc/compat_compiler.h b/src/lib/cc/compat_compiler.h
index 47782fda08..907622f942 100644
--- a/src/lib/cc/compat_compiler.h
+++ b/src/lib/cc/compat_compiler.h
@@ -227,4 +227,17 @@
#define EAT_SEMICOLON \
struct dummy_semicolon_eater__
+/**
+ * Tell our static analysis tool to believe that (clang's scan-build or
+ * coverity scan) that an expression might be true. We use this to suppress
+ * dead-code warnings.
+ **/
+#if defined(__COVERITY__) || defined(__clang_analyzer__)
+/* By calling getenv, we force the analyzer not to conclude that 'expr' is
+ * false. */
+#define POSSIBLE(expr) ((expr) || getenv("STATIC_ANALYZER_DEADCODE_DUMMY_"))
+#else
+#define POSSIBLE(expr) (expr)
+#endif
+
#endif /* !defined(TOR_COMPAT_COMPILER_H) */