Fix access to static variable inside function (#7474) (#7475)

Fixes #7474.
This commit is contained in:
Alex Zhou 2026-04-23 08:17:14 -07:00 committed by GitHub
parent 27e7fdc9eb
commit 7e0f25b41b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 53 additions and 2 deletions

View File

@ -4331,6 +4331,13 @@ class LinkDotResolveVisitor final : public VNVisitor {
<< cellp->modp()->prettyNameQ());
}
}
} else if (allowScope && !allowFTask && VN_IS(foundp->nodep(), NodeFTask)) {
// Function/task used as scope for static variable access (IEEE std 1800-2017 6.21)
// Don't set m_dotText so the static variable resolves as a VarRef rather than
// VarXRef. This is so that V3Begin won't move it out of the function/task's scope.
ok = true;
m_ds.m_dotSymp = foundp;
m_ds.m_dotPos = DP_SCOPE;
} else if (allowFTask && VN_IS(foundp->nodep(), NodeFTask)) {
AstNodeFTaskRef* taskrefp;
if (VN_IS(foundp->nodep(), Task)) {

View File

@ -0,0 +1,18 @@
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of either the GNU Lesser General Public License Version 3
# or the Perl Artistic License Version 2.0.
# SPDX-FileCopyrightText: 2024 Wilson Snyder
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
import vltest_bootstrap
test.scenarios('simulator')
test.compile()
test.execute()
test.passes()

View File

@ -0,0 +1,26 @@
// DESCRIPTION: Verilator: Dotted reference that uses another dotted reference
// as the select expression
//
// This file ONLY is placed under the Creative Commons Public Domain.
// SPDX-FileCopyrightText: 2020 Wilson Snyder
// SPDX-License-Identifier: CC0-1.0
package test_pkg;
class foo;
virtual function void visit();
static int compiled_regex;
compiled_regex = 1;
endfunction
function void end_v();
visit.compiled_regex = 0;
endfunction
endclass
endpackage
module t;
initial begin
$write("*-* All Finished *-*\n");
$finish;
end
endmodule

View File

@ -1,5 +1,5 @@
%Error: t/t_var_xref_bad.v:11:11: Found definition of 'tsk' as a TASK but expected a scope/variable
%Error: t/t_var_xref_bad.v:11:15: Can't find definition of variable/method: 'bad_missing_ref'
11 | initial tsk.bad_missing_ref = 0;
| ^~~
| ^~~~~~~~~~~~~~~
... See the manual at https://verilator.org/verilator_doc.html?v=latest for more assistance.
%Error: Exiting due to