Browse Source

Transform post-increment on float/double. Fixes #1764

pull/1769/head
Chicken-Bones 7 years ago
parent
commit
661acdfc08
  1. 10
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs
  2. 2
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  3. 4
      ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs

10
ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs

@ -4721,6 +4721,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return (*GetPointer())++; return (*GetPointer())++;
} }
public float PostIncrementFloat(float f)
{
return f++;
}
public double PostIncrementDouble(double d)
{
return d++;
}
public void Issue1552Pre(CustomStruct a, CustomStruct b) public void Issue1552Pre(CustomStruct a, CustomStruct b)
{ {
CustomStruct customStruct = a + b; CustomStruct customStruct = a + b;

2
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -1511,7 +1511,7 @@ namespace ICSharpCode.Decompiler.CSharp
TranslatedExpression resultExpr; TranslatedExpression resultExpr;
if (inst.EvalMode == CompoundEvalMode.EvaluatesToOldValue) { if (inst.EvalMode == CompoundEvalMode.EvaluatesToOldValue) {
Debug.Assert(op == AssignmentOperatorType.Add || op == AssignmentOperatorType.Subtract); Debug.Assert(op == AssignmentOperatorType.Add || op == AssignmentOperatorType.Subtract);
Debug.Assert(inst.Value.MatchLdcI(1)); Debug.Assert(inst.Value.MatchLdcI(1) || inst.Value.MatchLdcF4(1) || inst.Value.MatchLdcF8(1));
UnaryOperatorType unary; UnaryOperatorType unary;
ExpressionType exprType; ExpressionType exprType;
if (op == AssignmentOperatorType.Add) { if (op == AssignmentOperatorType.Add) {

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

@ -643,7 +643,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
} }
StLoc stloc; StLoc stloc;
var binary = UnwrapSmallIntegerConv(value, out var conv) as BinaryNumericInstruction; var binary = UnwrapSmallIntegerConv(value, out var conv) as BinaryNumericInstruction;
if (binary != null && binary.Right.MatchLdcI(1)) { if (binary != null && (binary.Right.MatchLdcI(1) || binary.Right.MatchLdcF4(1) || binary.Right.MatchLdcF8(1))) {
if (!(binary.Operator == BinaryNumericOperator.Add || binary.Operator == BinaryNumericOperator.Sub)) if (!(binary.Operator == BinaryNumericOperator.Add || binary.Operator == BinaryNumericOperator.Sub))
return false; return false;
if (!ValidateCompoundAssign(binary, conv, targetType)) if (!ValidateCompoundAssign(binary, conv, targetType))
@ -717,7 +717,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false; return false;
} }
if (UnwrapSmallIntegerConv(value, out var conv) is BinaryNumericInstruction binary) { if (UnwrapSmallIntegerConv(value, out var conv) is BinaryNumericInstruction binary) {
if (!binary.Left.MatchLdLoc(tmpVar) || !binary.Right.MatchLdcI(1)) if (!binary.Left.MatchLdLoc(tmpVar) || !(binary.Right.MatchLdcI(1) || binary.Right.MatchLdcF4(1) || binary.Right.MatchLdcF8(1)))
return false; return false;
if (!(binary.Operator == BinaryNumericOperator.Add || binary.Operator == BinaryNumericOperator.Sub)) if (!(binary.Operator == BinaryNumericOperator.Add || binary.Operator == BinaryNumericOperator.Sub))
return false; return false;

Loading…
Cancel
Save