From 8c291448114183784f008d9ea5b8ca8631943612 Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Sat, 15 Mar 2025 10:37:11 -0700 Subject: [PATCH] Add struct to struct tests --- .../TestCases/Pretty/PointerArithmetic.cs | 30 +++++++++++++++++++ .../CSharp/ExpressionBuilder.cs | 3 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PointerArithmetic.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PointerArithmetic.cs index a39524972..4a609f123 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PointerArithmetic.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/PointerArithmetic.cs @@ -49,6 +49,36 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty return ((uint*)ptr)[2]; } + public unsafe static void AssignmentGuidPointerToDateTimePointer(Guid* ptr) + { + ((DateTime*)ptr)[2] = DateTime.Now; + } + + public unsafe static void AssignmentGuidPointerToDateTimePointerDefault(Guid* ptr) + { + ((DateTime*)ptr)[2] = default(DateTime); + } + + public unsafe static void AssignmentGuidPointerToDateTimePointer_2(Guid* ptr) + { + *(DateTime*)(ptr + 2) = DateTime.Now; + } + + public unsafe static void AssignmentGuidPointerToDateTimePointerDefault_2(Guid* ptr) + { + *(DateTime*)(ptr + 2) = default(DateTime); + } + + public unsafe static DateTime AccessGuidPointerToDateTimePointer(Guid* ptr) + { + return ((DateTime*)ptr)[2]; + } + + public unsafe static DateTime AccessGuidPointerToDateTimePointer_2(Guid* ptr) + { + return *(DateTime*)(ptr + 2); + } + public unsafe static void AssignmentIntPointer(int* ptr) { ptr[2] = 1; diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index 4d046fbf2..292430eec 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -1258,7 +1258,8 @@ namespace ICSharpCode.Decompiler.CSharp var typeHint = (PointerType)context.TypeHint; int elementTypeSize = pointerType.ElementType.GetSize(); - if (elementTypeSize == 0 || typeHint.ElementType.GetSize() != elementTypeSize) + if ((elementTypeSize == 0 || typeHint.ElementType.GetSize() != elementTypeSize) + && GetPointerArithmeticOffset(byteOffsetInst, byteOffsetExpr, typeHint.ElementType, inst.CheckForOverflow) != null) { pointerType = typeHint; }