[clang] 1e8b65d - [clang][bytecode][NFC] Add a FIXME comment for heap allocations (#151700)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 1 07:30:47 PDT 2025
Author: Timm Baeder
Date: 2025-08-01T16:30:43+02:00
New Revision: 1e8b65d8cdb38cb7aba92a459a65abaf4a213593
URL: https://github.com/llvm/llvm-project/commit/1e8b65d8cdb38cb7aba92a459a65abaf4a213593
DIFF: https://github.com/llvm/llvm-project/commit/1e8b65d8cdb38cb7aba92a459a65abaf4a213593.diff
LOG: [clang][bytecode][NFC] Add a FIXME comment for heap allocations (#151700)
Added:
Modified:
clang/lib/AST/ByteCode/DynamicAllocator.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/DynamicAllocator.cpp b/clang/lib/AST/ByteCode/DynamicAllocator.cpp
index 169250ce05fa7..9b8b664df6afd 100644
--- a/clang/lib/AST/ByteCode/DynamicAllocator.cpp
+++ b/clang/lib/AST/ByteCode/DynamicAllocator.cpp
@@ -13,6 +13,25 @@
using namespace clang;
using namespace clang::interp;
+// FIXME: There is a peculiar problem with the way we track pointers
+// to blocks and the way we allocate dynamic memory.
+//
+// When we have code like this:
+// while (true) {
+// char *buffer = new char[1024];
+// delete[] buffer;
+// }
+//
+// We have a local variable 'buffer' pointing to the heap allocated memory.
+// When deallocating the memory via delete[], that local variable still
+// points to the memory, which means we will create a DeadBlock for it and move
+// it over to that block, essentially duplicating the allocation. Moving
+// the data is also slow.
+//
+// However, when we actually try to access the allocation after it has been
+// freed, we need the block to still exist (alive or dead) so we can tell
+// that it's a dynamic allocation.
+
DynamicAllocator::~DynamicAllocator() { cleanup(); }
void DynamicAllocator::cleanup() {
More information about the cfe-commits
mailing list