dotnet / dotnet/linker

Handling of constant expressions for binding flags

Open
#2,638 0 comments 0 reactions 0 assignees View on GitHub
area-Linker: DataFlow
Dominant language
C#
Stars
392
Forks
128
Avg merge
2d 10h
Merged PRs (30d)
2

Description

Linker currently implements very simplistic constant expression evaluation - it only recognizes constant value in IL directly. But Roslyn has lot of clever code and will perform const expr evaluation during lowering into IL - so code like `BindingFlags.Public | BindingFlags.Static` is emitted as `ldc_i4 24`. Unfortunately this clever code doesn't seem to be accessible from the analyzer/operation tree. So we will have to implement our own version.

The problem is compatibility between the two - if the analyzer doesn't recognize some pattern, but the Roslyn lowering will the analyzer will see "unknown" value for binding flags while linker will some specific value. Intrinsic handling is such that "unknown" value always translates to the "most inclusive binding flags possible". So this could lead into a situation where the analyzer sees "unknown" and will "mark" all (for example) methods on a type, potentially generating warnings from some of the methods. But linker will see only "public" and will only "mark" public methods, potentially generating less warnings.
In the end this leads to the case where analyzer produces warning where linker doesn't.

The problem can be also in reverse, if we implement some handling for this in the analyzer, it might be more clever than linker and thus not generate a warning where linker would.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.