ubsan: tilepro: signed integer overflow
authorAlan Modra <amodra@gmail.com>
Thu, 9 Jan 2020 21:57:33 +0000 (08:27 +1030)
committerAlan Modra <amodra@gmail.com>
Fri, 10 Jan 2020 07:02:33 +0000 (17:32 +1030)
* tilepro-opc.c (parse_insn_tilepro): Make opval unsigned.
* tilegx-opc.c (parse_insn_tilegx): Likewise.  Delete raw_opval.

opcodes/ChangeLog
opcodes/tilegx-opc.c
opcodes/tilepro-opc.c

index 7c5f16bbc6b3910480e90f038c895123e18c3449..68538bd0392ab38058a9a64f1dc5304131d48b4f 100644 (file)
@@ -1,3 +1,8 @@
+2020-01-10  Alan Modra  <amodra@gmail.com>
+
+       * tilepro-opc.c (parse_insn_tilepro): Make opval unsigned.
+       * tilegx-opc.c (parse_insn_tilegx): Likewise.  Delete raw_opval.
+
 2020-01-10  Alan Modra  <amodra@gmail.com>
 
        * m10300-dis.c (disassemble): Move extraction of DREG, AREG, RREG,
index f49dae5de39c6e092613740752167f9ff33ad039..a122f49abc92ceea2363cbf137d4b4b92ec10484 100644 (file)
@@ -8096,21 +8096,18 @@ parse_insn_tilegx (tilegx_bundle_bits bits,
        {
          const struct tilegx_operand *op =
            &tilegx_operands[opc->operands[pipe][i]];
-         int raw_opval = op->extract (bits);
-         long long opval;
+         unsigned int opval = op->extract (bits);
 
          if (op->is_signed)
            {
              /* Sign-extend the operand.  */
              unsigned int sign = 1u << (op->num_bits - 1);
-             raw_opval = ((raw_opval & (sign + sign - 1)) ^ sign) - sign;
+             opval = ((opval & (sign + sign - 1)) ^ sign) - sign;
            }
 
          /* Adjust PC-relative scaled branch offsets.  */
          if (op->type == TILEGX_OP_TYPE_ADDRESS)
-           opval = (raw_opval * TILEGX_BUNDLE_SIZE_IN_BYTES) + pc;
-         else
-           opval = raw_opval;
+           opval = opval * TILEGX_BUNDLE_SIZE_IN_BYTES + pc;
 
          /* Record the final value.  */
          d->operands[i] = op;
index 6449945aa4f4388d5cb973452030b180ccee5e62..dbe0605e0c6e4d9960cc473758a5588a972961e0 100644 (file)
@@ -10215,7 +10215,7 @@ parse_insn_tilepro (tilepro_bundle_bits bits,
        {
          const struct tilepro_operand *op =
            &tilepro_operands[opc->operands[pipe][i]];
-         int opval = op->extract (bits);
+         unsigned int opval = op->extract (bits);
 
          if (op->is_signed)
            {
@@ -10226,10 +10226,7 @@ parse_insn_tilepro (tilepro_bundle_bits bits,
 
          /* Adjust PC-relative scaled branch offsets.  */
          if (op->type == TILEPRO_OP_TYPE_ADDRESS)
-           {
-             opval *= TILEPRO_BUNDLE_SIZE_IN_BYTES;
-             opval += (int)pc;
-           }
+           opval = opval * TILEPRO_BUNDLE_SIZE_IN_BYTES + pc;
 
          /* Record the final value.  */
          d->operands[i] = op;