[release/8.0] JIT: Disallow mismatched GC-ness for physical promotions #90739
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.
Backport of #90694 to release/8.0
/cc @jakobbotsch
Customer Impact
Code that involves illegal reinterpretations of GC pointers in unreachable code paths can cause the JIT to generate code with incorrect GC reporting, even in the reachable paths.
For example, MemoryMarshal.Contains is a case. When
value
is a GC pointer,RuntimeHelpers.IsBitwiseEquatable<T>()
will return false, but under some stress scenarios the JIT will still see the laterUnsafe.As<T, long>(ref value)
. This can cause it to mistakenly reinterpretvalue
as a long without any GC reporting, even outside theRuntimeHelpers.IsBitwiseEquatable<T>()
branch.For this particular case, in normal circumstances (no stress modes) the unreachable code is folded away early enough that the JIT does not see the reinterpretation, so no issue happens.
Testing
Verified that the failing test case now generates correct code and GC reporting, even when the stress variables are set.
Risk
Low. Targeted fix with no diffs in any of our own code (under non stress circumstances) that disables physical promotion when the case is detected.