Browse Source

Improve support for post-increment/decrement on pointers

pull/2856/head
ElektroKill 2 years ago
parent
commit
25873a68e0
No known key found for this signature in database
GPG Key ID: 7E3C5C084E40E3EC
  1. 13
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  2. 14
      ICSharpCode.Decompiler/IL/Transforms/TransformAssignment.cs

13
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
// Copyright (c) 2014-2020 Daniel Grunwald
// Copyright (c) 2014-2020 Daniel Grunwald
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
@ -1901,7 +1901,16 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1901,7 +1901,16 @@ namespace ICSharpCode.Decompiler.CSharp
if (inst.EvalMode == CompoundEvalMode.EvaluatesToOldValue)
{
Debug.Assert(op == AssignmentOperatorType.Add || op == AssignmentOperatorType.Subtract);
Debug.Assert(inst.Value.MatchLdcI(1) || inst.Value.MatchLdcF4(1) || inst.Value.MatchLdcF8(1));
#if DEBUG
if (inst.Type is PointerType ptrType)
{
ILInstruction instValue = PointerArithmeticOffset.Detect(inst.Value, ptrType.ElementType, inst.CheckForOverflow);
Debug.Assert(instValue is not null);
Debug.Assert(instValue.MatchLdcI(1));
}
else
Debug.Assert(inst.Value.MatchLdcI(1) || inst.Value.MatchLdcF4(1) || inst.Value.MatchLdcF8(1));
#endif
UnaryOperatorType unary;
ExpressionType exprType;
if (op == AssignmentOperatorType.Add)

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
// Copyright (c) 2015 Siegfried Pammer
// Copyright (c) 2015 Siegfried Pammer
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
@ -871,10 +871,18 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -871,10 +871,18 @@ namespace ICSharpCode.Decompiler.IL.Transforms
}
if (UnwrapSmallIntegerConv(value, out var conv) is BinaryNumericInstruction binary)
{
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;
if (!binary.Left.MatchLdLoc(tmpVar))
return false;
if (targetType is PointerType ptrType)
{
var right = PointerArithmeticOffset.Detect(binary.Right, ptrType.ElementType, binary.CheckForOverflow);
if (right is null || !right.MatchLdcI(1))
return false;
}
else if (!(binary.Right.MatchLdcI(1) || binary.Right.MatchLdcF4(1) || binary.Right.MatchLdcF8(1)))
return false;
if (!ValidateCompoundAssign(binary, conv, targetType, context.Settings))
return false;
context.Step("TransformPostIncDecOperator (builtin)", inst);

Loading…
Cancel
Save