Browse Source

Merge pull request #2959 from ElektroKill/fix/try-finally-with-fixed

pull/2971/head
Siegfried Pammer 2 years ago committed by GitHub
parent
commit
66e02e3ee3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      ICSharpCode.Decompiler/IL/Transforms/ReduceNestingTransform.cs

23
ICSharpCode.Decompiler/IL/Transforms/ReduceNestingTransform.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
// Copyright (c) 2018 Siegfried Pammer
// Copyright (c) 2018 Siegfried Pammer
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
@ -637,10 +637,25 @@ namespace ICSharpCode.Decompiler.IL @@ -637,10 +637,25 @@ namespace ICSharpCode.Decompiler.IL
// Finally is empty and redundant. But we'll delete the block only if there's a PinnedRegion.
if (!(tryFinally.TryBlock is BlockContainer tryContainer))
return;
if (tryContainer.SingleInstruction() is PinnedRegion pinnedRegion)
if (tryContainer.Blocks.Count != 1)
return;
var tryBlock = tryContainer.Blocks[0];
if (tryBlock.Instructions.Count == 1)
{
context.Step("Removing try-finally around PinnedRegion", pinnedRegion);
tryFinally.ReplaceWith(pinnedRegion);
if (tryBlock.Instructions[0] is PinnedRegion pinnedRegion)
{
context.Step("Removing try-finally around PinnedRegion", pinnedRegion);
tryFinally.ReplaceWith(pinnedRegion);
}
}
else if (tryBlock.Instructions.Count == 2)
{
if (tryBlock.Instructions[0] is PinnedRegion pinnedRegion &&
tryBlock.Instructions[1].MatchLeave(tryContainer))
{
context.Step("Removing try-finally around PinnedRegion", pinnedRegion);
tryFinally.ReplaceWith(pinnedRegion);
}
}
}
}

Loading…
Cancel
Save