-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Reject folding local addresses the emitter cannot encode #130990
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
Open
tannergooding
wants to merge
4
commits into
dotnet:main
Choose a base branch
from
tannergooding:tannergooding-fix-minopts-avx512-invalidprogram
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+97
−13
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
342786c
Reject folding local addresses the emitter cannot encode
tannergooding 73bd905
Validate the resulting offset when folding local addresses
tannergooding 6215204
Add regression test for large-local block-init encoding
tannergooding b84d42c
Avoid signed-overflow when validating folded local offsets
tannergooding 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
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
53 changes: 53 additions & 0 deletions
53
src/tests/JIT/Regression/JitBlue/Runtime_126584/Runtime_126584.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,53 @@ | ||
| // 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.Reflection.Emit; | ||
| using TestLibrary; | ||
| using Xunit; | ||
|
|
||
| // A struct large enough that initializing it reaches offsets >= 256. | ||
| public struct Big_126584 | ||
| { | ||
| public long A0, A1, A2, A3, A4, A5, A6, A7, A8, A9; | ||
| public long A10, A11, A12, A13, A14, A15, A16, A17, A18, A19; | ||
| public long A20, A21, A22, A23, A24, A25, A26, A27, A28, A29; | ||
| public long A30, A31, A32, A33, A34, A35, A36, A37, A38, A39; | ||
| } | ||
|
|
||
| public class Runtime_126584 | ||
| { | ||
| // The emitter can only encode byte-sized offsets for locals numbered >= 32768. A struct | ||
| // block-init of such a local reaching offset >= 256 must not be folded into the stack | ||
| // addressing form, which the emitter cannot encode. Reflection.Emit is used to build a | ||
| // method with enough locals to push the struct past that boundary without a huge source file. | ||
| [ConditionalFact(typeof(Utilities), nameof(Utilities.IsReflectionEmitSupported))] | ||
| public static void TestEntryPoint() | ||
| { | ||
| var method = new DynamicMethod("M0", typeof(long), new[] { typeof(bool) }, typeof(Runtime_126584).Module); | ||
| ILGenerator il = method.GetILGenerator(); | ||
|
|
||
| const int DummyLocalCount = 33000; | ||
| for (int i = 0; i < DummyLocalCount; i++) | ||
| { | ||
| il.DeclareLocal(typeof(int)); | ||
| } | ||
| LocalBuilder big = il.DeclareLocal(typeof(Big_126584)); | ||
|
|
||
| // Initialize the struct behind a branch so it isn't hoisted into the prolog. | ||
| Label skip = il.DefineLabel(); | ||
| il.Emit(OpCodes.Ldarg_0); | ||
| il.Emit(OpCodes.Brfalse, skip); | ||
| il.Emit(OpCodes.Ldloca, big); | ||
| il.Emit(OpCodes.Initobj, typeof(Big_126584)); | ||
| il.MarkLabel(skip); | ||
|
|
||
| // Read a field past offset 255 so the access survives. | ||
| il.Emit(OpCodes.Ldloca, big); | ||
| il.Emit(OpCodes.Ldfld, typeof(Big_126584).GetField(nameof(Big_126584.A39))); | ||
| il.Emit(OpCodes.Ret); | ||
|
|
||
| var func = (Func<bool, long>)method.CreateDelegate(typeof(Func<bool, long>)); | ||
| Assert.Equal(0, func(true)); | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
src/tests/JIT/Regression/JitBlue/Runtime_126584/Runtime_126584.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> | ||
| <!-- Needed for CLRTestEnvironmentVariable --> | ||
| <RequiresProcessIsolation>true</RequiresProcessIsolation> | ||
| <CLRTestPriority>1</CLRTestPriority> | ||
|
tannergooding marked this conversation as resolved.
|
||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).cs" /> | ||
|
|
||
| <!-- Force the MinOpts path where the emitter encoding limit was hit. --> | ||
| <CLRTestEnvironmentVariable Include="DOTNET_JITMinOpts" Value="1" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="$(TestLibraryProjectPath)" /> | ||
| </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.