From 800a635663224d183d4238f3f337c8cf2d310d61 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 11 Oct 2017 23:21:36 +0200 Subject: [PATCH] Fix bug in SimplifyCascadingIfStatements --- .../IL/Transforms/SwitchOnStringTransform.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs index 0c8e6ef45..cd360d722 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs @@ -88,15 +88,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; if (!firstBlockJump.MatchBranch(out var firstBlock)) return false; - bool isLegacy; List<(string, Block)> values = new List<(string, Block)>(); // match null check: this is used by the old C# compiler. if (condition.MatchCompEquals(out var left, out var right) && right.MatchLdNull() && left.MatchLdLoc(out var switchValueVar)) { - isLegacy = true; values.Add((null, firstBlock)); // Roslyn: match call to operator ==(string, string) } else if (MatchStringEqualityComparison(condition, out switchValueVar, out string value)) { - isLegacy = false; values.Add((value, firstBlock)); } else return false; // switchValueVar must be assigned only once and must be of type string. @@ -115,9 +112,6 @@ namespace ICSharpCode.Decompiler.IL.Transforms // We didn't find enough cases, exit if (values.Count < 3) return false; - // The block after all cases should only be reachable from the previous block and the null-check (in legacy code). - if (currentCaseBlock.IncomingEdgeCount != (isLegacy ? 2 : 1)) - return false; var sections = new List(values.SelectWithIndex((index, b) => new SwitchSection { Labels = new LongSet(index), Body = new Branch(b.Item2) })); sections.Add(new SwitchSection { Labels = new LongSet(new LongInterval(0, sections.Count)).Invert(), Body = new Branch(currentCaseBlock) }); var stringToInt = new StringToInt(new LdLoc(switchValueVar), values.SelectArray(item => item.Item1));