Skip to content

Commit e4775e5

Browse files
tbaederryuxuanchen1997
authored andcommitted
[clang][Interp][NFC] Assert initialization state in invoke{C,D}tor
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251329
1 parent 85a1c58 commit e4775e5

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

clang/lib/AST/Interp/InterpBlock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class Block final {
107107

108108
/// Invokes the constructor.
109109
void invokeCtor() {
110+
assert(!IsInitialized);
110111
std::memset(rawData(), 0, Desc->getAllocSize());
111112
if (Desc->CtorFn)
112113
Desc->CtorFn(this, data(), Desc->IsConst, Desc->IsMutable,
@@ -116,6 +117,7 @@ class Block final {
116117

117118
/// Invokes the Destructor.
118119
void invokeDtor() {
120+
assert(IsInitialized);
119121
if (Desc->DtorFn)
120122
Desc->DtorFn(this, data(), Desc);
121123
IsInitialized = false;

clang/lib/AST/Interp/InterpFrame.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ Pointer InterpFrame::getParamPointer(unsigned Off) {
227227
size_t BlockSize = sizeof(Block) + Desc.second->getAllocSize();
228228
auto Memory = std::make_unique<char[]>(BlockSize);
229229
auto *B = new (Memory.get()) Block(S.Ctx.getEvalID(), Desc.second);
230+
B->invokeCtor();
230231

231232
// Copy the initial value.
232233
TYPE_SWITCH(Desc.first, new (B->data()) T(stackRef<T>(Off)));

clang/lib/AST/Interp/InterpState.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void InterpState::deallocate(Block *B) {
7777

7878
// We moved the contents over to the DeadBlock.
7979
B->IsInitialized = false;
80-
} else {
80+
} else if (B->IsInitialized) {
8181
B->invokeDtor();
8282
}
8383
}

0 commit comments

Comments
 (0)