Allow constrained. call and ldftn for static virtual interface methods in ILVerify - #132944
Merged
Conversation
|
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
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped, adds a targeted new verifier diagnostic with resources, and includes tests that cover both the accepted patterns and the new failure mode.
Pull request overview
This PR updates the CoreCLR ILVerify importer to recognize and validate the IL pattern used for static virtual interface method dispatch via a constrained type (e.g., constrained. !!T followed by call / ldftn), and introduces a dedicated verifier error when the constrained type cannot be proven to implement the target interface.
Changes:
- Teach
ILImporter.Verifyto consumeconstrained.oncall/ldftntargeting astatic virtualinterface method, instead of reportingConstrained/CallAbstract. - Add a new verifier error (
ConstrainedTypeNoInterfaceImpl) and resource string for the new validation rule. - Extend
PrefixTests.ilwith valid/invalid IL cases covering bothcallandldftnscenarios.
File summaries
| File | Description |
|---|---|
| src/coreclr/tools/ILVerification/ILImporter.Verify.cs | Consumes constrained. for static-virtual interface call/ldftn, relaxes CallAbstract only for that scenario, and validates interface implementation via CanCastTo. |
| src/coreclr/tools/ILVerification/VerifierError.cs | Adds ConstrainedTypeNoInterfaceImpl to the verifier error enum. |
| src/coreclr/tools/ILVerification/Strings.resx | Adds the localized message for ConstrainedTypeNoInterfaceImpl. |
| src/coreclr/tools/ILVerification.Tests/ILTests/PrefixTests.il | Adds coverage for valid/invalid constrained static-virtual interface call and ldftn patterns. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
Member
|
/ba-g known issue #132947 that has been fixed already |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #132820
ILVerify predates static virtual interface methods, so the IL Roslyn emits for
T.M()(constrained. !!Tfollowed bycall) gets flagged with bogusConstrainedandCallAbstracterrors.Consume the
constrained.prefix oncallwhen the target is a static virtual method on an interface, and check that the constrained type actually implements that interface (newConstrainedTypeNoInterfaceImplerror).Tests added to PrefixTests.il.