From bbb231dfe2c1947db6043a516e6d79594533c8c0 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 7 Feb 2026 14:16:12 -0500 Subject: [PATCH] Internals: Minor cleanups preparing for initialization fixes. No functional change. --- src/V3AstNodeDType.h | 2 +- src/V3AstNodeExpr.h | 2 +- src/V3AstNodeOther.h | 16 +++++++------- src/V3Begin.cpp | 2 +- src/V3EmitCFunc.h | 2 ++ src/V3Fork.cpp | 11 ++++++---- test_regress/driver.py | 2 +- test_regress/t/t_lint_historical.v | 2 ++ test_regress/t/t_static_in_loop.v | 25 ++++++++++++++++++++++ test_regress/t/t_static_in_loop_unsup.out | 6 +++--- test_regress/t/t_static_in_loop_unsup.py | 1 + test_regress/t/t_static_in_loop_unsup.v | 26 ----------------------- 12 files changed, 52 insertions(+), 45 deletions(-) create mode 100644 test_regress/t/t_static_in_loop.v delete mode 100644 test_regress/t/t_static_in_loop_unsup.v diff --git a/src/V3AstNodeDType.h b/src/V3AstNodeDType.h index b1cdba11c..d55196555 100644 --- a/src/V3AstNodeDType.h +++ b/src/V3AstNodeDType.h @@ -291,7 +291,7 @@ public: VNumRange declRange() const VL_MT_STABLE { return VNumRange{hi(), lo()}; } AstNodeModule* classOrPackagep() const { return m_classOrPackagep; } void classOrPackagep(AstNodeModule* classpackagep) { m_classOrPackagep = classpackagep; } - bool isConstrainedRand() { return m_constrainedRand; } + bool isConstrainedRand() const { return m_constrainedRand; } void markConstrainedRand(bool flag) { m_constrainedRand = flag; } }; diff --git a/src/V3AstNodeExpr.h b/src/V3AstNodeExpr.h index 63c39fe54..f228f7ca5 100644 --- a/src/V3AstNodeExpr.h +++ b/src/V3AstNodeExpr.h @@ -1367,7 +1367,7 @@ public: return resultp()->isPure(); } bool sameNode(const AstNode*) const override { return true; } - bool hasResult() { return m_hasResult; } + bool hasResult() const { return m_hasResult; } void hasResult(bool flag) { m_hasResult = flag; } }; class AstFError final : public AstNodeExpr { diff --git a/src/V3AstNodeOther.h b/src/V3AstNodeOther.h index e6f9767ef..9fc22e155 100644 --- a/src/V3AstNodeOther.h +++ b/src/V3AstNodeOther.h @@ -2110,26 +2110,26 @@ public: if (flag) m_funcLocalSticky = true; } void funcReturn(bool flag) { m_funcReturn = flag; } + bool gotNansiType() const { return m_gotNansiType; } void gotNansiType(bool flag) { m_gotNansiType = flag; } - bool gotNansiType() { return m_gotNansiType; } + bool hasStrengthAssignment() const { return m_hasStrengthAssignment; } void hasStrengthAssignment(bool flag) { m_hasStrengthAssignment = flag; } - bool hasStrengthAssignment() { return m_hasStrengthAssignment; } - void isDpiOpenArray(bool flag) { m_isDpiOpenArray = flag; } bool isDpiOpenArray() const VL_MT_SAFE { return m_isDpiOpenArray; } + void isDpiOpenArray(bool flag) { m_isDpiOpenArray = flag; } bool isHideLocal() const { return m_isHideLocal; } void isHideLocal(bool flag) { m_isHideLocal = flag; } bool isHideProtected() const { return m_isHideProtected; } void isHideProtected(bool flag) { m_isHideProtected = flag; } - void noCReset(bool flag) { m_noCReset = flag; } bool noCReset() const { return m_noCReset; } - void noReset(bool flag) { m_noReset = flag; } + void noCReset(bool flag) { m_noCReset = flag; } bool noReset() const { return m_noReset; } - void noSubst(bool flag) { m_noSubst = flag; } + void noReset(bool flag) { m_noReset = flag; } bool noSubst() const { return m_noSubst; } - void substConstOnly(bool flag) { m_substConstOnly = flag; } + void noSubst(bool flag) { m_noSubst = flag; } bool substConstOnly() const { return m_substConstOnly; } - void overriddenParam(bool flag) { m_overridenParam = flag; } + void substConstOnly(bool flag) { m_substConstOnly = flag; } bool overriddenParam() const { return m_overridenParam; } + void overriddenParam(bool flag) { m_overridenParam = flag; } void trace(bool flag) { m_trace = flag; } void isLatched(bool flag) { m_isLatched = flag; } bool isForceable() const { return m_isForceable; } diff --git a/src/V3Begin.cpp b/src/V3Begin.cpp index 64f595fd8..517b0e1fe 100644 --- a/src/V3Begin.cpp +++ b/src/V3Begin.cpp @@ -68,7 +68,7 @@ class BeginVisitor final : public VNVisitor { // STATE - for current visit position (use VL_RESTORER) AstNodeModule* m_modp = nullptr; // Current module AstNodeFTask* m_ftaskp = nullptr; // Current function/task - AstNode* m_liftedp = nullptr; // Local nodes we are lifting into m_ftaskp + AstNode* m_liftedp = nullptr; // Local nodes we are lifting into m_ftaskp string m_displayScope; // Name of %m in $display/AstScopeName string m_namedScope; // Name of begin blocks above us string m_unnamedScope; // Name of begin blocks, including unnamed blocks diff --git a/src/V3EmitCFunc.h b/src/V3EmitCFunc.h index 7cd652e43..e05785109 100644 --- a/src/V3EmitCFunc.h +++ b/src/V3EmitCFunc.h @@ -144,6 +144,8 @@ class EmitCFunc VL_NOT_FINAL : public EmitCConstInit { } m_emitDispState; protected: + VL_DEFINE_DEBUG_FUNCTIONS; + EmitCLazyDecls m_lazyDecls{*this}; // Visitor for emitting lazy declarations bool m_useSelfForThis = false; // Replace "this" with "vlSelf" bool m_usevlSelfRef = false; // Use vlSelfRef reference instead of vlSelf pointer diff --git a/src/V3Fork.cpp b/src/V3Fork.cpp index eea0f537a..6b810fffb 100644 --- a/src/V3Fork.cpp +++ b/src/V3Fork.cpp @@ -350,6 +350,7 @@ class DynScopeVisitor final : public VNVisitor { void visit(AstNodeModule* nodep) override { VL_RESTORER(m_modp); if (!VN_IS(nodep, Class)) m_modp = nodep; + VL_RESTORER(m_id); m_id = 0; iterateChildren(nodep); } @@ -385,10 +386,12 @@ class DynScopeVisitor final : public VNVisitor { bindNodeToDynScope(varp, framep); } for (AstNode* stmtp = nodep->stmtsp(); stmtp; stmtp = stmtp->nextp()) { - AstAssign* const asgnp = VN_CAST(stmtp, Assign); - UASSERT_OBJ(asgnp, stmtp, "Invalid node under block item initialization part of fork"); - bindNodeToDynScope(asgnp->lhsp(), framep); - iterate(asgnp->rhsp()); + if (AstAssign* const asgnp = VN_CAST(stmtp, Assign)) { + bindNodeToDynScope(asgnp->lhsp(), framep); + iterate(asgnp->rhsp()); + } else { + stmtp->v3fatalSrc("Invalid node under block item initialization part of fork"); + } } for (AstNode* stmtp = nodep->forksp(); stmtp; stmtp = stmtp->nextp()) { diff --git a/test_regress/driver.py b/test_regress/driver.py index a5bede1d9..d18074b51 100755 --- a/test_regress/driver.py +++ b/test_regress/driver.py @@ -2545,7 +2545,7 @@ class VlTest: if out != '': print(out) self.copy_if_golden(fn1, fn2) - self.error("SAIF files don't match!") + self.error("SAIF files miscompare") def _vcd_read(self, filename: str) -> dict: data = {} diff --git a/test_regress/t/t_lint_historical.v b/test_regress/t/t_lint_historical.v index c9bebb78c..573c429cf 100644 --- a/test_regress/t/t_lint_historical.v +++ b/test_regress/t/t_lint_historical.v @@ -56,6 +56,7 @@ module t; // verilator lint_off INFINITELOOP // verilator lint_off INITIALDLY // verilator lint_off INSECURE + // verilator lint_off INSIDETRUE // verilator lint_off LATCH // verilator lint_off LITENDIAN // verilator lint_off MINTYPMAXDLY @@ -103,6 +104,7 @@ module t; // verilator lint_off UNOPTFLAT // verilator lint_off UNOPTTHREADS // verilator lint_off UNPACKED + // verilator lint_off UNSATCONSTR // verilator lint_off UNSIGNED // verilator lint_off UNUSED // verilator lint_off UNUSEDGENVAR diff --git a/test_regress/t/t_static_in_loop.v b/test_regress/t/t_static_in_loop.v new file mode 100644 index 000000000..466b249e8 --- /dev/null +++ b/test_regress/t/t_static_in_loop.v @@ -0,0 +1,25 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain. +// SPDX-FileCopyrightText: 2023 Antmicro Ltd +// SPDX-License-Identifier: CC0-1.0 + +module t; + initial begin + int x = 0; + while (x < 10) begin : outer_loop + int y = 0; + while (y < x) begin : inner_loop + static int a = 0; + a++; + y++; + end + x++; + end + if (outer_loop.inner_loop.a != 45) $stop; + + $write("*-* All Finished *-*\n"); + $finish; + end + +endmodule diff --git a/test_regress/t/t_static_in_loop_unsup.out b/test_regress/t/t_static_in_loop_unsup.out index 0070d8d3f..48eb55263 100644 --- a/test_regress/t/t_static_in_loop_unsup.out +++ b/test_regress/t/t_static_in_loop_unsup.out @@ -1,6 +1,6 @@ -%Warning-STATICVAR: t/t_static_in_loop_unsup.v:14:24: Static variable with assignment declaration declared in a loop converted to automatic - 14 | static int a = 0; - | ^ +%Warning-STATICVAR: t/t_static_in_loop.v:13:20: Static variable with assignment declaration declared in a loop converted to automatic + 13 | static int a = 0; + | ^ ... For warning description see https://verilator.org/warn/STATICVAR?v=latest ... Use "/* verilator lint_off STATICVAR */" and lint_on around source to disable this message. %Error: Exiting due to diff --git a/test_regress/t/t_static_in_loop_unsup.py b/test_regress/t/t_static_in_loop_unsup.py index 3160d0589..715e8f4a9 100755 --- a/test_regress/t/t_static_in_loop_unsup.py +++ b/test_regress/t/t_static_in_loop_unsup.py @@ -10,6 +10,7 @@ import vltest_bootstrap test.scenarios('vlt') +test.top_filename = "t/t_static_in_loop.v" test.lint(fails=True, expect_filename=test.golden_filename) diff --git a/test_regress/t/t_static_in_loop_unsup.v b/test_regress/t/t_static_in_loop_unsup.v deleted file mode 100644 index 5a2e23ae0..000000000 --- a/test_regress/t/t_static_in_loop_unsup.v +++ /dev/null @@ -1,26 +0,0 @@ -// DESCRIPTION: Verilator: Verilog Test module -// -// This file ONLY is placed under the Creative Commons Public Domain. -// SPDX-FileCopyrightText: 2023 Antmicro Ltd -// SPDX-License-Identifier: CC0-1.0 - - -module t; - initial begin - int x = 0; - while (x < 10) begin : outer_loop - int y = 0; - while (y < x) begin : inner_loop - static int a = 0; - a++; - y++; - end - x++; - end - if (outer_loop.inner_loop.a != 45) $stop; - - $write("*-* All Finished *-*\n"); - $finish; - end - -endmodule