Author: Timm Baeder Date: 2026-10-20T08:19:55+02:00 New Revision: 4cafedea923a996e77b91375ffd66dc28a87bf80
URL: https://github.com/llvm/llvm-project/commit/4cafedea923a996e77b91375ffd66dc28a87bf80 DIFF: https://github.com/llvm/llvm-project/commit/4cafedea923a996e77b91375ffd66dc28a87bf80.diff LOG: [clang][bytecode] Fix `Pointer::getLifetime()` for non-primitive array elements (#232605) This code path is not reached for pointers to non-primitive array elements in regular evaluation, but we do call `getLifetime()` for random pointers in `__builtin_is_within_lifetime`. Added: Modified: clang/lib/AST/ByteCode/Pointer.cpp clang/test/AST/ByteCode/cxx23.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp index 41ae8be8e782f..cd2d7df17a532 100644 --- a/clang/lib/AST/ByteCode/Pointer.cpp +++ b/clang/lib/AST/ByteCode/Pointer.cpp @@ -768,7 +768,7 @@ Lifetime PtrView::getLifetime() const { if (Base < sizeof(InlineDescriptor)) return Lifetime::Started; - if (inArray() && !isArrayRoot()) { + if (inPrimitiveArray() && !isArrayRoot()) { InitMapPtr &IM = getInitMap(); if (!IM.hasInitMap()) { diff --git a/clang/test/AST/ByteCode/cxx23.cpp b/clang/test/AST/ByteCode/cxx23.cpp index e011aef22031b..ec6f7fe57cd55 100644 --- a/clang/test/AST/ByteCode/cxx23.cpp +++ b/clang/test/AST/ByteCode/cxx23.cpp @@ -702,4 +702,16 @@ namespace InvalidRecord { static_assert(foo(B{1, 2, 3}), ""); } + +namespace WithinLifetime { + struct S {}; + constexpr int f(int n) { + S *s = new S[n]; // all-note {{declared here}} + if (__builtin_is_within_lifetime(s)) { // all-error {{call to consteval function '__builtin_is_within_lifetime' is not a constant expression}} \ + // all-note {{read of non-constexpr variable 's' is not allowed in a constant expression}} + } + } // all-note {{control reached end of constexpr function}} + static_assert(f(42), ""); // all-error {{not an integral constant expression}} \ + // all-note {{in call to}} +} #endif _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
