mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-03-19 18:00:23 +08:00
assemble.c: for the signed byte operand, check overflow then rawbyte
When we are generating a signed byte operand, we anyway have to do the overflow check "manually". After doing so, output the result using out_rawbyte() instead of out_imm(), so we don't end up doing a redundant, and incorrect, second overflow check. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
parent
02788e1675
commit
64e87d0dfc
@ -1751,31 +1751,37 @@ static void gencode(struct out_data *data, insn *ins)
|
||||
uint64_t uv, um;
|
||||
int s;
|
||||
|
||||
if (ins->rex & REX_W)
|
||||
s = 64;
|
||||
else if (ins->prefixes[PPS_OSIZE] == P_O16)
|
||||
s = 16;
|
||||
else if (ins->prefixes[PPS_OSIZE] == P_O32)
|
||||
s = 32;
|
||||
else
|
||||
s = bits;
|
||||
if (absolute_op(opx)) {
|
||||
if (ins->rex & REX_W)
|
||||
s = 64;
|
||||
else if (ins->prefixes[PPS_OSIZE] == P_O16)
|
||||
s = 16;
|
||||
else if (ins->prefixes[PPS_OSIZE] == P_O32)
|
||||
s = 32;
|
||||
else
|
||||
s = bits;
|
||||
|
||||
um = (uint64_t)2 << (s-1);
|
||||
uv = opx->offset;
|
||||
um = (uint64_t)2 << (s-1);
|
||||
uv = opx->offset;
|
||||
|
||||
if (uv > 127 && uv < (uint64_t)-128 &&
|
||||
(uv < um-128 || uv > um-1)) {
|
||||
/* If this wasn't explicitly byte-sized, warn as though we
|
||||
* had fallen through to the imm16/32/64 case.
|
||||
*/
|
||||
nasm_error(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV,
|
||||
"%s value exceeds bounds",
|
||||
(opx->type & BITS8) ? "signed byte" :
|
||||
s == 16 ? "word" :
|
||||
s == 32 ? "dword" :
|
||||
"signed dword");
|
||||
if (uv > 127 && uv < (uint64_t)-128 &&
|
||||
(uv < um-128 || uv > um-1)) {
|
||||
/* If this wasn't explicitly byte-sized, warn as though we
|
||||
* had fallen through to the imm16/32/64 case.
|
||||
*/
|
||||
nasm_error(ERR_WARNING | ERR_PASS2 | ERR_WARN_NOV,
|
||||
"%s value exceeds bounds",
|
||||
(opx->type & BITS8) ? "signed byte" :
|
||||
s == 16 ? "word" :
|
||||
s == 32 ? "dword" :
|
||||
"signed dword");
|
||||
}
|
||||
|
||||
/* Output as a raw byte to avoid byte overflow check */
|
||||
out_rawbyte(data, (uint8_t)uv);
|
||||
} else {
|
||||
out_imm(data, opx, 1, OUT_WRAP); /* XXX: OUT_SIGNED? */
|
||||
}
|
||||
out_imm(data, opx, 1, OUT_WRAP); /* XXX: OUT_SIGNED? */
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user