[binutils-gdb] ubsan: iq2000: left shift of negative value

Alan Modra amodra@sourceware.org
Mon Dec 23 07:38:00 GMT 2019


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

commit 3e1056a1a6336f289d3f0def8f6a3632c8a75393
Author: Alan Modra <amodra@gmail.com>
Date:   Mon Dec 23 18:04:12 2019 +1030

    ubsan: iq2000: left shift of negative value
    
    cpu/
    	* iq2000.cpu (f-offset): Avoid left shift of negative values.
    opcodes/
    	* iq2000-ibld.c: Regenerate.

Diff:
---
 cpu/ChangeLog         | 4 ++++
 cpu/iq2000.cpu        | 2 +-
 opcodes/ChangeLog     | 4 ++++
 opcodes/iq2000-ibld.c | 2 +-
 4 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/cpu/ChangeLog b/cpu/ChangeLog
index 1729efd..3e6a8d8 100644
--- a/cpu/ChangeLog
+++ b/cpu/ChangeLog
@@ -1,3 +1,7 @@
+2019-12-23  Alan Modra  <amodra@gmail.com>
+
+	* iq2000.cpu (f-offset): Avoid left shift of negative values.
+
 2019-12-20  Alan Modra  <amodra@gmail.com>
 
 	* or1korbis.cpu (f-disp26, f-disp21): Don't left shift negative values.
diff --git a/cpu/iq2000.cpu b/cpu/iq2000.cpu
index e25ba69..cb9cfae 100644
--- a/cpu/iq2000.cpu
+++ b/cpu/iq2000.cpu
@@ -207,7 +207,7 @@
 (df  f-offset "pc offset field"                (PCREL-ADDR) 15 16 INT
      ; Actually, this is relative to the address of the delay slot.
      ((value pc) (sra SI (sub SI value pc) 2))
-     ((value pc) (add SI (sll SI value 2) (add pc 4))))
+     ((value pc) (add SI (mul SI value 4) (add pc 4))))
 
 ; Instruction fields that scarcely appear in instructions.
 
diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog
index 1c5592a..c3a9752 100644
--- a/opcodes/ChangeLog
+++ b/opcodes/ChangeLog
@@ -1,5 +1,9 @@
 2019-12-23  Alan Modra  <amodra@gmail.com>
 
+	* iq2000-ibld.c: Regenerate.
+
+2019-12-23  Alan Modra  <amodra@gmail.com>
+
 	* d30v-dis.c (extract_value): Make num param a uint64_t, constify
 	oper.  Use unsigned vars.
 	(print_insn): Make num var uint64_t.  Constify oper and remove now
diff --git a/opcodes/iq2000-ibld.c b/opcodes/iq2000-ibld.c
index 34482b3..3059fe1 100644
--- a/opcodes/iq2000-ibld.c
+++ b/opcodes/iq2000-ibld.c
@@ -838,7 +838,7 @@ iq2000_cgen_extract_operand (CGEN_CPU_DESC cd,
       {
         long value;
         length = extract_normal (cd, ex_info, insn_value, 0|(1<<CGEN_IFLD_SIGNED)|(1<<CGEN_IFLD_PCREL_ADDR), 0, 15, 16, 32, total_length, pc, & value);
-        value = ((((value) << (2))) + (((pc) + (4))));
+        value = ((((value) * (4))) + (((pc) + (4))));
         fields->f_offset = value;
       }
       break;



More information about the Binutils-cvs mailing list