* Undefined shift in print_insn_tilepro
@ 2026-10-28 22:24 Alan Modra
0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2026-10-28 22:24 UTC (permalink / raw)
To: binutils, gdb-patches
It is possible for tilepro operand_values to contain a value with the
top bit set (see parse_insn_tilepro op->is_signed code), which can
trigger a ubsan error when shifting it left. Avoid these "errors" by
making operand_values an unsigned int rather than an int.
tilegx has operand_values as long long but stores an unsigned int
value, so the field may as well be unsigned int there too.
include/
* opcode/tilepro.h (struct tilepro_decoded_instruction): Make
operand_values unsigned int.
* opcode/tilegx.h (struct tilegx_decoded_instruction): Likewise.
opcodes/
* tilepro-dis.c (contains_insn): Make expected_first_operand,
expected_second_operand and last_operand_ret unsigned int.
(print_insn_tilepro): Make num and addr_piece unsigned int.
* tilegx-dis.c (print_insn_tilegx): Make num unsigned int.
gdb/
* tilegx-tdep.c (tilegx_analyze_prologue): Adjust "operands".
diff --git a/gdb/tilegx-tdep.c b/gdb/tilegx-tdep.c
index 0d1421f8758..27829d2ad04 100644
--- a/gdb/tilegx-tdep.c
+++ b/gdb/tilegx-tdep.c
@@ -440,7 +440,7 @@ tilegx_analyze_prologue (struct gdbarch* gdbarch,
for (i = 0; i < num_insns; i++)
{
struct tilegx_decoded_instruction *this_insn = &decoded[i];
- long long *operands = this_insn->operand_values;
+ unsigned int *operands = this_insn->operand_values;
const struct tilegx_opcode *opcode = this_insn->opcode;
switch (opcode->mnemonic)
diff --git a/include/opcode/tilegx.h b/include/opcode/tilegx.h
index aeb73ddcec1..43ab417d04c 100644
--- a/include/opcode/tilegx.h
+++ b/include/opcode/tilegx.h
@@ -1258,7 +1258,7 @@ struct tilegx_decoded_instruction
{
const struct tilegx_opcode *opcode;
const struct tilegx_operand *operands[TILEGX_MAX_OPERANDS];
- long long operand_values[TILEGX_MAX_OPERANDS];
+ unsigned int operand_values[TILEGX_MAX_OPERANDS];
};
diff --git a/include/opcode/tilepro.h b/include/opcode/tilepro.h
index 86b7e90ebf7..2af4796abe5 100644
--- a/include/opcode/tilepro.h
+++ b/include/opcode/tilepro.h
@@ -1581,7 +1581,7 @@ struct tilepro_decoded_instruction
{
const struct tilepro_opcode *opcode;
const struct tilepro_operand *operands[TILEPRO_MAX_OPERANDS];
- int operand_values[TILEPRO_MAX_OPERANDS];
+ unsigned int operand_values[TILEPRO_MAX_OPERANDS];
};
diff --git a/opcodes/tilegx-dis.c b/opcodes/tilegx-dis.c
index b19afdfa454..2cb03266451 100644
--- a/opcodes/tilegx-dis.c
+++ b/opcodes/tilegx-dis.c
@@ -94,7 +94,7 @@ print_insn_tilegx (bfd_vma memaddr, disassemble_info *info)
for (j = 0; j < opcode->num_operands; j++)
{
- bfd_vma num;
+ unsigned int num;
const struct tilegx_operand *op;
const char *spr_name;
@@ -109,20 +109,20 @@ print_insn_tilegx (bfd_vma memaddr, disassemble_info *info)
{
case TILEGX_OP_TYPE_REGISTER:
info->fprintf_func (info->stream, "%s",
- tilegx_register_names[(int) num]);
+ tilegx_register_names[num]);
break;
case TILEGX_OP_TYPE_SPR:
spr_name = get_tilegx_spr_name (num);
if (spr_name != NULL)
info->fprintf_func (info->stream, "%s", spr_name);
else
- info->fprintf_func (info->stream, "%d", (int)num);
+ info->fprintf_func (info->stream, "%d", num);
break;
case TILEGX_OP_TYPE_IMMEDIATE:
- info->fprintf_func (info->stream, "%d", (int)num);
+ info->fprintf_func (info->stream, "%d", num);
break;
case TILEGX_OP_TYPE_ADDRESS:
- info->print_address_func (num, info);
+ info->print_address_func ((bfd_vma) num, info);
break;
default:
abort ();
diff --git a/opcodes/tilepro-dis.c b/opcodes/tilepro-dis.c
index aa9b532e2aa..d120545fd3f 100644
--- a/opcodes/tilepro-dis.c
+++ b/opcodes/tilepro-dis.c
@@ -32,10 +32,10 @@
static int
contains_insn (tilepro_mnemonic expected_mnemonic,
- int expected_first_operand,
- int expected_second_operand,
+ unsigned int expected_first_operand,
+ unsigned int expected_second_operand,
bfd_vma memaddr,
- int *last_operand_ret,
+ unsigned int *last_operand_ret,
disassemble_info *info)
{
struct tilepro_decoded_instruction
@@ -59,11 +59,11 @@ contains_insn (tilepro_mnemonic expected_mnemonic,
if (opcode->mnemonic != expected_mnemonic)
continue;
- if (expected_first_operand != -1
+ if (expected_first_operand != -1u
&& decoded[i].operand_values[0] != expected_first_operand)
continue;
- if (expected_second_operand != -1
+ if (expected_second_operand != -1u
&& decoded[i].operand_values[1] != expected_second_operand)
continue;
@@ -141,7 +141,7 @@ print_insn_tilepro (bfd_vma memaddr, disassemble_info *info)
for (j = 0; j < opcode->num_operands; j++)
{
- int num;
+ unsigned int num;
const struct tilepro_operand *op;
const char *spr_name;
@@ -171,7 +171,7 @@ print_insn_tilepro (bfd_vma memaddr, disassemble_info *info)
{
bfd_vma addr = 0;
int found_addr = 0;
- int addr_piece;
+ unsigned int addr_piece;
switch (opcode->mnemonic)
{
@@ -191,7 +191,7 @@ print_insn_tilepro (bfd_vma memaddr, disassemble_info *info)
case TILEPRO_OPC_AULI:
if (contains_insn (TILEPRO_OPC_MOVELI,
decoded[i].operand_values[1],
- -1,
+ -1u,
memaddr - TILEPRO_BUNDLE_SIZE_IN_BYTES,
&addr_piece,
info))
@@ -218,7 +218,7 @@ print_insn_tilepro (bfd_vma memaddr, disassemble_info *info)
break;
case TILEPRO_OP_TYPE_ADDRESS:
- info->print_address_func ((bfd_vma)(unsigned int) num, info);
+ info->print_address_func ((bfd_vma) num, info);
break;
default:
--
Alan Modra
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-28 22:24 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-28 22:24 Undefined shift in print_insn_tilepro Alan Modra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox