[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 13:34:22 PDT 2024


vitalybuka wrote:

> I've looked into this a bit more and it turns out that we have two unrelated bugs in `__recommend`. First, we add one if `__guess == __min_cap`, and second our minimum alignment we give to `__align_it` is one, instead of the `__endian_factor`.
> 
> I think
> 
> ```diff
> diff --git a/libcxx/include/string b/libcxx/include/string
> index 883bc1d7e5dc..13af92fbce3c 100644
> --- a/libcxx/include/string
> +++ b/libcxx/include/string
> @@ -1959,10 +1959,10 @@ private:
>      if (__s < __min_cap) {
>        return static_cast<size_type>(__min_cap) - 1;
>      }
> -    const size_type __boundary = sizeof(value_type) < __alignment ? __alignment / sizeof(value_type) : 1;
> +    const size_type __boundary = sizeof(value_type) < __alignment ? __alignment / sizeof(value_type) : __endian_factor;
>      size_type __guess          = __align_it<__boundary>(__s + 1) - 1;
>      if (__guess == __min_cap)
> -      ++__guess;
> +      __guess += 2;
>      return __guess;
>    }
> ```
> 
> should fix the issues you're seeing.

My last reply written before reading this, but looks like they are consistent.

https://github.com/llvm/llvm-project/pull/90292


More information about the libcxx-commits mailing list