Skip to content

Commit d6fb7d3

Browse files
committed
C#: Add positional pattern with missing flow.
1 parent ae1c4ad commit d6fb7d3

4 files changed

Lines changed: 122 additions & 15 deletions

File tree

‎csharp/ql/test/library-tests/dataflow/tuples/DataFlowStep.expected‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,24 @@
265265
| Tuples.cs:154:36:154:37 | SSA def(c2) | Tuples.cs:157:18:157:19 | access to local variable c2 |
266266
| Tuples.cs:154:36:154:37 | String c2 | Tuples.cs:154:36:154:37 | SSA def(c2) |
267267
| Tuples.cs:158:18:158:19 | access to local variable b2 | Tuples.cs:158:18:158:19 | (...) ... |
268-
| Tuples.cs:169:18:169:31 | this | Tuples.cs:169:18:169:31 | this access |
268+
| Tuples.cs:161:13:161:14 | access to local variable o5 | Tuples.cs:161:13:161:35 | SSA def(o5) |
269+
| Tuples.cs:161:13:161:35 | SSA def(o5) | Tuples.cs:163:18:163:19 | access to local variable o5 |
270+
| Tuples.cs:161:18:161:35 | call to method Source<String> | Tuples.cs:161:13:161:14 | access to local variable o5 |
271+
| Tuples.cs:161:33:161:34 | 14 | Tuples.cs:161:33:161:34 | (...) ... |
272+
| Tuples.cs:162:13:162:14 | access to local variable o6 | Tuples.cs:162:13:162:35 | SSA def(o6) |
273+
| Tuples.cs:162:13:162:35 | SSA def(o6) | Tuples.cs:163:26:163:27 | access to local variable o6 |
274+
| Tuples.cs:162:18:162:35 | call to method Source<String> | Tuples.cs:162:13:162:14 | access to local variable o6 |
275+
| Tuples.cs:162:33:162:34 | 15 | Tuples.cs:162:33:162:34 | (...) ... |
276+
| Tuples.cs:163:13:163:13 | access to local variable z | Tuples.cs:163:13:163:32 | SSA def(z) |
277+
| Tuples.cs:163:13:163:32 | SSA def(z) | Tuples.cs:164:13:164:13 | access to local variable z |
278+
| Tuples.cs:163:17:163:32 | (..., ...) | Tuples.cs:163:13:163:13 | access to local variable z |
279+
| Tuples.cs:164:13:164:13 | access to local variable z | Tuples.cs:164:18:164:47 | { ... } |
280+
| Tuples.cs:164:19:164:24 | SSA def(a3) | Tuples.cs:166:18:166:19 | access to local variable a3 |
281+
| Tuples.cs:164:19:164:24 | String a3 | Tuples.cs:164:19:164:24 | SSA def(a3) |
282+
| Tuples.cs:164:27:164:43 | (Int32,String) t | Tuples.cs:164:27:164:43 | SSA def(t) |
283+
| Tuples.cs:164:27:164:43 | SSA def(t) | Tuples.cs:167:18:167:18 | access to local variable t |
284+
| Tuples.cs:164:27:164:43 | SSA qualifier def(t.Item2) | Tuples.cs:167:18:167:24 | access to field Item2 |
285+
| Tuples.cs:164:28:164:33 | Int32 b3 | Tuples.cs:164:28:164:33 | SSA def(b3) |
286+
| Tuples.cs:164:28:164:33 | SSA def(b3) | Tuples.cs:168:18:168:19 | access to local variable b3 |
287+
| Tuples.cs:168:18:168:19 | access to local variable b3 | Tuples.cs:168:18:168:19 | (...) ... |
288+
| Tuples.cs:179:18:179:31 | this | Tuples.cs:179:18:179:31 | this access |

‎csharp/ql/test/library-tests/dataflow/tuples/PrintAst.expected‎

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -598,20 +598,68 @@ Tuples.cs:
598598
# 158| 0: [MethodCall] call to method Sink
599599
# 158| 0: [CastExpr] (...) ...
600600
# 158| 1: [LocalVariableAccess] access to local variable b2
601-
# 162| 14: [Method] Sink
602-
# 162| -1: [TypeMention] Void
601+
# 161| 8: [LocalVariableDeclStmt] ... ...;
602+
# 161| 0: [LocalVariableDeclAndInitExpr] String o5 = ...
603+
# 161| -1: [TypeMention] string
604+
# 161| 0: [LocalVariableAccess] access to local variable o5
605+
# 161| 1: [MethodCall] call to method Source<String>
606+
# 161| 0: [CastExpr] (...) ...
607+
# 161| 1: [IntLiteral] 14
608+
# 162| 9: [LocalVariableDeclStmt] ... ...;
609+
# 162| 0: [LocalVariableDeclAndInitExpr] String o6 = ...
610+
# 162| -1: [TypeMention] string
611+
# 162| 0: [LocalVariableAccess] access to local variable o6
612+
# 162| 1: [MethodCall] call to method Source<String>
613+
# 162| 0: [CastExpr] (...) ...
614+
# 162| 1: [IntLiteral] 15
615+
# 163| 10: [LocalVariableDeclStmt] ... ...;
616+
# 163| 0: [LocalVariableDeclAndInitExpr] (String,(Int32,String),Int32) z = ...
617+
# 163| -1: [TypeMention] (string, (int, string), int)
618+
# 163| 0: [LocalVariableAccess] access to local variable z
619+
# 163| 1: [TupleExpr] (..., ...)
620+
# 163| 0: [LocalVariableAccess] access to local variable o5
621+
# 163| 1: [TupleExpr] (..., ...)
622+
# 163| 0: [IntLiteral] 2
623+
# 163| 1: [LocalVariableAccess] access to local variable o6
624+
# 163| 2: [IntLiteral] 3
625+
# 164| 11: [IfStmt] if (...) ...
626+
# 164| 0: [IsExpr] ... is ...
627+
# 164| 0: [LocalVariableAccess] access to local variable z
628+
# 164| 1: [RecursivePatternExpr] { ... }
629+
# 164| 2: [PositionalPatternExpr] ( ... )
630+
# 164| 0: [VariablePatternExpr] String a3
631+
# 164| 1: [RecursivePatternExpr] { ... }
632+
# 164| 0: [VariablePatternExpr] (Int32,String) t
633+
# 164| 2: [PositionalPatternExpr] ( ... )
634+
# 164| 0: [VariablePatternExpr] Int32 b3
635+
# 164| 1: [DiscardPatternExpr] _
636+
# 164| 2: [DiscardPatternExpr] _
637+
# 165| 1: [BlockStmt] {...}
638+
# 166| 0: [ExprStmt] ...;
639+
# 166| 0: [MethodCall] call to method Sink
640+
# 166| 0: [LocalVariableAccess] access to local variable a3
641+
# 167| 1: [ExprStmt] ...;
642+
# 167| 0: [MethodCall] call to method Sink
643+
# 167| 0: [FieldAccess] access to field Item2
644+
# 167| -1: [LocalVariableAccess] access to local variable t
645+
# 168| 2: [ExprStmt] ...;
646+
# 168| 0: [MethodCall] call to method Sink
647+
# 168| 0: [CastExpr] (...) ...
648+
# 168| 1: [LocalVariableAccess] access to local variable b3
649+
# 172| 14: [Method] Sink
650+
# 172| -1: [TypeMention] Void
603651
#-----| 2: (Parameters)
604-
# 162| 0: [Parameter] o
605-
# 162| -1: [TypeMention] object
606-
# 162| 4: [BlockStmt] {...}
607-
# 164| 17: [Method] Source`1
608-
# 164| -1: [TypeMention] T
652+
# 172| 0: [Parameter] o
653+
# 172| -1: [TypeMention] object
654+
# 172| 4: [BlockStmt] {...}
655+
# 174| 17: [Method] Source`1
656+
# 174| -1: [TypeMention] T
609657
#-----| 1: (Type parameters)
610-
# 164| 0: [TypeParameter] T
658+
# 174| 0: [TypeParameter] T
611659
#-----| 2: (Parameters)
612-
# 164| 0: [Parameter] source
613-
# 164| -1: [TypeMention] object
614-
# 164| 4: [ThrowExpr] throw ...
615-
# 164| 0: [NullLiteral] null
616-
# 167| [NamespaceDeclaration] namespace ... { ... }
617-
# 169| 1: [Class] IsExternalInit
660+
# 174| 0: [Parameter] source
661+
# 174| -1: [TypeMention] object
662+
# 174| 4: [ThrowExpr] throw ...
663+
# 174| 0: [NullLiteral] null
664+
# 177| [NamespaceDeclaration] namespace ... { ... }
665+
# 179| 1: [Class] IsExternalInit

‎csharp/ql/test/library-tests/dataflow/tuples/Tuples.cs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ static void M7()
157157
Sink(c2); // $ hasValueFlow=13
158158
Sink(b2);
159159
}
160+
161+
var o5 = Source<string>(14);
162+
var o6 = Source<string>(15);
163+
var z = (o5, (2, o6), 3);
164+
if (z is (var a3, (var b3, var _) t, _))
165+
{
166+
Sink(a3); // $ hasValueFlow=14
167+
Sink(t.Item2); // $ hasValueFlow=15
168+
Sink(b3);
169+
}
160170
}
161171

162172
public static void Sink(object o) { }

‎csharp/ql/test/library-tests/dataflow/tuples/Tuples.expected‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,18 @@ edges
270270
| Tuples.cs:154:18:154:42 | { ... } : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item2, field Item2] : String | Tuples.cs:154:27:154:38 | (..., ...) : ValueTuple<Int32,String> [field Item2] : String | provenance | |
271271
| Tuples.cs:154:27:154:38 | (..., ...) : ValueTuple<Int32,String> [field Item2] : String | Tuples.cs:157:18:157:19 | access to local variable c2 | provenance | |
272272
| Tuples.cs:154:27:154:38 | (..., ...) : ValueTuple<Int32,String> [field Item2] : String | Tuples.cs:157:18:157:19 | access to local variable c2 | provenance | |
273+
| Tuples.cs:161:13:161:14 | access to local variable o5 : String | Tuples.cs:163:18:163:19 | access to local variable o5 : String | provenance | |
274+
| Tuples.cs:161:13:161:14 | access to local variable o5 : String | Tuples.cs:163:18:163:19 | access to local variable o5 : String | provenance | |
275+
| Tuples.cs:161:18:161:35 | call to method Source<String> : String | Tuples.cs:161:13:161:14 | access to local variable o5 : String | provenance | |
276+
| Tuples.cs:161:18:161:35 | call to method Source<String> : String | Tuples.cs:161:13:161:14 | access to local variable o5 : String | provenance | |
277+
| Tuples.cs:163:13:163:13 | access to local variable z : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String | Tuples.cs:164:18:164:47 | { ... } : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String | provenance | |
278+
| Tuples.cs:163:13:163:13 | access to local variable z : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String | Tuples.cs:164:18:164:47 | { ... } : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String | provenance | |
279+
| Tuples.cs:163:17:163:32 | (..., ...) : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String | Tuples.cs:163:13:163:13 | access to local variable z : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String | provenance | |
280+
| Tuples.cs:163:17:163:32 | (..., ...) : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String | Tuples.cs:163:13:163:13 | access to local variable z : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String | provenance | |
281+
| Tuples.cs:163:18:163:19 | access to local variable o5 : String | Tuples.cs:163:17:163:32 | (..., ...) : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String | provenance | |
282+
| Tuples.cs:163:18:163:19 | access to local variable o5 : String | Tuples.cs:163:17:163:32 | (..., ...) : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String | provenance | |
283+
| Tuples.cs:164:18:164:47 | { ... } : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String | Tuples.cs:166:18:166:19 | access to local variable a3 | provenance | |
284+
| Tuples.cs:164:18:164:47 | { ... } : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String | Tuples.cs:166:18:166:19 | access to local variable a3 | provenance | |
273285
nodes
274286
| Tuples.cs:7:13:7:14 | access to local variable o1 : Object | semmle.label | access to local variable o1 : Object |
275287
| Tuples.cs:7:13:7:14 | access to local variable o1 : Object | semmle.label | access to local variable o1 : Object |
@@ -559,10 +571,25 @@ nodes
559571
| Tuples.cs:156:18:156:19 | access to local variable a2 | semmle.label | access to local variable a2 |
560572
| Tuples.cs:157:18:157:19 | access to local variable c2 | semmle.label | access to local variable c2 |
561573
| Tuples.cs:157:18:157:19 | access to local variable c2 | semmle.label | access to local variable c2 |
574+
| Tuples.cs:161:13:161:14 | access to local variable o5 : String | semmle.label | access to local variable o5 : String |
575+
| Tuples.cs:161:13:161:14 | access to local variable o5 : String | semmle.label | access to local variable o5 : String |
576+
| Tuples.cs:161:18:161:35 | call to method Source<String> : String | semmle.label | call to method Source<String> : String |
577+
| Tuples.cs:161:18:161:35 | call to method Source<String> : String | semmle.label | call to method Source<String> : String |
578+
| Tuples.cs:163:13:163:13 | access to local variable z : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String | semmle.label | access to local variable z : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String |
579+
| Tuples.cs:163:13:163:13 | access to local variable z : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String | semmle.label | access to local variable z : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String |
580+
| Tuples.cs:163:17:163:32 | (..., ...) : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String | semmle.label | (..., ...) : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String |
581+
| Tuples.cs:163:17:163:32 | (..., ...) : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String | semmle.label | (..., ...) : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String |
582+
| Tuples.cs:163:18:163:19 | access to local variable o5 : String | semmle.label | access to local variable o5 : String |
583+
| Tuples.cs:163:18:163:19 | access to local variable o5 : String | semmle.label | access to local variable o5 : String |
584+
| Tuples.cs:164:18:164:47 | { ... } : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String | semmle.label | { ... } : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String |
585+
| Tuples.cs:164:18:164:47 | { ... } : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String | semmle.label | { ... } : ValueTuple<String,ValueTuple<Int32,String>,Int32> [field Item1] : String |
586+
| Tuples.cs:166:18:166:19 | access to local variable a3 | semmle.label | access to local variable a3 |
587+
| Tuples.cs:166:18:166:19 | access to local variable a3 | semmle.label | access to local variable a3 |
562588
subpaths
563589
| Tuples.cs:100:24:100:24 | access to local variable o : String | Tuples.cs:95:22:95:22 | i : String | Tuples.cs:95:12:95:13 | this [Return] : R1 [property i] : String | Tuples.cs:100:17:100:28 | object creation of type R1 : R1 [property i] : String |
564590
| Tuples.cs:100:24:100:24 | access to local variable o : String | Tuples.cs:95:22:95:22 | i : String | Tuples.cs:95:12:95:13 | this [Return] : R1 [property i] : String | Tuples.cs:100:17:100:28 | object creation of type R1 : R1 [property i] : String |
565591
testFailures
592+
| Tuples.cs:167:30:167:49 | // ... | Missing result: hasValueFlow=15 |
566593
#select
567594
| Tuples.cs:12:14:12:14 | access to local variable a | Tuples.cs:7:18:7:34 | call to method Source<Object> : Object | Tuples.cs:12:14:12:14 | access to local variable a | $@ | Tuples.cs:7:18:7:34 | call to method Source<Object> : Object | call to method Source<Object> : Object |
568595
| Tuples.cs:12:14:12:14 | access to local variable a | Tuples.cs:7:18:7:34 | call to method Source<Object> : Object | Tuples.cs:12:14:12:14 | access to local variable a | $@ | Tuples.cs:7:18:7:34 | call to method Source<Object> : Object | call to method Source<Object> : Object |
@@ -618,3 +645,5 @@ testFailures
618645
| Tuples.cs:156:18:156:19 | access to local variable a2 | Tuples.cs:151:18:151:35 | call to method Source<String> : String | Tuples.cs:156:18:156:19 | access to local variable a2 | $@ | Tuples.cs:151:18:151:35 | call to method Source<String> : String | call to method Source<String> : String |
619646
| Tuples.cs:157:18:157:19 | access to local variable c2 | Tuples.cs:152:18:152:35 | call to method Source<String> : String | Tuples.cs:157:18:157:19 | access to local variable c2 | $@ | Tuples.cs:152:18:152:35 | call to method Source<String> : String | call to method Source<String> : String |
620647
| Tuples.cs:157:18:157:19 | access to local variable c2 | Tuples.cs:152:18:152:35 | call to method Source<String> : String | Tuples.cs:157:18:157:19 | access to local variable c2 | $@ | Tuples.cs:152:18:152:35 | call to method Source<String> : String | call to method Source<String> : String |
648+
| Tuples.cs:166:18:166:19 | access to local variable a3 | Tuples.cs:161:18:161:35 | call to method Source<String> : String | Tuples.cs:166:18:166:19 | access to local variable a3 | $@ | Tuples.cs:161:18:161:35 | call to method Source<String> : String | call to method Source<String> : String |
649+
| Tuples.cs:166:18:166:19 | access to local variable a3 | Tuples.cs:161:18:161:35 | call to method Source<String> : String | Tuples.cs:166:18:166:19 | access to local variable a3 | $@ | Tuples.cs:161:18:161:35 | call to method Source<String> : String | call to method Source<String> : String |

0 commit comments

Comments
 (0)