Skip to content

Commit

Permalink
Fix JIT/SPMI CodeQL issues (#107056)
Browse files Browse the repository at this point in the history
  • Loading branch information
amanasifkhalid authored Aug 28, 2024
1 parent 7ff684a commit 8d24ba3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/jit/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8361,7 +8361,7 @@ void emitter::emitDispDataSec(dataSecDsc* section, BYTE* dst)
bool isRelative = (data->dsType == dataSection::blockRelative32);
size_t blockCount = data->dsSize / (isRelative ? 4 : TARGET_POINTER_SIZE);

for (unsigned i = 0; i < blockCount; i++)
for (size_t i = 0; i < blockCount; i++)
{
if (i > 0)
{
Expand Down
38 changes: 17 additions & 21 deletions src/coreclr/jit/lowerxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4845,8 +4845,6 @@ GenTree* Lowering::LowerHWIntrinsicCreate(GenTreeHWIntrinsic* node)
case TYP_INT:
case TYP_UINT:
{
unsigned N = 0;
GenTree* opN = nullptr;
NamedIntrinsic insIntrinsic = NI_Illegal;

if ((simdBaseType == TYP_SHORT) || (simdBaseType == TYP_USHORT))
Expand All @@ -4861,7 +4859,7 @@ GenTree* Lowering::LowerHWIntrinsicCreate(GenTreeHWIntrinsic* node)

if (insIntrinsic != NI_Illegal)
{
for (N = 1; N < argCnt - 1; N++)
for (size_t N = 1; N < argCnt - 1; N++)
{
// We will be constructing the following parts:
// ...
Expand All @@ -4877,7 +4875,7 @@ GenTree* Lowering::LowerHWIntrinsicCreate(GenTreeHWIntrinsic* node)
// tmp1 = Sse?.Insert(tmp1, opN, N);
// ...

opN = node->Op(N + 1);
GenTree* opN = node->Op(N + 1);

idx = comp->gtNewIconNode(N, TYP_INT);
// Place the insert as early as possible to avoid creating a lot of long lifetimes.
Expand All @@ -4889,26 +4887,24 @@ GenTree* Lowering::LowerHWIntrinsicCreate(GenTreeHWIntrinsic* node)
LowerNode(tmp1);
}

assert(N == (argCnt - 1));

// We will be constructing the following parts:
// idx = CNS_INT int N
// /--* tmp1 simd16
// +--* opN T
// +--* idx int
// idx = CNS_INT int (argCnt - 1)
// /--* tmp1 simd16
// +--* lastOp T
// +--* idx int
// node = * HWINTRINSIC simd16 T Insert

// This is roughly the following managed code:
// ...
// tmp1 = Sse?.Insert(tmp1, opN, N);
// tmp1 = Sse?.Insert(tmp1, lastOp, (argCnt - 1));
// ...

opN = node->Op(argCnt);
GenTree* lastOp = node->Op(argCnt);

idx = comp->gtNewIconNode(N, TYP_INT);
BlockRange().InsertAfter(opN, idx);
idx = comp->gtNewIconNode((argCnt - 1), TYP_INT);
BlockRange().InsertAfter(lastOp, idx);

node->ResetHWIntrinsicId(insIntrinsic, comp, tmp1, opN, idx);
node->ResetHWIntrinsicId(insIntrinsic, comp, tmp1, lastOp, idx);
break;
}

Expand All @@ -4918,17 +4914,17 @@ GenTree* Lowering::LowerHWIntrinsicCreate(GenTreeHWIntrinsic* node)
GenTree* op[16];
op[0] = tmp1;

for (N = 1; N < argCnt; N++)
for (size_t N = 1; N < argCnt; N++)
{
opN = node->Op(N + 1);
GenTree* opN = node->Op(N + 1);

op[N] = InsertNewSimdCreateScalarUnsafeNode(TYP_SIMD16, opN, simdBaseJitType, 16);
LowerNode(op[N]);
}

if ((simdBaseType == TYP_BYTE) || (simdBaseType == TYP_UBYTE))
{
for (N = 0; N < argCnt; N += 4)
for (size_t N = 0; N < argCnt; N += 4)
{
// We will be constructing the following parts:
// ...
Expand Down Expand Up @@ -4958,9 +4954,9 @@ GenTree* Lowering::LowerHWIntrinsicCreate(GenTreeHWIntrinsic* node)
// tmp3 = Sse2.UnpackLow(tmp1, tmp2);
// ...

unsigned O = N + 1;
unsigned P = N + 2;
unsigned Q = N + 3;
size_t O = N + 1;
size_t P = N + 2;
size_t Q = N + 3;

tmp1 = comp->gtNewSimdHWIntrinsicNode(simdType, op[N], op[O], NI_SSE2_UnpackLow, CORINFO_TYPE_UBYTE,
simdSize);
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/superpmi/superpmi-shared/mclist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bool MCList::processArgAsMCL(char* input, int* count, int** list)

size_t len = strlen(input);

for (unsigned int i = 0; (i < len) && isRangeList; i++)
for (size_t i = 0; (i < len) && isRangeList; i++)
{
if ((input[i] != '-') && (input[i] != ',') && (!isdigit((unsigned char)input[i])))
isRangeList = false;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,7 @@ int MyICJI::doAssert(const char* szFile, int iLine, const char* szExpr)
sprintf_s(buff, sizeof(buff), "%s (%d) - %s", szFile, iLine, szExpr);

LogIssue(ISSUE_ASSERT, "#%d %s", jitInstance->mc->index, buff);
jitInstance->mc->cr->recMessageLog(buff);
jitInstance->mc->cr->recMessageLog("%s", buff);

// Under "/boa", ask the user if they want to attach a debugger. If they do, the debugger will be attached,
// then we'll call DebugBreakorAV(), which will issue a __debugbreak() and actually cause
Expand Down

0 comments on commit 8d24ba3

Please sign in to comment.