Skip to content

Commit 0eebb8b

Browse files
authored
[clang][bytecode][NFC] Check hasTrivialDtor() in RunDestructors (#155381)
We do this when calling Free() on dynamically allocated memory.
1 parent 93b05dd commit 0eebb8b

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,17 +1207,15 @@ static bool runRecordDestructor(InterpState &S, CodePtr OpPC,
12071207
}
12081208

12091209
// Destructor of this record.
1210-
if (const CXXDestructorDecl *Dtor = R->getDestructor();
1211-
Dtor && !Dtor->isTrivial()) {
1212-
const Function *DtorFunc = S.getContext().getOrCreateFunction(Dtor);
1213-
if (!DtorFunc)
1214-
return false;
1210+
const CXXDestructorDecl *Dtor = R->getDestructor();
1211+
assert(Dtor);
1212+
assert(!Dtor->isTrivial());
1213+
const Function *DtorFunc = S.getContext().getOrCreateFunction(Dtor);
1214+
if (!DtorFunc)
1215+
return false;
12151216

1216-
S.Stk.push<Pointer>(BasePtr);
1217-
if (!Call(S, OpPC, DtorFunc, 0))
1218-
return false;
1219-
}
1220-
return true;
1217+
S.Stk.push<Pointer>(BasePtr);
1218+
return Call(S, OpPC, DtorFunc, 0);
12211219
}
12221220

12231221
static bool RunDestructors(InterpState &S, CodePtr OpPC, const Block *B) {
@@ -1229,6 +1227,9 @@ static bool RunDestructors(InterpState &S, CodePtr OpPC, const Block *B) {
12291227

12301228
assert(Desc->isRecord() || Desc->isCompositeArray());
12311229

1230+
if (Desc->hasTrivialDtor())
1231+
return true;
1232+
12321233
if (Desc->isCompositeArray()) {
12331234
unsigned N = Desc->getNumElems();
12341235
if (N == 0)

0 commit comments

Comments
 (0)