[libcxx-commits] [clang] [libcxx] [Clang][libc++] Implement C++23 std::start_lifetime_as (P2590R2, P2679R2) (PR #196286)
Yash Verma via libcxx-commits
libcxx-commits at lists.llvm.org
Thu May 7 05:14:31 PDT 2026
My-Bad-2 wrote:
> Thank you for your patch! Please see #82776 and ensure concerns in that PR are addressed in this PR.
Thanks for pointing me to the previous PR. It appears I'm a bit late to this lol. Anyways, After reading through the patch, it appears that the author wanted to implement `__builtin_start_lifetime` as a language extension. While my current PR strictly conforms to C++23 ISO guidelines.
There were concerns about TBAA. The previous implementation used the `__builtin_launder` path for CodeGen for both builtins. I don't think that this patch has to worry about TBAA as `Sema` validates that the element type (or base type) is implicit-lifetime and implicit-lifetime objects don't have to worry about vptr or vtables. Though, I'm not sure if `__builtin_start_lifetime_as` should be extended to support non-implicit types. It'll be appreciated if someone provides a second-opinion on this matter. Perhaps, it can be implemented as a flag in the builtin itself such that `std::start_lifetime_as` doesn't introduce instantiation overhead. Clang could handle code generation (and address TBAA concerns) internally. I'm thinking of something like:
```cpp
__builtin_start_lifetime_as((T*)ptr, Strict=True/False);
```
Another concern raised in the previous patch was about supporting the array version of start_lifetime. This patch does address this concern as `Sema` strips away array dimensions before checking the Base element type. #82776 requires libc++ to type-check, library maintainers might have to write recursive template traits to strip away array dimensions.
https://github.com/llvm/llvm-project/pull/196286
More information about the libcxx-commits
mailing list