Suggestion: debug-assert that the allocator returns aligned memory #131189
Labels
A-align
Area: alignment control (`repr(align(N))` and so on)
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
If the global allocator returns unaligned memory, the standard library catches it very late. Take this code:
Because of a bug in MiMalloc, the
Vec
gets non-aligned memory.This is not discovered until
vec.as_slice
callsslice::from_raw_parts
which has a debug-assert.I spent a lot of time looking for this bug before I realized it was MiMalloc that was to blame.
I suggest we add a debug-assert the standard library to check that the allocator returns aligned memory, i.e. here:
rust/library/alloc/src/raw_vec.rs
Lines 442 to 478 in 8885239
That would then report "The global allocator returned non-aligned memory", directly pointing the user at the problem, saving a lol of time for the next person.
The text was updated successfully, but these errors were encountered: