diff --git a/Changes b/Changes index f8d51a059..f0e862842 100644 --- a/Changes +++ b/Changes @@ -20,6 +20,7 @@ Verilator 5.015 devel * Fix jumping over object initialization (#4411). [Krzysztof Boroński] * Fix variable lifetimes in extern methods (#4414). [Krzysztof Boroński] * Fix multple function definitions in V3Sched (#4416). [Hennadii Chernyshchyk] +* Fix false UNUSEDPARAM on generate localparam (#4427). [Bill Pringlemeir] Verilator 5.014 2023-08-06 diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 53ab2238a..2718e5c37 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -2256,6 +2256,11 @@ private: // parameters or vice versa return pinp->param() == refVarType.isParam(); } + void updateVarUse(AstVar* nodep) { + // Avoid dotted.PARAM false positive when in a parameter block + // that is if ()'ed off by same dotted name as another block + if (nodep && nodep->isParam()) nodep->usedParam(true); + } // VISITs void visit(AstNetlist* nodep) override { @@ -2922,6 +2927,7 @@ private: if (AstVar* const varp = foundp ? foundToVarp(foundp, nodep, nodep->access()) : nullptr) { nodep->varp(varp); + updateVarUse(nodep->varp()); // Generally set by parse, but might be an import nodep->classOrPackagep(foundp->classOrPackagep()); } @@ -2964,6 +2970,7 @@ private: AstVar* const varp = foundp ? foundToVarp(foundp, nodep, nodep->access()) : nullptr; nodep->varp(varp); + updateVarUse(nodep->varp()); UINFO(7, " Resolved " << nodep << endl); // Also prints varp if (!nodep->varp()) { nodep->v3error("Can't find definition of " @@ -3001,6 +3008,7 @@ private: // later optimizations to deal with VarXRef. nodep->varp(vscp->varp()); nodep->varScopep(vscp); + updateVarUse(nodep->varp()); UINFO(7, " Resolved " << nodep << endl); // Also prints taskp AstVarRef* const newvscp = new AstVarRef{nodep->fileline(), vscp, nodep->access()}; diff --git a/test_regress/t/t_lint_unused_bad.v b/test_regress/t/t_lint_unused_bad.v index cc837c4ec..abcd94e51 100644 --- a/test_regress/t/t_lint_unused_bad.v +++ b/test_regress/t/t_lint_unused_bad.v @@ -64,10 +64,23 @@ module sub; genvar linter_genvar4; // verilator lint_on UNUSED + case (2) + 1: begin : named + localparam BLOCK_PARAM = 10; + end + 2: begin : named + localparam BLOCK_PARAM = 20; + end + 3: begin : named + localparam BLOCK_PARAM = 30; + end + endcase + initial begin if (0 && assunu1[0] != 0 && udrb2 != 0) begin end if (0 && assunub2[THREE] && assunub2[1:0]!=0) begin end if (0 && mixed[1:0] != 0) begin end + if (named.BLOCK_PARAM != 20) $stop; end generate