[libcxx-commits] [PATCH] D101638: [libc++] std::to_address mustn't depend on P::element_type.

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun May 2 11:09:52 PDT 2021


Quuxplusone updated this revision to Diff 342250.
Quuxplusone edited the summary of this revision.
Quuxplusone added a comment.

  [libc++] Prefer __to_address(it) over addressof(*it), for UBSAN's benefit.
  
  UBSAN doesn't like `addressof(*it)` when `it` is positioned one-past-the-end
  of an array, because that expression binds a reference to a non-object.
  On the other hand, we have an overload of `__to_address` for raw pointer types
  that Just Works; and we can expect that any user-provided fancy pointer type
  will implement `operator->` so that `__to_address` will work just as well
  (or better) than `operator*`.
  
  This fixes a UBSAN failure in the previous commit's new test:
  
      iterator:1343:42: runtime error: reference binding to address 0x[...]
      with insufficient space for an object of type 'const char'
      [...]
        in std::__1::__wrap_iter<char const*>::operator->() const
        in std::__1::__to_address_helper<false>
        in std::__1::__to_address<std::__1::__wrap_iter<char const*> >
        in auto std::__1::to_address<std::__1::__wrap_iter<char const*> >
        in void test_container_iterators<std::__1::span<char const> >


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101638/new/

https://reviews.llvm.org/D101638

Files:
  libcxx/include/__memory/pointer_traits.h
  libcxx/include/iterator
  libcxx/test/libcxx/utilities/memory/pointer.conversion/to_address.pass.cpp
  libcxx/test/libcxx/utilities/memory/pointer.conversion/to_address_std_iterators.pass.cpp
  libcxx/test/std/utilities/memory/pointer.conversion/to_address.pass.cpp
  libcxx/test/std/utilities/memory/pointer.conversion/to_address_std_iterators.pass.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101638.342250.patch
Type: text/x-patch
Size: 12598 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210502/205688d1/attachment-0001.bin>


More information about the libcxx-commits mailing list