Fix segfault in missing extends (#6903).

Fixes #6903.
This commit is contained in:
Wilson Snyder 2026-01-16 19:57:23 -05:00
parent b87675c0ea
commit 913cf933e9
3 changed files with 30 additions and 22 deletions

View File

@ -4983,7 +4983,10 @@ class LinkDotResolveVisitor final : public VNVisitor {
cprp = dotp->rhsp(); cprp = dotp->rhsp();
VSymEnt* const foundp = m_statep->resolveClassOrPackage( VSymEnt* const foundp = m_statep->resolveClassOrPackage(
lookSymp, lookNodep, true, false, nodep->verilogKwd()); lookSymp, lookNodep, true, false, nodep->verilogKwd());
if (!foundp) return; if (!foundp) {
VL_DO_DANGLING(pushDeletep(nodep->unlinkFrBack()), nodep);
return;
}
UASSERT_OBJ(lookNodep->classOrPackageSkipp(), nodep, "Bad package link"); UASSERT_OBJ(lookNodep->classOrPackageSkipp(), nodep, "Bad package link");
lookSymp = m_statep->getNodeSym(lookNodep->classOrPackageSkipp()); lookSymp = m_statep->getNodeSym(lookNodep->classOrPackageSkipp());
} else { } else {
@ -4995,11 +4998,15 @@ class LinkDotResolveVisitor final : public VNVisitor {
if (VL_UNCOVERABLE(!cpackagerefp)) { if (VL_UNCOVERABLE(!cpackagerefp)) {
// Linking the extend gives an error before this is hit // Linking the extend gives an error before this is hit
nodep->v3error("Attempting to extend using non-class"); // LCOV_EXCL_LINE nodep->v3error("Attempting to extend using non-class"); // LCOV_EXCL_LINE
VL_DO_DANGLING(pushDeletep(nodep->unlinkFrBack()), nodep);
return; return;
} }
VSymEnt* const foundp = m_statep->resolveClassOrPackage(lookSymp, cpackagerefp, true, VSymEnt* const foundp = m_statep->resolveClassOrPackage(lookSymp, cpackagerefp, true,
true, nodep->verilogKwd()); true, nodep->verilogKwd());
if (foundp) { if (!foundp) {
VL_DO_DANGLING(pushDeletep(nodep->unlinkFrBack()), nodep);
return;
}
if (AstClass* const classp = VN_CAST(foundp->nodep(), Class)) { if (AstClass* const classp = VN_CAST(foundp->nodep(), Class)) {
AstPin* paramsp = cpackagerefp->paramsp(); AstPin* paramsp = cpackagerefp->paramsp();
if (paramsp) { if (paramsp) {
@ -5011,20 +5018,15 @@ class LinkDotResolveVisitor final : public VNVisitor {
iterate(nodep->childDTypep()); iterate(nodep->childDTypep());
} else if (AstParamTypeDType* const paramp } else if (AstParamTypeDType* const paramp
= VN_CAST(foundp->nodep(), ParamTypeDType)) { = VN_CAST(foundp->nodep(), ParamTypeDType)) {
AstRefDType* const refParamp AstRefDType* const refParamp = new AstRefDType{nodep->fileline(), paramp->name()};
= new AstRefDType{nodep->fileline(), paramp->name()};
refParamp->refDTypep(paramp); refParamp->refDTypep(paramp);
nodep->childDTypep(refParamp); nodep->childDTypep(refParamp);
nodep->parameterized(true); nodep->parameterized(true);
} else { } else {
nodep->v3warn(E_UNSUPPORTED, nodep->v3warn(E_UNSUPPORTED, "Unsupported: " << foundp->nodep()->prettyTypeName()
"Unsupported: " << foundp->nodep()->prettyTypeName()
<< " in 'class extends'"); << " in 'class extends'");
return; return;
} }
} else {
return;
}
if (!nodep->childDTypep()) nodep->v3error("Attempting to extend using non-class"); if (!nodep->childDTypep()) nodep->v3error("Attempting to extend using non-class");
nodep->classOrPkgsp()->unlinkFrBack()->deleteTree(); nodep->classOrPkgsp()->unlinkFrBack()->deleteTree();
} else { } else {

View File

@ -7,4 +7,7 @@
: ... Suggested alternative: 'otFound2' : ... Suggested alternative: 'otFound2'
18 | class Cls2 extends Pkg::NotFound2; 18 | class Cls2 extends Pkg::NotFound2;
| ^~~~~~~~~ | ^~~~~~~~~
%Error: t/t_class_extends_nf_bad.v:20:10: 'super' used on non-extended class (IEEE 1800-2023 8.15)
20 | super.new();
| ^
%Error: Exiting due to %Error: Exiting due to

View File

@ -16,6 +16,9 @@ class Cls extends IsNotFound; // BAD: not found
endclass endclass
class Cls2 extends Pkg::NotFound2; // BAD: not found class Cls2 extends Pkg::NotFound2; // BAD: not found
function new;
super.new();
endfunction
endclass endclass
module t; module t;