diff --git a/src/V3LinkJump.cpp b/src/V3LinkJump.cpp index 030bccbf7..99e9dc5ba 100644 --- a/src/V3LinkJump.cpp +++ b/src/V3LinkJump.cpp @@ -356,14 +356,14 @@ class LinkJumpVisitor final : public VNVisitor { void visit(AstReturn* nodep) override { iterateChildren(nodep); const AstFunc* const funcp = VN_CAST(m_ftaskp, Func); - if (m_inFork) { - nodep->v3error("Return isn't legal under fork (IEEE 1800-2023 9.2.3)"); - VL_DO_DANGLING(pushDeletep(nodep->unlinkFrBack()), nodep); - return; - } else if (!m_ftaskp && m_randsequencep) { + if (m_randsequencep) { nodep->replaceWith(new AstRSReturn{nodep->fileline()}); VL_DO_DANGLING(pushDeletep(nodep), nodep); return; + } else if (m_inFork) { + nodep->v3error("Return isn't legal under fork (IEEE 1800-2023 9.2.3)"); + VL_DO_DANGLING(pushDeletep(nodep->unlinkFrBack()), nodep); + return; } else if (!m_ftaskp) { nodep->v3error("Return isn't underneath a task or function"); } else if (funcp && !nodep->lhsp() && !funcp->isConstructor()) { diff --git a/test_regress/t/t_randsequence_svtests.v b/test_regress/t/t_randsequence_svtests.v index 0955c8b5f..1b18daa60 100644 --- a/test_regress/t/t_randsequence_svtests.v +++ b/test_regress/t/t_randsequence_svtests.v @@ -7,6 +7,19 @@ module t; + function int abort_break(); + int x; + static int return_on = 1; + randsequence( main ) + main : first second third; + first : { x = x + 20; }; + second : { if (return_on == 1) return; x = x + 10; }; + third : { x = x + 5;}; + endsequence + return x; + endfunction + + initial begin int x; bit flag = 1; @@ -133,7 +146,7 @@ module t; main : first second third; first : { x = x + 20; }; second : { if (return_on == 1) return; x = x + 10; }; - third : { x = x + 5;}; + third : { x = x + 5; }; endsequence `checkd(x, 25); @@ -143,7 +156,7 @@ module t; main : first second third; first : { x = x + 20; }; second : { if (return_on == 1) return; x = x + 10; }; - third : { x = x + 5;}; + third : { x = x + 5; }; endsequence `checkd(x, 35); @@ -160,6 +173,9 @@ module t; `checkd(x, 17); `endif + x = abort_break(); + `checkd(x, 25); + $finish; end