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

Fix ILLink behavior for modreq types #108494

Merged
merged 4 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/tools/illink/src/linker/Linker/TypeReferenceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,18 +415,26 @@ public static TypeReference WithoutModifiers (this TypeReference type)
// not an array, pointer, byref, or generic parameter. Conceptually this is supposed to represent the same idea as Roslyn's
// INamedTypeSymbol, or ILC's DefType/MetadataType.
public static bool IsNamedType (this TypeReference typeReference) {
if (typeReference.IsRequiredModifier)
typeReference = ((RequiredModifierType) typeReference).ElementType;
if (typeReference.IsOptionalModifier)
typeReference = ((OptionalModifierType) typeReference).ElementType;
sbomer marked this conversation as resolved.
Show resolved Hide resolved

if (typeReference.IsDefinition || typeReference.IsGenericInstance)
return true;

if (typeReference.IsArray || typeReference.IsByReference || typeReference.IsPointer || typeReference.IsGenericParameter)
if (typeReference.IsArray ||
typeReference.IsByReference ||
typeReference.IsPointer ||
typeReference.IsFunctionPointer ||
typeReference.IsGenericParameter)
return false;

// Shouldn't get called for these cases
Debug.Assert (!typeReference.IsFunctionPointer);
Debug.Assert (!typeReference.IsRequiredModifier);
Debug.Assert (!typeReference.IsOptionalModifier);
Debug.Assert (!typeReference.IsPinned);
Debug.Assert (!typeReference.IsSentinel);
if (typeReference.IsPinned || typeReference.IsSentinel)
return false;

Debug.Assert (typeReference.GetType () == typeof (TypeReference));
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
using Mono.Linker.Tests.Cases.Expectations.Helpers;

namespace Mono.Linker.Tests.Cases.DataFlow
{
// Note: this test's goal is to validate that the product correctly reports unrecognized patterns
// - so the main validation is done by the ExpectedWarning attributes.
[SkipKeptItemsValidation]
[SetupCompileArgument ("/unsafe")]
[ExpectedNoWarnings]
public class FieldDataFlow
{
Expand All @@ -31,6 +33,7 @@ public static void Main ()
instance.WriteToStaticFieldOnADifferentClass ();

instance.WriteUnknownValue ();
instance.WriteModReqType ();

WriteCapturedField.Test ();
WriteFieldOfCapturedInstance.Test ();
Expand Down Expand Up @@ -156,6 +159,16 @@ static void MakeArrayValuesUnknown (object[] array)
}
}

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)]
volatile Type volatileType;

[ExpectedWarning ("IL2074", nameof (GetTypeWithPublicConstructors), nameof (volatileType))]
private void WriteModReqType ()
{
var type = GetTypeWithPublicConstructors ();
volatileType = type;
}

private static void TestStringEmpty ()
{
RequirePublicMethods (string.Empty);
Expand Down Expand Up @@ -394,11 +407,31 @@ static void TestTypeGenericParameter ()
GenericField<Type>.field = GetUnknownType ();
}

[ExpectedWarning ("IL2097")]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
static volatile Type[] volatileTypeArray;

static void TestModReqTypeArray ()
{
volatileTypeArray = new Type[1];
}

[ExpectedWarning ("IL2097")]
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)]
unsafe static delegate*<void> functionPointer;

unsafe static void TestFunctionPointer ()
{
functionPointer = null;
}

public static void Test ()
{
TestUnsupportedType ();
StringRef.Test ();
TestTypeGenericParameter ();
TestModReqTypeArray ();
TestFunctionPointer ();
}
}

Expand Down
Loading