Fix incomplete enum warnings

This commit is contained in:
Saksham 2026-06-21 00:21:25 +05:30
parent 78a2dc0738
commit a4f7aaed68
3 changed files with 31 additions and 3 deletions

View File

@ -284,6 +284,7 @@ class CaseVisitor final : public VNVisitor {
// Returns true iff the case items cover all enum values/patterns.
bool checkExhaustiveEnum(const AstCase* const nodep, const AstEnumDType* const enump) {
const uint32_t numCases = 1UL << nodep->exprp()->width();
bool fullyCovered = true;
for (AstEnumItem* eip = enump->itemsp(); eip; eip = VN_AS(eip->nextp(), EnumItem)) {
const auto& match = matchPattern(nodep, VN_AS(eip->valuep(), Const));
const uint32_t mask = match.first.toUInt();
@ -298,11 +299,11 @@ class CaseVisitor final : public VNVisitor {
nodep->v3warn(CASEINCOMPLETE,
"Enum item " << eip->prettyNameQ() << " not covered by case");
}
// TODO: warn for all uncovered enum values, not just the first
return false; // enum has uncovered value by case items
fullyCovered = false;
break;
}
}
return true; // enum is fully covered
return fullyCovered; // enum is fully covered
}
// Check and warn if case items are not complete over all possible values.

View File

@ -0,0 +1,5 @@
#!/usr/bin/env python3
import vltest_bootstrap
test.scenarios('linter')
test.lint(fails=True, expect_filename=test.golden_filename)
test.passes()

View File

@ -0,0 +1,22 @@
module test_bug;
// Define an enum with 4 states
typedef enum logic [1:0] {
STATE_IDLE = 2'd0,
STATE_READ = 2'd1,
STATE_WRITE = 2'd2,
STATE_ERROR = 2'd3
} system_state_t;
system_state_t current_state;
initial begin
current_state = STATE_IDLE;
// We only cover IDLE and READ.
// We intentionally leave out WRITE and ERROR!
unique case (current_state)
STATE_IDLE: $display("Idling...");
STATE_READ: $display("Reading...");
endcase
end
endmodule