[binutils-gdb] Re: ubsan: ns32k: left shift cannot be represented in type

Alan Modra amodra@sourceware.org
Wed Dec 11 03:06:00 GMT 2019


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5afa80e9a8e6585eeaac44ca51be9c6b2471bf80

commit 5afa80e9a8e6585eeaac44ca51be9c6b2471bf80
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Dec 11 13:11:07 2019 +1030

    Re: ubsan: ns32k: left shift cannot be represented in type
    
    	* ns32k-dis.c (sign_extend): Correct last patch.

Diff:
---
 opcodes/ChangeLog   | 4 ++++
 opcodes/ns32k-dis.c | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog
index c1fce7f..5345dfb 100644
--- a/opcodes/ChangeLog
+++ b/opcodes/ChangeLog
@@ -1,5 +1,9 @@
 2019-12-11  Alan Modra  <amodra@gmail.com>
 
+	* ns32k-dis.c (sign_extend): Correct last patch.
+
+2019-12-11  Alan Modra  <amodra@gmail.com>
+
 	* vax-dis.c (NEXTLONG): Avoid signed overflow.
 
 2019-12-11  Alan Modra  <amodra@gmail.com>
diff --git a/opcodes/ns32k-dis.c b/opcodes/ns32k-dis.c
index 5e6f096..e43fff7 100644
--- a/opcodes/ns32k-dis.c
+++ b/opcodes/ns32k-dis.c
@@ -327,8 +327,8 @@ bit_copy (bfd_byte *buffer, int offset, int count, char *to)
 static int
 sign_extend (unsigned int value, unsigned int bits)
 {
-  unsigned int sign = 1u << bits;
-  return ((value & (sign - 1)) ^ sign) - sign;
+  unsigned int sign = 1u << (bits - 1);
+  return ((value & (sign + sign - 1)) ^ sign) - sign;
 }
 
 static void



More information about the Binutils-cvs mailing list