From b408e097f6bae380c415934de81d0472508b5276 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 24 Jul 2025 22:55:26 -0400 Subject: [PATCH] Fix unsigned replicate (#6229) --- Changes | 2 +- src/V3Width.cpp | 3 ++- test_regress/t/t_math_repl3_bad.v | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 01df78779..b857da768 100644 --- a/Changes +++ b/Changes @@ -29,7 +29,7 @@ Verilator 5.039 devel * Optimize more complex combinational assignments in DFG (#6205) (#6209). [Geza Lore] * Optimize combinational cycles through arrays in DFG (#6210). [Geza Lore] * Fix constructor parameters in inheritance hierarchies (#6036) (#6070). [Petr Nohavica] -* Fix replicate of negative giving 'REPLICATE has no expected width' internal error (#6048). +* Fix replicate of negative giving 'REPLICATE has no expected width' internal error (#6048) (#6229). * Fix cmake `-Wno` compiler flag testing (#6145). [Martin Stadler] * Fix class extends dotted error (#6162). [Igor Zaworski, Antmicro Ltd.] * Fix genvar error with `-O0` (#6165). [Max Wipfli] diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 973ab54aa..83ef4b38e 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -802,7 +802,8 @@ class WidthVisitor final : public VNVisitor { const AstConst* const constp = VN_CAST(nodep->countp(), Const); if (constp) { - if (constp->num().isFourState() || constp->num().isNegative()) { + if (constp->num().isFourState() + || (constp->dtypep()->isSigned() && constp->num().isNegative())) { nodep->v3error("Replication value of < 0 or X/Z not legal" " (IEEE 1800-2023 11.4.12.1): " << constp->prettyNameQ()); diff --git a/test_regress/t/t_math_repl3_bad.v b/test_regress/t/t_math_repl3_bad.v index b3f86c0ab..b0e33eaca 100644 --- a/test_regress/t/t_math_repl3_bad.v +++ b/test_regress/t/t_math_repl3_bad.v @@ -15,4 +15,7 @@ module t #( end other = {32'bz{1'b1}}; end + + wire ok1 = 1'b1; + wire [6:0] ok7 = {3'b111{ok1}}; // Ok endmodule