Repository navigation
Add ILVerify tests for exception-handling errors - #136023
Merged
Merged
Conversation
Add one invalid-IL test to ExceptionRegionTests.il for each of Rethrow, Endfinally, Endfilter, BranchOutOfHandler and EndfilterStack. No test expected any of these codes before. Each new invalid test expects exactly that one error. Also add a valid test with rethrow inside a catch handler. No test used rethrow before, so nothing covered the accepted case.
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 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, @dotnet/jit-contrib |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused test additions match the verifier checks and existing test harness contracts, with no unresolved findings.
No open issues 🎉
What changed in this PR
Adds focused exception-handling coverage to ILVerify’s existing test suite without changing production code.
Changes:
- Adds five invalid IL cases covering previously untested verifier errors.
- Adds a valid catch-handler
rethrowcase. - Uses existing test-name conventions to specify expected errors.
The changes are narrowly scoped and have no identified blocking issues. Builds and tests were not rerun during this review.
| File | Description |
|---|---|
src/coreclr/tools/ILVerification.Tests/ILTests/ExceptionRegionTests.il |
Adds six exception-handling verification cases. |
Review effort: Balanced
Contributor
Author
|
Thank you for the review and merge! |
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.
At
main4211829, 42VerifierErrorcodes are not listed in any_Invalid_or_InvalidType_test name inILVerification.Tests. This is the first of a few small batches that add tests for those codes. It covers five exception-handling codes, all inExceptionRegionTests.il.Rethrow.InFinally_Invalid_RethrowRethrowCatch.EndsWithEndfinally_Invalid_EndfinallyEndfinallyCatch.BranchOut_Invalid_BranchOutOfHandlerBranchOutOfHandlerFilter.HandlerEndsWithEndfilter_Invalid_EndfilterEndfilterFilter.ExceptionLeftOnStack_Invalid_EndfilterStackEndfilterStackEach new invalid test expects exactly one error, so it fails if that error is missing or if any other error is also reported. I also added
Rethrow.InCatch_Valid. No test usedrethrowbefore, so nothing checked that arethrowinside a catch handler is accepted.I looked at three more exception-handling codes and left them out, because I could not write IL that reports them:
FilterOrCatchUnexpectedStackandFinOrFaultNonEmptyStack: the importer sets a handler's entry stack when it first imports the handler. The only valid branches to a handler's first instruction come from inside that handler. Those branches are imported after the entry stack has been set, so a depth mismatch is then reported asPathStackDepth.CatchByRef: a catch clause's type token cannot resolve to a byref type. A byref TypeSpec is rejected first, withBadTypeSpec.Validation
I used
mainat 4211829 as the base, with linux-x64 and SDK 11.0.100-rc.1.26420.103.mainunchangedTo check that each new test can fail, I made two kinds of temporary edit, one at a time. These edits are not part of this change.
ILImporter.Verify.csthat reports its expected error. Each time, the run was 507/508 and the only failure was that test, with no errors reported. Disabling the earlyreturnfor catch handlers inImportRethrowmadeRethrow.InCatchthe only failure, with aRethrowerror.For both trees in the table, and for each temporary edit, I ran these commands (shown without
nice -n 10and the test command's TRX logger option):./dotnet.sh build src/coreclr/tools/ILVerification.Tests/ILVerification.Tests.csproj -c Release -m:4 /p:NuGetAudit=false ./dotnet.sh test src/coreclr/tools/ILVerification.Tests/ILVerification.Tests.csproj -c Release --no-build /p:NuGetAudit=falseNote
This PR was prepared with AI assistance (Anthropic Claude and OpenAI Codex), under my direction. I reviewed it before posting.