Browse Source

Fix SwitchOnStringTransform.SimplifyCascadingIfStatements to handle newer Roslyn code-gen correctly.

pull/1425/head
Siegfried Pammer 7 years ago
parent
commit
80bc89f606
  1. 6
      ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs

6
ICSharpCode.Decompiler/IL/Transforms/SwitchOnStringTransform.cs

@ -173,6 +173,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms
if (instructions[i - 1].MatchStLoc(switchValueVar, out switchValue)) {
// stloc switchValueVar(switchValue)
// if (call op_Equality(ldloc switchValueVar, ldstr value)) br firstBlock
// Newer versions of Roslyn use extra variables:
if (i >= 2 && switchValue.MatchLdLoc(out var otherSwitchValueVar) && otherSwitchValueVar.IsSingleDefinition && otherSwitchValueVar.LoadCount == 1
&& instructions[i - 2].MatchStLoc(otherSwitchValueVar, out switchValue)) {
extraLoad = true;
}
} else if (instructions[i - 1] is StLoc stloc) {
if (stloc.Value.MatchLdLoc(switchValueVar)) {
// in case of optimized legacy code there are two stlocs:

Loading…
Cancel
Save