mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Initial implementation of data flow through fields, using the algorithm of the
shared data flow implementation. Fields (and field-like properties) are covered,
and stores can be either
- ordinary assignments, `Foo = x`,
- object initializers, `new C() { Foo = x }`, or
- field initializers, `int Foo = x`.
For field initializers, we need to synthesize calls (`SynthesizedCall`),
callables (`SynthesizedCallable`), parameters (`InstanceParameterNode`), and
arguments (`SynthesizedThisArgumentNode`), as the C# extractor does not (yet)
extract such entities. For example, in
```
class C
{
int Field1 = 1;
int Field2 = 2;
C() { }
}
```
there is a synthesized call from the constructor `C`, with a synthesized `this`
argument, and the targets of that call are two synthesized callables with bodies
`this.Field1 = 1` and `this.Field2 = 2`, respectively.
A consequence of this is that `DataFlowCallable` is no longer an alias for
`DotNet::Callable`, but instead an IPA type.
35 lines
594 B
C#
35 lines
594 B
C#
public class C
|
|
{
|
|
private Elem s1 = new Elem();
|
|
private readonly Elem s2 = new Elem();
|
|
private Elem s3;
|
|
private static Elem s4 = new Elem();
|
|
private Elem s5 { get; set; } = new Elem();
|
|
private Elem s6 { get => new Elem(); set { } }
|
|
|
|
void M1()
|
|
{
|
|
C c = new C();
|
|
c.M2();
|
|
}
|
|
|
|
private C()
|
|
{
|
|
this.s3 = new Elem();
|
|
}
|
|
|
|
public void M2()
|
|
{
|
|
Sink(s1);
|
|
Sink(s2);
|
|
Sink(s3);
|
|
Sink(s4);
|
|
Sink(s5);
|
|
Sink(s6);
|
|
}
|
|
|
|
public static void Sink(object o) { }
|
|
|
|
public class Elem { }
|
|
}
|