Skip to content

Commit 962768e

Browse files
committed
Disambiguate toStrings for nested synthetic local variables
1 parent 6678ac0 commit 962768e

6 files changed

Lines changed: 39 additions & 35 deletions

File tree

ql/src/codeql_ruby/ast/internal/Variable.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,11 @@ class LocalVariableSynth extends LocalVariable, TLocalVariableSynth {
434434

435435
LocalVariableSynth() { this = TLocalVariableSynth(n, i) }
436436

437-
final override string getName() { result = "__synth__" + i }
437+
final override string getName() {
438+
exists(int level | level = desugarLevel(n) |
439+
if level > 0 then result = "__synth__" + i + "__" + level else result = "__synth__" + i
440+
)
441+
}
438442

439443
final override Location getLocation() { result = n.getLocation() }
440444

ql/test/library-tests/ast/AstDesugar.expected

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ calls/calls.rb:
4242
# 316| getAnOperand/getRightOperand: [MethodCall] call to []
4343
# 316| getArgument: [IntegerLiteral] 0
4444
# 316| getReceiver: [LocalVariableAccess] __synth__0
45-
# 316| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0
46-
# 316| getStmt: [LocalVariableAccess] __synth__0
45+
# 316| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
46+
# 316| getStmt: [LocalVariableAccess] __synth__0__1
4747
# 316| getStmt: [AssignExpr] ... = ...
4848
# 316| getDesugared: [StmtSequence] ...
4949
# 316| getStmt: [SetterMethodCall] call to bar=
@@ -54,8 +54,8 @@ calls/calls.rb:
5454
# 316| getBegin: [IntegerLiteral] 1
5555
# 316| getEnd: [IntegerLiteral] -2
5656
# 316| getReceiver: [LocalVariableAccess] __synth__0
57-
# 316| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0
58-
# 316| getStmt: [LocalVariableAccess] __synth__0
57+
# 316| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
58+
# 316| getStmt: [LocalVariableAccess] __synth__0__1
5959
# 316| getAnOperand/getLeftOperand: [MethodCall] call to bar
6060
# 316| getStmt: [AssignExpr] ... = ...
6161
# 316| getDesugared: [StmtSequence] ...
@@ -66,9 +66,9 @@ calls/calls.rb:
6666
# 316| getAnOperand/getRightOperand: [MethodCall] call to []
6767
# 316| getArgument: [IntegerLiteral] -1
6868
# 316| getReceiver: [LocalVariableAccess] __synth__0
69-
# 316| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0
69+
# 316| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
7070
# 316| getArgument: [IntegerLiteral] 4
71-
# 316| getStmt: [LocalVariableAccess] __synth__0
71+
# 316| getStmt: [LocalVariableAccess] __synth__0__1
7272
# 316| getAnOperand/getLeftOperand: [ElementReference] ...[...]
7373
# 316| getStmt: [AssignExpr] ... = ...
7474
# 316| getAnOperand/getRightOperand: [SplatExpr] * ...
@@ -96,9 +96,9 @@ calls/calls.rb:
9696
# 317| getBegin: [IntegerLiteral] 1
9797
# 317| getEnd: [IntegerLiteral] -1
9898
# 317| getReceiver: [LocalVariableAccess] __synth__0
99-
# 317| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0
99+
# 317| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
100100
# 317| getArgument: [IntegerLiteral] 5
101-
# 317| getStmt: [LocalVariableAccess] __synth__0
101+
# 317| getStmt: [LocalVariableAccess] __synth__0__1
102102
# 317| getAnOperand/getLeftOperand: [ElementReference] ...[...]
103103
# 317| getStmt: [AssignExpr] ... = ...
104104
# 317| getAnOperand/getRightOperand: [SplatExpr] * ...

ql/test/library-tests/controlflow/graph/Cfg.expected

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ cfg.rb:
888888
#-----| -> __synth__0
889889

890890
# 62| ... = ...
891-
#-----| -> __synth__0
891+
#-----| -> __synth__0__1
892892

893893
# 62| call to []
894894
#-----| -> ... = ...
@@ -914,11 +914,11 @@ cfg.rb:
914914
# 62| * ...
915915
#-----| -> ... = ...
916916

917-
# 62| __synth__0
917+
# 62| __synth__0__1
918918
#-----| -> __synth__0
919919

920920
# 62| y
921-
#-----| -> __synth__0
921+
#-----| -> __synth__0__1
922922

923923
# 62| ... = ...
924924
#-----| -> z
@@ -929,11 +929,11 @@ cfg.rb:
929929
# 62| 0
930930
#-----| -> call to []
931931

932-
# 62| __synth__0
932+
# 62| __synth__0__1
933933
#-----| -> 0
934934

935935
# 62| z
936-
#-----| -> __synth__0
936+
#-----| -> __synth__0__1
937937

938938
# 62| ... = ...
939939
#-----| -> ...
@@ -944,7 +944,7 @@ cfg.rb:
944944
# 62| 1
945945
#-----| -> call to []
946946

947-
# 62| __synth__0
947+
# 62| __synth__0__1
948948
#-----| -> 1
949949

950950
# 62| [...]
@@ -2519,7 +2519,7 @@ desugar.rb:
25192519
#-----| -> _ .. _
25202520

25212521
# 22| call to z
2522-
#-----| -> __synth__0
2522+
#-----| -> __synth__0__1
25232523

25242524
# 22| self
25252525
#-----| -> call to z
@@ -2534,15 +2534,15 @@ desugar.rb:
25342534
#-----| -> -1
25352535

25362536
# 22| call to bar=
2537-
#-----| -> __synth__0
2537+
#-----| -> __synth__0__1
25382538

2539-
# 22| __synth__0
2539+
# 22| __synth__0__1
25402540
#-----| -> ...
25412541

25422542
# 22| ... = ...
25432543
#-----| -> call to bar=
25442544

2545-
# 22| __synth__0
2545+
# 22| __synth__0__1
25462546
#-----| -> __synth__0
25472547

25482548
# 22| [...]
@@ -2587,7 +2587,7 @@ desugar.rb:
25872587
#-----| -> exit m7 (normal)
25882588

25892589
# 26| ... = ...
2590-
#-----| -> __synth__0
2590+
#-----| -> __synth__0__1
25912591

25922592
# 26| call to []
25932593
#-----| -> ... = ...
@@ -2616,11 +2616,11 @@ desugar.rb:
26162616
# 26| * ...
26172617
#-----| -> ... = ...
26182618

2619-
# 26| __synth__0
2619+
# 26| __synth__0__1
26202620
#-----| -> __synth__0
26212621

26222622
# 26| y
2623-
#-----| -> __synth__0
2623+
#-----| -> __synth__0__1
26242624

26252625
# 26| ... = ...
26262626
#-----| -> z
@@ -2631,11 +2631,11 @@ desugar.rb:
26312631
# 26| 0
26322632
#-----| -> call to []
26332633

2634-
# 26| __synth__0
2634+
# 26| __synth__0__1
26352635
#-----| -> 0
26362636

26372637
# 26| z
2638-
#-----| -> __synth__0
2638+
#-----| -> __synth__0__1
26392639

26402640
# 26| ... = ...
26412641
#-----| -> ...
@@ -2646,7 +2646,7 @@ desugar.rb:
26462646
# 26| 1
26472647
#-----| -> call to []
26482648

2649-
# 26| __synth__0
2649+
# 26| __synth__0__1
26502650
#-----| -> 1
26512651

26522652
# 26| [...]

ql/test/library-tests/variables/ssa.expected

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ definition
4545
| scopes.rb:11:4:11:9 | ... = ... | scopes.rb:7:1:7:1 | a |
4646
| scopes.rb:13:4:13:4 | ... = ... | scopes.rb:7:1:7:1 | a |
4747
| scopes.rb:13:7:13:7 | ... = ... | scopes.rb:13:7:13:7 | b |
48-
| scopes.rb:13:10:13:15 | ... = ... | scopes.rb:13:10:13:15 | __synth__0 |
48+
| scopes.rb:13:10:13:15 | ... = ... | scopes.rb:13:10:13:15 | __synth__0__1 |
4949
| scopes.rb:13:11:13:11 | ... = ... | scopes.rb:13:11:13:11 | c |
5050
| scopes.rb:13:14:13:14 | ... = ... | scopes.rb:13:14:13:14 | d |
5151
| scopes.rb:13:19:13:32 | ... = ... | scopes.rb:13:4:13:32 | __synth__0 |
@@ -132,8 +132,8 @@ read
132132
| scopes.rb:11:4:11:9 | ... = ... | scopes.rb:7:1:7:1 | a | scopes.rb:12:9:12:9 | a |
133133
| scopes.rb:13:4:13:4 | ... = ... | scopes.rb:7:1:7:1 | a | scopes.rb:14:9:14:9 | a |
134134
| scopes.rb:13:7:13:7 | ... = ... | scopes.rb:13:7:13:7 | b | scopes.rb:15:9:15:9 | b |
135-
| scopes.rb:13:10:13:15 | ... = ... | scopes.rb:13:10:13:15 | __synth__0 | scopes.rb:13:11:13:11 | __synth__0 |
136-
| scopes.rb:13:10:13:15 | ... = ... | scopes.rb:13:10:13:15 | __synth__0 | scopes.rb:13:14:13:14 | __synth__0 |
135+
| scopes.rb:13:10:13:15 | ... = ... | scopes.rb:13:10:13:15 | __synth__0__1 | scopes.rb:13:11:13:11 | __synth__0__1 |
136+
| scopes.rb:13:10:13:15 | ... = ... | scopes.rb:13:10:13:15 | __synth__0__1 | scopes.rb:13:14:13:14 | __synth__0__1 |
137137
| scopes.rb:13:11:13:11 | ... = ... | scopes.rb:13:11:13:11 | c | scopes.rb:16:9:16:9 | c |
138138
| scopes.rb:13:14:13:14 | ... = ... | scopes.rb:13:14:13:14 | d | scopes.rb:17:9:17:9 | d |
139139
| scopes.rb:13:19:13:32 | ... = ... | scopes.rb:13:4:13:32 | __synth__0 | scopes.rb:13:4:13:4 | __synth__0 |
@@ -218,7 +218,7 @@ firstRead
218218
| scopes.rb:11:4:11:9 | ... = ... | scopes.rb:7:1:7:1 | a | scopes.rb:12:9:12:9 | a |
219219
| scopes.rb:13:4:13:4 | ... = ... | scopes.rb:7:1:7:1 | a | scopes.rb:14:9:14:9 | a |
220220
| scopes.rb:13:7:13:7 | ... = ... | scopes.rb:13:7:13:7 | b | scopes.rb:15:9:15:9 | b |
221-
| scopes.rb:13:10:13:15 | ... = ... | scopes.rb:13:10:13:15 | __synth__0 | scopes.rb:13:11:13:11 | __synth__0 |
221+
| scopes.rb:13:10:13:15 | ... = ... | scopes.rb:13:10:13:15 | __synth__0__1 | scopes.rb:13:11:13:11 | __synth__0__1 |
222222
| scopes.rb:13:11:13:11 | ... = ... | scopes.rb:13:11:13:11 | c | scopes.rb:16:9:16:9 | c |
223223
| scopes.rb:13:14:13:14 | ... = ... | scopes.rb:13:14:13:14 | d | scopes.rb:17:9:17:9 | d |
224224
| scopes.rb:13:19:13:32 | ... = ... | scopes.rb:13:4:13:32 | __synth__0 | scopes.rb:13:4:13:4 | __synth__0 |
@@ -291,7 +291,7 @@ lastRead
291291
| scopes.rb:11:4:11:9 | ... = ... | scopes.rb:7:1:7:1 | a | scopes.rb:12:9:12:9 | a |
292292
| scopes.rb:13:4:13:4 | ... = ... | scopes.rb:7:1:7:1 | a | scopes.rb:14:9:14:9 | a |
293293
| scopes.rb:13:7:13:7 | ... = ... | scopes.rb:13:7:13:7 | b | scopes.rb:15:9:15:9 | b |
294-
| scopes.rb:13:10:13:15 | ... = ... | scopes.rb:13:10:13:15 | __synth__0 | scopes.rb:13:14:13:14 | __synth__0 |
294+
| scopes.rb:13:10:13:15 | ... = ... | scopes.rb:13:10:13:15 | __synth__0__1 | scopes.rb:13:14:13:14 | __synth__0__1 |
295295
| scopes.rb:13:11:13:11 | ... = ... | scopes.rb:13:11:13:11 | c | scopes.rb:16:9:16:9 | c |
296296
| scopes.rb:13:14:13:14 | ... = ... | scopes.rb:13:14:13:14 | d | scopes.rb:17:9:17:9 | d |
297297
| scopes.rb:13:19:13:32 | ... = ... | scopes.rb:13:4:13:32 | __synth__0 | scopes.rb:13:10:13:15 | __synth__0 |
@@ -328,7 +328,7 @@ adjacentReads
328328
| parameters.rb:7:26:7:31 | pizzas | parameters.rb:7:26:7:31 | pizzas | parameters.rb:8:6:8:11 | pizzas | parameters.rb:11:14:11:19 | pizzas |
329329
| parameters.rb:25:15:25:18 | name | parameters.rb:25:15:25:18 | name | parameters.rb:25:40:25:43 | name | parameters.rb:26:8:26:11 | name |
330330
| scopes.rb:9:9:18:3 | <captured> | scopes.rb:7:1:7:1 | a | scopes.rb:10:9:10:9 | a | scopes.rb:11:4:11:4 | a |
331-
| scopes.rb:13:10:13:15 | ... = ... | scopes.rb:13:10:13:15 | __synth__0 | scopes.rb:13:11:13:11 | __synth__0 | scopes.rb:13:14:13:14 | __synth__0 |
331+
| scopes.rb:13:10:13:15 | ... = ... | scopes.rb:13:10:13:15 | __synth__0__1 | scopes.rb:13:11:13:11 | __synth__0__1 | scopes.rb:13:14:13:14 | __synth__0__1 |
332332
| scopes.rb:13:19:13:32 | ... = ... | scopes.rb:13:4:13:32 | __synth__0 | scopes.rb:13:4:13:4 | __synth__0 | scopes.rb:13:7:13:7 | __synth__0 |
333333
| scopes.rb:13:19:13:32 | ... = ... | scopes.rb:13:4:13:32 | __synth__0 | scopes.rb:13:7:13:7 | __synth__0 | scopes.rb:13:10:13:15 | __synth__0 |
334334
| scopes.rb:27:1:27:5 | ... = ... | scopes.rb:27:1:27:1 | x | scopes.rb:28:8:28:8 | x | scopes.rb:31:10:31:10 | x |

ql/test/library-tests/variables/varaccess.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ explicitWrite
219219
| scopes.rb:13:4:13:4 | a | scopes.rb:13:4:13:32 | ... = ... |
220220
| scopes.rb:13:7:13:7 | b | scopes.rb:13:4:13:32 | ... = ... |
221221
| scopes.rb:13:7:13:7 | b | scopes.rb:13:7:13:7 | ... = ... |
222-
| scopes.rb:13:10:13:15 | __synth__0 | scopes.rb:13:10:13:15 | ... = ... |
222+
| scopes.rb:13:10:13:15 | __synth__0__1 | scopes.rb:13:10:13:15 | ... = ... |
223223
| scopes.rb:13:11:13:11 | c | scopes.rb:13:4:13:32 | ... = ... |
224224
| scopes.rb:13:11:13:11 | c | scopes.rb:13:11:13:11 | ... = ... |
225225
| scopes.rb:13:14:13:14 | d | scopes.rb:13:4:13:32 | ... = ... |
@@ -343,8 +343,8 @@ readAccess
343343
| scopes.rb:13:4:13:4 | __synth__0 |
344344
| scopes.rb:13:7:13:7 | __synth__0 |
345345
| scopes.rb:13:10:13:15 | __synth__0 |
346-
| scopes.rb:13:11:13:11 | __synth__0 |
347-
| scopes.rb:13:14:13:14 | __synth__0 |
346+
| scopes.rb:13:11:13:11 | __synth__0__1 |
347+
| scopes.rb:13:14:13:14 | __synth__0__1 |
348348
| scopes.rb:14:9:14:9 | a |
349349
| scopes.rb:15:9:15:9 | b |
350350
| scopes.rb:16:9:16:9 | c |

ql/test/library-tests/variables/variable.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
| scopes.rb:9:14:9:14 | x |
5757
| scopes.rb:13:4:13:32 | __synth__0 |
5858
| scopes.rb:13:7:13:7 | b |
59-
| scopes.rb:13:10:13:15 | __synth__0 |
59+
| scopes.rb:13:10:13:15 | __synth__0__1 |
6060
| scopes.rb:13:11:13:11 | c |
6161
| scopes.rb:13:14:13:14 | d |
6262
| scopes.rb:24:1:24:6 | script |

0 commit comments

Comments
 (0)