Repository navigation
JIT: Reject native-int bounds checks in range check cloning - #135725
Conversation
`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
|
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. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
🟢 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
nintarray 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
|
PTAL @dotnet/jit-contrib, trivial bug-fix |
JulieLeeMSFT
left a comment
There was a problem hiding this comment.
LGTM. It disables range-check cloning for non-TYP_INT indices or lengths, which includes constant nint cases that previously bypassed type validation.
tannergooding
left a comment
There was a problem hiding this comment.
It'd be nice to get nint working consistently here
Yeah, it's just lack of diffs didn't motivate me for that |
BoundsCheckInfo::Initializeonly checked the index type on the non-constant path. ATYP_LONGconstant index (e.g.arr[(nint)0], whose bounds check also has aCAST(long <- ARR_LENGTH)length) passedIsIntCnsFitsInI32()and was accepted, whileoptRangeCheckCloning_DoClonebuilds the guards asTYP_INT, producing mixed int/long relops (asserts in Checked, invalid IR in Release).Fix: reject bounds checks whose index or length isn't
TYP_INTup front. No asm diffs in libraries.pmi.Fixes #134459
No diffs.