From 50b6954cfc68e3caf3fda91d414b892378988ab0 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 17 Jan 2026 23:18:09 -0500 Subject: [PATCH] Internals: cppcheck cleanups --- include/verilated_random.cpp | 2 ++ include/verilated_vpi.cpp | 6 ++---- src/V3AssertPre.cpp | 2 +- src/V3AstNodes.cpp | 2 +- src/V3Control.cpp | 4 ++-- src/V3DfgPasses.cpp | 2 +- src/V3Force.cpp | 2 +- src/V3InlineCFuncs.cpp | 4 ++-- src/V3LibMap.cpp | 2 +- src/V3LinkCells.cpp | 12 ++++++------ src/V3LinkDot.cpp | 4 ++-- src/V3LinkDotIfaceCapture.cpp | 6 +++--- src/V3RandSequence.cpp | 19 ++++++++++--------- src/V3Randomize.cpp | 1 - src/V3Task.cpp | 1 + src/V3UndrivenCapture.cpp | 2 +- src/verilog.y | 1 + 17 files changed, 37 insertions(+), 35 deletions(-) diff --git a/include/verilated_random.cpp b/include/verilated_random.cpp index fdbdd38bb..bfee50acf 100644 --- a/include/verilated_random.cpp +++ b/include/verilated_random.cpp @@ -433,6 +433,7 @@ bool VlRandomizer::next(VlRNG& rngr) { } os << "(check-sat)\n"; sat = parseSolution(os, true); + (void)sat; os << "(reset)\n"; return false; } @@ -442,6 +443,7 @@ bool VlRandomizer::next(VlRNG& rngr) { os << ")\n"; os << "\n(check-sat)\n"; sat = parseSolution(os, false); + (void)sat; } os << "(reset)\n"; diff --git a/include/verilated_vpi.cpp b/include/verilated_vpi.cpp index a1a5b1bd5..c2ea3ee94 100644 --- a/include/verilated_vpi.cpp +++ b/include/verilated_vpi.cpp @@ -2739,7 +2739,6 @@ void vl_vpi_get_value(const VerilatedVpioVarBase* vop, p_vpi_value valuep) { || (vop->varp()->isForceable() && (!forceEnableSignalVop || !forceValueSignalVop)))) { // Check if getForceControlSignals provided any additional error info - t_vpi_error_info getForceControlSignalsError{}; const bool gotErrorMessage = vpi_chk_error(&getForceControlSignalsError); const std::string previousErrorMessage = gotErrorMessage @@ -2982,7 +2981,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value valuep, p_vpi_time /*time_ const VerilatedVpioVar* const forceEnableSignalVop = forceControlSignals.first.get(); const VerilatedVpioVar* const forceValueSignalVop = forceControlSignals.second.get(); t_vpi_error_info getForceControlSignalsError{}; - const bool errorOccurred = vpi_chk_error(&getForceControlSignalsError); + bool errorOccurred = vpi_chk_error(&getForceControlSignalsError); // LCOV_EXCL_START - Cannot test, since getForceControlSignals does not (currently) produce // any notices or warnings. if (errorOccurred && getForceControlSignalsError.level < vpiError) { @@ -2995,7 +2994,6 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value valuep, p_vpi_time /*time_ && (!forceEnableSignalVop || !forceValueSignalVop))) { // Check if getForceControlSignals provided any additional error info - t_vpi_error_info getForceControlSignalsError{}; const bool gotErrorMessage = vpi_chk_error(&getForceControlSignalsError); const std::string previousErrorMessage = gotErrorMessage @@ -3028,7 +3026,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value valuep, p_vpi_time /*time_ vl_vpi_get_value(baseSignalVop, valuep); t_vpi_error_info baseValueGetError{}; - const bool errorOccurred = vpi_chk_error(&baseValueGetError); + errorOccurred = vpi_chk_error(&baseValueGetError); // LCOV_EXCL_START - Cannot test, because missing signal would already trigger error // earlier, at the getForceControlSignals stage // NOLINTNEXTLINE(readability-simplify-boolean-expr); diff --git a/src/V3AssertPre.cpp b/src/V3AssertPre.cpp index f835e4f97..790c8bb9b 100644 --- a/src/V3AssertPre.cpp +++ b/src/V3AssertPre.cpp @@ -158,7 +158,7 @@ private: // It has to be converted to a list of ModportClockingVarRefs, // because clocking blocks are removed in this pass for (AstNode* itemp = nodep->clockingp()->itemsp(); itemp; itemp = itemp->nextp()) { - if (AstClockingItem* citemp = VN_CAST(itemp, ClockingItem)) { + if (const AstClockingItem* citemp = VN_CAST(itemp, ClockingItem)) { if (AstVar* const varp = citemp->varp() ? citemp->varp() : VN_AS(citemp->user1p(), Var)) { AstModportVarRef* const modVarp = new AstModportVarRef{ diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index 3bf9aadd7..01b7ec4fc 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -348,7 +348,7 @@ const char* AstExecGraph::broken() const { BROKEN_RTN(!m_depGraphp); for (const V3GraphVertex& vtx : m_depGraphp->vertices()) { const ExecMTask* const mtaskp = vtx.as(); - AstCFunc* const funcp = mtaskp->funcp(); + const AstCFunc* const funcp = mtaskp->funcp(); BROKEN_RTN(!funcp || !funcp->brokeExists()); } return nullptr; diff --git a/src/V3Control.cpp b/src/V3Control.cpp index 412076fef..38ad3f166 100644 --- a/src/V3Control.cpp +++ b/src/V3Control.cpp @@ -466,7 +466,7 @@ public: IgnIndices data; std::vector> points = {{10, 10}, {20, 20}, {40, 40}, {10, 30}, {20, 40}}; - for (auto& it : points) { + for (const auto& it : points) { controlIgnLines.emplace_back( V3ControlIgnoresLine{V3ErrorCode::I_LINT, it.first, it.second, true}); data.emplace_back(static_cast(controlIgnLines.size() - 1)); @@ -514,7 +514,7 @@ public: UASSERT_SELFTEST(int, nextChange, std::numeric_limits::max()); // points = {{0, 0}}; - for (auto& it : points) { + for (const auto& it : points) { controlIgnLines.emplace_back( V3ControlIgnoresLine{V3ErrorCode::I_LINT, it.first, it.second, true}); data.emplace_back(static_cast(controlIgnLines.size() - 1)); diff --git a/src/V3DfgPasses.cpp b/src/V3DfgPasses.cpp index cd62d069e..8ce12794f 100644 --- a/src/V3DfgPasses.cpp +++ b/src/V3DfgPasses.cpp @@ -178,7 +178,7 @@ void V3DfgPasses::binToOneHot(DfgGraph& dfg, V3DfgBinToOneHotContext& ctx) { if (selp->width() != 1) continue; DfgShiftL* const shiftLp = selp->fromp()->cast(); if (!shiftLp) continue; - DfgConst* const constp = shiftLp->lhsp()->cast(); + const DfgConst* const constp = shiftLp->lhsp()->cast(); if (!constp || !useOk(selp, false)) continue; if (!constp->hasValue(1)) continue; srcp = shiftLp->rhsp(); diff --git a/src/V3Force.cpp b/src/V3Force.cpp index e727ef2e5..38ece22a6 100644 --- a/src/V3Force.cpp +++ b/src/V3Force.cpp @@ -244,7 +244,7 @@ private: << ELEMENTS_MAX << " elements"); } bool complexElem = true; - if (AstBasicDType* const basicp = VN_CAST(dtp, BasicDType)) { + if (const AstBasicDType* const basicp = VN_CAST(dtp, BasicDType)) { complexElem = basicp->isOpaque(); } if (complexElem) { diff --git a/src/V3InlineCFuncs.cpp b/src/V3InlineCFuncs.cpp index 930e09740..85fa018ec 100644 --- a/src/V3InlineCFuncs.cpp +++ b/src/V3InlineCFuncs.cpp @@ -112,7 +112,7 @@ class InlineCFuncsVisitor final : public VNVisitor { } // Check if a function is eligible for inlining into caller - bool isInlineable(AstCFunc* callerp, AstCFunc* cfuncp) { + bool isInlineable(const AstCFunc* callerp, AstCFunc* cfuncp) { // Must be in the same scope (same class) to access the same members if (callerp->scopep() != cfuncp->scopep()) return false; @@ -246,7 +246,7 @@ class InlineCFuncsVisitor final : public VNVisitor { public: // CONSTRUCTORS - explicit InlineCFuncsVisitor(AstNetlist* nodep) + explicit InlineCFuncsVisitor(const AstNetlist* nodep) : m_threshold1{v3Global.opt.inlineCFuncs()} , m_threshold2{v3Global.opt.inlineCFuncsProduct()} { // Don't inline when profiling or tracing diff --git a/src/V3LibMap.cpp b/src/V3LibMap.cpp index 5a91cf7eb..094c79408 100644 --- a/src/V3LibMap.cpp +++ b/src/V3LibMap.cpp @@ -59,7 +59,7 @@ class LibMapVisitor final : public VNVisitor { public: // CONSTRUCTORS - LibMapVisitor(AstNetlist* nodep) { iterate(nodep); } + explicit LibMapVisitor(AstNetlist* nodep) { iterate(nodep); } }; //###################################################################### diff --git a/src/V3LinkCells.cpp b/src/V3LinkCells.cpp index 1d4c7f0e8..b87fd0930 100644 --- a/src/V3LinkCells.cpp +++ b/src/V3LinkCells.cpp @@ -416,24 +416,24 @@ class LinkCellsVisitor final : public VNVisitor { m_graph.rank(); for (V3GraphVertex& vtx : m_graph.vertices()) { if (const LinkCellsVertex* const vvertexp = vtx.cast()) { - AstNodeModule* const modp = vvertexp->modp(); - modp->level(vvertexp->rank()); + AstNodeModule* const vmodp = vvertexp->modp(); + vmodp->level(vvertexp->rank()); } } m_graph.rankMin(); for (V3GraphVertex& vtx : m_graph.vertices()) { if (const LinkCellsVertex* const vvertexp = vtx.cast()) { // +1 so we leave level 1 for the new wrapper we'll make in a moment - AstNodeModule* const modp = vvertexp->modp(); - modp->depth(vvertexp->rank() + 1); + AstNodeModule* const vmodp = vvertexp->modp(); + vmodp->depth(vvertexp->rank() + 1); } } if (v3Global.opt.topModule() != "" && !m_topVertexp) { VSpellCheck spell; for (V3GraphVertex& vtx : m_graph.vertices()) { if (const LinkCellsVertex* const vvertexp = vtx.cast()) { - AstNodeModule* const modp = vvertexp->modp(); - if (VN_IS(modp, Module)) spell.pushCandidate(modp->prettyName()); + AstNodeModule* const vmodp = vvertexp->modp(); + if (VN_IS(vmodp, Module)) spell.pushCandidate(vmodp->prettyName()); } } const string suggest diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index af2c88826..b9e014a52 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -758,9 +758,9 @@ public: if ((cellp && cellp->modp()->origName() == ident) || (inlinep && inlinep->origModName() == ident)) { break; - } else if (VSymEnt* const findSymp + } else if (VSymEnt* const findSym2p = findWithAltFallback(lookupSymp, ident, altIdent)) { - lookupSymp = findSymp; + lookupSymp = findSym2p; if (crossedCell && VN_IS(lookupSymp->nodep(), Var)) { UINFO(9, " Not found but matches var name in parent " << lookupSymp); diff --git a/src/V3LinkDotIfaceCapture.cpp b/src/V3LinkDotIfaceCapture.cpp index 8f719bee5..248165399 100644 --- a/src/V3LinkDotIfaceCapture.cpp +++ b/src/V3LinkDotIfaceCapture.cpp @@ -47,9 +47,9 @@ bool V3LinkDotIfaceCapture::finalizeCapturedEntry(CapturedMap::iterator it, cons string V3LinkDotIfaceCapture::extractIfacePortName(const string& dotText) { string name = dotText; const size_t dotPos = name.find('.'); - if (dotPos != string::npos) name = name.substr(0, dotPos); + if (dotPos != string::npos) name.resize(dotPos); const size_t braPos = name.find("__BRA__"); - if (braPos != string::npos) name = name.substr(0, braPos); + if (braPos != string::npos) name.resize(braPos); return name; } @@ -203,7 +203,7 @@ void V3LinkDotIfaceCapture::captureTypedefContext( AstVar* ifacePortVarp = nullptr; if (!dotText.empty() && curSymp) { const std::string portName = extractIfacePortName(dotText); - if (VSymEnt* const portSymp = curSymp->findIdFallback(portName)) { + if (const VSymEnt* const portSymp = curSymp->findIdFallback(portName)) { ifacePortVarp = VN_CAST(portSymp->nodep(), Var); UINFO(9, indentFn() << "iface capture found port var '" << portName << "' -> " << ifacePortVarp); diff --git a/src/V3RandSequence.cpp b/src/V3RandSequence.cpp index f25554183..bc940832b 100644 --- a/src/V3RandSequence.cpp +++ b/src/V3RandSequence.cpp @@ -91,7 +91,7 @@ class RandSequenceVisitor final : public VNVisitor { void findLocalizes(AstRandSequence* nodep) { std::set localVars; nodep->foreach([&](AstNode* const nodep) { - if (AstVarRef* const anodep = VN_CAST(nodep, VarRef)) { + if (const AstVarRef* const anodep = VN_CAST(nodep, VarRef)) { m_localizes.emplace(anodep->varp()); } else if (AstVar* const anodep = VN_CAST(nodep, Var)) { localVars.emplace(anodep); @@ -116,7 +116,7 @@ class RandSequenceVisitor final : public VNVisitor { new AstConst{fl, AstConst::BitFalse{}}}); // Also add arguments as next's - for (auto& itr : m_localizeNames) { + for (const auto& itr : m_localizeNames) { const AstVar* const lvarp = itr.second; AstVar* const iovarp = new AstVar{fl, VVarType::PORT, "__Vrsarg_" + lvarp->name(), lvarp}; @@ -154,7 +154,7 @@ class RandSequenceVisitor final : public VNVisitor { FileLine* const fl = nodep->fileline(); AstArg* const argsp = new AstArg{fl, breakVarp->name(), new AstVarRef{fl, breakVarp, VAccess::WRITE}}; - for (auto& itr : m_localizeNames) { + for (const auto& itr : m_localizeNames) { const AstVar* const lvarp = itr.second; AstVar* const iovarp = m_localizeRemaps[lvarp]; UASSERT_OBJ(iovarp, nodep, "No new port variable for local variable" << lvarp); @@ -188,7 +188,7 @@ class RandSequenceVisitor final : public VNVisitor { for (AstRSProdItem* proditemp = VN_AS(prodlistp->prodsp(), RSProdItem); proditemp; proditemp = VN_AS(proditemp->nextp(), RSProdItem)) { lists.push_back(proditemp); - AstRSProd* const subProdp = proditemp->prodp(); + const AstRSProd* const subProdp = proditemp->prodp(); if (!subProdp) continue; if (!subProdp->rulesp()) continue; if (!subProdp->rulesp()->prodlistsp()) continue; @@ -202,7 +202,8 @@ class RandSequenceVisitor final : public VNVisitor { UINFO(9, "RandJoin productions called:"); for (AstRSProdItem* proditemp : lists) { UINFO(9, " list " << proditemp); - for (AstNodeStmt* prodp : listStmts[proditemp]) UINFO(9, " calls " << prodp); + for (const AstNodeStmt* prodip : listStmts[proditemp]) + UINFO(9, " calls " << prodip); } // Need to clone all nodes used @@ -353,12 +354,12 @@ class RandSequenceVisitor final : public VNVisitor { // "case 2 / * N(a) * /: {statement}; break;" // "case 1 / * N(a) - 1 * /: {statement}; break;" uint32_t j = static_cast(listStmts[proditemp].size()); - for (AstNodeStmt* prodp : listStmts[proditemp]) { + for (AstNodeStmt* iprodp : listStmts[proditemp]) { jIfp->addThensp(new AstIf{ fl, new AstEq{fl, new AstConst{fl, AstConst::WidthedValue{}, 32, j}, new AstVarRef{fl, nleftVarps[i], VAccess::READ}}, - prodp->cloneTree(false)}); + iprodp->cloneTree(false)}); --j; } @@ -431,7 +432,7 @@ class RandSequenceVisitor final : public VNVisitor { UINFOTREE(9, nodep, "RS Tree pre-it", "-"); std::unordered_set prodHasRandJoin; for (AstRSProd* prodp = nodep->prodsp(); prodp; prodp = VN_AS(prodp->nextp(), RSProd)) { - prodp->foreach([&](AstRSProdList* const prodlistp) { + prodp->foreach([&](const AstRSProdList* const prodlistp) { if (prodlistp->randJoin()) prodHasRandJoin.emplace(prodp); }); } @@ -501,7 +502,7 @@ class RandSequenceVisitor final : public VNVisitor { iterateAndNextNull(itemsp); } else if (!nodep->rulesp()->nextp()) { // Single rule/list, can just do it // RSPROD(RSRULE(weight, stmt)) -> IF(weight != 0, stmt) - AstRSRule* const rulep = nodep->rulesp(); + const AstRSRule* const rulep = nodep->rulesp(); AstNode* itemsp = nullptr; if (rulep->weightStmtsp()) itemsp = rulep->weightStmtsp()->unlinkFrBackWithNext(); if (rulep->prodlistsp()) diff --git a/src/V3Randomize.cpp b/src/V3Randomize.cpp index ba0c7360c..33de114b0 100644 --- a/src/V3Randomize.cpp +++ b/src/V3Randomize.cpp @@ -148,7 +148,6 @@ class RandomizeMarkVisitor final : public VNVisitor { bool m_inStdWith = false; // True when inside a 'with {}' clause std::set m_staticRefs; // References to static variables under `with` clauses AstWith* m_withp = nullptr; // Current 'with' constraint node - std::unordered_set m_processedVars; // Track by variable instance, not class // METHODS // Mark all rand variables in IS_RANDOMIZED_GLOBAL classes as globalConstrained diff --git a/src/V3Task.cpp b/src/V3Task.cpp index f8473cebc..dce865d76 100644 --- a/src/V3Task.cpp +++ b/src/V3Task.cpp @@ -372,6 +372,7 @@ struct TaskDpiUtils final { : dtypep->width() <= 16 ? 'S' : *dtypep->charIQWN(); const std::string& size = std::to_string(dtypep->width()); + // cppcheck-suppress strPlusChar return {"VL_SET_"s + sizeChar + "_" + vecType + "(" + size + ", ", true}; } }; diff --git a/src/V3UndrivenCapture.cpp b/src/V3UndrivenCapture.cpp index 4436ebd83..f9f554309 100644 --- a/src/V3UndrivenCapture.cpp +++ b/src/V3UndrivenCapture.cpp @@ -65,7 +65,7 @@ private: void visit(AstNodeFTaskRef* nodep) override { // Record the call edge if resolved if (m_curTaskp) { - if (AstNodeFTask* const calleep = nodep->taskp()) { + if (const AstNodeFTask* const calleep = nodep->taskp()) { UINFO(9, "undriven capture call edge " << CaptureUtil::taskNameQ( m_curTaskp) << " -> " << CaptureUtil::taskNameQ(calleep)); m_cap.noteCallEdge(m_curTaskp, calleep); diff --git a/src/verilog.y b/src/verilog.y index 9c53f884c..068086357 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -136,6 +136,7 @@ const VBasicDTypeKwd LOGIC_IMPLICIT = VBasicDTypeKwd::LOGIC_IMPLICIT; #define DEL(...) \ { \ + /* cppcheck-suppress constVariable */ \ AstNode* const nodeps[] = {__VA_ARGS__}; \ for (AstNode* const nodep : nodeps) \ if (nodep) nodep->deleteTree(); \