Skip to content

JIT: Reject native-int bounds checks in range check cloning - #135725

Merged
EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:jit-fix-134459
Oct 14, 2026
Merged

EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:jit-fix-134459

Conversation

@EgorBo

@EgorBo EgorBo commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

BoundsCheckInfo::Initialize only checked the index type on the non-constant path. A TYP_LONG constant index (e.g. arr[(nint)0], whose bounds check also has a CAST(long <- ARR_LENGTH) length) passed IsIntCnsFitsInI32() and was accepted, while optRangeCheckCloning_DoClone builds the guards as TYP_INT, producing mixed int/long relops (asserts in Checked, invalid IR in Release).

Fix: reject bounds checks whose index or length isn't TYP_INT up front. No asm diffs in libraries.pmi.

Fixes #134459

No diffs.

`BoundsCheckInfo::Initialize` only checked the index type on the non-constant
path. A `TYP_LONG` constant index (e.g. `arr[(nint)0]`, whose bounds check also
has a `CAST(long <- ARR_LENGTH)` length) passed `IsIntCnsFitsInI32()` and was
accepted, while `optRangeCheckCloning_DoClone` builds the guards as `TYP_INT`,
producing mixed int/long relops (asserts in Checked, invalid IR in Release).

Fix: reject bounds checks whose index or length isn't `TYP_INT` up front.
No asm diffs in libraries.pmi.

Fixes dotnet#134459

Co-authored-by: Copilot <[email protected]>
Copilot-Session: ef747772-3030-470e-b839-f9a4fc116717
@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 Oct 13, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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.

🟢 Approval recommended

The conservative type guard addresses the malformed IR and the optimized regression test exercises the original failure.

0 open findings

What changed in this PR

Prevents range-check cloning from generating invalid mixed-width JIT IR.

Changes:

  • Rejects bounds checks whose index or array length is not TYP_INT.
  • Adds a regression test for constant nint array indices.
File Description
src/​coreclr/​jit/​rangecheckcloning.cpp Adds operand-width validation before cloning.
src/​tests/​JIT/​Regression_ro_2/​Runtime_134459.cs Covers the reported native-int assertion failure.

🧠 Review effort: Balanced

@EgorBo

EgorBo commented Oct 14, 2026

Copy link
Copy Markdown
Member Author

PTAL @dotnet/jit-contrib, trivial bug-fix

@EgorBo
EgorBo requested a review from a team October 14, 2026 02:04

@JulieLeeMSFT JulieLeeMSFT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. It disables range-check cloning for non-TYP_INT indices or lengths, which includes constant nint cases that previously bypassed type validation.

@tannergooding tannergooding left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It'd be nice to get nint working consistently here

@EgorBo

EgorBo commented Oct 14, 2026

Copy link
Copy Markdown
Member Author

It'd be nice to get nint working consistently here

Yeah, it's just lack of diffs didn't motivate me for that

@EgorBo
EgorBo merged commit 50131be into dotnet:main Oct 14, 2026
136 of 138 checks passed
@EgorBo
EgorBo deleted the jit-fix-134459 branch October 14, 2026 21:46
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 19, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 19, 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.

JIT: (bug) assert genActualType(op1) == genActualType(op2) - range check cloning builds mixed-width (int/long) guard conditions

4 participants