[clang] fe0f7e5 - [clang][bytecode] Split up `InterpState::dealllocate()` (#239185)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 5 22:35:43 PST 2026
Author: Timm Baeder
Date: 2026-11-06T07:35:38+01:00
New Revision: fe0f7e54e4947e3722cca8a4425229290703a99d
URL: https://github.com/llvm/llvm-project/commit/fe0f7e54e4947e3722cca8a4425229290703a99d
DIFF: https://github.com/llvm/llvm-project/commit/fe0f7e54e4947e3722cca8a4425229290703a99d.diff
LOG: [clang][bytecode] Split up `InterpState::dealllocate()` (#239185)
Split it into the common case of "block has no pointers to it" and
"block that _does_".
Added:
Modified:
clang/lib/AST/ByteCode/InterpState.cpp
clang/lib/AST/ByteCode/InterpState.h
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/InterpState.cpp b/clang/lib/AST/ByteCode/InterpState.cpp
index 231acc31ff357..5816311ade340 100644
--- a/clang/lib/AST/ByteCode/InterpState.cpp
+++ b/clang/lib/AST/ByteCode/InterpState.cpp
@@ -93,21 +93,14 @@ void InterpState::cleanup() {
const Frame *InterpState::getCurrentFrame() { return Current; }
-void InterpState::deallocate(Block *B) {
+void InterpState::deallocateWithPointers(Block *B) {
assert(B);
+ assert(B->hasPointers());
assert(!B->isDynamic());
assert(!B->isGlobal());
assert(!B->isDead());
-
- // The block might have a pointer saved in a field in its data
- // that points to the block itself. We call the dtor first,
- // which will destroy all the data but leave InlineDescriptors
- // intact. If the block THEN still has pointers, we create a
- // DeadBlock for it.
- if (B->IsInitialized)
- B->invokeDtor();
-
assert(!B->isInitialized());
+
if (B->hasPointers()) {
size_t Size = B->getAllocSize();
// Allocate a new block, transferring over pointers.
diff --git a/clang/lib/AST/ByteCode/InterpState.h b/clang/lib/AST/ByteCode/InterpState.h
index f423ea56024a9..ef7d210be0da4 100644
--- a/clang/lib/AST/ByteCode/InterpState.h
+++ b/clang/lib/AST/ByteCode/InterpState.h
@@ -72,7 +72,20 @@ class InterpState final : public State {
bool inConstantContext() const;
/// Deallocates a pointer.
- void deallocate(Block *B);
+ void deallocate(Block *B) {
+ // The block might have a pointer saved in a field in its data
+ // that points to the block itself. We call the dtor first,
+ // which will destroy all the data but leave InlineDescriptors
+ // intact. If the block THEN still has pointers, we create a
+ // DeadBlock for it in deallocateWithPointers().
+ if (B->IsInitialized)
+ B->invokeDtor();
+
+ if (LLVM_LIKELY(!B->hasPointers()))
+ return;
+
+ deallocateWithPointers(B);
+ }
/// Delegates source mapping to the mapper.
SourceInfo getSource(CodePtr PC) const { return M->getSource(PC); }
@@ -245,6 +258,9 @@ class InterpState final : public State {
FrameAllocator &FrameAlloc;
+ /// Deallocate a block that still has pointers pointing to it.
+ void deallocateWithPointers(Block *B);
+
public:
CodePtr PC;
/// Reference to the module containing all bytecode.
More information about the cfe-commits
mailing list