OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_LOGGING_H_ | 5 #ifndef BASE_LOGGING_H_ |
6 #define BASE_LOGGING_H_ | 6 #define BASE_LOGGING_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <cassert> | 10 #include <cassert> |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 | 291 |
292 // ANALYZER_ASSUME_TRUE(...) generates compiler-specific annotations which | 292 // ANALYZER_ASSUME_TRUE(...) generates compiler-specific annotations which |
293 // prevent the static analyzer from analyzing the code using hypothetical | 293 // prevent the static analyzer from analyzing the code using hypothetical |
294 // values that are asserted to be impossible. | 294 // values that are asserted to be impossible. |
295 // The value of the condition passed to ANALYZER_ASSUME_TRUE() is returned | 295 // The value of the condition passed to ANALYZER_ASSUME_TRUE() is returned |
296 // directly. | 296 // directly. |
297 #if defined(__clang_analyzer__) | 297 #if defined(__clang_analyzer__) |
298 | 298 |
299 inline void AnalyzerNoReturn() __attribute__((analyzer_noreturn)) {} | 299 inline void AnalyzerNoReturn() __attribute__((analyzer_noreturn)) {} |
300 | 300 |
301 // |arg| is a universal reference for compatibility with lvalue and rvalue | |
302 // arguments. | |
301 template <typename TVal> | 303 template <typename TVal> |
302 inline constexpr TVal AnalysisAssumeTrue(TVal arg) { | 304 inline constexpr TVal AnalysisAssumeTrue(TVal&& arg) { |
303 if (!arg) { | 305 if (!arg) { |
304 AnalyzerNoReturn(); | 306 AnalyzerNoReturn(); |
305 } | 307 } |
306 return arg; | 308 return arg; |
307 } | 309 } |
308 | 310 |
309 #define ANALYZER_ASSUME_TRUE(val) ::logging::AnalysisAssumeTrue(val) | 311 #define ANALYZER_ASSUME_TRUE(val) ::logging::AnalysisAssumeTrue(val) |
310 | 312 |
311 #elif defined(_PREFAST_) && defined(OS_WIN) | 313 #elif defined(_PREFAST_) && defined(OS_WIN) |
312 | 314 |
315 // |arg| is a universal reference for compatibility with lvalue and rvalue | |
316 // arguments. | |
313 template <typename TVal> | 317 template <typename TVal> |
314 inline constexpr TVal AnalysisAssumeTrue(TVal arg) { | 318 inline constexpr TVal AnalysisAssumeTrue(TVal&& arg) { |
315 __analysis_assume(!!arg); | 319 __analysis_assume(!!arg); |
316 return arg; | 320 return arg; |
317 } | 321 } |
318 | 322 |
319 #define ANALYZER_ASSUME_TRUE(val) ::logging::AnalysisAssumeTrue(val) | 323 #define ANALYZER_ASSUME_TRUE(val) ::logging::AnalysisAssumeTrue(val) |
320 | 324 |
321 #else // !_PREFAST_ & !__clang_analyzer__ | 325 #else // !_PREFAST_ & !__clang_analyzer__ |
322 | 326 |
323 #define ANALYZER_ASSUME_TRUE(val) (val) | 327 #define ANALYZER_ASSUME_TRUE(val) (val) |
324 | 328 |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
621 std::string* MakeCheckOpString<unsigned int, unsigned long>( | 625 std::string* MakeCheckOpString<unsigned int, unsigned long>( |
622 const unsigned int&, const unsigned long&, const char* names); | 626 const unsigned int&, const unsigned long&, const char* names); |
623 extern template BASE_EXPORT | 627 extern template BASE_EXPORT |
624 std::string* MakeCheckOpString<std::string, std::string>( | 628 std::string* MakeCheckOpString<std::string, std::string>( |
625 const std::string&, const std::string&, const char* name); | 629 const std::string&, const std::string&, const char* name); |
626 | 630 |
627 // Helper functions for CHECK_OP macro. | 631 // Helper functions for CHECK_OP macro. |
628 // The (int, int) specialization works around the issue that the compiler | 632 // The (int, int) specialization works around the issue that the compiler |
629 // will not instantiate the template version of the function on values of | 633 // will not instantiate the template version of the function on values of |
630 // unnamed enum type - see comment below. | 634 // unnamed enum type - see comment below. |
631 #define DEFINE_CHECK_OP_IMPL(name, op) \ | 635 #define DEFINE_CHECK_OP_IMPL(name, op) \ |
632 template <class t1, class t2> \ | 636 template <class t1, class t2> \ |
633 inline std::string* Check##name##Impl(const t1& v1, const t2& v2, \ | 637 inline std::string* Check##name##Impl(const t1& v1, const t2& v2, \ |
634 const char* names) { \ | 638 const char* names) { \ |
635 if (v1 op v2) return NULL; \ | 639 if (ANALYZER_ASSUME_TRUE(v1 op v2)) \ |
danakj
2017/02/14 22:09:39
This is the other CL, it should be removed from th
Kevin M
2017/02/14 22:29:17
Removed
| |
636 else return ::logging::MakeCheckOpString(v1, v2, names); \ | 640 return NULL; \ |
637 } \ | 641 else \ |
642 return ::logging::MakeCheckOpString(v1, v2, names); \ | |
643 } \ | |
638 inline std::string* Check##name##Impl(int v1, int v2, const char* names) { \ | 644 inline std::string* Check##name##Impl(int v1, int v2, const char* names) { \ |
639 if (v1 op v2) return NULL; \ | 645 if (ANALYZER_ASSUME_TRUE(v1 op v2)) \ |
640 else return ::logging::MakeCheckOpString(v1, v2, names); \ | 646 return NULL; \ |
647 else \ | |
648 return ::logging::MakeCheckOpString(v1, v2, names); \ | |
641 } | 649 } |
642 DEFINE_CHECK_OP_IMPL(EQ, ==) | 650 DEFINE_CHECK_OP_IMPL(EQ, ==) |
643 DEFINE_CHECK_OP_IMPL(NE, !=) | 651 DEFINE_CHECK_OP_IMPL(NE, !=) |
644 DEFINE_CHECK_OP_IMPL(LE, <=) | 652 DEFINE_CHECK_OP_IMPL(LE, <=) |
645 DEFINE_CHECK_OP_IMPL(LT, < ) | 653 DEFINE_CHECK_OP_IMPL(LT, < ) |
646 DEFINE_CHECK_OP_IMPL(GE, >=) | 654 DEFINE_CHECK_OP_IMPL(GE, >=) |
647 DEFINE_CHECK_OP_IMPL(GT, > ) | 655 DEFINE_CHECK_OP_IMPL(GT, > ) |
648 #undef DEFINE_CHECK_OP_IMPL | 656 #undef DEFINE_CHECK_OP_IMPL |
649 | 657 |
650 #define CHECK_EQ(val1, val2) CHECK_OP(EQ, ==, val1, val2) | 658 #define CHECK_EQ(val1, val2) CHECK_OP(EQ, ==, val1, val2) |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1051 #elif NOTIMPLEMENTED_POLICY == 5 | 1059 #elif NOTIMPLEMENTED_POLICY == 5 |
1052 #define NOTIMPLEMENTED() do {\ | 1060 #define NOTIMPLEMENTED() do {\ |
1053 static bool logged_once = false;\ | 1061 static bool logged_once = false;\ |
1054 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ | 1062 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ |
1055 logged_once = true;\ | 1063 logged_once = true;\ |
1056 } while(0);\ | 1064 } while(0);\ |
1057 EAT_STREAM_PARAMETERS | 1065 EAT_STREAM_PARAMETERS |
1058 #endif | 1066 #endif |
1059 | 1067 |
1060 #endif // BASE_LOGGING_H_ | 1068 #endif // BASE_LOGGING_H_ |
OLD | NEW |