forked from github/verilator
Report error on typedef referencing self (#2539).
This commit is contained in:
parent
778f133118
commit
152689776d
2
Changes
2
Changes
@ -12,6 +12,8 @@ The contributors that suggested a given feature are shown in []. Thanks!
|
||||
|
||||
*** Support static methods and typedefs in classes (#2615). [Krzysztof Bieganski]
|
||||
|
||||
**** Report error on typedef referencing self (#2539). [Cody Piersall]
|
||||
|
||||
**** Fix iteration over mutating list bug in VPI (#2588). [Kaleb Barrett]
|
||||
|
||||
**** Fix return from callValueCbs (#2589) (#2605). [Marlon James]
|
||||
|
@ -1605,6 +1605,17 @@ private:
|
||||
}
|
||||
virtual void visit(AstTypedef* nodep) override {
|
||||
if (nodep->didWidthAndSet()) return; // This node is a dtype & not both PRELIMed+FINALed
|
||||
if (auto* refp = checkRefToTypedefRecurse(nodep, nodep)) {
|
||||
nodep->v3error("Typedef has self-reference: " << nodep->prettyNameQ() << endl
|
||||
<< nodep->warnContextPrimary() << endl
|
||||
<< refp->warnOther()
|
||||
<< "... Location of reference" << endl
|
||||
<< refp->warnContextSecondary());
|
||||
// May cause internel error but avoids infinite loop on dump
|
||||
refp->typedefp(nullptr);
|
||||
VL_DO_DANGLING(pushDeletep(nodep->unlinkFrBack()), nodep);
|
||||
return;
|
||||
}
|
||||
nodep->dtypep(iterateEditMoveDTypep(nodep, nodep->subDTypep()));
|
||||
userIterateChildren(nodep, nullptr);
|
||||
}
|
||||
@ -5808,6 +5819,20 @@ private:
|
||||
}
|
||||
return nodep; // By default return this
|
||||
}
|
||||
AstRefDType* checkRefToTypedefRecurse(AstNode* nodep, AstTypedef* typedefp) {
|
||||
// Recurse all children looking for self reference
|
||||
// This avoids iterateEditMoveDTypep going into a hard to resolve loop
|
||||
// Only call once for any given typedef, or will become O(n^2)
|
||||
if (VL_LIKELY(!nodep)) return nullptr;
|
||||
if (auto* refp = VN_CAST(nodep, RefDType)) {
|
||||
if (refp->typedefp() == typedefp) return refp;
|
||||
}
|
||||
if (auto* refp = checkRefToTypedefRecurse(nodep->op1p(), typedefp)) return refp;
|
||||
if (auto* refp = checkRefToTypedefRecurse(nodep->op2p(), typedefp)) return refp;
|
||||
if (auto* refp = checkRefToTypedefRecurse(nodep->op3p(), typedefp)) return refp;
|
||||
if (auto* refp = checkRefToTypedefRecurse(nodep->op4p(), typedefp)) return refp;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// METHODS - special iterators
|
||||
|
8
test_regress/t/t_enum_bad_circdecl.out
Normal file
8
test_regress/t/t_enum_bad_circdecl.out
Normal file
@ -0,0 +1,8 @@
|
||||
%Error: t/t_enum_bad_circdecl.v:11:6: Typedef has self-reference: 'bad_redecl'
|
||||
: ... In instance t
|
||||
11 | } bad_redecl;
|
||||
| ^~~~~~~~~~
|
||||
t/t_enum_bad_circdecl.v:9:17: ... Location of reference
|
||||
9 | typedef enum bad_redecl [2:0] {
|
||||
| ^~~~~~~~~~
|
||||
%Error: Exiting due to
|
20
test_regress/t/t_enum_bad_circdecl.pl
Executable file
20
test_regress/t/t_enum_bad_circdecl.pl
Executable file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env perl
|
||||
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
|
||||
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
|
||||
#
|
||||
# Copyright 2003 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(
|
||||
verilator_flags2 => ["--lint-only -Wwarn-VARHIDDEN"],
|
||||
fails => 1,
|
||||
expect_filename => $Self->{golden_filename},
|
||||
);
|
||||
|
||||
ok(1);
|
||||
1;
|
13
test_regress/t/t_enum_bad_circdecl.v
Normal file
13
test_regress/t/t_enum_bad_circdecl.v
Normal file
@ -0,0 +1,13 @@
|
||||
// DESCRIPTION: Verilator: Verilog Test module
|
||||
//
|
||||
// This file ONLY is placed under the Creative Commons Public Domain, for
|
||||
// any use, without warranty, 2020 by Wilson Snyder.
|
||||
// SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
module t();
|
||||
|
||||
typedef enum bad_redecl [2:0] {
|
||||
VALUE
|
||||
} bad_redecl;
|
||||
|
||||
endmodule
|
Loading…
Reference in New Issue
Block a user