Skip to content

Commit

Permalink
Use unsigned cast for Span_get_Item
Browse files Browse the repository at this point in the history
  • Loading branch information
pentp committed Sep 16, 2021
1 parent cc768d2 commit e45e445
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4150,7 +4150,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
GenTree* ptrToSpan = impPopStack().val;
GenTree* indexClone = nullptr;
GenTree* ptrToSpanClone = nullptr;
assert(varTypeIsIntegral(index));
assert(genActualType(index) == TYP_INT);
assert(ptrToSpan->TypeGet() == TYP_BYREF);

#if defined(DEBUG)
Expand All @@ -4177,12 +4177,25 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
GenTreeBoundsChk(GT_ARR_BOUNDS_CHECK, TYP_VOID, index, length, SCK_RNGCHK_FAIL);

// Element access
index = impImplicitIorI4Cast(indexClone, TYP_I_IMPL);
index = indexClone;

#ifdef TARGET_64BIT
if (index->OperGet() == GT_CNS_INT)
{
index->gtType = TYP_I_IMPL;
}
else
{
index = gtNewCastNode(TYP_I_IMPL, index, true, TYP_I_IMPL);
}
#endif

if (elemSize != 1)
{
GenTree* sizeofNode = gtNewIconNode(elemSize);
index = gtNewOperNode(GT_MUL, TYP_I_IMPL, index, sizeofNode);
}

CORINFO_FIELD_HANDLE ptrHnd = info.compCompHnd->getFieldInClass(clsHnd, 0);
const unsigned ptrOffset = info.compCompHnd->getFieldOffset(ptrHnd);
GenTree* data = gtNewFieldRef(TYP_BYREF, ptrHnd, ptrToSpanClone, ptrOffset);
Expand Down

0 comments on commit e45e445

Please sign in to comment.