This repository was archived by the owner on Sep 25, 2026. It is now read-only.
Repository navigation
[DAM analyzer] Support exceptional control flow - #2481
Merged
sbomer merged 12 commits intoJan 13, 2022
Merged
Conversation
sbomer
force-pushed
the
exceptionalControlFlow
branch
from
January 6, 2022 17:54
a85eb7a to
bb26622
Compare
By incorporating finally exception state too.
sbomer
marked this pull request as ready for review
January 11, 2022 19:14
vitek-karas
approved these changes
Jan 12, 2022
| switch (operation.Target) { | ||
| case ILocalReferenceOperation localRef: | ||
| state.Set (new LocalKey (localRef.Local), value); | ||
| state.Current.Set (new LocalKey (localRef.Local), value); |
Member
There was a problem hiding this comment.
In both places the Set should affect both the current and exception values. Why not add a Set method onto the state itself which does this automatically.
| public override TValue VisitFlowCaptureReference (IFlowCaptureReferenceOperation operation, DataFlowState<LocalState<TValue>> state) | ||
| { | ||
| return state.Get (new LocalKey (operation.Id)); | ||
| return state.Current.Get (new LocalKey (operation.Id)); |
Member
There was a problem hiding this comment.
Similarly for the get - there should be no place where we ask for a specific local value on the exception state. So let's just add a Get method onto the state which returns the current.
Share code in ControlFlowGraphProxy Implement wrapper type where Set automatically meets the exception state. The Set operation is specific to the local dataflow analysis, so this introduces a state interface to track the current/exception state. Only the state type for the local dataflow analysis (LocalDataFlowState) implements this specialized behavior.
Member
Author
|
I'm going to go ahead and merge this to unblock changes that depend on the analyzer not throwing exceptions on existing tests - if there's any more feedback, feel free to leave it here and I will address it in a follow-up. |
agocke
pushed a commit
to dotnet/runtime
that referenced
this pull request
Nov 16, 2022
This includes a change to make the analyzer tests fail when an exception is thrown. This models exceptional control flow by maintaining an exception state for try/catch regions, which is updated to include all possible states encountered within that region. This exceptional state is propagated from try regions to the beginning of catch regions, and from try or catch regions to the beginning of finally regions. Finally regions are represented as additional information for each predecessor edge in the control flow graph, following the data model given by Roslyn's CFG. Each edge includes a list of finally regions through which control flows as part of the edge before reaching its destination. For now, this approach inefficiently propagates the old finally state along these chains of finally regions when it encounters them. This has the downside that long finally regions will cause re-analysis until each finally block sees a new state. The finally state is also unified along all such paths, so the warning state at the exit of a finally is a conservative approximation that accounts for all normal control flow leading to the finally region. Additionally, the finally regions are analyzed separately for the case when an exception causes a finally block to be reached. Inside the finally region, this will produce a superset of the warnings for normal control flow inside the same region. However this exceptional finally state does not flow out of the finally, to avoid spurious warnings in code that is unreachable when executing finally blocks due to exceptions. Also, implement a wrapper type where Set automatically meets the exception state. The Set operation is specific to the local dataflow analysis, so this introduces a state interface to track the current/exception state. Only the state type for the local dataflow analysis (LocalDataFlowState) implements this specialized behavior. Commit migrated from dotnet/linker@b3c58ad
sbomer
added a commit
to dotnet/runtime
that referenced
this pull request
Nov 1, 2023
…94101) Fixes a bug I encountered while adding some new tests for feature checks. While analyzing finally regions in the mode where they will not exit normally, we weren't correctly propagating dataflow states through nested finally regions. See dotnet/linker#2481 for original context around the analysis done here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This includes a change to make the analyzer tests fail when an exception is thrown.
This models exceptional control flow by maintaining an exception state for try/catch regions, which is updated to include all possible states encountered within that region. This exceptional state is propagated from try regions to the beginning of catch regions, and from try or catch regions to the beginning of finally regions.
Finally regions are represented as additional information for each predecessor edge in the control flow graph, following the data model given by Roslyn's CFG. Each edge includes a list of finally regions through which control flows as part of the edge before reaching its destination. For now, this approach inefficiently propagates the old finally state along these chains of finally regions when it encounters them. This has the downside that long finally regions will cause re-analysis until each finally block sees a new state.
The finally state is also unified along all such paths, so the warning state at the exit of a finally is a conservative approximation that accounts for all normal control flow leading to the finally region.
Additionally, the finally regions are analyzed separately for the case when an exception causes a finally block to be reached. Inside the finally region, this will produce a superset of the warnings for normal control flow inside the same region. However this exceptional finally state does not flow out of the finally, to avoid spurious warnings in code that is unreachable when executing finally blocks due to exceptions.
This doesn't yet include any handling for filter regions. I'll work on that next, possibly in a follow-up change.