Browse Source

Merge pull request #1769 from Chicken-Bones/postincrementfloat

Transform post-increment on float/double. Fixes #1764
pull/1790/head
Daniel Grunwald 6 years ago committed by GitHub
parent
commit
74d46b0853
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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 @@ -4721,6 +4721,16 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return (*GetPointer())++;
}
public float PostIncrementFloat(float f)
{
return f++;
}
public double PostIncrementDouble(double d)
{
return d++;
}
public void Issue1552Pre(CustomStruct a, CustomStruct b)
{
CustomStruct customStruct = a + b;

2
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -1511,7 +1511,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1511,7 +1511,7 @@ namespace ICSharpCode.Decompiler.CSharp
TranslatedExpression resultExpr;
if (inst.EvalMode == CompoundEvalMode.EvaluatesToOldValue) {
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;
ExpressionType exprType;
if (op == AssignmentOperatorType.Add) {

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

@ -643,7 +643,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -643,7 +643,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
}
StLoc stloc;
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))
return false;
if (!ValidateCompoundAssign(binary, conv, targetType))
@ -717,7 +717,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -717,7 +717,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false;
}
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;
if (!(binary.Operator == BinaryNumericOperator.Add || binary.Operator == BinaryNumericOperator.Sub))
return false;

Loading…
Cancel
Save