Author: Timm Bäder Date: 2024-08-03T05:44:59+02:00 New Revision: 4d2c9d8cd849e8097f41b3c3b52e4475188b5489
URL: https://github.com/llvm/llvm-project/commit/4d2c9d8cd849e8097f41b3c3b52e4475188b5489 DIFF: https://github.com/llvm/llvm-project/commit/4d2c9d8cd849e8097f41b3c3b52e4475188b5489.diff LOG: [clang][Interp][NFC] Add more assertions to add/removePointer Added: Modified: clang/lib/AST/Interp/InterpBlock.cpp clang/lib/AST/Interp/Pointer.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/InterpBlock.cpp b/clang/lib/AST/Interp/InterpBlock.cpp index 5ac778aeb6075..7a3962290edb4 100644 --- a/clang/lib/AST/Interp/InterpBlock.cpp +++ b/clang/lib/AST/Interp/InterpBlock.cpp @@ -31,9 +31,13 @@ void Block::addPointer(Pointer *P) { P->Next = Pointers; P->Prev = nullptr; Pointers = P; +#ifndef NDEBUG + assert(hasPointer(P)); +#endif } void Block::removePointer(Pointer *P) { + assert(P->isBlockPointer()); assert(P); if (IsStatic) { assert(!Pointers); @@ -51,6 +55,10 @@ void Block::removePointer(Pointer *P) { P->Prev->Next = P->Next; if (P->Next) P->Next->Prev = P->Prev; + P->PointeeStorage.BS.Pointee = nullptr; +#ifndef NDEBUG + assert(!hasPointer(P)); +#endif } void Block::cleanup() { diff --git a/clang/lib/AST/Interp/Pointer.cpp b/clang/lib/AST/Interp/Pointer.cpp index afa9d19d62823..79fe317a61dff 100644 --- a/clang/lib/AST/Interp/Pointer.cpp +++ b/clang/lib/AST/Interp/Pointer.cpp @@ -60,6 +60,7 @@ Pointer::~Pointer() { if (Block *Pointee = PointeeStorage.BS.Pointee) { Pointee->removePointer(this); + PointeeStorage.BS.Pointee = nullptr; Pointee->cleanup(); } } @@ -68,8 +69,15 @@ void Pointer::operator=(const Pointer &P) { // If the current storage type is Block, we need to remove // this pointer from the block. if (isBlockPointer()) { + if (P.isBlockPointer() && this->block() == P.block()) { + Offset = P.Offset; + PointeeStorage.BS.Base = P.PointeeStorage.BS.Base; + return; + } + if (Block *Pointee = PointeeStorage.BS.Pointee) { Pointee->removePointer(this); + PointeeStorage.BS.Pointee = nullptr; Pointee->cleanup(); } } @@ -96,8 +104,16 @@ void Pointer::operator=(Pointer &&P) { // If the current storage type is Block, we need to remove // this pointer from the block. if (isBlockPointer()) { + if (P.isBlockPointer() && this->block() == P.block()) { + Offset = P.Offset; + PointeeStorage.BS.Base = P.PointeeStorage.BS.Base; + return; + } + if (Block *Pointee = PointeeStorage.BS.Pointee) { + assert(P.block() != this->block()); Pointee->removePointer(this); + PointeeStorage.BS.Pointee = nullptr; Pointee->cleanup(); } } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits