freebsd-src/contrib/llvm-project
Dimitry Andric ead8e4c081 Merge commit 382f70a877f0 from llvm-project (by Louis Dionne):
[libc++][NFC] Rewrite function call on two lines for clarity (#79141)

  Previously, there was a ternary conditional with a less-than comparison
  appearing inside a template argument, which was really confusing because
  of the <...> of the function template. This patch rewrites the same
  statement on two lines for clarity.

Merge commit d129ea8d2fa3 from llvm-project (by Vitaly Buka):

  [libcxx] Align `__recommend() + 1`  by __endian_factor (#90292)

  This is detected by asan after #83774

  Allocation size will be divided by `__endian_factor` before storing. If
  it's not aligned,
  we will not be able to recover allocation size to pass into
  `__alloc_traits::deallocate`.

  we have code like this
  ```
   auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1);
      __p               = __allocation.ptr;
      __set_long_cap(__allocation.count);

  void __set_long_cap(size_type __s) _NOEXCEPT {
      __r_.first().__l.__cap_     = __s / __endian_factor;
      __r_.first().__l.__is_long_ = true;
    }

  size_type __get_long_cap() const _NOEXCEPT {
      return __r_.first().__l.__cap_ * __endian_factor;
    }

  inline ~basic_string() {
      __annotate_delete();
      if (__is_long())
        __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
    }
  ```
  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
  (see `/ __endian_factor`)
  4. `__alloc_traits::deallocate(__alloc(), __get_long_pointer(),
  __get_long_cap())` -> uses even size (see `__get_long_cap`)

This should fix incorrect deallocation sizes for some instances of
std::string. Memory profiling or debugging tools like AddressSanitizer,
LeakSanitizer or TCMalloc could then complain about the the size passed
to a deallocation not matching the size originally passed to the
allocation.

Reported by:	Aliaksei Kandratsenka <alkondratenko@gmail.com>
PR:		279560
MFC after:	3 days
2024-06-07 20:43:46 +02:00
..
clang Merge llvm-project release/18.x llvmorg-18.1.6-0-g1118c2e05e67 2024-05-24 17:58:04 +02:00
compiler-rt Merge commit 0f329e0246d1 from llvm-project (by Dimitry Andric): 2024-04-25 18:47:47 +02:00
libcxx Merge commit 382f70a877f0 from llvm-project (by Louis Dionne): 2024-06-07 20:43:46 +02:00
libunwind Merge llvm-project main llvmorg-18-init-18359-g93248729cfae 2024-04-06 22:13:49 +02:00
lld Merge llvm-project release/18.x llvmorg-18.1.6-0-g1118c2e05e67 2024-05-24 17:58:04 +02:00
lldb Merge llvm-project main llvmorg-18-init-18359-g93248729cfae 2024-04-06 22:13:49 +02:00
llvm Merge commit 9f85bc834b07 from llvm-project (by Nikita Popov): 2024-05-30 17:35:15 +02:00
openmp Merge commit 73bb8d9d92f6 from llvm-project (by Jonathan Peyton): 2024-05-08 20:45:45 +02:00
FREEBSD-Xlist Merge llvm-project main llvmorg-18-init-18359-g93248729cfae 2024-04-06 22:13:49 +02:00