Skip to content

Commit 55da325

Browse files
committed
C++: Fix multiple toString consistency error in use-use dataflow
1 parent a2248cb commit 55da325

File tree

5 files changed

+10
-160
lines changed

5 files changed

+10
-160
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,11 @@ class InstructionNode extends Node0 {
413413
/** Gets the instruction corresponding to this node. */
414414
Instruction getInstruction() { result = instr }
415415

416-
override string toStringImpl() { result = instr.getAst().toString() }
416+
override string toStringImpl() {
417+
if instr.(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable
418+
then result = "this"
419+
else result = instr.getAst().toString()
420+
}
417421
}
418422

419423
/**
@@ -428,7 +432,11 @@ class OperandNode extends Node, Node0 {
428432
/** Gets the operand corresponding to this node. */
429433
Operand getOperand() { result = op }
430434

431-
override string toStringImpl() { result = op.getDef().getAst().toString() }
435+
override string toStringImpl() {
436+
if op.getDef().(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable
437+
then result = "this"
438+
else result = op.getDef().getAst().toString()
439+
}
432440
}
433441

434442
/**

cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-ir-consistency.expected

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@ uniqueType
33
uniqueNodeLocation
44
missingLocation
55
uniqueNodeToString
6-
| dispatch.cpp:15:8:15:8 | Middle | Node should have one toString but has 2. |
7-
| dispatch.cpp:15:8:15:8 | Middle indirection | Node should have one toString but has 2. |
8-
| dispatch.cpp:15:8:15:8 | Middle indirection | Node should have one toString but has 2. |
9-
| dispatch.cpp:15:8:15:8 | this | Node should have one toString but has 2. |
10-
| dispatch.cpp:15:8:15:8 | this indirection | Node should have one toString but has 2. |
11-
| dispatch.cpp:15:8:15:8 | this indirection | Node should have one toString but has 2. |
12-
| dispatch.cpp:21:8:21:8 | Bottom | Node should have one toString but has 2. |
13-
| dispatch.cpp:21:8:21:8 | Bottom indirection | Node should have one toString but has 2. |
14-
| dispatch.cpp:21:8:21:8 | Bottom indirection | Node should have one toString but has 2. |
15-
| dispatch.cpp:21:8:21:8 | this | Node should have one toString but has 2. |
16-
| dispatch.cpp:21:8:21:8 | this indirection | Node should have one toString but has 2. |
17-
| dispatch.cpp:21:8:21:8 | this indirection | Node should have one toString but has 2. |
186
missingToString
197
parameterCallable
208
localFlowIsLocal

cpp/ql/test/library-tests/dataflow/fields/dataflow-ir-consistency.expected

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,6 @@ uniqueType
33
uniqueNodeLocation
44
missingLocation
55
uniqueNodeToString
6-
| A.cpp:9:9:9:9 | C1 | Node should have one toString but has 2. |
7-
| A.cpp:9:9:9:9 | C1 indirection | Node should have one toString but has 2. |
8-
| A.cpp:9:9:9:9 | C1 indirection | Node should have one toString but has 2. |
9-
| A.cpp:9:9:9:9 | this | Node should have one toString but has 2. |
10-
| A.cpp:9:9:9:9 | this indirection | Node should have one toString but has 2. |
11-
| A.cpp:9:9:9:9 | this indirection | Node should have one toString but has 2. |
12-
| A.cpp:14:9:14:9 | C2 | Node should have one toString but has 2. |
13-
| A.cpp:14:9:14:9 | C2 indirection | Node should have one toString but has 2. |
14-
| A.cpp:14:9:14:9 | C2 indirection | Node should have one toString but has 2. |
15-
| A.cpp:14:9:14:9 | this | Node should have one toString but has 2. |
16-
| A.cpp:14:9:14:9 | this indirection | Node should have one toString but has 2. |
17-
| A.cpp:14:9:14:9 | this indirection | Node should have one toString but has 2. |
18-
| C.cpp:22:3:22:3 | C | Node should have one toString but has 2. |
19-
| C.cpp:22:3:22:3 | C indirection | Node should have one toString but has 2. |
20-
| C.cpp:22:3:22:3 | C indirection | Node should have one toString but has 2. |
21-
| C.cpp:22:3:22:3 | this | Node should have one toString but has 2. |
22-
| C.cpp:22:3:22:3 | this indirection | Node should have one toString but has 2. |
23-
| C.cpp:22:3:22:3 | this indirection | Node should have one toString but has 2. |
24-
| C.cpp:22:9:22:22 | C indirection [post update] | Node should have one toString but has 2. |
25-
| C.cpp:22:9:22:22 | this indirection [post update] | Node should have one toString but has 2. |
26-
| complex.cpp:22:3:22:5 | Bar | Node should have one toString but has 2. |
27-
| complex.cpp:22:3:22:5 | Bar indirection | Node should have one toString but has 2. |
28-
| complex.cpp:22:3:22:5 | Bar indirection | Node should have one toString but has 2. |
29-
| complex.cpp:22:3:22:5 | this | Node should have one toString but has 2. |
30-
| complex.cpp:22:3:22:5 | this indirection | Node should have one toString but has 2. |
31-
| complex.cpp:22:3:22:5 | this indirection | Node should have one toString but has 2. |
32-
| complex.cpp:22:11:22:17 | Bar indirection [post update] | Node should have one toString but has 2. |
33-
| complex.cpp:22:11:22:17 | Bar indirection [post update] | Node should have one toString but has 2. |
34-
| complex.cpp:22:11:22:17 | this indirection [post update] | Node should have one toString but has 2. |
35-
| complex.cpp:22:11:22:17 | this indirection [post update] | Node should have one toString but has 2. |
36-
| complex.cpp:25:7:25:7 | Outer | Node should have one toString but has 2. |
37-
| complex.cpp:25:7:25:7 | Outer indirection | Node should have one toString but has 2. |
38-
| complex.cpp:25:7:25:7 | Outer indirection | Node should have one toString but has 2. |
39-
| complex.cpp:25:7:25:7 | Outer indirection [post update] | Node should have one toString but has 2. |
40-
| complex.cpp:25:7:25:7 | Outer indirection [post update] | Node should have one toString but has 2. |
41-
| complex.cpp:25:7:25:7 | this | Node should have one toString but has 2. |
42-
| complex.cpp:25:7:25:7 | this indirection | Node should have one toString but has 2. |
43-
| complex.cpp:25:7:25:7 | this indirection | Node should have one toString but has 2. |
44-
| complex.cpp:25:7:25:7 | this indirection [post update] | Node should have one toString but has 2. |
45-
| complex.cpp:25:7:25:7 | this indirection [post update] | Node should have one toString but has 2. |
46-
| conflated.cpp:45:3:45:12 | LinkedList | Node should have one toString but has 2. |
47-
| conflated.cpp:45:3:45:12 | LinkedList indirection | Node should have one toString but has 2. |
48-
| conflated.cpp:45:3:45:12 | LinkedList indirection | Node should have one toString but has 2. |
49-
| conflated.cpp:45:3:45:12 | this | Node should have one toString but has 2. |
50-
| conflated.cpp:45:3:45:12 | this indirection | Node should have one toString but has 2. |
51-
| conflated.cpp:45:3:45:12 | this indirection | Node should have one toString but has 2. |
52-
| conflated.cpp:45:34:45:43 | LinkedList indirection [post update] | Node should have one toString but has 2. |
53-
| conflated.cpp:45:34:45:43 | this indirection [post update] | Node should have one toString but has 2. |
546
missingToString
557
parameterCallable
568
localFlowIsLocal
@@ -66,9 +18,7 @@ uniquePostUpdate
6618
| aliasing.cpp:77:11:77:11 | definition of w indirection | Node has multiple PostUpdateNodes. |
6719
| aliasing.cpp:84:11:84:11 | definition of w indirection | Node has multiple PostUpdateNodes. |
6820
| aliasing.cpp:91:11:91:11 | definition of w indirection | Node has multiple PostUpdateNodes. |
69-
| complex.cpp:22:3:22:5 | Bar indirection | Node has multiple PostUpdateNodes. |
7021
| complex.cpp:22:3:22:5 | this indirection | Node has multiple PostUpdateNodes. |
71-
| complex.cpp:25:7:25:7 | Outer indirection | Node has multiple PostUpdateNodes. |
7222
| complex.cpp:25:7:25:7 | this indirection | Node has multiple PostUpdateNodes. |
7323
| complex.cpp:42:10:42:14 | inner indirection | Node has multiple PostUpdateNodes. |
7424
| complex.cpp:43:10:43:14 | inner indirection | Node has multiple PostUpdateNodes. |

cpp/ql/test/library-tests/dataflow/fields/ir-path-flow.expected

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ edges
192192
| C.cpp:18:12:18:18 | call to C [s3] | C.cpp:19:5:19:5 | c indirection [s3] |
193193
| C.cpp:19:5:19:5 | c indirection [s1] | C.cpp:27:8:27:11 | this indirection [s1] |
194194
| C.cpp:19:5:19:5 | c indirection [s3] | C.cpp:27:8:27:11 | this indirection [s3] |
195-
| C.cpp:22:9:22:22 | C indirection [post update] [s1] | C.cpp:18:12:18:18 | call to C [s1] |
196195
| C.cpp:22:9:22:22 | this indirection [post update] [s1] | C.cpp:18:12:18:18 | call to C [s1] |
197-
| C.cpp:22:12:22:21 | new | C.cpp:22:9:22:22 | C indirection [post update] [s1] |
198196
| C.cpp:22:12:22:21 | new | C.cpp:22:9:22:22 | this indirection [post update] [s1] |
199197
| C.cpp:22:12:22:21 | new | C.cpp:22:12:22:21 | new |
200198
| C.cpp:24:5:24:25 | ... = ... | C.cpp:24:11:24:12 | this indirection [post update] [s3] |
@@ -1084,9 +1082,6 @@ nodes
10841082
| C.cpp:18:12:18:18 | call to C [s3] | semmle.label | call to C [s3] |
10851083
| C.cpp:19:5:19:5 | c indirection [s1] | semmle.label | c indirection [s1] |
10861084
| C.cpp:19:5:19:5 | c indirection [s3] | semmle.label | c indirection [s3] |
1087-
| C.cpp:22:9:22:22 | C indirection [post update] [s1] | semmle.label | C indirection [post update] [s1] |
1088-
| C.cpp:22:9:22:22 | C indirection [post update] [s1] | semmle.label | this indirection [post update] [s1] |
1089-
| C.cpp:22:9:22:22 | this indirection [post update] [s1] | semmle.label | C indirection [post update] [s1] |
10901085
| C.cpp:22:9:22:22 | this indirection [post update] [s1] | semmle.label | this indirection [post update] [s1] |
10911086
| C.cpp:22:12:22:21 | new | semmle.label | new |
10921087
| C.cpp:22:12:22:21 | new | semmle.label | new |

cpp/ql/test/library-tests/syntax-zoo/dataflow-ir-consistency.expected

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -28,94 +28,6 @@ uniqueNodeLocation
2828
missingLocation
2929
| Nodes without location: 12 |
3030
uniqueNodeToString
31-
| cpp11.cpp:65:20:65:20 | (unnamed constructor) | Node should have one toString but has 2. |
32-
| cpp11.cpp:65:20:65:20 | (unnamed constructor) indirection | Node should have one toString but has 2. |
33-
| cpp11.cpp:65:20:65:20 | (unnamed constructor) indirection | Node should have one toString but has 2. |
34-
| cpp11.cpp:65:20:65:20 | (unnamed constructor) indirection [post update] | Node should have one toString but has 2. |
35-
| cpp11.cpp:65:20:65:20 | this | Node should have one toString but has 2. |
36-
| cpp11.cpp:65:20:65:20 | this indirection | Node should have one toString but has 2. |
37-
| cpp11.cpp:65:20:65:20 | this indirection | Node should have one toString but has 2. |
38-
| cpp11.cpp:65:20:65:20 | this indirection [post update] | Node should have one toString but has 2. |
39-
| ir.cpp:747:8:747:8 | Base | Node should have one toString but has 2. |
40-
| ir.cpp:747:8:747:8 | Base indirection | Node should have one toString but has 2. |
41-
| ir.cpp:747:8:747:8 | Base indirection | Node should have one toString but has 2. |
42-
| ir.cpp:747:8:747:8 | Base indirection [post update] | Node should have one toString but has 2. |
43-
| ir.cpp:747:8:747:8 | Base indirection [post update] | Node should have one toString but has 2. |
44-
| ir.cpp:747:8:747:8 | this | Node should have one toString but has 2. |
45-
| ir.cpp:747:8:747:8 | this indirection | Node should have one toString but has 2. |
46-
| ir.cpp:747:8:747:8 | this indirection | Node should have one toString but has 2. |
47-
| ir.cpp:747:8:747:8 | this indirection [post update] | Node should have one toString but has 2. |
48-
| ir.cpp:747:8:747:8 | this indirection [post update] | Node should have one toString but has 2. |
49-
| ir.cpp:750:3:750:6 | Base | Node should have one toString but has 2. |
50-
| ir.cpp:750:3:750:6 | Base indirection | Node should have one toString but has 2. |
51-
| ir.cpp:750:3:750:6 | Base indirection | Node should have one toString but has 2. |
52-
| ir.cpp:750:3:750:6 | this | Node should have one toString but has 2. |
53-
| ir.cpp:750:3:750:6 | this indirection | Node should have one toString but has 2. |
54-
| ir.cpp:750:3:750:6 | this indirection | Node should have one toString but has 2. |
55-
| ir.cpp:750:10:750:10 | Base indirection [post update] | Node should have one toString but has 2. |
56-
| ir.cpp:750:10:750:10 | Base indirection [post update] | Node should have one toString but has 2. |
57-
| ir.cpp:750:10:750:10 | this indirection [post update] | Node should have one toString but has 2. |
58-
| ir.cpp:750:10:750:10 | this indirection [post update] | Node should have one toString but has 2. |
59-
| ir.cpp:752:3:752:7 | this | Node should have one toString but has 2. |
60-
| ir.cpp:752:3:752:7 | this indirection | Node should have one toString but has 2. |
61-
| ir.cpp:752:3:752:7 | this indirection | Node should have one toString but has 2. |
62-
| ir.cpp:752:3:752:7 | ~Base | Node should have one toString but has 2. |
63-
| ir.cpp:752:3:752:7 | ~Base indirection | Node should have one toString but has 2. |
64-
| ir.cpp:752:3:752:7 | ~Base indirection | Node should have one toString but has 2. |
65-
| ir.cpp:753:3:753:3 | this indirection [post update] | Node should have one toString but has 2. |
66-
| ir.cpp:753:3:753:3 | ~Base indirection [post update] | Node should have one toString but has 2. |
67-
| ir.cpp:848:8:848:8 | PolymorphicDerived | Node should have one toString but has 2. |
68-
| ir.cpp:848:8:848:8 | PolymorphicDerived indirection | Node should have one toString but has 2. |
69-
| ir.cpp:848:8:848:8 | PolymorphicDerived indirection | Node should have one toString but has 2. |
70-
| ir.cpp:848:8:848:8 | this | Node should have one toString but has 2. |
71-
| ir.cpp:848:8:848:8 | this | Node should have one toString but has 2. |
72-
| ir.cpp:848:8:848:8 | this indirection | Node should have one toString but has 2. |
73-
| ir.cpp:848:8:848:8 | this indirection | Node should have one toString but has 2. |
74-
| ir.cpp:848:8:848:8 | this indirection | Node should have one toString but has 2. |
75-
| ir.cpp:848:8:848:8 | this indirection | Node should have one toString but has 2. |
76-
| ir.cpp:848:8:848:8 | ~PolymorphicDerived | Node should have one toString but has 2. |
77-
| ir.cpp:848:8:848:8 | ~PolymorphicDerived indirection | Node should have one toString but has 2. |
78-
| ir.cpp:848:8:848:8 | ~PolymorphicDerived indirection | Node should have one toString but has 2. |
79-
| ir.cpp:869:1:869:14 | String | Node should have one toString but has 2. |
80-
| ir.cpp:869:1:869:14 | String indirection | Node should have one toString but has 2. |
81-
| ir.cpp:869:1:869:14 | String indirection | Node should have one toString but has 2. |
82-
| ir.cpp:869:1:869:14 | this | Node should have one toString but has 2. |
83-
| ir.cpp:869:1:869:14 | this indirection | Node should have one toString but has 2. |
84-
| ir.cpp:869:1:869:14 | this indirection | Node should have one toString but has 2. |
85-
| static_init_templates.cpp:236:7:236:7 | MyDerivedClass | Node should have one toString but has 2. |
86-
| static_init_templates.cpp:236:7:236:7 | MyDerivedClass indirection | Node should have one toString but has 2. |
87-
| static_init_templates.cpp:236:7:236:7 | MyDerivedClass indirection | Node should have one toString but has 2. |
88-
| static_init_templates.cpp:236:7:236:7 | this | Node should have one toString but has 2. |
89-
| static_init_templates.cpp:236:7:236:7 | this indirection | Node should have one toString but has 2. |
90-
| static_init_templates.cpp:236:7:236:7 | this indirection | Node should have one toString but has 2. |
91-
| static_init_templates.cpp:240:7:240:7 | MyContainingClass | Node should have one toString but has 2. |
92-
| static_init_templates.cpp:240:7:240:7 | MyContainingClass indirection | Node should have one toString but has 2. |
93-
| static_init_templates.cpp:240:7:240:7 | MyContainingClass indirection | Node should have one toString but has 2. |
94-
| static_init_templates.cpp:240:7:240:7 | MyContainingClass indirection [post update] | Node should have one toString but has 2. |
95-
| static_init_templates.cpp:240:7:240:7 | MyContainingClass indirection [post update] | Node should have one toString but has 2. |
96-
| static_init_templates.cpp:240:7:240:7 | this | Node should have one toString but has 2. |
97-
| static_init_templates.cpp:240:7:240:7 | this indirection | Node should have one toString but has 2. |
98-
| static_init_templates.cpp:240:7:240:7 | this indirection | Node should have one toString but has 2. |
99-
| static_init_templates.cpp:240:7:240:7 | this indirection [post update] | Node should have one toString but has 2. |
100-
| static_init_templates.cpp:240:7:240:7 | this indirection [post update] | Node should have one toString but has 2. |
101-
| try_catch.cpp:7:8:7:8 | exn1 | Node should have one toString but has 2. |
102-
| try_catch.cpp:7:8:7:8 | exn1 | Node should have one toString but has 2. |
103-
| try_catch.cpp:7:8:7:8 | exn1 indirection | Node should have one toString but has 2. |
104-
| try_catch.cpp:7:8:7:8 | exn1 indirection | Node should have one toString but has 2. |
105-
| try_catch.cpp:7:8:7:8 | exn1 indirection | Node should have one toString but has 2. |
106-
| try_catch.cpp:7:8:7:8 | exn1 indirection | Node should have one toString but has 2. |
107-
| try_catch.cpp:7:8:7:8 | this | Node should have one toString but has 2. |
108-
| try_catch.cpp:7:8:7:8 | this | Node should have one toString but has 2. |
109-
| try_catch.cpp:7:8:7:8 | this | Node should have one toString but has 2. |
110-
| try_catch.cpp:7:8:7:8 | this indirection | Node should have one toString but has 2. |
111-
| try_catch.cpp:7:8:7:8 | this indirection | Node should have one toString but has 2. |
112-
| try_catch.cpp:7:8:7:8 | this indirection | Node should have one toString but has 2. |
113-
| try_catch.cpp:7:8:7:8 | this indirection | Node should have one toString but has 2. |
114-
| try_catch.cpp:7:8:7:8 | this indirection | Node should have one toString but has 2. |
115-
| try_catch.cpp:7:8:7:8 | this indirection | Node should have one toString but has 2. |
116-
| try_catch.cpp:7:8:7:8 | ~exn1 | Node should have one toString but has 2. |
117-
| try_catch.cpp:7:8:7:8 | ~exn1 indirection | Node should have one toString but has 2. |
118-
| try_catch.cpp:7:8:7:8 | ~exn1 indirection | Node should have one toString but has 2. |
11931
missingToString
12032
parameterCallable
12133
localFlowIsLocal
@@ -136,16 +48,13 @@ uniquePostUpdate
13648
| ir.cpp:516:10:516:11 | definition of r4 indirection | Node has multiple PostUpdateNodes. |
13749
| ir.cpp:659:5:659:5 | this indirection | Node has multiple PostUpdateNodes. |
13850
| ir.cpp:659:5:659:5 | this indirection | Node has multiple PostUpdateNodes. |
139-
| ir.cpp:747:8:747:8 | Base indirection | Node has multiple PostUpdateNodes. |
14051
| ir.cpp:747:8:747:8 | this indirection | Node has multiple PostUpdateNodes. |
141-
| ir.cpp:750:3:750:6 | Base indirection | Node has multiple PostUpdateNodes. |
14252
| ir.cpp:750:3:750:6 | this indirection | Node has multiple PostUpdateNodes. |
14353
| ir.cpp:759:3:759:8 | this indirection | Node has multiple PostUpdateNodes. |
14454
| ir.cpp:768:3:768:9 | this indirection | Node has multiple PostUpdateNodes. |
14555
| ir.cpp:777:3:777:11 | this indirection | Node has multiple PostUpdateNodes. |
14656
| ir.cpp:786:3:786:11 | this indirection | Node has multiple PostUpdateNodes. |
14757
| ir.cpp:795:3:795:11 | this indirection | Node has multiple PostUpdateNodes. |
148-
| static_init_templates.cpp:240:7:240:7 | MyContainingClass indirection | Node has multiple PostUpdateNodes. |
14958
| static_init_templates.cpp:240:7:240:7 | this indirection | Node has multiple PostUpdateNodes. |
15059
postIsInSameCallable
15160
reverseRead

0 commit comments

Comments
 (0)