From 6d113445d5b65434358dd32f82d0bc977a2bfc5f Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Mon, 5 Oct 2020 17:20:42 -0700 Subject: [PATCH] Use correct size_t when determining if a value fits in a byte (#42987) - Use target_size_t when determining if a value fits in a byte when value is represented in the function as a ssize_t or cnssval_ssize_t. This drops the upper 32bits of a possibly 64bit size_t when performing the comparison on TARGET_X86 platforms. Those bits are uninitialized if the value not a reloc. --- src/coreclr/src/jit/emitxarch.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreclr/src/jit/emitxarch.cpp b/src/coreclr/src/jit/emitxarch.cpp index 58af8ad..0a6c7ae 100644 --- a/src/coreclr/src/jit/emitxarch.cpp +++ b/src/coreclr/src/jit/emitxarch.cpp @@ -3825,7 +3825,7 @@ void emitter::emitIns_R_I(instruction ins, emitAttr attr, regNumber reg, ssize_t UNATIVE_OFFSET sz; instrDesc* id; insFormat fmt = emitInsModeFormat(ins, IF_RRD_CNS); - bool valInByte = ((signed char)val == val) && (ins != INS_mov) && (ins != INS_test); + bool valInByte = ((signed char)val == (target_ssize_t)val) && (ins != INS_mov) && (ins != INS_test); // BT reg,imm might be useful but it requires special handling of the immediate value // (it is always encoded in a byte). Let's not complicate things until this is needed. @@ -3952,7 +3952,7 @@ void emitter::emitIns_I(instruction ins, emitAttr attr, cnsval_ssize_t val) { UNATIVE_OFFSET sz; instrDesc* id; - bool valInByte = ((signed char)val == val); + bool valInByte = ((signed char)val == (target_ssize_t)val); #ifdef TARGET_AMD64 // mov reg, imm64 is the only opcode which takes a full 8 byte immediate @@ -11760,7 +11760,7 @@ BYTE* emitter::emitOutputRI(BYTE* dst, instrDesc* id) instruction ins = id->idIns(); regNumber reg = id->idReg1(); ssize_t val = emitGetInsSC(id); - bool valInByte = ((signed char)val == val) && (ins != INS_mov) && (ins != INS_test); + bool valInByte = ((signed char)val == (target_ssize_t)val) && (ins != INS_mov) && (ins != INS_test); // BT reg,imm might be useful but it requires special handling of the immediate value // (it is always encoded in a byte). Let's not complicate things until this is needed. @@ -12111,7 +12111,7 @@ BYTE* emitter::emitOutputIV(BYTE* dst, instrDesc* id) instruction ins = id->idIns(); emitAttr size = id->idOpSize(); ssize_t val = emitGetInsSC(id); - bool valInByte = ((signed char)val == val); + bool valInByte = ((signed char)val == (target_ssize_t)val); // We would to update GC info correctly assert(!IsSSEInstruction(ins)); -- 2.7.4