Skip to content

Commit 8acf2b8

Browse files
tbaederrgithub-actions[bot]
authored andcommitted
Automerge: [clang][bytecode] Add Block::movePointersTo (#163795)
which moves all the block's pointers to a new block.
2 parents 641707c + 558d935 commit 8acf2b8

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

clang/lib/AST/ByteCode/InterpBlock.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@ bool Block::hasPointer(const Pointer *P) const {
100100
}
101101
#endif
102102

103+
void Block::movePointersTo(Block *B) {
104+
assert(B != this);
105+
106+
while (Pointers) {
107+
Pointer *P = Pointers;
108+
109+
this->removePointer(P);
110+
P->BS.Pointee = B;
111+
B->addPointer(P);
112+
}
113+
assert(!this->hasPointers());
114+
}
115+
103116
DeadBlock::DeadBlock(DeadBlock *&Root, Block *Blk)
104117
: Root(Root), B(~0u, Blk->Desc, Blk->isExtern(), Blk->IsStatic,
105118
Blk->isWeak(), Blk->isDummy(), /*IsDead=*/true) {

clang/lib/AST/ByteCode/InterpBlock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class Block final {
9292
bool isInitialized() const { return IsInitialized; }
9393
/// The Evaluation ID this block was created in.
9494
unsigned getEvalID() const { return EvalID; }
95+
/// Move all pointers from this block to \param B.
96+
void movePointersTo(Block *B);
9597

9698
/// Returns a pointer to the stored data.
9799
/// You are allowed to read Desc->getSize() bytes from this address.

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,7 @@ UnsignedOrNone Program::createGlobal(const ValueDecl *VD, const Expr *Init) {
226226
Globals[PIdx] = NewGlobal;
227227
// All pointers pointing to the previous extern decl now point to the
228228
// new decl.
229-
for (Pointer *Ptr = RedeclBlock->Pointers; Ptr; Ptr = Ptr->BS.Next) {
230-
RedeclBlock->removePointer(Ptr);
231-
Ptr->BS.Pointee = NewGlobal->block();
232-
NewGlobal->block()->addPointer(Ptr);
233-
}
229+
RedeclBlock->movePointersTo(NewGlobal->block());
234230
}
235231
}
236232
PIdx = *Idx;

0 commit comments

Comments
 (0)