diff options
author | Chris Lattner <clattner@nondot.org> | 2021-10-04 21:33:51 -0700 |
---|---|---|
committer | Chris Lattner <clattner@nondot.org> | 2021-10-05 08:41:53 -0700 |
commit | cc697fc292b0a405eaa42c6c8e5f117ba4f7d73b (patch) | |
tree | abca09d0395133e0acf64071f76719d242af32d2 /llvm/lib/Support/APInt.cpp | |
parent | 6831c1d8689bebe745aac1fdd7354c2e2f692c1a (diff) | |
download | llvm-cc697fc292b0a405eaa42c6c8e5f117ba4f7d73b.zip llvm-cc697fc292b0a405eaa42c6c8e5f117ba4f7d73b.tar.gz llvm-cc697fc292b0a405eaa42c6c8e5f117ba4f7d73b.tar.bz2 |
[APInt] Make insertBits and concat work with zero width APInts.
These should both clearly work with our current model for zero width
integers, but don't until now!
Differential Revision: https://reviews.llvm.org/D111113
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 9a22ccb..67ea57c 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -345,7 +345,7 @@ void APInt::flipAllBitsSlowCase() { /// In the slow case, we know the result is large. APInt APInt::concatSlowCase(const APInt &NewLSB) const { unsigned NewWidth = getBitWidth() + NewLSB.getBitWidth(); - APInt Result = NewLSB.zext(NewWidth); + APInt Result = NewLSB.zextOrSelf(NewWidth); Result.insertBits(*this, NewLSB.getBitWidth()); return Result; } @@ -360,9 +360,13 @@ void APInt::flipBit(unsigned bitPosition) { void APInt::insertBits(const APInt &subBits, unsigned bitPosition) { unsigned subBitWidth = subBits.getBitWidth(); - assert(0 < subBitWidth && (subBitWidth + bitPosition) <= BitWidth && + assert(subBitWidth >= 0 && (subBitWidth + bitPosition) <= BitWidth && "Illegal bit insertion"); + // inserting no bits is a noop. + if (subBitWidth == 0) + return; + // Insertion is a direct copy. if (subBitWidth == BitWidth) { *this = subBits; |