-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consider side effects when evaluating manually substituted methods
Fixes #2759
- Loading branch information
1 parent
3226921
commit 4d85c9d
Showing
4 changed files
with
179 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
test/Mono.Linker.Tests.Cases/Substitutions/StubBodyWithStaticCtor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
using Mono.Linker.Tests.Cases.Expectations.Assertions; | ||
using Mono.Linker.Tests.Cases.Expectations.Metadata; | ||
|
||
namespace Mono.Linker.Tests.Cases.Substitutions | ||
{ | ||
[SetupLinkerSubstitutionFile ("StubBodyWithStaticCtor.xml")] | ||
[SetupCompileArgument ("/optimize+")] | ||
[SetupLinkerArgument ("--enable-opt", "ipconstprop")] | ||
public class StubBodyWithStaticCtor | ||
{ | ||
public static void Main () | ||
{ | ||
TestMethod_1 (); | ||
TestMethod_2 (); | ||
TestMethod_3 (); | ||
} | ||
|
||
[Kept] | ||
[ExpectedInstructionSequence (new[] { | ||
"call System.Int32 Mono.Linker.Tests.Cases.Substitutions.StubBodyWithStaticCtorImpl::TestMethod()", | ||
"ldc.i4.2", | ||
"beq.s il_8", | ||
"ldc.i4.3", | ||
"ret", | ||
})] | ||
static int TestMethod_1 () | ||
{ | ||
if (StubBodyWithStaticCtorImpl.TestMethod () != 2) { | ||
Console.WriteLine (); | ||
return 1; | ||
} | ||
|
||
return 3; | ||
} | ||
|
||
[Kept] | ||
[ExpectedInstructionSequence (new[] { | ||
"call System.Int32 Mono.Linker.Tests.Cases.Substitutions.IntermediateClass::GetValue()", | ||
"ldc.i4.2", | ||
"beq.s il_8", | ||
"ldc.i4.3", | ||
"ret", | ||
})] | ||
static int TestMethod_2 () | ||
{ | ||
if (IntermediateClass.GetValue () != 2) { | ||
Console.WriteLine (); | ||
return 1; | ||
} | ||
|
||
return 3; | ||
} | ||
|
||
[Kept] | ||
[ExpectedInstructionSequence (new[] { | ||
"call System.Boolean Mono.Linker.Tests.Cases.Substitutions.WrappingClass::GetValue()", | ||
"brfalse.s il_7", | ||
"ldc.i4.3", | ||
"ret", | ||
})] | ||
static int TestMethod_3 () | ||
{ | ||
if (WrappingClass.GetValue ()) { | ||
Console.WriteLine (); | ||
return 1; | ||
} | ||
|
||
return 3; | ||
} | ||
} | ||
|
||
[Kept] | ||
class WrappingClass | ||
{ | ||
[Kept] | ||
public static bool GetValue () | ||
{ | ||
return Settings.TestValue (); | ||
} | ||
|
||
static class Settings | ||
{ | ||
[Kept] | ||
static Settings () | ||
{ | ||
Console.WriteLine (); | ||
} | ||
|
||
[Kept] | ||
[ExpectedInstructionSequence (new[] { | ||
"ldc.i4.0", | ||
"ret", | ||
})] | ||
public static bool TestValue () | ||
{ | ||
throw new NotImplementedException (); | ||
} | ||
} | ||
} | ||
|
||
[Kept] | ||
class StubBodyWithStaticCtorImpl | ||
{ | ||
[Kept] | ||
public static int count; | ||
|
||
[Kept] | ||
static StubBodyWithStaticCtorImpl () | ||
{ | ||
count = 100; | ||
} | ||
|
||
[Kept] | ||
[ExpectedInstructionSequence (new[] { | ||
"ldc.i4 0x2", | ||
"ret", | ||
})] | ||
public static int TestMethod () | ||
{ | ||
++count; | ||
return Environment.ExitCode; | ||
} | ||
} | ||
|
||
[Kept] | ||
class IntermediateClass | ||
{ | ||
[Kept] | ||
public static int GetValue () | ||
{ | ||
return StubBodyWithStaticCtorImpl.TestMethod (); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
test/Mono.Linker.Tests.Cases/Substitutions/StubBodyWithStaticCtor.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<linker> | ||
<assembly fullname="test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> | ||
<type fullname="Mono.Linker.Tests.Cases.Substitutions.StubBodyWithStaticCtorImpl"> | ||
<method signature="System.Int32 TestMethod()" body="stub" value="2"> | ||
</method> | ||
</type> | ||
<type fullname="Mono.Linker.Tests.Cases.Substitutions.WrappingClass/Settings"> | ||
<method signature="System.Boolean TestValue()" body="stub" value="false"> | ||
</method> | ||
</type> | ||
</assembly> | ||
</linker> |