[clr-interp] Fail with a BADCODE if the opcode is unknown#120391
Merged
davidwrighton merged 1 commit intodotnet:mainfrom Oct 7, 2025
Merged
[clr-interp] Fail with a BADCODE if the opcode is unknown#120391davidwrighton merged 1 commit intodotnet:mainfrom
davidwrighton merged 1 commit intodotnet:mainfrom
Conversation
Member
davidwrighton
commented
Oct 3, 2025
- Fail with BADCODE instead of asserting, which allows us to complete running some of the test suites, and will actually do the desired thing in actual retail builds.
- Also protect against unsafe memory access by bounds checking in CEEOpName
- Fail with BADCODE instead of asserting, which allows us to complete running some of the test suites, and will actually do the desired thing in actual retail builds. - Also protect against unsafe memory access by bounds checking in CEEOpName
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR improves error handling in the CLR interpreter by replacing assertion failures with proper BADCODE exceptions when encountering unknown opcodes. This allows test suites to complete execution rather than crashing on unsupported operations.
- Replace
assert()calls withBADCODE()macro for unknown opcodes and unsupported static field accessors - Add bounds checking in
CEEOpName()to prevent unsafe memory access when looking up opcode names - Wrap debug output in
#ifdef DEBUGto reduce overhead in release builds
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/interpreter/intops.cpp | Added bounds checking to prevent array access beyond valid opcode range |
| src/coreclr/interpreter/compiler.cpp | Replaced assertions with BADCODE exceptions and added debug-only output |
kg
approved these changes
Oct 3, 2025
Member
|
Will using BADCODE break fallback to JIT? |
janvorli
approved these changes
Oct 3, 2025
Member
Author
|
Maybe, but we don't really want that fallback if it isn't fixing things, and the current path is just an assert which is just wrong. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.