Repository navigation
Description
Description
When you define an inline array type that has a size such that size * pointer-size >= 65534, it crashes the NAOT compiler (unless you restrict generics to struct). It is possible there may be ways to trigger this with other (struct) instantiations too, but I have not seen any like this yet.
Reproduction Steps
using System;
using System.Runtime.CompilerServices;
public class C
{
static Array Create<T>() => new InlineArray65534<T>[1];
[InlineArray(65534)] struct InlineArray65534<T> { T field; }
}https://godbolt.org/z/PTa6Y8onP
Expected behavior
Compiles & calling Create with a type that is too large would cause Create to throw an exception at runtime, like in coreclr (which refuses to inline methods that have invalid types & if you end up calling it, just throws a TypeLoadException instead (which can be caught normally)).
Additionally, the limit should be 65535 like in coreclr, but seems to be 65534.
Actual behavior
Error: Array of type 'InlineArray65534`1<System.__Canon>' from assembly 'CompilerExplorer' cannot be created because base value type is too large
Internal.TypeSystem.TypeSystemException+TypeLoadException: Array of type 'InlineArray65534`1<System.__Canon>' from assembly 'CompilerExplorer' cannot be created because base value type is too large
at Internal.TypeSystem.ThrowHelper.ThrowTypeLoadException(ExceptionStringID, String, String) in /_/src/coreclr/tools/Common/TypeSystem/Common/ThrowHelper.cs:line 17
at ILCompiler.CompilerTypeSystemContext.EnsureLoadableTypeUncached(TypeDesc) in /_/src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.Validation.cs:line 272
at ILCompiler.CompilerTypeSystemContext.EnsureLoadableType(TypeDesc) in /_/src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.Validation.cs:line 83
at ILCompiler.DependencyAnalysis.NodeFactory.CreateNecessaryTypeNode(TypeDesc) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs:line 656
at Internal.TypeSystem.LockFreeReaderHashtable`2.CreateValueAndEnsureValueIsInTable(TKey) in /_/src/coreclr/tools/Common/TypeSystem/Common/Utilities/LockFreeReaderHashtable.cs:line 562
at ILCompiler.DependencyAnalysis.NodeFactory.NecessaryTypeSymbol(TypeDesc) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs:line 754
at ILCompiler.DependencyAnalysis.NodeFactory.NativeLayoutHelper.<TemplateConstructableTypes>d__3.MoveNext() in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.NativeLayout.cs:line 159
at ILCompiler.DependencyAnalysis.NativeLayoutTypeSignatureBasedGenericDictionarySlotNode.<GetStaticDependencies>d__6.MoveNext() in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NativeLayoutVertexNode.cs:line 1119
at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependenciesImpl(DependencyNodeCore`1) in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 185
at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ProcessMarkStack() in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 260
at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes() in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 308
at ILCompiler.ILScanner.ILCompiler.IILScanner.Scan() in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs:line 157
at ILCompiler.Program.<Run>g__RunScanner|4_0(Program.<>c__DisplayClass4_0&) in /_/src/coreclr/tools/aot/ILCompiler/Program.cs:line 525
at ILCompiler.Program.Run() in /_/src/coreclr/tools/aot/ILCompiler/Program.cs:line 594
at ILCompiler.ILCompilerRootCommand.<>c__DisplayClass263_0.<.ctor>b__0(ParseResult) in /_/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs:line 319
Compiler returned: 1
Regression?
No response
Known Workarounds
Don't have any methods that create arrays of inline arrays with more than repeat count 8191 that are via unconstrained generics.
Configuration
godbolt.org
Other information
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
hamarb123 commentedon Jun 30, 2026
/cc @MichalStrehovsky
dotnet-policy-service commentedon Jun 30, 2026
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.
MihuBot commentedon Jun 30, 2026
I'm a bot. Here is a possible related and/or duplicate issue (I may be wrong):
Validate targets of generic lookup in the scanner (#130110)
Validate targets of generic lookup in the scanner (#130110)