C++: suppress destructors on conditional temporaries

This commit is contained in:
Robert Marsh
2024-03-12 20:12:05 +00:00
committed by Mathias Vorreiter Pedersen
parent 894d934de8
commit 17e8c95e7f

View File

@@ -127,6 +127,11 @@ private predicate ignoreExprAndDescendants(Expr expr) {
exists(BuiltInVarArgsStart vaStartExpr |
vaStartExpr.getLastNamedParameter().getFullyConverted() = expr
)
or
// Do not translate implicit destructor calls for unnamed temporary variables that are
// conditionally constructed (until we have a mechanism for calling these only when the
// temporary's constructor was run)
isConditionalTemporaryDestructorCall(expr)
}
/**
@@ -252,6 +257,20 @@ private predicate usedAsCondition(Expr expr) {
)
}
private predicate isInConditionalEvaluation(Expr e) {
exists(ConditionalExpr cond |
e = cond.getThen() and not cond.isTwoOperand()
or
e = cond.getElse()
)
or
isInConditionalEvaluation(getRealParent(e))
}
private predicate isConditionalTemporaryDestructorCall(DestructorCall dc) {
isInConditionalEvaluation(dc.getQualifier().(ReuseExpr).getReusedExpr())
}
/**
* Holds if `conv` is an `InheritanceConversion` that requires a `TranslatedLoad`, despite not being
* marked as having an lvalue-to-rvalue conversion.