From 5c0ad5bd1f64974c61d034ed8fb856d0cb5ef4d0 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 12 Nov 2025 18:54:22 -0500 Subject: [PATCH] Internals: cppcheck fixes. No functional change. (#6687) --- include/verilatedos_c.h | 1 + src/V3Assert.cpp | 7 +++---- src/V3AssertProp.cpp | 4 ++-- src/V3Ast.cpp | 4 ++-- src/V3AstNodeExpr.h | 4 ++-- src/V3AstNodeOther.h | 10 +++++----- src/V3AstNodeStmt.h | 6 +++--- src/V3Broken.cpp | 1 + src/V3Const.cpp | 36 +++++++++++++++++------------------ src/V3Control.cpp | 2 +- src/V3Dead.cpp | 2 +- src/V3DfgAstToDfg.cpp | 2 +- src/V3DfgOptimizer.cpp | 5 +++-- src/V3EmitCBase.cpp | 2 +- src/V3EmitCPch.cpp | 2 +- src/V3EmitCSyms.cpp | 8 ++++---- src/V3EmitMkJson.cpp | 6 +++--- src/V3ExecGraph.cpp | 14 +++++++------- src/V3Expand.cpp | 8 ++++---- src/V3File.cpp | 2 +- src/V3HierBlock.cpp | 6 ++---- src/V3Inline.cpp | 3 +-- src/V3Life.cpp | 2 +- src/V3Number.cpp | 2 ++ src/V3Options.cpp | 3 ++- src/V3OrderInternal.h | 2 +- src/V3OrderParallel.cpp | 2 +- src/V3Param.cpp | 12 ++++++------ src/V3ParseGrammar.h | 18 ++++++++++-------- src/V3SchedTrigger.cpp | 10 +++++----- src/V3SchedUtil.cpp | 2 +- src/V3Simulate.h | 4 ++-- src/V3Unknown.cpp | 9 +++++---- src/V3Unroll.cpp | 4 ++-- src/V3UnrollGen.cpp | 6 +++--- src/Verilator.cpp | 2 +- src/cppcheck-suppressions.txt | 6 ++++++ src/verilog.y | 14 +++++++------- 38 files changed, 122 insertions(+), 111 deletions(-) diff --git a/include/verilatedos_c.h b/include/verilatedos_c.h index 79d16f0d8..b8ef98b43 100644 --- a/include/verilatedos_c.h +++ b/include/verilatedos_c.h @@ -133,6 +133,7 @@ unsigned getProcessAvailableParallelism() VL_MT_SAFE { unsigned getProcessDefaultParallelism() VL_MT_SAFE { const unsigned n = getProcessAvailableParallelism(); + // cppcheck-suppress knownConditionTrueFalse return n ? n : std::thread::hardware_concurrency(); } diff --git a/src/V3Assert.cpp b/src/V3Assert.cpp index 0940b6e5b..448c08e8b 100644 --- a/src/V3Assert.cpp +++ b/src/V3Assert.cpp @@ -280,9 +280,8 @@ class AssertVisitor final : public VNVisitor { return newp; } - static AstIf* assertCond(AstNodeCoverOrAssert* nodep, AstNodeExpr* propp, AstNode* passsp, - AstNode* failsp) { - + static AstIf* assertCond(const AstNodeCoverOrAssert* nodep, AstNodeExpr* propp, + AstNode* passsp, AstNode* failsp) { AstIf* const ifp = new AstIf{nodep->fileline(), propp, passsp, failsp}; // It's more LIKELY that we'll take the nullptr if clause // than the sim-killing else clause: @@ -291,7 +290,7 @@ class AssertVisitor final : public VNVisitor { return ifp; } - AstNode* assertBody(AstNodeCoverOrAssert* nodep, AstNode* propp, AstNode* passsp, + AstNode* assertBody(const AstNodeCoverOrAssert* nodep, AstNode* propp, AstNode* passsp, AstNode* failsp) { AstNode* bodyp = nullptr; if (AstPExpr* const pexprp = VN_CAST(propp, PExpr)) { diff --git a/src/V3AssertProp.cpp b/src/V3AssertProp.cpp index 922f10fba..28d2f7806 100644 --- a/src/V3AssertProp.cpp +++ b/src/V3AssertProp.cpp @@ -109,7 +109,7 @@ class AssertPropBuildVisitor final : public VNVisitorConst { bool m_underSExpr = false; // Is under sequence expression, for creating a start node size_t m_underLogNots = 0; // Number of 'not' operators before sequence - DfaStmtVertex* makeClause(AstSExpr* nodep, bool pass) { + DfaStmtVertex* makeClause(const AstSExpr* nodep, bool pass) { return new DfaStmtVertex{ &m_graph, new AstPExprClause{nodep->fileline(), m_underLogNots % 2 == 0 ? pass : !pass}}; @@ -227,7 +227,7 @@ class AssertPropTransformer final { m_current = passsp; return processEdge(vtxp->outEdges().frontp()); } - V3GraphVertex* processEdge(V3GraphEdge* edgep) { + V3GraphVertex* processEdge(const V3GraphEdge* edgep) { if (edgep) return processVtx(edgep->top()); return nullptr; } diff --git a/src/V3Ast.cpp b/src/V3Ast.cpp index 3d36866e6..0f5e5d990 100644 --- a/src/V3Ast.cpp +++ b/src/V3Ast.cpp @@ -55,14 +55,14 @@ V3AST_VCMETHOD_ITEMDATA_DECL; // VCMethod information VCMethod VCMethod::arrayMethod(const string& name) { - for (auto& it : s_itemData) + for (const auto& it : s_itemData) if (it.m_name == name) return it.m_e; v3fatalSrc("Not a method name known to VCMethod::s_itemData: '" << name << '\''); return VCMethod{}; } void VCMethod::selfTest() { int i = 0; - for (auto& it : s_itemData) { + for (const auto& it : s_itemData) { VCMethod exp{i}; UASSERT_STATIC(it.m_e == exp, "VCMethod::s_itemData table rows are out-of-order, starting at row "s diff --git a/src/V3AstNodeExpr.h b/src/V3AstNodeExpr.h index b1cccc769..2d879013e 100644 --- a/src/V3AstNodeExpr.h +++ b/src/V3AstNodeExpr.h @@ -583,7 +583,7 @@ class AstCExpr final : public AstNodeExpr { public: class Pure {}; - AstCExpr(FileLine* fl, const string& text = "", int setwidth = 0) + explicit AstCExpr(FileLine* fl, const string& text = "", int setwidth = 0) : ASTGEN_SUPER_CExpr(fl) , m_pure{false} { init(text, setwidth); @@ -617,7 +617,7 @@ class AstCExprUser final : public AstNodeExpr { const bool m_pure; // Whether the function is pure public: class Pure {}; - AstCExprUser(FileLine* fl) + explicit AstCExprUser(FileLine* fl) : ASTGEN_SUPER_CExprUser(fl) , m_pure{false} {} AstCExprUser(FileLine* fl, Pure) diff --git a/src/V3AstNodeOther.h b/src/V3AstNodeOther.h index 8c8b69cca..36913ebd4 100644 --- a/src/V3AstNodeOther.h +++ b/src/V3AstNodeOther.h @@ -1613,10 +1613,10 @@ class AstTextBlock final : public AstNode { const std::string m_separator; // Separator to print between each element in 'nodesp' const std::string m_suffix; // Suffix to pring after last element in 'nodesp' public: - AstTextBlock(FileLine* fl, // - const std::string& prefix = "", // - const std::string& separator = "", // - const std::string& suffix = "") + explicit AstTextBlock(FileLine* fl, // + const std::string& prefix = "", // + const std::string& separator = "", // + const std::string& suffix = "") : ASTGEN_SUPER_TextBlock(fl) , m_prefix{prefix} , m_separator{separator} @@ -2641,7 +2641,7 @@ public: , m_keyword{keyword} { this->sentreep(sentreep); } - inline AstAlways(AstAssignW* assignp); + explicit inline AstAlways(AstAssignW* assignp); ASTGEN_MEMBERS_AstAlways; // void dump(std::ostream& str) const override; diff --git a/src/V3AstNodeStmt.h b/src/V3AstNodeStmt.h index 9f97c54d2..6d87eabd0 100644 --- a/src/V3AstNodeStmt.h +++ b/src/V3AstNodeStmt.h @@ -289,7 +289,7 @@ class AstCStmt final : public AstNodeStmt { // C statement emitted into output, with some arbitrary nodes interspersed // @astgen op1 := nodesp : List[AstNode] public: - AstCStmt(FileLine* fl, const std::string& text = "") + explicit AstCStmt(FileLine* fl, const std::string& text = "") : ASTGEN_SUPER_CStmt(fl) { if (!text.empty()) add(text); } @@ -315,7 +315,7 @@ class AstCStmtUser final : public AstNodeStmt { // @astgen op1 := nodesp : List[AstNode] const bool m_fromDollarC; // Is from source '$c', emit decoration public: - AstCStmtUser(FileLine* fl, bool fromDollarC = false) + explicit AstCStmtUser(FileLine* fl, bool fromDollarC = false) : ASTGEN_SUPER_CStmtUser(fl) , m_fromDollarC{fromDollarC} {} ASTGEN_MEMBERS_AstCStmtUser; @@ -763,7 +763,7 @@ class AstLoop final : public AstNodeStmt { // @astgen op2 := contsp : List[AstNode] // Empty after LinkJump VOptionBool m_unroll; // Full, none, or default unrolling public: - AstLoop(FileLine* fl) + explicit AstLoop(FileLine* fl) : ASTGEN_SUPER_Loop(fl) {} ASTGEN_MEMBERS_AstLoop; void dump(std::ostream& str) const override; diff --git a/src/V3Broken.cpp b/src/V3Broken.cpp index f62df7a04..d7916185b 100644 --- a/src/V3Broken.cpp +++ b/src/V3Broken.cpp @@ -88,6 +88,7 @@ public: } private: // for V3Broken only + // cppcheck-suppress unusedPrivateFunction bool isAllocated(const AstNode* nodep) const VL_REQUIRES(m_mutex) { return m_allocated.count(nodep) != 0; } diff --git a/src/V3Const.cpp b/src/V3Const.cpp index a1dd854b9..bb0d69434 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -1122,7 +1122,7 @@ class ConstVisitor final : public VNVisitor { return true; } - bool matchCondCond(AstCond* nodep) { + bool matchCondCond(const AstCond* nodep) { // Same condition on either leg of a condition means that // expression is either always true or always false if (VN_IS(nodep->backp(), Cond)) return false; // Was checked when visited parent @@ -1133,14 +1133,14 @@ class ConstVisitor final : public VNVisitor { matchCondCondRecurse(nodep, truesp /*ref*/, falsesp /*ref*/); return false; // Can optimize further } - void matchCondCondRecurse(AstCond* nodep, std::vector& truesp, + void matchCondCondRecurse(const AstCond* nodep, std::vector& truesp, std::vector& falsesp) { // Avoid O(n^2) compares // Could reduce cost with hash table, but seems unlikely to be worth cost if (truesp.size() > 4 || falsesp.size() > 4) return; if (!nodep->condp()->isPure()) return; bool replaced = false; - for (AstNodeExpr* condp : truesp) { + for (const AstNodeExpr* condp : truesp) { if (replaced) break; if (!operandsSame(nodep->condp(), condp)) continue; UINFO(9, "COND(c, CONDb(c, tt, tf), f) -> CONDb(1, tt, tf) " << nodep); @@ -1148,7 +1148,7 @@ class ConstVisitor final : public VNVisitor { replaced = true; ++m_statCondExprRedundant; } - for (AstNodeExpr* condp : falsesp) { + for (const AstNodeExpr* condp : falsesp) { if (replaced) break; if (!operandsSame(nodep->condp(), condp)) continue; UINFO(9, "COND(c, t, CONDb(c, ft, ff)) -> CONDb(0, ft, ff) " << nodep); @@ -1156,18 +1156,18 @@ class ConstVisitor final : public VNVisitor { replaced = true; ++m_statCondExprRedundant; } - if (AstCond* subCondp = VN_CAST(nodep->thenp(), Cond)) { + if (const AstCond* subCondp = VN_CAST(nodep->thenp(), Cond)) { if (!replaced) truesp.emplace_back(nodep->condp()); matchCondCondRecurse(subCondp, truesp /*ref*/, falsesp /*ref*/); if (!replaced) truesp.pop_back(); } - if (AstCond* subCondp = VN_CAST(nodep->elsep(), Cond)) { + if (const AstCond* subCondp = VN_CAST(nodep->elsep(), Cond)) { if (!replaced) falsesp.emplace_back(nodep->condp()); matchCondCondRecurse(subCondp, truesp /*ref*/, falsesp /*ref*/); if (!replaced) falsesp.pop_back(); } } - void matchIfCondCond(AstNodeIf* nodep) { + void matchIfCondCond(const AstNodeIf* nodep) { // Same condition on either leg of a condition means that // expression is either always true or always false if (VN_IS(nodep->backp(), If)) return; // Was checked when visited parent @@ -1176,14 +1176,14 @@ class ConstVisitor final : public VNVisitor { std::vector falsesp; matchIfCondCondRecurse(nodep, truesp /*ref*/, falsesp /*ref*/); } - void matchIfCondCondRecurse(AstNodeIf* nodep, std::vector& truesp, + void matchIfCondCondRecurse(const AstNodeIf* nodep, std::vector& truesp, std::vector& falsesp) { // Avoid O(n^2) compares // Could reduce cost with hash table, but seems unlikely to be worth cost if (truesp.size() > 4 || falsesp.size() > 4) return; if (!nodep->condp()->isPure()) return; bool replaced = false; - for (AstNodeExpr* condp : truesp) { + for (const AstNodeExpr* condp : truesp) { if (replaced) break; if (!operandsSame(nodep->condp(), condp)) continue; UINFO(9, "COND(c, CONDb(c, tt, tf), f) -> CONDb(1, tt, tf) " << nodep); @@ -1191,7 +1191,7 @@ class ConstVisitor final : public VNVisitor { replaced = true; ++m_statIfCondExprRedundant; } - for (AstNodeExpr* condp : falsesp) { + for (const AstNodeExpr* condp : falsesp) { if (replaced) break; if (!operandsSame(nodep->condp(), condp)) continue; UINFO(9, "COND(c, t, CONDb(c, ft, ff)) -> CONDb(0, ft, ff) " << nodep); @@ -1202,12 +1202,12 @@ class ConstVisitor final : public VNVisitor { // We only check the first statement of parent IF is an If // So we don't need to check for effects in the executing thensp/elsesp // altering the child't condition. e.g. 'if (x) begin x=1; if (x) end' - if (AstNodeIf* subIfp = VN_CAST(nodep->thensp(), NodeIf)) { + if (const AstNodeIf* subIfp = VN_CAST(nodep->thensp(), NodeIf)) { if (!replaced) truesp.emplace_back(nodep->condp()); matchIfCondCondRecurse(subIfp, truesp /*ref*/, falsesp /*ref*/); if (!replaced) truesp.pop_back(); } - if (AstNodeIf* subIfp = VN_CAST(nodep->elsesp(), NodeIf)) { + if (const AstNodeIf* subIfp = VN_CAST(nodep->elsesp(), NodeIf)) { if (!replaced) falsesp.emplace_back(nodep->condp()); matchIfCondCondRecurse(subIfp, truesp /*ref*/, falsesp /*ref*/); if (!replaced) falsesp.pop_back(); @@ -2635,7 +2635,7 @@ class ConstVisitor final : public VNVisitor { } bool matchToStringNConst(AstToStringN* nodep) { iterateChildren(nodep); - if (AstInitArray* const initp = VN_CAST(nodep->lhsp(), InitArray)) { + if (const AstInitArray* const initp = VN_CAST(nodep->lhsp(), InitArray)) { if (!(m_doExpensive || m_params)) return false; // At present only support 1D unpacked arrays const auto initOfConst = [](const AstNode* const nodep) -> bool { // @@ -2823,9 +2823,9 @@ class ConstVisitor final : public VNVisitor { // cppcheck-suppress constVariablePointer // children unlinked below AstReplicate* const rep2p = VN_AS(nodep->srcp(), Replicate); AstNodeExpr* const from2p = rep2p->srcp(); - AstConst* const cnt1p = VN_CAST(nodep->countp(), Const); + const AstConst* const cnt1p = VN_CAST(nodep->countp(), Const); if (!cnt1p) return false; - AstConst* const cnt2p = VN_CAST(rep2p->countp(), Const); + const AstConst* const cnt2p = VN_CAST(rep2p->countp(), Const); if (!cnt2p) return false; // from2p->unlinkFrBack(); @@ -3606,7 +3606,7 @@ class ConstVisitor final : public VNVisitor { bool thisLoopHasJumpDelay = m_hasJumpDelay; m_hasJumpDelay = thisLoopHasJumpDelay || oldHasJumpDelay; // If the first statement always break, the loop is useless - if (AstLoopTest* const testp = VN_CAST(nodep->stmtsp(), LoopTest)) { + if (const AstLoopTest* const testp = VN_CAST(nodep->stmtsp(), LoopTest)) { if (testp->condp()->isZero()) { nodep->v3warn(UNUSEDLOOP, "Loop condition is always false"); VL_DO_DANGLING(pushDeletep(nodep->unlinkFrBack()), nodep); @@ -3680,8 +3680,8 @@ class ConstVisitor final : public VNVisitor { return; } // Remove calls to empty functions - if (AstCCall* const callp = VN_CAST(nodep->exprp(), CCall)) { - AstCFunc* const funcp = callp->funcp(); + if (const AstCCall* const callp = VN_CAST(nodep->exprp(), CCall)) { + const AstCFunc* const funcp = callp->funcp(); if (!callp->argsp() && funcp->emptyBody()) { VL_DO_DANGLING(pushDeletep(nodep->unlinkFrBack()), nodep); return; diff --git a/src/V3Control.cpp b/src/V3Control.cpp index a1f432a22..40367cd6b 100644 --- a/src/V3Control.cpp +++ b/src/V3Control.cpp @@ -796,7 +796,7 @@ void V3Control::applyFTask(AstNodeModule* modulep, AstNodeFTask* ftaskp) { void V3Control::applyVarAttr(const AstNodeModule* modulep, const AstNodeFTask* ftaskp, AstVar* varp) { - V3ControlVar* vp; + const V3ControlVar* vp; V3ControlModule* const modp = V3ControlResolver::s().modules().resolve(modulep->prettyDehashOrigOrName()); if (!modp) return; diff --git a/src/V3Dead.cpp b/src/V3Dead.cpp index 97cd5d36e..e17b18e52 100644 --- a/src/V3Dead.cpp +++ b/src/V3Dead.cpp @@ -378,7 +378,7 @@ class DeadVisitor final : public VNVisitor { }); taskp->user1(-1); // we don't want to try deleting twice deleting(taskp); - m_statFTasksDeadified++; + ++m_statFTasksDeadified; } } } diff --git a/src/V3DfgAstToDfg.cpp b/src/V3DfgAstToDfg.cpp index ba56509a3..0ccdb80d3 100644 --- a/src/V3DfgAstToDfg.cpp +++ b/src/V3DfgAstToDfg.cpp @@ -181,7 +181,7 @@ class AstToDfgVisitor final : public VNVisitor { const VAlwaysKwd kwd = nodep->keyword(); if (kwd == VAlwaysKwd::CONT_ASSIGN) { // TODO: simplify once CFG analysis can handle arrays - if (AstAssignW* const ap = VN_CAST(nodep->stmtsp(), AssignW)) { + if (const AstAssignW* const ap = VN_CAST(nodep->stmtsp(), AssignW)) { if (ap->nextp()) return false; // Cannot handle assignment with timing control if (ap->timingControlp()) return false; diff --git a/src/V3DfgOptimizer.cpp b/src/V3DfgOptimizer.cpp index 04cb69fa3..bd3a89578 100644 --- a/src/V3DfgOptimizer.cpp +++ b/src/V3DfgOptimizer.cpp @@ -269,8 +269,9 @@ class DataflowOptimize final { } // TODO: remove once Actives can tolerate NEVER SenItems if (AstSenItem* senItemp = VN_CAST(nodep, SenItem)) { - senItemp->foreach( - [](AstVarRef* refp) { DfgVertexVar::setHasExtRdRefs(refp->varScopep()); }); + senItemp->foreach([](const AstVarRef* refp) { + DfgVertexVar::setHasExtRdRefs(refp->varScopep()); + }); } } else { if (AstVar* const varp = VN_CAST(nodep, Var)) { diff --git a/src/V3EmitCBase.cpp b/src/V3EmitCBase.cpp index afce95b18..50a2ec195 100644 --- a/src/V3EmitCBase.cpp +++ b/src/V3EmitCBase.cpp @@ -273,7 +273,7 @@ std::pair EmitCBaseVisitorConst::scSection(const AstNodeModul FileLine* fl = nullptr; int last_line = -999; for (AstNode* nodep = modp->stmtsp(); nodep; nodep = nodep->nextp()) { - AstSystemCSection* const ssp = VN_CAST(nodep, SystemCSection); + const AstSystemCSection* const ssp = VN_CAST(nodep, SystemCSection); if (!ssp) continue; if (ssp->sectionType() != type) continue; if (text.empty()) { diff --git a/src/V3EmitCPch.cpp b/src/V3EmitCPch.cpp index 7673f625f..0865fdfd2 100644 --- a/src/V3EmitCPch.cpp +++ b/src/V3EmitCPch.cpp @@ -64,7 +64,7 @@ public: } // VISITOR - void visit(AstNode* nodep) { nodep->v3fatalSrc("Unused"); } + void visit(AstNode* nodep) override { nodep->v3fatalSrc("Unused"); } public: explicit EmitCPch() { emitPch(); } diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index 929c04f91..d5553504f 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -108,11 +108,11 @@ class EmitCSyms final : EmitCBaseVisitorConst { void emitSymHdr(); void emitSymImpPreamble(); void emitScopeHier(std::vector& stmts, bool destroy); - void emitSymImp(AstNetlist* netlistp); + void emitSymImp(const AstNetlist* netlistp); void emitDpiHdr(); void emitDpiImp(); - void emitSplit(std::vector& stmts, const std::string name, size_t max_stmts); + void emitSplit(std::vector& stmts, const std::string& name, size_t max_stmts); std::vector getSymCtorStmts(); std::vector getSymDtorStmts(); @@ -863,7 +863,7 @@ std::vector EmitCSyms::getSymDtorStmts() { return stmts; } -void EmitCSyms::emitSplit(std::vector& stmts, const std::string name, +void EmitCSyms::emitSplit(std::vector& stmts, const std::string& name, size_t maxCost) { size_t nSubFunctions = 0; // Reduce into a balanced tree of sub-function calls until we end up with a single statement @@ -912,7 +912,7 @@ void EmitCSyms::emitSplit(std::vector& stmts, const std::string nam } } -void EmitCSyms::emitSymImp(AstNetlist* netlistp) { +void EmitCSyms::emitSymImp(const AstNetlist* netlistp) { UINFO(6, __FUNCTION__ << ": "); // Get the body of the constructor and destructor diff --git a/src/V3EmitMkJson.cpp b/src/V3EmitMkJson.cpp index f9bd18a6d..9a2517095 100644 --- a/src/V3EmitMkJson.cpp +++ b/src/V3EmitMkJson.cpp @@ -118,11 +118,11 @@ class V3EmitMkJsonEmitter final { // really have to, but verilator-config.cmake.in depends on order. for (const V3GraphVertex& vtx : vlstd::reverse_view(graphp->vertices())) { const V3HierBlock* const hblockp = vtx.as(); - std::vector deps; + std::vector hierDeps; std::vector sources; for (const V3GraphEdge& edge : hblockp->outEdges()) { const V3HierBlock* const dependencyp = edge.top()->as(); - deps.emplace_back(dependencyp->hierPrefix()); + hierDeps.emplace_back(dependencyp->hierPrefix()); sources.emplace_back(makeDir + "/" + dependencyp->hierWrapperFilename(true)); } @@ -137,7 +137,7 @@ class V3EmitMkJsonEmitter final { of.begin() .put("prefix", hblockp->hierPrefix()) .put("top", hblockp->modp()->name()) - .putList("deps", deps) + .putList("deps", hierDeps) .put("directory", makeDir + "/" + hblockp->hierPrefix()) .putList("sources", sources) .putList("cflags", {"-fPIC"}) diff --git a/src/V3ExecGraph.cpp b/src/V3ExecGraph.cpp index 28f5b86db..941aa9966 100644 --- a/src/V3ExecGraph.cpp +++ b/src/V3ExecGraph.cpp @@ -35,13 +35,13 @@ VL_DEFINE_DEBUG_FUNCTIONS; AstCFunc* ExecMTask::createCFunc(AstExecGraph* execGraphp, AstScope* scopep, AstNodeStmt* stmtsp, uint32_t id) { - const std::string name = execGraphp->name() + "_mtask" + std::to_string(id); - AstCFunc* const funcp = new AstCFunc{execGraphp->fileline(), name, scopep}; - funcp->isLoose(true); - funcp->dontCombine(true); - funcp->addStmtsp(stmtsp); - if (scopep) scopep->addBlocksp(funcp); - return funcp; + const std::string newName = execGraphp->name() + "_mtask" + std::to_string(id); + AstCFunc* const newp = new AstCFunc{execGraphp->fileline(), newName, scopep}; + newp->isLoose(true); + newp->dontCombine(true); + newp->addStmtsp(stmtsp); + if (scopep) scopep->addBlocksp(newp); + return newp; } ExecMTask::ExecMTask(AstExecGraph* execGraphp, AstScope* scopep, diff --git a/src/V3Expand.cpp b/src/V3Expand.cpp index b3a57154a..43d3b37b7 100644 --- a/src/V3Expand.cpp +++ b/src/V3Expand.cpp @@ -234,7 +234,7 @@ class ExpandVisitor final : public VNVisitor { static AstNodeExpr* newWordIndex(AstNodeExpr* lsbp, uint32_t wordOffset = 0) { // This is indexing a WordSel, so a 32 bit constants are fine FileLine* const flp = lsbp->fileline(); - if (AstConst* constp = VN_CAST(lsbp, Const)) { + if (const AstConst* constp = VN_CAST(lsbp, Const)) { return new AstConst{flp, wordOffset + VL_BITWORD_E(constp->toUInt())}; } @@ -250,7 +250,7 @@ class ExpandVisitor final : public VNVisitor { uint32_t wordOffset = 0) { UASSERT_OBJ(fromp->isWide(), fromp, "Only need AstWordSel on wide from's"); - if (AstConst* const constp = VN_CAST(indexp, Const)) { + if (const AstConst* const constp = VN_CAST(indexp, Const)) { indexp = nullptr; wordOffset += constp->toUInt(); } @@ -545,7 +545,7 @@ class ExpandVisitor final : public VNVisitor { V3Const::constifyEditCpp(rhsp->lsbp()); // If it's a constant select and aligned, we can just copy the words - if (AstConst* const lsbConstp = VN_CAST(rhsp->lsbp(), Const)) { + if (const AstConst* const lsbConstp = VN_CAST(rhsp->lsbp(), Const)) { const uint32_t lsb = lsbConstp->toUInt(); if (VL_BITBIT_E(lsb) == 0) { UINFO(8, " Wordize ASSIGN(SEL,align) " << nodep); @@ -577,7 +577,7 @@ class ExpandVisitor final : public VNVisitor { AstNodeExpr* loShftp = nullptr; AstNodeExpr* hiShftp = nullptr; AstNodeExpr* hiMaskp = nullptr; - if (AstConst* const lsbConstp = VN_CAST(rhsp->lsbp(), Const)) { + if (const AstConst* const lsbConstp = VN_CAST(rhsp->lsbp(), Const)) { const uint32_t bitOffset = VL_BITBIT_E(lsbConstp->toUInt()); // Must be unaligned, otherwise we would have handled it above UASSERT_OBJ(bitOffset, nodep, "Missed aligned wide select"); diff --git a/src/V3File.cpp b/src/V3File.cpp index 10f3fc990..762b1893d 100644 --- a/src/V3File.cpp +++ b/src/V3File.cpp @@ -752,7 +752,7 @@ void V3OutFormatter::putns(const AstNode* nodep, const char* strg) { } if (putNodeDecoration) { - FileLine* const flp = nodep->fileline(); + const FileLine* const flp = nodep->fileline(); m_sourceLastLineno = flp->firstLineno(); m_sourceLastFilenameno = flp->filenameno(); const std::string lineno = std::to_string(flp->lineno()); diff --git a/src/V3HierBlock.cpp b/src/V3HierBlock.cpp index e0bf4ab6c..2c0d24607 100644 --- a/src/V3HierBlock.cpp +++ b/src/V3HierBlock.cpp @@ -173,9 +173,7 @@ VStringList V3HierBlock::commandArgs(bool forMkJson) const { const StrGParams gparamsStr = stringifyParams(m_params, true); for (const StrGParam& param : gparamsStr) { - const string name = param.first; - const string value = param.second; - opts.push_back("-G" + name + "=" + value + ""); + opts.push_back("-G" + param.first + "=" + param.second + ""); } if (!m_typeParams.empty()) { opts.push_back(" --hierarchical-params-file " + typeParametersFilename()); @@ -382,7 +380,7 @@ class HierBlockUsageCollectVisitor final : public VNVisitorConst { void visit(AstNode* nodep) override { iterateChildrenConst(nodep); } // CONSTRUCTOR - HierBlockUsageCollectVisitor(AstNetlist* netlistp) { + explicit HierBlockUsageCollectVisitor(AstNetlist* netlistp) { iterateChildrenConst(netlistp); if (dumpGraphLevel() >= 3) m_graphp->dumpDotFilePrefixed("hierblocks_initial"); // Simplify dependencies diff --git a/src/V3Inline.cpp b/src/V3Inline.cpp index 03649a5ce..eab6919ef 100644 --- a/src/V3Inline.cpp +++ b/src/V3Inline.cpp @@ -429,7 +429,7 @@ namespace ModuleInliner { // against it later in V3Scope (and also for tracing, which is inserted //later). Returns ture iff the given port variable should be inlined, // and false if a continuous assignment should be used. -bool inlinePort(AstVar* nodep) { +bool inlinePort(const AstVar* nodep) { // Interface references are always inlined if (nodep->isIfaceRef()) return true; // Ref ports must be always inlined @@ -544,7 +544,6 @@ void inlineCell(AstNodeModule* modp, AstCell* cellp, bool last) { : cellp->modp()->cloneTree(false); // Compute map from original port variables and cells to their clones - std::unordered_map modVar2Clone; for (AstNode *ap = cellp->modp()->stmtsp(), *bp = inlinedp->stmtsp(); ap || bp; ap = ap->nextp(), bp = bp->nextp()) { UASSERT_OBJ(ap && bp, ap ? ap : bp, "Clone has different number of children"); diff --git a/src/V3Life.cpp b/src/V3Life.cpp index 938281e32..a4495d22f 100644 --- a/src/V3Life.cpp +++ b/src/V3Life.cpp @@ -133,7 +133,7 @@ public: , m_statep{statep} {} ~LifeBlock() = default; // METHODS - void checkRemoveAssign(AstVarScope* vscp, LifeVarEntry& entr) { + void checkRemoveAssign(const AstVarScope* vscp, LifeVarEntry& entr) { const AstVar* const varp = vscp->varp(); // We don't optimize any public sigs if (varp->isSigPublic()) return; diff --git a/src/V3Number.cpp b/src/V3Number.cpp index c683ed828..3b7f87e06 100644 --- a/src/V3Number.cpp +++ b/src/V3Number.cpp @@ -920,6 +920,7 @@ string V3Number::emitC() const VL_MT_STABLE { } else if (words() == 2) { // Quad const uint64_t qnum = static_cast(toUQuad()); const char* const fmt = (qnum < 10) ? ("%" PRIx64 "ULL") : ("0x%016" PRIx64 "ULL"); + // cppcheck-suppress wrongPrintfScanfArgNum VL_SNPRINTF(sbuf, bufsize, fmt, qnum); return sbuf; } else { @@ -930,6 +931,7 @@ string V3Number::emitC() const VL_MT_STABLE { : (width() > 16) ? ("0x%08" PRIx32 "U") : (width() > 8) ? ("0x%04" PRIx32 "U") : ("0x%02" PRIx32 "U"); + // cppcheck-suppress wrongPrintfScanfArgNum VL_SNPRINTF(sbuf, bufsize, fmt, unum); return sbuf; } diff --git a/src/V3Options.cpp b/src/V3Options.cpp index fac3ebaca..6a300f141 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -486,7 +486,8 @@ std::vector V3Options::traceClassBases() const VL_MT_SAFE { } std::vector V3Options::traceClassLangs() const VL_MT_SAFE { std::vector result; - for (auto& cbase : traceClassBases()) result.emplace_back(cbase + (systemC() ? "Sc" : "C")); + for (const auto& cbase : traceClassBases()) + result.emplace_back(cbase + (systemC() ? "Sc" : "C")); return result; } std::vector V3Options::traceSourceBases() const VL_MT_SAFE { diff --git a/src/V3OrderInternal.h b/src/V3OrderInternal.h index 09cee9b64..f2d5eb998 100644 --- a/src/V3OrderInternal.h +++ b/src/V3OrderInternal.h @@ -55,7 +55,7 @@ AstNodeStmt* createSerial(OrderMoveGraph& moveGraph, // const std::string& tag, // bool slow); -AstNodeStmt* createParallel(OrderGraph& orderGraph, // +AstNodeStmt* createParallel(const OrderGraph& orderGraph, // OrderMoveGraph& moveGraph, // const std::string& tag, // bool slow); diff --git a/src/V3OrderParallel.cpp b/src/V3OrderParallel.cpp index d3b4b3904..912311bf8 100644 --- a/src/V3OrderParallel.cpp +++ b/src/V3OrderParallel.cpp @@ -2394,7 +2394,7 @@ struct MTaskVxIdLessThan final { } }; -AstNodeStmt* V3Order::createParallel(OrderGraph& orderGraph, OrderMoveGraph& moveGraph, +AstNodeStmt* V3Order::createParallel(const OrderGraph& orderGraph, OrderMoveGraph& moveGraph, const std::string& tag, bool slow) { UINFO(2, " Constructing parallel code for '" + tag + "'"); diff --git a/src/V3Param.cpp b/src/V3Param.cpp index b5d8472c9..212533fd4 100644 --- a/src/V3Param.cpp +++ b/src/V3Param.cpp @@ -771,10 +771,10 @@ class ParamProcessor final { UINFOTREE(1, pinp, "", "errnode"); pinp->v3error("Can't convert defparam value to constant: Param " << pinp->prettyNameQ() << " of " << nodep->prettyNameQ()); - AstNode* const exprp = pinp->exprp(); - exprp->replaceWith(new AstConst{pinp->fileline(), AstConst::WidthedValue{}, - modvarp->width(), 0}); - VL_DO_DANGLING(exprp->deleteTree(), exprp); + AstNode* const pinExprp = pinp->exprp(); + pinExprp->replaceWith(new AstConst{pinp->fileline(), AstConst::WidthedValue{}, + modvarp->width(), 0}); + VL_DO_DANGLING(pinExprp->deleteTree(), pinExprp); } else if (origp && exprp->sameTree(origp)) { // Setting parameter to its default value. Just ignore it. // This prevents making additional modules, and makes coverage more @@ -1087,7 +1087,7 @@ class ParamProcessor final { // We need to relink the pins to the new module relinkPinsByName(pinsp, paramedModp); newModp = paramedModp; - any_overrides = true; + // any_overrides = true; // Unused later, so not needed } else if (!any_overrides) { UINFO(8, "Cell parameters all match original values, skipping expansion."); // If it's the first use of the default instance, create a copy and store it in user3p. @@ -1281,7 +1281,7 @@ class ParamVisitor final : public VNVisitor { m_isCircular; // Stores information whether `AstRefDType` is circular // STATE - for current visit position (use VL_RESTORER) - AstNodeModule* m_modp; // Module iterating + AstNodeModule* m_modp = nullptr; // Module iterating std::unordered_set m_ifacePortNames; // Interface port names in current module std::unordered_set m_ifaceInstNames; // Interface decl names in current module string m_generateHierName; // Generate portion of hierarchy name diff --git a/src/V3ParseGrammar.h b/src/V3ParseGrammar.h index 29d660154..173f5aa56 100644 --- a/src/V3ParseGrammar.h +++ b/src/V3ParseGrammar.h @@ -64,7 +64,7 @@ public: // METHODS AstArg* argWrapList(AstNodeExpr* nodep) VL_MT_DISABLED; - bool allTracingOn(FileLine* fl) { + bool allTracingOn(const FileLine* fl) const { return v3Global.opt.trace() && m_tracingParse && fl->tracingOn(); } AstRange* scrubRange(AstNodeRange* rangep) VL_MT_DISABLED; @@ -99,11 +99,13 @@ public: nodep->addStmtsp(defaultVarp); // IEEE: function void sample() - AstFunc* const funcp = new AstFunc{nodep->fileline(), "sample", nullptr, nullptr}; - funcp->addStmtsp(sampleArgs); - funcp->classMethod(true); - funcp->dtypep(funcp->findVoidDType()); - nodep->addMembersp(funcp); + { + AstFunc* const funcp = new AstFunc{nodep->fileline(), "sample", nullptr, nullptr}; + funcp->addStmtsp(sampleArgs); + funcp->classMethod(true); + funcp->dtypep(funcp->findVoidDType()); + nodep->addMembersp(funcp); + } // IEEE: function void start(), void stop() for (const string& name : {"start"s, "stop"s}) { @@ -200,10 +202,10 @@ public: V3ParseImp::parsep()->tagNodep(nodep); return nodep; } - void endLabel(FileLine* fl, AstNode* nodep, string* endnamep) { + void endLabel(FileLine* fl, const AstNode* nodep, const string* endnamep) { endLabel(fl, nodep->prettyName(), endnamep); } - void endLabel(FileLine* fl, const string& name, string* endnamep) { + void endLabel(FileLine* fl, const string& name, const string* endnamep) { if (fl && endnamep && *endnamep != "" && name != *endnamep && name != AstNode::prettyName(*endnamep)) { fl->v3warn(ENDLABEL, "End label '" << *endnamep << "' does not match begin label '" diff --git a/src/V3SchedTrigger.cpp b/src/V3SchedTrigger.cpp index 06731880b..d04d2d359 100644 --- a/src/V3SchedTrigger.cpp +++ b/src/V3SchedTrigger.cpp @@ -607,8 +607,8 @@ TriggerKit TriggerKit::create(AstNetlist* netlistp, // for (uint32_t level = 0; level < WORD_SIZE_LOG2; ++level) { const uint32_t stride = 1 << level; for (uint32_t j = 0; j < WORD_SIZE; j += 2 * stride) { - FileLine* const flp = trigps[i + j]->fileline(); - trigps[i + j] = new AstConcat{flp, trigps[i + j + stride], trigps[i + j]}; + trigps[i + j] = new AstConcat{trigps[i + j]->fileline(), trigps[i + j + stride], + trigps[i + j]}; trigps[i + j + stride] = nullptr; } } @@ -668,11 +668,11 @@ TriggerKit TriggerKit::create(AstNetlist* netlistp, // for (AstNodeStmt* const nodep : senResults.m_postUpdates) fp->addStmtsp(nodep); // Add the initialization time triggers if (initialTrigsp) { - AstVarScope* const vscp = scopep->createTemp("__V" + name + "DidInit", 1); - AstIf* const ifp = new AstIf{flp, new AstNot{flp, rd(vscp)}}; + AstVarScope* const initVscp = scopep->createTemp("__V" + name + "DidInit", 1); + AstIf* const ifp = new AstIf{flp, new AstNot{flp, rd(initVscp)}}; fp->addStmtsp(ifp); ifp->branchPred(VBranchPred::BP_UNLIKELY); - ifp->addThensp(util::setVar(vscp, 1)); + ifp->addThensp(util::setVar(initVscp, 1)); ifp->addThensp(initialTrigsp); } // If there are 'pre' triggers, compute them diff --git a/src/V3SchedUtil.cpp b/src/V3SchedUtil.cpp index f6230aa2f..a919c9506 100644 --- a/src/V3SchedUtil.cpp +++ b/src/V3SchedUtil.cpp @@ -92,7 +92,7 @@ AstNodeStmt* checkIterationLimit(AstNetlist* netlistp, const string& name, AstVa ifp->addThensp(dumpCallp); AstCStmt* const stmtp = new AstCStmt{flp}; ifp->addThensp(stmtp); - FileLine* const locp = netlistp->topModulep()->fileline(); + const FileLine* const locp = netlistp->topModulep()->fileline(); const std::string& file = VIdProtect::protect(locp->filename()); const std::string& line = std::to_string(locp->lineno()); stmtp->add("VL_FATAL_MT(\"" + V3OutFormatter::quoteNameControls(file) + "\", " + line diff --git a/src/V3Simulate.h b/src/V3Simulate.h index b48eedb22..4c540b1ac 100644 --- a/src/V3Simulate.h +++ b/src/V3Simulate.h @@ -1204,7 +1204,7 @@ private: } // Apply value to the function if (!m_checkOnly && optimizable()) - for (auto& it : portValues) { + for (const auto& it : portValues) { if (!m_checkOnly && optimizable()) newValue(it.first, it.second); } SimStackNode stackNode{nodep, &tconnects}; @@ -1222,7 +1222,7 @@ private: // Evaluate the function iterateConst(funcp); m_callStack.pop_back(); - AstNodeExpr* returnp = nullptr; + const AstNodeExpr* returnp = nullptr; if (!m_checkOnly && optimizable()) { // Grab return value from output variable UASSERT_OBJ(funcp->fvarp(), nodep, "Function reference points at non-function"); diff --git a/src/V3Unknown.cpp b/src/V3Unknown.cpp index 56763cdf2..f0e227238 100644 --- a/src/V3Unknown.cpp +++ b/src/V3Unknown.cpp @@ -551,10 +551,11 @@ class UnknownVisitor final : public VNVisitor { } else if (!lvalue) { // Mid-multidimension read, just use zero // ARRAYSEL(...) -> ARRAYSEL(COND(LT(bitbitp()->unlinkFrBack(&replaceHandle); - AstNodeExpr* const newp = new AstCond{ - bitp->fileline(), condp, bitp, - new AstConst{bitp->fileline(), AstConst::WidthedValue{}, bitp->width(), 0}}; + AstNodeExpr* const asBitp = nodep->bitp()->unlinkFrBack(&replaceHandle); + AstNodeExpr* const newp + = new AstCond{asBitp->fileline(), condp, asBitp, + new AstConst{asBitp->fileline(), AstConst::WidthedValue{}, + asBitp->width(), 0}}; // Added X's, tristate them too UINFOTREE(9, newp, "", "_new"); replaceHandle.relink(newp); diff --git a/src/V3Unroll.cpp b/src/V3Unroll.cpp index 1011e70f4..d0dc582bc 100644 --- a/src/V3Unroll.cpp +++ b/src/V3Unroll.cpp @@ -36,7 +36,7 @@ struct UnrollStats final { const char* const m_name; // Name for stats file and UDEBUG public: - Stat(const char* const name) + explicit Stat(const char* const name) : m_name{name} {} ~Stat() { V3Stats::addStat("Optimizations, Loop unrolling, "s + m_name, m_value); } const char* name() const { return m_name; } @@ -384,7 +384,7 @@ class UnrollAllVisitor final : VNVisitor { void visit(AstNode* nodep) override { iterateChildren(nodep); } // CONSTRUCTOR - UnrollAllVisitor(AstNetlist* netlistp) { iterate(netlistp); } + explicit UnrollAllVisitor(AstNetlist* netlistp) { iterate(netlistp); } public: static void apply(AstNetlist* netlistp) { UnrollAllVisitor{netlistp}; } diff --git a/src/V3UnrollGen.cpp b/src/V3UnrollGen.cpp index 88477afe6..db856ffb5 100644 --- a/src/V3UnrollGen.cpp +++ b/src/V3UnrollGen.cpp @@ -124,7 +124,7 @@ class UnrollGenVisitor final : public VNVisitor { return true; } - bool simulateTree(AstNodeExpr* nodep, const V3Number* loopValue, AstNode* dtypep, + bool simulateTree(AstNodeExpr* nodep, const V3Number* loopValue, const AstNode* dtypep, V3Number& outNum) { AstNode* clonep = nodep->cloneTree(true); UASSERT_OBJ(clonep, nodep, "Failed to clone tree"); @@ -146,7 +146,7 @@ class UnrollGenVisitor final : public VNVisitor { return false; } // Fetch the result - V3Number* resp = simvis.fetchNumberNull(clonep); + const V3Number* resp = simvis.fetchNumberNull(clonep); if (!resp) { UINFO(3, "No number returned from simulation"); VL_DO_DANGLING(clonep->deleteTree(), clonep); @@ -231,7 +231,7 @@ class UnrollGenVisitor final : public VNVisitor { } // loopValue += valInc - AstAssign* const incpass = VN_AS(incp, Assign); + const AstAssign* const incpass = VN_AS(incp, Assign); V3Number newLoopValue{nodep}; if (!simulateTree(incpass->rhsp(), &loopValue, incpass, newLoopValue)) { nodep->v3error("Loop unrolling failed"); diff --git a/src/Verilator.cpp b/src/Verilator.cpp index 226b49129..139c86fef 100644 --- a/src/Verilator.cpp +++ b/src/Verilator.cpp @@ -748,7 +748,7 @@ static bool verilate(const string& argString) { V3Error::abortIfWarnings(); - if (V3HierGraph* const hierGraphp + if (const V3HierGraph* const hierGraphp = v3Global.hierGraphp()) { // This run is for just write a makefile UASSERT(v3Global.opt.hierarchical(), "hierarchical must be set"); UASSERT(!v3Global.opt.hierChild(), "This must not be a hierarchical-child run"); diff --git a/src/cppcheck-suppressions.txt b/src/cppcheck-suppressions.txt index 80d510457..4e48160c3 100644 --- a/src/cppcheck-suppressions.txt +++ b/src/cppcheck-suppressions.txt @@ -27,6 +27,12 @@ unmatchedSuppression *:verilog.c *:V3Lexer_pregen.yy.cpp *:V3PreLex_pregen.yy.cpp +constParameterPointer:V3ParseBison.c +cstyleCast:../V3PreLex.l +cstyleCast:../verilog.l +cstyleCast:../verilog.y +cstyleCast:V3ParseBison.c +redundantContinue:V3ParseBison.c // Just check the hand written code missingInclude:examples/* // We intentionally redefine AstNode methods to improve type safety diff --git a/src/verilog.y b/src/verilog.y index 1d3bb513a..b2e58496b 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -136,7 +136,7 @@ const VBasicDTypeKwd LOGIC_IMPLICIT = VBasicDTypeKwd::LOGIC_IMPLICIT; #define DEL(...) \ { \ - AstNode* nodeps[] = {__VA_ARGS__}; \ + AstNode* const nodeps[] = {__VA_ARGS__}; \ for (AstNode* const nodep : nodeps) \ if (nodep) nodep->deleteTree(); \ } @@ -5500,9 +5500,9 @@ gateBuf: AstAssignW* const ap = new AstAssignW{$1, $2, rhsp}; $$->addNext(new AstAlways{ap}); for (AstNodeExpr* outp = $4; outp->nextp(); outp = VN_CAST(outp->nextp(), NodeExpr)) { - AstNodeExpr* const rhsp = GRAMMARP->createGatePin(inp->cloneTree(false)); - AstAssignW* const ap = new AstAssignW{$1, outp->cloneTree(false), rhsp}; - $$->addNext(new AstAlways{ap}); + AstNodeExpr* const pinRhsp = GRAMMARP->createGatePin(inp->cloneTree(false)); + AstAssignW* const pinAssp = new AstAssignW{$1, outp->cloneTree(false), pinRhsp}; + $$->addNext(new AstAlways{pinAssp}); } DEL($1); DEL($4); } ; @@ -5515,9 +5515,9 @@ gateNot: AstAssignW* const ap = new AstAssignW{$1, $2, rhsp}; $$->addNext(new AstAlways{ap}); for (AstNodeExpr* outp = $4; outp->nextp(); outp = VN_CAST(outp->nextp(), NodeExpr)) { - AstNodeExpr* const rhsp = new AstNot{$1, GRAMMARP->createGatePin(inp->cloneTree(false))}; - AstAssignW* const ap = new AstAssignW{$1, outp->cloneTree(false), rhsp}; - $$->addNext(new AstAlways{ap}); + AstNodeExpr* const pinRhsp = new AstNot{$1, GRAMMARP->createGatePin(inp->cloneTree(false))}; + AstAssignW* const pinAssp = new AstAssignW{$1, outp->cloneTree(false), pinRhsp}; + $$->addNext(new AstAlways{pinAssp}); } DEL($1, $4); } ;