summaryrefslogtreecommitdiff
path: root/include/llvm/ADT/APInt.h
diff options
context:
space:
mode:
authorMichael Gottesman <mgottesman@apple.com>2014-01-19 20:33:38 +0000
committerMichael Gottesman <mgottesman@apple.com>2014-01-19 20:33:38 +0000
commite7413972a42ebb9ff63df448cc1ed40ff7a6d20d (patch)
tree2ad31fff2bddb290cf274c7b8acad946129288fe /include/llvm/ADT/APInt.h
parentb45edea9b3575ee8738cac38d51f24c66b2c09e0 (diff)
downloadllvm-e7413972a42ebb9ff63df448cc1ed40ff7a6d20d.tar.gz
llvm-e7413972a42ebb9ff63df448cc1ed40ff7a6d20d.tar.bz2
llvm-e7413972a42ebb9ff63df448cc1ed40ff7a6d20d.tar.xz
[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
Diffstat (limited to 'include/llvm/ADT/APInt.h')
-rw-r--r--include/llvm/ADT/APInt.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h
index 8bfdcbfa36..8f5c72d8a2 100644
--- a/include/llvm/ADT/APInt.h
+++ b/include/llvm/ADT/APInt.h
@@ -1265,7 +1265,7 @@ public:
/// \returns the number of words to hold the integer value with a given bit
/// width.
static unsigned getNumWords(unsigned BitWidth) {
- return (BitWidth + APINT_BITS_PER_WORD - 1) / APINT_BITS_PER_WORD;
+ return ((uint64_t)BitWidth + APINT_BITS_PER_WORD - 1) / APINT_BITS_PER_WORD;
}
/// \brief Compute the number of active bits in the value