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 06:43:37 +0000 (14:43 +0800)
commit43653547e7c8da2cd861bceb4a3e4bd338787ced
tree5ceae88828d4f0a36774914bad8785dab44cf64f
parentb93ae1a01bbad59ee77b7c84f4743a730138ba87
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.
gcc/config/loongarch/loongarch.cc