Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
This uncovers a null ref in sweepstep.
The test is order dependent:
- Assembly (librarywithnonemtpy) has a virtual method which referes to type from second library (library). This processes the type reference.
- The type is removed from library
- The virtual method is re-processed again -> hits a type def which does not belong to any assembly/scope

For this to happen the virtual method must be processed after the type has been removed.
This also requires the method to be meant for removal later on (the body will be rewritten to throw), since otherwise the type would have been marked.
This also requires the library with the removed type to be kept (so something else in it must be kept).

Commit migrated from dotnet/linker@43fb979
  • Loading branch information
vitek-karas authored Sep 8, 2021
1 parent 2ac715b commit 6d67275
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses.NoKeptCtor.OverrideRemoval.Dependencies
{
public class OverrideOfAbstractIsKeptNonEmpty_UnusedType
{
}

public abstract class OverrideOfAbstractIsKeptNonEmpty_BaseType
{
public abstract void Method ();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses.NoKeptCtor.OverrideRemoval.Dependencies
{
public class OverrideOfAbstractIsKeptNonEmptyLibraryWithNonEmpty :
OverrideOfAbstractIsKeptNonEmpty_BaseType
{
Dependencies.OverrideOfAbstractIsKeptNonEmpty_UnusedType _field;

public override void Method ()
{
_field = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,34 @@
namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses.NoKeptCtor.OverrideRemoval
{
[SetupLinkerArgument ("--enable-opt", "unreachablebodies")]

// The order is important - since the bug this uncovers depends on order of processing of assemblies in the sweep step
[SetupCompileBefore ("library.dll", new[] { "Dependencies/OverrideOfAbstractIsKeptNonEmptyLibrary.cs" })]
[SetupCompileBefore (
"librarywithnonempty.dll",
new[] { "Dependencies/OverrideOfAbstractIsKeptNonEmptyLibraryWithNonEmpty.cs" },
new[] { "library.dll" })]

[KeptAssembly ("library.dll")]
[KeptAssembly ("librarywithnonempty.dll")]

// Uncomment after this bug is fixed
// https://github.com/mono/linker/issues/2260
//[RemovedTypeInAssembly ("library.dll", typeof (Dependencies.OverrideOfAbstractIsKeptNonEmpty_UnusedType))]

public class OverrideOfAbstractIsKeptNonEmpty
{
public static void Main ()
{
Base b = HelperToMarkFooAndRequireBase ();
b.Method ();

Dependencies.OverrideOfAbstractIsKeptNonEmpty_BaseType c = HelperToMarkLibraryAndRequireItsBase ();
c.Method ();

// Remove after this bug is fixed
// https://github.com/mono/linker/issues/2260
new Dependencies.OverrideOfAbstractIsKeptNonEmpty_UnusedType ();
}

[Kept]
Expand All @@ -18,6 +40,12 @@ static Foo HelperToMarkFooAndRequireBase ()
return null;
}

[Kept]
static Dependencies.OverrideOfAbstractIsKeptNonEmptyLibraryWithNonEmpty HelperToMarkLibraryAndRequireItsBase ()
{
return null;
}

[Kept]
abstract class Base
{
Expand All @@ -41,11 +69,14 @@ abstract class Base3 : Base2
[KeptBaseType (typeof (Base3))]
class Foo : Base3
{
Dependencies.OverrideOfAbstractIsKeptNonEmpty_UnusedType _field;

[Kept]
[ExpectBodyModified]
public override void Method ()
{
Other ();
_field = null;
}

static void Other ()
Expand Down

0 comments on commit 6d67275

Please sign in to comment.