check_example.cc 1.2 KB

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