[clang] 6d97082 - [clang][bytecode] Fix an assertion for composite array roots (#195530)
via cfe-commits
cfe-commits at lists.llvm.org
Sun May 3 09:01:22 PDT 2026
Author: Timm Baeder
Date: 2026-05-03T18:01:17+02:00
New Revision: 6d97082a3d14b800eb8ebdb805bf377b5d17354f
URL: https://github.com/llvm/llvm-project/commit/6d97082a3d14b800eb8ebdb805bf377b5d17354f
DIFF: https://github.com/llvm/llvm-project/commit/6d97082a3d14b800eb8ebdb805bf377b5d17354f.diff
LOG: [clang][bytecode] Fix an assertion for composite array roots (#195530)
The assertion only holds if the array is primitive.
Added:
Modified:
clang/lib/AST/ByteCode/Interp.cpp
clang/test/AST/ByteCode/lifetimes.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 6e93c6e88f261..8563ab8d844b7 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -2083,8 +2083,9 @@ static void setLifeStateRecurse(const Pointer &Ptr, Lifetime L) {
if (const Descriptor *FieldDesc = Ptr.getFieldDesc();
FieldDesc->isCompositeArray()) {
- // No endLifetime() for array roots.
- assert(Ptr.getLifetime() == Lifetime::Started);
+ // No endLifetime() for primitive array roots.
+ if (Ptr.getFieldDesc()->isPrimitiveArray())
+ assert(Ptr.getLifetime() == Lifetime::Started);
for (unsigned I = 0; I != FieldDesc->getNumElems(); ++I)
setLifeStateRecurse(Ptr.atIndex(I).narrow(), L);
return;
diff --git a/clang/test/AST/ByteCode/lifetimes.cpp b/clang/test/AST/ByteCode/lifetimes.cpp
index e775bed751821..a68c72e526e02 100644
--- a/clang/test/AST/ByteCode/lifetimes.cpp
+++ b/clang/test/AST/ByteCode/lifetimes.cpp
@@ -96,12 +96,10 @@ namespace CallScope {
constexpr Q *out_of_lifetime(Q q) { return &q; } // both-warning {{address of stack}} \
// both-note 2{{declared here}}
constexpr int k3 = out_of_lifetime({})->n; // both-error {{must be initialized by a constant expression}} \
- // expected-note {{read of object outside its lifetime}} \
- // ref-note {{read of object outside its lifetime}}
+ // both-note {{read of object outside its lifetime}}
constexpr int k4 = out_of_lifetime({})->f(); // both-error {{must be initialized by a constant expression}} \
- // expected-note {{member call on object outside its lifetime}} \
- // ref-note {{member call on object outside its lifetime}}
+ // both-note {{member call on object outside its lifetime}}
}
namespace ExprDoubleDestroy {
@@ -115,3 +113,12 @@ namespace ExprDoubleDestroy {
constexpr bool t = test<S>(); // both-error {{must be initialized by a constant expression}} \
// both-note {{in call to}}
}
+
+namespace CompositeArrayRootAssertion {
+ class C {
+ public:
+ bool B[2][2];
+ constexpr ~C() {}
+ };
+ void foo(int i) { C c; }
+}
More information about the cfe-commits
mailing list