In spite of commit af3f2f9168fc0f2345c23d8c8b34a73563935834 (fix assertions and warnings on gcc), I get this warning
.../src/segment.c: In function 'mi_segment_span_free_coalesce':
.../src/segment.c:665:30: warning: '__atomic_load_8' writing 8 bytes into a region of size 0 overflows the destination [-Wstringop-overflow=]
665 | const bool is_abandoned = (segment->thread_id == 0); // mi_segment_is_abandoned(segment);
| ^~~
when compiling with GCC 12.3.1. The reason: the compiler thinks that segment might be NULL (_mi_ptr_segment explicitly returns NULL in some cases). So I suggest this patch, which moves the call to mi_segment_is_abandoned a few lines later, after segment has been dereferenced (so the compiler knows that segment can't be NULL):
// for huge pages, just mark as free but don't add to the queues
if (segment->kind == MI_SEGMENT_HUGE) {
@@ -675,6 +674,7 @@ static mi_slice_t mi_segment_span_free_coalesce(mi_slice_t slice, misegments
}
// otherwise coalesce the span and add to the free span queues
In spite of commit af3f2f9168fc0f2345c23d8c8b34a73563935834 (fix assertions and warnings on gcc), I get this warning
.../src/segment.c: In function 'mi_segment_span_free_coalesce': .../src/segment.c:665:30: warning: '__atomic_load_8' writing 8 bytes into a region of size 0 overflows the destination [-Wstringop-overflow=] 665 | const bool is_abandoned = (segment->thread_id == 0); // mi_segment_is_abandoned(segment); | ^
~~when compiling with GCC 12.3.1. The reason: the compiler thinks that segment might be NULL (_mi_ptr_segment explicitly returns NULL in some cases). So I suggest this patch, which moves the call to mi_segment_is_abandoned a few lines later, after segment has been dereferenced (so the compiler knows that segment can't be NULL):
--- a/src/segment.c +++ b/src/segment.c @@ -662,7 +662,6 @@ static void mi_segment_span_remove_from_queue(mi_slice_t slice, mi_segments_tld static mi_slice_t mi_segment_span_free_coalesce(mi_slice_t slice, mi_segments_tld_t tld) { mi_assert_internal(slice != NULL && slice->slice_count > 0 && slice->slice_offset == 0); mi_segment_t* const segment = _mi_ptr_segment(slice);
const bool is_abandoned = (segment->thread_id == 0); // mi_segment_is_abandoned(segment);
// for huge pages, just mark as free but don't add to the queues if (segment->kind == MI_SEGMENT_HUGE) { @@ -675,6 +674,7 @@ static mi_slice_t mi_segment_span_free_coalesce(mi_slice_t slice, misegments }
// otherwise coalesce the span and add to the free span queues