Skip to content

Commit

Permalink
Don't require an extra bit for the sign for signed vector literals wi…
Browse files Browse the repository at this point in the history
…th a binary, octal, or hex base
  • Loading branch information
MikePopoloski committed Oct 18, 2024
1 parent 8b2a9b7 commit 2e6c82b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 0 additions & 4 deletions source/parsing/NumberParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,6 @@ Token NumberParser::finishValue(Token firstToken, bool singleToken, bool isNegat
if (!digits[0].isUnknown())
bits += (bitwidth_t)std::bit_width(digits[0].value);

// Signed numbers need an extra bit for the sign.
if (signFlag)
bits++;

if (bits > sizeBits) {
if (sizeBits == 0) {
if (bits > SVInt::MAX_BITS) {
Expand Down
6 changes: 4 additions & 2 deletions tests/unittests/parsing/ExpressionParsingTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,15 +917,17 @@ TEST_CASE("Vector literal overflow parsing") {
shortint a = -16'sd32769;
int b = -32'sd2147483649;
int c = 32'd4294967297;
// No warnings for these
int d = 9'so777;
int e = 4'sb1000;
)";
parseCompilationUnit(text);

REQUIRE(diagnostics.size() == 4);
REQUIRE(diagnostics.size() == 3);
CHECK(diagnostics[0].code == diag::VectorLiteralOverflow);
CHECK(diagnostics[1].code == diag::VectorLiteralOverflow);
CHECK(diagnostics[2].code == diag::VectorLiteralOverflow);
CHECK(diagnostics[3].code == diag::VectorLiteralOverflow);
}

TEST_CASE("Diagnosing missing base after signed specifier parsing") {
Expand Down

0 comments on commit 2e6c82b

Please sign in to comment.