dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.37k stars 4.75k forks source link

ILLink analyzer recognizes `&&` and `||`, but neither trimmer or ilc do #102830

Open jtschuster opened 5 months ago

jtschuster commented 5 months ago

The trim analyzer recognizes and understands && and || and will not warn for code that is guarded by a feature guard, but the trimmer and ilc don't understand it and will not eliminate the branch with problematic code and will warn if there is code that should be considered guarded.

This is expected according to the feature-checks docs: https://github.com/dotnet/runtime/blob/main/docs/design/tools/illink/feature-checks.md#boolean-andor

If neither tool recognizes the pattern and will warn, does it make sense for the analyzer to not warn and leave the user surprised at publish?

dotnet-policy-service[bot] commented 5 months ago

Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas See info in area-owners.md if you want to be subscribed.

sbomer commented 5 months ago

The analyzer behavior fell out of the control-flow graph representation. It's one of those cases where the analyzer would have to do extra work to not recognize that pattern, but the other tools would have to do extra work to recognize it. Personally I'm more inclined to teach the other tools to recognize it.

But I also agree that ideally the analyzer would match the other tools. I haven't looked into it yet, but if it's simple enough to make the analyzer not recognize the pattern I would be supportive.