Skip to content

Commit e0c7849

Browse files
committed
C++: fix incorrect use of getChildInternal
1 parent 2494b7d commit e0c7849

File tree

9 files changed

+81
-58
lines changed

9 files changed

+81
-58
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ class TranslatedReturnVoidExpressionStmt extends TranslatedReturnStmt {
482482
override Instruction getInstructionSuccessorInternal(InstructionTag tag, EdgeKind kind) {
483483
tag = OnlyInstructionTag() and
484484
if this.hasAnImplicitDestructorCall()
485-
then result = this.getChildInternal(1).getFirstInstruction(kind)
485+
then result = this.getChild(1).getFirstInstruction(kind)
486486
else result = this.getEnclosingFunction().getReturnSuccessorInstruction(kind)
487487
}
488488

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

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13526,21 +13526,21 @@ ir.cpp:
1352613526
#-----| True -> Block 3
1352713527

1352813528
# 2240| Block 1
13529-
# 2240| m2240_7(unknown) = Phi : from 3:~m2249_5, from 6:~m2249_14
13529+
# 2240| m2240_7(unknown) = Phi : from 2:~m2249_21, from 2:~m2249_5, from 5:~m2249_21, from 5:~m2249_5, from 3:~m2249_13, from 2:~m2249_21, from 2:~m2249_5, from 5:~m2249_21, from 5:~m2249_5, from 6:~m2249_30
1353013530
# 2240| v2240_8(void) = ReturnVoid :
1353113531
# 2240| v2240_9(void) = AliasedUse : ~m2240_7
1353213532
# 2240| v2240_10(void) = ExitFunction :
1353313533

1353413534
# 2243| Block 3
13535-
# 2243| v2243_1(void) = NoOp :
13536-
# 2249| r2249_1(glval<String>) = VariableAddress[s] :
13537-
# 2249| r2249_2(glval<unknown>) = FunctionAddress[~String] :
13538-
# 2249| v2249_3(void) = Call[~String] : func:r2249_2, this:r2249_1
13539-
# 2249| m2249_4(unknown) = ^CallSideEffect : ~m2241_6
13540-
# 2249| m2249_5(unknown) = Chi : total:m2241_6, partial:m2249_4
13541-
# 2249| v2249_6(void) = ^IndirectReadSideEffect[-1] : &:r2249_1, m2241_8
13542-
# 2249| m2249_7(String) = ^IndirectMayWriteSideEffect[-1] : &:r2249_1
13543-
# 2249| m2249_8(String) = Chi : total:m2241_8, partial:m2249_7
13535+
# 2243| v2243_1(void) = NoOp :
13536+
# 2249| r2249_9(glval<String>) = VariableAddress[s] :
13537+
# 2249| r2249_10(glval<unknown>) = FunctionAddress[~String] :
13538+
# 2249| v2249_11(void) = Call[~String] : func:r2249_10, this:r2249_9
13539+
# 2249| m2249_12(unknown) = ^CallSideEffect : ~m2241_6
13540+
# 2249| m2249_13(unknown) = Chi : total:m2241_6, partial:m2249_12
13541+
# 2249| v2249_14(void) = ^IndirectReadSideEffect[-1] : &:r2249_9, m2241_8
13542+
# 2249| m2249_15(String) = ^IndirectMayWriteSideEffect[-1] : &:r2249_9
13543+
# 2249| m2249_16(String) = Chi : total:m2241_8, partial:m2249_15
1354413544
#-----| Goto -> Block 1
1354513545

1354613546
# 2245| Block 4
@@ -13552,25 +13552,35 @@ ir.cpp:
1355213552
#-----| True -> Block 5
1355313553

1355413554
# 2246| Block 5
13555-
# 2246| r2246_6(glval<unknown>) = FunctionAddress[VoidFunc] :
13556-
# 2246| v2246_7(void) = Call[VoidFunc] : func:r2246_1, func:r2246_6
13557-
# 2246| m2246_8(unknown) = ^CallSideEffect : ~m2241_6
13558-
# 2246| m2246_9(unknown) = Chi : total:m2241_6, partial:m2246_3, partial:m2246_8
13559-
# 2246| v2246_5(void) = NoOp :
13555+
# 2246| r2246_6(glval<unknown>) = FunctionAddress[VoidFunc] :
13556+
# 2246| v2246_7(void) = Call[VoidFunc] : func:r2246_1, func:r2246_6
13557+
# 2246| m2246_8(unknown) = ^CallSideEffect : ~m2241_6
13558+
# 2246| m2246_9(unknown) = Chi : total:m2241_6, partial:m2246_3, partial:m2246_8
13559+
# 2246| v2246_5(void) = NoOp :
13560+
# 2249| r2249_1(glval<String>) = VariableAddress[s] :
13561+
# 2249| r2249_2(glval<unknown>) = FunctionAddress[~String] :
13562+
# 2249| v2249_3(void) = Call[~String] : func:r2249_18, func:r2249_2, this:r2249_1, this:r2249_17
13563+
# 2249| m2249_4(unknown) = ^CallSideEffect : ~m2246_4, ~m2246_9
13564+
# 2249| m2249_5(unknown) = Chi : total:m2246_4, total:m2246_9, partial:m2249_20, partial:m2249_4
13565+
# 2249| v2249_6(void) = ^IndirectReadSideEffect[-1] : &:r2249_1, &:r2249_17, m2241_8
13566+
# 2249| m2249_7(String) = ^IndirectMayWriteSideEffect[-1] : &:r2249_1, &:r2249_17
13567+
# 2249| m2249_8(String) = Chi : total:m2241_8, partial:m2249_23, partial:m2249_7
13568+
#-----| Goto -> Block 1
1356013569

1356113570
# 2246| Block 5
13571+
#-----| Goto -> Block 1
1356213572

1356313573
# 2248| Block 6
1356413574
# 2248| r2248_1(glval<String>) = VariableAddress[s] :
13565-
# 2249| v2249_9(void) = NoOp :
13566-
# 2249| r2249_10(glval<String>) = VariableAddress[s] :
13567-
# 2249| r2249_11(glval<unknown>) = FunctionAddress[~String] :
13568-
# 2249| v2249_12(void) = Call[~String] : func:r2249_11, this:r2249_10
13569-
# 2249| m2249_13(unknown) = ^CallSideEffect : ~m2241_6
13570-
# 2249| m2249_14(unknown) = Chi : total:m2241_6, partial:m2249_13
13571-
# 2249| v2249_15(void) = ^IndirectReadSideEffect[-1] : &:r2249_10, m2241_8
13572-
# 2249| m2249_16(String) = ^IndirectMayWriteSideEffect[-1] : &:r2249_10
13573-
# 2249| m2249_17(String) = Chi : total:m2241_8, partial:m2249_16
13575+
# 2249| v2249_25(void) = NoOp :
13576+
# 2249| r2249_26(glval<String>) = VariableAddress[s] :
13577+
# 2249| r2249_27(glval<unknown>) = FunctionAddress[~String] :
13578+
# 2249| v2249_28(void) = Call[~String] : func:r2249_27, this:r2249_26
13579+
# 2249| m2249_29(unknown) = ^CallSideEffect : ~m2241_6
13580+
# 2249| m2249_30(unknown) = Chi : total:m2241_6, partial:m2249_29
13581+
# 2249| v2249_31(void) = ^IndirectReadSideEffect[-1] : &:r2249_26, m2241_8
13582+
# 2249| m2249_32(String) = ^IndirectMayWriteSideEffect[-1] : &:r2249_26
13583+
# 2249| m2249_33(String) = Chi : total:m2241_8, partial:m2249_32
1357413584
#-----| Goto -> Block 1
1357513585

1357613586
# 2251| int IfReturnDestructors3(bool)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
99
| ir.cpp:2138:21:2138:21 | Chi: x | Instruction 'Chi: x' has no successors in function '$@'. | ir.cpp:2136:6:2136:35 | void initialization_with_destructor(bool, char) | void initialization_with_destructor(bool, char) |
10-
| ir.cpp:2246:9:2246:26 | NoOp: return ... | Instruction 'NoOp: return ...' has no successors in function '$@'. | ir.cpp:2240:6:2240:24 | void IfReturnDestructors(bool) | void IfReturnDestructors(bool) |
1110
ambiguousSuccessors
1211
unexplainedLoop
1312
unnecessaryPhiInstruction

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
99
| ir.cpp:2138:21:2138:21 | Chi: x | Instruction 'Chi: x' has no successors in function '$@'. | ir.cpp:2136:6:2136:35 | void initialization_with_destructor(bool, char) | void initialization_with_destructor(bool, char) |
10-
| ir.cpp:2246:9:2246:26 | NoOp: return ... | Instruction 'NoOp: return ...' has no successors in function '$@'. | ir.cpp:2240:6:2240:24 | void IfReturnDestructors(bool) | void IfReturnDestructors(bool) |
1110
ambiguousSuccessors
1211
unexplainedLoop
1312
unnecessaryPhiInstruction

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

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11047,8 +11047,12 @@
1104711047
| ir.cpp:2238:6:2238:13 | SideEffect | m2238_3 |
1104811048
| ir.cpp:2240:6:2240:24 | ChiPartial | partial:m2240_3 |
1104911049
| ir.cpp:2240:6:2240:24 | ChiTotal | total:m2240_2 |
11050-
| ir.cpp:2240:6:2240:24 | Phi | from 3:~m2249_5 |
11051-
| ir.cpp:2240:6:2240:24 | Phi | from 6:~m2249_14 |
11050+
| ir.cpp:2240:6:2240:24 | Phi | from 2:~m2249_5 |
11051+
| ir.cpp:2240:6:2240:24 | Phi | from 2:~m2249_21 |
11052+
| ir.cpp:2240:6:2240:24 | Phi | from 3:~m2249_13 |
11053+
| ir.cpp:2240:6:2240:24 | Phi | from 5:~m2249_5 |
11054+
| ir.cpp:2240:6:2240:24 | Phi | from 5:~m2249_21 |
11055+
| ir.cpp:2240:6:2240:24 | Phi | from 6:~m2249_30 |
1105211056
| ir.cpp:2240:6:2240:24 | SideEffect | ~m2240_7 |
1105311057
| ir.cpp:2240:31:2240:31 | Address | &:r2240_5 |
1105411058
| ir.cpp:2241:12:2241:12 | Address | &:r2241_1 |
@@ -11074,24 +11078,42 @@
1107411078
| ir.cpp:2246:16:2246:23 | SideEffect | ~m2241_6 |
1107511079
| ir.cpp:2249:1:2249:1 | Address | &:r2249_1 |
1107611080
| ir.cpp:2249:1:2249:1 | Address | &:r2249_1 |
11077-
| ir.cpp:2249:1:2249:1 | Address | &:r2249_10 |
11078-
| ir.cpp:2249:1:2249:1 | Address | &:r2249_10 |
11081+
| ir.cpp:2249:1:2249:1 | Address | &:r2249_9 |
11082+
| ir.cpp:2249:1:2249:1 | Address | &:r2249_9 |
11083+
| ir.cpp:2249:1:2249:1 | Address | &:r2249_17 |
11084+
| ir.cpp:2249:1:2249:1 | Address | &:r2249_17 |
11085+
| ir.cpp:2249:1:2249:1 | Address | &:r2249_26 |
11086+
| ir.cpp:2249:1:2249:1 | Address | &:r2249_26 |
1107911087
| ir.cpp:2249:1:2249:1 | Arg(this) | this:r2249_1 |
11080-
| ir.cpp:2249:1:2249:1 | Arg(this) | this:r2249_10 |
11088+
| ir.cpp:2249:1:2249:1 | Arg(this) | this:r2249_9 |
11089+
| ir.cpp:2249:1:2249:1 | Arg(this) | this:r2249_17 |
11090+
| ir.cpp:2249:1:2249:1 | Arg(this) | this:r2249_26 |
1108111091
| ir.cpp:2249:1:2249:1 | CallTarget | func:r2249_2 |
11082-
| ir.cpp:2249:1:2249:1 | CallTarget | func:r2249_11 |
11092+
| ir.cpp:2249:1:2249:1 | CallTarget | func:r2249_10 |
11093+
| ir.cpp:2249:1:2249:1 | CallTarget | func:r2249_18 |
11094+
| ir.cpp:2249:1:2249:1 | CallTarget | func:r2249_27 |
1108311095
| ir.cpp:2249:1:2249:1 | ChiPartial | partial:m2249_4 |
1108411096
| ir.cpp:2249:1:2249:1 | ChiPartial | partial:m2249_7 |
11085-
| ir.cpp:2249:1:2249:1 | ChiPartial | partial:m2249_13 |
11086-
| ir.cpp:2249:1:2249:1 | ChiPartial | partial:m2249_16 |
11097+
| ir.cpp:2249:1:2249:1 | ChiPartial | partial:m2249_12 |
11098+
| ir.cpp:2249:1:2249:1 | ChiPartial | partial:m2249_15 |
11099+
| ir.cpp:2249:1:2249:1 | ChiPartial | partial:m2249_20 |
11100+
| ir.cpp:2249:1:2249:1 | ChiPartial | partial:m2249_23 |
11101+
| ir.cpp:2249:1:2249:1 | ChiPartial | partial:m2249_29 |
11102+
| ir.cpp:2249:1:2249:1 | ChiPartial | partial:m2249_32 |
1108711103
| ir.cpp:2249:1:2249:1 | ChiTotal | total:m2241_6 |
1108811104
| ir.cpp:2249:1:2249:1 | ChiTotal | total:m2241_6 |
1108911105
| ir.cpp:2249:1:2249:1 | ChiTotal | total:m2241_8 |
1109011106
| ir.cpp:2249:1:2249:1 | ChiTotal | total:m2241_8 |
11107+
| ir.cpp:2249:1:2249:1 | ChiTotal | total:m2241_8 |
11108+
| ir.cpp:2249:1:2249:1 | ChiTotal | total:m2246_4 |
11109+
| ir.cpp:2249:1:2249:1 | ChiTotal | total:m2246_9 |
11110+
| ir.cpp:2249:1:2249:1 | SideEffect | m2241_8 |
1109111111
| ir.cpp:2249:1:2249:1 | SideEffect | m2241_8 |
1109211112
| ir.cpp:2249:1:2249:1 | SideEffect | m2241_8 |
1109311113
| ir.cpp:2249:1:2249:1 | SideEffect | ~m2241_6 |
1109411114
| ir.cpp:2249:1:2249:1 | SideEffect | ~m2241_6 |
11115+
| ir.cpp:2249:1:2249:1 | SideEffect | ~m2246_4 |
11116+
| ir.cpp:2249:1:2249:1 | SideEffect | ~m2246_9 |
1109511117
| ir.cpp:2251:5:2251:24 | Address | &:r2251_9 |
1109611118
| ir.cpp:2251:5:2251:24 | ChiPartial | partial:m2251_3 |
1109711119
| ir.cpp:2251:5:2251:24 | ChiTotal | total:m2251_2 |

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ instructionWithoutSuccessor
1010
| ir.cpp:2140:39:2140:39 | IndirectMayWriteSideEffect: call to ClassWithDestructor | Instruction 'IndirectMayWriteSideEffect: call to ClassWithDestructor' has no successors in function '$@'. | ir.cpp:2136:6:2136:35 | void initialization_with_destructor(bool, char) | void initialization_with_destructor(bool, char) |
1111
| ir.cpp:2140:42:2140:76 | Constant: initialization_with_destructor_bool | Instruction 'Constant: initialization_with_destructor_bool' has no successors in function '$@'. | ir.cpp:2136:6:2136:35 | void initialization_with_destructor(bool, char) | void initialization_with_destructor(bool, char) |
1212
| ir.cpp:2141:9:2141:9 | IndirectMayWriteSideEffect: x | Instruction 'IndirectMayWriteSideEffect: x' has no successors in function '$@'. | ir.cpp:2136:6:2136:35 | void initialization_with_destructor(bool, char) | void initialization_with_destructor(bool, char) |
13-
| ir.cpp:2246:9:2246:26 | NoOp: return ... | Instruction 'NoOp: return ...' has no successors in function '$@'. | ir.cpp:2240:6:2240:24 | void IfReturnDestructors(bool) | void IfReturnDestructors(bool) |
1413
ambiguousSuccessors
1514
unexplainedLoop
1615
unnecessaryPhiInstruction

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

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12711,23 +12711,15 @@ ir.cpp:
1271112711
# 2242| r2242_1(glval<bool>) = VariableAddress[b] :
1271212712
# 2242| r2242_2(bool) = Load[b] : &:r2242_1, ~m?
1271312713
# 2242| v2242_3(void) = ConditionalBranch : r2242_2
12714-
#-----| False -> Block 5
12715-
#-----| True -> Block 4
12714+
#-----| False -> Block 4
12715+
#-----| True -> Block 3
1271612716

1271712717
# 2240| Block 1
1271812718
# 2240| v2240_6(void) = ReturnVoid :
1271912719
# 2240| v2240_7(void) = AliasedUse : ~m?
1272012720
# 2240| v2240_8(void) = ExitFunction :
1272112721

12722-
# 2246| Block 6
12723-
# 2246| r2246_5(glval<unknown>) = FunctionAddress[VoidFunc] :
12724-
# 2246| v2246_6(void) = Call[VoidFunc] : func:r2246_1, func:r2246_5
12725-
# 2246| mu2246_7(unknown) = ^CallSideEffect : ~m?
12726-
# 2246| v2246_8(void) = NoOp :
12727-
12728-
# 2246| Block 6
12729-
12730-
# 2243| Block 4
12722+
# 2243| Block 3
1273112723
# 2243| v2243_1(void) = NoOp :
1273212724
# 2249| r2249_7(glval<String>) = VariableAddress[s] :
1273312725
# 2249| r2249_8(glval<unknown>) = FunctionAddress[~String] :
@@ -12737,27 +12729,31 @@ ir.cpp:
1273712729
# 2249| mu2249_12(String) = ^IndirectMayWriteSideEffect[-1] : &:r2249_7
1273812730
#-----| Goto -> Block 1
1273912731

12740-
# 2245| Block 5
12732+
# 2245| Block 4
1274112733
# 2245| r2245_1(glval<bool>) = VariableAddress[b] :
1274212734
# 2245| r2245_2(bool) = Load[b] : &:r2245_1, ~m?
1274312735
# 2245| v2245_3(void) = ConditionalBranch : r2245_2
12744-
#-----| False -> Block 8
12745-
#-----| True -> Block 6
12746-
#-----| True -> Block 6
12736+
#-----| False -> Block 6
12737+
#-----| True -> Block 5
12738+
#-----| True -> Block 5
1274712739

12748-
# 2249| Block 7
12749-
# 2249| r2249_1(glval<String>) = VariableAddress[s] :
12750-
# 2249| r2249_2(glval<unknown>) = FunctionAddress[~String] :
12740+
# 2246| Block 5
12741+
# 2246| r2246_5(glval<unknown>) = FunctionAddress[VoidFunc] :
12742+
# 2246| v2246_6(void) = Call[VoidFunc] : func:r2246_1, func:r2246_5
12743+
# 2246| mu2246_7(unknown) = ^CallSideEffect : ~m?
12744+
# 2246| v2246_8(void) = NoOp :
12745+
# 2249| r2249_13(glval<String>) = VariableAddress[s] :
12746+
# 2249| r2249_14(glval<unknown>) = FunctionAddress[~String] :
1275112747
# 2249| v2249_3(void) = Call[~String] : func:r2249_14, func:r2249_2, this:r2249_1, this:r2249_13
1275212748
# 2249| mu2249_4(unknown) = ^CallSideEffect : ~m?
1275312749
# 2249| v2249_5(void) = ^IndirectReadSideEffect[-1] : &:r2249_1, &:r2249_13, ~m?
1275412750
# 2249| mu2249_6(String) = ^IndirectMayWriteSideEffect[-1] : &:r2249_1, &:r2249_13
1275512751
#-----| Goto -> Block 1
1275612752

12757-
# 2249| Block 7
12753+
# 2246| Block 5
1275812754
#-----| Goto -> Block 1
1275912755

12760-
# 2248| Block 8
12756+
# 2248| Block 6
1276112757
# 2248| r2248_1(glval<String>) = VariableAddress[s] :
1276212758
# 2249| v2249_19(void) = NoOp :
1276312759
# 2249| r2249_20(glval<String>) = VariableAddress[s] :

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
99
| ir.cpp:2138:21:2138:21 | IndirectMayWriteSideEffect: x | Instruction 'IndirectMayWriteSideEffect: x' has no successors in function '$@'. | ir.cpp:2136:6:2136:35 | void initialization_with_destructor(bool, char) | void initialization_with_destructor(bool, char) |
10-
| ir.cpp:2246:9:2246:26 | NoOp: return ... | Instruction 'NoOp: return ...' has no successors in function '$@'. | ir.cpp:2240:6:2240:24 | void IfReturnDestructors(bool) | void IfReturnDestructors(bool) |
1110
ambiguousSuccessors
1211
unexplainedLoop
1312
unnecessaryPhiInstruction

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
99
| ir.cpp:2138:21:2138:21 | IndirectMayWriteSideEffect: x | Instruction 'IndirectMayWriteSideEffect: x' has no successors in function '$@'. | ir.cpp:2136:6:2136:35 | void initialization_with_destructor(bool, char) | void initialization_with_destructor(bool, char) |
10-
| ir.cpp:2246:9:2246:26 | NoOp: return ... | Instruction 'NoOp: return ...' has no successors in function '$@'. | ir.cpp:2240:6:2240:24 | void IfReturnDestructors(bool) | void IfReturnDestructors(bool) |
1110
ambiguousSuccessors
1211
unexplainedLoop
1312
unnecessaryPhiInstruction

0 commit comments

Comments
 (0)