Add error on missing pure virtual functions (#4961).

This commit is contained in:
Wilson Snyder 2024-03-11 18:56:30 -04:00
parent 49022c3e73
commit 4a439beae5
6 changed files with 62 additions and 8 deletions

View File

@ -20,6 +20,7 @@ Verilator 5.023 devel
**Minor:**
* Add DFG 'regularize' pass, and improve variable removal (#4937). [Geza Lore]
* Add error on missing pure virtual functions (#4961).
* Add error on calling static function without object (#4962).
* Support public packed struct / union (#860) (#4878). [Kefa Chen]
* Change installation to be relocatable (#4927). [Geza Lore]

View File

@ -2449,6 +2449,7 @@ void AstNodeFTask::dump(std::ostream& str) const {
if (dpiOpenChild()) str << " [DPIOPENCHILD]";
if (dpiOpenParent()) str << " [DPIOPENPARENT]";
if (prototype()) str << " [PROTOTYPE]";
if (pureVirtual()) str << " [PUREVIRTUAL]";
if (recursive()) str << " [RECURSIVE]";
if (taskPublic()) str << " [PUBLIC]";
if ((dpiImport() || dpiExport()) && cname() != name()) str << " [c=" << cname() << "]";

View File

@ -2214,20 +2214,25 @@ class LinkDotResolveVisitor final : public VNVisitor {
return classSymp;
}
void importImplementsClass(AstClass* implementsClassp, VSymEnt* interfaceSymp,
AstClass* interfaceClassp) {
UINFO(8, "importImplementsClass to " << implementsClassp << " from " << interfaceClassp
<< endl);
AstClass* baseClassp) {
// Also used for standard 'extends' from a base class
UINFO(8,
"importImplementsClass to " << implementsClassp << " from " << baseClassp << endl);
for (VSymEnt::const_iterator it = interfaceSymp->begin(); it != interfaceSymp->end();
++it) {
if (AstNode* interfaceSubp = it->second->nodep()) {
UINFO(8, " SymFunc " << interfaceSubp << endl);
if (VN_IS(interfaceSubp, NodeFTask)) {
const VSymEnt* const foundp = m_curSymp->findIdFlat(interfaceSubp->name());
const AstNodeFTask* const interfaceFuncp = VN_CAST(interfaceSubp, NodeFTask);
if (!interfaceFuncp || !interfaceFuncp->pureVirtual()) continue;
bool existsInChild = foundp && !foundp->imported();
const string impOrExtends
= baseClassp->isInterfaceClass() ? " implements " : " extends ";
if (!existsInChild && !implementsClassp->isInterfaceClass()) {
implementsClassp->v3error(
"Class " << implementsClassp->prettyNameQ() << " implements "
<< interfaceClassp->prettyNameQ()
"Class " << implementsClassp->prettyNameQ() << impOrExtends
<< baseClassp->prettyNameQ()
<< " but is missing implementation for "
<< interfaceSubp->prettyNameQ() << " (IEEE 1800-2023 8.26)\n"
<< implementsClassp->warnContextPrimary() << '\n'
@ -2239,8 +2244,8 @@ class LinkDotResolveVisitor final : public VNVisitor {
if (!existsInChild && it != m_ifClassImpNames.end()
&& it->second != interfaceSubp) { // Not exact same function from diamond
implementsClassp->v3error(
"Class " << implementsClassp->prettyNameQ() << " implements "
<< interfaceClassp->prettyNameQ()
"Class " << implementsClassp->prettyNameQ() << impOrExtends
<< baseClassp->prettyNameQ()
<< " but missing inheritance conflict resolution for "
<< interfaceSubp->prettyNameQ()
<< " (IEEE 1800-2023 8.26.6.2)\n"
@ -2257,7 +2262,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
void importSymbolsFromExtended(AstClass* const nodep, AstClassExtends* const cextp) {
AstClass* const baseClassp = cextp->classp();
VSymEnt* const srcp = m_statep->getNodeSym(baseClassp);
if (baseClassp->isInterfaceClass()) importImplementsClass(nodep, srcp, baseClassp);
importImplementsClass(nodep, srcp, baseClassp);
if (!cextp->isImplements()) m_curSymp->importFromClass(m_statep->symsp(), srcp);
}
void classExtendImport(AstClass* nodep) {

View File

@ -0,0 +1,7 @@
%Error: t/t_class_mispure_bad.v:11:1: Class 'Bar' extends 'Base' but is missing implementation for 'pvfunc' (IEEE 1800-2023 8.26)
11 | class Bar extends Base;
| ^~~~~
t/t_class_mispure_bad.v:8:31: ... Location of interface class's function
8 | pure virtual function void pvfunc();
| ^~~~~~
%Error: Exiting due to

View File

@ -0,0 +1,19 @@
#!/usr/bin/env perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2010 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
scenarios(linter => 1);
lint(
fails => 1,
expect_filename => $Self->{golden_filename},
);
ok(1);
1;

View File

@ -0,0 +1,21 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2024 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
virtual class Base;
pure virtual function void pvfunc();
endclass
class Bar extends Base;
// Bad, no implementation of pvfunc
endclass
module t;
initial begin
Bar obj = new();
obj.pvfunc();
$stop;
end
endmodule