Skip to content

Crash in ilc due to a method & type being defined #130028

Closed

Description

@hamarb123

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

Activity

  1. hamarb123 commented on Jun 30, 2026

    @hamarb123
    ContributorAuthor
  2. added
    untriaged
    on Jun 30, 2026
  3. dotnet-policy-service commented on Jun 30, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
    See info in area-owners.md if you want to be subscribed.

  4. MihuBot commented on Jun 30, 2026

    @MihuBot

    I'm a bot. Here is a possible related and/or duplicate issue (I may be wrong):

  5. added a commit that references this issue on Jul 2, 2026
    414f660
  6. removed
    untriaged
    on Jul 2, 2026
  7. added a commit that references this issue on Jul 15, 2026
    80b6854
  8. locked and limited conversation to collaborators on Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions