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 @@ -23,7 +23,7 @@ public ExpectedWarningAttribute (string warningCode, params string[] messageCont
/// Property used by the result checkers of trimmer and analyzers to determine whether
/// the tool should have produced the specified warning on the annotated member.
/// </summary>
public ProducedBy ProducedBy { get; set; } = ProducedBy.TrimmerAndAnalyzer;
public ProducedBy ProducedBy { get; set; } = ProducedBy.TrimmerAnalyzerAndNativeAot;

public bool CompilerGeneratedCode { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public LogContainsAttribute (string message, bool regexMatch = false)
/// Property used by the result checkers of trimmer and analyzers to determine whether
/// the tool should have produced the specified warning on the annotated member.
/// </summary>
public ProducedBy ProducedBy { get; set; } = ProducedBy.TrimmerAndAnalyzer;
public ProducedBy ProducedBy { get; set; } = ProducedBy.TrimmerAnalyzerAndNativeAot;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public LogDoesNotContainAttribute (string message, bool regexMatch = false)
/// Property used by the result checkers of trimmer and analyzers to determine whether
/// the tool should have produced the specified warning on the annotated member.
/// </summary>
public ProducedBy ProducedBy { get; set; } = ProducedBy.TrimmerAndAnalyzer;
public ProducedBy ProducedBy { get; set; } = ProducedBy.TrimmerAnalyzerAndNativeAot;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum ProducedBy
{
Trimmer = 1,
Analyzer = 2,
TrimmerAndAnalyzer = Trimmer | Analyzer
NativeAot = 4,
TrimmerAnalyzerAndNativeAot = Trimmer | Analyzer | NativeAot
}
}
110 changes: 60 additions & 50 deletions test/Mono.Linker.Tests.Cases/DataFlow/ArrayDataFlow.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// 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.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
Expand Down Expand Up @@ -57,6 +60,7 @@ static void TestConstructors ()
RequireNothing (type);
}

// NativeAOT doesn't implement this yet: https://github.com/dotnet/runtime/issues/72833
[ExpectedWarning ("IL2105",
"Type 'System.Invalid.TypeName' was not found in the caller assembly nor in the base library. " +
"Type name strings used for dynamically accessing a type should be assembly qualified.",
Expand Down
8 changes: 4 additions & 4 deletions test/Mono.Linker.Tests.Cases/DataFlow/ByRefDataflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public static void Main ()

[Kept]
// Trimmer and analyzer use different formats for ref parameters: https://github.com/dotnet/linker/issues/2406
[ExpectedWarning ("IL2077", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(Type&)", ProducedBy = ProducedBy.Trimmer)]
[ExpectedWarning ("IL2077", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(Type&)", ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
[ExpectedWarning ("IL2077", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(ref Type)", ProducedBy = ProducedBy.Analyzer)]
[ExpectedWarning ("IL2069", nameof (s_typeWithPublicParameterlessConstructor), "parameter 'type'", nameof (MethodWithRefParameter), ProducedBy = ProducedBy.Trimmer)]
[ExpectedWarning ("IL2069", nameof (s_typeWithPublicParameterlessConstructor), "parameter 'type'", nameof (MethodWithRefParameter), ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
// MethodWithRefParameter (ref x)
[ExpectedWarning ("IL2077", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(Type&)", ProducedBy = ProducedBy.Trimmer)]
[ExpectedWarning ("IL2077", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(Type&)", ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
[ExpectedWarning ("IL2077", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(ref Type)", ProducedBy = ProducedBy.Analyzer)]
public static void PassRefToField ()
{
Expand All @@ -58,7 +58,7 @@ public static void PassRefToField ()

[Kept]
// Trimmer and analyzer use different formats for ref parameters: https://github.com/dotnet/linker/issues/2406
[ExpectedWarning ("IL2067", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(Type&)", ProducedBy = ProducedBy.Trimmer)]
[ExpectedWarning ("IL2067", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(Type&)", ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
[ExpectedWarning ("IL2067", nameof (ByRefDataflow) + "." + nameof (MethodWithRefParameter) + "(ref Type)", ProducedBy = ProducedBy.Analyzer)]
public static void PassRefToParameter (Type parameter)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ static IEnumerable<int> FlowAcrossYieldReturn ()

// Linker tracks all assignments of hoisted locals, so this produces warnings.
[ExpectedWarning ("IL2072", nameof (GetWithPublicMethods), nameof (DataFlowTypeExtensions.RequiresPublicFields), CompilerGeneratedCode = true,
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
[ExpectedWarning ("IL2072", nameof (GetWithPublicFields), nameof (DataFlowTypeExtensions.RequiresPublicMethods), CompilerGeneratedCode = true,
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
static IEnumerable<int> NoFlowAcrossYieldReturn ()
{
Type t = GetWithPublicMethods ();
Expand Down Expand Up @@ -119,9 +119,9 @@ static async void FlowAcrossAwait ()

// Linker tracks all assignments of hoisted locals, so this produces warnings.
[ExpectedWarning ("IL2072", nameof (GetWithPublicMethods), nameof (DataFlowTypeExtensions.RequiresPublicFields), CompilerGeneratedCode = true,
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
[ExpectedWarning ("IL2072", nameof (GetWithPublicFields), nameof (DataFlowTypeExtensions.RequiresPublicMethods), CompilerGeneratedCode = true,
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
static async void NoFlowAcrossAwait ()
{
Type t = GetWithPublicMethods ();
Expand Down Expand Up @@ -430,7 +430,7 @@ static void ReadCapturedVariableAfterWriteAfterDefinition ()
Type t = GetWithPublicFields ();

Action lambda =
[ExpectedWarning ("IL2072", nameof (GetWithPublicFields), nameof (DataFlowTypeExtensions.RequiresAll))]
[ExpectedWarning ("IL2072", nameof (GetWithPublicFields), nameof (DataFlowTypeExtensions.RequiresAll))]
[ExpectedWarning ("IL2072", nameof (GetWithPublicMethods), nameof (DataFlowTypeExtensions.RequiresAll))]
() => t.RequiresAll ();

Expand Down Expand Up @@ -703,4 +703,4 @@ struct TestStruct
public Type TypeWithPublicFields => null;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,4 @@ void LocalFunction ()
LocalFunction ();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// 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.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
Expand Down
48 changes: 24 additions & 24 deletions test/Mono.Linker.Tests.Cases/DataFlow/ExceptionalDataFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ public static void MultipleTryExits ()

// Linker merges branches going forward.
[ExpectedWarning ("IL2073", nameof (MultipleFinallyPaths) + "()", nameof (GetWithPublicMethods) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
[ExpectedWarning ("IL2073", nameof (MultipleFinallyPaths) + "()", nameof (GetWithPublicFields) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
[ExpectedWarning ("IL2073", nameof (MultipleFinallyPaths) + "()", nameof (GetWithPublicProperties) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)]
public static Type MultipleFinallyPaths ()
{
Expand Down Expand Up @@ -325,25 +325,25 @@ public class Exception2 : Exception { }

// Linker merges branches going forward.
[ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicFields) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
[ExpectedWarning ("IL2072", nameof (RequireAll4) + "(Type)", nameof (GetWithPublicProperties) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
[ExpectedWarning ("IL2072", nameof (RequireAll5) + "(Type)", nameof (GetWithPublicFields) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
[ExpectedWarning ("IL2072", nameof (RequireAll5) + "(Type)", nameof (GetWithPublicProperties) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
[ExpectedWarning ("IL2072", nameof (RequireAll7) + "(Type)", nameof (GetWithPublicFields) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
[ExpectedWarning ("IL2072", nameof (RequireAll7) + "(Type)", nameof (GetWithPublicProperties) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
[ExpectedWarning ("IL2072", nameof (RequireAll7) + "(Type)", nameof (GetWithPublicEvents) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
[ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
[ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicProperties) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
[ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicEvents) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]

public static void TryFlowsToMultipleCatchAndFinally ()
{
Expand Down Expand Up @@ -487,7 +487,7 @@ public static void NestedWithCatch ()
[ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields) + "()")]
// Linker merges branches going forward.
[ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
public static void CatchInTry ()
{
try {
Expand All @@ -512,7 +512,7 @@ public static void CatchInTry ()

// Linker merges branches going forward.
[ExpectedWarning ("IL2072", nameof (RequireAll1) + "(Type)", nameof (GetWithPublicMethods) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
public static void CatchInTryWithFinally ()
{
Type t = GetWithPublicConstructors ();
Expand Down Expand Up @@ -542,7 +542,7 @@ public static void CatchInTryWithFinally ()

// Linker merges branches going forward.
[ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicFields) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
public static void TestCatchesHaveSeparateState ()
{
Type t = GetWithPublicMethods ();
Expand Down Expand Up @@ -713,7 +713,7 @@ public static void FinallyInTryWithPredecessor ()

// Linker merges branches going forward.
[ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicFields) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
public static void NestedFinally ()
{
Type t = GetWithPublicMethods ();
Expand Down Expand Up @@ -743,7 +743,7 @@ public static void NestedFinally ()

// Linker merges branches going forward.
[ExpectedWarning ("IL2072", nameof (RequireAll3) + "(Type)", nameof (GetWithPublicFields) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
public static void NestedFinallyWithPredecessor ()
{
Type t = GetWithPublicMethods ();
Expand Down Expand Up @@ -784,7 +784,7 @@ public static void ExceptionFilter ()

// Linker merges branches going forward.
[ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
public static void ExceptionFilterStateChange ()
{
Type t = GetWithPublicMethods ();
Expand Down Expand Up @@ -823,11 +823,11 @@ public static void ExceptionFilterStateChange ()

// Linker merges branches going forward.
[ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
[ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicMethods) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
[ExpectedWarning ("IL2072", nameof (RequireAll2) + "(Type)", nameof (GetWithPublicFields) + "()",
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
public static void ExceptionMultipleFilters ()
{
Type t = GetWithPublicMethods ();
Expand Down Expand Up @@ -859,7 +859,7 @@ public static void ExceptionMultipleFilters ()

// Linker merges branches going forward.
[ExpectedWarning ("IL2072", nameof (RequireAll) + "(Type)", nameof (GetWithPublicMethods),
ProducedBy = ProducedBy.Trimmer)]
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
public static void ExceptionFilterWithBranch ()
{
Type t = GetWithPublicMethods ();
Expand Down Expand Up @@ -989,4 +989,4 @@ public static void RequireAll7 (
{
}
}
}
}
6 changes: 3 additions & 3 deletions test/Mono.Linker.Tests.Cases/DataFlow/FieldDataFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,23 +202,23 @@ class AccessReturnedInstanceField
static AccessReturnedInstanceField GetInstance ([DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.All)] Type unused) => null;

[ExpectedWarning ("IL2072", nameof (GetUnknownType), nameof (GetInstance),
ProducedBy = ProducedBy.Trimmer)] // https://github.com/dotnet/linker/issues/2832
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)] // https://github.com/dotnet/linker/issues/2832
[ExpectedWarning ("IL2077", nameof (field), nameof (DataFlowTypeExtensions.RequiresAll))]
static void TestRead ()
{
GetInstance (GetUnknownType ()).field.RequiresAll ();
}

[ExpectedWarning ("IL2072", nameof (GetUnknownType), nameof (GetInstance),
ProducedBy = ProducedBy.Trimmer)] // https://github.com/dotnet/linker/issues/2832
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)] // https://github.com/dotnet/linker/issues/2832
[ExpectedWarning ("IL2074", nameof (GetUnknownType), nameof (field))]
static void TestWrite ()
{
GetInstance (GetUnknownType ()).field = GetUnknownType ();
}

[ExpectedWarning ("IL2072", nameof (GetUnknownType), nameof (GetInstance),
ProducedBy = ProducedBy.Trimmer)] // https://github.com/dotnet/linker/issues/2832
ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)] // https://github.com/dotnet/linker/issues/2832
[ExpectedWarning ("IL2074", nameof (GetUnknownType), nameof (field))]
static void TestNullCoalescingAssignment ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static void Main ()

// Correct behavior in the linker, but needs to be added in analyzer
// Bug link: https://github.com/dotnet/linker/issues/2158
[ExpectedWarning ("IL2026", "Message for --TestType.Requires--", ProducedBy = ProducedBy.Trimmer)]
[ExpectedWarning ("IL2026", "Message for --TestType.Requires--", ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
static void AssignToAnnotatedTypeReference ()
{
ref Type typeShouldHaveAllMethods = ref ReturnAnnotatedTypeReferenceAsAnnotated ();
Expand All @@ -48,23 +48,23 @@ static void AssignToAnnotatedTypeReference ()

// Same as above for IL analysis, but this looks different to the Roslyn analyzer.
// https://github.com/dotnet/linker/issues/2158
[ExpectedWarning ("IL2026", "Message for --TestType.Requires--", ProducedBy = ProducedBy.Trimmer)]
[ExpectedWarning ("IL2026", "Message for --TestType.Requires--", ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
static void AssignDirectlyToAnnotatedTypeReference ()
{
ReturnAnnotatedTypeReferenceAsAnnotated () = typeof (TestTypeWithRequires);
_annotatedField.GetMethods ();
}

// https://github.com/dotnet/linker/issues/2158
[ExpectedWarning ("IL2073", nameof (GetWithPublicFields), ProducedBy = ProducedBy.Trimmer)]
[ExpectedWarning ("IL2073", nameof (GetWithPublicFields), ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
static void AssignToCapturedAnnotatedTypeReference ()
{
// In this testcase, the Roslyn analyzer sees an assignment to a flow-capture reference.
ReturnAnnotatedTypeReferenceAsAnnotated () = GetWithPublicMethods () ?? GetWithPublicFields ();
}

[ExpectedWarning ("IL2072", nameof (GetWithPublicMethods), nameof (ReturnAnnotatedTypeWithRequirements))]
[ExpectedWarning ("IL2073", nameof (ReturnAnnotatedTypeWithRequirements), nameof (GetWithPublicFields), ProducedBy = ProducedBy.Trimmer)]
[ExpectedWarning ("IL2073", nameof (ReturnAnnotatedTypeWithRequirements), nameof (GetWithPublicFields), ProducedBy = ProducedBy.Trimmer | ProducedBy.NativeAot)]
static void AssignToAnnotatedTypeReferenceWithRequirements ()
{
ReturnAnnotatedTypeWithRequirements (GetWithPublicMethods ()) = GetWithPublicFields ();
Expand Down
Loading