Fixes #7815.
This commit is contained in:
parent
7765738e11
commit
729794bc0e
|
|
@ -252,6 +252,7 @@ Rowan Goemans
|
|||
Rupert Swarbrick
|
||||
Ryan Ziegler
|
||||
Ryszard Rozak
|
||||
Saksham Gupta
|
||||
Samuel Riedel
|
||||
Sean Cross
|
||||
Sebastien Van Cauwenberghe
|
||||
|
|
|
|||
|
|
@ -284,6 +284,8 @@ 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;
|
||||
string missingItems;
|
||||
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();
|
||||
|
|
@ -293,16 +295,17 @@ class CaseVisitor final : public VNVisitor {
|
|||
for (uint32_t i = 0; i < numCases; ++i) {
|
||||
if ((i & mask) != bits) continue; // This case is not for this enum value
|
||||
if (m_caseDetails.records[i].itemp) continue; // Covered case
|
||||
// Warn unless unique0 case which allows no-match
|
||||
if (!nodep->unique0Pragma()) {
|
||||
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
|
||||
if (!missingItems.empty()) missingItems += ", ";
|
||||
missingItems += eip->prettyNameQ();
|
||||
fullyCovered = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true; // enum is fully covered
|
||||
if (!missingItems.empty() && !nodep->unique0Pragma()) {
|
||||
nodep->v3warn(CASEINCOMPLETE,
|
||||
"Enum item(s) not covered by case: " << missingItems);
|
||||
}
|
||||
return fullyCovered; // enum is fully covered
|
||||
}
|
||||
|
||||
// Check and warn if case items are not complete over all possible values.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
%Warning-CASEINCOMPLETE: t/t_case_enum_incomplete_bad.v:18:12: Enum item 'S1' not covered by case
|
||||
%Warning-CASEINCOMPLETE: t/t_case_enum_incomplete_bad.v:18:12: Enum item(s) not covered by case: 'S1', 'S2'
|
||||
18 | unique case (state)
|
||||
| ^~~~
|
||||
... For warning description see https://verilator.org/warn/CASEINCOMPLETE?v=latest
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ module t;
|
|||
|
||||
unique case (state)
|
||||
S0: $stop;
|
||||
S2: $stop;
|
||||
endcase
|
||||
end
|
||||
endmodule
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
%Warning-CASEINCOMPLETE: t/t_case_enum_incomplete_wildcard_bad.v:26:12: Enum item 'S10' not covered by case
|
||||
%Warning-CASEINCOMPLETE: t/t_case_enum_incomplete_wildcard_bad.v:26:12: Enum item(s) not covered by case: 'S10', 'SX0'
|
||||
26 | unique case (state)
|
||||
| ^~~~
|
||||
... For warning description see https://verilator.org/warn/CASEINCOMPLETE?v=latest
|
||||
... Use "/* verilator lint_off CASEINCOMPLETE */" and lint_on around source to disable this message.
|
||||
%Warning-CASEINCOMPLETE: t/t_case_enum_incomplete_wildcard_bad.v:30:12: Enum item 'S00' not covered by case
|
||||
%Warning-CASEINCOMPLETE: t/t_case_enum_incomplete_wildcard_bad.v:30:12: Enum item(s) not covered by case: 'S00', 'SX0', 'S0X'
|
||||
30 | unique case (state)
|
||||
| ^~~~
|
||||
%Warning-CASEINCOMPLETE: t/t_case_enum_incomplete_wildcard_bad.v:35:12: Enum item 'S10' not covered by case
|
||||
%Warning-CASEINCOMPLETE: t/t_case_enum_incomplete_wildcard_bad.v:35:12: Enum item(s) not covered by case: 'S10', 'SX0'
|
||||
35 | unique casez (state)
|
||||
| ^~~~~
|
||||
%Warning-CASEINCOMPLETE: t/t_case_enum_incomplete_wildcard_bad.v:40:5: Case values incompletely covered (example pattern 0x3)
|
||||
|
|
|
|||
Loading…
Reference in New Issue