Repository navigation
[DAM analyzer] Analyze exception filters - #2593
Conversation
Also add a catch clause to testcase to test propagation from filter to catch.
To a later catch or filter region. This should check all previous filter clauses, not just the immediately preceding one. Also update the testcase to show that both previous filter states reach a subsequent filter state.
From the IL perspective (not sure how much that is relevant to the analyzer), a valid filter region will have exactly one There can be multiple basic blocks within the filter but they all have to lead to the single Type academicalSituation = null;
try { throw new Exception(); }
catch (Exception ex) when ((ex is NullReferenceException ? (academicalSituation = typeof(object)) : (academicalSituation = typeof(string))) == null) { }
`` |
|
Thanks for the example @MichalStrehovsky, I added a test similar to it. It looks like Roslyn does insert a final basic block that merges the two branches and is the source for the fall-through case (where control doesn't enter the corresponding handler), so the assumption holds at least for this case. |
|
@tlakollo I addressed the case you pointed out where a filter may throw an exception that is caught by a later catch, PTAL. Thanks for noticing this! |
This adds support for exception filters in the analyzer. Now the exception state will flow from from try blocks to any catch blocks without filters, or to the filter regions of any catch blocks that do have filters. Additionally, the dataflow state flows from a filter region to the next filter or catch. We don't check whether the exception type of the filter regions match, but conservatively assume that control can flow out of any filter to the next filter or catch. This also assumes that control leaves the filter region from its last block - I don't know if there are cases where a filter region can contain more than one basic block, so if this is possible the logic might need to be updated. I added a few testcases with dataflow and side effects in filter regions. This fixes dotnet/linker#2415 and allows enabling two more of the previously failing tests. Commit migrated from dotnet/linker@60bce42
This adds support for exception filters in the analyzer. Now the exception state will flow from from try blocks to any catch blocks without filters, or to the filter regions of any catch blocks that do have filters. Additionally, the dataflow state flows from a filter region to the next filter or catch. We don't check whether the exception type of the filter regions match, but conservatively assume that control can flow out of any filter to the next filter or catch.
This also assumes that control leaves the filter region from its last block - I don't know if there are cases where a filter region can contain more than one basic block, so if this is possible the logic might need to be updated.
I added a few testcases with dataflow and side effects in filter regions. This fixes #2415 and allows enabling two more of the previously failing tests.