C#: Add dataflow field test for ref structs with ref and ordinary fields.

This commit is contained in:
Michael Nebel
2024-02-01 13:40:12 +01:00
parent 73d0b7ef49
commit 4dfeff38f9
2 changed files with 31 additions and 1 deletions

View File

@@ -17,7 +17,7 @@ public class E
s.Field = o;
}
private void M()
private void M1()
{
var o = Source<object>(1);
var s = CreateS(o);
@@ -28,6 +28,35 @@ public class E
Sink(s.Field); // no flow
}
ref struct RefS
{
public object Field;
public ref object RefField;
public RefS(object o1, ref object o2)
{
Field = o1;
RefField = ref o2;
}
}
static void PartialSetter(RefS s, object o)
{
s.Field = o;
s.RefField = o;
}
private void M2()
{
var o1 = new object();
var o2 = new object();
var refs = new RefS(o1, ref o2);
var taint = Source<object>(2);
PartialSetter(refs, taint);
Sink(refs.Field); // no flow
Sink(refs.RefField); // $ hasValueFlow=2
}
public static void Sink(object o) { }
static T Source<T>(object source) => throw null;

View File

@@ -1,4 +1,5 @@
testFailures
| E.cs:57:30:57:48 | // ... | Missing result:hasValueFlow=2 |
edges
| A.cs:5:17:5:28 | call to method Source<C> : C | A.cs:6:24:6:24 | access to local variable c : C |
| A.cs:5:17:5:28 | call to method Source<C> : C | A.cs:6:24:6:24 | access to local variable c : C |