[libcxx-commits] [PATCH] D143327: [libc++] Introduce __is_pointer_in_range

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Feb 14 02:09:55 PST 2023


philnik added inline comments.


================
Comment at: libcxx/include/__utility/is_pointer_in_range.h:50
+
+  auto __t_ptr = reinterpret_cast<const _Tp*>(__ptr);
+  return __begin <= __t_ptr && __t_ptr < __end;
----------------
Mordante wrote:
> philnik wrote:
> > Mordante wrote:
> > > Is this really safe on all supported platforms?
> > I think it should be. Do you have anything specific in mind?
> You can compare integral types with different sizes, but you can't just cast pointers from one to another.
> 
> Concretely I wonder whether we violate alignment rules.
> For example`_Tp == int`, `_Up = signed char` and `__ptr = 0xFFF01`. This will create a `const int*` at an odd numbered address. (This is valid on x86, but that platform has less alignment restrictions than other platforms.)
Yeah, I'm not sure. Casting all pointers to `char` should make it safe.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143327



More information about the libcxx-commits mailing list