From a4db488b0237bc011bbb67b03ec3cf9b300d2d62 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 20 Sep 2025 17:40:50 -0400 Subject: [PATCH] Internals: Fix some object-less asserts --- src/V3CUse.cpp | 2 +- src/V3Case.cpp | 2 +- src/V3Const.cpp | 8 +++++--- src/V3Fork.cpp | 4 ++-- src/V3LinkInc.cpp | 2 +- src/V3Param.cpp | 2 +- src/V3PreProc.cpp | 6 +++--- src/V3Timing.cpp | 4 ++-- 8 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/V3CUse.cpp b/src/V3CUse.cpp index 19687d603..8cdb3b785 100644 --- a/src/V3CUse.cpp +++ b/src/V3CUse.cpp @@ -61,7 +61,7 @@ class CUseVisitor final : public VNVisitorConst { } void visit(AstCCall* nodep) override { return; } void visit(AstCReturn* nodep) override { - UASSERT(!nodep->user1SetOnce(), "Visited same return twice."); + UASSERT_OBJ(!nodep->user1SetOnce(), nodep, "Visited same return twice"); iterateConst(nodep->lhsp()->dtypep()); } void visit(AstNodeDType* nodep) override { diff --git a/src/V3Case.cpp b/src/V3Case.cpp index 154f81da6..b57e51e9f 100644 --- a/src/V3Case.cpp +++ b/src/V3Case.cpp @@ -308,7 +308,7 @@ class CaseVisitor final : public VNVisitor { for (uint32_t i = 0; i < numCases; ++i) { if (AstNode* const condp = m_valueItem[i]) { const AstCaseItem* const caseItemp = caseItemMap[condp]; - UASSERT(caseItemp, "caseItemp should exist"); + UASSERT_OBJ(caseItemp, condp, "caseItemp should exist"); m_valueItem[i] = caseItemp->stmtsp(); } } diff --git a/src/V3Const.cpp b/src/V3Const.cpp index b4b0e1308..9c22ac4a9 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -574,7 +574,7 @@ class ConstBitOpTreeVisitor final : public VNVisitorConst { // Reach past a cast then add to frozen nodes to be added to final reduction if (const AstCCast* const castp = VN_CAST(opp, CCast)) opp = castp->lhsp(); const bool pol = isXorTree() || m_polarity; // Only AND/OR tree needs polarity - UASSERT(pol, "AND/OR tree expects m_polarity==true"); + UASSERT_OBJ(pol, nodep, "AND/OR tree expects m_polarity==true"); m_frozenNodes.emplace_back(opp, FrozenNodeInfo{pol, m_lsb}); m_failed = origFailed; continue; @@ -2274,7 +2274,8 @@ class ConstVisitor final : public VNVisitor { if (VN_IS(dstDTypep, UnpackArrayDType)) { streamp = new AstCvtPackedToArray{nodep->fileline(), streamp, dstDTypep}; } else { - UASSERT(sWidth >= dWidth, "sWidth >= dWidth should have caused an error earlier"); + UASSERT_OBJ(sWidth >= dWidth, nodep, + "sWidth >= dWidth should have caused an error earlier"); if (dWidth == 0) { streamp = new AstCvtPackedToArray{nodep->fileline(), streamp, dstDTypep}; } else if (sWidth >= dWidth) { @@ -2307,7 +2308,8 @@ class ConstVisitor final : public VNVisitor { } srcp = new AstCvtPackedToArray{nodep->fileline(), srcp, dstDTypep}; } else { - UASSERT(sWidth >= dWidth, "sWidth >= dWidth should have caused an error earlier"); + UASSERT_OBJ(sWidth >= dWidth, nodep, + "sWidth >= dWidth should have caused an error earlier"); if (dWidth == 0) { srcp = new AstCvtPackedToArray{nodep->fileline(), srcp, dstDTypep}; } else if (sWidth >= dWidth) { diff --git a/src/V3Fork.cpp b/src/V3Fork.cpp index 9cf4da556..d5d346474 100644 --- a/src/V3Fork.cpp +++ b/src/V3Fork.cpp @@ -575,7 +575,7 @@ class ForkVisitor final : public VNVisitor { if (!m_newProcess || nodep->user1()) { VL_RESTORER(m_forkDepth); if (nodep->user1()) { - UASSERT(m_forkDepth > 0, "Wrong fork depth!"); + UASSERT_OBJ(m_forkDepth > 0, nodep, "Wrong fork depth"); --m_forkDepth; } iterateChildren(nodep); @@ -601,7 +601,7 @@ class ForkVisitor final : public VNVisitor { AstTask* taskp = nullptr; if (AstBegin* const beginp = VN_CAST(nodep, Begin)) { - UASSERT(beginp->stmtsp(), "No stmtsp\n"); + UASSERT_OBJ(beginp->stmtsp(), beginp, "No stmtsp"); const string taskName = generateTaskName(beginp, "fork_begin"); taskp = makeTask(beginp->fileline(), beginp->stmtsp()->unlinkFrBackWithNext(), taskName); diff --git a/src/V3LinkInc.cpp b/src/V3LinkInc.cpp index a8809a6d7..c45d93af0 100644 --- a/src/V3LinkInc.cpp +++ b/src/V3LinkInc.cpp @@ -69,7 +69,7 @@ class LinkIncVisitor final : public VNVisitor { } else if (m_modp) { stmtsp = m_modp->stmtsp(); } - UASSERT(stmtsp, "Variable not under FTASK/MODULE"); + UASSERT_OBJ(stmtsp, newp, "Variable not under FTASK/MODULE"); newp->addNext(stmtsp->unlinkFrBackWithNext()); if (m_ftaskp) { m_ftaskp->addStmtsp(newp); diff --git a/src/V3Param.cpp b/src/V3Param.cpp index 0e9bc4457..4a80b99f9 100644 --- a/src/V3Param.cpp +++ b/src/V3Param.cpp @@ -136,7 +136,7 @@ public: } AstNodeModule* findByParams(const string& origName, AstPin* firstPinp, const AstNodeModule* modp) { - UASSERT(isHierBlock(origName), origName << " is not hierarchical block\n"); + UASSERT(isHierBlock(origName), origName << " is not hierarchical block"); // This module is a hierarchical block. Need to replace it by the --lib-create wrapper. const std::pair candidates = m_hierBlockOptsByOrigName.equal_range(origName); diff --git a/src/V3PreProc.cpp b/src/V3PreProc.cpp index b0a8f2000..671a542c3 100644 --- a/src/V3PreProc.cpp +++ b/src/V3PreProc.cpp @@ -1154,7 +1154,7 @@ int V3PreProcImp::getStateToken() { m_lexp->pushStateDefForm(); goto next_tok; } else { // LCOV_EXCL_LINE - v3fatalSrc("Bad case\n"); + v3fatalSrc("Bad case"); } goto next_tok; } else if (tok == VP_TEXT) { @@ -1521,7 +1521,7 @@ int V3PreProcImp::getStateToken() { goto next_tok; } } - default: v3fatalSrc("Bad case\n"); + default: v3fatalSrc("Bad case"); } // Default is to do top level expansion of some tokens switch (tok) { @@ -1637,7 +1637,7 @@ int V3PreProcImp::getStateToken() { goto next_tok; } } - v3fatalSrc("Bad case\n"); // FALLTHRU + v3fatalSrc("Bad case"); // FALLTHRU goto next_tok; // above fatal means unreachable, but fixes static analysis warning } case VP_ERROR: { diff --git a/src/V3Timing.cpp b/src/V3Timing.cpp index 78e827077..05a9b5914 100644 --- a/src/V3Timing.cpp +++ b/src/V3Timing.cpp @@ -253,7 +253,7 @@ class TimingSuspendableVisitor final : public VNVisitor { // VISITORS void visit(AstClass* nodep) override { - UASSERT(!m_classp, "Class under class"); + UASSERT_OBJ(!m_classp, nodep, "Class under class"); VL_RESTORER(m_classp); m_classp = nodep; iterateChildren(nodep); @@ -752,7 +752,7 @@ class TimingControlVisitor final : public VNVisitor { // VISITORS void visit(AstNodeModule* nodep) override { - UASSERT(!m_classp, "Module or class under class"); + UASSERT_OBJ(!m_classp, nodep, "Module or class under class"); VL_RESTORER(m_classp); m_classp = VN_CAST(nodep, Class); VL_RESTORER(m_forkCnt);