From d20a4db7738fe7f5c7e0b1df7231a45215f04ce8 Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Mon, 18 May 2020 18:46:00 +0100 Subject: [PATCH] Fix regression due to early constant folding in +: and -: (#2338) --- src/V3WidthSel.cpp | 1 + test_regress/t/t_select_plus.v | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/V3WidthSel.cpp b/src/V3WidthSel.cpp index c23f0c208..8e539443e 100644 --- a/src/V3WidthSel.cpp +++ b/src/V3WidthSel.cpp @@ -458,6 +458,7 @@ private: UINFO(6, "SELPLUS/MINUS " << nodep << endl); // Below 2 lines may change nodep->widthp() if (debug() >= 9) nodep->dumpTree(cout, "--SELPM0: "); + V3Width::widthParamsEdit(nodep->rhsp()); // constifyEdit doesn't ensure widths finished V3Const::constifyEdit(nodep->rhsp()); // May relink pointed to node, ok if not const V3Const::constifyParamsEdit(nodep->thsp()); // May relink pointed to node checkConstantOrReplace(nodep->thsp(), "Width of :+ or :- bit extract isn't a constant"); diff --git a/test_regress/t/t_select_plus.v b/test_regress/t/t_select_plus.v index 9d9e55879..247f166f8 100644 --- a/test_regress/t/t_select_plus.v +++ b/test_regress/t/t_select_plus.v @@ -74,4 +74,19 @@ module t (/*AUTOARG*/ endcase end + // Additional constant folding check - this used to trigger a bug + reg [23:0] a; + reg [3:0] b; + + initial begin + a = 24'd0; + b = 4'b0111; + a[3*(b[2:0]+0)+:3] = 3'd7; // Check LSB expression goes to 32-bits + if (a != 24'b11100000_00000000_00000000) $stop; + + a = 24'd0; + b = 4'b0110; + a[3*(b[2:0]+0)-:3] = 3'd7; // Check MSB expression goes to 32-bits + if (a != 24'b00000111_00000000_00000000) $stop; + end endmodule