ext: Fix undefined-behavior bug in bitshift
authorSamuel Grayson <sam@samgrayson.me>
Thu, 17 Oct 2019 18:15:57 +0000 (13:15 -0500)
committerSamuel Grayson <sam@samgrayson.me>
Thu, 31 Oct 2019 03:37:54 +0000 (03:37 +0000)
commitdfd4c084f914539e605a1e34e7b3510dcd45f336
treed7eb1964d07cb627bf90ca104992ca070bfd3bd3
parent5260c7efeff525b74f16258057abf83edb57c79e
ext: Fix undefined-behavior bug in bitshift

If a small number or zero is passed in, fp64_exp could be very
negative (-1000 for example). The intent of the line is to evaluate to
zero in these cases, but what it actually did was bitshift right by
1000, which is undefined behavior (according to ubsan) that so happens
to result in 0 on GCC/most architectures. This commit changes the code
to check for cases where the bitshift is larger than the width of the
integer.

Change-Id: I8de4bd8ad170f0321d54689460de449b7f8fb60a
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/21859
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
ext/fputils/fp80.c