-
Notifications
You must be signed in to change notification settings - Fork 5.5k
JIT: Fix CEA cloning when enumerator local is reassigned from an untracked source #127079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+82
−0
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c73106e
JIT: Fix CEA cloning when enumerator local is reassigned from an unre…
EgorBo 3901ce4
Strengthen regression test: use <>z__ReadOnlyArray wrapper for second…
EgorBo 024d95d
TEMP: comment out fix to verify CI catches the bug
EgorBo a9d7a52
Update objectalloc.cpp
EgorBo 1501e11
Merge branch 'main' into fix-127075-cea-enumerator-reuse
EgorBo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
51 changes: 51 additions & 0 deletions
51
src/tests/JIT/Regression/JitBlue/Runtime_127075/Runtime_127075.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Threading; | ||
| using Xunit; | ||
|
|
||
| public class Runtime_127075 | ||
| { | ||
| public interface I; | ||
| public sealed class A : I; | ||
| public sealed class B : I; | ||
|
|
||
| // Roslyn lowers this collection literal stored to IReadOnlyCollection<I> | ||
| // into a `new <>z__ReadOnlyArray<I>(new I[]{...})` wrapper. The wrapper's | ||
| // GetEnumerator() does NOT devirtualize even under PGO (the array element | ||
| // type is inexact), so it stays as a virtual call. That is what triggered | ||
| // the bug: the second loop's enumerator local store was hidden from | ||
| // conditional escape analysis. | ||
| // | ||
| private static readonly IReadOnlyCollection<I> s_tail = [new B(), new B()]; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static I[] Combine(IReadOnlyCollection<I> head) | ||
| { | ||
| return [.. head, .. s_tail]; | ||
| } | ||
|
|
||
| [Fact] | ||
| public static void TestEntryPoint() | ||
| { | ||
| I[] head = [new A(), new A(), new A(), new A()]; | ||
| for (int i = 0; i < 300; i++) | ||
| { | ||
| I[] result = Combine(head); | ||
| Assert.Equal(head.Length + s_tail.Count, result.Length); | ||
| for (int j = 0; j < head.Length; j++) | ||
| { | ||
| Assert.Same(head[j], result[j]); | ||
| } | ||
| int k = head.Length; | ||
| foreach (I t in s_tail) | ||
| { | ||
| Assert.Same(t, result[k++]); | ||
| } | ||
| Thread.Sleep(1); | ||
| } | ||
| } | ||
| } | ||
16 changes: 16 additions & 0 deletions
16
src/tests/JIT/Regression/JitBlue/Runtime_127075/Runtime_127075.csproj
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <Optimize>True</Optimize> | ||
| <!-- Needed for CLRTestEnvironmentVariable --> | ||
| <RequiresProcessIsolation>true</RequiresProcessIsolation> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).cs" /> | ||
| <!-- The issue reproduces only with tiered compilation and PGO enabled, | ||
| and with QuickJitForLoops enabled so the spread method is instrumented | ||
| in Tier-0 before being promoted to Tier-1 with PGO data. --> | ||
| <CLRTestEnvironmentVariable Include="DOTNET_TieredCompilation" Value="1" /> | ||
| <CLRTestEnvironmentVariable Include="DOTNET_TieredPGO" Value="1" /> | ||
| <CLRTestEnvironmentVariable Include="DOTNET_TC_QuickJitForLoops" Value="1" /> | ||
| </ItemGroup> | ||
| </Project> |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.