From 8285d01cadeccd4f41b6f2d017678e5677a5b468 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 19 Sep 2017 10:16:25 +0200 Subject: [PATCH] Do not match lock if lockObj is used in or after the try block. --- ICSharpCode.Decompiler/IL/Transforms/LockTransform.cs | 6 ++++++ 1 file changed, 6 insertions(+) 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);