From a93aa7cffb70f257b600356421a96d44eadf8dba Mon Sep 17 00:00:00 2001 From: MikePopoloski Date: Mon, 4 Sep 2023 15:46:06 -0400 Subject: [PATCH] Fix inference of parameters from large based integer literals --- source/ast/Expression.cpp | 2 +- tests/unittests/ast/ExpressionTests.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/source/ast/Expression.cpp b/source/ast/Expression.cpp index f076a386d..64d2f4d9b 100644 --- a/source/ast/Expression.cpp +++ b/source/ast/Expression.cpp @@ -388,7 +388,7 @@ std::tuple Expression::bindImplicitParam( if (lhsType->isIntegral()) { bitwidth_t bits = lhsType->getBitWidth(); if (expr.isUnsizedInteger()) - bits = 32; + bits = std::max(bits, 32u); // Keep the signed flag but force four state. auto flags = lhsType->getIntegralFlags(); diff --git a/tests/unittests/ast/ExpressionTests.cpp b/tests/unittests/ast/ExpressionTests.cpp index 89e15eabc..32e48a563 100644 --- a/tests/unittests/ast/ExpressionTests.cpp +++ b/tests/unittests/ast/ExpressionTests.cpp @@ -2956,3 +2956,18 @@ endclass compilation.addSyntaxTree(tree); NO_COMPILATION_ERRORS; } + +TEST_CASE("Type of unsized based literal") { + auto tree = SyntaxTree::fromText(R"( +module m; + parameter p = 'd999999999999; +endmodule +)"); + + Compilation compilation; + compilation.addSyntaxTree(tree); + NO_COMPILATION_ERRORS; + + auto& p = compilation.getRoot().lookupName("m.p"); + CHECK(p.getType().toString() == "logic[39:0]"); +}