[release/10.0] JIT: Fix CEA cloning when enumerator local is reassigned from an untracked source#128909
Open
github-actions[bot] wants to merge 4 commits into
Open
[release/10.0] JIT: Fix CEA cloning when enumerator local is reassigned from an untracked source#128909github-actions[bot] wants to merge 4 commits into
github-actions[bot] wants to merge 4 commits into
Conversation
…cognized source In the conditional escape analysis (CEA) pipeline for GDV-guarded enumerator allocations, CheckForGuardedAllocationOrCopy only recorded stores whose data was GT_ALLOCOBJ, GT_LCL_VAR, or GT_BOX. Stores whose data was something else (e.g. a non-devirtualized virtual call) were silently ignored, so a reassignment of the enumerator local in a second spread loop was never recorded as a def. CheckCanClone therefore saw the local as single-def and proceeded to clone, renaming all uses of the local in the cloned region to a new local that held the first allocation. The second loop's body ended up iterating over the first source array. Record such stores as appearances so the multiple-defs check fires and we bail out of unsafe cloning. Skip null/zero constant stores: the inliner emits these to clear dead inlinee gc-ref temps and treating them as real defs would pessimize unrelated methods. Fixes #127075
… source Direct I[] -> IReadOnlyCollection<I> assignment lets Tier1+PGO devirt the second GetEnumerator() into an inlined SZGenericArrayEnumerator allocation, so the buggy code path (where the second store is a non-devirt virtual call into the shared enumerator local) never executes and the test passes even against the broken JIT. Storing a collection literal directly to the interface type forces Roslyn's <>z__ReadOnlyArray<I> wrapper, whose GetEnumerator() remains a virtual call and exercises the fix.
AndyAyersMS
approved these changes
Jun 2, 2026
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.
Backport of #127079 to release/10.0
/cc @EgorBo
Customer Impact
Customer-reported (#127075). Silent data loss: a C# collection expression spread with two sources,
[.. a, .. b], miscompiles under Tier1 + PGO. The result array has the correct length but the tail elements coming from the second source are left at their default value (nullfor reference types) because the second copy loop becomes dead code.A bug in JIT's escape analysis.
Regression
Introduced in .NET 10
Testing
Added a standalone JIT regression test (
src/tests/JIT/Regression/JitBlue/Runtime_127075) that reproduces the wrong codegen under Tier1 + PGO.Risk
Low