Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ILLink: Trim analyzer doesn't warn on reflection access to annotated members when the source of the Type is GetType on a DAM-annotated class #102002

Closed
jtschuster opened this issue May 7, 2024 · 1 comment · Fixed by #105956 or #105994
Assignees
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@jtschuster
Copy link
Member

The following code in Test() should cause warnings to appear on MethodWithDataflow and MethodWithRequires because o is known to be DamOnTypeAccessesMembers which is annotated with DAMT.All, and is passed to RequiresAll, enforcing the requirement. The analyzer should recognize the pattern of Object.GetType() on a statically known type with DAM on the type.

Related to #93720

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
public class DamOnTypeAccessesMembers
{
	[ExpectedWarning("IL2114", nameof(MethodWithDataflow), nameof(DynamicallyAccessedMembersAttribute), Tool.Trimmer | Tool.NativeAot, "")]
	public void MethodWithDataflow ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type type) { }

	[RequiresDynamicCode ("--MethodWithRequires--")]
	[RequiresUnreferencedCode("--MethodWithRequires--")]
	[RequiresAssemblyFiles("--MethodWithRequires--")]
	[ExpectedWarning("IL2112", "requires unreferenced code", "--MethodWithRequires--", Tool.Trimmer | Tool.NativeAot, "")]
	public void MethodWithRequires () { }

	public static void Test ()
	{
		var o = new DamOnTypeAccessesMembers ();
		var t = o.GetType ();
		t.RequiresAll();
		t.ToString ();
		// This triggers the warnings in the analyzer, but not Object.GetType() on DamOnTypeAccessesMembers
		//typeof(DamOnTypeAccessesMembers).RequiresAll();
	}
}
@jtschuster jtschuster added the area-Tools-ILLink .NET linker development as well as trimming analyzers label May 7, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label May 7, 2024
Copy link
Contributor

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

jtschuster added a commit that referenced this issue May 9, 2024
Populates more issue links in the ExpectedWarning attributes, and adds a more targeted test case for #102002.

Some AOT warnings are expected to only be in the analyzer and NativeAOT, so those are marked as "NativeAOT specific warning"
Ruihan-Yin pushed a commit to Ruihan-Yin/runtime that referenced this issue May 30, 2024
Populates more issue links in the ExpectedWarning attributes, and adds a more targeted test case for dotnet#102002.

Some AOT warnings are expected to only be in the analyzer and NativeAOT, so those are marked as "NativeAOT specific warning"
@agocke agocke added this to the 9.0.0 milestone Jun 3, 2024
@agocke agocke removed the untriaged New issue has not been triaged by the area owner label Jun 3, 2024
@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Aug 5, 2024
@sbomer sbomer self-assigned this Aug 5, 2024
@sbomer sbomer closed this as completed in d5af5bd Aug 6, 2024
@sbomer sbomer reopened this Aug 7, 2024
@sbomer sbomer modified the milestones: 9.0.0, 10.0.0 Aug 13, 2024
@sbomer sbomer closed this as completed in a418138 Aug 19, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Sep 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers in-pr There is an active PR which will close this issue when it is merged
Projects
Archived in project
3 participants