[libcxx-commits] [libcxx] [libcxx] Align allocation to match `__set_long_cap` and `__get_long_cap` (PR #90292)
Vitaly Buka via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Apr 30 10:41:53 PDT 2024
vitalybuka wrote:
> > > AFAICT we always return `__align_it() - 1` from `__recommend` though? Adding 1 would bring us back to an aligned size. (Don't ask me why it's written this way)
> >
> >
> > The assert inserted there confirms that it's not true in some cases, on check-cxx, even without sanitizers.
>
> Ok, then what am I missing?
Sorry, maybe we are discussing different things.
Are you questioning particular case? Some __align_it<> from this patch may be unnecessary.
but most stuff like this:
```
auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1);
__p = __allocation.ptr;
__begin_lifetime(__p, __allocation.count);
__set_long_pointer(__p);
__set_long_cap(__allocation.count);
__set_long_size(__sz);
```
1. __recommend() -> even size
2. std::__allocate_at_least(__alloc(), __recommend(__sz) + 1) - > not even size
3. __set_long_cap() - > lose one bit of size for __endian_factor == 2
4. __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); -> uses even size
https://github.com/llvm/llvm-project/pull/90292
More information about the libcxx-commits
mailing list