Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix test failures
  • Loading branch information
MichalStrehovsky committed Nov 18, 2021
commit 800cf0e3d24528a5b66d09c278c803628d554cc1
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ protected virtual ComputedInstanceFieldLayout ComputeInstanceFieldLayout(Metadat
return ComputeExplicitFieldLayout(type, numInstanceFields);
}
// Sequential layout has to be respected for blittable types only. We use approximation and respect it for
// all types without GC references (ie C# unmanaged types).
else if (type.IsSequentialLayout && !type.ContainsGCPointers)
// all types without GC references (ie C# unmanaged types). Universal canonical instances might be blittable.
else if (type.IsSequentialLayout && (type.IsCanonicalSubtype(CanonicalFormKind.Universal) || !type.ContainsGCPointers))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field offsets in universal type have to match the field offsets of all non-universal types; or the field offset in universal type has to be undermined. This condition violates that invariant.

I am wondering whether it would be better to disable the tests for universal layout instead of adding this change that makes the tests work, but does not actually make the code work correctly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can key off SupportsUniversalCanon to do the old thing. I think that's what we'll have to do if we ever activate universal canon here.

{
return ComputeSequentialFieldLayout(type, numInstanceFields);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,19 @@ public void TestAlignmentBehavior_LongIntEnumStruct()

Assert.Equal(0x20, tX64.InstanceByteCountUnaligned.AsInt);
Assert.Equal(0x20, tARM.InstanceByteCountUnaligned.AsInt);
Assert.Equal(0x20, tX86.InstanceByteCountUnaligned.AsInt);
Assert.Equal(0x18, tX86.InstanceByteCountUnaligned.AsInt);

Assert.Equal(0x20, tX64.InstanceByteCount.AsInt);
Assert.Equal(0x20, tARM.InstanceByteCount.AsInt);
Assert.Equal(0x20, tX86.InstanceByteCount.AsInt);
Assert.Equal(0x18, tX86.InstanceByteCount.AsInt);

Assert.Equal(0x8, tX64.InstanceFieldAlignment.AsInt);
Assert.Equal(0x8, tARM.InstanceFieldAlignment.AsInt);
Assert.Equal(0x8, tX86.InstanceFieldAlignment.AsInt);
Assert.Equal(0x4, tX86.InstanceFieldAlignment.AsInt);

Assert.Equal(0x20, tX64.InstanceFieldSize.AsInt);
Assert.Equal(0x20, tARM.InstanceFieldSize.AsInt);
Assert.Equal(0x20, tX86.InstanceFieldSize.AsInt);
Assert.Equal(0x18, tX86.InstanceFieldSize.AsInt);

Assert.Equal(0x0, tX64.GetField("_1").Offset.AsInt);
Assert.Equal(0x0, tARM.GetField("_1").Offset.AsInt);
Expand All @@ -123,18 +123,18 @@ public void TestAlignmentBehavior_LongIntEnumStruct()

Assert.Equal(0x10, tX64.GetField("_3").Offset.AsInt);
Assert.Equal(0x10, tARM.GetField("_3").Offset.AsInt);
Assert.Equal(0x10, tX86.GetField("_3").Offset.AsInt);
Assert.Equal(0xC, tX86.GetField("_3").Offset.AsInt);

Assert.Equal(0x18, tX64.GetField("_4").Offset.AsInt);
Assert.Equal(0x18, tARM.GetField("_4").Offset.AsInt);
Assert.Equal(0x18, tX86.GetField("_4").Offset.AsInt);
Assert.Equal(0x14, tX86.GetField("_4").Offset.AsInt);

MetadataType tX64FieldStruct = _testModuleX64.GetType(_namespace, _type + "FieldStruct");
MetadataType tX86FieldStruct = _testModuleX86.GetType(_namespace, _type + "FieldStruct");
MetadataType tARMFieldStruct = _testModuleARM.GetType(_namespace, _type + "FieldStruct");

Assert.Equal(0x8, tX64FieldStruct.GetField("_struct").Offset.AsInt);
Assert.Equal(0x8, tX86FieldStruct.GetField("_struct").Offset.AsInt);
Assert.Equal(0x4, tX86FieldStruct.GetField("_struct").Offset.AsInt);
Assert.Equal(0x8, tARMFieldStruct.GetField("_struct").Offset.AsInt);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public void TestInstanceMap()
{
var map = GCPointerMap.FromInstanceLayout(classWithStringField);
Assert.Equal(4, map.Size);
Assert.Equal("0010", map.ToString());
Assert.Equal("0100", map.ToString());
}

{
var map = GCPointerMap.FromInstanceLayout(mixedStruct);
Assert.Equal(5, map.Size);
Assert.Equal("01001", map.ToString());
Assert.Equal("11000", map.ToString());
}

{
Expand All @@ -60,13 +60,13 @@ public void TestInstanceMap()
{
var map = GCPointerMap.FromInstanceLayout(doubleMixedStructLayout);
Assert.Equal(10, map.Size);
Assert.Equal("0100101001", map.ToString());
Assert.Equal("1100011000", map.ToString());
}

{
var map = GCPointerMap.FromInstanceLayout(explicitlyFarPointer);
Assert.Equal(117, map.Size);
Assert.Equal("100000000000000000000000000000000000000000000000000000000000000010000000000000001000000000000000000000000000000001001", map.ToString());
Assert.Equal("100000000000000000000000000000000000000000000000000000000000000010000000000000001000000000000000000000000000000011000", map.ToString());
}

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,22 @@ public void TestSequentialTypeLayout()
switch (f.Name)
{
case "MyInt":
Assert.Equal(0x8, f.Offset.AsInt);
Assert.Equal(0x20, f.Offset.AsInt);
break;
case "MyBool":
Assert.Equal(0xC, f.Offset.AsInt);
Assert.Equal(0x26, f.Offset.AsInt);
break;
case "MyChar":
Assert.Equal(0xE, f.Offset.AsInt);
Assert.Equal(0x24, f.Offset.AsInt);
break;
case "MyString":
Assert.Equal(0x10, f.Offset.AsInt);
Assert.Equal(0x8, f.Offset.AsInt);
break;
case "MyByteArray":
Assert.Equal(0x18, f.Offset.AsInt);
Assert.Equal(0x10, f.Offset.AsInt);
break;
case "MyClass1SelfRef":
Assert.Equal(0x20, f.Offset.AsInt);
Assert.Equal(0x18, f.Offset.AsInt);
break;
default:
Assert.True(false);
Expand Down Expand Up @@ -226,19 +226,19 @@ public void TestSequentialTypeLayoutStruct()
switch (f.Name)
{
case "b1":
Assert.Equal(0x0, f.Offset.AsInt);
Assert.Equal(0xC, f.Offset.AsInt);
break;
case "b2":
Assert.Equal(0x1, f.Offset.AsInt);
Assert.Equal(0xD, f.Offset.AsInt);
break;
case "b3":
Assert.Equal(0x2, f.Offset.AsInt);
Assert.Equal(0xE, f.Offset.AsInt);
break;
case "i1":
Assert.Equal(0x4, f.Offset.AsInt);
Assert.Equal(0x8, f.Offset.AsInt);
break;
case "s1":
Assert.Equal(0x8, f.Offset.AsInt);
Assert.Equal(0x0, f.Offset.AsInt);
break;
default:
Assert.True(false);
Expand Down Expand Up @@ -269,10 +269,10 @@ public void TestSequentialTypeLayoutStructEmbedded()
switch (f.Name)
{
case "MyStruct0":
Assert.Equal(0x0, f.Offset.AsInt);
Assert.Equal(0x8, f.Offset.AsInt);
break;
case "MyBool":
Assert.Equal(0x10, f.Offset.AsInt);
Assert.Equal(0x0, f.Offset.AsInt);
break;
default:
Assert.True(false);
Expand Down