Skip to content

Commit

Permalink
Test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo committed Feb 2, 2022
1 parent 6fc39ae commit b321357
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ void CodeGen::genCodeForNullCheck(GenTreeIndir* tree)
genConsumeRegs(op1);
regNumber targetReg = REG_ZR;

GetEmitter()->emitInsLoadStoreOp(INS_ldr, EA_4BYTE, targetReg, tree);
GetEmitter()->emitInsLoadStoreOp(ins_Load(tree->TypeGet()), emitActualTypeSize(tree), targetReg, tree);
#endif
}

Expand Down
1 change: 0 additions & 1 deletion src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9735,7 +9735,6 @@ void Compiler::gtChangeOperToNullCheck(GenTree* tree, BasicBlock* block)
{
assert(tree->OperIs(GT_FIELD, GT_IND, GT_OBJ, GT_BLK));
tree->ChangeOper(GT_NULLCHECK);
tree->ChangeType(TYP_INT);
block->bbFlags |= BBF_HAS_NULLCHECK;
optMethodFlags |= OMF_HAS_NULLCHECK;
}
Expand Down
7 changes: 0 additions & 7 deletions src/coreclr/jit/emitarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6993,13 +6993,6 @@ void emitter::emitIns_R_R_R_Ext(instruction ins,
shiftAmount = insOptsLSL(opt) ? scale : 0;
}

// If target reg is ZR - it means we're doing an implicit nullcheck
// where target type was ignored and set to TYP_INT.
if ((reg1 == REG_ZR) && (shiftAmount > 0))
{
shiftAmount = scale;
}

assert((shiftAmount == scale) || (shiftAmount == 0));

reg2 = encodingSPtoZR(reg2);
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6855,7 +6855,6 @@ void Lowering::TransformUnusedIndirection(GenTreeIndir* ind, Compiler* comp, Bas
//
assert(ind->OperIs(GT_NULLCHECK, GT_IND, GT_BLK, GT_OBJ));

ind->gtType = TYP_INT;
#ifdef TARGET_ARM64
bool useNullCheck = true;
#elif TARGET_ARM
Expand Down
42 changes: 42 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_64657/Runtime_64657.cs
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.InteropServices;
using System.Runtime.CompilerServices;

public class Runtime_64657
{
[DllImport("kernel32")]
public static extern byte* VirtualAlloc(IntPtr lpAddress, nuint dwSize, uint flAllocationType, uint flProtect);

[MethodImpl(MethodImplOptions.NoInlining)]
static void Validate<T>(T* c, int x) where T : unmanaged
{
// this nullcheck should not read more than requested
T implicitNullcheck = c[x];
}

public static int Main()
{
if (!OperatingSystem.IsWindows())
return 100; // VirtualAlloc is only for Windows

uint length = (uint)Environment.SystemPageSize;
byte* ptr = VirtualAlloc(IntPtr.Zero, length, 0x1000 | 0x2000 /* reserve commit */, 0x04 /*readonly guard*/);

Validate((byte*)(ptr + length - sizeof(byte)), 0);
Validate((sbyte*)(ptr + length - sizeof(sbyte)), 0);
Validate((bool*)(ptr + length - sizeof(bool)), 0);
Validate((ushort*)(ptr + length - sizeof(ushort)), 0);
Validate((short*)(ptr + length - sizeof(short)), 0);
Validate((uint*)(ptr + length - sizeof(uint)), 0);
Validate((int*)(ptr + length - sizeof(int)), 0);
Validate((ulong*)(ptr + length - sizeof(ulong)), 0);
Validate((long*)(ptr + length - sizeof(long)), 0);
Validate((nint*)(ptr + length - sizeof(nint)), 0);
Validate((nuint*)(ptr + length - sizeof(nuint)), 0);

return 100;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>

0 comments on commit b321357

Please sign in to comment.