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 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 LAZY_STREAM(LOG_STREAM(DCHECK), false) \ | 718 LAZY_STREAM(LOG_STREAM(DCHECK), false) \ |
719 << "Check failed: " #condition ". " | 719 << "Check failed: " #condition ". " |
720 | 720 |
721 #define DPCHECK(condition) \ | 721 #define DPCHECK(condition) \ |
722 __analysis_assume(!!(condition)), \ | 722 __analysis_assume(!!(condition)), \ |
723 LAZY_STREAM(PLOG_STREAM(DCHECK), false) \ | 723 LAZY_STREAM(PLOG_STREAM(DCHECK), false) \ |
724 << "Check failed: " #condition ". " | 724 << "Check failed: " #condition ". " |
725 | 725 |
726 #else // _PREFAST_ | 726 #else // _PREFAST_ |
727 | 727 |
728 #if defined(__clang_analyzer__) | 728 #if __has_feature(attribute_analyzer_noreturn) |
| 729 // Alternative DCHECK implementation for Clang static analysis. |
729 | 730 |
730 // Stops the analyzer from proceeding along the current codepath. | 731 // Prevents the analyzer from proceeding along the current codepath. |
731 void AnalyzerNoReturn() __attribute__((analyzer_noreturn)) {} | 732 // Function is short-circuit evaluated when a DCHECK condition fails. |
| 733 constexpr bool AnalyzerNoReturn() __attribute__((analyzer_noreturn)) { |
| 734 return false; |
| 735 } |
732 | 736 |
733 #define DCHECK(condition) \ | 737 #define DCHECK(condition) \ |
734 LAZY_STREAM( \ | 738 LAZY_STREAM( \ |
735 LOG_STREAM(DCHECK), \ | 739 LOG_STREAM(DCHECK), \ |
736 DCHECK_IS_ON() ? (logging::AnalyzerNoReturn(), !(condition)) : false) \ | 740 DCHECK_IS_ON() ? !((condition) || logging::AnalyzerNoReturn()) : false) \ |
737 << "Check failed: " #condition ". " | 741 << "Check failed: " #condition ". " |
738 | 742 |
739 #define DPCHECK(condition) \ | 743 #define DPCHECK(condition) \ |
740 LAZY_STREAM( \ | 744 LAZY_STREAM( \ |
741 PLOG_STREAM(DCHECK), \ | 745 PLOG_STREAM(DCHECK), \ |
742 DCHECK_IS_ON() ? (logging::AnalyzerNoReturn(), !(condition)) : false) \ | 746 DCHECK_IS_ON() ? !((condition) || logging::AnalyzerNoReturn()) : false) \ |
743 << "Check failed: " #condition ". " | 747 << "Check failed: " #condition ". " |
744 | 748 |
745 #else // __clang_analyzer__ | 749 #else // attribute_analyzer_noreturn |
746 | 750 |
747 #define DCHECK(condition) \ | 751 #define DCHECK(condition) \ |
748 LAZY_STREAM(LOG_STREAM(DCHECK), \ | 752 LAZY_STREAM(LOG_STREAM(DCHECK), \ |
749 DCHECK_IS_ON() ? !(condition) : false) \ | 753 DCHECK_IS_ON() ? !(condition) : false) \ |
750 << "Check failed: " #condition ". " | 754 << "Check failed: " #condition ". " |
751 | 755 |
752 #define DPCHECK(condition) \ | 756 #define DPCHECK(condition) \ |
753 LAZY_STREAM(PLOG_STREAM(DCHECK), \ | 757 LAZY_STREAM(PLOG_STREAM(DCHECK), \ |
754 DCHECK_IS_ON() ? !(condition) : false) \ | 758 DCHECK_IS_ON() ? !(condition) : false) \ |
755 << "Check failed: " #condition ". " | 759 << "Check failed: " #condition ". " |
756 | 760 |
757 #endif // __clang_analyzer__ | 761 #endif // attribute_analyzer_noreturn |
758 | 762 |
759 #define DCHECK_INTERNAL_TEST(condition) \ | 763 #define DCHECK_INTERNAL_TEST(condition) \ |
760 (DCHECK_IS_ON() ? !DCHECK_INTERNAL_ASSUME(condition) : false) | 764 (DCHECK_IS_ON() ? !DCHECK_INTERNAL_ASSUME(condition) : false) |
761 | 765 |
762 | 766 |
763 #endif // _PREFAST_ | 767 #endif // _PREFAST_ |
764 | 768 |
765 // Helper macro for binary operators. | 769 // Helper macro for binary operators. |
766 // Don't use this macro directly in your code, use DCHECK_EQ et al below. | 770 // Don't use this macro directly in your code, use DCHECK_EQ et al below. |
767 // The 'switch' is used to prevent the 'else' from being ambiguous when the | 771 // The 'switch' is used to prevent the 'else' from being ambiguous when the |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 #elif NOTIMPLEMENTED_POLICY == 5 | 1046 #elif NOTIMPLEMENTED_POLICY == 5 |
1043 #define NOTIMPLEMENTED() do {\ | 1047 #define NOTIMPLEMENTED() do {\ |
1044 static bool logged_once = false;\ | 1048 static bool logged_once = false;\ |
1045 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ | 1049 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ |
1046 logged_once = true;\ | 1050 logged_once = true;\ |
1047 } while(0);\ | 1051 } while(0);\ |
1048 EAT_STREAM_PARAMETERS | 1052 EAT_STREAM_PARAMETERS |
1049 #endif | 1053 #endif |
1050 | 1054 |
1051 #endif // BASE_LOGGING_H_ | 1055 #endif // BASE_LOGGING_H_ |
OLD | NEW |