Browse Source

Add struct to struct tests

pull/3413/head
ds5678 3 months ago
parent
commit
8c29144811
  1. 30
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/PointerArithmetic.cs
  2. 3
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

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

@ -49,6 +49,36 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return ((uint*)ptr)[2]; 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) public unsafe static void AssignmentIntPointer(int* ptr)
{ {
ptr[2] = 1; ptr[2] = 1;

3
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -1258,7 +1258,8 @@ namespace ICSharpCode.Decompiler.CSharp
var typeHint = (PointerType)context.TypeHint; var typeHint = (PointerType)context.TypeHint;
int elementTypeSize = pointerType.ElementType.GetSize(); 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; pointerType = typeHint;
} }

Loading…
Cancel
Save