Skip to content

Commit fbf8b82

Browse files
committed
[clang][Interp][NFC] Be more cautious about Block initialization state
... when moving a Block to a DeadBlock. Only invoke the MoveFn if the old block was initialized at all.
1 parent 810adba commit fbf8b82

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

clang/lib/AST/Interp/InterpBlock.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ DeadBlock::DeadBlock(DeadBlock *&Root, Block *Blk)
110110
}
111111

112112
void DeadBlock::free() {
113+
if (B.IsInitialized)
114+
B.invokeDtor();
115+
113116
if (Prev)
114117
Prev->Next = Next;
115118
if (Next)

clang/lib/AST/Interp/InterpState.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ void InterpState::deallocate(Block *B) {
6969
char *Memory =
7070
reinterpret_cast<char *>(std::malloc(sizeof(DeadBlock) + Size));
7171
auto *D = new (Memory) DeadBlock(DeadBlocks, B);
72+
std::memset(D->B.rawData(), 0, D->B.getSize());
7273

7374
// Move data and metadata from the old block to the new (dead)block.
74-
if (Desc->MoveFn) {
75+
if (B->IsInitialized && Desc->MoveFn) {
7576
Desc->MoveFn(B, B->data(), D->data(), Desc);
7677
if (Desc->getMetadataSize() > 0)
7778
std::memcpy(D->rawData(), B->rawData(), Desc->getMetadataSize());
7879
}
80+
D->B.IsInitialized = B->IsInitialized;
7981

8082
// We moved the contents over to the DeadBlock.
8183
B->IsInitialized = false;

0 commit comments

Comments
 (0)