From 7f578b959c3d4b4a1756c66aec4426743b82c6b8 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Fri, 10 Jan 2020 08:27:33 +1030 Subject: [PATCH] ubsan: tilepro: signed integer overflow * tilepro-opc.c (parse_insn_tilepro): Make opval unsigned. * tilegx-opc.c (parse_insn_tilegx): Likewise. Delete raw_opval. --- opcodes/ChangeLog | 5 +++++ opcodes/tilegx-opc.c | 9 +++------ opcodes/tilepro-opc.c | 7 ++----- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog index 7c5f16bbc6b..68538bd0392 100644 --- a/opcodes/ChangeLog +++ b/opcodes/ChangeLog @@ -1,3 +1,8 @@ +2020-01-10 Alan Modra + + * tilepro-opc.c (parse_insn_tilepro): Make opval unsigned. + * tilegx-opc.c (parse_insn_tilegx): Likewise. Delete raw_opval. + 2020-01-10 Alan Modra * m10300-dis.c (disassemble): Move extraction of DREG, AREG, RREG, diff --git a/opcodes/tilegx-opc.c b/opcodes/tilegx-opc.c index f49dae5de39..a122f49abc9 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 6449945aa4f..dbe0605e0c6 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; -- 2.30.2