ubsan: d30v: left shift cannot be represented in type 'int'
authorAlan Modra <amodra@gmail.com>
Wed, 1 Jan 2020 08:16:43 +0000 (18:46 +1030)
committerAlan Modra <amodra@gmail.com>
Sat, 4 Jan 2020 08:50:33 +0000 (19:20 +1030)
* d30v-dis.c (print_insn): Avoid signed overflow in left shift.

opcodes/ChangeLog
opcodes/d30v-dis.c

index fb9f9e0929e334833ee7ba9f09ded58d28ee906a..52ebe868cc9b277089ec88bbee3642bf7f05a88e 100644 (file)
@@ -1,3 +1,7 @@
+2020-01-04  Alan Modra  <amodra@gmail.com>
+
+       * d30v-dis.c (print_insn): Avoid signed overflow in left shift.
+
 2020-01-03  Jan Beulich  <jbeulich@suse.com>
 
        * aarch64-tbl.h (aarch64_opcode_table): Use
index 61bb16d6d252b1f08c8c286e0d0763999576866e..212d24a70830c3e7dd280ab6f3aa538d1ba868a3 100644 (file)
@@ -271,14 +271,10 @@ print_insn (struct disassemble_info *info,
          /* IMM6S3 is unsigned.  */
          if (oper->flags & OPERAND_SIGNED || bits == 32)
            {
-             long max;
-             max = (1 << (bits - 1));
-             if (val & max)
+             unsigned int sign = 1u << (bits - 1);
+             if (val & sign)
                {
-                 if (bits == 32)
-                   val = -val;
-                 else
-                   val = -val & ((1 << bits) - 1);
+                 val = -val & (sign + sign - 1);
                  neg = 1;
                }
            }
@@ -303,13 +299,11 @@ print_insn (struct disassemble_info *info,
        {
          if (oper->flags & OPERAND_SIGNED)
            {
-             int max = (1 << (bits - 1));
+             unsigned int sign = 1u << (bits - 1);
 
-             if (val & max)
+             if (val & sign)
                {
-                 val = -val;
-                 if (bits < 32)
-                   val &= ((1 << bits) - 1);
+                 val = -val & (sign + sign - 1);
                  (*info->fprintf_func) (info->stream, "-");
                }
            }