From a4f7aaed6826c6b7301c6ed3e99055ff1f322a44 Mon Sep 17 00:00:00 2001 From: Saksham Date: Sun, 21 Jun 2026 00:21:25 +0530 Subject: [PATCH] Fix incomplete enum warnings --- src/V3Case.cpp | 7 +++--- test_regress/t/t_case_incomplete_enum_warn.py | 5 +++++ test_regress/t/t_case_incomplete_enum_warn.v | 22 +++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 test_regress/t/t_case_incomplete_enum_warn.py create mode 100644 test_regress/t/t_case_incomplete_enum_warn.v diff --git a/src/V3Case.cpp b/src/V3Case.cpp index c4d4fbc21..8a4f471b7 100644 --- a/src/V3Case.cpp +++ b/src/V3Case.cpp @@ -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. diff --git a/test_regress/t/t_case_incomplete_enum_warn.py b/test_regress/t/t_case_incomplete_enum_warn.py new file mode 100644 index 000000000..c2e742cc3 --- /dev/null +++ b/test_regress/t/t_case_incomplete_enum_warn.py @@ -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() \ No newline at end of file diff --git a/test_regress/t/t_case_incomplete_enum_warn.v b/test_regress/t/t_case_incomplete_enum_warn.v new file mode 100644 index 000000000..b38913519 --- /dev/null +++ b/test_regress/t/t_case_incomplete_enum_warn.v @@ -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 \ No newline at end of file