[llvm] 63f417e - [ADT] Remove 0-width Asserts in APInt.getZExtValue
Schuyler Eldridge via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 30 14:03:16 PST 2021
Author: Schuyler Eldridge
Date: 2021-11-30T17:03:12-05:00
New Revision: 63f417ef39963afa9722a7b3c5cf3b28a9d41883
URL: https://github.com/llvm/llvm-project/commit/63f417ef39963afa9722a7b3c5cf3b28a9d41883
DIFF: https://github.com/llvm/llvm-project/commit/63f417ef39963afa9722a7b3c5cf3b28a9d41883.diff
LOG: [ADT] Remove 0-width Asserts in APInt.getZExtValue
Remove assertion that disallows getting a zero-extended value from a
zero-width APInt. This check is too restrictive and makes it difficult
to use APInt to model zero-width things, e.g., zero-width wires in the
CIRCT project.
Signed-off-by: Schuyler Eldridge <schuyler.eldridge at sifive.com>
Reviewed By: lattner, darthscsi, nikic
Differential Revision: https://reviews.llvm.org/D114768
Added:
Modified:
llvm/include/llvm/ADT/APInt.h
llvm/unittests/ADT/APIntTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index 595cd94b6b8f6..c2660502a4192 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -1458,10 +1458,8 @@ class LLVM_NODISCARD APInt {
/// uint64_t. The bitwidth must be <= 64 or the value must fit within a
/// uint64_t. Otherwise an assertion will result.
uint64_t getZExtValue() const {
- if (isSingleWord()) {
- assert(BitWidth && "zero width values not allowed");
+ if (isSingleWord())
return U.VAL;
- }
assert(getActiveBits() <= 64 && "Too many bits for uint64_t");
return U.pVal[0];
}
diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp
index 8a7316335193d..95cb213aa8512 100644
--- a/llvm/unittests/ADT/APIntTest.cpp
+++ b/llvm/unittests/ADT/APIntTest.cpp
@@ -3054,6 +3054,9 @@ TEST(APIntTest, ZeroWidth) {
EXPECT_EQ(0U, APInt(4, 3).trunc(0).getBitWidth());
EXPECT_TRUE(ZW.isAllOnes());
+ // Zero extension.
+ EXPECT_EQ(0U, ZW.getZExtValue());
+
SmallString<42> STR;
ZW.toStringUnsigned(STR);
EXPECT_EQ("0", STR);
More information about the llvm-commits
mailing list