Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.0] Process also exception filters when marking unreachable blocks #1513

Merged
merged 1 commit into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion external/cecil
Submodule cecil updated from 75fc41 to c600e6
2 changes: 2 additions & 0 deletions src/linker/Linker.Steps/RemoveUnreachableBlocksStep.cs
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
101 changes: 101 additions & 0 deletions test/Mono.Linker.Tests.Cases/UnreachableBlock/TryFilterBlocks.cs
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;
}
}