xref: /aosp_15_r20/external/libchrome/base/check_example.cc (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker // This file is meant for analyzing the code generated by the CHECK
6*635a8641SAndroid Build Coastguard Worker // macros in a small executable file that's easy to disassemble.
7*635a8641SAndroid Build Coastguard Worker 
8*635a8641SAndroid Build Coastguard Worker #include "base/compiler_specific.h"
9*635a8641SAndroid Build Coastguard Worker #include "base/logging.h"
10*635a8641SAndroid Build Coastguard Worker 
11*635a8641SAndroid Build Coastguard Worker // An official build shouldn't generate code to print out messages for
12*635a8641SAndroid Build Coastguard Worker // the CHECK* macros, nor should it have the strings in the
13*635a8641SAndroid Build Coastguard Worker // executable. It is also important that the CHECK() function collapse to the
14*635a8641SAndroid Build Coastguard Worker // same implementation as RELEASE_ASSERT(), in particular on Windows x86.
15*635a8641SAndroid Build Coastguard Worker // Historically, the stream eating caused additional unnecessary instructions.
16*635a8641SAndroid Build Coastguard Worker // See https://crbug.com/672699.
17*635a8641SAndroid Build Coastguard Worker 
18*635a8641SAndroid Build Coastguard Worker #define BLINK_RELEASE_ASSERT_EQUIVALENT(assertion) \
19*635a8641SAndroid Build Coastguard Worker   (UNLIKELY(!(assertion)) ? (IMMEDIATE_CRASH()) : (void)0)
20*635a8641SAndroid Build Coastguard Worker 
DoCheck(bool b)21*635a8641SAndroid Build Coastguard Worker void DoCheck(bool b) {
22*635a8641SAndroid Build Coastguard Worker   CHECK(b) << "DoCheck " << b;
23*635a8641SAndroid Build Coastguard Worker }
24*635a8641SAndroid Build Coastguard Worker 
DoBlinkReleaseAssert(bool b)25*635a8641SAndroid Build Coastguard Worker void DoBlinkReleaseAssert(bool b) {
26*635a8641SAndroid Build Coastguard Worker   BLINK_RELEASE_ASSERT_EQUIVALENT(b);
27*635a8641SAndroid Build Coastguard Worker }
28*635a8641SAndroid Build Coastguard Worker 
DoCheckEq(int x,int y)29*635a8641SAndroid Build Coastguard Worker void DoCheckEq(int x, int y) {
30*635a8641SAndroid Build Coastguard Worker   CHECK_EQ(x, y);
31*635a8641SAndroid Build Coastguard Worker }
32*635a8641SAndroid Build Coastguard Worker 
main(int argc,const char * argv[])33*635a8641SAndroid Build Coastguard Worker int main(int argc, const char* argv[]) {
34*635a8641SAndroid Build Coastguard Worker   DoCheck(argc > 1);
35*635a8641SAndroid Build Coastguard Worker   DoCheckEq(argc, 1);
36*635a8641SAndroid Build Coastguard Worker   DoBlinkReleaseAssert(argc > 1);
37*635a8641SAndroid Build Coastguard Worker }
38