Fix for failing test from sanitizer-x86_64-linux-fast where there was a

left shift on a negative value.

llvm-svn: 339037
This commit is contained in:
Leonard Chan 2018-08-06 17:55:38 +00:00
parent e98b9d4c74
commit b30502efc3
1 changed files with 7 additions and 0 deletions

View File

@ -364,12 +364,19 @@ TEST(FixedPoint, compare) {
void CheckUnsaturatedConversion(FixedPointSemantics Src, void CheckUnsaturatedConversion(FixedPointSemantics Src,
FixedPointSemantics Dst, int64_t TestVal) { FixedPointSemantics Dst, int64_t TestVal) {
int64_t ScaledVal = TestVal; int64_t ScaledVal = TestVal;
bool IsNegative = ScaledVal < 0;
if (IsNegative)
ScaledVal = -ScaledVal;
if (Dst.getScale() > Src.getScale()) { if (Dst.getScale() > Src.getScale()) {
ScaledVal <<= (Dst.getScale() - Src.getScale()); ScaledVal <<= (Dst.getScale() - Src.getScale());
} else { } else {
ScaledVal >>= (Src.getScale() - Dst.getScale()); ScaledVal >>= (Src.getScale() - Dst.getScale());
} }
if (IsNegative)
ScaledVal = -ScaledVal;
APFixedPoint Fixed(TestVal, Src); APFixedPoint Fixed(TestVal, Src);
APFixedPoint Expected(ScaledVal, Dst); APFixedPoint Expected(ScaledVal, Dst);
ASSERT_EQ(Fixed.convert(Dst), Expected); ASSERT_EQ(Fixed.convert(Dst), Expected);