ubsan: signed integer multiply overflow
authorAlan Modra <amodra@gmail.com>
Sat, 1 Jan 2022 03:22:53 +0000 (13:52 +1030)
committerAlan Modra <amodra@gmail.com>
Sat, 1 Jan 2022 03:52:11 +0000 (14:22 +1030)
9223371018427387904 * 2 cannot be represented in type 'long', yes, but
we don't care.

* expr.c (expr): Avoid signed overflow.

gas/expr.c

index 03caa91f4d18a8f25361d8d36b4b975cc0c83840..618927a605fde704dd7f3f4c1d23a7409de2024a 100644 (file)
@@ -1959,7 +1959,12 @@ expr (int rankarg,               /* Larger # is higher rank.  */
          switch (op_left)
            {
            default:                    goto general;
-           case O_multiply:            resultP->X_add_number *= v; break;
+           case O_multiply:
+             /* Do the multiply as unsigned to silence ubsan.  The
+                result is of course the same when we throw away high
+                bits of the result.  */
+             resultP->X_add_number *= (valueT) v;
+             break;
            case O_divide:              resultP->X_add_number /= v; break;
            case O_modulus:             resultP->X_add_number %= v; break;
            case O_left_shift: