diff options
author | Sven Boemer <sbomer@gmail.com> | 2022-08-12 20:09:01 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-12 20:09:01 +0300 |
commit | d559347987ba45c0dc3389cb96dce1ae20204513 (patch) | |
tree | 9fd6b098611a5ac0ef3a2e5a74fdfda8b7948211 /test | |
parent | 95ea1842abc8634d1e98d995577c4202ad3fc5c5 (diff) |
Fix il corruption (#2966)
This prevents invalid IL in situations where removing the last
instruction of a method would result in the last instruction
being a conditional branch. There needs to be some IL in the
not-taken branch for the IL to be valid, so this fixes the issue
by injecting "ldnull; throw" at the end.
Co-authored-by: vitek-karas <10670590+vitek-karas@users.noreply.github.com>
Co-authored-by: Adam Sitnik <adam.sitnik@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/Mono.Linker.Tests.Cases/UnreachableBlock/ReplacedJumpTarget.cs | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/test/Mono.Linker.Tests.Cases/UnreachableBlock/ReplacedJumpTarget.cs b/test/Mono.Linker.Tests.Cases/UnreachableBlock/ReplacedJumpTarget.cs index 5c7ee375f..90d9a3e7e 100644 --- a/test/Mono.Linker.Tests.Cases/UnreachableBlock/ReplacedJumpTarget.cs +++ b/test/Mono.Linker.Tests.Cases/UnreachableBlock/ReplacedJumpTarget.cs @@ -1,5 +1,4 @@ using System; -using System.Reflection.Emit; using Mono.Linker.Tests.Cases.Expectations.Assertions; using Mono.Linker.Tests.Cases.Expectations.Metadata; @@ -12,6 +11,7 @@ namespace Mono.Linker.Tests.Cases.UnreachableBlock public static void Main () { Test_1 (int.Parse ("91")); + TestRemovedLastBranch (int.Parse ("92")); } [Kept] @@ -73,5 +73,36 @@ namespace Mono.Linker.Tests.Cases.UnreachableBlock } static int Value => 2; + + [Kept] + [ExpectedInstructionSequence (new[] { + "br.s il_3", + "ret", + "ldc.i4.1", + "brtrue.s il_2", + "ldnull", + "throw" + })] + static void TestRemovedLastBranch (int param) + { + goto DoWork; + + ReturnFromMethod: + return; + + DoWork: + if (AlwaysTrue) { + goto ReturnFromMethod; + } else { // This branch will be removed + DoSomething (); + goto ReturnFromMethod; + } + } + + static void DoSomething () + { + } + + static bool AlwaysTrue => true; } }
\ No newline at end of file |