Skip to content

Fix tree type in impStoreNullableFields and impLoadNullableFields for simds - #124432

Merged
EgorBo merged 3 commits into
dotnet:mainfrom
EgorBo:fix-nullable-struct-bug
Feb 16, 2026
Merged

EgorBo merged 3 commits into
dotnet:mainfrom
EgorBo:fix-nullable-struct-bug

Conversation

@EgorBo

@EgorBo EgorBo commented Feb 14, 2026 •

Copy link
Copy Markdown
Member

Fixes #124425 - the actual issue is TYP_SIMD* was typed as TYP_STRUCT.

We use TypeHandleToVarType for similar places - it correctly maps CORINFO_CLASS_HANDLE into SIMD.

Copilot AI review requested due to automatic review settings February 14, 2026 22:57
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 14, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

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

This PR fixes a critical bug (issue #124425) where nullable SIMD types (e.g., Vector2?, Vector3?, Vector4?) caused an InvalidProgramException in debug builds (with JIT MinOpts enabled). The root cause was that impStoreNullableFields and impLoadNullableFields were using JITtype2varType, which always maps CORINFO_TYPE_VALUECLASS to the generic TYP_STRUCT type. For SIMD types, the specific normalized type (e.g., TYP_SIMD8 for Vector2) must be used instead.

Changes:

  • Modified impStoreNullableFields and impLoadNullableFields to use TypeHandleToVarType with both the CorInfoType and class handle, which properly resolves SIMD types to their normalized type through the layout system
  • Added a comprehensive regression test that verifies nullable SIMD types throw the expected NullReferenceException when cast from null values

Reviewed changes

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

File Description
src/coreclr/jit/importer.cpp Fixed type resolution for nullable SIMD fields in impStoreNullableFields (lines 2996-2998) and impLoadNullableFields (lines 3034-3036) to use TypeHandleToVarType instead of JITtype2varType
src/tests/JIT/Regression/JitBlue/Runtime_124425/Runtime_124425.csproj Test project configuration with DOTNET_JITMinOpts=1 to trigger the unoptimized code path where the bug occurred
src/tests/JIT/Regression/JitBlue/Runtime_124425/Runtime_124425.cs Regression test covering nullable Vector2, Vector3, and Vector4 types

Comment thread src/coreclr/jit/importer.cpp Resolved
Comment thread src/coreclr/jit/importer.cpp Resolved
Copilot AI review requested due to automatic review settings February 14, 2026 23:07

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

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

@EgorBo
EgorBo marked this pull request as ready for review February 15, 2026 01:56
@EgorBo
EgorBo requested a review from jakobbotsch February 16, 2026 12:48
@EgorBo

EgorBo commented Feb 16, 2026

Copy link
Copy Markdown
Member Author

PTAL @jakobbotsch @dotnet/jit-contrib

@EgorBo
EgorBo merged commit 908c168 into dotnet:main Feb 16, 2026
138 checks passed
iremyux pushed a commit to iremyux/dotnet-runtime that referenced this pull request Mar 2, 2026
… simds (dotnet#124432)

Fixes dotnet#124425 - the actual issue
is TYP_SIMD* was typed as TYP_STRUCT.

We use TypeHandleToVarType for similar places - it correctly maps
CORINFO_CLASS_HANDLE into SIMD.
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 19, 2026
@tannergooding

Copy link
Copy Markdown
Member

/backport to release/10.0

@github-actions github-actions Bot unlocked this conversation Jul 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0 (link to workflow run)

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InvalidProgramException: Common Language Runtime detected an invalid program (Debug-only)

4 participants