Skip to content

Commit

Permalink
ILLink: Avoid warning for RUC field rooted as part of a root assembly (
Browse files Browse the repository at this point in the history
…#108498)

Similar to #81864, fields
in a RUC class are producing trim analysis warnings in the OOB
trim step (the mentioned issue was specific to library mode, but
it's also a problem for the normal root assembly mode).

This extends the fix from
#84620 to avoid producing
warnings for fields that are marked just because an assembly was
rooted. Arguably rooting an assembly _should_ warn about rooted
RUC members, but that's not the case today for RUC methods, so
this makes the behavior consistent for fields.

---------

Co-authored-by: Jackson Schuster <[email protected]>
  • Loading branch information
sbomer and jtschuster authored Oct 4, 2024
1 parent e183f70 commit e67f230
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/tools/illink/src/linker/Linker.Steps/MarkStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,7 @@ void ProcessAnalysisAnnotationsForField (FieldDefinition field, DependencyKind d
case DependencyKind.AlreadyMarked:
case DependencyKind.TypePreserve:
case DependencyKind.PreservedMethod:
case DependencyKind.MemberOfType:
return;

case DependencyKind.DynamicallyAccessedMemberOnType:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Diagnostics.CodeAnalysis;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;

namespace Mono.Linker.Tests.Cases.RequiresCapability
{
[SetupLinkerArgument ("-a", "test.exe", "all")]

[SkipKeptItemsValidation]
[ExpectedNoWarnings]
public class RequiresInRootAllAssembly
{
public static void Main ()
{
}

[RequiresDynamicCode ("--MethodWhichRequires--")]
public static void MethodWhichRequires () { }

[RequiresDynamicCode ("--InstanceMethodWhichRequires--")]
public void InstanceMethodWhichRequires () { }

public sealed class ClassWithDAMAnnotatedMembers
{
public static void Method ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] Type type) { }

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
public static Type Field;
}

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
public sealed class ClassWithDAMAnnotation
{
public void Method () { }
}

[RequiresUnreferencedCode ("--ClassWithRequires--")]
public sealed class ClassWithRequires
{
public static int Field;

internal static int InternalField;

private static int PrivateField;

public static void Method () { }

public void InstanceMethod () { }

public static int Property { get; set; }

public static event EventHandler PropertyChanged;
}
}
}

0 comments on commit e67f230

Please sign in to comment.