diff --git a/Makefile.in b/Makefile.in index 205c912d9..312eccb6a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -340,7 +340,7 @@ CPPCHECK_FLAGS = --enable=all --inline-suppr \ --suppress=useStlAlgorithm CPPCHECK_FLAGS += --xml CPPCHECK_DEP = $(subst .cpp,.cppcheck,$(CHECK_CPP)) -CPPCHECK_INC = -I$(srcdir)/include -I$(srcdir)/src/obj_dbg -I$(srcdir)/src +CPPCHECK_INC = -I$(srcdir)/include -I$(srcdir)/include/gtkwave -I$(srcdir)/include/vltstd -I$(srcdir)/src/obj_dbg -I$(srcdir)/src cppcheck: cppcheck-1 cppcheck-2 cppcheck-3 cppcheck-4 cppcheck-5 cppcheck-6 cppcheck-7 cppcheck-8 cppcheck-1: diff --git a/include/verilated.cpp b/include/verilated.cpp index 3ce0fe4da..73d3cee4f 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -2693,7 +2693,7 @@ std::pair VerilatedContextImp::argc_argv() VL_MT_SAFE_EXCLUDES(m_ar int in = 0; for (const auto& i : m_args.m_argVec) { s_argvp[in] = new char[i.length() + 1]; - std::strcpy(s_argvp[in], i.c_str()); + std::memcpy(s_argvp[in], i.c_str(), i.length() + 1); ++in; } s_argvp[s_argc] = nullptr; diff --git a/include/verilated_vpi.cpp b/include/verilated_vpi.cpp index 03ad2abe9..151393cf9 100644 --- a/include/verilated_vpi.cpp +++ b/include/verilated_vpi.cpp @@ -507,9 +507,9 @@ public: delete this; // IEEE 37.2.2 vpi_scan at end does a vpi_release_handle return nullptr; } - const VerilatedScope::Type type = (*m_it)->type(); + const VerilatedScope::Type itype = (*m_it)->type(); const VerilatedScope* const modp = *m_it++; - if (type == VerilatedScope::SCOPE_MODULE) { + if (itype == VerilatedScope::SCOPE_MODULE) { return (new VerilatedVpioModule{modp})->castVpiHandle(); } } @@ -523,9 +523,9 @@ class VerilatedVpioPackage final : public VerilatedVpioScope { public: explicit VerilatedVpioPackage(const VerilatedScope* modulep) : VerilatedVpioScope{modulep} { - const char* fullname = m_scopep->name(); - if (std::strncmp(fullname, "TOP.", 4) == 0) fullname += 4; - m_fullname = std::string{fullname} + "::"; + const char* sfullname = m_scopep->name(); + if (std::strncmp(sfullname, "TOP.", 4) == 0) sfullname += 4; + m_fullname = std::string{sfullname} + "::"; if (m_fullname == "\\$unit ::") m_fullname = "$unit::"; m_name = std::string(m_scopep->identifier()); if (m_name == "\\$unit ") m_name = "$unit"; @@ -558,12 +558,12 @@ public: delete this; // IEEE 37.2.2 vpi_scan at end does a vpi_release_handle return nullptr; } - const VerilatedScope::Type type = (*m_it)->type(); + const VerilatedScope::Type itype = (*m_it)->type(); const VerilatedScope* const modp = *m_it++; - if (type == VerilatedScope::SCOPE_MODULE) { + if (itype == VerilatedScope::SCOPE_MODULE) { return (new VerilatedVpioModule{modp})->castVpiHandle(); } - if (type == VerilatedScope::SCOPE_PACKAGE) { + if (itype == VerilatedScope::SCOPE_PACKAGE) { return (new VerilatedVpioPackage{modp})->castVpiHandle(); } } diff --git a/src/V3Ast.cpp b/src/V3Ast.cpp index 1948e60ff..8dc5b7565 100644 --- a/src/V3Ast.cpp +++ b/src/V3Ast.cpp @@ -1116,6 +1116,7 @@ bool AstNode::sameTreeIter(const AstNode* node1p, const AstNode* node2p, bool ig void AstNode::checkTreeIter(const AstNode* prevBackp) const VL_MT_STABLE { // private: Check a tree and children UASSERT_OBJ(prevBackp == this->backp(), this, "Back node inconsistent"); + // cppcheck-suppress danglingTempReference const VNTypeInfo& typeInfo = *type().typeInfo(); for (int i = 1; i <= 4; i++) { AstNode* nodep = nullptr; @@ -1126,6 +1127,7 @@ void AstNode::checkTreeIter(const AstNode* prevBackp) const VL_MT_STABLE { case 4: nodep = op4p(); break; default: this->v3fatalSrc("Bad case"); break; } + // cppcheck-suppress danglingTempReference const char* opName = typeInfo.m_opNamep[i - 1]; switch (typeInfo.m_opType[i - 1]) { case VNTypeInfo::OP_UNUSED: @@ -1142,7 +1144,7 @@ void AstNode::checkTreeIter(const AstNode* prevBackp) const VL_MT_STABLE { case VNTypeInfo::OP_LIST: if (const AstNode* const headp = nodep) { const AstNode* backp = this; - const AstNode* tailp = headp; + const AstNode* tailp; const AstNode* opp = headp; do { opp->checkTreeIter(backp); diff --git a/src/V3Ast.h b/src/V3Ast.h index 71ec84aa0..af40b6ad9 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -125,6 +125,7 @@ public: constexpr VNType(en _e) VL_MT_SAFE : m_e{_e} {} explicit VNType(int _e) : m_e(static_cast(_e)) {} // Need () or GCC 4.8 false warning + // cppcheck-suppress danglingTempReference const VNTypeInfo* typeInfo() const VL_MT_SAFE { return &typeInfoTable[m_e]; } constexpr operator en() const VL_MT_SAFE { return m_e; } }; diff --git a/src/V3Const.cpp b/src/V3Const.cpp index 397324ed1..0b12137e1 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -542,9 +542,8 @@ class ConstBitOpTreeVisitor final : public VNVisitorConst { restorer.disableRestore(); // Now all checks passed } else if (nodep->type() == m_rootp->type()) { // And, Or, Xor incrOps(nodep, __LINE__); - VL_RESTORER(m_leafp); - for (const bool right : {false, true}) { + VL_RESTORER(m_leafp); Restorer restorer{*this}; LeafInfo leafInfo{m_lsb}; m_leafp = &leafInfo; diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index 217645f73..a2c253150 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -237,6 +237,7 @@ class EmitCSyms final : EmitCBaseVisitorConst { // << scpSym << endl); if (v3Global.opt.vpi()) varHierarchyScopes(scpName); if (m_scopeNames.find(scpSym) == m_scopeNames.end()) { + // cppcheck-suppress stlFindInsert m_scopeNames.emplace(scpSym, ScopeData{scpSym, scpPretty, 0, "SCOPE_OTHER"}); } @@ -341,6 +342,7 @@ class EmitCSyms final : EmitCBaseVisitorConst { ScopeFuncData(nodep, m_cfuncp, m_modp)); } else { if (m_scopeNames.find(nodep->scopeDpiName()) == m_scopeNames.end()) { + // cppcheck-suppress stlFindInsert m_scopeNames.emplace(nodep->scopeDpiName(), ScopeData{nodep->scopeDpiName(), nodep->scopePrettyDpiName(), timeunit, "SCOPE_OTHER"}); diff --git a/src/V3Gate.cpp b/src/V3Gate.cpp index 2e2976ff9..a25d7feea 100644 --- a/src/V3Gate.cpp +++ b/src/V3Gate.cpp @@ -48,7 +48,7 @@ class GateEitherVertex VL_NOT_FINAL : public V3GraphVertex { bool m_dedupable = true; // True if this node should be able to be deduped bool m_consumed = false; // Output goes to something meaningful public: - GateEitherVertex(V3Graph* graphp) + explicit GateEitherVertex(V3Graph* graphp) : V3GraphVertex{graphp} {} ~GateEitherVertex() override = default; @@ -811,8 +811,9 @@ class GateInline final { // If the consumer logic writes one of the variables that the substitution // is reading, then we would get a cycles, so we cannot do that. bool canInline = true; - for (V3GraphEdge* edgep = dstVtxp->outBeginp(); edgep; edgep = edgep->outNextp()) { - const GateVarVertex* const consVVertexp = edgep->top()->as(); + for (V3GraphEdge* dedgep = dstVtxp->outBeginp(); dedgep; + dedgep = dedgep->outNextp()) { + const GateVarVertex* const consVVertexp = dedgep->top()->as(); if (readVscps.count(consVVertexp->varScp())) { canInline = false; break; @@ -1327,7 +1328,7 @@ class GateUnused final { } } - GateUnused(GateGraph& graph) + explicit GateUnused(GateGraph& graph) : m_graph{graph} { mark(); // Mark all used vertices remove(); // Remove unused vertices diff --git a/src/V3Simulate.h b/src/V3Simulate.h index b9c4c80ab..42f1b4009 100644 --- a/src/V3Simulate.h +++ b/src/V3Simulate.h @@ -456,12 +456,12 @@ private: clearOptimizable(nodep, "Var write & read"); } m_varAux(vscp).usage |= VU_RV; - const bool isConst = (nodep->varp()->isConst() || nodep->varp()->isParam()) - && nodep->varp()->valuep(); + const bool varIsConst = (nodep->varp()->isConst() || nodep->varp()->isParam()) + && nodep->varp()->valuep(); AstNodeExpr* const valuep - = isConst ? fetchValueNull(nodep->varp()->valuep()) : nullptr; + = varIsConst ? fetchValueNull(nodep->varp()->valuep()) : nullptr; // Propagate PARAM constants for constant function analysis - if (isConst && valuep) { + if (varIsConst && valuep) { if (!m_checkOnly && optimizable()) newValue(vscp, valuep); } else { if (m_checkOnly) varRefCb(nodep); diff --git a/src/V3StackCount.cpp b/src/V3StackCount.cpp index f500b8602..19850cd27 100644 --- a/src/V3StackCount.cpp +++ b/src/V3StackCount.cpp @@ -58,7 +58,7 @@ class StackCountVisitor final : public VNVisitorConst { public: // CONSTRUCTORS - StackCountVisitor(AstNode* nodep) { iterateConstNull(nodep); } + explicit StackCountVisitor(AstNode* nodep) { iterateConstNull(nodep); } ~StackCountVisitor() override = default; // METHODS diff --git a/src/V3TraceDecl.cpp b/src/V3TraceDecl.cpp index 63302b5c2..088573c84 100644 --- a/src/V3TraceDecl.cpp +++ b/src/V3TraceDecl.cpp @@ -391,9 +391,8 @@ class TraceDeclVisitor final : public VNVisitor { } else { // This is a subscope: insert a placeholder to be fixed up later AstCell* const cellp = entry.cellp(); - FileLine* const flp = cellp->fileline(); - AstNodeStmt* const stmtp - = new AstComment{flp, "Cell init for: " + cellp->prettyName()}; + AstNodeStmt* const stmtp = new AstComment{ + cellp->fileline(), "Cell init for: " + cellp->prettyName()}; addToSubFunc(stmtp); m_cellInitPlaceholders.emplace_back(nodep, cellp, stmtp); } diff --git a/src/V3Width.cpp b/src/V3Width.cpp index d6cfaae8f..373233981 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -4411,10 +4411,8 @@ class WidthVisitor final : public VNVisitor { static bool usesDynamicScheduler(AstNode* nodep) { UASSERT_OBJ(nodep->dtypep()->isEvent(), nodep, "Node does not have an event dtype"); - - AstVarRef* vrefp; while (true) { - vrefp = VN_CAST(nodep, VarRef); + AstVarRef* const vrefp = VN_CAST(nodep, VarRef); if (vrefp) return usesDynamicScheduler(vrefp); if (VN_IS(nodep, MemberSel)) { return true;