[all-commits] [llvm/llvm-project] bf1bcb: [libc++] Use intptr_t instead of ptrdiff_t for mes...

Alexander Richardson via All-commits all-commits at lists.llvm.org
Fri Sep 8 06:16:16 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: bf1bcb68fc4142c792576b53866df60ead8ac501
      https://github.com/llvm/llvm-project/commit/bf1bcb68fc4142c792576b53866df60ead8ac501
  Author: Alexander Richardson <arichardson.kde at gmail.com>
  Date:   2023-09-08 (Fri, 08 Sep 2023)

  Changed paths:
    M libcxx/include/locale
    M libcxx/test/std/localization/locale.categories/category.messages/locale.messages/messages_base.pass.cpp

  Log Message:
  -----------
  [libc++] Use intptr_t instead of ptrdiff_t for messages_base::catalog

On GLibc, FreeBSD and macOS systems nl_catd is a pointer type, and
round-tripping this in a variable of ptrdiff_t is not portable.
In fact such a round-trip yields a non-dereferenceable pointer on
CHERI-enabled architectures such as Arm Morello. There pointers (and
therefore intptr_t) are twice the size of ptrdiff_t, which means casting
to ptrdiff_t strips the high (metadata) bits (as well as a hidden pointer
validity bit).

Since catalog is now guaranteed to be the same size or larger than nl_catd,
we can store all return values safely and the shifting workaround from
commit 0c68ed006d4f38c3cdcab6a565aa3e208015895f should not be needed
anymore (this is also not portable to CHERI systems on since shifting a
valid pointer right will create a massively out-of-bounds pointer that
may not be representable).

This can be fixed by using intptr_t which should be the same type as
ptrdiff_t on all currently supported architectures.

See also: https://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2028

Differential Revision: https://reviews.llvm.org/D134420

Co-authored-by: Louis Dionne <ldionne.2 at gmail.com>




More information about the All-commits mailing list