Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(590)

Unified Diff: base/logging.h

Issue 2617283002: Add Clang static analyzer to Clang toolchain defs in GN (Closed)
Patch Set: wez feedback Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | build/toolchain/clang_static_analyzer.gni » ('j') | build/toolchain/gcc_toolchain.gni » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/logging.h
diff --git a/base/logging.h b/base/logging.h
index 3088c291901453b1664a3b03e5240804e379f0fe..4888da8c5de81f7cfbcc4775e36687844df72105 100644
--- a/base/logging.h
+++ b/base/logging.h
@@ -725,24 +725,28 @@ const LogSeverity LOG_DCHECK = LOG_INFO;
#else // _PREFAST_
-#if defined(__clang_analyzer__)
+#if __has_feature(attribute_analyzer_noreturn)
+// Alternative DCHECK implementation for Clang static analysis.
-// Stops the analyzer from proceeding along the current codepath.
-void AnalyzerNoReturn() __attribute__((analyzer_noreturn)) {}
+// Prevents the analyzer from proceeding along the current codepath.
+// Function is short-circuit evaluated when a DCHECK condition fails.
+constexpr bool AnalyzerNoReturn() __attribute__((analyzer_noreturn)) {
+ return false;
+}
-#define DCHECK(condition) \
- LAZY_STREAM( \
- LOG_STREAM(DCHECK), \
- DCHECK_IS_ON() ? (logging::AnalyzerNoReturn(), !(condition)) : false) \
+#define DCHECK(condition) \
+ LAZY_STREAM( \
+ LOG_STREAM(DCHECK), \
+ DCHECK_IS_ON() ? !((condition) || logging::AnalyzerNoReturn()) : false) \
<< "Check failed: " #condition ". "
-#define DPCHECK(condition) \
- LAZY_STREAM( \
- PLOG_STREAM(DCHECK), \
- DCHECK_IS_ON() ? (logging::AnalyzerNoReturn(), !(condition)) : false) \
+#define DPCHECK(condition) \
+ LAZY_STREAM( \
+ PLOG_STREAM(DCHECK), \
+ DCHECK_IS_ON() ? !((condition) || logging::AnalyzerNoReturn()) : false) \
<< "Check failed: " #condition ". "
-#else // __clang_analyzer__
+#else // attribute_analyzer_noreturn
#define DCHECK(condition) \
LAZY_STREAM(LOG_STREAM(DCHECK), \
@@ -754,7 +758,7 @@ void AnalyzerNoReturn() __attribute__((analyzer_noreturn)) {}
DCHECK_IS_ON() ? !(condition) : false) \
<< "Check failed: " #condition ". "
-#endif // __clang_analyzer__
+#endif // attribute_analyzer_noreturn
#define DCHECK_INTERNAL_TEST(condition) \
(DCHECK_IS_ON() ? !DCHECK_INTERNAL_ASSUME(condition) : false)
« no previous file with comments | « no previous file | build/toolchain/clang_static_analyzer.gni » ('j') | build/toolchain/gcc_toolchain.gni » ('J')

Powered by Google App Engine
This is Rietveld 408576698