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

Make flow analysis more conservative in presence of entities that can point to multiple different objects #6794

Merged
merged 2 commits into from
Jul 25, 2023

Conversation

mavasani
Copy link
Contributor

Fixes #6520

Now we store an additional optional EntityForInstanceLocation for analysis entities that can point to more than one possible locations across all control flow paths. This is required to distinguis from other entities that can point to the same set of potential locations, but the actual runtime value of the pointed to location may not be the same for both these entities.

… point to multiple different objects

Fixes dotnet#6520
Now we store an additional optional EntityForInstanceLocation for analysis entities that can point to more than one possible locations across all control flow paths. This is required to distinguis from other entities that can point to the same set of potential locations, but the actual runtime value of the pointed to location may not be the same for both these entities.
literal = predicate.Left;
}

if (identifier.TypePrimitive != PredicateTypePrimitive.F1)
Copy link
Contributor Author

@mavasani mavasani Jul 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core issue here was that we were correctly deducing that identifer and literal can point to the exact same set of two potential runtime objects stored in predicate.Left and predicate.Right. However, the value deduction from predicate in this line identifier.TypePrimitive != PredicateTypePrimitive.F1 shouldn't be applied to literal.TypePrimitive, which was the case prior to this fix. Now, for cases where an entity's instance location can point to more than one runtime location, we also store the entity for this instance location, i.e. entity for identifier in this case, in the analysis entity created for identifier.TypePrimitive. This allows us to avoid applying value deduction for identifier.TypePrimitive to literal.TypePrimitive.

return predicate;
}

if (identifier.TypePrimitive == PredicateTypePrimitive.F2)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are still able to successfully preserve the value deduction for identifier.TypePrimitive from the previous if statement after this fix.

@codecov
Copy link

codecov bot commented Jul 24, 2023

Codecov Report

Merging #6794 (0344c96) into main (62135dd) will increase coverage by 0.00%.
The diff coverage is 95.04%.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #6794    +/-   ##
========================================
  Coverage   96.34%   96.34%            
========================================
  Files        1386     1386            
  Lines      326057   326367   +310     
  Branches    10721    10733    +12     
========================================
+ Hits       314141   314454   +313     
- Misses       9210     9211     +1     
+ Partials     2706     2702     -4     

@mavasani mavasani marked this pull request as ready for review July 24, 2023 12:16
@mavasani mavasani requested a review from a team as a code owner July 24, 2023 12:16
@mavasani
Copy link
Contributor Author

@Youssef1313

@mavasani
Copy link
Contributor Author

@Youssef1313 are you able to help with a quick review here? Thanks!

Copy link
Member

@Youssef1313 Youssef1313 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not following that much on the core logic, but I don't see any obvious comments. Given tests are in place, LGTM

Happy to see DFA is being looked into! 🎉

@mavasani mavasani merged commit 47edf21 into dotnet:main Jul 25, 2023
@mavasani mavasani deleted the CA1508_Enums branch July 25, 2023 14:25
amiru3f pushed a commit to amiru3f/roslyn-analyzers that referenced this pull request Jul 26, 2023
Make flow analysis more conservative in presence of entities that can point to multiple different objects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CA1508 false positive
2 participants