Skip to content

Commit 1ffcb20

Browse files
committed
change for the Native AOT
1 parent 37d4869 commit 1ffcb20

File tree

7 files changed

+19
-2
lines changed

7 files changed

+19
-2
lines changed

src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/TypeLoaderExceptionHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ private static string GetFormatString(ExceptionStringID id)
9292
return SR.ClassLoad_InlineArrayLength;
9393
case ExceptionStringID.ClassLoadInlineArrayExplicit:
9494
return SR.ClassLoad_InlineArrayExplicit;
95+
case ExceptionStringID.ClassLoadInlineArrayExplicitSize:
96+
return SR.ClassLoad_InlineArrayExplicitSize;
9597
case ExceptionStringID.InvalidProgramDefault:
9698
return SR.InvalidProgram_Default;
9799
case ExceptionStringID.InvalidProgramSpecific:

src/coreclr/tools/Common/TypeSystem/Common/ExceptionStringID.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public enum ExceptionStringID
1919
ClassLoadInlineArrayFieldCount,
2020
ClassLoadInlineArrayLength,
2121
ClassLoadInlineArrayExplicit,
22+
ClassLoadInlineArrayExplicitSize,
2223

2324
// MissingMethodException
2425
MissingMethod,

src/coreclr/tools/Common/TypeSystem/Common/MetadataFieldLayoutAlgorithm.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,12 @@ protected ComputedInstanceFieldLayout ComputeSequentialFieldLayout(MetadataType
473473

474474
if (type.IsInlineArray)
475475
{
476+
// inline array cannot have explicit instance size
477+
if (layoutMetadata.Size != 0)
478+
{
479+
ThrowHelper.ThrowTypeLoadException(ExceptionStringID.ClassLoadInlineArrayExplicitSize, type);
480+
}
481+
476482
AdjustForInlineArray(type, numInstanceFields, ref instanceByteSizeAndAlignment, ref instanceSizeAndAlignment);
477483
}
478484

src/coreclr/tools/Common/TypeSystem/Common/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@
138138
<data name="ClassLoadInlineArrayExplicit" xml:space="preserve">
139139
<value>InlineArrayAttribute cannot be applied to a type with explicit layout. Type: '{0}'. Assembly: '{1}'.'</value>
140140
</data>
141+
<data name="ClassLoadInlineArrayExplicitSize" xml:space="preserve">
142+
<value>InlineArrayAttribute cannot be applied to a type with explicit size. Type: '{0}'. Assembly: '{1}'.'</value>
143+
</data>
141144
<data name="ClassLoadValueClassTooLarge" xml:space="preserve">
142145
<value>Array of type '{0}' from assembly '{1}' cannot be created because base value type is too large</value>
143146
</data>

src/coreclr/vm/methodtablebuilder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,9 @@ MethodTableBuilder::BuildMethodTableThrowing(
17941794
if ((int)bmtFP->NumInstanceFieldBytes != (INT64)bmtFP->NumInstanceFieldBytes)
17951795
BuildMethodTableThrowException(IDS_CLASSLOAD_FIELDTOOLARGE);
17961796

1797-
if (HasExplicitSize() && GetHalfBakedClass()->IsInlineArray())
1797+
if (HasExplicitSize() &&
1798+
bmtLayout->layoutType == EEClassLayoutInfo::LayoutType::Sequential &&
1799+
GetHalfBakedClass()->IsInlineArray())
17981800
{
17991801
BuildMethodTableThrowException(IDS_CLASSLOAD_INLINE_ARRAY_EXPLICIT_SIZE);
18001802
}

src/libraries/System.Private.CoreLib/src/Resources/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4202,6 +4202,9 @@
42024202
<data name="ClassLoad_InlineArrayExplicit" xml:space="preserve">
42034203
<value>InlineArrayAttribute cannot be applied to a type with explicit layout. Type: '{0}'. Assembly: '{1}'.</value>
42044204
</data>
4205+
<data name="ClassLoad_InlineArrayExplicitSize" xml:space="preserve">
4206+
<value>InlineArrayAttribute cannot be applied to a type with explicit size. Type: '{0}'. Assembly: '{1}'.</value>
4207+
</data>
42054208
<data name="ClassLoad_ExplicitGeneric" xml:space="preserve">
42064209
<value>Could not load type '{0}' from assembly '{1}' because generic types cannot have explicit layout.</value>
42074210
</data>

src/mono/mono/metadata/class-init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ mono_class_setup_fields (MonoClass *klass)
317317
if (explicit_size)
318318
instance_size += real_size;
319319

320-
if (explicit_size && m_class_is_inlinearray (klass)) {
320+
if (explicit_size && layout == TYPE_ATTRIBUTE_SEQUENTIAL_LAYOUT && m_class_is_inlinearray (klass)) {
321321
if (mono_get_runtime_callbacks ()->mono_class_set_deferred_type_load_failure_callback)
322322
mono_get_runtime_callbacks ()->mono_class_set_deferred_type_load_failure_callback (klass, "Inline array must not have explicit size.");
323323
else

0 commit comments

Comments
 (0)