diff --git a/src/coreclr/tools/Common/Compiler/Int128FieldLayoutAlgorithm.cs b/src/coreclr/tools/Common/Compiler/Int128FieldLayoutAlgorithm.cs index c38a7bdbead108..ad98ae3cc1e101 100644 --- a/src/coreclr/tools/Common/Compiler/Int128FieldLayoutAlgorithm.cs +++ b/src/coreclr/tools/Common/Compiler/Int128FieldLayoutAlgorithm.cs @@ -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) { layoutFromMetadata.LayoutAbiStable = true; layoutFromMetadata.IsInt128OrHasInt128Fields = true; diff --git a/src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/ArchitectureSpecificFieldLayoutTests.cs b/src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/ArchitectureSpecificFieldLayoutTests.cs index 987d49ce274c66..c972dcbe8a60e8 100644 --- a/src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/ArchitectureSpecificFieldLayoutTests.cs +++ b/src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/ArchitectureSpecificFieldLayoutTests.cs @@ -22,6 +22,8 @@ public class ArchitectureSpecificFieldLayoutTests private ModuleDesc _testModuleARM; private TestTypeSystemContext _contextARM64; private ModuleDesc _testModuleARM64; + private TestTypeSystemContext _contextWasm32; + private ModuleDesc _testModuleWasm32; public ArchitectureSpecificFieldLayoutTests() { @@ -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] @@ -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) { @@ -530,6 +540,9 @@ public void TestAlignmentBehavior_AutoAlignmentRulesWithOSDependence(string wrap case "X86": testModule = _testModuleX86; break; + case "Wasm32": + testModule = _testModuleWasm32; + break; default: throw new Exception(); } diff --git a/src/coreclr/vm/methodtablebuilder.cpp b/src/coreclr/vm/methodtablebuilder.cpp index c18e0dd914fb21..de320a56206e8b 100644 --- a/src/coreclr/vm/methodtablebuilder.cpp +++ b/src/coreclr/vm/methodtablebuilder.cpp @@ -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