From e7413972a42ebb9ff63df448cc1ed40ff7a6d20d Mon Sep 17 00:00:00 2001 From: Michael Gottesman Date: Sun, 19 Jan 2014 20:33:38 +0000 Subject: [APInt] Fixed bug where APInt(UINT32_MAX, 0) would blow up when being constructed. This was due to arithmetic overflow in the getNumBits() computation. Now we cast BitWidth to a uint64_t so that does not occur during the computation. After the computation is complete, the uint64_t is truncated when the function returns. I know that this is not something that is likely to happen, but it *IS* a valid input and we should not blow up. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199609 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/ADT/APIntTest.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'unittests') diff --git a/unittests/ADT/APIntTest.cpp b/unittests/ADT/APIntTest.cpp index 5043aa0eec..01a30dfd20 100644 --- a/unittests/ADT/APIntTest.cpp +++ b/unittests/ADT/APIntTest.cpp @@ -623,6 +623,14 @@ TEST(APIntTest, arrayAccess) { } } +TEST(APIntTest, LargeAPIntConstruction) { + // Check that we can properly construct very large APInt. It is very + // unlikely that people will ever do this, but it is a legal input, + // so we should not crash on it. + APInt A9(UINT32_MAX, 0); + EXPECT_FALSE(A9.getBoolValue()); +} + TEST(APIntTest, nearestLogBase2) { // Single word check. -- cgit v1.2.3