Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackson Schuster <36744439+jtschuster@users.noreply.github.com>2022-11-02 18:37:46 +0300
committerGitHub <noreply@github.com>2022-11-02 18:37:46 +0300
commit391ac60bbfb2c618b82f08af728d2d4d259d584e (patch)
tree94147f3fec3c7d8a0ef09fb0a07cc137ce632d3e
parente502e7255030dde029e984e397924338485d1079 (diff)
Don't mark override of abstract base if the override's declaring type is not marked (#3098)
* Don't mark an override every time the base is abstract, only if the declaring type is also marked Adds a condition to ShouldMarkOverrideForBase to exit early if the declaring type of the method is not marked.
-rw-r--r--src/linker/Linker.Steps/MarkStep.cs2
-rw-r--r--test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/Inheritance.VirtualMethodsTests.g.cs6
-rw-r--r--test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/OverrideOfAbstractInUnmarkedClassIsRemoved.cs97
3 files changed, 105 insertions, 0 deletions
diff --git a/src/linker/Linker.Steps/MarkStep.cs b/src/linker/Linker.Steps/MarkStep.cs
index 646e2e6bd..67a3c42b3 100644
--- a/src/linker/Linker.Steps/MarkStep.cs
+++ b/src/linker/Linker.Steps/MarkStep.cs
@@ -715,6 +715,8 @@ namespace Mono.Linker.Steps
// TODO: Move interface method marking logic here https://github.com/dotnet/linker/issues/3090
bool ShouldMarkOverrideForBase (OverrideInformation overrideInformation)
{
+ if (!Annotations.IsMarked (overrideInformation.Override.DeclaringType))
+ return false;
if (overrideInformation.IsOverrideOfInterfaceMember) {
_interfaceOverrides.Add ((overrideInformation, ScopeStack.CurrentScope));
return false;
diff --git a/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/Inheritance.VirtualMethodsTests.g.cs b/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/Inheritance.VirtualMethodsTests.g.cs
index a7cadcdb3..5ddfcf4f3 100644
--- a/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/Inheritance.VirtualMethodsTests.g.cs
+++ b/test/ILLink.RoslynAnalyzer.Tests/generated/ILLink.RoslynAnalyzer.Tests.Generator/ILLink.RoslynAnalyzer.Tests.TestCaseGenerator/Inheritance.VirtualMethodsTests.g.cs
@@ -28,6 +28,12 @@ namespace ILLink.RoslynAnalyzer.Tests.Inheritance
}
[Fact]
+ public Task OverrideInUnmarkedClassIsRemoved ()
+ {
+ return RunTest (allowMissingWarnings: true);
+ }
+
+ [Fact]
public Task UnusedTypeWithOverrideOfVirtualMethodIsRemoved ()
{
return RunTest (allowMissingWarnings: true);
diff --git a/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/OverrideOfAbstractInUnmarkedClassIsRemoved.cs b/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/OverrideOfAbstractInUnmarkedClassIsRemoved.cs
new file mode 100644
index 000000000..366fd6a3f
--- /dev/null
+++ b/test/Mono.Linker.Tests.Cases/Inheritance.VirtualMethods/OverrideOfAbstractInUnmarkedClassIsRemoved.cs
@@ -0,0 +1,97 @@
+// 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.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Mono.Linker.Tests.Cases.Expectations.Assertions;
+using Mono.Linker.Tests.Cases.Expectations.Metadata;
+
+namespace Mono.Linker.Tests.Cases.Inheritance.VirtualMethods
+{
+ public class OverrideOfAbstractInUnmarkedClassIsRemoved
+ {
+ [Kept]
+ public static void Main ()
+ {
+ MarkedBase x = new MarkedDerived ();
+ x.Method ();
+
+ UsedSecondLevelTypeWithAbstractBase y = new ();
+ y.Method ();
+
+ UsedSecondLevelType z = new ();
+ z.Method ();
+ }
+
+ [Kept]
+ [KeptMember (".ctor()")]
+ abstract class MarkedBase
+ {
+ [Kept]
+ public abstract int Method ();
+ }
+
+ [Kept]
+ [KeptMember (".ctor()")]
+ [KeptBaseType (typeof (MarkedBase))]
+ class MarkedDerived : MarkedBase
+ {
+ [Kept]
+ public override int Method () => 1;
+ }
+
+ class UnmarkedDerived : MarkedBase
+ {
+ public override int Method () => 1;
+ }
+
+ [Kept]
+ [KeptMember (".ctor()")]
+ [KeptBaseType (typeof (MarkedBase))]
+ class UnusedIntermediateType : MarkedBase
+ {
+ [Kept]
+ public override int Method () => 1;
+ }
+
+ [Kept]
+ [KeptMember (".ctor()")]
+ [KeptBaseType (typeof (UnusedIntermediateType))]
+ class UsedSecondLevelType : UnusedIntermediateType
+ {
+ [Kept]
+ public override int Method () => 1;
+ }
+
+ [Kept]
+ [KeptMember (".ctor()")]
+ [KeptBaseType (typeof (MarkedBase))]
+ abstract class UnusedIntermediateTypeWithAbstractOverride : MarkedBase
+ {
+ [Kept]
+ public abstract override int Method ();
+ }
+
+ [Kept]
+ [KeptMember (".ctor()")]
+ [KeptBaseType (typeof (UnusedIntermediateTypeWithAbstractOverride))]
+ class UsedSecondLevelTypeWithAbstractBase : UnusedIntermediateTypeWithAbstractOverride
+ {
+ [Kept]
+ public override int Method () => 1;
+ }
+
+ class UnusedSecondLevelTypeWithAbstractBase : UnusedIntermediateTypeWithAbstractOverride
+ {
+ public override int Method () => 1;
+ }
+
+ class UnusedSecondLevelType : UnusedIntermediateType
+ {
+ public override int Method () => 1;
+ }
+ }
+}