From 10d0088f735cd485aed406185bcd1d2c4e7fe84e Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 12 Feb 2023 18:14:18 -0500 Subject: [PATCH] Fix generate case with empty body statements. --- Changes | 1 + src/V3Param.cpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 03ac89d67..e0bd5e8ed 100644 --- a/Changes +++ b/Changes @@ -85,6 +85,7 @@ Verilator 5.006 2023-01-22 * Fix elaboration of member selected classes (#3890). [Ilya Barkov] * Fix mismatched widths in DFG (#3872). [Geza Lore, Yike Zhou] * Fix lint for non-integral types in packed structs. +* Fix generate case with empty body statements. Verilator 5.004 2022-12-14 diff --git a/src/V3Param.cpp b/src/V3Param.cpp index c4a8f69de..e4ebfd493 100644 --- a/src/V3Param.cpp +++ b/src/V3Param.cpp @@ -1250,6 +1250,7 @@ class ParamVisitor final : public VNVisitor { } void visit(AstGenCase* nodep) override { UINFO(9, " GENCASE " << nodep << endl); + bool hit = false; AstNode* keepp = nullptr; iterateAndNextNull(nodep->exprp()); V3Case::caseLint(nodep); @@ -1275,7 +1276,10 @@ class ParamVisitor final : public VNVisitor { if (const AstConst* const ccondp = VN_CAST(ep, Const)) { V3Number match{nodep, 1}; match.opEq(ccondp->num(), exprp->num()); - if (!keepp && match.isNeqZero()) keepp = itemp->stmtsp(); + if (!hit && match.isNeqZero()) { + hit = true; + keepp = itemp->stmtsp(); + } } else { itemp->v3error("Generate Case item does not evaluate to constant"); } @@ -1286,7 +1290,10 @@ class ParamVisitor final : public VNVisitor { for (AstCaseItem* itemp = nodep->itemsp(); itemp; itemp = VN_AS(itemp->nextp(), CaseItem)) { if (itemp->isDefault()) { - if (!keepp) keepp = itemp->stmtsp(); + if (!hit) { + hit = true; + keepp = itemp->stmtsp(); + } } } // Replace