Skip to content

Commit 1e8b65d

Browse files
authored
[clang][bytecode][NFC] Add a FIXME comment for heap allocations (#151700)
1 parent 89e4d9f commit 1e8b65d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

clang/lib/AST/ByteCode/DynamicAllocator.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@
1313
using namespace clang;
1414
using namespace clang::interp;
1515

16+
// FIXME: There is a peculiar problem with the way we track pointers
17+
// to blocks and the way we allocate dynamic memory.
18+
//
19+
// When we have code like this:
20+
// while (true) {
21+
// char *buffer = new char[1024];
22+
// delete[] buffer;
23+
// }
24+
//
25+
// We have a local variable 'buffer' pointing to the heap allocated memory.
26+
// When deallocating the memory via delete[], that local variable still
27+
// points to the memory, which means we will create a DeadBlock for it and move
28+
// it over to that block, essentially duplicating the allocation. Moving
29+
// the data is also slow.
30+
//
31+
// However, when we actually try to access the allocation after it has been
32+
// freed, we need the block to still exist (alive or dead) so we can tell
33+
// that it's a dynamic allocation.
34+
1635
DynamicAllocator::~DynamicAllocator() { cleanup(); }
1736

1837
void DynamicAllocator::cleanup() {

0 commit comments

Comments
 (0)