Skip to content

Commit b2e0485

Browse files
authored
Merge pull request #15908 from jketema/destructors12
C++: suppress destructors with reuse expressions until proper support is added
2 parents 67b3670 + 866a393 commit b2e0485

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedElement.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ private predicate ignoreExprAndDescendants(Expr expr) {
9999
or
100100
// suppress destructors of temporary variables until proper support is added for them.
101101
exists(Expr parent | parent.getAnImplicitDestructorCall() = expr)
102+
or
103+
exists(Stmt parent |
104+
parent.getAnImplicitDestructorCall() = expr and
105+
expr.(DestructorCall).getQualifier() instanceof ReuseExpr
106+
)
102107
}
103108

104109
/**

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedStmt.qll

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,19 @@ abstract class TranslatedStmt extends TranslatedElement, TTranslatedStmt {
248248
final override TranslatedElement getChild(int id) {
249249
result = this.getChildInternal(id)
250250
or
251-
exists(int destructorIndex |
251+
exists(int destructorIndex, int tempDestructorCount |
252252
result.(TranslatedExpr).getExpr() = stmt.getImplicitDestructorCall(destructorIndex) and
253-
id = this.getFirstDestructorCallIndex() + destructorIndex
253+
id = this.getFirstDestructorCallIndex() + destructorIndex - tempDestructorCount and
254+
// suppress destructors of temporary variables until proper support is added for them.
255+
tempDestructorCount =
256+
count(DestructorCall call, int tempIndex |
257+
stmt.getImplicitDestructorCall(tempIndex) = call and
258+
tempIndex < destructorIndex and
259+
call.getQualifier() instanceof ReuseExpr
260+
|
261+
call
262+
) and
263+
not stmt.getImplicitDestructorCall(destructorIndex).getQualifier() instanceof ReuseExpr
254264
)
255265
}
256266

@@ -261,7 +271,11 @@ abstract class TranslatedStmt extends TranslatedElement, TTranslatedStmt {
261271
}
262272

263273
final override predicate hasAnImplicitDestructorCall() {
264-
exists(stmt.getAnImplicitDestructorCall())
274+
exists(stmt.getAnImplicitDestructorCall()) and
275+
// suppress destructors of temporary variables until proper support is added for them.
276+
exists(Expr expr | stmt.getAnImplicitDestructorCall().getQualifier() = expr |
277+
not expr instanceof ReuseExpr
278+
)
265279
}
266280

267281
final override string toString() { result = stmt.toString() }

0 commit comments

Comments
 (0)