Fix static call after covergroup (#6916 repair)

This commit is contained in:
Wilson Snyder 2026-01-18 19:58:33 -05:00
parent db9bd3a792
commit ac4f9f013e
5 changed files with 54 additions and 3 deletions

View File

@ -139,6 +139,13 @@ AstNode* AstNode::abovep() const {
const AstNode* const firstp = firstAbovep() ? this : m_headtailp;
return firstp->backp();
}
AstNode* AstNode::aboveLoopp() const {
// Returns parent node. Avoid using this, may have performance issues.
const AstNode* nodep = this;
// Backwards over peers (versus parents)
while (nodep->backp() && nodep->backp()->nextp() == nodep) nodep = nodep->backp();
return nodep->backp();
}
string AstNode::encodeName(const string& namein) {
// Encode signal name raw from parser, then not called again on same signal

View File

@ -540,6 +540,7 @@ public:
AstNode* nextp() const VL_MT_STABLE { return m_nextp; }
AstNode* backp() const VL_MT_STABLE { return m_backp; }
AstNode* abovep() const; // Get parent node above, only for list head and tail
AstNode* aboveLoopp() const; // Get parent node above, may have performance issues as loops
AstNode* op1p() const VL_MT_STABLE { return m_op1p; }
AstNode* op2p() const VL_MT_STABLE { return m_op2p; }
AstNode* op3p() const VL_MT_STABLE { return m_op3p; }

View File

@ -6654,7 +6654,7 @@ class WidthVisitor final : public VNVisitor {
return VN_CAST(pkgItemp->backp(), Package);
}
const AstClass* containingClass(AstNode* nodep) {
// backp is still needed, m_containingClassp is just a cache
// abovep is still needed, m_containingClassp is just a cache
if (const AstClass* const classp = VN_CAST(nodep, Class))
return m_containingClassp[nodep] = classp;
if (const AstClassPackage* const packagep = VN_CAST(nodep, ClassPackage)) {
@ -6663,8 +6663,8 @@ class WidthVisitor final : public VNVisitor {
if (m_containingClassp.find(nodep) != m_containingClassp.end()) {
return m_containingClassp[nodep];
}
if (nodep->backp()) {
return m_containingClassp[nodep] = containingClass(nodep->backp());
if (AstNode* const abovep = nodep->aboveLoopp()) {
return m_containingClassp[nodep] = containingClass(abovep);
} else {
return m_containingClassp[nodep] = nullptr;
}

View File

@ -0,0 +1,16 @@
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2025 by Wilson Snyder. 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-License-Identifier: LGPL-3.0-only OR Artistic-2.0
import vltest_bootstrap
test.scenarios('simulator')
test.lint()
test.passes()

View File

@ -0,0 +1,27 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2026 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
module t;
class Cls;
// verilator lint_off COVERIGN
covergroup cov_trans;
option.per_instance = 1;
endgroup
virtual function void perform_transfer_checks();
check_transfer_size();
endfunction
virtual function void check_transfer_size();
endfunction
endclass
initial begin
Cls c;
c = new;
c.perform_transfer_checks();
$finish;
end
endmodule