Skip to content

Add ILVerify tests for exception-handling errors - #136023

Merged
jkotas merged 1 commit into
dotnet:mainfrom
pcshrosbree:test/ilverify-invalid-tests-1
Oct 18, 2026
Merged

jkotas merged 1 commit into
dotnet:mainfrom
pcshrosbree:test/ilverify-invalid-tests-1

Conversation

@pcshrosbree

Copy link
Copy Markdown
Contributor

At main 4211829, 42 VerifierError codes are not listed in any _Invalid_ or _InvalidType_ test name in ILVerification.Tests. This is the first of a few small batches that add tests for those codes. It covers five exception-handling codes, all in ExceptionRegionTests.il.

New test Expected error
Rethrow.InFinally_Invalid_Rethrow Rethrow
Catch.EndsWithEndfinally_Invalid_Endfinally Endfinally
Catch.BranchOut_Invalid_BranchOutOfHandler BranchOutOfHandler
Filter.HandlerEndsWithEndfilter_Invalid_Endfilter Endfilter
Filter.ExceptionLeftOnStack_Invalid_EndfilterStack EndfilterStack

Each 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 used rethrow before, so nothing checked that a rethrow inside 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:

  • FilterOrCatchUnexpectedStack and FinOrFaultNonEmptyStack: 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 as PathStackDepth.
  • CatchByRef: a catch clause's type token cannot resolve to a byref type. A byref TypeSpec is rejected first, with BadTypeSpec.

Validation

I used main at 4211829 as the base, with linux-x64 and SDK 11.0.100-rc.1.26420.103.

Tree Result (passed/total)
main unchanged 502/502
this change 508/508

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

  • For each new invalid test, I disabled the check in ILImporter.Verify.cs that reports its expected error. Each time, the run was 507/508 and the only failure was that test, with no errors reported. Disabling the early return for catch handlers in ImportRethrow made Rethrow.InCatch the only failure, with a Rethrow error.
  • For each new invalid test, I changed the expected error in its name to a different code. Each time, the run was 507/508 and the only failure was that test, which reported its original error.

For both trees in the table, and for each temporary edit, I ran these commands (shown without nice -n 10 and 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=false

Note

This PR was prepared with AI assistance (Anthropic Claude and OpenAI Codex), under my direction. I reviewed it before posting.

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.
@github-actions github-actions Bot added the area-ExceptionHandling-coreclr only use for closed issues label Oct 18, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 18, 2026
@azure-pipelines

Copy link
Copy Markdown
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.

@jkotas jkotas added area-Tools-ILVerification Issues related to ilverify tool and IL verification in general and removed area-ExceptionHandling-coreclr only use for closed issues labels Oct 18, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib
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 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 rethrow case.
  • 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

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

Thanks

@jkotas
jkotas merged commit 8fc62c3 into dotnet:main Oct 18, 2026
119 of 121 checks passed
@pcshrosbree

Copy link
Copy Markdown
Contributor Author

Thank you for the review and merge!

@pcshrosbree
pcshrosbree deleted the test/ilverify-invalid-tests-1 branch October 18, 2026 06:18
@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-Tools-ILVerification Issues related to ilverify tool and IL verification in general community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants