Skip to content

Fix use of uninitialized memory for Vector3 constants #74857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions src/coreclr/jit/codegenarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2412,8 +2412,14 @@ void CodeGen::genSetRegToConst(regNumber targetReg, var_types targetType, GenTre
// Get a temp integer register to compute long address.
regNumber addrReg = tree->GetSingleTempReg();

simd16_t constValue = vecCon->gtSimd16Val;
CORINFO_FIELD_HANDLE hnd = emit->emitSimd16Const(constValue);
simd16_t constValue = {};

if (vecCon->TypeIs(TYP_SIMD12))
memcpy(&constValue, &vecCon->gtSimd12Val, sizeof(simd12_t));
else
constValue = vecCon->gtSimd16Val;

CORINFO_FIELD_HANDLE hnd = emit->emitSimd16Const(constValue);

emit->emitIns_R_C(INS_ldr, attr, targetReg, addrReg, hnd, 0);
}
Expand Down
10 changes: 8 additions & 2 deletions src/coreclr/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,14 @@ void CodeGen::genSetRegToConst(regNumber targetReg, var_types targetType, GenTre
case TYP_SIMD12:
case TYP_SIMD16:
{
simd16_t constValue = vecCon->gtSimd16Val;
CORINFO_FIELD_HANDLE hnd = emit->emitSimd16Const(constValue);
simd16_t constValue = {};

if (vecCon->TypeIs(TYP_SIMD12))
memcpy(&constValue, &vecCon->gtSimd12Val, sizeof(simd12_t));
else
constValue = vecCon->gtSimd16Val;

CORINFO_FIELD_HANDLE hnd = emit->emitSimd16Const(constValue);

emit->emitIns_R_C(ins_Load(targetType), attr, targetReg, hnd, 0);
break;
Expand Down
8 changes: 7 additions & 1 deletion src/coreclr/jit/instr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,13 @@ CodeGen::OperandDesc CodeGen::genOperandDesc(GenTree* op)
case TYP_SIMD12:
case TYP_SIMD16:
{
simd16_t constValue = op->AsVecCon()->gtSimd16Val;
simd16_t constValue = {};

if (op->TypeIs(TYP_SIMD12))
memcpy(&constValue, &op->AsVecCon()->gtSimd12Val, sizeof(simd12_t));
else
constValue = op->AsVecCon()->gtSimd16Val;

return OperandDesc(emit->emitSimd16Const(constValue));
}

Expand Down