From c83ee391bb3fac36ba97db1b266741eb666aceb9 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 7 Sep 2024 15:25:35 -0400 Subject: [PATCH] Fix associative array next/prev/first/last mis-propagating constants (#5435). --- Changes | 1 + src/V3Ast.h | 2 +- src/V3Width.cpp | 1 + test_regress/t/t_assoc.v | 23 +++++++++++++++++++++++ test_regress/t/t_assoc_method_bad.out | 9 +++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index b0e88f90e..c8472df19 100644 --- a/Changes +++ b/Changes @@ -33,6 +33,7 @@ Verilator 5.029 devel * Fix sformatf internal error on initial automatics (#5423). [Todd Strader] * Fix clearing trigger of events with no sensitivity trees (#5426). [Arkadiusz Kozdra, Antmicro Ltd.] * Fix driving clocking block in reactive region (#5430). [Krzysztof Bieganski, Antmicro Ltd.] +* Fix associative array next/prev/first/last mis-propagating constants (#5435). [Ethan Sifferman] Verilator 5.028 2024-08-21 diff --git a/src/V3Ast.h b/src/V3Ast.h index a6637fc60..b8ec59dac 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -215,7 +215,7 @@ public: return names[m_e]; } const char* arrow() const { - static const char* const names[] = {"[RV] <-", "[LV] =>", "[LV] <=>", "--"}; + static const char* const names[] = {"[RV] <-", "[LV] =>", "[LRV] <=>", "--"}; return names[m_e]; } VAccess() diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 400daad64..69a5ace16 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -3432,6 +3432,7 @@ class WidthVisitor final : public VNVisitor { || nodep->name() == "prev") { methodOkArguments(nodep, 1, 1); AstNodeExpr* const index_exprp = methodCallAssocIndexExpr(nodep, adtypep); + methodCallLValueRecurse(nodep, index_exprp, VAccess::READWRITE); newp = new AstCMethodHard{nodep->fileline(), nodep->fromp()->unlinkFrBack(), nodep->name(), // first/last/next/prev index_exprp->unlinkFrBack()}; diff --git a/test_regress/t/t_assoc.v b/test_regress/t/t_assoc.v index f3e89620e..f6939b6c3 100644 --- a/test_regress/t/t_assoc.v +++ b/test_regress/t/t_assoc.v @@ -121,6 +121,29 @@ module t (/*AUTOARG*/ `checkh(sum, 1 + 2); end + begin // Issue #5435 + int a; + int ok; + int dict [int]; + + dict[3] = 'h13; + dict[4] = 'h14; + dict[5] = 'h15; + + a = 4; + ok = dict.first(a); + if (a != 3) $stop; + if (ok != 1) $stop; + a = 4; + ok = dict.next(a); + if (a != 5) $stop; + if (ok != 1) $stop; + a = 4; + ok = dict.last(a); + if (a != 5) $stop; + if (ok != 1) $stop; + end + $write("*-* All Finished *-*\n"); $finish; end diff --git a/test_regress/t/t_assoc_method_bad.out b/test_regress/t/t_assoc_method_bad.out index 794685136..52cb6da31 100644 --- a/test_regress/t/t_assoc_method_bad.out +++ b/test_regress/t/t_assoc_method_bad.out @@ -18,6 +18,11 @@ : ... note: In instance 't' 18 | v = a.first(); | ^~~~~ +%Error-UNSUPPORTED: t/t_assoc_method_bad.v:18:13: Unsupported: Non-variable on LHS of built-in method 'first' + : ... note: In instance 't' + 18 | v = a.first(); + | ^~~~~ + ... For error description see https://verilator.org/warn/UNSUPPORTED?v=latest %Error: t/t_assoc_method_bad.v:19:13: The 2 arguments passed to .next method does not match its requiring 1 arguments : ... note: In instance 't' 19 | v = a.next(k, "bad2"); @@ -26,6 +31,10 @@ : ... note: In instance 't' 20 | v = a.last(); | ^~~~ +%Error-UNSUPPORTED: t/t_assoc_method_bad.v:20:13: Unsupported: Non-variable on LHS of built-in method 'last' + : ... note: In instance 't' + 20 | v = a.last(); + | ^~~~ %Error: t/t_assoc_method_bad.v:21:13: The 2 arguments passed to .prev method does not match its requiring 1 arguments : ... note: In instance 't' 21 | v = a.prev(k, "bad2");