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.