ubsan: cr16: left shift cannot be represented in type 'int'
authorAlan Modra <amodra@gmail.com>
Tue, 10 Dec 2019 12:32:37 +0000 (23:02 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 11 Dec 2019 01:08:04 +0000 (11:38 +1030)
This was:
  unsigned long mask = SBM (instruction->match_bits);
with
  #define SBM(offs)  ((((1 << (32 - offs)) -1) << (offs)))

Well, there are a couple of problems.  Firstly, the expression uses
int values (1 rather than 1u or 1ul) resulting in the ubsan error, and
secondly, a zero offs will result in a 32-bit shift which is undefined
if ints are only 32 bits.

* cr16-dis.c (EXTRACT, SBM): Rewrite.
(cr16_match_opcode): Delete duplicate bcond test.

opcodes/ChangeLog
opcodes/cr16-dis.c

index faa160a37b54eedfd8da44f3e10bb2200a88a7f2..57212f843baa4a034b3c11e810e1d6f1e42351bc 100644 (file)
@@ -1,3 +1,8 @@
+2019-12-11  Alan Modra  <amodra@gmail.com>
+
+       * cr16-dis.c (EXTRACT, SBM): Rewrite.
+       (cr16_match_opcode): Delete duplicate bcond test.
+
 2019-12-11  Alan Modra  <amodra@gmail.com>
 
        * bfin-dis.c (HOST_LONG_WORD_SIZE, XFIELD): Delete.
index 65cf91cfed264fcf0791c956ee4bced1fa3a5c4c..68fbe42a6514240f7268a0061c19fc51cfcef54f 100644 (file)
 
 /* Extract 'n_bits' from 'a' starting from offset 'offs'.  */
 #define EXTRACT(a, offs, n_bits)                    \
-  (n_bits == 32 ? (((a) >> (offs)) & 0xffffffffL)   \
-  : (((a) >> (offs)) & ((1 << (n_bits)) -1)))
+  (((a) >> (offs)) & ((1ul << ((n_bits) - 1) << 1) - 1))
 
-/* Set Bit Mask - a mask to set all bits starting from offset 'offs'.  */
-#define SBM(offs)  ((((1 << (32 - offs)) -1) << (offs)))
+/* Set Bit Mask - a mask to set all bits in a 32-bit word starting
+   from offset 'offs'.  */
+#define SBM(offs)  ((1ul << 31 << 1) - (1ul << (offs)))
 
 typedef struct
 {
@@ -329,9 +329,6 @@ cr16_match_opcode (void)
   while (instruction >= cr16_instruction)
     {
       mask = build_mask ();
-      /* Adjust mask for bcond with 32-bit size instruction */
-      if ((IS_INSN_MNEMONIC("b") && instruction->size == 2))
-        mask = 0xff0f0000;
 
       if ((doubleWord & mask) == BIN (instruction->match,
                                       instruction->match_bits))
This page took 0.026237 seconds and 4 git commands to generate.