[clr-interp] allow modification of the this pointer in functions which use it as the generics context#119554
Merged
davidwrighton merged 9 commits intodotnet:mainfrom Sep 11, 2025
Merged
Conversation
…h use it as the generics context - When the this pointer is used as the generics context, if some code modifies the this pointer, do not allow that modification to affect the generics behavior of the function - Implement this by making a shadow copy of the this pointer in this situation - To avoid doing this ALL of the time, I've added a scheme where we can restart the entire method compilation by setting a flag which describes the current set of retry rules.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR implements a fix for CLR interpreter's handling of generic methods that use the "this" pointer as the generics context. The change addresses a scenario where modifications to the "this" pointer during method execution could incorrectly affect the generics behavior.
Key Changes:
- Creates a shadow copy of the "this" pointer when it's used as the generics context in generic methods
- Implements lazy evaluation - reserves space for the shadow copy but only uses it if the "this" pointer is actually modified
- Adds null reference checking for the generics context when derived from "this"
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/coreclr/vm/codeman.cpp | Adds null reference checking for "this"-derived generics context |
| src/coreclr/interpreter/compiler.h | Adds tracking variables for shadow copy state |
| src/coreclr/interpreter/compiler.cpp | Implements shadow copy logic, variable management, and GC reporting |
Contributor
|
Tagging subscribers to this area: @BrzVlad, @janvorli, @kg |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
69 tasks
kg
reviewed
Sep 10, 2025
kg
reviewed
Sep 10, 2025
kg
reviewed
Sep 10, 2025
Address feedback from @kg
Co-authored-by: Jan Vorlicek <jan.vorlicek@volny.cz>
BrzVlad
reviewed
Sep 11, 2025
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.
This is a new PR replacing #119338, since I fouled up a merge in that PR.