ubsan: tilepro: signed integer overflow

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

ubsan: tilepro: signed integer overflow

Alan Modra-3
        * tilepro-opc.c (parse_insn_tilepro): Make opval unsigned.
        * tilegx-opc.c (parse_insn_tilegx): Likewise.  Delete raw_opval.

diff --git a/opcodes/tilegx-opc.c b/opcodes/tilegx-opc.c
index f49dae5de3..a122f49abc 100644
--- a/opcodes/tilegx-opc.c
+++ b/opcodes/tilegx-opc.c
@@ -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;
diff --git a/opcodes/tilepro-opc.c b/opcodes/tilepro-opc.c
index 6449945aa4..dbe0605e0c 100644
--- a/opcodes/tilepro-opc.c
+++ b/opcodes/tilepro-opc.c
@@ -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;

--
Alan Modra
Australia Development Lab, IBM