<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/147528>147528</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Bytecode Interpreter: Primtive arrays do not have per-element lifetime information
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:frontend,
clang:bytecode
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tbaederr
</td>
</tr>
</table>
<pre>
Similar to their `InitMap`.
To see this in action, we have to apply
```diff
--- i/clang/lib/AST/ByteCode/Compiler.cpp
+++ w/clang/lib/AST/ByteCode/Compiler.cpp
@@ -5008,7 +5008,8 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
if (!this->emitCheckPseudoDtor(E))
return false;
const Expr *Base = PD->getBase();
- if (!Base->isGLValue())
+ // if (!Base->isGLValue())
+ if (classify(Base) != PT_Ptr)
return this->discard(Base);
if (!this->visit(Base))
return false;
```
See:
```c++
#define assert_alive(l) if (!__builtin_is_within_lifetime(&l)) (void)(1/0);
#define assert_dead(l) if ( __builtin_is_within_lifetime(&l)) (void)(1/0);
consteval bool partial_arrays() {
int arr[2];
assert_alive(arr);
assert_alive(arr[0]);
assert_alive(arr[1]);
std::construct_at(&arr[0]);
assert_alive(arr);
assert_alive(arr[0]);
assert_alive(arr[1]);
std::destroy_at(&arr[0]);
assert_alive(arr);
assert_dead(arr[0]);
assert_alive(arr[1]);
std::construct_at(&arr[0]);
return true;
}
static_assert(partial_arrays());
```
The call to `std::destroy_at(&arr[0])` will mark the entire array as dead, because that's where the base offset points at the time of calling it.
After this call, the `assert_alive(arr)` and the `assert_alive(array[1])` both fail.
To properly support this, we need so ave the lifetime information for primitive array elements somewhere.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8Vt1uo0gTfZr2TclRu7ExvuACO_Gnkb6VIiWaW6uBwtROQ6Puwlm__arB2J4d72xGWm2EFEz9nKpT1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