Skip to content

Commit ce96fdd

Browse files
authored
[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.
1 parent d3f13a0 commit ce96fdd

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

clang/lib/AST/ByteCode/InterpStack.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
using namespace clang;
2020
using namespace clang::interp;
2121

22-
InterpStack::~InterpStack() { clear(); }
23-
24-
void InterpStack::clear() {
22+
InterpStack::~InterpStack() {
2523
if (Chunk && Chunk->Next)
2624
std::free(Chunk->Next);
2725
if (Chunk)
@@ -33,6 +31,21 @@ void InterpStack::clear() {
3331
#endif
3432
}
3533

34+
// We keep the last chunk around to reuse.
35+
void InterpStack::clear() {
36+
if (!Chunk)
37+
return;
38+
39+
if (Chunk->Next)
40+
std::free(Chunk->Next);
41+
42+
assert(Chunk);
43+
StackSize = 0;
44+
#ifndef NDEBUG
45+
ItemTypes.clear();
46+
#endif
47+
}
48+
3649
void InterpStack::clearTo(size_t NewSize) {
3750
assert(NewSize <= size());
3851
size_t ToShrink = size() - NewSize;

0 commit comments

Comments
 (0)