Browse Source

Fix array.Length == 0 in Roslyn.

pull/887/head
Siegfried Pammer 8 years ago
parent
commit
9e5d4c10f7
  1. 20
      ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs

20
ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs

@ -111,16 +111,6 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -111,16 +111,6 @@ namespace ICSharpCode.Decompiler.IL.Transforms
&& inst.Sign == Sign.Unsigned
&& (inst.Kind == ComparisonKind.GreaterThan || inst.Kind == ComparisonKind.LessThanOrEqual))
{
ILInstruction array;
if (inst.Left.MatchLdLen(StackType.I, out array)) {
// comp.unsigned(ldlen array > conv i4->i(ldc.i4 0))
// => comp(ldlen.i4 array > ldc.i4 0)
// This is a special case where the C# compiler doesn't generate conv.i4 after ldlen.
context.Step("comp(ldlen.i4 array > ldc.i4 0)", inst);
inst.InputType = StackType.I4;
inst.Left.ReplaceWith(new LdLen(StackType.I4, array) { ILRange = inst.Left.ILRange });
inst.Right = rightWithoutConv;
}
if (inst.Kind == ComparisonKind.GreaterThan) {
context.Step("comp.unsigned(left > ldc.i4 0) => comp(left != ldc.i4 0)", inst);
inst.Kind = ComparisonKind.Inequality;
@ -132,6 +122,16 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -132,6 +122,16 @@ namespace ICSharpCode.Decompiler.IL.Transforms
VisitComp(inst);
return;
}
} else if (rightWithoutConv.MatchLdcI4(0) && inst.Kind.IsEqualityOrInequality()) {
if (inst.Left.MatchLdLen(StackType.I, out ILInstruction array)) {
// comp.unsigned(ldlen array == conv i4->i(ldc.i4 0))
// => comp(ldlen.i4 array == ldc.i4 0)
// This is a special case where the C# compiler doesn't generate conv.i4 after ldlen.
context.Step("comp(ldlen.i4 array == ldc.i4 0)", inst);
inst.InputType = StackType.I4;
inst.Left.ReplaceWith(new LdLen(StackType.I4, array) { ILRange = inst.Left.ILRange });
inst.Right = rightWithoutConv;
}
}
if (inst.Right.MatchLdNull() && inst.Left.MatchBox(out arg, out var type) && type.Kind == TypeKind.TypeParameter) {

Loading…
Cancel
Save