ubsan: undefined shift in sign_extend

* libhppa.h (sign_extend): Avoid undefined behaviour.
This commit is contained in:
Alan Modra 2022-08-13 14:07:31 +09:30
parent 8c68d88cc4
commit 9effb9f15f

View File

@ -162,7 +162,7 @@ enum hppa_reloc_expr_type_alt
static inline unsigned ATTRIBUTE_UNUSED
sign_extend (unsigned x, unsigned len)
{
unsigned signbit = (1 << (len - 1));
unsigned signbit = (1u << (len - 1));
unsigned mask = (signbit << 1) - 1;
return ((x & mask) ^ signbit) - signbit;
}