Fix crash on self-referential enum type. (#2319)

This commit is contained in:
Stephen Henry 2020-05-11 23:44:28 +01:00 committed by GitHub
parent 29695adf70
commit 484b574cef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 0 deletions

View File

@ -41,6 +41,7 @@ Richard Myers
Sean Cross
Sebastien Van Cauwenberghe
Stefan Wallentowitz
Stephen Henry
Tim Snyder
Tobias Rosenkranz
Tobias Wölfel

View File

@ -2369,6 +2369,12 @@ private:
}
}
}
virtual void visit(AstEnumDType* nodep) VL_OVERRIDE {
iterateChildren(nodep);
AstRefDType* refdtype = VN_CAST(nodep->childDTypep(), RefDType);
if (refdtype && (nodep == refdtype->refDTypep()))
refdtype->v3error("Self-referential enumerated type definition");
}
virtual void visit(AstEnumItemRef* nodep) VL_OVERRIDE {
// EnumItemRef may be under a dot. Should already be resolved.
iterateChildren(nodep);

View File

@ -0,0 +1,4 @@
%Error: t/t_enum_recurse_bad2.v:7:14: Self-referential enumerated type definition
7 | typedef enum foo_t { A = 'b0, B = 'b1 } foo_t;
| ^~~~~
%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 2004 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(simulator => 1);
compile(
fails => 1,
expect_filename => $Self->{golden_filename},
);
ok(1);
1;

View File

@ -0,0 +1,7 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2019 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
typedef enum foo_t { A = 'b0, B = 'b1 } foo_t;