Fix for loop missing initializer, bug1605.

This commit is contained in:
Wilson Snyder 2019-11-15 18:24:55 -05:00
parent 30c2e53f9e
commit e9c4ffa04e
3 changed files with 15 additions and 2 deletions

View File

@ -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

View File

@ -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 "<<loopValue<<endl);
V3Number res = V3Number(nodep);
@ -352,6 +352,10 @@ private:
}
}
}
if (!newbodysp) { // initp might have effects after the loop
newbodysp = initp; // Maybe NULL
initp = NULL;
}
// Replace the FOR()
if (newbodysp) nodep->replaceWith(newbodysp);
else nodep->unlinkFrBack();

View File

@ -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