Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/ast/expressions/OperatorExpressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2274,7 +2274,7 @@ Expression& ReplicationExpression::fromSyntax(Compilation& compilation,
}

auto width = context.requireValidBitWidth(
SVInt(32, uint64_t(*count), true) * right->type->getBitWidth(), syntax.sourceRange());
SVInt(64, uint64_t(*count), true) * right->type->getBitWidth(), syntax.sourceRange());
if (!width)
return badExpr(compilation, result);

Expand Down
32 changes: 32 additions & 0 deletions tests/unittests/ast/ExpressionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3894,3 +3894,35 @@ endmodule
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}

TEST_CASE("Replication widths are checked before uint32 truncation") {
for (const auto [count, width] :
{std::pair{16777216, 256}, std::pair{16777217, 256}, std::pair{33554432, 256},
std::pair{8388608, 512}, std::pair{4194304, 1024}, std::pair{16777215, 256},
std::pair{2147483647, 2}}) {
for (auto bit : {"0", "1", "x"}) {
CAPTURE(count, width, bit);
auto tree = SyntaxTree::fromText("module m(output logic o); assign o = ^{ " +
std::to_string(count) + "{ {" + std::to_string(width) +
"{1'b" + bit + "}} } }; endmodule");
Compilation compilation;
compilation.addSyntaxTree(tree);
auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 1);
CHECK(diags[0].code == diag::ValueExceedsMaxBitWidth);
}
}
}

TEST_CASE("Replication accepts the maximum supported vector width") {
auto tree = SyntaxTree::fromText(R"(
module m(input logic [16777214:0] v, output logic [16777214:0] o,
output logic [255:0] small_value);
assign o = {1{v}};
assign small_value = {2{128'h1234}};
endmodule
)");
Compilation compilation;
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}
Loading