Browse Source

Fix missing checked/unchecked annotations

pull/728/head
Daniel Grunwald 9 years ago
parent
commit
8b85feb8d5
  1. 21
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  2. 8
      ICSharpCode.Decompiler/Tests/RoundtripAssembly.cs

21
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -499,6 +499,8 @@ namespace ICSharpCode.Decompiler.CSharp
var resultExpr = new BinaryOperatorExpression(left.Expression, op, right.Expression) var resultExpr = new BinaryOperatorExpression(left.Expression, op, right.Expression)
.WithILInstruction(inst) .WithILInstruction(inst)
.WithRR(rr); .WithRR(rr);
if (BinaryOperatorMightCheckForOverflow(op))
resultExpr.Expression.AddAnnotation(inst.CheckForOverflow ? AddCheckedBlocks.CheckedAnnotation : AddCheckedBlocks.UncheckedAnnotation);
return resultExpr.ConvertTo(compilation.FindType(inst.ResultType.ToKnownTypeCode()), this); return resultExpr.ConvertTo(compilation.FindType(inst.ResultType.ToKnownTypeCode()), this);
} else { } else {
rr = resolverWithOverflowCheck.ResolveBinaryOperator(op, left.ResolveResult, right.ResolveResult); rr = resolverWithOverflowCheck.ResolveBinaryOperator(op, left.ResolveResult, right.ResolveResult);
@ -511,12 +513,29 @@ namespace ICSharpCode.Decompiler.CSharp
right = right.ConvertTo(targetType, this); right = right.ConvertTo(targetType, this);
rr = resolverWithOverflowCheck.ResolveBinaryOperator(op, left.ResolveResult, right.ResolveResult); rr = resolverWithOverflowCheck.ResolveBinaryOperator(op, left.ResolveResult, right.ResolveResult);
} }
return new BinaryOperatorExpression(left.Expression, op, right.Expression) var resultExpr = new BinaryOperatorExpression(left.Expression, op, right.Expression)
.WithILInstruction(inst) .WithILInstruction(inst)
.WithRR(rr); .WithRR(rr);
if (BinaryOperatorMightCheckForOverflow(op))
resultExpr.Expression.AddAnnotation(inst.CheckForOverflow ? AddCheckedBlocks.CheckedAnnotation : AddCheckedBlocks.UncheckedAnnotation);
return resultExpr;
} }
} }
static bool BinaryOperatorMightCheckForOverflow(BinaryOperatorType op)
{
switch (op) {
case BinaryOperatorType.BitwiseAnd:
case BinaryOperatorType.BitwiseOr:
case BinaryOperatorType.ExclusiveOr:
case BinaryOperatorType.ShiftLeft:
case BinaryOperatorType.ShiftRight:
return false;
default:
return true;
}
}
/// <summary> /// <summary>
/// Gets whether <paramref name="type"/> has the specified <paramref name="sign"/>. /// Gets whether <paramref name="type"/> has the specified <paramref name="sign"/>.
/// If <paramref name="sign"/> is None, always returns true. /// If <paramref name="sign"/> is None, always returns true.

8
ICSharpCode.Decompiler/Tests/RoundtripAssembly.cs

@ -37,11 +37,7 @@ namespace ICSharpCode.Decompiler.Tests
[Test] [Test]
public void Cecil_net45() public void Cecil_net45()
{ {
try { RunWithTest("Mono.Cecil-net45", "Mono.Cecil.dll", "Mono.Cecil.Tests.dll");
RunWithTest("Mono.Cecil-net45", "Mono.Cecil.dll", "Mono.Cecil.Tests.dll");
} catch (CompilationFailedException ex) {
Assert.Ignore(ex.Message);
}
} }
[Test] [Test]
@ -49,7 +45,7 @@ namespace ICSharpCode.Decompiler.Tests
{ {
try { try {
RunWithOutput("Random Tests\\TestCases", "TestCase-1.exe"); RunWithOutput("Random Tests\\TestCases", "TestCase-1.exe");
} catch (CompilationFailedException ex) { } catch (AssertionException ex) {
Assert.Ignore(ex.Message); Assert.Ignore(ex.Message);
} }
} }

Loading…
Cancel
Save