[clang] [clang][bytecode] Split up `InterpState::dealllocate()` (PR #239185)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 5 07:57:36 PST 2026
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/239185
>From f8233cac733e80801da3ecde71e0682af5073978 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Thu, 5 Nov 2026 12:03:50 +0100
Subject: [PATCH] deallocate with pointers
---
clang/lib/AST/ByteCode/InterpState.cpp | 13 +++----------
clang/lib/AST/ByteCode/InterpState.h | 18 +++++++++++++++++-
2 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/clang/lib/AST/ByteCode/InterpState.cpp b/clang/lib/AST/ByteCode/InterpState.cpp
index 231acc31ff3578..5816311ade340a 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 f423ea56024a9d..ef7d210be0da4b 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