LoongArch: Remove undefined behavior from code [PR 106097]
authorLulu Cheng <chenglulu@loongson.cn>
Mon, 27 Jun 2022 08:26:25 +0000 (16:26 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Wed, 29 Jun 2022 08:10:33 +0000 (16:10 +0800)
commitef1c61dd8be966b974ccb525922f6d79112b807f
tree441dd0345639d5e9af4ce52cbcb26be391f9bbe2
parent306733df26db99916fc9f46dad3c1a9814d13462
LoongArch: Remove undefined behavior from code [PR 106097]

C++2017 and previous standard description:

The value of E1 << E2 is E1 left-shifted E2 bit positions;
vacated bits are zero-filled. If E1 has an unsigned type,
the value of the result is E1×2E2, reduced modulo one more
than the maximum value representable inthe result type.
Otherwise, if E1 has a signed type and non-negative value,
and E1×2E2 is representablein the corresponding unsigned
type of the result type, then that value, converted to the
result type, is the resulting value; otherwise, the behavior
is undefined.

The value of E1 >> E2 is E1 right-shifted E2 bit positions.
If E1 has an unsigned type or if E1 has a signed type and
a non-negative value, the value of the result is the integral
part of the quotient of E1/2E2. If E1 has a signed type and
a negative value, the resulting value is implementation-defined.

gcc/ChangeLog:

PR target/106097
* config/loongarch/loongarch.cc (loongarch_build_integer):
Remove undefined behavior from code.

(cherry picked from commit 43653547e7c8da2cd861bceb4a3e4bd338787ced)
gcc/config/loongarch/loongarch.cc