[libcxx-commits] [libcxx] [libc++] Pass type information down to __libcpp_allocate (PR #118837)

Hans Wennborg via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jan 28 05:54:47 PST 2025


================
@@ -47,52 +49,58 @@ _LIBCPP_HIDE_FROM_ABI void __libcpp_operator_delete(_Args... __args) _NOEXCEPT {
 #endif
 }
 
-inline _LIBCPP_HIDE_FROM_ABI void* __libcpp_allocate(size_t __size, size_t __align) {
+template <class _Tp>
+inline _LIBCPP_HIDE_FROM_ABI _Tp* __libcpp_allocate(__element_count __n, size_t __align = _LIBCPP_ALIGNOF(_Tp)) {
+  size_t __size = static_cast<size_t>(__n) * sizeof(_Tp);
 #if _LIBCPP_HAS_ALIGNED_ALLOCATION
   if (__is_overaligned_for_new(__align)) {
     const align_val_t __align_val = static_cast<align_val_t>(__align);
-    return __libcpp_operator_new(__size, __align_val);
+    return static_cast<_Tp*>(std::__libcpp_operator_new(__size, __align_val));
   }
 #endif
 
   (void)__align;
-  return __libcpp_operator_new(__size);
+  return static_cast<_Tp*>(std::__libcpp_operator_new(__size));
----------------
zmodem wrote:

We're hitting CFI errors for this cast (see https://crbug.com/392652315), which I suppose is expected since it's casting a pointer to uninitialized memory(?). Should `__libcpp_allocate` have a `_LIBCPP_NO_CFI` attribute?

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


More information about the libcxx-commits mailing list