Skip to content

Commit

Permalink
Fix detecting local vars in nested forks (verilator#4493) (verilator#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilrakoczy authored Sep 19, 2023
1 parent b9ea249 commit a16ea94
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
10 changes: 6 additions & 4 deletions src/V3Fork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,11 @@ class ForkVisitor final : public VNVisitor {
VL_RESTORER(m_capturedVarsp);
VL_RESTORER(m_capturedVarRefsp);
VL_RESTORER(m_newProcess);
VL_RESTORER(m_forkLocalsp);
m_capturedVarsp = nullptr;
m_capturedVarRefsp = nullptr;
m_newProcess = false;
m_forkLocalsp.clear();

iterateChildren(nodep);

Expand Down Expand Up @@ -566,7 +568,6 @@ class ForkVisitor final : public VNVisitor {
if (!nodep->joinType().join()) {
++m_forkDepth;
m_newProcess = true;
m_forkLocalsp.clear();
// Nested forks get moved into separate tasks
if (nested) {
visitTaskifiable(nodep);
Expand Down Expand Up @@ -604,9 +605,10 @@ class ForkVisitor final : public VNVisitor {
UASSERT_OBJ(
!nodep->varp()->lifetime().isNone(), nodep,
"Variable's lifetime is unknown. Can't determine if a capture is necessary.");

AstVar* const varp = captureRef(nodep);
nodep->varp(varp);
if (m_forkLocalsp.count(nodep->varp()) == 0) {
AstVar* const varp = captureRef(nodep);
nodep->varp(varp);
}
}
}
void visit(AstAssign* nodep) override {
Expand Down
8 changes: 3 additions & 5 deletions test_regress/t/t_fork_none_var.pl
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
compile(
verilator_flags2 => ["--exe --main --timing"],
make_main => 0,
fails => $Self->{vlt_all}, # issue #4493
);

# issue #4493
#execute(
# check_finished => 1,
# );
execute(
check_finished => 1,
);

ok(1);
1;
2 changes: 1 addition & 1 deletion test_regress/t/t_fork_none_var.v
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module t(/*AUTOARG*/);
fork
automatic int k = i;
begin
// issue #4493
// see issue #4493
$display("[%0t] start %0d", $time, k);
// UVM's arb_sequence_q[is_relevant_entries[k]].wait_for_relevant();
m_mask[k] = 1;
Expand Down
4 changes: 1 addition & 3 deletions test_regress/t/t_uvm_pkg_todo.vh
Original file line number Diff line number Diff line change
Expand Up @@ -19192,9 +19192,7 @@ task uvm_sequencer_base::m_wait_for_available_sequence();
fork
automatic int k = i;
begin
//TODO issue #4493 - Fix UVM fork..join_none local variable can't locate varref scope
//TODO %Error: Internal Error: t/t_uvm_pkg_todo.vh:19203:56: ../V3Scope.cpp:80: Can't locate varref scope
//TODO arb_sequence_q[is_relevant_entries[k]].sequence_ptr.wait_for_relevant();
arb_sequence_q[is_relevant_entries[k]].sequence_ptr.wait_for_relevant();
if ($realtime != m_last_wait_relevant_time) begin
m_last_wait_relevant_time = $realtime ;
m_wait_relevant_count = 0 ;
Expand Down

0 comments on commit a16ea94

Please sign in to comment.