resolve gas shift expressions with large exponents to zero
authorAlan Modra <amodra@gmail.com>
Thu, 26 Jan 2023 08:14:51 +0000 (18:44 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 26 Jan 2023 21:48:46 +0000 (08:18 +1030)
* expr.c (resolve_expression <O_left_shift, O_right_shift>): Resolve
shifts exceeding bits in a valueT to zero.

gas/expr.c

index ba3d2109b9d3d481f59a4ba87eb84065a9b6e0bc..794be6f09d8a25a7e7b2136c62b101c962c33997 100644 (file)
@@ -2320,8 +2320,18 @@ resolve_expression (expressionS *expressionP)
            return 0;
          left = (offsetT) left % (offsetT) right;
          break;
-       case O_left_shift:              left <<= right; break;
-       case O_right_shift:             left >>= right; break;
+       case O_left_shift:
+         if (right >= sizeof (left) * CHAR_BIT)
+           left = 0;
+         else
+           left <<= right;
+         break;
+       case O_right_shift:
+         if (right >= sizeof (left) * CHAR_BIT)
+           left = 0;
+         else
+           left >>= right;
+         break;
        case O_bit_inclusive_or:        left |= right; break;
        case O_bit_or_not:              left |= ~right; break;
        case O_bit_exclusive_or:        left ^= right; break;