diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.cs index 37ce5c345..e2a5d65d0 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/UnsafeCode.cs @@ -340,6 +340,26 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty return p - q; } + public unsafe long Issue2158a(void* p, void* q) + { + return (long)p - (long)q; + } + + public unsafe long Issue2158b(sbyte* p, sbyte* q) + { + return (long)p - (long)q; + } + + public unsafe long Issue2158c(int* p, int* q) + { + return (long)p - (long)q; + } + + public unsafe long Issue2158d(SimpleStruct* p, SimpleStruct* q) + { + return (long)p - (long)q; + } + public unsafe double FixedMemberAccess(StructWithFixedSizeMembers* m, int i) { return (double)m->Integers[i] + m->Doubles[i]; diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index 333ecc340..69fbc66e3 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -1152,7 +1152,7 @@ namespace ICSharpCode.Decompiler.CSharp /// int + ptr /// ptr - int /// Returns null if 'inst' is not performing pointer arithmetic. - /// This function not handle 'ptr - ptr'! + /// 'ptr - ptr' is not handled here, but in HandlePointerSubtraction()! /// TranslatedExpression? HandlePointerArithmetic(BinaryNumericInstruction inst, TranslatedExpression left, TranslatedExpression right) { diff --git a/ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs b/ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs index fd98642c0..4def735e5 100644 --- a/ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs +++ b/ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs @@ -748,24 +748,6 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver return BinaryOperatorResolveResult(rhsType, lhs, op, rhs); } - if (lhsType is PointerType) - { - methodGroup = new[] { - PointerArithmeticOperator(lhsType, lhsType, KnownTypeCode.Int32), - PointerArithmeticOperator(lhsType, lhsType, KnownTypeCode.UInt32), - PointerArithmeticOperator(lhsType, lhsType, KnownTypeCode.Int64), - PointerArithmeticOperator(lhsType, lhsType, KnownTypeCode.UInt64) - }; - } - else if (rhsType is PointerType) - { - methodGroup = new[] { - PointerArithmeticOperator(rhsType, KnownTypeCode.Int32, rhsType), - PointerArithmeticOperator(rhsType, KnownTypeCode.UInt32, rhsType), - PointerArithmeticOperator(rhsType, KnownTypeCode.Int64, rhsType), - PointerArithmeticOperator(rhsType, KnownTypeCode.UInt64, rhsType) - }; - } if (lhsType.Kind == TypeKind.Null && rhsType.Kind == TypeKind.Null) return new ErrorResolveResult(SpecialType.NullType); } @@ -813,28 +795,6 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver return BinaryOperatorResolveResult(rhsType, lhs, op, rhs); } - if (lhsType is PointerType) - { - if (rhsType is PointerType) - { - IType int64 = compilation.FindType(KnownTypeCode.Int64); - if (lhsType.Equals(rhsType)) - { - return BinaryOperatorResolveResult(int64, lhs, op, rhs); - } - else - { - return new ErrorResolveResult(int64); - } - } - methodGroup = new[] { - PointerArithmeticOperator(lhsType, lhsType, KnownTypeCode.Int32), - PointerArithmeticOperator(lhsType, lhsType, KnownTypeCode.UInt32), - PointerArithmeticOperator(lhsType, lhsType, KnownTypeCode.Int64), - PointerArithmeticOperator(lhsType, lhsType, KnownTypeCode.UInt64) - }; - } - if (lhsType.Kind == TypeKind.Null && rhsType.Kind == TypeKind.Null) return new ErrorResolveResult(SpecialType.NullType); }