Skip to content

Commit 4d2c9d8

Browse files
committed
[clang][Interp][NFC] Add more assertions to add/removePointer
1 parent 13faed8 commit 4d2c9d8

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

clang/lib/AST/Interp/InterpBlock.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ void Block::addPointer(Pointer *P) {
3131
P->Next = Pointers;
3232
P->Prev = nullptr;
3333
Pointers = P;
34+
#ifndef NDEBUG
35+
assert(hasPointer(P));
36+
#endif
3437
}
3538

3639
void Block::removePointer(Pointer *P) {
40+
assert(P->isBlockPointer());
3741
assert(P);
3842
if (IsStatic) {
3943
assert(!Pointers);
@@ -51,6 +55,10 @@ void Block::removePointer(Pointer *P) {
5155
P->Prev->Next = P->Next;
5256
if (P->Next)
5357
P->Next->Prev = P->Prev;
58+
P->PointeeStorage.BS.Pointee = nullptr;
59+
#ifndef NDEBUG
60+
assert(!hasPointer(P));
61+
#endif
5462
}
5563

5664
void Block::cleanup() {

clang/lib/AST/Interp/Pointer.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Pointer::~Pointer() {
6060

6161
if (Block *Pointee = PointeeStorage.BS.Pointee) {
6262
Pointee->removePointer(this);
63+
PointeeStorage.BS.Pointee = nullptr;
6364
Pointee->cleanup();
6465
}
6566
}
@@ -68,8 +69,15 @@ void Pointer::operator=(const Pointer &P) {
6869
// If the current storage type is Block, we need to remove
6970
// this pointer from the block.
7071
if (isBlockPointer()) {
72+
if (P.isBlockPointer() && this->block() == P.block()) {
73+
Offset = P.Offset;
74+
PointeeStorage.BS.Base = P.PointeeStorage.BS.Base;
75+
return;
76+
}
77+
7178
if (Block *Pointee = PointeeStorage.BS.Pointee) {
7279
Pointee->removePointer(this);
80+
PointeeStorage.BS.Pointee = nullptr;
7381
Pointee->cleanup();
7482
}
7583
}
@@ -96,8 +104,16 @@ void Pointer::operator=(Pointer &&P) {
96104
// If the current storage type is Block, we need to remove
97105
// this pointer from the block.
98106
if (isBlockPointer()) {
107+
if (P.isBlockPointer() && this->block() == P.block()) {
108+
Offset = P.Offset;
109+
PointeeStorage.BS.Base = P.PointeeStorage.BS.Base;
110+
return;
111+
}
112+
99113
if (Block *Pointee = PointeeStorage.BS.Pointee) {
114+
assert(P.block() != this->block());
100115
Pointee->removePointer(this);
116+
PointeeStorage.BS.Pointee = nullptr;
101117
Pointee->cleanup();
102118
}
103119
}

0 commit comments

Comments
 (0)