Skip to content

Commit 758a4ee

Browse files
pboschromeos-ci-prod
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} CrOS-Libchrome-Original-Commit: 541196559fa83bb1abe11cedbca23d410a8b00d9
1 parent cf8dbb5 commit 758a4ee

File tree

20 files changed

+45
-43
lines changed

20 files changed

+45
-43
lines changed

base/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

base/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 {

base/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

base/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) {

base/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

base/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) {

base/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

base/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)

base/logging.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,11 +638,11 @@ namespace {
638638
const char* buf_start,
639639
const char* prefix_end,
640640
const char* buf_end) {
641-
// This simulates a CHECK(false) at file:line instead of here. This is used
641+
// This simulates a NOTREACHED() at file:line instead of here. This is used
642642
// instead of base::ImmediateCrash() to give better error messages locally
643643
// (printed stack for one).
644644
LogMessageFatal(file, line, LOGGING_FATAL).stream()
645-
<< "Check failed: false. " << prefix_end;
645+
<< "NOTREACHED hit. " << prefix_end;
646646
}
647647

648648
} // namespace

base/memory/aligned_memory.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <bit>
88

9+
#include "base/check.h"
910
#include "base/check_op.h"
1011
#include "base/logging.h"
1112
#include "build/build_config.h"
@@ -41,11 +42,9 @@ void* AlignedAlloc(size_t size, size_t alignment) {
4142
// Since aligned allocations may fail for non-memory related reasons, force a
4243
// crash if we encounter a failed allocation; maintaining consistent behavior
4344
// with a normal allocation failure in Chrome.
44-
if (!ptr) {
45-
DLOG(ERROR) << "If you crashed here, your aligned allocation is incorrect: "
46-
<< "size=" << size << ", alignment=" << alignment;
47-
CHECK(false);
48-
}
45+
CHECK(ptr) << "If you crashed here, your aligned allocation is incorrect: "
46+
<< "size=" << size << ", alignment=" << alignment;
47+
4948
// Sanity check alignment just to be safe.
5049
DCHECK(IsAligned(ptr, alignment));
5150
return ptr;

0 commit comments

Comments
 (0)