diff --git a/ICSharpCode.Decompiler/IL/Transforms/LockTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/LockTransform.cs index 9bc03a7b8..cbc06bbb3 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/LockTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/LockTransform.cs @@ -60,6 +60,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; if (!(body.FinallyBlock is BlockContainer finallyContainer) || !MatchExitBlock(finallyContainer.EntryPoint, null, objectStore.Variable)) return false; + if (objectStore.Variable.LoadCount > 1) + return false; context.Step("LockTransformV2", block); block.Instructions.RemoveAt(i - 1); block.Instructions.RemoveAt(i - 2); @@ -102,6 +104,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; if (!(body.FinallyBlock is BlockContainer finallyContainer) || !MatchExitBlock(finallyContainer.EntryPoint, flagStore.Variable, objectStore.Variable)) return false; + if (objectStore.Variable.LoadCount > 1) + return false; context.Step("LockTransformV4", block); block.Instructions.RemoveAt(i - 1); tryContainer.EntryPoint.Instructions.RemoveAt(0); @@ -145,6 +149,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; if (!(body.FinallyBlock is BlockContainer finallyContainer) || !MatchExitBlock(finallyContainer.EntryPoint, flagStore.Variable, objectStore.Variable)) return false; + if (objectStore.Variable.LoadCount > 2) + return false; context.Step("LockTransformRoslyn", block); block.Instructions.RemoveAt(i - 1); block.Instructions.RemoveAt(i - 2);