Skip to content

Commit 8c29144

Browse files
committed
Add struct to struct tests
1 parent 437bd56 commit 8c29144

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

ICSharpCode.Decompiler.Tests/TestCases/Pretty/PointerArithmetic.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,36 @@ public unsafe static uint AccessGuidPointerToUIntPointer(Guid* ptr)
4949
return ((uint*)ptr)[2];
5050
}
5151

52+
public unsafe static void AssignmentGuidPointerToDateTimePointer(Guid* ptr)
53+
{
54+
((DateTime*)ptr)[2] = DateTime.Now;
55+
}
56+
57+
public unsafe static void AssignmentGuidPointerToDateTimePointerDefault(Guid* ptr)
58+
{
59+
((DateTime*)ptr)[2] = default(DateTime);
60+
}
61+
62+
public unsafe static void AssignmentGuidPointerToDateTimePointer_2(Guid* ptr)
63+
{
64+
*(DateTime*)(ptr + 2) = DateTime.Now;
65+
}
66+
67+
public unsafe static void AssignmentGuidPointerToDateTimePointerDefault_2(Guid* ptr)
68+
{
69+
*(DateTime*)(ptr + 2) = default(DateTime);
70+
}
71+
72+
public unsafe static DateTime AccessGuidPointerToDateTimePointer(Guid* ptr)
73+
{
74+
return ((DateTime*)ptr)[2];
75+
}
76+
77+
public unsafe static DateTime AccessGuidPointerToDateTimePointer_2(Guid* ptr)
78+
{
79+
return *(DateTime*)(ptr + 2);
80+
}
81+
5282
public unsafe static void AssignmentIntPointer(int* ptr)
5383
{
5484
ptr[2] = 1;

ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,8 @@ protected internal override TranslatedExpression VisitBinaryNumericInstruction(B
12581258

12591259
var typeHint = (PointerType)context.TypeHint;
12601260
int elementTypeSize = pointerType.ElementType.GetSize();
1261-
if (elementTypeSize == 0 || typeHint.ElementType.GetSize() != elementTypeSize)
1261+
if ((elementTypeSize == 0 || typeHint.ElementType.GetSize() != elementTypeSize)
1262+
&& GetPointerArithmeticOffset(byteOffsetInst, byteOffsetExpr, typeHint.ElementType, inst.CheckForOverflow) != null)
12621263
{
12631264
pointerType = typeHint;
12641265
}

0 commit comments

Comments
 (0)