Skip to content

Commit fa06d88

Browse files
committed
C++: Add forgotten getLastChild to TranslatedConstExprIfStmt
1 parent 6575927 commit fa06d88

File tree

4 files changed

+107
-98
lines changed

4 files changed

+107
-98
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,12 @@ class TranslatedConstExprIfStmt extends TranslatedStmt, ConditionContext {
923923
else result = this.getFirstConditionInstruction(kind)
924924
}
925925

926+
override Instruction getALastInstructionInternal() {
927+
result = this.getElse().getALastInstruction() or result = this.getThen().getALastInstruction()
928+
}
929+
930+
override TranslatedElement getLastChild() { result = this.getElse() or result = this.getThen() }
931+
926932
override TranslatedElement getChildInternal(int id) {
927933
id = 0 and result = this.getInitialization()
928934
or
@@ -978,12 +984,6 @@ class TranslatedConstExprIfStmt extends TranslatedStmt, ConditionContext {
978984
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType resultType) {
979985
none()
980986
}
981-
982-
override Instruction getALastInstructionInternal() {
983-
result = this.getThen().getALastInstruction()
984-
or
985-
result = this.getElse().getALastInstruction()
986-
}
987987
}
988988

989989
abstract class TranslatedLoop extends TranslatedStmt, ConditionContext {

cpp/ql/test/library-tests/ir/ir/aliased_ir.expected

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15413,27 +15413,35 @@ ir.cpp:
1541315413
#-----| True -> Block 4
1541415414

1541515415
# 2204| Block 4
15416-
# 2204| r2204_1(glval<ClassWithDestructor>) = VariableAddress[x] :
15417-
# 2204| r2204_2(glval<unknown>) = FunctionAddress[set_x] :
15418-
# 2204| r2204_3(char) = Constant[97] :
15419-
# 2204| v2204_4(void) = Call[set_x] : func:r2204_2, this:r2204_1, 0:r2204_3
15420-
# 2204| m2204_5(unknown) = ^CallSideEffect : ~m2203_7
15421-
# 2204| m2204_6(unknown) = Chi : total:m2203_7, partial:m2204_5
15422-
# 2204| v2204_7(void) = ^IndirectReadSideEffect[-1] : &:r2204_1, m2203_9
15423-
# 2204| m2204_8(ClassWithDestructor) = ^IndirectMayWriteSideEffect[-1] : &:r2204_1
15424-
# 2204| m2204_9(ClassWithDestructor) = Chi : total:m2203_9, partial:m2204_8
15425-
# 2206| r2206_1(glval<ClassWithDestructor>) = VariableAddress[x] :
15426-
# 2206| m2206_2(ClassWithDestructor) = Uninitialized[x] : &:r2206_1
15427-
# 2206| r2206_3(glval<unknown>) = FunctionAddress[ClassWithDestructor] :
15428-
# 2206| v2206_4(void) = Call[ClassWithDestructor] : func:r2206_3, this:r2206_1
15429-
# 2206| m2206_5(unknown) = ^CallSideEffect : ~m2204_6
15430-
# 2206| m2206_6(unknown) = Chi : total:m2204_6, partial:m2206_5
15431-
# 2206| m2206_7(ClassWithDestructor) = ^IndirectMayWriteSideEffect[-1] : &:r2206_1
15432-
# 2206| m2206_8(ClassWithDestructor) = Chi : total:m2206_2, partial:m2206_7
15433-
# 2206| r2206_9(glval<char>) = VariableAddress[c] :
15434-
# 2206| r2206_10(char) = Load[c] : &:r2206_9, m2199_8
15435-
# 2206| r2206_11(int) = Convert : r2206_10
15436-
# 2206| v2206_12(void) = Switch : r2206_11
15416+
# 2204| r2204_1(glval<ClassWithDestructor>) = VariableAddress[x] :
15417+
# 2204| r2204_2(glval<unknown>) = FunctionAddress[set_x] :
15418+
# 2204| r2204_3(char) = Constant[97] :
15419+
# 2204| v2204_4(void) = Call[set_x] : func:r2204_2, this:r2204_1, 0:r2204_3
15420+
# 2204| m2204_5(unknown) = ^CallSideEffect : ~m2203_7
15421+
# 2204| m2204_6(unknown) = Chi : total:m2203_7, partial:m2204_5
15422+
# 2204| v2204_7(void) = ^IndirectReadSideEffect[-1] : &:r2204_1, m2203_9
15423+
# 2204| m2204_8(ClassWithDestructor) = ^IndirectMayWriteSideEffect[-1] : &:r2204_1
15424+
# 2204| m2204_9(ClassWithDestructor) = Chi : total:m2203_9, partial:m2204_8
15425+
# 2204| r2204_10(glval<ClassWithDestructor>) = VariableAddress[x] :
15426+
# 2204| r2204_11(glval<unknown>) = FunctionAddress[~ClassWithDestructor] :
15427+
# 2204| v2204_12(void) = Call[~ClassWithDestructor] : func:r2204_11, this:r2204_10
15428+
# 2204| m2204_13(unknown) = ^CallSideEffect : ~m2204_6
15429+
# 2204| m2204_14(unknown) = Chi : total:m2204_6, partial:m2204_13
15430+
# 2204| v2204_15(void) = ^IndirectReadSideEffect[-1] : &:r2204_10, m2204_9
15431+
# 2204| m2204_16(ClassWithDestructor) = ^IndirectMayWriteSideEffect[-1] : &:r2204_10
15432+
# 2204| m2204_17(ClassWithDestructor) = Chi : total:m2204_9, partial:m2204_16
15433+
# 2206| r2206_1(glval<ClassWithDestructor>) = VariableAddress[x] :
15434+
# 2206| m2206_2(ClassWithDestructor) = Uninitialized[x] : &:r2206_1
15435+
# 2206| r2206_3(glval<unknown>) = FunctionAddress[ClassWithDestructor] :
15436+
# 2206| v2206_4(void) = Call[ClassWithDestructor] : func:r2206_3, this:r2206_1
15437+
# 2206| m2206_5(unknown) = ^CallSideEffect : ~m2204_14
15438+
# 2206| m2206_6(unknown) = Chi : total:m2204_14, partial:m2206_5
15439+
# 2206| m2206_7(ClassWithDestructor) = ^IndirectMayWriteSideEffect[-1] : &:r2206_1
15440+
# 2206| m2206_8(ClassWithDestructor) = Chi : total:m2206_2, partial:m2206_7
15441+
# 2206| r2206_9(glval<char>) = VariableAddress[c] :
15442+
# 2206| r2206_10(char) = Load[c] : &:r2206_9, m2199_8
15443+
# 2206| r2206_11(int) = Convert : r2206_10
15444+
# 2206| v2206_12(void) = Switch : r2206_11
1543715445
#-----| Case[97] -> Block 5
1543815446
#-----| Default -> Block 6
1543915447

@@ -18326,11 +18334,19 @@ ir.cpp:
1832618334
#-----| True -> Block 1
1832718335

1832818336
# 2552| Block 1
18329-
# 2552| v2552_1(void) = NoOp :
18330-
# 2553| v2553_1(void) = NoOp :
18331-
# 2550| v2550_7(void) = ReturnVoid :
18332-
# 2550| v2550_8(void) = AliasedUse : ~m2551_6
18333-
# 2550| v2550_9(void) = ExitFunction :
18337+
# 2552| v2552_1(void) = NoOp :
18338+
# 2552| r2552_2(glval<ClassWithDestructor>) = CopyValue : r2551_2
18339+
# 2552| r2552_3(glval<unknown>) = FunctionAddress[~ClassWithDestructor] :
18340+
# 2552| v2552_4(void) = Call[~ClassWithDestructor] : func:r2552_3, this:r2552_2
18341+
# 2552| m2552_5(unknown) = ^CallSideEffect : ~m2551_6
18342+
# 2552| m2552_6(unknown) = Chi : total:m2551_6, partial:m2552_5
18343+
# 2552| v2552_7(void) = ^IndirectReadSideEffect[-1] : &:r2552_2, m2551_7
18344+
# 2552| m2552_8(ClassWithDestructor) = ^IndirectMayWriteSideEffect[-1] : &:r2552_2
18345+
# 2552| m2552_9(ClassWithDestructor) = Chi : total:m2551_7, partial:m2552_8
18346+
# 2553| v2553_1(void) = NoOp :
18347+
# 2550| v2550_7(void) = ReturnVoid :
18348+
# 2550| v2550_8(void) = AliasedUse : ~m2552_6
18349+
# 2550| v2550_9(void) = ExitFunction :
1833418350

1833518351
# 2550| Block 2
1833618352
# 2550| v2550_10(void) = Unreached :

cpp/ql/test/library-tests/ir/ir/raw_consistency.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ lostReachability
2121
backEdgeCountMismatch
2222
useNotDominatedByDefinition
2323
| ir.cpp:1535:8:1535:8 | Unary | Operand 'Unary' is not dominated by its definition in function '$@'. | ir.cpp:1535:8:1535:8 | void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct() | void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct() |
24-
| ir.cpp:2551:48:2551:71 | Unary | Operand 'Unary' is not dominated by its definition in function '$@'. | ir.cpp:2550:6:2550:28 | void constexpr_inconsistency(bool) | void constexpr_inconsistency(bool) |
2524
| try_except.c:13:13:13:13 | Left | Operand 'Left' is not dominated by its definition in function '$@'. | try_except.c:6:6:6:6 | void f() | void f() |
2625
| try_except.c:13:13:13:13 | Left | Operand 'Left' is not dominated by its definition in function '$@'. | try_except.c:6:6:6:6 | void f() | void f() |
2726
| try_except.c:39:15:39:15 | Left | Operand 'Left' is not dominated by its definition in function '$@'. | try_except.c:32:6:32:6 | void h(int) | void h(int) |

0 commit comments

Comments
 (0)