-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JIT: remove incorrect type deduction for an Unsafe.As case (#93694)
Thanks to @SingleAccretion for the fix. The JIT was assuming that an indirectly accessed value type field had the type of the field, but that might not be the case if the field was accessed via `Unsafe.As`. Fix this by limiting type deduction from these indirectly accessed fields to only ref type fields. Closes #93650.
- Loading branch information
1 parent
fa3babd
commit 90c417a
Showing
3 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
42 changes: 42 additions & 0 deletions
42
src/tests/JIT/Regression/JitBlue/Runtime_93650/Runtime_93650.cs
This file contains 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,42 @@ | ||
// 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.Runtime.CompilerServices; | ||
using System.Text; | ||
using Xunit; | ||
|
||
public struct Holder | ||
{ | ||
internal StringBuilder.AppendInterpolatedStringHandler _h; | ||
public Holder() => _h = new(0, 0, new()); | ||
|
||
internal StringBuilder GetBuilder() => Unsafe.As<StringBuilder.AppendInterpolatedStringHandler, StringBuilder>(ref _h); | ||
} | ||
|
||
public static class Runtime_93650 | ||
{ | ||
static int N = 1; | ||
|
||
[Fact] | ||
public static int Problem() | ||
{ | ||
var sb = new Holder(); | ||
for (int i = 0; i < N; i++) | ||
{ | ||
var s = Bind(ref sb); | ||
if (s.Length != 0) | ||
{ | ||
Console.WriteLine("FAILED: StringBuilder.ToString() returned: " + s); | ||
return -1; | ||
} | ||
} | ||
|
||
return 100; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
public static string Bind(ref Holder parameters) => GetString(parameters.GetBuilder()); | ||
|
||
public static string GetString(StringBuilder sb) => sb.ToString(); | ||
} |
8 changes: 8 additions & 0 deletions
8
src/tests/JIT/Regression/JitBlue/Runtime_93650/Runtime_93650.csproj
This file contains 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,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
</Project> |