[clang][bytecode] Keep the last chunk in InterpStack::clear() (#144487)

We call clear when checking for potential constant expressions, but that
used to free all the chunks. Keep the last one so we don't have to
re-allocate it.
This commit is contained in:
Timm Baeder
2025-06-17 12:38:02 +02:00
committed by GitHub
parent d3f13a0732
commit ce96fdde54

View File

@@ -19,9 +19,7 @@
using namespace clang;
using namespace clang::interp;
InterpStack::~InterpStack() { clear(); }
void InterpStack::clear() {
InterpStack::~InterpStack() {
if (Chunk && Chunk->Next)
std::free(Chunk->Next);
if (Chunk)
@@ -33,6 +31,21 @@ void InterpStack::clear() {
#endif
}
// We keep the last chunk around to reuse.
void InterpStack::clear() {
if (!Chunk)
return;
if (Chunk->Next)
std::free(Chunk->Next);
assert(Chunk);
StackSize = 0;
#ifndef NDEBUG
ItemTypes.clear();
#endif
}
void InterpStack::clearTo(size_t NewSize) {
assert(NewSize <= size());
size_t ToShrink = size() - NewSize;