Skip to content

Commit 674838e

Browse files
committed
C#: Add flow test for inline arrays.
1 parent f14b326 commit 674838e

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

csharp/ql/test/library-tests/dataflow/collections/CollectionFlow.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,4 +393,25 @@ public void ListAddClearNoFlow()
393393
SinkListElem(list); // no flow
394394
Sink(ListFirst(list)); // no flow
395395
}
396+
397+
[System.Runtime.CompilerServices.InlineArray(10)]
398+
struct MyInlineArray
399+
{
400+
private A myInlineArrayElements;
401+
}
402+
403+
public void InlineArraySetterFlow()
404+
{
405+
var a = new A();
406+
var array = new MyInlineArray();
407+
array[0] = a;
408+
Sink(array[0]); // flow
409+
}
410+
411+
public void InlineArraySetterNoFlow(A other)
412+
{
413+
var array = new MyInlineArray();
414+
array[0] = other;
415+
Sink(array[0]); // no flow
416+
}
396417
}

csharp/ql/test/library-tests/dataflow/collections/CollectionFlow.expected

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ edges
229229
| CollectionFlow.cs:375:20:375:38 | array creation of type A[] : null [element] : A | CollectionFlow.cs:35:49:35:52 | args : null [element] : A |
230230
| CollectionFlow.cs:375:28:375:38 | { ..., ... } : null [element] : A | CollectionFlow.cs:375:20:375:38 | array creation of type A[] : null [element] : A |
231231
| CollectionFlow.cs:375:30:375:36 | object creation of type A : A | CollectionFlow.cs:375:28:375:38 | { ..., ... } : null [element] : A |
232+
| CollectionFlow.cs:405:17:405:23 | object creation of type A : A | CollectionFlow.cs:407:20:407:20 | access to local variable a : A |
233+
| CollectionFlow.cs:407:9:407:13 | [post] access to local variable array : MyInlineArray [element] : A | CollectionFlow.cs:408:14:408:18 | access to local variable array : MyInlineArray [element] : A |
234+
| CollectionFlow.cs:407:20:407:20 | access to local variable a : A | CollectionFlow.cs:407:9:407:13 | [post] access to local variable array : MyInlineArray [element] : A |
235+
| CollectionFlow.cs:408:14:408:18 | access to local variable array : MyInlineArray [element] : A | CollectionFlow.cs:408:14:408:21 | access to array element |
232236
nodes
233237
| CollectionFlow.cs:13:40:13:41 | ts : A[] [element] : A | semmle.label | ts : A[] [element] : A |
234238
| CollectionFlow.cs:13:40:13:41 | ts : null [element] : A | semmle.label | ts : null [element] : A |
@@ -459,6 +463,11 @@ nodes
459463
| CollectionFlow.cs:375:20:375:38 | array creation of type A[] : null [element] : A | semmle.label | array creation of type A[] : null [element] : A |
460464
| CollectionFlow.cs:375:28:375:38 | { ..., ... } : null [element] : A | semmle.label | { ..., ... } : null [element] : A |
461465
| CollectionFlow.cs:375:30:375:36 | object creation of type A : A | semmle.label | object creation of type A : A |
466+
| CollectionFlow.cs:405:17:405:23 | object creation of type A : A | semmle.label | object creation of type A : A |
467+
| CollectionFlow.cs:407:9:407:13 | [post] access to local variable array : MyInlineArray [element] : A | semmle.label | [post] access to local variable array : MyInlineArray [element] : A |
468+
| CollectionFlow.cs:407:20:407:20 | access to local variable a : A | semmle.label | access to local variable a : A |
469+
| CollectionFlow.cs:408:14:408:18 | access to local variable array : MyInlineArray [element] : A | semmle.label | access to local variable array : MyInlineArray [element] : A |
470+
| CollectionFlow.cs:408:14:408:21 | access to array element | semmle.label | access to array element |
462471
subpaths
463472
| CollectionFlow.cs:43:20:43:22 | access to local variable as : null [element] : A | CollectionFlow.cs:21:34:21:35 | ts : null [element] : A | CollectionFlow.cs:21:41:21:45 | access to array element : A | CollectionFlow.cs:43:14:43:23 | call to method First<A> |
464473
| CollectionFlow.cs:61:20:61:23 | access to field As : A[] [element] : A | CollectionFlow.cs:21:34:21:35 | ts : A[] [element] : A | CollectionFlow.cs:21:41:21:45 | access to array element : A | CollectionFlow.cs:61:14:61:24 | call to method First<A> |
@@ -539,3 +548,4 @@ subpaths
539548
| CollectionFlow.cs:373:26:373:32 | object creation of type A : A | CollectionFlow.cs:373:26:373:32 | object creation of type A : A | CollectionFlow.cs:35:63:35:69 | access to array element | $@ | CollectionFlow.cs:35:63:35:69 | access to array element | access to array element |
540549
| CollectionFlow.cs:374:26:374:32 | object creation of type A : A | CollectionFlow.cs:374:26:374:32 | object creation of type A : A | CollectionFlow.cs:35:63:35:69 | access to array element | $@ | CollectionFlow.cs:35:63:35:69 | access to array element | access to array element |
541550
| CollectionFlow.cs:375:30:375:36 | object creation of type A : A | CollectionFlow.cs:375:30:375:36 | object creation of type A : A | CollectionFlow.cs:35:63:35:69 | access to array element | $@ | CollectionFlow.cs:35:63:35:69 | access to array element | access to array element |
551+
| CollectionFlow.cs:405:17:405:23 | object creation of type A : A | CollectionFlow.cs:405:17:405:23 | object creation of type A : A | CollectionFlow.cs:408:14:408:21 | access to array element | $@ | CollectionFlow.cs:408:14:408:21 | access to array element | access to array element |

0 commit comments

Comments
 (0)