Skip to content

Commit b60117c

Browse files
authored
Fix typedefs pointing to parameterized classes (verilator#4747)
* Skip handling of ClassOrPackageRef nodes that point to Typedefs
1 parent d314273 commit b60117c

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

src/V3Param.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,12 @@ class ParamVisitor final : public VNVisitor {
11501150
if (nodep->ifacep()) visitCellOrClassRef(nodep, true);
11511151
}
11521152
void visit(AstClassRefDType* nodep) override { visitCellOrClassRef(nodep, false); }
1153-
void visit(AstClassOrPackageRef* nodep) override { visitCellOrClassRef(nodep, false); }
1153+
void visit(AstClassOrPackageRef* nodep) override {
1154+
// If it points to a typedef it is not really a class reference. That typedef will be
1155+
// visited anyway (from its parent node), so even if it points to a parameterized class
1156+
// type, the instance will be created.
1157+
if (!VN_IS(nodep->classOrPackageNodep(), Typedef)) visitCellOrClassRef(nodep, false);
1158+
}
11541159

11551160
// Make sure all parameters are constantified
11561161
void visit(AstVar* nodep) override {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env perl
2+
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
3+
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
4+
#
5+
# Copyright 2022 by Wilson Snyder. This program is free software; you
6+
# can redistribute it and/or modify it under the terms of either the GNU
7+
# Lesser General Public License Version 3 or the Perl Artistic License
8+
# Version 2.0.
9+
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
10+
11+
scenarios(simulator => 1);
12+
13+
compile(
14+
);
15+
16+
execute(
17+
check_finished => 1,
18+
);
19+
20+
ok(1);
21+
1;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// DESCRIPTION: Verilator: Verilog Test module
2+
//
3+
// This file ONLY is placed under the Creative Commons Public Domain, for
4+
// any use, without warranty, 2023 by Antmicro Ltd.
5+
// SPDX-License-Identifier: CC0-1.0
6+
7+
virtual class Virt;
8+
endclass
9+
10+
class MyInt;
11+
int x;
12+
endclass
13+
14+
class uvm_object_registry #(
15+
type T = Virt
16+
);
17+
static function T create_object();
18+
T obj = new();
19+
obj.x = 1;
20+
return obj;
21+
endfunction
22+
endclass
23+
24+
typedef uvm_object_registry#(MyInt) type_id;
25+
26+
module t;
27+
initial begin
28+
MyInt mi = type_id::create_object();
29+
if (mi.x != 1) $stop;
30+
31+
$write("*-* All Finished *-*\n");
32+
$finish;
33+
end
34+
endmodule

0 commit comments

Comments
 (0)