Skip to content

Commit

Permalink
Add support for MCS 2.6.4 pinned region with array variable
Browse files Browse the repository at this point in the history
  • Loading branch information
ElektroKill committed Nov 4, 2023
1 parent 95108c9 commit 684a863
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions ICSharpCode.Decompiler/IL/ControlFlow/DetectPinnedRegions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -614,14 +614,25 @@ bool CreatePinnedRegion(Block block, StLoc stLoc)
}
Branch br = innerBlock.Instructions.LastOrDefault() as Branch;
if (br != null && br.TargetBlock.IncomingEdgeCount == 1
&& br.TargetContainer == sourceContainer && reachedEdgesPerBlock[br.TargetBlock.ChildIndex] == 0)
&& br.TargetContainer == sourceContainer)
{
// branch that leaves body.
Block unpinBlock = null;
if (reachedEdgesPerBlock[br.TargetBlock.ChildIndex] == 0)
{
unpinBlock = br.TargetBlock;
}
else if (innerBlock.Instructions[0].MatchIfInstruction(out _, out var trueInstr) &&
trueInstr is Branch trueBr && trueBr.TargetContainer == sourceContainer &&
reachedEdgesPerBlock[trueBr.TargetBlock.ChildIndex] == 0)
{
unpinBlock = trueBr.TargetBlock;
}

// The target block should have an instruction that resets the pin; delete that instruction:
StLoc unpin = br.TargetBlock.Instructions.First() as StLoc;
StLoc unpin = unpinBlock?.Instructions.First() as StLoc;
if (unpin != null && unpin.Variable == stLoc.Variable && IsNullOrZero(unpin.Value))
{
br.TargetBlock.Instructions.RemoveAt(0);
unpinBlock.Instructions.RemoveAt(0);
}
}
// move block into body
Expand Down Expand Up @@ -750,6 +761,10 @@ void ProcessPinnedRegion(PinnedRegion pinnedRegion)
// fixing a string
HandleStringToPointer(pinnedRegion);
}
else if (pinnedRegion.Init is Conv { Kind: ConversionKind.StopGCTracking, Argument: LdElema ldElema })
{
pinnedRegion.Init = ldElema;
}
// Detect nested pinned regions:
BlockContainer body = (BlockContainer)pinnedRegion.Body;
foreach (var block in body.Blocks)
Expand Down

0 comments on commit 684a863

Please sign in to comment.