Various fixes to shift-related undefined behaviour (as specified by Annex J.2 of n1570.pdf).

The behavior is undefined in the following circumstances:
...
— An expression is shifted by a negative number or by an amount greater than or equal
to the width of the promoted expression (6.5.7).
— An expression having signed promoted type is left-shifted and either the value of the
expression is negative or the result of shifting would be not be representable in the
promoted type (6.5.7).