From 5b512e4f1ec6bc20ed119d09ba0181fdc1e1c41e Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 6 Jun 2026 14:18:52 -0700 Subject: [PATCH] Preserve function and final context in nested scopes Currently checks for statements that are not allowed in functions or final procedures only inspect the immediate scope. If the statement is inside a named block or a block with declarations, the current scope is the block and the context is lost. Make `NetScope::in_func()` and `NetScope::in_final()` preserve the context through begin-end, fork-join and generate block scopes. Other scope types are treated as context boundaries so function and final state does not leak across subroutine or definition scopes. Signed-off-by: Lars-Peter Clausen --- net_scope.cc | 19 ++++++++++++++++++- netlist.h | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/net_scope.cc b/net_scope.cc index cd9e923d0..be9d1c4c6 100644 --- a/net_scope.cc +++ b/net_scope.cc @@ -535,7 +535,24 @@ NetFuncDef* NetScope::func_def() bool NetScope::in_func() const { - return (type_ == FUNC) ? true : false; + if (type_ == FUNC) + return true; + + if (type_ == BEGIN_END || type_ == FORK_JOIN || type_ == GENBLOCK) + return up_ ? up_->in_func() : false; + + return false; +} + +bool NetScope::in_final() const +{ + if (in_final_) + return true; + + if (type_ == BEGIN_END || type_ == FORK_JOIN || type_ == GENBLOCK) + return up_ ? up_->in_final() : false; + + return false; } const NetFuncDef* NetScope::func_def() const diff --git a/netlist.h b/netlist.h index 86bfb9b73..d485a5be8 100644 --- a/netlist.h +++ b/netlist.h @@ -1193,7 +1193,7 @@ class NetScope : public Definitions, public Attrib { /* Is this scope elaborating a final procedure? */ void in_final(bool in_final__) { in_final_ = in_final__; }; - bool in_final() const { return in_final_; }; + bool in_final() const; const NetTaskDef* task_def() const; const NetFuncDef* func_def() const;