Skip to content

Commit 43fb979

Browse files
authored
Add a test for #2260 (#2263)
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).
1 parent 23f5f59 commit 43fb979

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
11+
namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses.NoKeptCtor.OverrideRemoval.Dependencies
12+
{
13+
public class OverrideOfAbstractIsKeptNonEmpty_UnusedType
14+
{
15+
}
16+
17+
public abstract class OverrideOfAbstractIsKeptNonEmpty_BaseType
18+
{
19+
public abstract void Method ();
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
11+
namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses.NoKeptCtor.OverrideRemoval.Dependencies
12+
{
13+
public class OverrideOfAbstractIsKeptNonEmptyLibraryWithNonEmpty :
14+
OverrideOfAbstractIsKeptNonEmpty_BaseType
15+
{
16+
Dependencies.OverrideOfAbstractIsKeptNonEmpty_UnusedType _field;
17+
18+
public override void Method ()
19+
{
20+
_field = null;
21+
}
22+
}
23+
}

test/Mono.Linker.Tests.Cases/Inheritance.AbstractClasses/NoKeptCtor/OverrideRemoval/OverrideOfAbstractIsKeptNonEmpty.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,34 @@
44
namespace Mono.Linker.Tests.Cases.Inheritance.AbstractClasses.NoKeptCtor.OverrideRemoval
55
{
66
[SetupLinkerArgument ("--enable-opt", "unreachablebodies")]
7+
8+
// The order is important - since the bug this uncovers depends on order of processing of assemblies in the sweep step
9+
[SetupCompileBefore ("library.dll", new[] { "Dependencies/OverrideOfAbstractIsKeptNonEmptyLibrary.cs" })]
10+
[SetupCompileBefore (
11+
"librarywithnonempty.dll",
12+
new[] { "Dependencies/OverrideOfAbstractIsKeptNonEmptyLibraryWithNonEmpty.cs" },
13+
new[] { "library.dll" })]
14+
15+
[KeptAssembly ("library.dll")]
16+
[KeptAssembly ("librarywithnonempty.dll")]
17+
18+
// Uncomment after this bug is fixed
19+
// https://github.com/mono/linker/issues/2260
20+
//[RemovedTypeInAssembly ("library.dll", typeof (Dependencies.OverrideOfAbstractIsKeptNonEmpty_UnusedType))]
21+
722
public class OverrideOfAbstractIsKeptNonEmpty
823
{
924
public static void Main ()
1025
{
1126
Base b = HelperToMarkFooAndRequireBase ();
1227
b.Method ();
28+
29+
Dependencies.OverrideOfAbstractIsKeptNonEmpty_BaseType c = HelperToMarkLibraryAndRequireItsBase ();
30+
c.Method ();
31+
32+
// Remove after this bug is fixed
33+
// https://github.com/mono/linker/issues/2260
34+
new Dependencies.OverrideOfAbstractIsKeptNonEmpty_UnusedType ();
1335
}
1436

1537
[Kept]
@@ -18,6 +40,12 @@ static Foo HelperToMarkFooAndRequireBase ()
1840
return null;
1941
}
2042

43+
[Kept]
44+
static Dependencies.OverrideOfAbstractIsKeptNonEmptyLibraryWithNonEmpty HelperToMarkLibraryAndRequireItsBase ()
45+
{
46+
return null;
47+
}
48+
2149
[Kept]
2250
abstract class Base
2351
{
@@ -41,11 +69,14 @@ abstract class Base3 : Base2
4169
[KeptBaseType (typeof (Base3))]
4270
class Foo : Base3
4371
{
72+
Dependencies.OverrideOfAbstractIsKeptNonEmpty_UnusedType _field;
73+
4474
[Kept]
4575
[ExpectBodyModified]
4676
public override void Method ()
4777
{
4878
Other ();
79+
_field = null;
4980
}
5081

5182
static void Other ()

0 commit comments

Comments
 (0)