From 3c4131d45dc2be40e21494ca44664abd0ab14071 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 15 May 2022 09:53:48 -0400 Subject: [PATCH] Fix 'with' operator with type casting (#3387). --- Changes | 1 + src/V3LinkDot.cpp | 1 - src/V3Width.cpp | 4 ++-- test_regress/t/t_with.v | 5 +++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Changes b/Changes index c3958d189..85b3f62bb 100644 --- a/Changes +++ b/Changes @@ -15,6 +15,7 @@ Verilator 4.223 devel * Support compile time trace signal selection with tracing_on/off (#3323). [Shunyao CAD] * Fix hang with large case statement optimization (#3405). [Mike Urbach] +* Fix 'with' operator with type casting (#3387). [xiak95] Verilator 4.222 2022-05-02 diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 535f57b40..22f4d97ca 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -1729,7 +1729,6 @@ class LinkDotScopeVisitor final : public VNVisitor { // Note we allow AstNodeStmt's as generates may be under them virtual void visit(AstCell*) override {} virtual void visit(AstVar*) override {} - virtual void visit(AstNodeMath*) override {} virtual void visit(AstNode* nodep) override { iterateChildren(nodep); } public: diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 17e302ccc..f5e16ec21 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -2725,7 +2725,7 @@ private: methodCallLValueRecurse(nodep, nodep->fromp(), VAccess::READ); newp = new AstCMethodHard(nodep->fileline(), nodep->fromp()->unlinkFrBack(), "r_" + nodep->name(), withp); - newp->dtypeFrom(adtypep->subDTypep()); + newp->dtypeFrom(withp ? withp->dtypep() : adtypep->subDTypep()); if (!nodep->firstAbovep()) newp->makeStatement(); } else if (nodep->name() == "min" || nodep->name() == "max" || nodep->name() == "unique" || nodep->name() == "unique_index") { @@ -2949,7 +2949,7 @@ private: methodCallLValueRecurse(nodep, nodep->fromp(), VAccess::READ); newp = new AstCMethodHard(nodep->fileline(), nodep->fromp()->unlinkFrBack(), "r_" + nodep->name(), withp); - newp->dtypeFrom(adtypep->subDTypep()); + newp->dtypeFrom(withp ? withp->dtypep() : adtypep->subDTypep()); if (!nodep->firstAbovep()) newp->makeStatement(); } else if (nodep->name() == "reverse" || nodep->name() == "shuffle" || nodep->name() == "sort" || nodep->name() == "rsort") { diff --git a/test_regress/t/t_with.v b/test_regress/t/t_with.v index 64684e46c..64f6485c5 100644 --- a/test_regress/t/t_with.v +++ b/test_regress/t/t_with.v @@ -16,6 +16,7 @@ module t (/*AUTOARG*/); int aliases[$]; int found[$]; int i; + byte byteq[$] = {2, -1, 127}; aliases = '{ 1, 4, 6, 8}; tofind = 6; @@ -35,8 +36,8 @@ module t (/*AUTOARG*/); // bug3387 i = aliases.sum(); `checkh(i, 'h13); - i = aliases.sum() with (2'(item)); - `checkh(i, 'h3); + i = byteq.sum() with (int'(item)); + `checkh(i, 128); // Unique (array method) tofind = 4;