Browse Source

Merge pull request #1633 from icsharpcode/fix-1632

Fix #1632: await pattern might use negated IsCompleted check.
pull/1649/head
Daniel Grunwald 6 years ago committed by GitHub
parent
commit
fd56768820
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs

14
ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs

@ -730,15 +730,21 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow @@ -730,15 +730,21 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
// if (call get_IsCompleted(ldloca awaiterVar)) br completedBlock
if (!block.Instructions[block.Instructions.Count - 2].MatchIfInstruction(out var condition, out var trueInst))
return;
if (!MatchCall(condition, "get_IsCompleted", out var isCompletedArgs) || isCompletedArgs.Count != 1)
return;
if (!isCompletedArgs[0].MatchLdLocRef(awaiterVar))
return;
if (!trueInst.MatchBranch(out var completedBlock))
return;
// br awaitBlock
if (!block.Instructions.Last().MatchBranch(out var awaitBlock))
return;
// condition might be inverted, swap branches:
if (condition.MatchLogicNot(out var negatedCondition)) {
condition = negatedCondition;
ExtensionMethods.Swap(ref completedBlock, ref awaitBlock);
}
// continue matching call get_IsCompleted(ldloca awaiterVar)
if (!MatchCall(condition, "get_IsCompleted", out var isCompletedArgs) || isCompletedArgs.Count != 1)
return;
if (!isCompletedArgs[0].MatchLdLocRef(awaiterVar))
return;
// Check awaitBlock and resumeBlock:
if (!awaitBlocks.TryGetValue(awaitBlock, out var awaitBlockData))
return;

Loading…
Cancel
Save