summaryrefslogtreecommitdiffstats
path: root/unittests/Support/ScaledNumberTest.cpp
diff options
context:
space:
mode:
authorDiego Novillo <dnovillo@google.com>2015-05-01 17:59:15 +0000
committerDiego Novillo <dnovillo@google.com>2015-05-01 17:59:15 +0000
commit3c178d82ce6c24cf25232f194142a5b30c6f20c2 (patch)
tree6658365bb156f46fc0e5a203a5c162ee4232d60c /unittests/Support/ScaledNumberTest.cpp
parenta2dd41dead24b530a8a542e5b849560b25fd011a (diff)
Fix infinite recursion in ScaledNumber::toInt.
Patch from dexonsmith. The call to toInt() was calling compareTo() which in some cases would call back to toInt(), creating an infinite loop. Fixed by simplifying the logic in compareTo() to avoid the co-recursion. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236326 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Support/ScaledNumberTest.cpp')
-rw-r--r--unittests/Support/ScaledNumberTest.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/unittests/Support/ScaledNumberTest.cpp b/unittests/Support/ScaledNumberTest.cpp
index 38721552ec95..2f38b2a40fb8 100644
--- a/unittests/Support/ScaledNumberTest.cpp
+++ b/unittests/Support/ScaledNumberTest.cpp
@@ -556,4 +556,9 @@ TEST(ScaledNumberHelpersTest, arithmeticOperators) {
EXPECT_EQ(ScaledNumber<uint64_t>(1, 4), ScaledNumber<uint64_t>(1, 3) << 1);
}
+TEST(ScaledNumberHelpersTest, toIntBug) {
+ ScaledNumber<uint32_t> n(1, 0);
+ EXPECT_EQ(1u, (n * n).toInt<uint32_t>());
+}
+
} // end namespace