Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial data flows of MemberExpression nodes from/to their base #1421

Merged
merged 38 commits into from
Mar 4, 2024

Conversation

oxisto
Copy link
Member

@oxisto oxisto commented Jan 26, 2024

This PR changes the way we define the DFG for member expressions. Previously, we connected all of them directly to their FieldDeclaration. This is problematic and inconsistent with the way we handle variables/locals in the control sensitive DFG.

This new approach connects the member expression with their base and introduces DFG granularities properties on the DFG edge to denote that this flow is only "partial" and only matches a certain field.

It also includes a very experimental DFG mermaid printer.

Loading
%%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart TD
-834991509["`s
(VariableDeclaration)
field.c(8:19-8:20)`"]-->|"DFG"|-1496149577["`s
(Reference)
field.c(9:3-9:4)`"]
-1496149577["`s
(Reference)
field.c(9:3-9:4)`"]-->|"DFG"|-1150393309["`s
(Reference)
field.c(11:15-11:16)`"]
-1150393309["`s
(Reference)
field.c(11:15-11:16)`"]-->|"DFG (partial, myStruct::field1)"|-98834102["`myStruct::field1
(MemberExpression)
field.c(11:15-11:23)`"]
1721867210["`myStruct::field1
(MemberExpression)
field.c(9:3-9:11)`"]-->|"DFG (partial, myStruct::field1)"|-1496149577["`s
(Reference)
field.c(9:3-9:4)`"]
1390425348["`
(Literal)
field.c(9:14-9:15)`"]-->|"DFG"|1721867210["`myStruct::field1
(MemberExpression)
field.c(9:3-9:11)`"]
-98834102["`myStruct::field1
(MemberExpression)
field.c(11:15-11:23)`"]-->|"DFG"|460955417["`i
(ParameterDeclaration)
field.c(5:18-5:23)`"]

@oxisto oxisto changed the title improve field dfg Improve DFG of MemberExpression nodes Jan 26, 2024
@oxisto oxisto changed the title Improve DFG of MemberExpression nodes Include the concept of partial data flows of MemberExpression nodes to their base Jan 26, 2024
@oxisto oxisto changed the title Include the concept of partial data flows of MemberExpression nodes to their base Introduce the concept of partial data flows of MemberExpression nodes to their base Jan 26, 2024
@oxisto oxisto changed the title Introduce the concept of partial data flows of MemberExpression nodes to their base Partial data flows of MemberExpression nodes to their base Jan 26, 2024
@oxisto
Copy link
Member Author

oxisto commented Jan 26, 2024

It would be interesting, whether we could introduce a "full" DFG flow from the member expression in 9:3 to the one in 11:15. not sure if this is possible?

@oxisto
Copy link
Member Author

oxisto commented Jan 26, 2024

I added an even more hacky approach to this, to have something which is somewhat object-sensitive as well:

Loading
%%{init: {"flowchart": {"htmlLabels": false}} }%%
flowchart TD
-741817423["`s
(VariableDeclaration)
field.c(8:19-8:20)`"]-->|"DFG (full)"|2076022928["`s
(Reference)
field.c(9:3-9:4)`"]
548976981["`myStruct::field1
(MemberExpression)
field.c(9:3-9:11)`"]-->|"DFG (partial, myStruct::field1)"|2076022928["`s
(Reference)
field.c(9:3-9:4)`"]
2076022928["`s
(Reference)
field.c(9:3-9:4)`"]-->|"DFG (full)"|-1873188100["`s
(Reference)
field.c(11:15-11:16)`"]
-1873188100["`s
(Reference)
field.c(11:15-11:16)`"]-->|"DFG (partial, myStruct::field1)"|-1271724331["`myStruct::field1
(MemberExpression)
field.c(11:15-11:23)`"]
2120835341["`
(Literal)
field.c(9:14-9:15)`"]-->|"DFG (full)"|548976981["`myStruct::field1
(MemberExpression)
field.c(9:3-9:11)`"]
548976981["`myStruct::field1
(MemberExpression)
field.c(9:3-9:11)`"]-->|"DFG (full)"|-1271724331["`myStruct::field1
(MemberExpression)
field.c(11:15-11:23)`"]
-1271724331["`myStruct::field1
(MemberExpression)
field.c(11:15-11:23)`"]-->|"DFG (full)"|-1602965580["`i
(ParameterDeclaration)
field.c(5:18-5:23)`"]

@oxisto
Copy link
Member Author

oxisto commented Jan 26, 2024

Here is another example using two structs:

struct myStruct {
  int field1;
};

void doSomething(int i) {}

int main() {
  struct myStruct s1;
  struct myStruct s2;

  s1.field1 = 1;
  s2.field1 = 1;

  doSomething(s1.field1);
  doSomething(s2.field1);
}

This results in the following DFG:

Loading
flowchart TD
-1453381603["s1
(VariableDeclaration)
field.c(8:19-8:21)"]-->|"DFG (full)"|2023738053["s1
(Reference)
field.c(11:15-11:17)"]
-1453381603["s1
(VariableDeclaration)
field.c(8:19-8:21)"]-->|"DFG (full)"|1681679713["s1
(Reference)
field.c(13:3-13:5)"]
2023738053["s1
(Reference)
field.c(11:15-11:17)"]-->|"DFG (partial, myStruct::field1)"|-998413250["myStruct::field1
(MemberExpression)
field.c(11:15-11:24)"]
1681679713["s1
(Reference)
field.c(13:3-13:5)"]-->|"DFG (full)"|2028360463["s1
(Reference)
field.c(16:15-16:17)"]
940621758["myStruct::field1
(MemberExpression)
field.c(13:3-13:12)"]-->|"DFG (partial, myStruct::field1)"|1681679713["s1
(Reference)
field.c(13:3-13:5)"]
-998413250["myStruct::field1
(MemberExpression)
field.c(11:15-11:24)"]-->|"DFG (full)"|800622645["i
(ParameterDeclaration)
field.c(5:18-5:23)"]
202134477["myStruct::field1
(FieldDeclaration)
field.c(2:7-2:13)"]-->|"DFG (full)"|-998413250["myStruct::field1
(MemberExpression)
field.c(11:15-11:24)"]
2028360463["s1
(Reference)
field.c(16:15-16:17)"]-->|"DFG (partial, myStruct::field1)"|-850496130["myStruct::field1
(MemberExpression)
field.c(16:15-16:24)"]
940621758["myStruct::field1
(MemberExpression)
field.c(13:3-13:12)"]-->|"DFG (full)"|-850496130["myStruct::field1
(MemberExpression)
field.c(16:15-16:24)"]
1496727722["
(Literal)
field.c(13:15-13:16)"]-->|"DFG (full)"|940621758["myStruct::field1
(MemberExpression)
field.c(13:3-13:12)"]
-850496130["myStruct::field1
(MemberExpression)
field.c(16:15-16:24)"]-->|"DFG (full)"|800622645["i
(ParameterDeclaration)
field.c(5:18-5:23)"]
-792283555["myStruct::field1
(MemberExpression)
field.c(17:15-17:24)"]-->|"DFG (full)"|800622645["i
(ParameterDeclaration)
field.c(5:18-5:23)"]
998834333["myStruct::field1
(MemberExpression)
field.c(14:3-14:12)"]-->|"DFG (full)"|-792283555["myStruct::field1
(MemberExpression)
field.c(17:15-17:24)"]
2057914096["s2
(Reference)
field.c(17:15-17:17)"]-->|"DFG (partial, myStruct::field1)"|-792283555["myStruct::field1
(MemberExpression)
field.c(17:15-17:24)"]
998834333["myStruct::field1
(MemberExpression)
field.c(14:3-14:12)"]-->|"DFG (partial, myStruct::field1)"|1711233346["s2
(Reference)
field.c(14:3-14:5)"]
1525386664["
(Literal)
field.c(14:15-14:16)"]-->|"DFG (full)"|998834333["myStruct::field1
(MemberExpression)
field.c(14:3-14:12)"]
1711233346["s2
(Reference)
field.c(14:3-14:5)"]-->|"DFG (full)"|2057914096["s2
(Reference)
field.c(17:15-17:17)"]
-1452428260["s2
(VariableDeclaration)
field.c(9:19-9:21)"]-->|"DFG (full)"|1711233346["s2
(Reference)
field.c(14:3-14:5)"]

@oxisto oxisto changed the title Partial data flows of MemberExpression nodes to their base Partial data flows of MemberExpression nodes from/to their base Jan 27, 2024
@KuechA
Copy link
Contributor

KuechA commented Feb 8, 2024

I tried to add another "full" DFG edge between the two occurrences of o.i in the example above. However, I'm not sure if the flow from o to o.i makes sense or if it should be turned around to a flow from o.i to o (which seems to be more consistent to me).

Loading
flowchart TD
-665835678["o
(VariableDeclaration)
nested.c(12:16-12:17)"]-->|"DFG (full)"|1132347668["o
(Reference)
nested.c(13:3-13:4)"]
1132347668["o
(Reference)
nested.c(13:3-13:4)"]-->|"DFG (full)"|1478103936["o
(Reference)
nested.c(15:15-15:16)"]
1132347668["o
(Reference)
nested.c(13:3-13:4)"]-->|"DFG (partial, outer::i)"|381457095["outer::i
(MemberExpression)
nested.c(13:3-13:6)"]
1478103936["o
(Reference)
nested.c(15:15-15:16)"]-->|"DFG (partial, outer::i)"|-1439244217["outer::i
(MemberExpression)
nested.c(15:15-15:18)"]
381457095["outer::i
(MemberExpression)
nested.c(13:3-13:6)"]-->|"DFG (full)"|-1439244217["outer::i
(MemberExpression)
nested.c(15:15-15:18)"]
-1091946730["inner::field
(MemberExpression)
nested.c(13:3-13:12)"]-->|"DFG (partial, inner::field)"|381457095["outer::i
(MemberExpression)
nested.c(13:3-13:6)"]
410745339["outer::i
(FieldDeclaration)
nested.c(6:16-6:17)"]-->|"DFG (full)"|381457095["outer::i
(MemberExpression)
nested.c(13:3-13:6)"]
-1439244217["outer::i
(MemberExpression)
nested.c(15:15-15:18)"]-->|"DFG (partial, inner::field)"|-784138326["inner::field
(MemberExpression)
nested.c(15:15-15:24)"]
-1091946730["inner::field
(MemberExpression)
nested.c(13:3-13:12)"]-->|"DFG (full)"|-784138326["inner::field
(MemberExpression)
nested.c(15:15-15:24)"]
-1476331749["
(Literal)
nested.c(13:15-13:16)"]-->|"DFG (full)"|-1091946730["inner::field
(MemberExpression)
nested.c(13:3-13:12)"]
-117842857["
(ConstructExpression)
null"]-->|"DFG (full)"|410745339["outer::i
(FieldDeclaration)
nested.c(6:16-6:17)"]
-784138326["inner::field
(MemberExpression)
nested.c(15:15-15:24)"]-->|"DFG (full)"|1001880489["i
(ParameterDeclaration)
nested.c(9:18-9:23)"]
-674809415["inner::inner
(ConstructorDeclaration)
null"]-->|"DFG (full)"|-117842857["
(ConstructExpression)
null"]

@oxisto oxisto marked this pull request as ready for review February 22, 2024 14:18
@oxisto oxisto requested a review from konradweiss as a code owner February 22, 2024 14:18
Copy link

sonarqubecloud bot commented Mar 1, 2024

@oxisto oxisto merged commit 29a51e9 into main Mar 4, 2024
4 checks passed
@oxisto oxisto deleted the improve-field-dfg branch March 4, 2024 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants