Skip to content

Align NativeAOT array element size limit#130019

Open
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-array-type-size-limit
Open

Align NativeAOT array element size limit#130019
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-array-type-size-limit

Conversation

Copilot AI commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Description

NativeAOT rejected array element value types of exactly 65,535 bytes, while CoreCLR allows that boundary value. The validation now rejects only element sizes greater than ushort.MaxValue.

  • Updated NativeAOT compiler type validation:
    • >= ushort.MaxValue> ushort.MaxValue
  • Added a focused InlineArray regression test:
    • Verifies [InlineArray(65535)] can be used as an array element type.
    • Covers NativeAOT compilation via IlcCompile.
var array = new MaxSizedArrayElement[1];

[InlineArray(65535)]
struct MaxSizedArrayElement
{
    private byte _first;
}

Test methodology

  • Built the NativeAOT compiler project.
  • Built and ran the new regression test on CoreCLR.
  • Built and ran the NativeAOT-compiled test binary.

Additional context

This keeps NativeAOT behavior consistent with CoreCLR at the maximum supported array element size boundary.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 30, 2026 04:34
Copilot AI changed the title [WIP] Fix maximum allowed size of base type in arrays in NativeAOT Align NativeAOT array element size limit Jun 30, 2026
Copilot AI requested a review from MichalStrehovsky June 30, 2026 04:36
Copilot AI review requested due to automatic review settings June 30, 2026 04:39
@MichalStrehovsky MichalStrehovsky marked this pull request as ready for review June 30, 2026 04:40
@MichalStrehovsky

Copy link
Copy Markdown
Member

/azp run runtime-nativeaot-outerloop, runtime-coreclr outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Aligns NativeAOT’s array element-size validation with the runtime limit so that value-type array elements of exactly 65,535 bytes are accepted (matching CoreCLR behavior at the boundary). This avoids rejecting a size that still fits the GCDesc/component-size encodings used by the NativeAOT toolchain.

Changes:

  • Adjusted NativeAOT type loadability validation for arrays to reject only element sizes greater than ushort.MaxValue.
  • Added a new InlineArray-focused regression test project and test that exercises using an [InlineArray(65535)] struct as an array element type.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.Validation.cs Updates array element-size check from >= ushort.MaxValue to > ushort.MaxValue, allowing the 65,535-byte boundary.
src/tests/Loader/classloader/InlineArray/MaxArrayElementSize.csproj Adds a new standalone test project for the regression scenario.
src/tests/Loader/classloader/InlineArray/MaxArrayElementSize.cs Adds a test covering [InlineArray(65535)] as an array element type (size + successful array construction).

@hez2010

hez2010 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Can this be backported to .NET 10 as well?

@jkotas

jkotas commented Jun 30, 2026

Copy link
Copy Markdown
Member

This does not meet the bar for backport.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants