Repository navigation
Fix ILVerify crash on callvirt to a static method - #135772
Merged
Merged
Conversation
A callvirt whose target is a static method reported CallVirtOnStatic and then dereferenced the null owning type in the CallVirtOnValueType check, so a NullReferenceException escaped Verifier.Verify. Make the CallVirtOnStatic check fatal, and add a regression test.
|
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: @agocke |
This was referenced Oct 14, 2026
Closed
Member
|
/ba-g Opened #135795 on the test failure |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib |
Contributor
Author
|
Thank you for the quick 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.
Problem: when the target of a
callvirtis a static method, ILVerify throwsNullReferenceExceptioninImportCall. That stops the CLI from completing the assembly: later methods and the type pass are not verified. The repro is in the linked issue.Fix: make the
CallVirtOnStaticcheck aFatalCheck.methodTypeis null for a static target, and the next line, theCallVirtOnValueTypecheck, dereferences it. With the change, the method fails withCallVirtOnStaticand verification continues with the next method.I stopped verification of the method rather than only skipping the value-type check. The IL may or may not have pushed a receiver for the static target, so verifying the rest of the call as a static call could report stack errors that follow from that guess. The nearest precedent, #135445, guarded the dereference and continued; there both delegate constructor operands had already been popped, so the stack after the instruction did not depend on a guess.
Validation
New test in
CallTests.il:Callvirt.StaticMethod_Invalid_CallVirtOnStaticcalls the staticSimpleClass::InObjectMethod(object&)withcallvirt. It passes a byref local of the parameter's type, soCallVirtOnStaticis the only error in the method. ilasm addsinstanceto the signature of acallvirttarget written by name, so the test names theMethodDefby token.ILVerification.Tests, on
mainat 6d39701, with linux-x64 and SDK 11.0.100-rc.1.26420.103. Each row ran./dotnet.sh build src/coreclr/tools/ILVerification.Tests/ILVerification.Tests.csproj -c <config>, then./dotnet.sh teston the same project with--no-build:mainunchangedmainunchangedNullReferenceExceptionILVerifyCLI, built from this branch and from its parent, on the repro from the issue:NullReferenceException, exit code 1;CallVirtOnStaticat offset 1 inCallvirtStatic, then theReturnVoiderror inLater; exit code 2.Scope
This changes only the
callvirtcheck inImportCall, and adds the test.Resolves #135771
Note
This PR was prepared with AI assistance (Anthropic Claude and OpenAI Codex), under my direction. I reviewed it before posting.