aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/ADT/APInt.h
diff options
context:
space:
mode:
authorMeador Inge <meadori@codesourcery.com>2013-02-07 18:36:50 +0000
committerMeador Inge <meadori@codesourcery.com>2013-02-07 18:36:50 +0000
commit35b1423ee67a6ec7052016dda486e6ee4a118db4 (patch)
treede4008f97ca37a551caff7463b7fb6c9ad87121a /include/llvm/ADT/APInt.h
parentdef0c1f756562601829364e3fca4bd1f0407316e (diff)
downloadexternal_llvm-35b1423ee67a6ec7052016dda486e6ee4a118db4.zip
external_llvm-35b1423ee67a6ec7052016dda486e6ee4a118db4.tar.gz
external_llvm-35b1423ee67a6ec7052016dda486e6ee4a118db4.tar.bz2
ADT: Correct APInt::getActiveWords for zero values
PR15138 was opened because of a segfault in the Bitcode writer. The actual issue ended up being a bug in APInt where calls to APInt::getActiveWords returns a bogus value when the APInt value is 0. This patch fixes the problem by ensuring that getActiveWords returns 1 for 0 valued APInts. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174641 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/APInt.h')
-rw-r--r--include/llvm/ADT/APInt.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h
index e67e032..2e623a1 100644
--- a/include/llvm/ADT/APInt.h
+++ b/include/llvm/ADT/APInt.h
@@ -1191,7 +1191,8 @@ public:
/// APInt. This is used in conjunction with getActiveData to extract the raw
/// value of the APInt.
unsigned getActiveWords() const {
- return whichWord(getActiveBits()-1) + 1;
+ unsigned numActiveBits = getActiveBits();
+ return numActiveBits ? whichWord(numActiveBits - 1) + 1 : 1;
}
/// Computes the minimum bit width for this APInt while considering it to be