Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
1,427 changes: 877 additions & 550 deletions src/linker/Linker.Steps/UnreachableBlocksOptimizer.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,35 @@ namespace Mono.Linker.Tests.Cases.FeatureSettings
[SetupLinkerArgument ("--enable-opt", "ipconstprop")]
public class FeatureSubstitutions
{
[Kept]
static bool IsOptionalFeatureEnabled {
[Kept]
[ExpectedInstructionSequence (new[] {
"ldc.i4.0",
"ret",
})]
get;
}

[ExpectedInstructionSequence (new[] {
"nop",
"call System.Void Mono.Linker.Tests.Cases.FeatureSettings.FeatureSubstitutions::TestOptionalFeature()",
"nop",
"ldc.i4.1",
"pop",
"ret",
})]
public static void Main ()
{
TestOptionalFeature ();
_ = IsDefaultFeatureEnabled;
}

[Kept]
[ExpectBodyModified]
[ExpectedInstructionSequence (new[] {
"call",
"brfalse",
"call",
"nop",
"ldc.i4.0",
"stloc.0",
"ldloc.0",
"brfalse.s il_6",
"nop",
"call System.Void Mono.Linker.Tests.Cases.FeatureSettings.FeatureSubstitutions::UseFallback()",
"nop",
"nop",
"ret",
})]
static void TestOptionalFeature ()
Expand All @@ -51,13 +58,7 @@ static void UseFallback ()
{
}

[Kept]
static bool IsDefaultFeatureEnabled {
[Kept]
[ExpectedInstructionSequence (new[] {
"ldc.i4.1",
"ret",
})]
get => throw new NotImplementedException ();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ namespace Mono.Linker.Tests.Cases.FeatureSettings
[KeptResource ("ResourceFileRemoveWhenFalse.txt")]
public class FeatureSubstitutionsNested
{
[ExpectedInstructionSequence (new[] {
"nop",
"ldc.i4.1",
"pop",
"ldc.i4.0",
"pop",
"ldc.i4.1",
"pop",
"ldc.i4.0",
"pop",
"ldsfld System.Boolean Mono.Linker.Tests.Cases.FeatureSettings.FeatureSubstitutionsNested::FieldConditionField",
"pop",
"ret",
})]
public static void Main ()
{
GlobalConditionMethod ();
Expand All @@ -28,41 +42,21 @@ public static void Main ()
_ = FieldConditionField;
}

[Kept]
[ExpectedInstructionSequence (new[] {
"ldc.i4.1",
"ret",
})]
static bool GlobalConditionMethod ()
{
throw new NotImplementedException ();
}

[Kept]
[ExpectedInstructionSequence (new[] {
"ldc.i4.0",
"ret",
})]
static bool AssemblyConditionMethod ()
{
throw new NotImplementedException ();
}

[Kept]
[ExpectedInstructionSequence (new[] {
"ldc.i4.1",
"ret",
})]
static bool TypeConditionMethod ()
{
throw new NotImplementedException ();
}

[Kept]
[ExpectedInstructionSequence (new[] {
"ldc.i4.0",
"ret",
})]
static bool MethodConditionMethod ()
{
throw new NotImplementedException ();
Expand Down
3 changes: 1 addition & 2 deletions test/Mono.Linker.Tests.Cases/Libraries/RootLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ public void NotUsed ()
[Kept]
public class SubstitutionsTest
{
[Kept]
private static bool FalseProp { [Kept] get { return false; } }
private static bool FalseProp { get { return false; } }

[Kept]
[ExpectBodyModified]
Expand Down
88 changes: 36 additions & 52 deletions test/Mono.Linker.Tests.Cases/Substitutions/StubBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,42 @@ namespace Mono.Linker.Tests.Cases.Substitutions
[SetupLinkerSubstitutionFile ("StubBody.xml")]
public class StubBody
{
[ExpectedInstructionSequence (new[] {
"nop",
"newobj System.Void Mono.Linker.Tests.Cases.Substitutions.StubBody::.ctor()",
"pop",
"ldc.i4.5",
"newobj System.Void Mono.Linker.Tests.Cases.Substitutions.StubBody/NestedType::.ctor(System.Int32)",
"pop",
"ldnull",
"pop",
"ldc.i4.0",
"pop",
"ldc.i4.0",
"pop",
"call System.Decimal Mono.Linker.Tests.Cases.Substitutions.StubBody::TestMethod_4()",
"pop",
"ldc.i4.0",
"pop",
"call System.Void Mono.Linker.Tests.Cases.Substitutions.StubBody::TestMethod_6()",
"nop",
"ldc.r8 0",
"pop",
"ldc.i4.5",
"call T Mono.Linker.Tests.Cases.Substitutions.StubBody::TestMethod_8<System.Int32>(T)",
"pop",
"ldc.r4 0",
"pop",
"ldc.i8 0x0",
"pop",
"ldnull",
"pop",
"ldnull",
"pop",
"ldnull",
"pop",
"ret",
})]
public static void Main ()
{
new StubBody ();
Expand Down Expand Up @@ -50,31 +86,16 @@ public StubBody ()
throw new NotImplementedException ();
}

[Kept]
[ExpectedInstructionSequence (new[] {
"ldnull",
"ret",
})]
static string TestMethod_1 ()
{
throw new NotImplementedException ();
}

[Kept]
[ExpectedInstructionSequence (new[] {
"ldc.i4.0",
"ret",
})]
static byte TestMethod_2 ()
{
throw new NotImplementedException ();
}

[Kept]
[ExpectedInstructionSequence (new[] {
"ldc.i4.0",
"ret",
})]
static char TestMethod_3 ()
{
throw new NotImplementedException ();
Expand All @@ -93,11 +114,6 @@ static decimal TestMethod_4 ()
throw new NotImplementedException ();
}

[Kept]
[ExpectedInstructionSequence (new[] {
"ldc.i4.0",
"ret",
})]
static bool TestMethod_5 ()
{
throw new NotImplementedException ();
Expand All @@ -112,12 +128,6 @@ static void TestMethod_6 ()
TestMethod_5 ();
}

[Kept]
[ExpectedInstructionSequence (new[] {
"ldc.r8 0",
"ret",
})]
[ExpectLocalsModified]
static double TestMethod_7 ()
{
double d = 1.1;
Expand All @@ -137,53 +147,27 @@ static T TestMethod_8<T> (T t)
throw new NotImplementedException ();
}

[Kept]
[ExpectedInstructionSequence (new[] {
"ldc.r4 0",
"ret",
})]
[ExpectLocalsModified]
static float TestMethod_9 ()
{
float f = 1.1f;
return f;
}

[Kept]
[ExpectedInstructionSequence (new[] {
"ldc.i8 0x0",
"ret",
})]
static ulong TestMethod_10 ()
{
throw new NotImplementedException ();
}

[Kept]
[ExpectedInstructionSequence (new[] {
"ldnull",
"ret",
})]
static long[] TestMethod_11 ()
{
throw new NotImplementedException ();
}

[Kept]
[ExpectedInstructionSequence (new[] {
"ldnull",
"ret",
})]
static object TestMethod_12 ()
{
throw new NotImplementedException ();
}

[Kept]
[ExpectedInstructionSequence (new[] {
"ldnull",
"ret",
})]
static System.Collections.Generic.List<int> TestMethod_13 ()
{
throw new NotImplementedException ();
Expand Down
13 changes: 13 additions & 0 deletions test/Mono.Linker.Tests.Cases/Substitutions/StubBodyWithValue.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.CompilerServices;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;

Expand Down Expand Up @@ -28,6 +29,7 @@ public static void Main ()
"ldstr 'abcd'",
"ret",
})]
[MethodImplAttribute (MethodImplOptions.NoInlining)]
static string TestMethod_1 ()
{
throw new NotImplementedException ();
Expand All @@ -38,6 +40,7 @@ static string TestMethod_1 ()
"ldc.i4 0x4",
"ret",
})]
[MethodImplAttribute (MethodImplOptions.NoInlining)]
static byte TestMethod_2 ()
{
throw new NotImplementedException ();
Expand All @@ -48,6 +51,7 @@ static byte TestMethod_2 ()
"ldc.i4 0x78",
"ret",
})]
[MethodImplAttribute (MethodImplOptions.NoInlining)]
static char TestMethod_3 ()
{
throw new NotImplementedException ();
Expand All @@ -58,6 +62,7 @@ static char TestMethod_3 ()
"ldc.i4 0x3",
"ret"
})]
[MethodImplAttribute (MethodImplOptions.NoInlining)]
static sbyte TestMethod_4 ()
{
throw new NotImplementedException ();
Expand All @@ -68,6 +73,7 @@ static sbyte TestMethod_4 ()
"ldc.i4.1",
"ret",
})]
[MethodImplAttribute (MethodImplOptions.NoInlining)]
static bool TestMethod_5 ()
{
throw new NotImplementedException ();
Expand All @@ -78,6 +84,7 @@ static bool TestMethod_5 ()
"ldc.i4.1",
"ret",
})]
[MethodImplAttribute (MethodImplOptions.NoInlining)]
static bool TestMethod_6 ()
{
throw new NotImplementedException ();
Expand All @@ -88,6 +95,7 @@ static bool TestMethod_6 ()
"ldc.r8 2.5",
"ret",
})]
[MethodImplAttribute (MethodImplOptions.NoInlining)]
static double TestMethod_7 ()
{
throw new NotImplementedException ();
Expand All @@ -98,6 +106,7 @@ static double TestMethod_7 ()
"ldc.i4 0xfffffffd",
"ret"
})]
[MethodImplAttribute (MethodImplOptions.NoInlining)]
static int TestMethod_8 ()
{
throw new NotImplementedException ();
Expand All @@ -108,6 +117,7 @@ static int TestMethod_8 ()
"ldc.r4 6",
"ret",
})]
[MethodImplAttribute (MethodImplOptions.NoInlining)]
static float TestMethod_9 ()
{
throw new NotImplementedException ();
Expand All @@ -118,6 +128,7 @@ static float TestMethod_9 ()
"ldc.i8 0x1e240",
"ret",
})]
[MethodImplAttribute (MethodImplOptions.NoInlining)]
static ulong TestMethod_10 ()
{
throw new NotImplementedException ();
Expand All @@ -128,6 +139,7 @@ static ulong TestMethod_10 ()
"ldc.i8 0xfffffffffffffc18",
"ret",
})]
[MethodImplAttribute (MethodImplOptions.NoInlining)]
static long TestMethod_11 ()
{
throw new NotImplementedException ();
Expand All @@ -138,6 +150,7 @@ static long TestMethod_11 ()
"ldc.i4 0xffffffff",
"ret",
})]
[MethodImplAttribute (MethodImplOptions.NoInlining)]
static uint TestMethod_12 ()
{
throw new NotImplementedException ();
Expand Down
Loading