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

8
ICSharpCode.Decompiler/Tests/RoundtripAssembly.cs

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

Loading…
Cancel
Save