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 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 #define DCHECK(condition) \ | 719 #define DCHECK(condition) \ |
720 __analysis_assume(!!(condition)), \ | 720 __analysis_assume(!!(condition)), \ |
721 LAZY_STREAM(LOG_STREAM(DCHECK), false) \ | 721 LAZY_STREAM(LOG_STREAM(DCHECK), false) \ |
722 << "Check failed: " #condition ". " | 722 << "Check failed: " #condition ". " |
723 | 723 |
724 #define DPCHECK(condition) \ | 724 #define DPCHECK(condition) \ |
725 __analysis_assume(!!(condition)), \ | 725 __analysis_assume(!!(condition)), \ |
726 LAZY_STREAM(PLOG_STREAM(DCHECK), false) \ | 726 LAZY_STREAM(PLOG_STREAM(DCHECK), false) \ |
727 << "Check failed: " #condition ". " | 727 << "Check failed: " #condition ". " |
728 | 728 |
729 #else // _PREFAST_ | 729 #elif defined(__clang_analyzer__) |
| 730 |
| 731 // Keeps the static analyzer from proceeding along the current codepath, |
| 732 // otherwise false positive errors may be generated by null pointer checks. |
| 733 inline constexpr bool AnalyzerNoReturn() __attribute__((analyzer_noreturn)) { |
| 734 return false; |
| 735 } |
| 736 |
| 737 #define DCHECK(condition) \ |
| 738 LAZY_STREAM( \ |
| 739 LOG_STREAM(DCHECK), \ |
| 740 DCHECK_IS_ON() ? (logging::AnalyzerNoReturn(), !(condition)) : false) \ |
| 741 << "Check failed: " #condition ". " |
| 742 |
| 743 #define DPCHECK(condition) \ |
| 744 LAZY_STREAM( \ |
| 745 PLOG_STREAM(DCHECK), \ |
| 746 DCHECK_IS_ON() ? (logging::AnalyzerNoReturn(), !(condition)) : false) \ |
| 747 << "Check failed: " #condition ". " |
| 748 |
| 749 #else |
730 | 750 |
731 #define DCHECK(condition) \ | 751 #define DCHECK(condition) \ |
732 LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \ | 752 LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \ |
733 << "Check failed: " #condition ". " | 753 << "Check failed: " #condition ". " |
734 | 754 |
735 #define DPCHECK(condition) \ | 755 #define DPCHECK(condition) \ |
736 LAZY_STREAM(PLOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \ | 756 LAZY_STREAM(PLOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \ |
737 << "Check failed: " #condition ". " | 757 << "Check failed: " #condition ". " |
738 | 758 |
739 #endif // _PREFAST_ | 759 #endif |
740 | 760 |
741 // Helper macro for binary operators. | 761 // Helper macro for binary operators. |
742 // Don't use this macro directly in your code, use DCHECK_EQ et al below. | 762 // Don't use this macro directly in your code, use DCHECK_EQ et al below. |
743 // The 'switch' is used to prevent the 'else' from being ambiguous when the | 763 // The 'switch' is used to prevent the 'else' from being ambiguous when the |
744 // macro is used in an 'if' clause such as: | 764 // macro is used in an 'if' clause such as: |
745 // if (a == 1) | 765 // if (a == 1) |
746 // DCHECK_EQ(2, a); | 766 // DCHECK_EQ(2, a); |
747 #define DCHECK_OP(name, op, val1, val2) \ | 767 #define DCHECK_OP(name, op, val1, val2) \ |
748 switch (0) case 0: default: \ | 768 switch (0) case 0: default: \ |
749 if (::logging::CheckOpResult true_if_passed = \ | 769 if (::logging::CheckOpResult true_if_passed = \ |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 #elif NOTIMPLEMENTED_POLICY == 5 | 1038 #elif NOTIMPLEMENTED_POLICY == 5 |
1019 #define NOTIMPLEMENTED() do {\ | 1039 #define NOTIMPLEMENTED() do {\ |
1020 static bool logged_once = false;\ | 1040 static bool logged_once = false;\ |
1021 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ | 1041 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ |
1022 logged_once = true;\ | 1042 logged_once = true;\ |
1023 } while(0);\ | 1043 } while(0);\ |
1024 EAT_STREAM_PARAMETERS | 1044 EAT_STREAM_PARAMETERS |
1025 #endif | 1045 #endif |
1026 | 1046 |
1027 #endif // BASE_LOGGING_H_ | 1047 #endif // BASE_LOGGING_H_ |
OLD | NEW |