From d896f1ff081af7653086e9806d90842441a441c1 Mon Sep 17 00:00:00 2001 From: Krzysztof Bieganski Date: Wed, 28 Aug 2024 17:29:12 +0200 Subject: [PATCH] Fix queue `[$-i]` select as reference argument (#5411) Signed-off-by: Krzysztof Bieganski --- src/V3Task.cpp | 2 +- src/V3Width.cpp | 5 +++-- test_regress/t/t_queue_back.v | 7 ++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/V3Task.cpp b/src/V3Task.cpp index ae8a6373b..a743b33b5 100644 --- a/src/V3Task.cpp +++ b/src/V3Task.cpp @@ -493,7 +493,7 @@ class TaskVisitor final : public VNVisitor { || VN_IS(pinp, ArraySel)) { refArgOk = true; } else if (const AstCMethodHard* const cMethodp = VN_CAST(pinp, CMethodHard)) { - refArgOk = cMethodp->name() == "at"; + refArgOk = cMethodp->name() == "at" || cMethodp->name() == "atBack"; } if (refArgOk) { if (AstVarRef* const varrefp = VN_CAST(pinp, VarRef)) { diff --git a/src/V3Width.cpp b/src/V3Width.cpp index a2b7b398d..3d5ec00a1 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -3677,10 +3677,11 @@ class WidthVisitor final : public VNVisitor { } void methodCallQueue(AstMethodCall* nodep, AstQueueDType* adtypep) { AstCMethodHard* newp = nullptr; - if (nodep->name() == "at") { // Created internally for [] + if (nodep->name() == "at" || nodep->name() == "atBack") { // Created internally for [] methodOkArguments(nodep, 1, 1); methodCallLValueRecurse(nodep, nodep->fromp(), VAccess::WRITE); - newp = new AstCMethodHard{nodep->fileline(), nodep->fromp()->unlinkFrBack(), "at"}; + newp = new AstCMethodHard{nodep->fileline(), nodep->fromp()->unlinkFrBack(), + nodep->name()}; newp->dtypeFrom(adtypep->subDTypep()); } else if (nodep->name() == "num" // function int num() || nodep->name() == "size") { diff --git a/test_regress/t/t_queue_back.v b/test_regress/t/t_queue_back.v index 1d8d2bb90..1c33b73ec 100644 --- a/test_regress/t/t_queue_back.v +++ b/test_regress/t/t_queue_back.v @@ -9,8 +9,13 @@ module t(/*AUTOARG*/); int q[$]; int r; + function void set_val(ref int lhs, input int rhs); + lhs = rhs; + endfunction + initial begin - q = { 20, 30, 40 }; + q = { 20, 50, 40 }; + set_val(q[$-1], 30); r = q[$]; if (r != 40) $stop;