| Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors |
| [email protected] | ddb9b33 | 2011-12-02 07:31:09 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // This file is meant for analyzing the code generated by the CHECK |
| 6 | // macros in a small executable file that's easy to disassemble. |
| 7 | |
| Hans Wennborg | c3cffa6 | 2020-04-27 10:09:12 | [diff] [blame] | 8 | #include <ostream> |
| 9 | |
| 10 | #include "base/check_op.h" |
| scottmg | 3c957a5 | 2016-12-10 20:57:59 | [diff] [blame] | 11 | #include "base/compiler_specific.h" |
| [email protected] | ddb9b33 | 2011-12-02 07:31:09 | [diff] [blame] | 12 | |
| 13 | // An official build shouldn't generate code to print out messages for |
| 14 | // the CHECK* macros, nor should it have the strings in the |
| scottmg | 3c957a5 | 2016-12-10 20:57:59 | [diff] [blame] | 15 | // executable. It is also important that the CHECK() function collapse to the |
| 16 | // same implementation as RELEASE_ASSERT(), in particular on Windows x86. |
| 17 | // Historically, the stream eating caused additional unnecessary instructions. |
| 18 | // See https://crbug.com/672699. |
| 19 | |
| 20 | #define BLINK_RELEASE_ASSERT_EQUIVALENT(assertion) \ |
| Peter Kasting | fa48899 | 2024-08-06 07:48:14 | [diff] [blame] | 21 | if (!(assertion)) [[unlikely]] { \ |
| 22 | base::ImmediateCrash(); \ |
| 23 | } |
| [email protected] | ddb9b33 | 2011-12-02 07:31:09 | [diff] [blame] | 24 | |
| 25 | void DoCheck(bool b) { |
| 26 | CHECK(b) << "DoCheck " << b; |
| 27 | } |
| 28 | |
| scottmg | 3c957a5 | 2016-12-10 20:57:59 | [diff] [blame] | 29 | void DoBlinkReleaseAssert(bool b) { |
| 30 | BLINK_RELEASE_ASSERT_EQUIVALENT(b); |
| 31 | } |
| 32 | |
| [email protected] | ddb9b33 | 2011-12-02 07:31:09 | [diff] [blame] | 33 | void DoCheckEq(int x, int y) { |
| 34 | CHECK_EQ(x, y); |
| 35 | } |
| 36 | |
| 37 | int main(int argc, const char* argv[]) { |
| 38 | DoCheck(argc > 1); |
| 39 | DoCheckEq(argc, 1); |
| scottmg | 3c957a5 | 2016-12-10 20:57:59 | [diff] [blame] | 40 | DoBlinkReleaseAssert(argc > 1); |
| [email protected] | ddb9b33 | 2011-12-02 07:31:09 | [diff] [blame] | 41 | } |