Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public CapturedReferenceValue (IOperation operation)
case OperationKind.FieldReference:
case OperationKind.ParameterReference:
case OperationKind.ArrayElementReference:
case OperationKind.InlineArrayAccess:
case OperationKind.ImplicitIndexerReference:
break;
case OperationKind.None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ TValue ProcessSingleTargetAssignment (IOperation targetOperation, ISimpleAssignm
}
return value;
}
case IInlineArrayAccessOperation inlineArrayAccess: {
TValue arrayRef = Visit (inlineArrayAccess.Instance, state);
TValue index = Visit (inlineArrayAccess.Argument, state);
TValue value = Visit (operation.Value, state);
HandleArrayElementWrite (arrayRef, index, value, operation, merge: merge);
return value;
}
case IDiscardOperation:
// Assignments like "_ = SomeMethod();" don't need dataflow tracking.
// Seems like this can't happen with a flow capture operation.
Expand Down Expand Up @@ -509,6 +516,15 @@ public override TValue VisitArrayElementReference (IArrayElementReferenceOperati
return HandleArrayElementRead (Visit (operation.ArrayReference, state), Visit (operation.Indices[0], state), operation);
}

public override TValue VisitInlineArrayAccess (IInlineArrayAccessOperation operation, LocalDataFlowState<TValue, TValueLattice> state)
{
Debug.Assert (operation.GetValueUsageInfo (OwningSymbol).HasFlag (ValueUsageInfo.Read));
if (!operation.GetValueUsageInfo (OwningSymbol).HasFlag (ValueUsageInfo.Read))
return TopValue;

return HandleArrayElementRead (Visit (operation.Instance, state), Visit (operation.Argument, state), operation);
}

public override TValue VisitArgument (IArgumentOperation operation, LocalDataFlowState<TValue, TValueLattice> state)
{
return Visit (operation.Value, state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static Task VerifyDynamicallyAccessedMembersCodeFix (
var test = new VerifyCS.Test {
TestCode = source,
FixedCode = fixedSource,
ReferenceAssemblies = TestCaseUtils.Net6PreviewAssemblies
ReferenceAssemblies = TestCaseUtils.NetCoreAppReferencessemblies
};
test.ExpectedDiagnostics.AddRange (baselineExpected);
test.TestState.AnalyzerConfigFiles.Add (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static Task VerifyRequiresAssemblyFilesCodeFix (
var test = new VerifyCS.Test {
TestCode = source,
FixedCode = fixedSource,
ReferenceAssemblies = TestCaseUtils.Net6PreviewAssemblies
ReferenceAssemblies = TestCaseUtils.NetCoreAppReferencessemblies
};
test.ExpectedDiagnostics.AddRange (baselineExpected);
test.TestState.AnalyzerConfigFiles.Add (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static Task VerifyRequiresDynamicCodeCodeFix (
var test = new VerifyCS.Test {
TestCode = source + dynamicCodeAttribute,
FixedCode = fixedSource + dynamicCodeAttribute,
ReferenceAssemblies = TestCaseUtils.Net6PreviewAssemblies
ReferenceAssemblies = TestCaseUtils.NetCoreAppReferencessemblies
};
test.ExpectedDiagnostics.AddRange (baselineExpected);
test.TestState.AnalyzerConfigFiles.Add (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static Task VerifyRequiresUnreferencedCodeCodeFix (
var test = new VerifyCS.Test {
TestCode = source,
FixedCode = fixedSource,
ReferenceAssemblies = TestCaseUtils.Net6PreviewAssemblies
ReferenceAssemblies = TestCaseUtils.NetCoreAppReferencessemblies
};
test.ExpectedDiagnostics.AddRange (baselineExpected);
test.TestState.AnalyzerConfigFiles.Add (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ public abstract class TestCaseUtils
{
private static readonly string MonoLinkerTestsCases = "Mono.Linker.Tests.Cases";

public static readonly ReferenceAssemblies Net6PreviewAssemblies =
public static readonly ReferenceAssemblies NetCoreAppReferencessemblies =
new ReferenceAssemblies (
"net8.0",
new PackageIdentity ("Microsoft.NETCore.App.Ref", "8.0.0-alpha.1.23060.19"),
new PackageIdentity ("Microsoft.NETCore.App.Ref", "8.0.0-rc.1.23419.4"),
Path.Combine ("ref", "net8.0"))
.WithNuGetConfigFilePath (Path.Combine (TestCaseUtils.GetRepoRoot (), "NuGet.config"));

private static ImmutableArray<MetadataReference> s_net6Refs;
private static ImmutableArray<MetadataReference> s_netcoreappRefs;
public static async ValueTask<ImmutableArray<MetadataReference>> GetNet6References ()
{
if (s_net6Refs.IsDefault) {
var refs = await Net6PreviewAssemblies.ResolveAsync (null, default);
ImmutableInterlocked.InterlockedInitialize (ref s_net6Refs, refs);
if (s_netcoreappRefs.IsDefault) {
var refs = await NetCoreAppReferencessemblies.ResolveAsync (null, default);
ImmutableInterlocked.InterlockedInitialize (ref s_netcoreappRefs, refs);
}
return s_net6Refs;
return s_netcoreappRefs;
}

public static string FindTestSuiteDir (string rootDir, string suiteName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static Task VerifyUnconditionalSuppressMessageCodeFixWithRUC (
var test = new VerifyCSUSMwithRUC.Test {
TestCode = source,
FixedCode = fixedSource,
ReferenceAssemblies = TestCaseUtils.Net6PreviewAssemblies
ReferenceAssemblies = TestCaseUtils.NetCoreAppReferencessemblies
};
test.ExpectedDiagnostics.AddRange (baselineExpected);
test.TestState.AnalyzerConfigFiles.Add (
Expand All @@ -69,7 +69,7 @@ static Task VerifyUnconditionalSuppressMessageCodeFixWithRAF (
var test = new VerifyCSUSMwithRAF.Test {
TestCode = source,
FixedCode = fixedSource,
ReferenceAssemblies = TestCaseUtils.Net6PreviewAssemblies
ReferenceAssemblies = TestCaseUtils.NetCoreAppReferencessemblies
};
test.ExpectedDiagnostics.AddRange (baselineExpected);
test.TestState.AnalyzerConfigFiles.Add (
Expand All @@ -89,7 +89,7 @@ static Task VerifyUnconditionalSuppressMessageCodeFixWithRDC (
var test = new VerifyCSUSMwithRDC.Test {
TestCode = source + dynamicCodeAttribute,
FixedCode = fixedSource + dynamicCodeAttribute,
ReferenceAssemblies = TestCaseUtils.Net6PreviewAssemblies
ReferenceAssemblies = TestCaseUtils.NetCoreAppReferencessemblies
};
test.ExpectedDiagnostics.AddRange (baselineExpected);
test.TestState.AnalyzerConfigFiles.Add (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
using Mono.Linker.Tests.Cases.Expectations.Helpers;
Expand Down Expand Up @@ -273,6 +276,41 @@ static void TestArrayElementAssignment (bool b = true)
arr2[0].RequiresAll ();
}

[Kept]
[KeptAttributeAttribute (typeof (InlineArrayAttribute))]
[InlineArray (8)]
public struct InlineTypeArray
{
[Kept]
public Type t;
}

[Kept]
[ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresAll))]
[ExpectedWarning ("IL2062", nameof (DataFlowTypeExtensions.RequiresAll))]
static void TestInlineArrayElementReferenceAssignment (bool b = true)
{
var arr1 = new InlineTypeArray ();
arr1[0] = GetUnknownType ();
var arr2 = new InlineTypeArray ();
arr2[0] = GetTypeWithPublicConstructors ();
(b ? ref arr1[0] : ref arr2[0]) = GetTypeWithPublicFields ();
arr1[0].RequiresAll ();
arr2[0].RequiresAll ();
}

// Inline array references are not allowed in conditionals, unlike array references.
// static void TestInlineArrayElementAssignment (bool b = true)
// {
// var arr1 = new InlineTypeArray ();
// arr1[0] = GetUnknownType ();
// var arr2 = new InlineTypeArray ();
// arr2[0] = GetTypeWithPublicConstructors ();
// (b ? arr1 : arr2)[0] = GetTypeWithPublicFields ();
// arr1[0].RequiresAll ();
// arr2[0].RequiresAll ();
// }

[Kept]
[ExpectedWarning ("IL2074", nameof (_publicMethodsField), nameof (GetUnknownType))]
[ExpectedWarning ("IL2074", nameof (_publicPropertiesField), nameof (GetUnknownType))]
Expand Down Expand Up @@ -321,6 +359,8 @@ public static void Test ()
TestLocalAssignment ();
TestArrayElementReferenceAssignment ();
TestArrayElementAssignment ();
TestInlineArrayElementReferenceAssignment ();
// TestInlineArrayElementAssignment ();
TestNullCoalescingAssignment ();
TestNullCoalescingAssignmentComplex ();
TestDataFlowOnRightHandOfAssignment ();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// 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;
Expand Down Expand Up @@ -45,8 +45,7 @@ struct UnannotatedTypeArray
public Type value;
}

// Analyzer doesn't understand inline arrays currently - so it doesn't produce a warning here
[ExpectedWarning ("IL2065", "GetProperty", ProducedBy = Tool.Trimmer | Tool.NativeAot)]
[ExpectedWarning ("IL2065", "GetProperty")]
static void AccessUnannotatedTypeArray ()
{
UnannotatedTypeArray a = new UnannotatedTypeArray ();
Expand All @@ -64,7 +63,7 @@ struct AnnotatedTypeArray
}

// Currently tracking of annotations on inline array values is not implemented
[ExpectedWarning("IL2065", "GetProperty", ProducedBy = Tool.Trimmer | Tool.NativeAot)]
[ExpectedWarning("IL2065", "GetProperty")]
static void AccessAnnotatedTypeArray ()
{
AnnotatedTypeArray a = new AnnotatedTypeArray ();
Expand Down