From 7320de5ce2f440190caab6a248c6c207bb3003d1 Mon Sep 17 00:00:00 2001 From: Michael Gottesman Date: Sun, 19 Jan 2014 20:33:48 +0000 Subject: [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 --- unittests/ADT/APIntTest.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'unittests') 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(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); } } -- cgit v1.2.3