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.
This commit is contained in:
Alan Modra 2020-08-30 19:37:57 +09:30
parent 34d8e6d0c5
commit c930281005
2 changed files with 770 additions and 772 deletions

View File

@ -1,3 +1,15 @@
2020-08-30 Alan Modra <amodra@gmail.com>
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): Use unsigned variables. Simplify handling of
index regs.
(check_range): Use int32_t variables. Correct range checks.
2020-08-29 Alan Modra <amodra@gmail.com>
PR 26481

File diff suppressed because it is too large Load Diff