mirror of
https://github.com/verilator/verilator.git
synced 2025-01-01 04:07:34 +00:00
Add error on missing pure virtual functions (#4961).
This commit is contained in:
parent
49022c3e73
commit
4a439beae5
1
Changes
1
Changes
@ -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]
|
||||
|
@ -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() << "]";
|
||||
|
@ -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) {
|
||||
|
7
test_regress/t/t_class_mispure_bad.out
Normal file
7
test_regress/t/t_class_mispure_bad.out
Normal 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
|
19
test_regress/t/t_class_mispure_bad.pl
Executable file
19
test_regress/t/t_class_mispure_bad.pl
Executable 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;
|
21
test_regress/t/t_class_mispure_bad.v
Normal file
21
test_regress/t/t_class_mispure_bad.v
Normal 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
|
Loading…
Reference in New Issue
Block a user