1 // Copyright 2020 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 
5 #ifndef THIRD_PARTY_BASE_CHECK_H_
6 #define THIRD_PARTY_BASE_CHECK_H_
7 
8 #include <assert.h>
9 
10 #include "build/build_config.h"
11 #include "third_party/base/compiler_specific.h"
12 #include "third_party/base/immediate_crash.h"
13 
14 #define CHECK(condition)          \
15   do {                            \
16     if (UNLIKELY(!(condition))) { \
17       IMMEDIATE_CRASH();          \
18     }                             \
19   } while (0)
20 
21 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
22 #define DCHECK_IS_ON() 0
23 #else
24 #define DCHECK_IS_ON() 1
25 #endif
26 
27 // Debug mode: Use assert() for better diagnostics
28 // Release mode, DCHECK_ALWAYS_ON: Use CHECK() since assert() is a no-op.
29 // Release mode, no DCHECK_ALWAYS_ON: Use assert(), which is a no-op.
30 #if defined(NDEBUG) && defined(DCHECK_ALWAYS_ON)
31 #define DCHECK CHECK
32 #else
33 #define DCHECK assert
34 #endif
35 
36 #endif  // THIRD_PARTY_BASE_CHECK_H_
37