| Index: base/logging.h
|
| diff --git a/base/logging.h b/base/logging.h
|
| index c969f3dcc1684bacbfa11ebec5f54d158c20a780..c67b937e5b08607736e860dd349f1de6204c6a5b 100644
|
| --- a/base/logging.h
|
| +++ b/base/logging.h
|
| @@ -289,45 +289,6 @@ typedef bool (*LogMessageHandlerFunction)(int severity,
|
| BASE_EXPORT void SetLogMessageHandler(LogMessageHandlerFunction handler);
|
| BASE_EXPORT LogMessageHandlerFunction GetLogMessageHandler();
|
|
|
| -// ANALYZER_ASSUME_TRUE(...) generates compiler-specific annotations which
|
| -// prevent the static analyzer from analyzing the code using hypothetical
|
| -// values that are asserted to be impossible.
|
| -// The value of the condition passed to ANALYZER_ASSUME_TRUE() is returned
|
| -// directly.
|
| -#if defined(__clang_analyzer__)
|
| -
|
| -inline void AnalyzerNoReturn() __attribute__((analyzer_noreturn)) {}
|
| -
|
| -// |arg| is a universal reference for compatibility with lvalue and rvalue
|
| -// arguments.
|
| -template <typename TVal>
|
| -inline constexpr TVal&& AnalysisAssumeTrue(TVal&& arg) {
|
| - if (!arg) {
|
| - AnalyzerNoReturn();
|
| - }
|
| - return std::forward<TVal>(arg);
|
| -}
|
| -
|
| -#define ANALYZER_ASSUME_TRUE(val) ::logging::AnalysisAssumeTrue(val)
|
| -
|
| -#elif defined(_PREFAST_) && defined(OS_WIN)
|
| -
|
| -// |arg| is a universal reference for compatibility with lvalue and rvalue
|
| -// arguments.
|
| -template <typename TVal>
|
| -inline constexpr TVal&& AnalysisAssumeTrue(TVal&& arg) {
|
| - __analysis_assume(!!arg);
|
| - return std::forward<TVal>(arg);
|
| -}
|
| -
|
| -#define ANALYZER_ASSUME_TRUE(val) ::logging::AnalysisAssumeTrue(val)
|
| -
|
| -#else // !_PREFAST_ & !__clang_analyzer__
|
| -
|
| -#define ANALYZER_ASSUME_TRUE(val) (val)
|
| -
|
| -#endif // !_PREFAST_ & !__clang_analyzer__
|
| -
|
| typedef int LogSeverity;
|
| const LogSeverity LOG_VERBOSE = -1; // This is level 1 verbosity
|
| // Note: the log severities are used to index into the array of names,
|
| @@ -447,9 +408,8 @@ const LogSeverity LOG_0 = LOG_ERROR;
|
|
|
| // TODO(akalin): Add more VLOG variants, e.g. VPLOG.
|
|
|
| -#define LOG_ASSERT(condition) \
|
| - LOG_IF(FATAL, !ANALYZER_ASSUME_TRUE(condition)) \
|
| - << "Assert failed: " #condition ". "
|
| +#define LOG_ASSERT(condition) \
|
| + LOG_IF(FATAL, !(condition)) << "Assert failed: " #condition ". "
|
|
|
| #if defined(OS_WIN)
|
| #define PLOG_STREAM(severity) \
|
| @@ -602,15 +562,37 @@ class CheckOpResult {
|
|
|
| #else // !(OFFICIAL_BUILD && NDEBUG)
|
|
|
| +#if defined(_PREFAST_) && defined(OS_WIN)
|
| +// Use __analysis_assume to tell the VC++ static analysis engine that
|
| +// assert conditions are true, to suppress warnings. The LAZY_STREAM
|
| +// parameter doesn't reference 'condition' in /analyze builds because
|
| +// this evaluation confuses /analyze. The !! before condition is because
|
| +// __analysis_assume gets confused on some conditions:
|
| +// http://randomascii.wordpress.com/2011/09/13/analyze-for-visual-studio-the-ugly-part-5/
|
| +
|
| +#define CHECK(condition) \
|
| + __analysis_assume(!!(condition)), \
|
| + LAZY_STREAM(LOG_STREAM(FATAL), false) \
|
| + << "Check failed: " #condition ". "
|
| +
|
| +#define PCHECK(condition) \
|
| + __analysis_assume(!!(condition)), \
|
| + LAZY_STREAM(PLOG_STREAM(FATAL), false) \
|
| + << "Check failed: " #condition ". "
|
| +
|
| +#else // _PREFAST_
|
| +
|
| // Do as much work as possible out of line to reduce inline code size.
|
| #define CHECK(condition) \
|
| LAZY_STREAM(::logging::LogMessage(__FILE__, __LINE__, #condition).stream(), \
|
| - !ANALYZER_ASSUME_TRUE(condition))
|
| + !(condition))
|
|
|
| -#define PCHECK(condition) \
|
| - LAZY_STREAM(PLOG_STREAM(FATAL), !ANALYZER_ASSUME_TRUE(condition)) \
|
| +#define PCHECK(condition) \
|
| + LAZY_STREAM(PLOG_STREAM(FATAL), !(condition)) \
|
| << "Check failed: " #condition ". "
|
|
|
| +#endif // _PREFAST_
|
| +
|
| // Helper macro for binary operators.
|
| // Don't use this macro directly in your code, use CHECK_EQ et al below.
|
| // The 'switch' is used to prevent the 'else' from being ambiguous when the
|
| @@ -707,13 +689,13 @@ std::string* MakeCheckOpString<std::string, std::string>(
|
| template <class t1, class t2> \
|
| inline std::string* Check##name##Impl(const t1& v1, const t2& v2, \
|
| const char* names) { \
|
| - if (ANALYZER_ASSUME_TRUE(v1 op v2)) \
|
| + if (v1 op v2) \
|
| return NULL; \
|
| else \
|
| return ::logging::MakeCheckOpString(v1, v2, names); \
|
| } \
|
| inline std::string* Check##name##Impl(int v1, int v2, const char* names) { \
|
| - if (ANALYZER_ASSUME_TRUE(v1 op v2)) \
|
| + if (v1 op v2) \
|
| return NULL; \
|
| else \
|
| return ::logging::MakeCheckOpString(v1, v2, names); \
|
| @@ -810,24 +792,58 @@ const LogSeverity LOG_DCHECK = LOG_INFO;
|
| // DCHECK_IS_ON() is true. When DCHECK_IS_ON() is false, the macros use
|
| // EAT_STREAM_PARAMETERS to avoid expressions that would create temporaries.
|
|
|
| +#if defined(_PREFAST_) && defined(OS_WIN)
|
| +// See comments on the previous use of __analysis_assume.
|
| +
|
| +#define DCHECK(condition) \
|
| + __analysis_assume(!!(condition)), \
|
| + LAZY_STREAM(LOG_STREAM(DCHECK), false) \
|
| + << "Check failed: " #condition ". "
|
| +
|
| +#define DPCHECK(condition) \
|
| + __analysis_assume(!!(condition)), \
|
| + LAZY_STREAM(PLOG_STREAM(DCHECK), false) \
|
| + << "Check failed: " #condition ". "
|
| +
|
| +#elif defined(__clang_analyzer__)
|
| +
|
| +// Keeps the static analyzer from proceeding along the current codepath,
|
| +// otherwise false positive errors may be generated by null pointer checks.
|
| +inline constexpr bool AnalyzerNoReturn() __attribute__((analyzer_noreturn)) {
|
| + return false;
|
| +}
|
| +
|
| +#define DCHECK(condition) \
|
| + LAZY_STREAM( \
|
| + LOG_STREAM(DCHECK), \
|
| + DCHECK_IS_ON() ? (logging::AnalyzerNoReturn() || !(condition)) : false) \
|
| + << "Check failed: " #condition ". "
|
| +
|
| +#define DPCHECK(condition) \
|
| + LAZY_STREAM( \
|
| + PLOG_STREAM(DCHECK), \
|
| + DCHECK_IS_ON() ? (logging::AnalyzerNoReturn() || !(condition)) : false) \
|
| + << "Check failed: " #condition ". "
|
| +
|
| +#else
|
| +
|
| #if DCHECK_IS_ON()
|
|
|
| -#define DCHECK(condition) \
|
| - LAZY_STREAM(LOG_STREAM(DCHECK), !ANALYZER_ASSUME_TRUE(condition)) \
|
| +#define DCHECK(condition) \
|
| + LAZY_STREAM(LOG_STREAM(DCHECK), !(condition)) \
|
| << "Check failed: " #condition ". "
|
| -#define DPCHECK(condition) \
|
| - LAZY_STREAM(PLOG_STREAM(DCHECK), !ANALYZER_ASSUME_TRUE(condition)) \
|
| +#define DPCHECK(condition) \
|
| + LAZY_STREAM(PLOG_STREAM(DCHECK), !(condition)) \
|
| << "Check failed: " #condition ". "
|
|
|
| #else // DCHECK_IS_ON()
|
|
|
| -#define DCHECK(condition) \
|
| - EAT_STREAM_PARAMETERS << !ANALYZER_ASSUME_TRUE(condition)
|
| -#define DPCHECK(condition) \
|
| - EAT_STREAM_PARAMETERS << !ANALYZER_ASSUME_TRUE(condition)
|
| +#define DCHECK(condition) EAT_STREAM_PARAMETERS << !(condition)
|
| +#define DPCHECK(condition) EAT_STREAM_PARAMETERS << !(condition)
|
|
|
| #endif // DCHECK_IS_ON()
|
|
|
| +#endif
|
|
|
| // Helper macro for binary operators.
|
| // Don't use this macro directly in your code, use DCHECK_EQ et al below.
|
| @@ -863,7 +879,7 @@ const LogSeverity LOG_DCHECK = LOG_INFO;
|
| ::logging::g_swallow_stream, val1), \
|
| ::logging::MakeCheckOpValueString( \
|
| ::logging::g_swallow_stream, val2), \
|
| - ANALYZER_ASSUME_TRUE((val1)op(val2)))
|
| + (val1)op(val2))
|
|
|
| #endif // DCHECK_IS_ON()
|
|
|
| @@ -1052,7 +1068,7 @@ BASE_EXPORT void RawLog(int level, const char* message);
|
|
|
| #define RAW_CHECK(condition) \
|
| do { \
|
| - if (!ANALYZER_ASSUME_TRUE(condition)) \
|
| + if (!(condition)) \
|
| ::logging::RawLog(::logging::LOG_FATAL, \
|
| "Check failed: " #condition "\n"); \
|
| } while (0)
|
|
|