mirror of
https://github.com/github/codeql.git
synced 2026-04-23 15:55:18 +02:00
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:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user