diff options
author | Marek Safar <marek.safar@gmail.com> | 2019-12-21 01:41:17 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2019-12-22 11:08:08 +0300 |
commit | 01b3a688d624f9e8f1db92ad5abbebc4b09cd1f5 (patch) | |
tree | 8d418c6026e7bb7cfa0892b2fe4e2056d01cd03c /test/Mono.Linker.Tests.Cases/UnreachableBlock/DeadVariables.cs | |
parent | 14eb4b2e4486e0761e313954579f4f4816514e36 (diff) |
Remove variables which were used in removed scopes only.
Diffstat (limited to 'test/Mono.Linker.Tests.Cases/UnreachableBlock/DeadVariables.cs')
-rw-r--r-- | test/Mono.Linker.Tests.Cases/UnreachableBlock/DeadVariables.cs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/test/Mono.Linker.Tests.Cases/UnreachableBlock/DeadVariables.cs b/test/Mono.Linker.Tests.Cases/UnreachableBlock/DeadVariables.cs new file mode 100644 index 000000000..58c960936 --- /dev/null +++ b/test/Mono.Linker.Tests.Cases/UnreachableBlock/DeadVariables.cs @@ -0,0 +1,75 @@ +using System; +using Mono.Linker.Tests.Cases.Expectations.Assertions; +using Mono.Linker.Tests.Cases.Expectations.Metadata; + +namespace Mono.Linker.Tests.Cases.UnreachableBlock +{ + [SetupCSharpCompilerToUse ("csc")] + [SetupCompileArgument ("/optimize+")] + public class DeadVariables + { + public static void Main () + { + Test_1 (); + Test_2 (4); + Test_3 (); + } + + [Kept] + [ExpectBodyModified] + [ExpectedLocalsSequence (new string [0])] + static void Test_1 () + { + if (!AlwaysTrue) { + int var = 1; + Console.WriteLine (var); + } + } + + [Kept] + [ExpectBodyModified] + [ExpectedLocalsSequence (new string [] { "System.Object", "System.Int32" })] + static int Test_2 (int arg) + { + if (!AlwaysTrue) { + long var = 3; + Console.WriteLine (var++); + return (int) var; + } + + { + int b = arg; + Console.WriteLine (b++); + return b; + } + } + + [Kept] + [ExpectBodyModified] + [ExpectedLocalsSequence (new string [] { "System.Int32", "System.DateTime", "System.DateTimeOffset", "System.DateTimeOffset" })] + static int Test_3 () + { + var b = 3; + var c = new DateTime (); + var d = new DateTimeOffset (); + var e = new DateTimeOffset (); + + if (!AlwaysTrue) { + int a = b; + ref int var = ref a; + } + + Console.WriteLine (b.ToString (), c, d, e); + + return 2; + } + + [Kept] + static bool AlwaysTrue { + [Kept] + get { + return true; + } + } + } +}
\ No newline at end of file |