Skip to content

Trim analysis fails to track integer across iterator yield #110553

Open
@sbomer

Description

@sbomer

For code like this:

public static IEnumerable<int> IteratorWithIntegerDataflow ()
{
	int integerLocal = 0;
	yield return 0;
	var types = new Type[] { GetWithPublicMethods (), GetWithPublicFields () };
	types[integerLocal].RequiresPublicMethods ();
}

ILLink tracks assignments and reads of the int local, and before #110105 this was enough for the analysis to determine that array element 0 satisfies PublicMethods.

The dependency update changed the iterator codegen, introducing a dispose method that assigns null to the array. This interferes with the analysis and causes this to report a warning:

Trim analysis warning IL2062: Mono.Linker.Tests.Cases.DataFlow.CompilerGeneratedCodeAccessedViaReflection.IteratorStateMachines.<IteratorWithIntegerDataflow>d__3.MoveNext(): Value passed to parameter 'type' of method 'Mono.Linker.Tests.Cases.Expectations.Helpers.DataFlowTypeExtensions.RequiresPublicMethods(Type)' can not be statically determined and may not meet 'DynamicallyAccessedMembersAttribute' requirements.

Metadata

Metadata

Assignees

Labels

area-Tools-ILLink.NET linker development as well as trimming analyzers

Type

No type

Projects

Status

No status

Relationships

None yet

Development

No branches or pull requests

Issue actions