summaryrefslogtreecommitdiff
path: root/opcodes/v850-dis.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2019-12-11 08:53:50 +1030
committerAlan Modra <amodra@gmail.com>2019-12-11 11:41:52 +1030
commit2a81ccbbbf81ab9c66ba366a0c1da7abb6460423 (patch)
treed317cd7fdfac17e024009d78a2fdd58889c08de2 /opcodes/v850-dis.c
parentb84f6152ee8bb141acae181b34a51c3e58da8930 (diff)
downloadbinutils-gdb-2a81ccbbbf81ab9c66ba366a0c1da7abb6460423.tar.gz
ubsan: v850: left shift cannot be represented in type 'long'
* v850-dis.c (get_operand_value): Use unsigned arithmetic. Don't sign extend using shifts.
Diffstat (limited to 'opcodes/v850-dis.c')
-rw-r--r--opcodes/v850-dis.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/opcodes/v850-dis.c b/opcodes/v850-dis.c
index f8b5d1c93f2..45e6c65d83a 100644
--- a/opcodes/v850-dis.c
+++ b/opcodes/v850-dis.c
@@ -88,7 +88,7 @@ get_operand_value (const struct v850_operand *operand,
bfd_boolean noerror,
int *invalid)
{
- long value;
+ unsigned long value;
bfd_byte buffer[4];
if ((operand->flags & V850E_IMMEDIATE16)
@@ -158,11 +158,13 @@ get_operand_value (const struct v850_operand *operand,
if (operand->bits == -1)
value = (insn & operand->shift);
else
- value = (insn >> operand->shift) & ((1 << operand->bits) - 1);
+ value = (insn >> operand->shift) & ((1ul << operand->bits) - 1);
if (operand->flags & V850_OPERAND_SIGNED)
- value = ((long)(value << (sizeof (long)*8 - operand->bits))
- >> (sizeof (long)*8 - operand->bits));
+ {
+ unsigned long sign = 1ul << (operand->bits - 1);
+ value = (value ^ sign) - sign;
+ }
}
return value;