summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorMichael Gottesman <mgottesman@apple.com>2014-01-19 20:33:48 +0000
committerMichael Gottesman <mgottesman@apple.com>2014-01-19 20:33:48 +0000
commit7320de5ce2f440190caab6a248c6c207bb3003d1 (patch)
tree5593b90e41bec506cc3532e48c558a1c0492e50f /unittests
parente7413972a42ebb9ff63df448cc1ed40ff7a6d20d (diff)
downloadllvm-7320de5ce2f440190caab6a248c6c207bb3003d1.tar.gz
llvm-7320de5ce2f440190caab6a248c6c207bb3003d1.tar.bz2
llvm-7320de5ce2f440190caab6a248c6c207bb3003d1.tar.xz
[APInt] Fix nearestLogBase2 to return correct answers for very large APInt and APInt with a bitwidth of 1.
I also improved the comments, added some more tests, etc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199610 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/ADT/APIntTest.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/unittests/ADT/APIntTest.cpp b/unittests/ADT/APIntTest.cpp
index 01a30dfd20..ee547db52a 100644
--- a/unittests/ADT/APIntTest.cpp
+++ b/unittests/ADT/APIntTest.cpp
@@ -665,6 +665,17 @@ TEST(APIntTest, nearestLogBase2) {
uint64_t I6[4] = {0x0, 0x0, 0x0, 0x18};
APInt A6(integerPartWidth*4, ArrayRef<integerPart>(I6, 4));
EXPECT_EQ(A6.nearestLogBase2(), A6.ceilLogBase2());
+
+ // Test BitWidth == 1 special cases.
+ APInt A7(1, 1);
+ EXPECT_EQ(A7.nearestLogBase2(), 0ULL);
+ APInt A8(1, 0);
+ EXPECT_EQ(A8.nearestLogBase2(), UINT32_MAX);
+
+ // Test the zero case when we have a bit width large enough such
+ // that the bit width is larger than UINT32_MAX-1.
+ APInt A9(UINT32_MAX, 0);
+ EXPECT_EQ(A9.nearestLogBase2(), UINT32_MAX);
}
}