Skip to content

Commit 062f954

Browse files
pboscopybara-github
authored andcommitted
Replace CHECK(false) in base/
In most cases NOTREACHED() is now a better option. Also performs dead-code removal. Bug: 40122554, 40580068 Change-Id: I5d0ef0b0c05a913a040905f7bebbbbf22985fef8 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6011172 Reviewed-by: Lei Zhang <[email protected]> Commit-Queue: Peter Boström <[email protected]> Code-Coverage: [email protected] <[email protected]> Cr-Commit-Position: refs/heads/main@{#1382693} NOKEYCHECK=True GitOrigin-RevId: 541196559fa83bb1abe11cedbca23d410a8b00d9
1 parent 0aea308 commit 062f954

23 files changed

+55
-53
lines changed

allocator/partition_allocator/src/partition_alloc/partition_alloc_base/debug/alias.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace partition_alloc::internal::base::debug {
3535
// strncpy(name_copy, p->name, sizeof(name_copy)-1);
3636
// name_copy[sizeof(name_copy)-1] = '\0';;
3737
// base::debug::alias(name_copy);
38-
// CHECK(false);
38+
// NOTREACHED();
3939
//
4040
// Case #2: Prevent a tail call into a function. This is useful to make sure the
4141
// function containing the call to base::debug::Alias() will be present in the

allocator/partition_allocator/src/partition_alloc/partition_alloc_base/numerics/safe_conversions_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ constexpr bool kEnableAsmCode = true;
8989
constexpr bool kEnableAsmCode = false;
9090
#endif
9191

92-
// Forces a crash, like a CHECK(false). Used for numeric boundary errors.
92+
// Forces a crash, like a NOTREACHED(). Used for numeric boundary errors.
9393
// Also used in a constexpr template to trigger a compilation failure on
9494
// an error condition.
9595
struct CheckOnFailure {

barrier_callback.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "base/functional/bind.h"
1717
#include "base/functional/callback.h"
1818
#include "base/functional/callback_helpers.h"
19+
#include "base/notreached.h"
1920
#include "base/synchronization/lock.h"
2021
#include "base/thread_annotations.h"
2122

@@ -55,7 +56,7 @@ class BarrierCallbackInfo {
5556

5657
template <typename T>
5758
void ShouldNeverRun(T t) {
58-
CHECK(false);
59+
NOTREACHED();
5960
}
6061

6162
} // namespace internal

barrier_callback_unittest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ TEST(BarrierCallbackTest, ErrorToCallCallbackWithZeroCallbacks) {
2929
base::BarrierCallback<int>(0, base::BindOnce([](std::vector<int>) {}));
3030
EXPECT_FALSE(barrier_callback.is_null());
3131

32-
EXPECT_CHECK_DEATH(barrier_callback.Run(3));
32+
EXPECT_NOTREACHED_DEATH(barrier_callback.Run(3));
3333
}
3434

3535
TEST(BarrierCallbackTest, RunAfterNumCallbacks) {

barrier_closure.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "base/atomic_ref_count.h"
1010
#include "base/functional/bind.h"
1111
#include "base/memory/ptr_util.h"
12+
#include "base/notreached.h"
1213
#include "base/numerics/safe_conversions.h"
1314

1415
namespace base {
@@ -38,7 +39,7 @@ void BarrierInfo::Run() {
3839
}
3940

4041
void ShouldNeverRun() {
41-
CHECK(false);
42+
NOTREACHED();
4243
}
4344

4445
} // namespace

barrier_closure_unittest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ TEST(BarrierClosureTest, ChecksIfCalledForZeroClosures) {
2626
base::BarrierClosure(0, base::DoNothing());
2727
EXPECT_FALSE(barrier_closure.is_null());
2828

29-
EXPECT_CHECK_DEATH(barrier_closure.Run());
29+
EXPECT_NOTREACHED_DEATH(barrier_closure.Run());
3030
}
3131

3232
TEST(BarrierClosureTest, RunAfterNumClosures) {

debug/alias.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace debug {
3333
// int last_error = err_;
3434
// base::debug::Alias(&last_error);
3535
// DEBUG_ALIAS_FOR_CSTR(name_copy, p->name, 16);
36-
// CHECK(false);
36+
// NOTREACHED();
3737
//
3838
// Case #2: Prevent a tail call into a function. This is useful to make sure the
3939
// function containing the call to base::debug::Alias() will be present in the

debug/asan_invalid_access.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "base/check.h"
1717
#include "base/debug/alias.h"
18+
#include "base/immediate_crash.h"
1819
#include "build/build_config.h"
1920

2021
#if BUILDFLAG(IS_WIN)
@@ -47,8 +48,9 @@ NOINLINE void CorruptMemoryBlock(bool induce_crash) {
4748
LONG volatile dummy = InterlockedIncrementFn(array - 1);
4849
base::debug::Alias(const_cast<LONG*>(&dummy));
4950

50-
if (induce_crash)
51-
CHECK(false);
51+
if (induce_crash) {
52+
base::ImmediateCrash();
53+
}
5254
delete[] array;
5355
}
5456
#endif // BUILDFLAG(IS_WIN) && defined(ADDRESS_SANITIZER)

debug/gdi_debug_util_win.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "base/debug/alias.h"
1818
#include "base/logging.h"
19+
#include "base/notreached.h"
1920
#include "base/process/process.h"
2021
#include "base/win/scoped_handle.h"
2122
#include "base/win/win_util.h"
@@ -369,7 +370,7 @@ NOINLINE DWORD GetNumGdiHandles() {
369370
if (num_gdi_handles == 0) {
370371
DWORD get_gui_resources_error = GetLastError();
371372
base::debug::Alias(&get_gui_resources_error);
372-
CHECK(false);
373+
NOTREACHED();
373374
}
374375
return num_gdi_handles;
375376
}
@@ -426,7 +427,7 @@ void CollectChildGDIUsageAndDie(DWORD parent_pid) {
426427
} while (Process32Next(snapshot, &proc_entry));
427428

428429
CloseHandle(snapshot);
429-
CHECK(false);
430+
NOTREACHED();
430431
}
431432

432433
} // namespace

debug/invalid_access_win.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <stdlib.h>
1616

1717
#include "base/check.h"
18+
#include "base/notreached.h"
1819
#include "build/build_config.h"
1920

2021
namespace base {
@@ -65,7 +66,7 @@ void TerminateWithHeapCorruption() {
6566
HeapDestroy(heap);
6667
} __except (EXCEPTION_EXECUTE_HANDLER) {
6768
// Heap corruption exception should never be caught.
68-
CHECK(false);
69+
NOTREACHED();
6970
}
7071
// Should never reach here.
7172
abort();
@@ -80,7 +81,7 @@ void TerminateWithControlFlowViolation() {
8081
IndirectCall(&func);
8182
} __except (EXCEPTION_EXECUTE_HANDLER) {
8283
// CFG fast fail should never be caught.
83-
CHECK(false);
84+
NOTREACHED();
8485
}
8586
// Should only reach here if CFG is disabled.
8687
abort();

0 commit comments

Comments
 (0)