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
2 changes: 1 addition & 1 deletion src/tools/illink/src/linker/Linker.Steps/MarkStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3167,7 +3167,7 @@ void MarkMethodCollection(IList<MethodDefinition> methods, in DependencyInfo rea
var methodAction = Annotations.GetAction(method);
if (methodAction is MethodAction.ConvertToStub)
{
// CodeRewriterStep runs after sweeping, and may request the stubbed value for any preserved method
// CodeRewriterStep may request the stubbed value for any preserved method
// with the action ConvertToStub. Ensure we have precomputed any stub value that may be needed by
// CodeRewriterStep. This ensures sweeping doesn't change the stub value (which can be determined by
// FeatureGuardAttribute or FeatureSwitchDefinitionAttribute that might have been removed).
Expand Down
2 changes: 1 addition & 1 deletion src/tools/illink/src/linker/Linker/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1620,9 +1620,9 @@ static Pipeline GetStandardPipeline()
p.AppendStep(new ValidateVirtualMethodAnnotationsStep());
p.AppendStep(new ProcessWarningsStep());
p.AppendStep(new OutputWarningSuppressions());
Comment thread
sbomer marked this conversation as resolved.
p.AppendStep(new CodeRewriterStep());
p.AppendStep(new SweepStep());
p.AppendStep(new CheckSuppressionsDispatcher());
p.AppendStep(new CodeRewriterStep());
p.AppendStep(new CleanStep());
p.AppendStep(new RegenerateGuidStep());
p.AppendStep(new OutputStep());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ public Task NotWorthConvertingReturnTrue()
return RunTest(allowMissingWarnings: true);
}

[Fact]
public Task OnlyReferenceInUnreachableBody()
{
return RunTest(allowMissingWarnings: true);
}

[Fact]
public Task OverrideOfAbstractAndInterfaceMethodCalledFromLocal()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// 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.

namespace Mono.Linker.Tests.Cases.UnreachableBody.Dependencies;

public class OtherAssembly2
{
public static int Field;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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 Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
using Mono.Linker.Tests.Cases.UnreachableBody.Dependencies;

namespace Mono.Linker.Tests.Cases.UnreachableBody;

/// <summary>
/// This test was added to fix an issue with how SweepStep.SweepAssemblyReferences and CodeRewriterStep interact.
/// CodeRewriterStep must run before SweepStep to ensure that SweepStep.SweepAssemblyReferences doesn't see TypeReferences in method bodies that
/// are going to be removed by CodeRewriterStep.
/// </summary>
[SetupCompileBefore("other.dll", new[] { typeof(OtherAssembly2) })]
Comment thread
mrvoorhe marked this conversation as resolved.
[RemovedAssemblyReference("test", "other")]
[RemovedAssembly("other.dll")]
[SetupLinkerArgument("--enable-opt", "unreachablebodies")]
public class OnlyReferenceInUnreachableBody
{
public static void Main()
{
UsedToMarkMethod(null);
}

[Kept]
static void UsedToMarkMethod(Foo f)
{
f.Method();
}

[Kept]
class Foo
{
[Kept]
[ExpectBodyModified]
public void Method()
{
OtherAssembly2.Field = 1;
}
}
}
Loading