Skip to content

Commit 5b5dd07

Browse files
committed
C#: Add data flow test that illustrates issue with flow into phi nodes
1 parent 7a8c9e7 commit 5b5dd07

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

csharp/ql/test/library-tests/dataflow/fields/FieldFlow.expected

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
failures
2+
| J.cs:125:21:125:40 | // ... | Missing result:hasValueFlow=10 |
3+
| J.cs:140:14:140:17 | (...) ... | Unexpected result: hasValueFlow=11 |
24
edges
35
| A.cs:5:17:5:28 | call to method Source<C> : C | A.cs:6:24:6:24 | access to local variable c : C |
46
| A.cs:5:17:5:28 | call to method Source<C> : C | A.cs:6:24:6:24 | access to local variable c : C |
@@ -918,6 +920,14 @@ edges
918920
| J.cs:106:14:106:15 | access to local variable a3 [property X] : Object | J.cs:106:14:106:17 | access to property X |
919921
| J.cs:107:14:107:15 | access to local variable a3 [property Y] : Object | J.cs:107:14:107:17 | access to property Y |
920922
| J.cs:107:14:107:15 | access to local variable a3 [property Y] : Object | J.cs:107:14:107:17 | access to property Y |
923+
| J.cs:133:13:133:13 | [post] access to local variable a [element] : Int32 | J.cs:140:14:140:14 | access to local variable a [element] : Int32 |
924+
| J.cs:133:13:133:13 | [post] access to local variable a [element] : Int32 | J.cs:140:14:140:14 | access to local variable a [element] : Int32 |
925+
| J.cs:133:19:133:33 | call to method Source<Int32> : Int32 | J.cs:133:13:133:13 | [post] access to local variable a [element] : Int32 |
926+
| J.cs:133:19:133:33 | call to method Source<Int32> : Int32 | J.cs:133:13:133:13 | [post] access to local variable a [element] : Int32 |
927+
| J.cs:140:14:140:14 | access to local variable a [element] : Int32 | J.cs:140:14:140:17 | access to indexer : Int32 |
928+
| J.cs:140:14:140:14 | access to local variable a [element] : Int32 | J.cs:140:14:140:17 | access to indexer : Int32 |
929+
| J.cs:140:14:140:17 | access to indexer : Int32 | J.cs:140:14:140:17 | (...) ... |
930+
| J.cs:140:14:140:17 | access to indexer : Int32 | J.cs:140:14:140:17 | (...) ... |
921931
nodes
922932
| A.cs:5:17:5:28 | call to method Source<C> : C | semmle.label | call to method Source<C> : C |
923933
| A.cs:5:17:5:28 | call to method Source<C> : C | semmle.label | call to method Source<C> : C |
@@ -1925,6 +1935,16 @@ nodes
19251935
| J.cs:107:14:107:15 | access to local variable a3 [property Y] : Object | semmle.label | access to local variable a3 [property Y] : Object |
19261936
| J.cs:107:14:107:17 | access to property Y | semmle.label | access to property Y |
19271937
| J.cs:107:14:107:17 | access to property Y | semmle.label | access to property Y |
1938+
| J.cs:133:13:133:13 | [post] access to local variable a [element] : Int32 | semmle.label | [post] access to local variable a [element] : Int32 |
1939+
| J.cs:133:13:133:13 | [post] access to local variable a [element] : Int32 | semmle.label | [post] access to local variable a [element] : Int32 |
1940+
| J.cs:133:19:133:33 | call to method Source<Int32> : Int32 | semmle.label | call to method Source<Int32> : Int32 |
1941+
| J.cs:133:19:133:33 | call to method Source<Int32> : Int32 | semmle.label | call to method Source<Int32> : Int32 |
1942+
| J.cs:140:14:140:14 | access to local variable a [element] : Int32 | semmle.label | access to local variable a [element] : Int32 |
1943+
| J.cs:140:14:140:14 | access to local variable a [element] : Int32 | semmle.label | access to local variable a [element] : Int32 |
1944+
| J.cs:140:14:140:17 | (...) ... | semmle.label | (...) ... |
1945+
| J.cs:140:14:140:17 | (...) ... | semmle.label | (...) ... |
1946+
| J.cs:140:14:140:17 | access to indexer : Int32 | semmle.label | access to indexer : Int32 |
1947+
| J.cs:140:14:140:17 | access to indexer : Int32 | semmle.label | access to indexer : Int32 |
19281948
subpaths
19291949
| A.cs:6:24:6:24 | access to local variable c : C | A.cs:147:32:147:32 | c : C | A.cs:149:20:149:27 | object creation of type B [field c] : C | A.cs:6:17:6:25 | call to method Make [field c] : C |
19301950
| A.cs:6:24:6:24 | access to local variable c : C | A.cs:147:32:147:32 | c : C | A.cs:149:20:149:27 | object creation of type B [field c] : C | A.cs:6:17:6:25 | call to method Make [field c] : C |
@@ -2101,3 +2121,4 @@ subpaths
21012121
| J.cs:102:14:102:17 | access to property X | J.cs:97:17:97:33 | call to method Source<Object> : Object | J.cs:102:14:102:17 | access to property X | $@ | J.cs:97:17:97:33 | call to method Source<Object> : Object | call to method Source<Object> : Object |
21022122
| J.cs:106:14:106:17 | access to property X | J.cs:97:17:97:33 | call to method Source<Object> : Object | J.cs:106:14:106:17 | access to property X | $@ | J.cs:97:17:97:33 | call to method Source<Object> : Object | call to method Source<Object> : Object |
21032123
| J.cs:107:14:107:17 | access to property Y | J.cs:105:32:105:48 | call to method Source<Object> : Object | J.cs:107:14:107:17 | access to property Y | $@ | J.cs:105:32:105:48 | call to method Source<Object> : Object | call to method Source<Object> : Object |
2124+
| J.cs:140:14:140:17 | (...) ... | J.cs:133:19:133:33 | call to method Source<Int32> : Int32 | J.cs:140:14:140:17 | (...) ... | $@ | J.cs:133:19:133:33 | call to method Source<Int32> : Int32 | call to method Source<Int32> : Int32 |

csharp/ql/test/library-tests/dataflow/fields/J.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,35 @@ private void M5()
111111
Sink(a4.Y); // no flow
112112
}
113113

114+
private void M6(bool b)
115+
{
116+
var a = new int[1];
117+
if (b)
118+
{
119+
a[0] = Source<int>(10);
120+
}
121+
else
122+
{
123+
a = new int[1];
124+
}
125+
Sink(a[0]); // $ hasValueFlow=10
126+
}
127+
128+
private void M7(bool b)
129+
{
130+
var a = new System.Collections.Generic.List<int>();
131+
if (b)
132+
{
133+
a.Add(Source<int>(11));
134+
a.Clear();
135+
}
136+
else
137+
{
138+
a = new System.Collections.Generic.List<int>();
139+
}
140+
Sink(a[0]);
141+
}
142+
114143
public static void Sink(object o) { }
115144

116145
static T Source<T>(object source) => throw null;

0 commit comments

Comments
 (0)