Skip to content

Fix ILVerify crash on callvirt to a static method - #135772

Merged
jkotas merged 1 commit into
dotnet:mainfrom
pcshrosbree:fix/ilverify-callvirt-static
Oct 14, 2026
Merged

jkotas merged 1 commit into
dotnet:mainfrom
pcshrosbree:fix/ilverify-callvirt-static

Conversation

@pcshrosbree

Copy link
Copy Markdown
Contributor

Problem: when the target of a callvirt is a static method, ILVerify throws NullReferenceException in ImportCall. 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 CallVirtOnStatic check a FatalCheck. methodType is null for a static target, and the next line, the CallVirtOnValueType check, dereferences it. With the change, the method fails with CallVirtOnStatic and 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_CallVirtOnStatic calls the static SimpleClass::InObjectMethod(object&) with callvirt. It passes a byref local of the parameter's type, so CallVirtOnStatic is the only error in the method. ilasm adds instance to the signature of a callvirt target written by name, so the test names the MethodDef by token.

ILVerification.Tests, on main at 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 test on the same project with --no-build:

Tree Configuration Result
main unchanged Release 468/468
main unchanged Debug 468/468
this change Release 469/469
this change Debug 469/469
new test with the fix reverted Release 468/469; the new test fails with the NullReferenceException

ILVerify CLI, built from this branch and from its parent, on the repro from the issue:

  • before: NullReferenceException, exit code 1;
  • after: CallVirtOnStatic at offset 1 in CallvirtStatic, then the ReturnVoid error in Later; exit code 2.

Scope

This changes only the callvirt check in ImportCall, 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.

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.
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 14, 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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

@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 added area-Tools-ILVerification Issues related to ilverify tool and IL verification in general and removed area-VM-coreclr labels Oct 14, 2026
@jkotas

jkotas commented Oct 14, 2026

Copy link
Copy Markdown
Member

/ba-g Opened #135795 on the test failure

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

@jkotas
jkotas merged commit b6a58f9 into dotnet:main Oct 14, 2026
139 of 141 checks passed
@pcshrosbree

Copy link
Copy Markdown
Contributor Author

Thank you for the quick review and merge!

@pcshrosbree
pcshrosbree deleted the fix/ilverify-callvirt-static branch October 14, 2026 22:03
@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.

ILVerify throws NullReferenceException on a callvirt to a static method

2 participants