From a19c46430f61cbefd7024dd9c2aace8e48121e7a Mon Sep 17 00:00:00 2001 From: User Date: Mon, 5 May 2025 04:28:11 +0300 Subject: [PATCH 1/2] Fix instance size emission in ILCompiler to handle indeterminate sizes --- .../Compiler/UserDefinedTypeDescriptor.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UserDefinedTypeDescriptor.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UserDefinedTypeDescriptor.cs index 26d008f8377fee..e39ec99b00ae3c 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UserDefinedTypeDescriptor.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UserDefinedTypeDescriptor.cs @@ -732,11 +732,11 @@ private uint GetClassTypeIndex(TypeDesc type, bool needsCompleteType) statics[i] = staticsDescs[i]; } - LayoutInt elementSize = defType.GetElementSize(); - int elementSizeEmit = elementSize.IsIndeterminate ? 0xBAAD : elementSize.AsInt; + LayoutInt instanceSize = defType.InstanceByteCount; + int instanceSizeEmit = instanceSize.IsIndeterminate ? 0xBAAD : instanceSize.AsInt; ClassFieldsTypeDescriptor fieldsDescriptor = new ClassFieldsTypeDescriptor { - Size = (ulong)elementSizeEmit, + Size = (ulong)instanceSizeEmit, FieldsCount = fieldsDescs.Count, }; From ec8c1cc77ad4b911a8d9831592be7c9c4926fe77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Tue, 6 May 2025 13:37:17 -0700 Subject: [PATCH 2/2] Update src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UserDefinedTypeDescriptor.cs --- .../ILCompiler.Compiler/Compiler/UserDefinedTypeDescriptor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UserDefinedTypeDescriptor.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UserDefinedTypeDescriptor.cs index e39ec99b00ae3c..6decba09f41ca9 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UserDefinedTypeDescriptor.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UserDefinedTypeDescriptor.cs @@ -732,7 +732,7 @@ private uint GetClassTypeIndex(TypeDesc type, bool needsCompleteType) statics[i] = staticsDescs[i]; } - LayoutInt instanceSize = defType.InstanceByteCount; + LayoutInt instanceSize = defType.IsValueType ? defType.InstanceFieldSize : defType.InstanceByteCount; int instanceSizeEmit = instanceSize.IsIndeterminate ? 0xBAAD : instanceSize.AsInt; ClassFieldsTypeDescriptor fieldsDescriptor = new ClassFieldsTypeDescriptor {