summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorChih-Hung Hsieh <chh@google.com>2016-02-26 11:32:14 -0800
committerChih-Hung Hsieh <chh@google.com>2016-03-02 09:23:02 -0800
commit7e0e14ca84892771c08377479d509db749cd304d (patch)
treed3b38161a3a3063beb67f56505385ec8238ba3bc /base
parentf666ba41a729834bf15296ab13a92f33c5b0d592 (diff)
downloadcore-7e0e14ca84892771c08377479d509db749cd304d.tar.gz
core-7e0e14ca84892771c08377479d509db749cd304d.tar.bz2
core-7e0e14ca84892771c08377479d509db749cd304d.zip
Make CHECK(x) work with static analyzer.
When __clang_analyzer__ is defined call abort after FATAL LogMessage. BUG: 27379879 Change-Id: I198aad2be1191b6eb45db5333f94436f619facd9
Diffstat (limited to 'base')
-rw-r--r--base/include/android-base/logging.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/base/include/android-base/logging.h b/base/include/android-base/logging.h
index cd526d03d..e5babedf3 100644
--- a/base/include/android-base/logging.h
+++ b/base/include/android-base/logging.h
@@ -150,6 +150,14 @@ class ErrnoRestorer {
#define UNIMPLEMENTED(level) \
LOG(level) << __PRETTY_FUNCTION__ << " unimplemented "
+#ifdef __clang_analyzer__
+// ClangL static analyzer does not see the conditional statement inside
+// LogMessage's destructor that will abort on FATAL severity.
+#define ABORT_AFTER_LOG_FATAL for (;;abort())
+#else
+#define ABORT_AFTER_LOG_FATAL
+#endif
+
// Check whether condition x holds and LOG(FATAL) if not. The value of the
// expression x is only evaluated once. Extra logging can be appended using <<
// after. For example:
@@ -160,6 +168,7 @@ class ErrnoRestorer {
if (LIKELY((x))) \
; \
else \
+ ABORT_AFTER_LOG_FATAL \
::android::base::LogMessage(__FILE__, __LINE__, ::android::base::DEFAULT, \
::android::base::FATAL, -1).stream() \
<< "Check failed: " #x << " "
@@ -169,6 +178,7 @@ class ErrnoRestorer {
for (auto _values = ::android::base::MakeEagerEvaluator(LHS, RHS); \
UNLIKELY(!(_values.lhs OP _values.rhs)); \
/* empty */) \
+ ABORT_AFTER_LOG_FATAL \
::android::base::LogMessage(__FILE__, __LINE__, ::android::base::DEFAULT, \
::android::base::FATAL, -1).stream() \
<< "Check failed: " << #LHS << " " << #OP << " " << #RHS \
@@ -192,6 +202,7 @@ class ErrnoRestorer {
if (LIKELY((strcmp(s1, s2) == 0) == sense)) \
; \
else \
+ ABORT_AFTER_LOG_FATAL \
LOG(FATAL) << "Check failed: " \
<< "\"" << s1 << "\"" \
<< (sense ? " == " : " != ") << "\"" << s2 << "\""
@@ -206,6 +217,7 @@ class ErrnoRestorer {
int rc = call args; \
if (rc != 0) { \
errno = rc; \
+ ABORT_AFTER_LOG_FATAL \
PLOG(FATAL) << #call << " failed for " << what; \
} \
} while (false)