gas: Fix left shift of negative value.
authorDominik Vogt <vogt@linux.vnet.ibm.com>
Mon, 9 Nov 2015 16:12:57 +0000 (17:12 +0100)
committerAndreas Krebbel <krebbel@linux.vnet.ibm.com>
Mon, 9 Nov 2015 16:12:57 +0000 (17:12 +0100)
This patch fixes all occurences of left-shifting negative constants in C cod
which is undefined by the C standard.

gas/ChangeLog:

        * read.c (parse_bitfield_cons): Fix left shift of negative value.
        * config/tc-xstormy16.c (md_section_align): Likewise.
        * config/tc-xgate.c (md_section_align): Likewise.
        * config/tc-visium.c (md_section_align): Likewise.
        * config/tc-v850.c (md_section_align): Likewise.
        * config/tc-tic6x.c (md_section_align): Likewise.
        * config/tc-sh.c (SH64PCREL32_M, SH64PCREL48_M, SH64PCREL32_M)
        (MOVI_32_M, MOVI_48_M, MOVI_32_M, md_section_align): Likewise.
        * config/tc-sh64.c (shmedia_md_estimate_size_before_relax): Likewise.
        * config/tc-score.c (s3_section_align): Likewise.
        * config/tc-score7.c (s7_section_align): Likewise.
        * config/tc-s390.c (md_section_align): Likewise.
        * config/tc-rx.c (md_section_align): Likewise.
        * config/tc-rl78.c (md_section_align): Likewise.
        * config/tc-ppc.c (md_section_align): Likewise.
        * config/tc-or1k.c (md_section_align): Likewise.
        * config/tc-nds32.c (md_section_align): Likewise.
        * config/tc-mt.c (md_section_align): Likewise.
        * config/tc-msp430.c (md_section_align): Likewise.
        * config/tc-mn10300.c (md_section_align): Likewise.
        * config/tc-mn10200.c (md_section_align): Likewise.
        * config/tc-mips.c (md_section_align): Likewise.
        * config/tc-microblaze.c (parse_imm): Likewise.
        * config/tc-mep.c (md_section_align): Likewise.
        * config/tc-m68k.c (md_section_align): Likewise.
        * config/tc-m68hc11.c (md_section_align): Likewise.
        * config/tc-m32r.c (md_section_align): Likewise.
        * config/tc-m32c.c (md_section_align): Likewise.
        * config/tc-lm32.c (md_section_align): Likewise.
        * config/tc-iq2000.c (md_section_align): Likewise.
        * config/tc-ip2k.c (md_section_align): Likewise.
        * config/tc-ia64.c (dot_save, dot_vframe): Likewise.
        * config/tc-i960.c (md_number_to_field, md_section_align): Likewise.
        * config/tc-i386.c (md_section_align): Likewise.
        * config/tc-i370.c (md_section_align): Likewise.
        * config/tc-frv.c (md_section_align): Likewise.
        * config/tc-fr30.c (md_section_align): Likewise.
        * config/tc-epiphany.c (md_section_align): Likewise.
        * config/tc-d30v.c (md_section_align): Likewise.
        * config/tc-d10v.c (md_section_align): Likewise.
        * config/tc-cr16.c (l_cons): Likewise.
        * config/tc-bfin.c (md_section_align): Likewise.
        * config/tc-arm.c (md_section_align): Likewise.
        * config/tc-arc.c (md_section_align): Likewise.
        * config/bfin-parse.y (expr_1): Likewise.

gas/testsuite/ChangeLog:

        * gas/all/test-gen.c (random_order_16s, random_order_24s)
        (random_order_32s): Fix left shift of negative value.

48 files changed:
gas/ChangeLog
gas/config/bfin-parse.y
gas/config/tc-arc.c
gas/config/tc-arm.c
gas/config/tc-bfin.c
gas/config/tc-cr16.c
gas/config/tc-d10v.c
gas/config/tc-d30v.c
gas/config/tc-epiphany.c
gas/config/tc-fr30.c
gas/config/tc-frv.c
gas/config/tc-i370.c
gas/config/tc-i386.c
gas/config/tc-i960.c
gas/config/tc-ia64.c
gas/config/tc-ip2k.c
gas/config/tc-iq2000.c
gas/config/tc-lm32.c
gas/config/tc-m32c.c
gas/config/tc-m32r.c
gas/config/tc-m68hc11.c
gas/config/tc-m68k.c
gas/config/tc-mep.c
gas/config/tc-microblaze.c
gas/config/tc-mips.c
gas/config/tc-mn10200.c
gas/config/tc-mn10300.c
gas/config/tc-msp430.c
gas/config/tc-mt.c
gas/config/tc-nds32.c
gas/config/tc-or1k.c
gas/config/tc-ppc.c
gas/config/tc-rl78.c
gas/config/tc-rx.c
gas/config/tc-s390.c
gas/config/tc-score.c
gas/config/tc-score7.c
gas/config/tc-sh.c
gas/config/tc-sh64.c
gas/config/tc-tic6x.c
gas/config/tc-v850.c
gas/config/tc-visium.c
gas/config/tc-xc16x.c
gas/config/tc-xgate.c
gas/config/tc-xstormy16.c
gas/read.c
gas/testsuite/ChangeLog
gas/testsuite/gas/all/test-gen.c

index 09b81c3..2214ed3 100644 (file)
@@ -1,3 +1,51 @@
+2015-11-09  Dominik Vogt  <vogt@linux.vnet.ibm.com>
+
+       * read.c (parse_bitfield_cons): Fix left shift of negative value.
+       * config/tc-xstormy16.c (md_section_align): Likewise.
+       * config/tc-xgate.c (md_section_align): Likewise.
+       * config/tc-visium.c (md_section_align): Likewise.
+       * config/tc-v850.c (md_section_align): Likewise.
+       * config/tc-tic6x.c (md_section_align): Likewise.
+       * config/tc-sh.c (SH64PCREL32_M, SH64PCREL48_M, SH64PCREL32_M)
+       (MOVI_32_M, MOVI_48_M, MOVI_32_M, md_section_align): Likewise.
+       * config/tc-sh64.c (shmedia_md_estimate_size_before_relax): Likewise.
+       * config/tc-score.c (s3_section_align): Likewise.
+       * config/tc-score7.c (s7_section_align): Likewise.
+       * config/tc-s390.c (md_section_align): Likewise.
+       * config/tc-rx.c (md_section_align): Likewise.
+       * config/tc-rl78.c (md_section_align): Likewise.
+       * config/tc-ppc.c (md_section_align): Likewise.
+       * config/tc-or1k.c (md_section_align): Likewise.
+       * config/tc-nds32.c (md_section_align): Likewise.
+       * config/tc-mt.c (md_section_align): Likewise.
+       * config/tc-msp430.c (md_section_align): Likewise.
+       * config/tc-mn10300.c (md_section_align): Likewise.
+       * config/tc-mn10200.c (md_section_align): Likewise.
+       * config/tc-mips.c (md_section_align): Likewise.
+       * config/tc-microblaze.c (parse_imm): Likewise.
+       * config/tc-mep.c (md_section_align): Likewise.
+       * config/tc-m68k.c (md_section_align): Likewise.
+       * config/tc-m68hc11.c (md_section_align): Likewise.
+       * config/tc-m32r.c (md_section_align): Likewise.
+       * config/tc-m32c.c (md_section_align): Likewise.
+       * config/tc-lm32.c (md_section_align): Likewise.
+       * config/tc-iq2000.c (md_section_align): Likewise.
+       * config/tc-ip2k.c (md_section_align): Likewise.
+       * config/tc-ia64.c (dot_save, dot_vframe): Likewise.
+       * config/tc-i960.c (md_number_to_field, md_section_align): Likewise.
+       * config/tc-i386.c (md_section_align): Likewise.
+       * config/tc-i370.c (md_section_align): Likewise.
+       * config/tc-frv.c (md_section_align): Likewise.
+       * config/tc-fr30.c (md_section_align): Likewise.
+       * config/tc-epiphany.c (md_section_align): Likewise.
+       * config/tc-d30v.c (md_section_align): Likewise.
+       * config/tc-d10v.c (md_section_align): Likewise.
+       * config/tc-cr16.c (l_cons): Likewise.
+       * config/tc-bfin.c (md_section_align): Likewise.
+       * config/tc-arm.c (md_section_align): Likewise.
+       * config/tc-arc.c (md_section_align): Likewise.
+       * config/bfin-parse.y (expr_1): Likewise.
+
 2015-11-02  Nick Clifton  <nickc@redhat.com>
 
        * config/rx-parse.y: Allow zero value for 5-bit displacements.
index c2a1d53..75d1b1e 100644 (file)
@@ -4505,7 +4505,7 @@ static int
 value_match (Expr_Node *exp, int sz, int sign, int mul, int issigned)
 {
   int umax = (1 << sz) - 1;
-  int min = -1 << (sz - 1);
+  int min = -(1 << (sz - 1));
   int max = (1 << (sz - 1)) - 1;
 
   int v = (EXPR_VALUE (exp)) & 0xffffffff;
index e0a4b57..ca43566 100644 (file)
@@ -1067,7 +1067,7 @@ md_section_align (segT segment,
 {
   int align = bfd_get_section_alignment (stdoutput, segment);
 
-  return ((size + (1 << align) - 1) & (-1 << align));
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
 
 /* The location from which a PC relative jump should be calculated,
index 025e0be..de99d72 100644 (file)
@@ -21019,7 +21019,7 @@ md_section_align (segT   segment ATTRIBUTE_UNUSED,
       int align;
 
       align = bfd_get_section_alignment (stdoutput, segment);
-      size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
+      size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
     }
 #endif
 
index 656e515..77b6013 100644 (file)
@@ -796,7 +796,7 @@ md_section_align (segment, size)
      valueT size;
 {
   int boundary = bfd_get_section_alignment (stdoutput, segment);
-  return ((size + (1 << boundary) - 1) & (-1 << boundary));
+  return ((size + (1 << boundary) - 1) & -(1 << boundary));
 }
 
 
index 0f2456e..b524bb7 100644 (file)
@@ -206,7 +206,7 @@ l_cons (int nbytes)
                   return;
                 }
 
-              value |= ((~(-1 << width) & exp.X_add_number)
+              value |= ((~(-(1 << width)) & exp.X_add_number)
                         << ((BITS_PER_CHAR * nbytes) - bits_available));
 
               if ((bits_available -= width) == 0
index 8b4b4e1..664fdb6 100644 (file)
@@ -269,7 +269,7 @@ valueT
 md_section_align (asection *seg, valueT addr)
 {
   int align = bfd_get_section_alignment (stdoutput, seg);
-  return ((addr + (1 << align) - 1) & (-1 << align));
+  return ((addr + (1 << align) - 1) & -(1 << align));
 }
 
 void
index e6174a9..31875d5 100644 (file)
@@ -303,7 +303,7 @@ valueT
 md_section_align (asection *seg, valueT addr)
 {
   int align = bfd_get_section_alignment (stdoutput, seg);
-  return ((addr + (1 << align) - 1) & (-1 << align));
+  return ((addr + (1 << align) - 1) & -(1 << align));
 }
 
 void
index 276691a..fe1a12f 100644 (file)
@@ -173,7 +173,7 @@ md_section_align (segT segment, valueT size)
 {
   int align = bfd_get_section_alignment (stdoutput, segment);
 
-  return ((size + (1 << align) - 1) & (-1 << align));
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
 
 \f
index c6e80e3..a151c35 100644 (file)
@@ -156,7 +156,7 @@ md_section_align (segT segment, valueT size)
 {
   int align = bfd_get_section_alignment (stdoutput, segment);
 
-  return ((size + (1 << align) - 1) & (-1 << align));
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
 
 symbolS *
index 0ca1a6e..a7a1665 100644 (file)
@@ -1227,7 +1227,7 @@ valueT
 md_section_align (segT segment, valueT size)
 {
   int align = bfd_get_section_alignment (stdoutput, segment);
-  return ((size + (1 << align) - 1) & (-1 << align));
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
 
 symbolS *
index ba82b2c..321cae8 100644 (file)
@@ -2375,7 +2375,7 @@ md_section_align (asection *seg, valueT addr)
 {
   int align = bfd_get_section_alignment (stdoutput, seg);
 
-  return (addr + (1 << align) - 1) & (-1 << align);
+  return (addr + (1 << align) - 1) & -(1 << align);
 }
 
 /* We don't have any form of relaxing.  */
index d74e870..d341193 100644 (file)
@@ -10317,7 +10317,7 @@ md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size)
       int align;
 
       align = bfd_get_section_alignment (stdoutput, segment);
-      size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
+      size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
     }
 #endif
 
index e27d816..35ec138 100644 (file)
@@ -1751,7 +1751,7 @@ md_number_to_field (char *instrP,         /* Pointer to instruction to be fixed.  */
     {
       /* Put bit field into instruction and write back in target
          * byte order.  */
-      val &= ~(-1 << (int) numbits);   /* Clear unused sign bits.  */
+      val &= ~(-(1 << (int) numbits)); /* Clear unused sign bits.  */
       instr |= val;
       md_number_to_chars (instrP, instr, 4);
     }
@@ -2466,7 +2466,7 @@ md_section_align (segT seg,
   int align;
 
   align = bfd_get_section_alignment (stdoutput, seg);
-  return (addr + (1 << align) - 1) & (-1 << align);
+  return (addr + (1 << align) - 1) & -(1 << align);
 }
 
 extern int coff_flags;
index ea7dcc6..8a34fea 100644 (file)
@@ -3339,7 +3339,7 @@ dot_vframe (int dummy ATTRIBUTE_UNUSED)
   if (! (unwind.prologue_mask & 2))
     add_unwind_entry (output_psp_gr (reg), NOT_A_CHAR);
   else if (reg != unwind.prologue_gr
-                 + (unsigned) popcount (unwind.prologue_mask & (-2 << 1)))
+                 + (unsigned) popcount (unwind.prologue_mask & -(2 << 1)))
     as_warn (_("Operand of .vframe contradicts .prologue"));
 }
 
@@ -3421,7 +3421,7 @@ dot_save (int dummy ATTRIBUTE_UNUSED)
       if (! (unwind.prologue_mask & 4))
        add_unwind_entry (output_pfs_gr (reg2), NOT_A_CHAR);
       else if (reg2 != unwind.prologue_gr
-                      + (unsigned) popcount (unwind.prologue_mask & (-4 << 1)))
+                      + (unsigned) popcount (unwind.prologue_mask & -(4 << 1)))
        as_warn (_("Second operand of .save contradicts .prologue"));
       break;
     case REG_AR + AR_LC:
@@ -3440,7 +3440,7 @@ dot_save (int dummy ATTRIBUTE_UNUSED)
       if (! (unwind.prologue_mask & 1))
        add_unwind_entry (output_preds_gr (reg2), NOT_A_CHAR);
       else if (reg2 != unwind.prologue_gr
-                      + (unsigned) popcount (unwind.prologue_mask & (-1 << 1)))
+                      + (unsigned) popcount (unwind.prologue_mask & -(1 << 1)))
        as_warn (_("Second operand of .save contradicts .prologue"));
       break;
     case REG_PRIUNAT:
index 4f4cffe..d58a85f 100644 (file)
@@ -231,7 +231,7 @@ md_section_align (segT segment, valueT size)
 {
   int align = bfd_get_section_alignment (stdoutput, segment);
 
-  return ((size + (1 << align) - 1) & (-1 << align));
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
 
 
index 2d55da1..381d627 100644 (file)
@@ -432,7 +432,7 @@ valueT
 md_section_align (segT segment, valueT size)
 {
   int align = bfd_get_section_alignment (stdoutput, segment);
-  return ((size + (1 << align) - 1) & (-1 << align));
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
 
 symbolS *
index 3b127fd..032175a 100644 (file)
@@ -278,7 +278,7 @@ valueT
 md_section_align (asection *seg, valueT addr)
 {
   int align = bfd_get_section_alignment (stdoutput, seg);
-  return ((addr + (1 << align) - 1) & (-1 << align));
+  return ((addr + (1 << align) - 1) & -(1 << align));
 }
 
 /* This function assembles the instructions. It emits the frags/bytes to the
index 10eba14..7644cb2 100644 (file)
@@ -410,7 +410,7 @@ valueT
 md_section_align (segT segment, valueT size)
 {
   int align = bfd_get_section_alignment (stdoutput, segment);
-  return ((size + (1 << align) - 1) & (-1 << align));
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
 
 symbolS *
index 4a14bf1..ce68f25 100644 (file)
@@ -1450,7 +1450,7 @@ md_section_align (segT segment, valueT size)
 {
   int align = bfd_get_section_alignment (stdoutput, segment);
 
-  return ((size + (1 << align) - 1) & (-1 << align));
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
 
 symbolS *
index 43cf6b6..fdaf901 100644 (file)
@@ -584,7 +584,7 @@ valueT
 md_section_align (asection *seg, valueT addr)
 {
   int align = bfd_get_section_alignment (stdoutput, seg);
-  return ((addr + (1 << align) - 1) & (-1 << align));
+  return ((addr + (1 << align) - 1) & -(1 << align));
 }
 
 static int
index b8f051e..d3e22fc 100644 (file)
@@ -7888,7 +7888,7 @@ md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size)
   int align;
 
   align = bfd_get_section_alignment (stdoutput, segment);
-  size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
+  size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
 #endif
 
   return size;
index 780356f..88d111a 100644 (file)
@@ -1382,7 +1382,7 @@ valueT
 md_section_align (segT segment, valueT size)
 {
   int align = bfd_get_section_alignment (stdoutput, segment);
-  return ((size + (1 << align) - 1) & (-1 << align));
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
 
 
index b43925b..ac7c828 100644 (file)
@@ -739,7 +739,7 @@ parse_imm (char * s, expressionS * e, offsetT min, offsetT max)
     {
       /* Special case: sign extend negative 32-bit values to 64-bits.  */
       if ((e->X_add_number >> 31) == 1)
-       e->X_add_number |= (-1 << 31);
+       e->X_add_number |= -(1 << 31);
 
       if (e->X_add_number < min || e->X_add_number > max)
        {
index d951dfc..a2d45a4 100644 (file)
@@ -16500,7 +16500,7 @@ md_section_align (asection *seg, valueT addr)
   if (align > 4)
     align = 4;
 
-  return ((addr + (1 << align) - 1) & (-1 << align));
+  return ((addr + (1 << align) - 1) & -(1 << align));
 }
 
 /* Utility routine, called from above as well.  If called while the
index cabbcc1..7e3e835 100644 (file)
@@ -676,7 +676,7 @@ valueT
 md_section_align (asection *seg, valueT addr)
 {
   int align = bfd_get_section_alignment (stdoutput, seg);
-  return ((addr + (1 << align) - 1) & (-1 << align));
+  return ((addr + (1 << align) - 1) & -(1 << align));
 }
 
 void
index da05cac..8a265aa 100644 (file)
@@ -905,7 +905,7 @@ md_section_align (asection *seg, valueT addr)
 {
   int align = bfd_get_section_alignment (stdoutput, seg);
 
-  return ((addr + (1 << align) - 1) & (-1 << align));
+  return ((addr + (1 << align) - 1) & -(1 << align));
 }
 
 void
index 8e32189..ef7c5ee 100644 (file)
@@ -3955,7 +3955,7 @@ md_section_align (asection * seg, valueT addr)
 {
   int align = bfd_get_section_alignment (stdoutput, seg);
 
-  return ((addr + (1 << align) - 1) & (-1 << align));
+  return ((addr + (1 << align) - 1) & -(1 << align));
 }
 
 /* If you define this macro, it should return the offset between the
index b90ee60..1d51465 100644 (file)
@@ -333,7 +333,7 @@ md_section_align (segT segment, valueT size)
 {
   int align = bfd_get_section_alignment (stdoutput, segment);
 
-  return ((size + (1 << align) - 1) & (-1 << align));
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
 
 symbolS *
index 06e419d..1846256 100644 (file)
@@ -5380,7 +5380,7 @@ md_section_align (segT segment, valueT size)
 {
   int align = bfd_get_section_alignment (stdoutput, segment);
 
-  return ((size + (1 << align) - 1) & (-1 << align));
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
 
 /* GAS will call this function when a symbol table lookup fails, before it
index dba2dde..18db230 100644 (file)
@@ -166,7 +166,7 @@ valueT
 md_section_align (segT segment, valueT size)
 {
   int align = bfd_get_section_alignment (stdoutput, segment);
-  return ((size + (1 << align) - 1) & (-1 << align));
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
 
 symbolS *
index b6b4412..b4c00c4 100644 (file)
@@ -6090,7 +6090,7 @@ md_section_align (asection *seg ATTRIBUTE_UNUSED, valueT addr)
 #else
   int align = bfd_get_section_alignment (stdoutput, seg);
 
-  return ((addr + (1 << align) - 1) & (-1 << align));
+  return ((addr + (1 << align) - 1) & -(1 << align));
 #endif
 }
 
index a74703e..9fbaa42 100644 (file)
@@ -1469,5 +1469,5 @@ valueT
 md_section_align (segT segment, valueT size)
 {
   int align = bfd_get_section_alignment (stdoutput, segment);
-  return ((size + (1 << align) - 1) & (-1 << align));
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
index 8e99fa3..4697e95 100644 (file)
@@ -1248,7 +1248,7 @@ valueT
 md_section_align (segT segment, valueT size)
 {
   int align = bfd_get_section_alignment (stdoutput, segment);
-  return ((size + (1 << align) - 1) & (-1 << align));
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
 
                                /* NOP - 1 cycle */
index e217e56..d597ee6 100644 (file)
@@ -2047,7 +2047,7 @@ md_section_align (asection *seg, valueT addr)
 {
   int align = bfd_get_section_alignment (stdoutput, seg);
 
-  return ((addr + (1 << align) - 1) & (-1 << align));
+  return ((addr + (1 << align) - 1) & -(1 << align));
 }
 
 /* We don't have any form of relaxing.  */
index 49ed5f2..15b4ed7 100644 (file)
@@ -7089,7 +7089,7 @@ static valueT
 s3_section_align (segT segment ATTRIBUTE_UNUSED, valueT size)
 {
   int align = bfd_get_section_alignment (stdoutput, segment);
-  return ((size + (1 << align) - 1) & (-1 << align));
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
 
 static void
index e8af055..2b1eb5d 100644 (file)
@@ -6634,7 +6634,7 @@ s7_section_align (segT segment, valueT size)
 {
   int align = bfd_get_section_alignment (stdoutput, segment);
 
-  return ((size + (1 << align) - 1) & (-1 << align));
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
 
 static void
index 1b5beb2..125f073 100644 (file)
@@ -281,15 +281,15 @@ const char FLT_CHARS[] = "rRsSfFdDxXpP";
 #if BFD_HOST_64BIT_LONG
 /* The "reach" type is long, so we can only do this for a 64-bit-long
    host.  */
-#define SH64PCREL32_M (((long) -1 << 30) * 2 - 4)
+#define SH64PCREL32_M ((-((long) 1 << 30)) * 2 - 4)
 #define SH64PCREL48_F ((((long) 1 << 47) - 1) - 4)
-#define SH64PCREL48_M (((long) -1 << 47) - 4)
+#define SH64PCREL48_M ((-((long) 1 << 47)) - 4)
 #define SH64PCREL48_LENGTH (3 * 4)
 #else
 /* If the host does not have 64-bit longs, just make this state identical
    in reach to the 32-bit state.  Note that we have a slightly incorrect
    reach, but the correct one above will overflow a 32-bit number.  */
-#define SH64PCREL32_M (((long) -1 << 30) * 2)
+#define SH64PCREL32_M ((-((long) 1 << 30)) * 2)
 #define SH64PCREL48_F SH64PCREL32_F
 #define SH64PCREL48_M SH64PCREL32_M
 #define SH64PCREL48_LENGTH (3 * 4)
@@ -313,14 +313,14 @@ const char FLT_CHARS[] = "rRsSfFdDxXpP";
 #if BFD_HOST_64BIT_LONG
 /* The "reach" type is long, so we can only do this for a 64-bit-long
    host.  */
-#define MOVI_32_M (((long) -1 << 30) * 2 - 4)
+#define MOVI_32_M ((-((long) 1 << 30)) * 2 - 4)
 #define MOVI_48_F ((((long) 1 << 47) - 1) - 4)
-#define MOVI_48_M (((long) -1 << 47) - 4)
+#define MOVI_48_M ((-((long) 1 << 47)) - 4)
 #else
 /* If the host does not have 64-bit longs, just make this state identical
    in reach to the 32-bit state.  Note that we have a slightly incorrect
    reach, but the correct one above will overflow a 32-bit number.  */
-#define MOVI_32_M (((long) -1 << 30) * 2)
+#define MOVI_32_M ((-((long) 1 << 30)) * 2)
 #define MOVI_48_F MOVI_32_F
 #define MOVI_48_M MOVI_32_M
 #endif /* BFD_HOST_64BIT_LONG */
@@ -3692,7 +3692,7 @@ md_section_align (segT seg ATTRIBUTE_UNUSED, valueT size)
   return size;
 #else /* ! OBJ_ELF */
   return ((size + (1 << bfd_get_section_alignment (stdoutput, seg)) - 1)
-         & (-1 << bfd_get_section_alignment (stdoutput, seg)));
+         & -(1 << bfd_get_section_alignment (stdoutput, seg)));
 #endif /* ! OBJ_ELF */
 }
 
index 780052b..2c0bcde 100644 (file)
@@ -2020,7 +2020,7 @@ shmedia_md_estimate_size_before_relax (fragS *fragP,
          offsetT value = fragP->fr_offset
            + (fragP->fr_symbol == NULL ? 0 : S_GET_VALUE (fragP->fr_symbol));
 
-         if (value >= ((offsetT) -1 << 15) && value < ((offsetT) 1 << 15))
+         if (value >= (-((offsetT) 1 << 15)) && value < ((offsetT) 1 << 15))
            {
              /* Fits in 16-bit signed number.  */
              int what = GET_WHAT (fragP->fr_subtype);
index 64d39be..1a8ddde 100644 (file)
@@ -4484,7 +4484,7 @@ md_section_align (segT segment ATTRIBUTE_UNUSED,
   /* Round up section sizes to ensure that text sections consist of
      whole fetch packets.  */
   int align = bfd_get_section_alignment (stdoutput, segment);
-  return ((size + (1 << align) - 1) & ((valueT) -1 << align));
+  return ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
 }
 
 /* No special undefined symbol handling needed for now.  */
index f42e767..1091316 100644 (file)
@@ -1879,7 +1879,7 @@ valueT
 md_section_align (asection *seg, valueT addr)
 {
   int align = bfd_get_section_alignment (stdoutput, seg);
-  return ((addr + (1 << align) - 1) & (-1 << align));
+  return ((addr + (1 << align) - 1) & -(1 << align));
 }
 
 void
index 3cc434e..2b656fe 100644 (file)
@@ -224,7 +224,7 @@ md_section_align (asection *seg, valueT addr)
 {
   int align = bfd_get_section_alignment (stdoutput, seg);
 
-  return ((addr + (1 << align) - 1) & (-1 << align));
+  return ((addr + (1 << align) - 1) & -(1 << align));
 }
 
 void
index bcfc845..d5fc3d5 100644 (file)
@@ -235,7 +235,7 @@ valueT
 md_section_align (segT segment, valueT size)
 {
   int align = bfd_get_section_alignment (stdoutput, segment);
-  return ((size + (1 << align) - 1) & (-1 << align));
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
 
 symbolS *
index 3c00b01..afb2578 100644 (file)
@@ -469,7 +469,7 @@ valueT
 md_section_align (asection * seg, valueT addr)
 {
   int align = bfd_get_section_alignment (stdoutput, seg);
-  return ((addr + (1 << align) - 1) & (-1 << align));
+  return ((addr + (1 << align) - 1) & -(1 << align));
 }
 
 void
index 981dc95..3f0613c 100644 (file)
@@ -279,7 +279,7 @@ md_section_align (segT segment, valueT size)
 {
   int align = bfd_get_section_alignment (stdoutput, segment);
 
-  return ((size + (1 << align) - 1) & (-1 << align));
+  return ((size + (1 << align) - 1) & -(1 << align));
 }
 
 symbolS *
index 53440de..5f8bb40 100644 (file)
@@ -4602,7 +4602,7 @@ parse_bitfield_cons (exp, nbytes)
              return;
            }                   /* Too complex.  */
 
-         value |= ((~(-1 << width) & exp->X_add_number)
+         value |= ((~(-(1 << width)) & exp->X_add_number)
                    << ((BITS_PER_CHAR * nbytes) - bits_available));
 
          if ((bits_available -= width) == 0
index 5e1e88f..b125ba6 100644 (file)
@@ -1,3 +1,8 @@
+2015-11-09  Dominik Vogt  <vogt@linux.vnet.ibm.com>
+
+       * gas/all/test-gen.c (random_order_16s, random_order_24s)
+       (random_order_32s): Fix left shift of negative value.
+
 2015-11-02  Nick Clifton  <nickc@redhat.com>
 
        * gas/rx/max.d: Update expected disassembly.
index abd7b9e..97c4d4b 100644 (file)
@@ -404,12 +404,12 @@ int random_order_16s[] =
        generated often enough.  */
     -32768,
     32767,
-    (-1 << 15) | (64 << 8) | 32,
+    (-(1 << 15)) | (64 << 8) | 32,
     (64 << 8) | 32,
     0x1234,
-    (-1 << 15) | 0x8765,
+    (-(1 << 15)) | 0x8765,
     0x0180,
-    (-1 << 15) | 0x8001
+    (-(1 << 15)) | 0x8001
 };
 
 /* Use `24s' to generate 24-bit signed values.  Good for selecting
@@ -420,14 +420,14 @@ int random_order_24s[] =
        intermediate values selected by chance.  Keep the number of
        intermediate values low, to ensure that the limit values are
        generated often enough.  */
-    -1 << 23,
+    -(1 << 23),
     1 << 23 -1,
-    (-1 << 23) | (((64 << 8) | 32) << 8) | 16,
+    (-(1 << 23)) | (((64 << 8) | 32) << 8) | 16,
     (((64 << 8) | 32) << 8) | 16,
     0x123456,
-    (-1 << 23) | 0x876543,
+    (-(1 << 23)) | 0x876543,
     0x01ff80,
-    (-1 << 23) | 0x80ff01
+    (-(1 << 23)) | 0x80ff01
 };
 
 /* Use `32s' to generate 32-bit signed values.  Good for selecting
@@ -438,14 +438,14 @@ int random_order_32s[] =
        intermediate values selected by chance.  Keep the number of
        intermediate values low, to ensure that the limit values are
        generated often enough.  */
-    -1 << 31,
+    -(1 << 31),
     1 << 31 - 1,
-    (-1 << 31) | (((((64 << 8) | 32) << 8) | 16) << 8) | 8,
+    (-(1 << 31)) | (((((64 << 8) | 32) << 8) | 16) << 8) | 8,
     (((((64 << 8) | 32) << 8) | 16) << 8) | 8,
     0x12345678,
-    (-1 << 31) | 0x87654321,
+    (-(1 << 31)) | 0x87654321,
     0x01ffff80,
-    (-1 << 31) | 0x80ffff01
+    (-(1 << 31)) | 0x80ffff01
   };
 
 /* This function computes the number of digits needed to represent a