Skip to content

Commit

Permalink
[release/7.0] Fix use of uninitialized memory for Vector3 constants (#…
Browse files Browse the repository at this point in the history
…74880)

* Fix use of uninitialized memory for Vector3 constants

* Formatting

* Update src/coreclr/jit/codegenarm64.cpp

Co-authored-by: Jakob Botsch Nielsen <Jakob.botsch.nielsen@gmail.com>

* Apply the same fix for x64

* PR feedback

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Jakob Botsch Nielsen <Jakob.botsch.nielsen@gmail.com>
  • Loading branch information
3 people committed Sep 1, 2022
1 parent 9ce88fc commit 6d10e4c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
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

0 comments on commit 6d10e4c

Please sign in to comment.