On i386, binutils-2.17/gas fails to build with clang:

/usr/src/gnu/usr.bin/binutils-2.17/gas/config/tc-i386.c:2107:53: error: signed
      shift result (0x100000000) requires 34 bits to represent, but 'offsetT'
      (aka 'long') only has 32 bits [-Werror,-Wshift-overflow]
                && ((i.op[op].imms->X_add_number & ~(((offsetT) 2 << 31) - 1))
                                                      ~~~~~~~~~~~ ^  ~~

Since ((2 << 31) - 1) is just a fancy way of saying 0xffffffff,
let's use the latter.  Note that this code is compiled on both i386
and amd64.

ok?

Index: gas/config/tc-i386.c
===================================================================
RCS file: /cvs/src/gnu/usr.bin/binutils-2.17/gas/config/tc-i386.c,v
retrieving revision 1.6
diff -u -p -r1.6 tc-i386.c
--- gas/config/tc-i386.c        10 Sep 2016 14:02:32 -0000      1.6
+++ gas/config/tc-i386.c        2 Jun 2017 16:05:49 -0000
@@ -2104,7 +2104,7 @@ optimize_imm ()
                  (((i.op[op].imms->X_add_number & 0xffff) ^ 0x8000) - 0x8000);
              }
            if ((i.types[op] & Imm32)
-               && ((i.op[op].imms->X_add_number & ~(((offsetT) 2 << 31) - 1))
+               && ((i.op[op].imms->X_add_number & ~(offsetT) 0xffffffffL)
                    == 0))
              {
                i.op[op].imms->X_add_number = ((i.op[op].imms->X_add_number
@@ -2183,12 +2183,12 @@ optimize_disp ()
                i.types[op] &= ~Disp64;
              }
            if ((i.types[op] & Disp32)
-               && (disp & ~(((offsetT) 2 << 31) - 1)) == 0)
+               && (disp & ~(offsetT) 0xffffffffL) == 0)
              {
                /* If this operand is at most 32 bits, convert
                   to a signed 32 bit number and don't use 64bit
                   displacement.  */
-               disp &= (((offsetT) 2 << 31) - 1);
+               disp &= (offsetT) 0xffffffffL;
                disp = (disp ^ ((offsetT) 1 << 31)) - ((addressT) 1 << 31);
                i.types[op] &= ~Disp64;
              }
-- 
Christian "naddy" Weisgerber                          [email protected]

Reply via email to