diff --git a/Changes b/Changes index 02a80acac..1310057cb 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,8 @@ The contributors that suggested a given feature are shown in []. Thanks! * Verilator 4.023 devel +**** Fix for loop missing initializer, bug1605. [Andrew Holme] + * Verilator 4.022 2019-11-10 diff --git a/src/V3Unroll.cpp b/src/V3Unroll.cpp index dd2453afa..71365769b 100644 --- a/src/V3Unroll.cpp +++ b/src/V3Unroll.cpp @@ -277,7 +277,7 @@ private: if (initp) { initp->unlinkFrBack(); // Always a single statement; nextp() may be nodep // Don't add to list, we do it once, and setting loop index isn't - // needed as we're constant propagating it + // needed if we have > 1 loop, as we're constant propagating it } if (precondsp) { precondsp->unlinkFrBackWithNext(); @@ -296,8 +296,8 @@ private: AstNode* newbodysp = NULL; ++m_statLoops; + int times = 0; if (stmtsp) { - int times = 0; while (1) { UINFO(8," Looping "<replaceWith(newbodysp); else nodep->unlinkFrBack(); diff --git a/test_regress/t/t_for_loop.v b/test_regress/t/t_for_loop.v index 8d8c4acc5..5cc70b77c 100644 --- a/test_regress/t/t_for_loop.v +++ b/test_regress/t/t_for_loop.v @@ -94,6 +94,13 @@ module t (/*AUTOARG*/ for (; ; ++i) begin ++loops; break; end if (loops !== 1) $stop; // + // bug1605 + i = 1; + for (i=20; 0; ) ; + if (i != 20) $stop; + for (i=30; i<10; i++) ; + if (i != 30) $stop; + // $write("*-* All Finished *-*\n"); $finish; end