-
Notifications
You must be signed in to change notification settings - Fork 465
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
Fix predicated analysis within points to analysis #6750
Conversation
Fixes dotnet#6695 Fix predicated value flow in points to analysis to handle different types between the targetAnalysisEntity and different analysisEntity that shares the same location but has a different type. We use the conversion info between target type and analysis entity type to ensure the value can be flowed.
@@ -237,38 +237,6 @@ private static void ResetAbstractValueIfTracked(AnalysisEntity analysisEntity, P | |||
} | |||
} | |||
|
|||
private static void SetAbstractValueFromPredicate( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method was converted to a local function as it had a single reference.
// Ensure that the predicated 'value' can be flowed from the target type to the analysis entity. | ||
if (!SymbolEqualityComparer.Default.Equals(targetType, analysisEntity.Type)) | ||
{ | ||
var conversion = compilation.ClassifyCommonConversion(targetType, analysisEntity.Type); | ||
if (!conversion.Exists) | ||
{ | ||
// No conversion exists, so we bail out from flowing the predicated value. | ||
return; | ||
} | ||
|
||
if (!conversion.IsIdentity && !conversion.IsNumeric && !conversion.IsNullable) | ||
{ | ||
// For 'Null' predicated value, there needs to be an explicit conversion | ||
// from targetType to the analysisEntity's type to flow the predicated value. | ||
// For 'NotNull' predicated value, there needs to be an implicit conversion | ||
// from targetType to the analysisEntity's type to flow the predicated value. | ||
if (nullState == NullAbstractValue.Null && conversion.IsImplicit || | ||
nullState == NullAbstractValue.NotNull && !conversion.IsImplicit) | ||
{ | ||
return; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the core bug fix. Rest of the code in this local function is same as before.
if (!sourceAnalysisData.TryGetValue(analysisEntity, out var existingValue)) | ||
{ | ||
existingValue = defaultPointsToValueGenerator.GetOrCreateDefaultValue(analysisEntity); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this area well, but wanted to make sure whether we want to add the analysisEntity
and existingValue
pair to sourceAnalysisData
or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is only designed to modify targetAnalysisData
...
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #6750 +/- ##
=======================================
Coverage 96.33% 96.33%
=======================================
Files 1389 1389
Lines 325555 325649 +94
Branches 10731 10735 +4
=======================================
+ Hits 313614 313711 +97
+ Misses 9228 9226 -2
+ Partials 2713 2712 -1 |
Thanks @Youssef1313! |
Fixes #6695
Fix predicated value flow in points to analysis to handle different types between the targetAnalysisEntity and different analysisEntity that shares the same location but has a different type. We use the conversion info between target type and analysis entity type to ensure the value can be flowed.
This change may likely fix other CA1508 false positives which involve conversions. I am going to try to add tests for such cases and see if they are fixed, and if so, add unit tests for them in this PR.I'll instead create separate test PRs for any such fixed issues.