Skip to content

Analyze nested functions in Roslyn analyzer#2892

Merged
sbomer merged 6 commits intodotnet:mainfrom
sbomer:analyzerCGCDataflow
Jul 15, 2022
Merged

Analyze nested functions in Roslyn analyzer#2892
sbomer merged 6 commits intodotnet:mainfrom
sbomer:analyzerCGCDataflow

Conversation

@sbomer
Copy link
Copy Markdown
Member

@sbomer sbomer commented Jul 13, 2022

This is the Roslyn analyzer counterpart to #2842.

It adds detection of captured locals, and conservatively analyzes them with all values that it encounters in the method.
The analyzer makes no attempt to warn on reflection access to compiler-generated fields, because the compilation strategy for these is not known by the analyzer.

Unlike the linker, this doesn't do conservative analysis for hoisted locals in state machine methods. The analyzer already understands control flow within state machines the same way it does for normal methods, so we just continue using that behavior here. We could consider improving the linker's analysis to match, but it would require a deeper understanding of the state machine methods.

@sbomer sbomer requested a review from marek-safar as a code owner July 13, 2022 22:04
In the exception handling logic to avoid walking out to regions that
are part of a different control flow graph.

This fixes an analyzer crash discovered when running with these changes
on dotnet/runtime.
Copy link
Copy Markdown
Member

@vitek-karas vitek-karas left a comment

Choose a reason for hiding this comment

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

Looks good!

var cfg = method.ControlFlowGraph;
var lValueFlowCaptures = LValueFlowCapturesProvider.CreateLValueFlowCaptures (cfg);
var visitor = GetVisitor (method.Method, cfg, lValueFlowCaptures, interproceduralState);
Fixpoint (new ControlFlowGraphProxy (cfg), Lattice, visitor);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not for this PR - in theory we should be able to use the solver similar to Fixpoint to drive the inter-method analysis as well instead of rolling out a private simple version here.

Adjust indentation
@sbomer sbomer merged commit d27ff61 into dotnet:main Jul 15, 2022
@sbomer sbomer deleted the analyzerCGCDataflow branch July 18, 2022 16:34
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
This is the Roslyn analyzer counterpart to
dotnet/linker@bc46e44.

It adds detection of captured locals, and conservatively analyzes
them with all values that it encounters in the method.  The
analyzer makes no attempt to warn on reflection access to
compiler-generated fields, because the compilation strategy for
these is not known by the analyzer.

Unlike the linker, this doesn't do conservative analysis for
hoisted locals in state machine methods. The analyzer already
understands control flow within state machines the same way it
does for normal methods, so we just continue using that behavior
here. We could consider improving the linker's analysis to match,
but it would require a deeper understanding of the state machine
methods.


Commit migrated from dotnet/linker@d27ff61
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants