Skip to content

Perform exceptions path analysis for all flow analyses #6828

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

Merged
merged 4 commits into from
Aug 2, 2023

Conversation

mavasani
Copy link

@mavasani mavasani commented Aug 2, 2023

Fixes #5199
Fixes #5160
Fixes #4984

We already had implementation and option based support to perform exception path analysis to handle all operations that can potentially throw an exception, and hence need flow analysis data at the point of operation to be merged with analysis data at start of reachable catch blocks from that operation. However, we were only performing this analysis post pass when flow analysis is looking at exceptions data. Now we do it for all analysis as this is required for more accurate input analysis data at start of catch and finally blocks.

NOTE: Fixing this issue led to an assert firing in CodeAnalysis dataflow operation visitor for an existing unit test, which has also been fixed in this PR

Fixes dotnet#5199
Fixes dotnet#5160

We already had implementation and option based support to perform exception path analysis to handle all operations that can potentially throw an exception, and hence need flow analysis data at the point of operation to be merged with analysis data at start of reachable catch blocks from that operation. However, we were only performing this analysis post pass when flow analysis is looking at exceptions data. Now we do it for all analysis as this is required for more accurate input analysis data at start of catch and finally blocks.
NOTE: Fixing this issue led to an assert firing in CodeAnalysis dataflow operation visitor for an existing unit test, which has also been fixed in this PR
@mavasani mavasani requested a review from a team as a code owner August 2, 2023 11:26
Comment on lines +118 to +123
// If we are executing exception paths analysis OR have at least one try/catch/finally block
// in the method, execute an exception path analysis post pass.
// This post pass will handle all possible operations within the control flow graph that can
// throw an exception and merge analysis data after all such operation analyses into the
// catch blocks reachable from those operations.
if (analysisContext.ExceptionPathsAnalysis || hasAnyTryBlock)
Copy link
Author

Choose a reason for hiding this comment

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

This is the core fix

@codecov
Copy link

codecov bot commented Aug 2, 2023

Codecov Report

Merging #6828 (c764ccd) into main (48e7c8f) will increase coverage by 0.01%.
Report is 13 commits behind head on main.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6828      +/-   ##
==========================================
+ Coverage   96.36%   96.37%   +0.01%     
==========================================
  Files        1401     1401              
  Lines      329956   330237     +281     
  Branches    10837    10841       +4     
==========================================
+ Hits       317968   318272     +304     
+ Misses       9256     9242      -14     
+ Partials     2732     2723       -9     

@mavasani
Copy link
Author

mavasani commented Aug 2, 2023

@Youssef1313

@@ -286,11 +291,9 @@ protected DataFlowAnalysis(AbstractAnalysisDomain<TAnalysisData> analysisDomain,

// Check if we are starting a try region which has one or more associated catch/filter regions.
// If so, we conservatively merge the input data for try region into the input data for the associated catch/filter regions.
#pragma warning disable CA1508 // Avoid dead conditional code - https://github.com/dotnet/roslyn-analyzers/issues/4408
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants