From 425379eec7dbfb7f43106c5fb09a4354c2880eb1 Mon Sep 17 00:00:00 2001 From: Yilou Wang Date: Thu, 18 Jun 2026 13:50:26 +0200 Subject: [PATCH] Use AstClass::isClassExtendedFrom instead of local isSubclassOf helper --- src/V3Randomize.cpp | 8 +------- test_regress/t/t_randomize_prepost_with_baseref.v | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/V3Randomize.cpp b/src/V3Randomize.cpp index e9c7000b4..82d2cc29e 100644 --- a/src/V3Randomize.cpp +++ b/src/V3Randomize.cpp @@ -3770,12 +3770,6 @@ class RandomizeVisitor final : public VNVisitor { funcp->addStmtsp(callp->makeStmt()); } } - static bool isSubclassOf(AstClass* classp, const AstClass* const basep) { - for (AstClass* cp = classp; cp; cp = cp->extendsp() ? cp->extendsp()->classp() : nullptr) { - if (cp == basep) return true; - } - return false; - } // Per-class virtual wrapper that invokes the class's effective // pre_randomize/post_randomize. IEEE 1800-2023 18.6.2: pre_randomize and // post_randomize "appear to behave as virtual methods" because randomize() @@ -3804,7 +3798,7 @@ class RandomizeVisitor final : public VNVisitor { if (cachedIt != m_prePostWrap.end()) return cachedIt->second; std::vector hierp{classp}; v3Global.rootp()->foreach([&](AstClass* subp) { - if (subp != classp && isSubclassOf(subp, classp)) hierp.push_back(subp); + if (subp != classp && AstClass::isClassExtendedFrom(subp, classp)) hierp.push_back(subp); }); bool hasPre = false; bool hasPost = false; diff --git a/test_regress/t/t_randomize_prepost_with_baseref.v b/test_regress/t/t_randomize_prepost_with_baseref.v index 451957340..1bfe4ca64 100644 --- a/test_regress/t/t_randomize_prepost_with_baseref.v +++ b/test_regress/t/t_randomize_prepost_with_baseref.v @@ -72,7 +72,7 @@ module t; b = d; ok = b.randomize() with {a == 8'h3c;}; `checkd(ok, 1); - `checkd(d.a, 8'h3c); + `checkd(b.a, 8'h3c); `checkd(d.m_pre, 8'd10); `checkd(d.m_post, 8'h3d);