mirror of
https://github.com/netwide-assembler/nasm.git
synced 2024-11-21 03:14:19 +08:00
asm/assemble.c: change the overflow handling for signed byte immediates
For byte immediates that are sign-extended to a wider operand size, simplify the code and make the warning code behave as what is expected. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
parent
55e06dead1
commit
fbb07d6843
@ -1748,34 +1748,28 @@ static void gencode(struct out_data *data, insn *ins)
|
||||
|
||||
case4(0274):
|
||||
{
|
||||
uint64_t uv, um;
|
||||
int64_t uv;
|
||||
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;
|
||||
|
||||
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.
|
||||
/*
|
||||
* Forcibly discard bits irrelevant for our needs, to
|
||||
* prevent bogus warnings.
|
||||
*/
|
||||
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");
|
||||
uv = opx->offset;
|
||||
uv = (uv << (64-s)) >> (64-s);
|
||||
opx->offset = uv;
|
||||
}
|
||||
out_imm(data, opx, 1, OUT_WRAP); /* XXX: OUT_SIGNED? */
|
||||
out_imm(data, opx, 1, OUT_SIGNED);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user