C++: fix for destructor of while-loop condition

This commit is contained in:
Robert Marsh
2024-02-13 00:13:22 +00:00
parent bac7e46b0f
commit b94c4a6e1b
4 changed files with 55 additions and 19 deletions

View File

@@ -805,12 +805,10 @@ class TranslatedIfStmt extends TranslatedStmt, ConditionContext {
}
override Instruction getALastInstructionInternal() {
result = this.getElse().getALastInstruction() or result = this.getThen().getALastInstruction() // FIXME: how do we handle the CFG merge here
result = this.getElse().getALastInstruction() or result = this.getThen().getALastInstruction()
}
override TranslatedElement getLastChild() {
result = this.getElse() or result = this.getThen() // FIXME: how do we handle the CFG merge here
}
override TranslatedElement getLastChild() { result = this.getElse() or result = this.getThen() }
override TranslatedElement getChildInternal(int id) {
id = 0 and result = this.getInitialization()
@@ -873,7 +871,7 @@ abstract class TranslatedLoop extends TranslatedStmt, ConditionContext {
override Loop stmt;
override Instruction getALastInstructionInternal() {
result = this.getCondition().getALastInstruction() // FIXME: how do we handle the branch here
result = this.getCondition().getALastInstruction()
}
override TranslatedElement getLastChild() { result = this.getCondition() }
@@ -919,6 +917,26 @@ abstract class TranslatedLoop extends TranslatedStmt, ConditionContext {
class TranslatedWhileStmt extends TranslatedLoop {
TranslatedWhileStmt() { stmt instanceof WhileStmt }
override TranslatedElement getChildInternal(int id) {
id = 0 and result = this.getCondition()
or
id = 1 and result = this.getBody()
or
exists(int n |
result.getAst() = stmt.getImplicitDestructorCall(n) and
id = 2 + n
)
}
override predicate handlesDestructorsExplicitly() { any() }
final override Instruction getChildFalseSuccessor(TranslatedCondition child, EdgeKind kind) {
child = this.getCondition() and
if this.hasAnImplicitDestructorCall()
then result = this.getChild(this.getFirstDestructorCallIndex()).getFirstInstruction(kind)
else result = this.getParent().getChildSuccessor(this, kind)
}
override Instruction getFirstInstruction(EdgeKind kind) {
result = this.getFirstConditionInstruction(kind)
}
@@ -926,6 +944,9 @@ class TranslatedWhileStmt extends TranslatedLoop {
override Instruction getChildSuccessorInternal(TranslatedElement child, EdgeKind kind) {
child = this.getBody() and
result = this.getFirstConditionInstruction(kind)
or
child = this.getChild(this.getFirstDestructorCallIndex()) and
result = this.getParent().getChildSuccessor(this, kind)
}
}

View File

@@ -13246,11 +13246,19 @@ ir.cpp:
# 2204| m2204_8(Bool) = Chi : total:m2202_20, partial:m2204_7
#-----| Goto (back edge) -> Block 4
# 2206| Block 6
# 2206| v2206_1(void) = NoOp :
# 2193| v2193_7(void) = ReturnVoid :
# 2193| v2193_8(void) = AliasedUse : ~m2202_17
# 2193| v2193_9(void) = ExitFunction :
# 2204| Block 6
# 2204| r2204_9(glval<Bool>) = VariableAddress[B] :
# 2204| r2204_10(glval<unknown>) = FunctionAddress[~Bool] :
# 2204| v2204_11(void) = Call[~Bool] : func:r2204_10, this:r2204_9
# 2204| m2204_12(unknown) = ^CallSideEffect : ~m2202_17
# 2204| m2204_13(unknown) = Chi : total:m2202_17, partial:m2204_12
# 2204| v2204_14(void) = ^IndirectReadSideEffect[-1] : &:r2204_9, m2202_20
# 2204| m2204_15(Bool) = ^IndirectMayWriteSideEffect[-1] : &:r2204_9
# 2204| m2204_16(Bool) = Chi : total:m2202_20, partial:m2204_15
# 2206| v2206_1(void) = NoOp :
# 2193| v2193_7(void) = ReturnVoid :
# 2193| v2193_8(void) = AliasedUse : ~m2204_13
# 2193| v2193_9(void) = ExitFunction :
perf-regression.cpp:
# 6| void Big::Big()

View File

@@ -10760,7 +10760,7 @@
| ir.cpp:2182:5:2182:5 | SideEffect | ~m2182_9 |
| ir.cpp:2193:6:2193:25 | ChiPartial | partial:m2193_3 |
| ir.cpp:2193:6:2193:25 | ChiTotal | total:m2193_2 |
| ir.cpp:2193:6:2193:25 | SideEffect | ~m2202_17 |
| ir.cpp:2193:6:2193:25 | SideEffect | ~m2204_13 |
| ir.cpp:2193:32:2193:32 | Address | &:r2193_5 |
| ir.cpp:2195:16:2195:16 | Address | &:r2195_1 |
| ir.cpp:2195:16:2195:16 | Address | &:r2195_1 |
@@ -10820,13 +10820,23 @@
| ir.cpp:2203:17:2203:21 | StoreValue | r2203_1 |
| ir.cpp:2204:9:2204:9 | Address | &:r2204_1 |
| ir.cpp:2204:9:2204:9 | Address | &:r2204_1 |
| ir.cpp:2204:9:2204:9 | Address | &:r2204_9 |
| ir.cpp:2204:9:2204:9 | Address | &:r2204_9 |
| ir.cpp:2204:9:2204:9 | Arg(this) | this:r2204_1 |
| ir.cpp:2204:9:2204:9 | Arg(this) | this:r2204_9 |
| ir.cpp:2204:9:2204:9 | CallTarget | func:r2204_2 |
| ir.cpp:2204:9:2204:9 | CallTarget | func:r2204_10 |
| ir.cpp:2204:9:2204:9 | ChiPartial | partial:m2204_4 |
| ir.cpp:2204:9:2204:9 | ChiPartial | partial:m2204_7 |
| ir.cpp:2204:9:2204:9 | ChiPartial | partial:m2204_12 |
| ir.cpp:2204:9:2204:9 | ChiPartial | partial:m2204_15 |
| ir.cpp:2204:9:2204:9 | ChiTotal | total:m2202_17 |
| ir.cpp:2204:9:2204:9 | ChiTotal | total:m2202_17 |
| ir.cpp:2204:9:2204:9 | ChiTotal | total:m2202_20 |
| ir.cpp:2204:9:2204:9 | ChiTotal | total:m2202_20 |
| ir.cpp:2204:9:2204:9 | SideEffect | m2202_20 |
| ir.cpp:2204:9:2204:9 | SideEffect | m2202_20 |
| ir.cpp:2204:9:2204:9 | SideEffect | ~m2202_17 |
| ir.cpp:2204:9:2204:9 | SideEffect | ~m2202_17 |
| perf-regression.cpp:6:3:6:5 | Address | &:r6_5 |
| perf-regression.cpp:6:3:6:5 | Address | &:r6_5 |

View File

@@ -12304,7 +12304,7 @@ ir.cpp:
# 2202| mu2202_14(Bool) = ^IndirectMayWriteSideEffect[-1] : &:r2202_9
# 2202| r2202_15(bool) = CopyValue : r2202_11
# 2202| v2202_16(void) = ConditionalBranch : r2202_15
#-----| False -> Block 7
#-----| False -> Block 6
#-----| True -> Block 5
# 2203| Block 5
@@ -12326,13 +12326,10 @@ ir.cpp:
# 2204| mu2204_10(unknown) = ^CallSideEffect : ~m?
# 2204| v2204_11(void) = ^IndirectReadSideEffect[-1] : &:r2204_7, ~m?
# 2204| mu2204_12(Bool) = ^IndirectMayWriteSideEffect[-1] : &:r2204_7
#-----| Goto -> Block 7
# 2206| Block 7
# 2206| v2206_1(void) = NoOp :
# 2193| v2193_6(void) = ReturnVoid :
# 2193| v2193_7(void) = AliasedUse : ~m?
# 2193| v2193_8(void) = ExitFunction :
# 2206| v2206_1(void) = NoOp :
# 2193| v2193_6(void) = ReturnVoid :
# 2193| v2193_7(void) = AliasedUse : ~m?
# 2193| v2193_8(void) = ExitFunction :
perf-regression.cpp:
# 6| void Big::Big()