We use a bump pointer to implement malloc for the hermetic tests.
Currently, we bump the pointer up by any amount. This means that calling
malloc(1) will misalign the buffer so any following malloc(8)
accesses will not be aligned. This causes problems in architectures
which require alignment.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
libc/test/UnitTest/HermeticTestUtils.cpp | ||
---|---|---|
68 | Is it 8 that we want or is it alignof(uintptr_t)? |
libc/test/UnitTest/HermeticTestUtils.cpp | ||
---|---|---|
68 | Eight is just a good number. I think to be consistent with most implementations of malloc it's alignof(long double) or something. But I could change it to use that number since it's clearer to say "We want alignment for at least a 64-bit type" |
Using alignof(long double) is the best I think. Feel free to change to it.
libc/test/UnitTest/HermeticTestUtils.cpp | ||
---|---|---|
68 | Nit: If you want to do long double, you should use a convenience var: constexpr size_t ALIGNMENT = aligngof(long double); |
Was somewhat concerned using long double since it would double the wasted space for most tests. I wonder if it's possible to run asan or ubsan on the hermetic tests to catch stuff like this.
Is it 8 that we want or is it alignof(uintptr_t)?