diff --git a/ICSharpCode.Decompiler/ILAst/LoopsAndConditions.cs b/ICSharpCode.Decompiler/ILAst/LoopsAndConditions.cs index 3582d7d96..a310624c0 100644 --- a/ICSharpCode.Decompiler/ILAst/LoopsAndConditions.cs +++ b/ICSharpCode.Decompiler/ILAst/LoopsAndConditions.cs @@ -364,12 +364,12 @@ namespace ICSharpCode.Decompiler.ILAst labelToCfNode.TryGetValue(falseLabel, out falseTarget); // Pull in the conditional code - if (trueTarget != null && trueTarget.Incoming.Count == 1) { + if (trueTarget != null && HasSingleEdgeEnteringBlock(trueTarget)) { HashSet content = FindDominatedNodes(scope, trueTarget); scope.ExceptWith(content); ilCond.TrueBlock.Body.AddRange(FindConditions(content, trueTarget)); } - if (falseTarget != null && falseTarget.Incoming.Count == 1) { + if (falseTarget != null && HasSingleEdgeEnteringBlock(falseTarget)) { HashSet content = FindDominatedNodes(scope, falseTarget); scope.ExceptWith(content); ilCond.FalseBlock.Body.AddRange(FindConditions(content, falseTarget)); @@ -398,6 +398,11 @@ namespace ICSharpCode.Decompiler.ILAst return result; } + static bool HasSingleEdgeEnteringBlock(ControlFlowNode node) + { + return node.Incoming.Count(edge => !node.Dominates(edge.Source)) == 1; + } + static HashSet FindDominatedNodes(HashSet scope, ControlFlowNode head) { HashSet agenda = new HashSet();