diff --git a/Changes b/Changes index 8e139e7eb..93fd64859 100644 --- a/Changes +++ b/Changes @@ -19,6 +19,8 @@ indicates the contributor was also the author of the fix; Thanks! **** Fix $signed casts under generates, bug999. [Clifford Wolf] +**** Fix genvar constant propagation from package, bug1003. [Johan Bjork] + * Verilator 3.878 2015-11-01 diff --git a/src/V3Simulate.h b/src/V3Simulate.h index 60a0301b0..6be2813de 100644 --- a/src/V3Simulate.h +++ b/src/V3Simulate.h @@ -255,6 +255,7 @@ private: virtual void visit(AstVarRef* nodep, AstNUser*) { if (jumpingOver(nodep)) return; if (!optimizable()) return; // Accelerate + nodep->varp()->iterateChildren(*this); AstNode* vscp = varOrScope(nodep); // We can't have non-delayed assignments with same value on LHS and RHS @@ -282,10 +283,10 @@ private: if (!m_params && (vscp->user1() & VU_LV)) clearOptimizable(nodep,"Var write & read"); vscp->user1( vscp->user1() | VU_RV); bool isConst = nodep->varp()->isParam(); - AstConst* constp = (isConst ? nodep->varp()->valuep()->castConst() : NULL); - if (isConst && constp) { // Propagate PARAM constants for constant function analysis + V3Number* nump = isConst ? fetchNumberNull(nodep->varp()->valuep()) : NULL; + if (isConst && nump) { // Propagate PARAM constants for constant function analysis if (!m_checkOnly && optimizable()) { - newNumber(vscp)->opAssign(constp->num()); + newNumber(vscp)->opAssign(*nump); } } else { if (m_checkOnly) varRefCb (nodep); diff --git a/test_regress/t/t_func_const.v b/test_regress/t/t_func_const.v index a783b8f8b..fa0ed25e7 100644 --- a/test_regress/t/t_func_const.v +++ b/test_regress/t/t_func_const.v @@ -3,6 +3,11 @@ // This file ONLY is placed into the Public Domain, for any use, // without warranty, 2009 by Wilson Snyder. +package testpackage; + localparam PARAM = 1024 >> 3; +endpackage +import testpackage::*; + module t; localparam P4 = f_add(P3,1); @@ -12,6 +17,7 @@ module t; localparam P18 = f_case(P4); localparam P6 = f_return(P4); localparam P3 = 3; + localparam P128 = f_package(); typedef struct packed { logic [7:0] data; @@ -42,10 +48,15 @@ module t; if (bigparam.first != 1'b1) $stop; if (bigparam.second != 1'b0) $stop; if (bigparam.data != 32'hfff12fff) $stop; + if (P128 != 128) $stop; $write("*-* All Finished *-*\n"); $finish; end + function integer f_package(); + return PARAM; + endfunction + function integer f_add(input [31:0] a, input [31:0] b); f_add = a+b; endfunction