Browse Source

Also combine 'ldlen; conv.i4.ovf' to 'ldlen.i4'.

The VB compiler emits overflow checks when accessing the array length. (#1097)
pull/1108/head
Daniel Grunwald 7 years ago
parent
commit
a46ac9dc84
  1. 15
      ICSharpCode.Decompiler/DecompilerSettings.cs
  2. 4
      ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs

15
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -568,6 +568,21 @@ namespace ICSharpCode.Decompiler @@ -568,6 +568,21 @@ namespace ICSharpCode.Decompiler
}
#region Options to aid VB decompilation
bool assumeArrayLengthFitsIntoInt32 = true;
/// <summary>
/// Gets/Sets whether the decompiler can assume that 'ldlen; conv.i4.ovf' does not throw an overflow exception.
/// </summary>
public bool AssumeArrayLengthFitsIntoInt32 {
get { return assumeArrayLengthFitsIntoInt32; }
set {
if (assumeArrayLengthFitsIntoInt32 != value) {
assumeArrayLengthFitsIntoInt32 = value;
OnPropertyChanged();
}
}
}
bool introduceIncrementAndDecrement = true;
/// <summary>

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

@ -148,7 +148,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -148,7 +148,9 @@ namespace ICSharpCode.Decompiler.IL.Transforms
protected internal override void VisitConv(Conv inst)
{
inst.Argument.AcceptVisitor(this);
if (inst.Argument.MatchLdLen(StackType.I, out ILInstruction array) && inst.TargetType.IsIntegerType() && !inst.CheckForOverflow) {
if (inst.Argument.MatchLdLen(StackType.I, out ILInstruction array) && inst.TargetType.IsIntegerType()
&& (!inst.CheckForOverflow || context.Settings.AssumeArrayLengthFitsIntoInt32))
{
context.Step("conv.i4(ldlen array) => ldlen.i4(array)", inst);
inst.AddILRange(inst.Argument.ILRange);
inst.ReplaceWith(new LdLen(inst.TargetType.GetStackType(), array) { ILRange = inst.ILRange });

Loading…
Cancel
Save