Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix fgValueNumberArrIndexVal for wide reads
  • Loading branch information
EgorBo committed Aug 28, 2021
commit 50d18ed983c17df6e19775f6705bc7ac11a003fd
4 changes: 2 additions & 2 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4243,10 +4243,10 @@ ValueNum Compiler::fgValueNumberArrIndexVal(GenTree* tree,
var_types indType = (tree == nullptr) ? elemTyp : tree->TypeGet();
ValueNum selectedElem;

if (fldSeq == FieldSeqStore::NotAField())
if ((fldSeq == FieldSeqStore::NotAField()) || (genTypeSize(indType) > genTypeSize(elemTyp)))
{
// This doesn't represent a proper array access
JITDUMP(" *** NotAField sequence encountered in fgValueNumberArrIndexVal\n");
JITDUMP(" *** Not a proper arrray access encountered in fgValueNumberArrIndexVal\n");

// a new unique value number
selectedElem = vnStore->VNForExpr(compCurBB, elemTyp);
Expand Down
48 changes: 48 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_57914/Runtime_57914.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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;

public class Program
{
public static int Main()
{
return (Test1() && Test2()) ? 100 : 101;
}

private static bool Test1()
{
byte[] arr = new byte[2];
arr[0] = 1;
arr[1] = 2;

short a1 = Unsafe.ReadUnaligned<short>(ref arr[0]);
arr[1] = 42;
short a2 = Unsafe.ReadUnaligned<short>(ref arr[0]);

return a1 != a2;
}

private static bool Test2()
{
bool result = true;
byte[] buffer = new byte[4];
buffer[0] = 0x1;
buffer[1] = 0x2;
buffer[2] = 0x3;
buffer[3] = 0x4;

if (buffer.Length > 0)
{
int n = Unsafe.ReadUnaligned<int>(ref buffer[0]);
if (n != 0x4030201)
result = false;
Consume(n);
}
return result;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static void Consume(int n) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>
<PropertyGroup>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>