aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/APFloat.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@intel.com>2020-09-30 19:31:08 -0700
committerCraig Topper <craig.topper@intel.com>2020-09-30 19:32:34 -0700
commit12bdd427b33a75bd7abb5d4cb095d0b983328034 (patch)
tree36c967fd3d262314167e90bae763f50bcdeb7075 /llvm/lib/Support/APFloat.cpp
parentd4a1db4f3fd7ce701454127465dd0ddbdb7face2 (diff)
downloadllvm-12bdd427b33a75bd7abb5d4cb095d0b983328034.zip
llvm-12bdd427b33a75bd7abb5d4cb095d0b983328034.tar.gz
llvm-12bdd427b33a75bd7abb5d4cb095d0b983328034.tar.bz2
[APFloat] Improve asserts in isSignificandAllOnes and isSignificandAllZeros so they protect shift operations from undefined behavior.
For example, the assert in isSignificandAllZeros allowed NumHighBits to be integerPartWidth. But since it is used directly as a shift amount it must be less than integerPartWidth.
Diffstat (limited to 'llvm/lib/Support/APFloat.cpp')
-rw-r--r--llvm/lib/Support/APFloat.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index c5adbe9..58e49b5 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -850,8 +850,8 @@ bool IEEEFloat::isSignificandAllOnes() const {
// Set the unused high bits to all ones when we compare.
const unsigned NumHighBits =
PartCount*integerPartWidth - semantics->precision + 1;
- assert(NumHighBits <= integerPartWidth && "Can not have more high bits to "
- "fill than integerPartWidth");
+ assert(NumHighBits <= integerPartWidth && NumHighBits > 0 &&
+ "Can not have more high bits to fill than integerPartWidth");
const integerPart HighBitFill =
~integerPart(0) << (integerPartWidth - NumHighBits);
if (~(Parts[PartCount - 1] | HighBitFill))
@@ -870,9 +870,10 @@ bool IEEEFloat::isSignificandAllZeros() const {
if (Parts[i])
return false;
+ // Compute how many bits are used in the final word.
const unsigned NumHighBits =
PartCount*integerPartWidth - semantics->precision + 1;
- assert(NumHighBits <= integerPartWidth && "Can not have more high bits to "
+ assert(NumHighBits < integerPartWidth && "Can not have more high bits to "
"clear than integerPartWidth");
const integerPart HighBitMask = ~integerPart(0) >> NumHighBits;