aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2019-12-11 08:34:57 +1030
committerAlan Modra <amodra@gmail.com>2019-12-11 11:40:33 +1030
commitfb4cb4e26d16f928f00973fcdc99934c9174c957 (patch)
tree29b29e3cc3b8105f4a37ede29652a2605bf48a91
parent96f1f60460a87fa63c33e1004f2c98d30f686d8d (diff)
downloadgdb-fb4cb4e26d16f928f00973fcdc99934c9174c957.zip
gdb-fb4cb4e26d16f928f00973fcdc99934c9174c957.tar.gz
gdb-fb4cb4e26d16f928f00973fcdc99934c9174c957.tar.bz2
ubsan: ns32k: left shift cannot be represented in type 'int'
* ns32k-dis.c (bit_extract): Use unsigned arithmetic. (bit_extract_simple, sign_extend): Likewise.
-rw-r--r--opcodes/ChangeLog5
-rw-r--r--opcodes/ns32k-dis.c16
2 files changed, 12 insertions, 9 deletions
diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog
index b36a9e2..ddf8cd0 100644
--- a/opcodes/ChangeLog
+++ b/opcodes/ChangeLog
@@ -1,5 +1,10 @@
2019-12-11 Alan Modra <amodra@gmail.com>
+ * ns32k-dis.c (bit_extract): Use unsigned arithmetic.
+ (bit_extract_simple, sign_extend): Likewise.
+
+2019-12-11 Alan Modra <amodra@gmail.com>
+
* nios2-dis.c (nios2_print_insn_arg): Use 1u << 31.
2019-12-11 Alan Modra <amodra@gmail.com>
diff --git a/opcodes/ns32k-dis.c b/opcodes/ns32k-dis.c
index 22a9389..5e6f096 100644
--- a/opcodes/ns32k-dis.c
+++ b/opcodes/ns32k-dis.c
@@ -262,8 +262,8 @@ list_search (int reg_value, const struct ns32k_option *optionP, char *result)
static int
bit_extract (bfd_byte *buffer, int offset, int count)
{
- int result;
- int bit;
+ unsigned int result;
+ unsigned int bit;
if (offset < 0 || count < 0)
return 0;
@@ -291,8 +291,8 @@ bit_extract (bfd_byte *buffer, int offset, int count)
static int
bit_extract_simple (bfd_byte *buffer, int offset, int count)
{
- int result;
- int bit;
+ unsigned int result;
+ unsigned int bit;
if (offset < 0 || count < 0)
return 0;
@@ -325,12 +325,10 @@ bit_copy (bfd_byte *buffer, int offset, int count, char *to)
}
static int
-sign_extend (int value, int bits)
+sign_extend (unsigned int value, unsigned int bits)
{
- value = value & ((1 << bits) - 1);
- return (value & (1 << (bits - 1))
- ? value | (~((1 << bits) - 1))
- : value);
+ unsigned int sign = 1u << bits;
+ return ((value & (sign - 1)) ^ sign) - sign;
}
static void