PR26437, PR26438 UBSAN: tc-cr16.c left shifts and overflows
authorAlan Modra <amodra@gmail.com>
Sun, 30 Aug 2020 10:07:57 +0000 (19:37 +0930)
committerAlan Modra <amodra@gmail.com>
Sun, 30 Aug 2020 11:19:18 +0000 (20:49 +0930)
commitc930281005b0a01ab824864c231c19c297bfdda5
tree100a7c5da77337a593a8dc18387219ecddf7a179
parent34d8e6d0c5f3c51d0e7858572791d8269b9d0f1c
PR26437, PR26438 UBSAN: tc-cr16.c left shifts and overflows

Always use unsigned constants in expressions generating masks.  The
following trys mightily to avoid UB (but hits it anyway with bits=32
and 0x7fffffff << 1), and worse, for 32-bit int, 64-bit long, bits=32
doesn't generate 0xffffffff.
    max = ((((1 << (bits - 1)) - 1) << 1) | 1);
results in -1, or max = 0xffffffffffffffff.

This patch fixes that problem, a possible shift exponent of -1U,
removes some dead code, and makes general tidies.

PR26437
PR26438
* config/tc-cr16.c: Include limits.h, formatting.
(CR16_PRINT): Wrap params in parentheses.  Remove parens from uses
throughout file.
(getconstant): Handle zero nbits.
(print_operand): Simplify handling of index regs.
(check_range): Use int32_t variables.  Correct range checks.
gas/ChangeLog
gas/config/tc-cr16.c
This page took 0.024264 seconds and 4 git commands to generate.