Skip to content

Commit 5e31187

Browse files
mjp41Copilot
andcommitted
Recover CI fixes that resist folding into natural targets
Three semantic CI fixes whose intent doesn't translate back into the historical APIs of their natural target commits: * sizeclasstable.h: restore sentinel slot's slab_mask = ~size_t(0) so the bounds-checked memcpy shim treats foreign pointers as unbounded and any memcpy bound check trivially passes the sentinel through to the destination's native checks. * arena.cc: replace the indirect mock_index probe in can_consolidate with an explicit in-range guard so GCC's release-mode -Warray-bounds analysis sees a visible guard covering the mock_store[] read. * largearenarange.cc: pass MinBaseSizeBits<Pal>() as the MIN_REFILL_SIZE_BITS template arg so PalRange has enough to reserve on Windows. Also rolls in small clang-format-15 drift and a stray duplicate include that surfaced after re-targeting the bulk of the original CI fix into the commits that introduced each affected line. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0ccaee9 commit 5e31187

8 files changed

Lines changed: 18 additions & 17 deletions

File tree

src/snmalloc/backend_helpers/inplacerep.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,7 @@ namespace snmalloc
234234
static ArenaVariant get_variant(uintptr_t addr)
235235
{
236236
auto w = unit_at<0>(addr)->word_one;
237-
return static_cast<ArenaVariant>(
238-
(w & VARIANT_MASK) >> VARIANT_SHIFT);
237+
return static_cast<ArenaVariant>((w & VARIANT_MASK) >> VARIANT_SHIFT);
239238
}
240239

241240
static void set_variant(uintptr_t addr, ArenaVariant v)

src/snmalloc/ds/sizeclasstable.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,13 +420,16 @@ namespace snmalloc
420420
constexpr SizeClassTable sizeclass_metadata = SizeClassTable();
421421
422422
// Sentinel must remain zero-initialised so fast-path lookups via
423-
// `start(sc)` return zero size and slab_mask without a branch.
423+
// `start(sc)` return zero size without a branch. Slab_mask is
424+
// `~size_t(0)` so foreign-pointer `remaining_bytes` underflows to a
425+
// huge value (see `SizeClassTable::SizeClassTable`).
424426
static_assert(
425427
sizeclass_metadata.start(sizeclass_t{}).size == 0,
426428
"sentinel slot must have size 0");
427429
static_assert(
428-
sizeclass_metadata.start(sizeclass_t{}).slab_mask == 0,
429-
"sentinel slot must have slab_mask 0");
430+
sizeclass_metadata.start(sizeclass_t{}).slab_mask == ~size_t(0),
431+
"sentinel slot must have slab_mask ~0 for foreign-pointer "
432+
"remaining_bytes underflow");
430433
431434
static_assert(
432435
bits::BITS - sizeclass_metadata.DIV_MULT_SHIFT <= MAX_CAPACITY_BITS);

src/test/func/aligned_dealloc/aligned_dealloc.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "test/snmalloc_testlib.h"
2323

2424
#include <iostream>
25-
#include "test/snmalloc_testlib.h"
2625

2726
using namespace snmalloc;
2827

src/test/func/arena/arena.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,11 @@ namespace snmalloc
202202

203203
// Mirrors PagemapRep::can_consolidate, which reads
204204
// entry.is_boundary() from the pagemap. The boundary flag lives
205-
// per-chunk in mock_store; mock_index asserts the index is in
206-
// range, so any caller that probes outside the arena trips the
207-
// assertion — this catches accidental out-of-region probes in
208-
// Arena unit tests rather than as a release-build
209-
// segfault.
205+
// per-chunk in mock_store. An out-of-region probe returns false
206+
// (cannot consolidate) — both because that is the right semantic
207+
// (no neighbour exists outside the arena) and because it gives
208+
// GCC's release-mode `-Warray-bounds` analysis a visible guard
209+
// covering the `mock_store[...]` read on this branch.
210210
static bool can_consolidate(uintptr_t addr)
211211
{
212212
size_t idx = addr >> MIN_CHUNK_BITS;
@@ -1472,6 +1472,7 @@ namespace snmalloc
14721472

14731473
auto r1 = arena.remove_block(chunk_size(4));
14741474
SNMALLOC_ASSERT(r1 == top_addr);
1475+
UNUSED(r1);
14751476

14761477
printf(" Block at arena top edge: OK\n");
14771478
}

src/test/func/arenabins/arenabins.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,7 @@ namespace
542542
/// (defined directly in terms of `bin_subsets`).
543543
template<size_t B>
544544
size_t reference_find(
545-
size_t n_chunks,
546-
const typename ArenaBinsTestAccess<B, 0>::Bitmap& bm)
545+
size_t n_chunks, const typename ArenaBinsTestAccess<B, 0>::Bitmap& bm)
547546
{
548547
using Bins = ArenaBinsTestAccess<B, 0>;
549548
using Bitmap = typename Bins::Bitmap;

src/test/func/large_offset_frontend/large_offset_frontend.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
#include <iostream>
3434
#include <snmalloc/snmalloc.h>
35-
#include "test/setup.h"
3635

3736
#ifdef assert
3837
# undef assert

src/test/func/largearenarange/largearenarange.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ namespace
5353
static constexpr size_t MAX_BITS = bits::BITS - 1;
5454
static constexpr size_t MIN_REFILL_BITS = MinBaseSizeBits<Pal>();
5555

56-
using ArenaRange =
57-
Pipe<ParentSource, LargeArenaRange<REFILL_BITS, MAX_BITS, TestPagemap>>;
56+
using ArenaRange = Pipe<
57+
ParentSource,
58+
LargeArenaRange<REFILL_BITS, MAX_BITS, TestPagemap, MIN_REFILL_BITS>>;
5859

5960
// --- Tests ---
6061

src/test/func/smallarenarange/smallarenarange.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#include <map>
1919
#include <new>
2020
#include <set>
21-
#include <snmalloc/backend_helpers/authmap.h>
2221
#include <snmalloc/backend_helpers/arena.h>
22+
#include <snmalloc/backend_helpers/authmap.h>
2323
#include <snmalloc/backend_helpers/inplacerep.h>
2424
#include <snmalloc/backend_helpers/smallarenarange.h>
2525
#include <vector>

0 commit comments

Comments
 (0)