Skip to content

Commit d400584

Browse files
authored
Fix concatenation and type casting (verilator#6012) (verilator#6013)
1 parent de08655 commit d400584

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

src/V3Width.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,6 +2112,7 @@ class WidthVisitor final : public VNVisitor {
21122112
VFlagChildDType{}, refp};
21132113
nodep->replaceWith(newp);
21142114
VL_DO_DANGLING(pushDeletep(nodep), nodep);
2115+
userIterate(newp, m_vup);
21152116
} else {
21162117
nodep->v3warn(E_UNSUPPORTED,
21172118
"Unsupported: Cast to " << nodep->dtp()->prettyTypeName());
@@ -2126,6 +2127,11 @@ class WidthVisitor final : public VNVisitor {
21262127
if (m_vup->prelim()) {
21272128
if (debug() >= 9) nodep->dumpTree("- CastPre: ");
21282129
// if (debug()) nodep->backp()->dumpTree("- CastPreUpUp: ");
2130+
if (AstSigned* const fromp = VN_CAST(nodep->fromp(), Signed)) {
2131+
AstNode* const lhsp = fromp->lhsp()->unlinkFrBack();
2132+
fromp->replaceWith(lhsp);
2133+
VL_DO_DANGLING(fromp->deleteTree(), fromp);
2134+
}
21292135
userIterateAndNext(nodep->fromp(), WidthVP{SELF, PRELIM}.p());
21302136
if (debug() >= 9) nodep->dumpTree("- CastDit: ");
21312137
AstNodeDType* const toDtp = nodep->dtypep()->skipRefToEnump();

test_regress/t/t_concat_casts.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python3
2+
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
3+
#
4+
# Copyright 2025 by Wilson Snyder. This program is free software; you
5+
# can redistribute it and/or modify it under the terms of either the GNU
6+
# Lesser General Public License Version 3 or the Perl Artistic License
7+
# Version 2.0.
8+
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
9+
10+
import vltest_bootstrap
11+
12+
test.scenarios("simulator")
13+
14+
test.compile()
15+
16+
test.execute()
17+
18+
test.passes()

test_regress/t/t_concat_casts.v

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// DESCRIPTION: Verilator: Verilog Test module
2+
//
3+
// This file ONLY is placed into the Public Domain, for any use,
4+
// without warranty, 2025 by Wilson Snyder.
5+
// SPDX-License-Identifier: CC0-1.0
6+
7+
package my_pkg;
8+
typedef enum logic [1:0] {
9+
SIG_0, SIG_1, SIG_2
10+
} sig_t;
11+
endpackage : my_pkg
12+
13+
14+
module t;
15+
import my_pkg::*;
16+
17+
typedef logic [7:0] foo_t;
18+
typedef logic [31:0] bar_t;
19+
20+
bar_t [1:0] the_bars;
21+
22+
foo_t [0:0][1:0] the_foos;
23+
24+
always_comb begin
25+
the_bars = {32'd7, 32'd8};
26+
the_foos[0] = {foo_t'(the_bars[1]), foo_t'(the_bars[0])};
27+
end
28+
29+
logic [6:0] data;
30+
logic [2:0] opt;
31+
32+
assign data = 7'b110_0101;
33+
assign opt = {data[5], sig_t'(data[1:0])};
34+
35+
initial begin
36+
if (the_foos != 'h0708) $stop();
37+
if (opt != 'b101) $stop();
38+
$write("*-* All Finished *-*\n");
39+
$finish;
40+
end
41+
endmodule

0 commit comments

Comments
 (0)