From 574b6e3cb8006e4d71668886f6294524e564fd8c Mon Sep 17 00:00:00 2001 From: Chris Kennelly Date: Mon, 10 Aug 2026 09:12:09 -0700 Subject: [PATCH] Elide zero checks in absl::bit_width. Spans with no allocated objects are deallocated. PiperOrigin-RevId: 962190216 --- tcmalloc/central_freelist.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tcmalloc/central_freelist.h b/tcmalloc/central_freelist.h index e93f2b28f..59faed8f1 100644 --- a/tcmalloc/central_freelist.h +++ b/tcmalloc/central_freelist.h @@ -737,6 +737,9 @@ inline int CentralFreeList::RemoveRange(absl::Span batch) { } const uint16_t prev_allocated = span->Allocated(); +#ifndef TCMALLOC_INTERNAL_LEGACY_LOCKING + ASSUME(prev_allocated > 0); +#endif const uint8_t prev_bitwidth = absl::bit_width(prev_allocated); TC_ASSERT_EQ(prev_index, span->nonempty_index()); #ifdef TCMALLOC_INTERNAL_LEGACY_LOCKING @@ -753,8 +756,7 @@ inline int CentralFreeList::RemoveRange(absl::Span batch) { ASSUME(result < size); #endif int here = span->FreelistPopBatch(batch.subspan(result), object_size); - // TODO(b/451807659): Return this to an assert after debugging is done. - TC_CHECK_GT(here, 0, "Failed to make progress. Freelist corrupted?"); + ASSUME(here > 0 && "Failed to make progress. Freelist corrupted?"); // As the objects are being popped from the span, its utilization might // change. So, we remove the stale utilization from the histogram here and // add it again once we pop the objects.