mirror of https://github.com/llvm/circt.git
[FVInt] Fix printing when bit width is less than one full digit
Printing of `FVInt`s would continuously shift the value right by the log2 of the radix. This triggers an assertion in `APInt` in the case where the bit width is less than the number of bits being shifted.
This commit is contained in:
parent
fcdefe5a1a
commit
aae791b1e9
|
@ -102,8 +102,9 @@ bool FVInt::tryToString(SmallVectorImpl<char> &str, unsigned radix,
|
|||
while (!value.isZero() || !unknown.isZero()) {
|
||||
unsigned digitValue = value.getRawData()[0] & radixMask;
|
||||
unsigned digitUnknown = unknown.getRawData()[0] & radixMask;
|
||||
value.lshrInPlace(radixLog2);
|
||||
unknown.lshrInPlace(radixLog2);
|
||||
unsigned shiftAmount = std::min(radixLog2, getBitWidth());
|
||||
value.lshrInPlace(shiftAmount);
|
||||
unknown.lshrInPlace(shiftAmount);
|
||||
|
||||
// Handle unknown bits. Since we only get to print a single X or Z character
|
||||
// to the string, either all bits in the digit have to be X, or all have to
|
||||
|
|
|
@ -94,6 +94,9 @@ TEST(FVIntTest, StringConversion) {
|
|||
StringRef("12345XZ67890ABCDEF"));
|
||||
ASSERT_EQ(FVInt::fromString("12345xz67890abcdef", 16).toString(16, false),
|
||||
StringRef("12345xz67890abcdef"));
|
||||
|
||||
// Narrow <4 bit integers printed as hex.
|
||||
ASSERT_EQ(FVInt::fromString("10", 2).toString(16), StringRef("2"));
|
||||
}
|
||||
|
||||
TEST(FVIntTest, LogicOps) {
|
||||
|
|
Loading…
Reference in New Issue