Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override ComputedInstanceFieldLayout ComputeInstanceLayout(DefType defTyp
ComputedInstanceFieldLayout layoutFromMetadata = _fallbackAlgorithm.ComputeInstanceLayout(defType, layoutKind);

// 32bit platforms use standard metadata layout engine
if (defType.Context.Target.Architecture == TargetArchitecture.ARM)
if (defType.Context.Target.Architecture is TargetArchitecture.ARM or TargetArchitecture.Wasm32)
{
Comment on lines 33 to 35

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct that the comment is imprecise — X86 is 32-bit and does take the 16-byte override. That imprecision predates this change though, and the condition it describes is right there on the next line, so I'd rather not expand it here: rewording a pre-existing comment is unrelated churn, and per repo convention comments are kept minimal because inaccurate ones mislead and need maintenance.

Happy to fix it if a maintainer would prefer.

Note

This comment was generated by GitHub Copilot.

layoutFromMetadata.LayoutAbiStable = true;
layoutFromMetadata.IsInt128OrHasInt128Fields = true;
Comment on lines +34 to 37

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added Wasm32 cases to TestAlignmentBehavior_AutoAlignmentRulesWithOSDependence in 5fe365d. Both fail without the layout change (alignment 16 rather than 8), so they actually guard the new branch rather than just documenting it.

Note

This comment was generated by GitHub Copilot.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class ArchitectureSpecificFieldLayoutTests
private ModuleDesc _testModuleARM;
private TestTypeSystemContext _contextARM64;
private ModuleDesc _testModuleARM64;
private TestTypeSystemContext _contextWasm32;
private ModuleDesc _testModuleWasm32;

public ArchitectureSpecificFieldLayoutTests()
{
Expand Down Expand Up @@ -60,6 +62,12 @@ public ArchitectureSpecificFieldLayoutTests()
_contextARM64.SetSystemModule(systemModuleARM64);

_testModuleARM64 = systemModuleARM64;

_contextWasm32 = new TestTypeSystemContext(TargetArchitecture.Wasm32);
var systemModuleWasm32 = _contextWasm32.CreateModuleForSimpleName("CoreTestAssembly");
_contextWasm32.SetSystemModule(systemModuleWasm32);

_testModuleWasm32 = systemModuleWasm32;
}

[Fact]
Expand Down Expand Up @@ -501,11 +509,13 @@ public void TestAlignmentBehavior_AutoAlignmentRules(string wrapperType, int[] a
[InlineData("StructStructByte_Int128StructAuto", "X86", 16, 32)]
[InlineData("StructStructByte_Int128StructAuto", "X64Linux", 16, 32)]
[InlineData("StructStructByte_Int128StructAuto", "X64Windows", 16, 32)]
[InlineData("StructStructByte_Int128StructAuto", "Wasm32", 8, 24)]
[InlineData("StructStructByte_UInt128StructAuto", "ARM64", 16, 32)]
[InlineData("StructStructByte_UInt128StructAuto", "ARM", 8, 24)]
[InlineData("StructStructByte_UInt128StructAuto", "X86", 16, 32)]
[InlineData("StructStructByte_UInt128StructAuto", "X64Linux", 16, 32)]
[InlineData("StructStructByte_UInt128StructAuto", "X64Windows", 16, 32)]
[InlineData("StructStructByte_UInt128StructAuto", "Wasm32", 8, 24)]
// Variation of TestAlignmentBehavior_AutoAlignmentRules above that is able to deal with os specific behavior
public void TestAlignmentBehavior_AutoAlignmentRulesWithOSDependence(string wrapperType, string osArch, int alignment, int size)
{
Expand All @@ -530,6 +540,9 @@ public void TestAlignmentBehavior_AutoAlignmentRulesWithOSDependence(string wrap
case "X86":
testModule = _testModuleX86;
break;
case "Wasm32":
testModule = _testModuleWasm32;
break;
default:
throw new Exception();
}
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/vm/methodtablebuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10817,7 +10817,8 @@ void MethodTableBuilder::CheckForSystemTypes()
// even on X86
pLayout->SetAlignmentRequirement(16); // sizeof(__int128)
#elif defined(TARGET_WASM)
pLayout->SetAlignmentRequirement(16); // sizeof(v128)
// Wasm has no 128-bit scalar type to match, so use the natural field alignment.
pLayout->SetAlignmentRequirement(8);
#else
#error Unknown architecture
#endif // TARGET_64BIT
Comment on lines +10820 to 10824
Expand Down
Loading