Repository navigation
JIT: Report precise exceptions for non-IndexOutOfRange bounds checks - #137649
Merged
Merged
Conversation
`GenTree::OperExceptions` reported `IndexOutOfRangeException` for every `GT_BOUNDS_CHECK`, ignoring `gtThrowKind`. Bounds checks created for SIMD/HW intrinsics (e.g. `Vector128<T>.GetElement(int)` or out-of-range immediates) use `SCK_ARG_RNG_EXCPN` and throw `ArgumentOutOfRangeException` instead. Consumers that allow reordering trees throwing "the same single exception" (`CallArgs::ArgsComplete`, forward substitution, LIR side effect sets) could therefore reorder such a check with a real array/string bounds check, changing which exception is observed. E.g. in `Callee("abc"[i], v.GetElement(j) * ...)` the call args got sorted so that `GetElement(j)` threw `ArgumentOutOfRangeException` before `"abc"[i]` threw `IndexOutOfRangeException`.
Add `ArgumentException` and `ArgumentOutOfRangeException` to `ExceptionSetFlags` and map each bounds check throw kind to its precise exception. The debug-code check in `ArgsComplete` that treats inline-throwing args like calls is updated to keep covering these bounds checks.
Fixes dotnet#137637
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 3e6c4fb6-77fd-4a5a-9011-1cf5506af1bb
|
Azure Pipelines: Successfully started running 5 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
jakobbotsch
approved these changes
Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GenTree::OperExceptionsreportedIndexOutOfRangeExceptionfor everyGT_BOUNDS_CHECK, ignoringgtThrowKind. Bounds checks created for SIMD/HW intrinsics (e.g.Vector128<T>.GetElement(int)or out-of-range immediates) useSCK_ARG_RNG_EXCPNand throwArgumentOutOfRangeExceptioninstead. Consumers that allow reordering trees throwing "the same single exception" (CallArgs::ArgsComplete, forward substitution, LIR side effect sets) could therefore reorder such a check with a real array/string bounds check, changing which exception is observed. E.g. inCallee("abc"[i], v.GetElement(j) * ...)the call args got sorted so thatGetElement(j)threwArgumentOutOfRangeExceptionbefore"abc"[i]threwIndexOutOfRangeException.Add
ArgumentExceptionandArgumentOutOfRangeExceptiontoExceptionSetFlagsand map each bounds check throw kind to its precise exception. The debug-code check inArgsCompletethat treats inline-throwing args like calls is updated to keep covering these bounds checks.Fixes #137637