+2021-05-20 Sergey Belyashov <sergey.belyashov@gmail.com>
+
+ * config/tc-z80.c (emit_data_val): Warn on constant overflow.
+ (signed_overflow): New function.
+ (unsigned_overflow): New function.
+ (is_overflow): Use new functions.
+ (md_apply_fix): Use signed_overflow.
+ * testsuite/gas/z80/ez80_adl_suf.d: Fix test.
+ * testsuite/gas/z80/ez80_isuf.s: Likewise.
+ * testsuite/gas/z80/ez80_z80_suf.d: Likewise.
+
2021-05-20 Nicolas Boulenguez <nicolas@debian.org>
PR 27888
{"xdcb", INS_ROT_II_LD, 0, 0, "instructions like RL (IX+d),R (DD/FD CB dd oo)" }
};
+
+static int signed_overflow (signed long value, unsigned bitsize);
+static int unsigned_overflow (unsigned long value, unsigned bitsize);
+static int is_overflow (long value, unsigned bitsize);
+
static void
setup_march (const char *name, int *ok, int *err, int *mode)
{
if (val->X_op == O_constant)
{
int i;
+ if (is_overflow (val->X_add_number, size*8))
+ as_warn ( _("%d-bit overflow (%+ld)"), size*8, val->X_add_number);
for (i = 0; i < size; ++i)
p[i] = (char)(val->X_add_number >> (i*8));
return;
input_line_pointer = old_ptr;
}
+static int
+signed_overflow (signed long value, unsigned bitsize)
+{
+ signed long max = (signed long)(1UL << (bitsize-1));
+ return value < -max || value >= max;
+}
+
+static int
+unsigned_overflow (unsigned long value, unsigned bitsize)
+{
+ return (value >> bitsize) != 0;
+}
+
static int
is_overflow (long value, unsigned bitsize)
{
- long fieldmask = (2UL << (bitsize - 1)) - 1;
- long signmask = ~fieldmask;
- long a = value & fieldmask;
- long ss = a & signmask;
- if (ss != 0 && ss != (signmask & fieldmask))
- return 1;
- return 0;
+ if (value < 0)
+ return signed_overflow (value, bitsize);
+ return unsigned_overflow ((unsigned long)value, bitsize);
}
void
{
case BFD_RELOC_8_PCREL:
case BFD_RELOC_Z80_DISP8:
- if (fixP->fx_done && (val < -0x80 || val > 0x7f))
+ if (fixP->fx_done && signed_overflow (val, 8))
as_bad_where (fixP->fx_file, fixP->fx_line,
_("8-bit signed offset out of range (%+ld)"), val);
*p_lit++ = val;