Skip to content

Commit

Permalink
icsharpcode#1388: Fix ArgumentOutOfRangeException in AsyncAwaitDecomp…
Browse files Browse the repository at this point in the history
…iler.AnalyzeAwaitBlock.
  • Loading branch information
siegfriedpammer authored and ElektroKill committed Jul 14, 2021
1 parent ad1228f commit 635ad66
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ bool AnalyzeAwaitBlock(Block block, out ILVariable awaiter, out IField awaiterFi
awaiterField = null;
state = 0;
int pos = block.Instructions.Count - 2;
if (doFinallyBodies != null && block.Instructions[pos] is StLoc storeDoFinallyBodies) {
if (pos >= 0 && doFinallyBodies != null && block.Instructions[pos] is StLoc storeDoFinallyBodies) {
if (!(storeDoFinallyBodies.Variable.Kind == VariableKind.Local
&& storeDoFinallyBodies.Variable.Type.IsKnownType(KnownTypeCode.Boolean)
&& storeDoFinallyBodies.Variable.Index == doFinallyBodies.Index)) {
Expand All @@ -594,9 +594,9 @@ bool AnalyzeAwaitBlock(Block block, out ILVariable awaiter, out IField awaiterFi
pos--;
}

if (MatchCall(block.Instructions[pos], "AwaitUnsafeOnCompleted", out var callArgs)) {
if (pos >= 0 && MatchCall(block.Instructions[pos], "AwaitUnsafeOnCompleted", out var callArgs)) {
// call AwaitUnsafeOnCompleted(ldflda <>t__builder(ldloc this), ldloca awaiter, ldloc this)
} else if (MatchCall(block.Instructions[pos], "AwaitOnCompleted", out callArgs)) {
} else if (pos >= 0 && MatchCall(block.Instructions[pos], "AwaitOnCompleted", out callArgs)) {
// call AwaitOnCompleted(ldflda <>t__builder(ldloc this), ldloca awaiter, ldloc this)
// The C# compiler emits the non-unsafe call when the awaiter does not implement
// ICriticalNotifyCompletion.
Expand Down

0 comments on commit 635ad66

Please sign in to comment.