Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 17e8c95

Browse files
Robert MarshMathiasVP
authored andcommitted
C++: suppress destructors on conditional temporaries
1 parent 894d934 commit 17e8c95

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ private predicate ignoreExprAndDescendants(Expr expr) {
127127
exists(BuiltInVarArgsStart vaStartExpr |
128128
vaStartExpr.getLastNamedParameter().getFullyConverted() = expr
129129
)
130+
or
131+
// Do not translate implicit destructor calls for unnamed temporary variables that are
132+
// conditionally constructed (until we have a mechanism for calling these only when the
133+
// temporary's constructor was run)
134+
isConditionalTemporaryDestructorCall(expr)
130135
}
131136

132137
/**
@@ -252,6 +257,20 @@ private predicate usedAsCondition(Expr expr) {
252257
)
253258
}
254259

260+
private predicate isInConditionalEvaluation(Expr e) {
261+
exists(ConditionalExpr cond |
262+
e = cond.getThen() and not cond.isTwoOperand()
263+
or
264+
e = cond.getElse()
265+
)
266+
or
267+
isInConditionalEvaluation(getRealParent(e))
268+
}
269+
270+
private predicate isConditionalTemporaryDestructorCall(DestructorCall dc) {
271+
isInConditionalEvaluation(dc.getQualifier().(ReuseExpr).getReusedExpr())
272+
}
273+
255274
/**
256275
* Holds if `conv` is an `InheritanceConversion` that requires a `TranslatedLoad`, despite not being
257276
* marked as having an lvalue-to-rvalue conversion.

0 commit comments

Comments
 (0)