C++: Fix a bug where the destructor attached to a 'new' expression would

have multiple parents (the 'new' expression, the call to 'operator new',
and the size expression). This happens because the latter two are
'TranslatedExpr's that return the 'new' expression as their expression
even though they don't technically represent the translation of this
expression.
To prevent this bug we tell the IR construction that the latter two
handle their destructors explicitly which means that IR construction
doesn't try to synthesize them.
This commit is contained in:
Mathias Vorreiter Pedersen
2024-04-05 14:46:27 +01:00
parent b042366c8e
commit f1d2dac648

View File

@@ -2015,6 +2015,13 @@ abstract class TranslatedAllocationSize extends TranslatedExpr, TTranslatedAlloc
final override predicate producesExprResult() { none() }
final override Instruction getResult() { result = this.getInstruction(AllocationSizeTag()) }
final override predicate handlesDestructorsExplicitly() {
// Since the enclosing `TranslatedNewOrNewArrayExpr` (implicitly) handles the destructors
// we need to disable the implicit handling here as otherwise the destructors will have
// multiple parents
any()
}
}
TranslatedAllocationSize getTranslatedAllocationSize(NewOrNewArrayExpr newExpr) {
@@ -2172,6 +2179,13 @@ class TranslatedAllocatorCall extends TTranslatedAllocatorCall, TranslatedDirect
final override predicate producesExprResult() { none() }
final override predicate handlesDestructorsExplicitly() {
// Since the enclosing `TranslatedNewOrNewArrayExpr` (implicitly) handles the destructors
// we need to disable the implicit handling here as otherwise the destructors will have
// multiple parents
any()
}
override Function getInstructionFunction(InstructionTag tag) {
tag = CallTargetTag() and result = expr.getAllocator()
}