Skip to content

Commit 91d8443

Browse files
committed
C#: Add some tests with expected output.
1 parent 7f5d2e1 commit 91d8443

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,4 +481,40 @@ public void CollectionExpressionSpreadElementNoFieldFlow()
481481
IntegerCollection ic1 = [.. ic0];
482482
Sink(ic1.Payload); // No flow
483483
}
484+
485+
public void SpanConstructorFlow()
486+
{
487+
var a = new A();
488+
Span<A> span = new Span<A>(ref a);
489+
Sink(span[0]); // flow
490+
}
491+
492+
public void SpanToArrayFlow()
493+
{
494+
var a = new A();
495+
Span<A> span = new Span<A>(ref a);
496+
var arr = span.ToArray();
497+
Sink(arr[0]); // flow
498+
}
499+
500+
public void SpanFillFlow(Span<A> target)
501+
{
502+
var a = new A();
503+
target.Fill(a);
504+
Sink(target[0]); // flow
505+
}
506+
507+
public void SpanCopyToFlow(Span<A> target)
508+
{
509+
var source = new Span<A>(new[] { new A() });
510+
source.CopyTo(target);
511+
Sink(target[0]); // flow
512+
}
513+
514+
public void ReadOnlySpanConstructorFlow()
515+
{
516+
var a = new A();
517+
ReadOnlySpan<A> span = new ReadOnlySpan<A>(new[] { a });
518+
Sink(span[0]); // flow
519+
}
484520
}

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,33 @@ edges
246246
| CollectionFlow.cs:448:21:448:21 | access to local variable a : A | CollectionFlow.cs:448:20:448:22 | [...] : A[] [element] : A |
247247
| CollectionFlow.cs:449:22:449:28 | .. access to local variable temp : A[] [element] : A | CollectionFlow.cs:450:14:450:18 | access to local variable array : A[] [element] : A |
248248
| CollectionFlow.cs:450:14:450:18 | access to local variable array : A[] [element] : A | CollectionFlow.cs:450:14:450:21 | access to array element |
249+
| CollectionFlow.cs:487:17:487:23 | object creation of type A : A | CollectionFlow.cs:488:40:488:40 | access to local variable a : A |
250+
| CollectionFlow.cs:488:24:488:41 | object creation of type Span<A> : Span<T> [element] : A | CollectionFlow.cs:489:14:489:17 | access to local variable span : Span<T> [element] : A |
251+
| CollectionFlow.cs:488:40:488:40 | access to local variable a : A | CollectionFlow.cs:488:24:488:41 | object creation of type Span<A> : Span<T> [element] : A |
252+
| CollectionFlow.cs:489:14:489:17 | access to local variable span : Span<T> [element] : A | CollectionFlow.cs:489:14:489:20 | access to indexer |
253+
| CollectionFlow.cs:494:17:494:23 | object creation of type A : A | CollectionFlow.cs:495:40:495:40 | access to local variable a : A |
254+
| CollectionFlow.cs:495:24:495:41 | object creation of type Span<A> : Span<T> [element] : A | CollectionFlow.cs:496:19:496:22 | access to local variable span : Span<T> [element] : A |
255+
| CollectionFlow.cs:495:40:495:40 | access to local variable a : A | CollectionFlow.cs:495:24:495:41 | object creation of type Span<A> : Span<T> [element] : A |
256+
| CollectionFlow.cs:496:19:496:22 | access to local variable span : Span<T> [element] : A | CollectionFlow.cs:496:19:496:32 | call to method ToArray : T[] [element] : A |
257+
| CollectionFlow.cs:496:19:496:32 | call to method ToArray : T[] [element] : A | CollectionFlow.cs:497:14:497:16 | access to local variable arr : T[] [element] : A |
258+
| CollectionFlow.cs:497:14:497:16 | access to local variable arr : T[] [element] : A | CollectionFlow.cs:497:14:497:19 | access to array element |
259+
| CollectionFlow.cs:502:17:502:23 | object creation of type A : A | CollectionFlow.cs:503:21:503:21 | access to local variable a : A |
260+
| CollectionFlow.cs:503:9:503:14 | [post] access to parameter target : Span<T> [element] : A | CollectionFlow.cs:504:14:504:19 | access to parameter target : Span<T> [element] : A |
261+
| CollectionFlow.cs:503:21:503:21 | access to local variable a : A | CollectionFlow.cs:503:9:503:14 | [post] access to parameter target : Span<T> [element] : A |
262+
| CollectionFlow.cs:504:14:504:19 | access to parameter target : Span<T> [element] : A | CollectionFlow.cs:504:14:504:22 | access to indexer |
263+
| CollectionFlow.cs:509:22:509:51 | object creation of type Span<A> : Span<T> [element] : A | CollectionFlow.cs:510:9:510:14 | access to local variable source : Span<T> [element] : A |
264+
| CollectionFlow.cs:509:34:509:50 | array creation of type A[] : null [element] : A | CollectionFlow.cs:509:22:509:51 | object creation of type Span<A> : Span<T> [element] : A |
265+
| CollectionFlow.cs:509:40:509:50 | { ..., ... } : null [element] : A | CollectionFlow.cs:509:34:509:50 | array creation of type A[] : null [element] : A |
266+
| CollectionFlow.cs:509:42:509:48 | object creation of type A : A | CollectionFlow.cs:509:40:509:50 | { ..., ... } : null [element] : A |
267+
| CollectionFlow.cs:510:9:510:14 | access to local variable source : Span<T> [element] : A | CollectionFlow.cs:510:23:510:28 | [post] access to parameter target : Span<T> [element] : A |
268+
| CollectionFlow.cs:510:23:510:28 | [post] access to parameter target : Span<T> [element] : A | CollectionFlow.cs:511:14:511:19 | access to parameter target : Span<T> [element] : A |
269+
| CollectionFlow.cs:511:14:511:19 | access to parameter target : Span<T> [element] : A | CollectionFlow.cs:511:14:511:22 | access to indexer |
270+
| CollectionFlow.cs:516:17:516:23 | object creation of type A : A | CollectionFlow.cs:517:60:517:60 | access to local variable a : A |
271+
| CollectionFlow.cs:517:32:517:63 | object creation of type ReadOnlySpan<A> : ReadOnlySpan<T> [element] : A | CollectionFlow.cs:518:14:518:17 | access to local variable span : ReadOnlySpan<T> [element] : A |
272+
| CollectionFlow.cs:517:52:517:62 | array creation of type A[] : null [element] : A | CollectionFlow.cs:517:32:517:63 | object creation of type ReadOnlySpan<A> : ReadOnlySpan<T> [element] : A |
273+
| CollectionFlow.cs:517:58:517:62 | { ..., ... } : null [element] : A | CollectionFlow.cs:517:52:517:62 | array creation of type A[] : null [element] : A |
274+
| CollectionFlow.cs:517:60:517:60 | access to local variable a : A | CollectionFlow.cs:517:58:517:62 | { ..., ... } : null [element] : A |
275+
| CollectionFlow.cs:518:14:518:17 | access to local variable span : ReadOnlySpan<T> [element] : A | CollectionFlow.cs:518:14:518:20 | access to indexer |
249276
nodes
250277
| CollectionFlow.cs:14:40:14:41 | ts : A[] [element] : A | semmle.label | ts : A[] [element] : A |
251278
| CollectionFlow.cs:14:40:14:41 | ts : null [element] : A | semmle.label | ts : null [element] : A |
@@ -497,6 +524,38 @@ nodes
497524
| CollectionFlow.cs:449:22:449:28 | .. access to local variable temp : A[] [element] : A | semmle.label | .. access to local variable temp : A[] [element] : A |
498525
| CollectionFlow.cs:450:14:450:18 | access to local variable array : A[] [element] : A | semmle.label | access to local variable array : A[] [element] : A |
499526
| CollectionFlow.cs:450:14:450:21 | access to array element | semmle.label | access to array element |
527+
| CollectionFlow.cs:487:17:487:23 | object creation of type A : A | semmle.label | object creation of type A : A |
528+
| CollectionFlow.cs:488:24:488:41 | object creation of type Span<A> : Span<T> [element] : A | semmle.label | object creation of type Span<A> : Span<T> [element] : A |
529+
| CollectionFlow.cs:488:40:488:40 | access to local variable a : A | semmle.label | access to local variable a : A |
530+
| CollectionFlow.cs:489:14:489:17 | access to local variable span : Span<T> [element] : A | semmle.label | access to local variable span : Span<T> [element] : A |
531+
| CollectionFlow.cs:489:14:489:20 | access to indexer | semmle.label | access to indexer |
532+
| CollectionFlow.cs:494:17:494:23 | object creation of type A : A | semmle.label | object creation of type A : A |
533+
| CollectionFlow.cs:495:24:495:41 | object creation of type Span<A> : Span<T> [element] : A | semmle.label | object creation of type Span<A> : Span<T> [element] : A |
534+
| CollectionFlow.cs:495:40:495:40 | access to local variable a : A | semmle.label | access to local variable a : A |
535+
| CollectionFlow.cs:496:19:496:22 | access to local variable span : Span<T> [element] : A | semmle.label | access to local variable span : Span<T> [element] : A |
536+
| CollectionFlow.cs:496:19:496:32 | call to method ToArray : T[] [element] : A | semmle.label | call to method ToArray : T[] [element] : A |
537+
| CollectionFlow.cs:497:14:497:16 | access to local variable arr : T[] [element] : A | semmle.label | access to local variable arr : T[] [element] : A |
538+
| CollectionFlow.cs:497:14:497:19 | access to array element | semmle.label | access to array element |
539+
| CollectionFlow.cs:502:17:502:23 | object creation of type A : A | semmle.label | object creation of type A : A |
540+
| CollectionFlow.cs:503:9:503:14 | [post] access to parameter target : Span<T> [element] : A | semmle.label | [post] access to parameter target : Span<T> [element] : A |
541+
| CollectionFlow.cs:503:21:503:21 | access to local variable a : A | semmle.label | access to local variable a : A |
542+
| CollectionFlow.cs:504:14:504:19 | access to parameter target : Span<T> [element] : A | semmle.label | access to parameter target : Span<T> [element] : A |
543+
| CollectionFlow.cs:504:14:504:22 | access to indexer | semmle.label | access to indexer |
544+
| CollectionFlow.cs:509:22:509:51 | object creation of type Span<A> : Span<T> [element] : A | semmle.label | object creation of type Span<A> : Span<T> [element] : A |
545+
| CollectionFlow.cs:509:34:509:50 | array creation of type A[] : null [element] : A | semmle.label | array creation of type A[] : null [element] : A |
546+
| CollectionFlow.cs:509:40:509:50 | { ..., ... } : null [element] : A | semmle.label | { ..., ... } : null [element] : A |
547+
| CollectionFlow.cs:509:42:509:48 | object creation of type A : A | semmle.label | object creation of type A : A |
548+
| CollectionFlow.cs:510:9:510:14 | access to local variable source : Span<T> [element] : A | semmle.label | access to local variable source : Span<T> [element] : A |
549+
| CollectionFlow.cs:510:23:510:28 | [post] access to parameter target : Span<T> [element] : A | semmle.label | [post] access to parameter target : Span<T> [element] : A |
550+
| CollectionFlow.cs:511:14:511:19 | access to parameter target : Span<T> [element] : A | semmle.label | access to parameter target : Span<T> [element] : A |
551+
| CollectionFlow.cs:511:14:511:22 | access to indexer | semmle.label | access to indexer |
552+
| CollectionFlow.cs:516:17:516:23 | object creation of type A : A | semmle.label | object creation of type A : A |
553+
| CollectionFlow.cs:517:32:517:63 | object creation of type ReadOnlySpan<A> : ReadOnlySpan<T> [element] : A | semmle.label | object creation of type ReadOnlySpan<A> : ReadOnlySpan<T> [element] : A |
554+
| CollectionFlow.cs:517:52:517:62 | array creation of type A[] : null [element] : A | semmle.label | array creation of type A[] : null [element] : A |
555+
| CollectionFlow.cs:517:58:517:62 | { ..., ... } : null [element] : A | semmle.label | { ..., ... } : null [element] : A |
556+
| CollectionFlow.cs:517:60:517:60 | access to local variable a : A | semmle.label | access to local variable a : A |
557+
| CollectionFlow.cs:518:14:518:17 | access to local variable span : ReadOnlySpan<T> [element] : A | semmle.label | access to local variable span : ReadOnlySpan<T> [element] : A |
558+
| CollectionFlow.cs:518:14:518:20 | access to indexer | semmle.label | access to indexer |
500559
subpaths
501560
| CollectionFlow.cs:44:20:44:22 | access to local variable as : null [element] : A | CollectionFlow.cs:22:34:22:35 | ts : null [element] : A | CollectionFlow.cs:22:41:22:45 | access to array element : A | CollectionFlow.cs:44:14:44:23 | call to method First<A> |
502561
| CollectionFlow.cs:62:20:62:23 | access to field As : A[] [element] : A | CollectionFlow.cs:22:34:22:35 | ts : A[] [element] : A | CollectionFlow.cs:22:41:22:45 | access to array element : A | CollectionFlow.cs:62:14:62:24 | call to method First<A> |
@@ -581,3 +640,8 @@ subpaths
581640
| CollectionFlow.cs:427:17:427:23 | object creation of type A : A | CollectionFlow.cs:427:17:427:23 | object creation of type A : A | CollectionFlow.cs:429:14:429:21 | access to array element | $@ | CollectionFlow.cs:429:14:429:21 | access to array element | access to array element |
582641
| CollectionFlow.cs:434:17:434:23 | object creation of type A : A | CollectionFlow.cs:434:17:434:23 | object creation of type A : A | CollectionFlow.cs:436:14:436:17 | access to indexer | $@ | CollectionFlow.cs:436:14:436:17 | access to indexer | access to indexer |
583642
| CollectionFlow.cs:447:17:447:23 | object creation of type A : A | CollectionFlow.cs:447:17:447:23 | object creation of type A : A | CollectionFlow.cs:450:14:450:21 | access to array element | $@ | CollectionFlow.cs:450:14:450:21 | access to array element | access to array element |
643+
| CollectionFlow.cs:487:17:487:23 | object creation of type A : A | CollectionFlow.cs:487:17:487:23 | object creation of type A : A | CollectionFlow.cs:489:14:489:20 | access to indexer | $@ | CollectionFlow.cs:489:14:489:20 | access to indexer | access to indexer |
644+
| CollectionFlow.cs:494:17:494:23 | object creation of type A : A | CollectionFlow.cs:494:17:494:23 | object creation of type A : A | CollectionFlow.cs:497:14:497:19 | access to array element | $@ | CollectionFlow.cs:497:14:497:19 | access to array element | access to array element |
645+
| CollectionFlow.cs:502:17:502:23 | object creation of type A : A | CollectionFlow.cs:502:17:502:23 | object creation of type A : A | CollectionFlow.cs:504:14:504:22 | access to indexer | $@ | CollectionFlow.cs:504:14:504:22 | access to indexer | access to indexer |
646+
| CollectionFlow.cs:509:42:509:48 | object creation of type A : A | CollectionFlow.cs:509:42:509:48 | object creation of type A : A | CollectionFlow.cs:511:14:511:22 | access to indexer | $@ | CollectionFlow.cs:511:14:511:22 | access to indexer | access to indexer |
647+
| CollectionFlow.cs:516:17:516:23 | object creation of type A : A | CollectionFlow.cs:516:17:516:23 | object creation of type A : A | CollectionFlow.cs:518:14:518:20 | access to indexer | $@ | CollectionFlow.cs:518:14:518:20 | access to indexer | access to indexer |

0 commit comments

Comments
 (0)