Skip to content

Commit

Permalink
Process also exception filters when marking unreachable blocks
Browse files Browse the repository at this point in the history
Fixes dotnet/linker#1507


Commit migrated from dotnet/linker@337f0c5
  • Loading branch information
marek-safar committed Sep 28, 2020
1 parent f96e791 commit 278e1e4
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ BitArray GetReachableInstructionsMap (out List<ExceptionHandler> unreachableHand
condBranches = new Stack<int> ();

condBranches.Push (GetInstructionIndex (handler.HandlerStart));
if (handler.FilterStart != null)
condBranches.Push (GetInstructionIndex (handler.FilterStart));
}

if (condBranches?.Count > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;

namespace Mono.Linker.Tests.Cases.UnreachableBlock
{
[SetupCSharpCompilerToUse ("csc")]
[SetupCompileArgument ("/optimize+")]
[SetupLinkerArgument ("--enable-opt", "ipconstprop")]
public class TryFilterBlocks
{
public static void Main ()
{
TestUnreachableInsideTry ();
TestUnreachableInsideFilterCondition ();
}

[Kept]
[ExpectedInstructionSequence (new[] {
"call",
"brfalse.s",
"call",
"leave.s",
"pop",
"call",
"ldc.i4.0",
"cgt.un",
"endfilter",
"pop",
"leave.s",
"ldc.i4.2",
"ret"
})]
[ExpectedExceptionHandlerSequence (new string[] { "filter" })]
static int TestUnreachableInsideTry ()
{
try {
if (Prop)
Unreached_1 ();

Reached_1 ();
} catch when (Log ()) {
}

return 2;
}

[Kept]
[ExpectedInstructionSequence (new[] {
"call",
"leave.s",
"pop",
"call",
"brfalse.s",
"ldc.i4.0",
"ldc.i4.0",
"cgt.un",
"endfilter",
"pop",
"leave.s",
"ldc.i4.3",
"ret"
})]
[ExpectedExceptionHandlerSequence (new string[] { "filter" })]
static int TestUnreachableInsideFilterCondition ()
{
try {
Reached_2 ();
} catch when (Log () && Unreached_2 ()) {
}

return 3;
}

[Kept]
static bool Prop {
[Kept]
get {
return false;
}
}

[Kept]
static bool Log () => false;

[Kept]
static void Reached_1 ()
{
}

[Kept]
static void Reached_2 ()
{
}

static void Unreached_1 ()
{
}

static bool Unreached_2 () => true;
}
}

0 comments on commit 278e1e4

Please sign in to comment.