Skip to content

Commit f636773

Browse files
authored
Tidy: fix handling of ranges with non-zero lower bounds in undriven ranges check (MikePopoloski#1527)
1 parent c3e8fd0 commit f636773

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

tools/tidy/src/synthesis/UndrivenRange.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ struct UndrivenRangeVisitor : public TidyVisitor,
4242
void handle(const VariableSymbol& symbol) {
4343

4444
// If the variable has a fixed range, then determine if any ranges are
45-
// undriven.
45+
// undriven. Note that driver bit ranges are zero indexed, so we need to
46+
// offset them by the lower bound of the variable's range.
4647
if (symbol.getType().hasFixedRange()) {
4748
auto range = symbol.getType().getFixedRange();
4849

@@ -62,11 +63,11 @@ struct UndrivenRangeVisitor : public TidyVisitor,
6263
}
6364

6465
for (auto [driver, bounds] : drivers) {
65-
if (bounds.first > current) {
66-
undriven.push_back({current, (int)bounds.first - 1});
66+
if (bounds.first + start > current) {
67+
undriven.push_back({current, (int)bounds.first + start - 1});
6768
}
6869

69-
current = std::max(current, (int)bounds.second + 1);
70+
current = std::max(current, (int)bounds.second + start + 1);
7071
}
7172

7273
if (current <= end) {

tools/tidy/tests/UndrivenRangeTest.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,35 @@ endmodule
8585

8686
CHECK(result);
8787
}
88+
89+
TEST_CASE("Undriven range: ensure variables with non-zero lower bounds are handled correctly") {
90+
std::string output;
91+
auto result = runCheckTest("UndrivenRange", R"(
92+
typedef logic [28:3] data_t;
93+
module offset_bus(input data_t i_input,
94+
output data_t o_output);
95+
assign o_output = i_input;
96+
endmodule
97+
)",
98+
{}, &output);
99+
CHECK(result);
100+
}
101+
102+
TEST_CASE("Undriven range: ensure variables with non-zero lower bounds report the correct undriven "
103+
"bits") {
104+
std::string output;
105+
auto result = runCheckTest("UndrivenRange", R"(
106+
typedef logic [28:3] data_t;
107+
module offset_bus(input data_t i_input,
108+
output data_t o_output);
109+
assign o_output[28:4] = i_input;
110+
endmodule
111+
)",
112+
{}, &output);
113+
CHECK_FALSE(result);
114+
CHECK("\n" + output == R"(
115+
source:4:33: warning: [SYNTHESIS-20] variable o_output has undriven bits: 3
116+
output data_t o_output);
117+
^
118+
)");
119+
}

0 commit comments

Comments
 (0)