[libcxx-commits] [libcxx] [libc++] P2590R2: Explicit lifetime management (PR #107206)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Wed Sep 4 03:21:15 PDT 2024


================
@@ -0,0 +1,47 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___MEMORY_START_LIFETIME_AS_ARRAY_H
+#define _LIBCPP___MEMORY_START_LIFETIME_AS_ARRAY_H
+
+#include <__config>
+#include <__memory/start_lifetime_as.h>
+#include <cstddef>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* start_lifetime_as_array(void* __p, [[maybe_unused]] size_t __n) _NOEXCEPT {
+  return static_cast<_Tp*>(__p);
----------------
frederick-vs-ja wrote:

> When the compiler sees a call to this function,

Currently, I'm not seeing anything in the source code of Clang or GCC that recognizes `start_lifetime_as(_array)`. So I can't believe this approach will automatically work,

> Or is it intended something else? I am not sure, Could you explain?

I _guess_ an intrinsic like `__builitin_start_lifetime_as` (or `__builtin_tbaa_barrier`?) is expected.

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


More information about the libcxx-commits mailing list