From 609a5dc26d28b8448ae7efb635fd56031918f8d7 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 3 Feb 2020 23:21:56 -0500 Subject: [PATCH] Fix cppcheck warnings. No functional change intended. --- src/V3Ast.h | 4 ++-- src/V3AstNodes.cpp | 2 +- src/V3AstNodes.h | 15 ++++++++------- src/V3CUse.cpp | 6 +++--- src/V3Const.cpp | 2 +- src/V3EmitC.cpp | 10 +++++++--- src/V3EmitMk.cpp | 2 +- src/V3FileLine.cpp | 1 + src/V3FileLine.h | 2 +- src/V3Gate.cpp | 10 ++++++---- src/V3GraphDfa.cpp | 1 + src/V3GraphDfa.h | 2 +- src/V3GraphPathChecker.h | 4 ++-- src/V3GraphStream.h | 6 +++--- src/V3Inline.cpp | 6 +++--- src/V3LinkCells.cpp | 4 +--- src/V3LinkDot.cpp | 1 - src/V3Number.cpp | 4 ++-- src/V3Number.h | 2 +- src/V3Options.cpp | 20 +++++--------------- src/V3Param.cpp | 6 +++--- src/V3Partition.cpp | 2 +- src/V3Simulate.h | 4 ++-- src/V3Stats.cpp | 2 +- src/V3SymTable.h | 12 ++++++------ src/V3Task.cpp | 14 +++++++------- src/V3Trace.cpp | 4 +--- src/V3Unroll.cpp | 1 + src/V3Width.cpp | 20 ++++++++++---------- src/V3WidthSel.cpp | 4 ++-- src/VlcMain.cpp | 4 +--- src/cppcheck_filtered | 3 +++ src/verilog.y | 14 ++++++++------ 33 files changed, 96 insertions(+), 98 deletions(-) diff --git a/src/V3Ast.h b/src/V3Ast.h index 9aa0c6644..2f8c2857b 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -1024,14 +1024,14 @@ protected: clearcnt(id, cntGblRef, userBusyRef); // Includes a checkUse for us userBusyRef = false; } - static void clearcnt(int id, uint32_t& cntGblRef, bool& userBusyRef) { + static void clearcnt(int id, uint32_t& cntGblRef, const bool& userBusyRef) { UASSERT_STATIC(userBusyRef, "Clear of User"+cvtToStr(id)+"() not under AstUserInUse"); // If this really fires and is real (after 2^32 edits???) // we could just walk the tree and clear manually ++cntGblRef; UASSERT_STATIC(cntGblRef, "User*() overflowed!"); } - static void checkcnt(int id, uint32_t&, bool& userBusyRef) { + static void checkcnt(int id, uint32_t&, const bool& userBusyRef) { UASSERT_STATIC(userBusyRef, "Check of User"+cvtToStr(id)+"() failed, not under AstUserInUse"); } }; diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index 1ac50e7bf..835758651 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -630,7 +630,7 @@ std::pair AstNodeDType::dimensions(bool includeBasic) { else if (const AstBasicDType* adtypep = VN_CAST(dtypep, BasicDType)) { if (includeBasic && (adtypep->isRanged() || adtypep->isString())) packed++; } - else if (const AstStructDType* sdtypep = VN_CAST(dtypep, StructDType)) { + else if (VN_IS(dtypep, StructDType)) { packed++; } break; diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index 2661fdb22..dcba2822f 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -996,7 +996,7 @@ public: class AstVoidDType : public AstNodeDType { // For e.g. a function returning void public: - AstVoidDType(FileLine* fl) + explicit AstVoidDType(FileLine* fl) : ASTGEN_SUPER(fl) { dtypep(this); } ASTNODE_NODE_FUNCS(VoidDType) virtual void dumpSmall(std::ostream& str) const; @@ -2420,7 +2420,7 @@ public: class AstUnbounded : public AstNode { // A $ in the parser, used for unbounded and queues public: - AstUnbounded(FileLine* fl) + explicit AstUnbounded(FileLine* fl) : ASTGEN_SUPER(fl) {} ASTNODE_NODE_FUNCS(Unbounded) virtual string emitVerilog() { return "$"; } @@ -3616,7 +3616,7 @@ public: class AstReturn : public AstNodeStmt { public: - AstReturn(FileLine* fl, AstNode* lhsp = NULL) + explicit AstReturn(FileLine* fl, AstNode* lhsp = NULL) : ASTGEN_SUPER(fl) { setNOp1p(lhsp); } @@ -3917,7 +3917,7 @@ class AstNew : public AstNodeMath { // Parents: math|stmt // Children: varref|arraysel, math public: - AstNew(FileLine* fl) + explicit AstNew(FileLine* fl) : ASTGEN_SUPER(fl) { dtypep(NULL); // V3Width will resolve } @@ -6472,9 +6472,10 @@ class AstTextBlock : public AstNodeSimpleText { private: bool m_commas; // Comma separate emitted children public: - AstTextBlock(FileLine* fl, const string& textp="", bool tracking=false, - bool commas=false) - : ASTGEN_SUPER(fl, textp, tracking), m_commas(commas) {} + explicit AstTextBlock(FileLine* fl, const string& textp = "", bool tracking = false, + bool commas = false) + : ASTGEN_SUPER(fl, textp, tracking) + , m_commas(commas) {} ASTNODE_NODE_FUNCS(TextBlock) void commas(bool flag) { m_commas = flag; } bool commas() const { return m_commas; } diff --git a/src/V3CUse.cpp b/src/V3CUse.cpp index 72ed029ac..f13ed23d0 100644 --- a/src/V3CUse.cpp +++ b/src/V3CUse.cpp @@ -115,11 +115,11 @@ public: void V3CUse::cUseAll(AstNetlist* nodep) { UINFO(2, __FUNCTION__ << ": " << endl); // Call visitor separately for each module, so visitor state is cleared - for (AstNodeModule* nodep = v3Global.rootp()->modulesp(); nodep; - nodep = VN_CAST(nodep->nextp(), NodeModule)) { + for (AstNodeModule* modp = v3Global.rootp()->modulesp(); modp; + modp = VN_CAST(modp->nextp(), NodeModule)) { // Insert under this module; someday we should e.g. make Ast // for each output file and put under that - CUseVisitor visitor(nodep); + CUseVisitor visitor(modp); } V3Global::dumpCheckGlobalTree("cuse", 0, v3Global.opt.dumpTreeLevel(__FILE__) >= 3); } diff --git a/src/V3Const.cpp b/src/V3Const.cpp index 2ae16580a..5ba0db8a2 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -2087,7 +2087,7 @@ private: default: // Most operators, just move to next argument if (argp) { AstNode* nextp = argp->nextp(); - if (argp && VN_IS(argp, Const)) { // Convert it + if (VN_IS(argp, Const)) { // Convert it string out = VN_CAST(argp, Const)->num().displayed(nodep, fmt); UINFO(9," DispConst: "< "<rhsp()) { if (!gotOne) gotOne = true; @@ -1453,7 +1454,8 @@ class EmitCImp : EmitCStmts { puts(emitVarResetRecurse(varp, dtypep, 0, "")); } } - string emitVarResetRecurse(AstVar* varp, AstNodeDType* dtypep, int depth, string suffix) { + string emitVarResetRecurse(AstVar* varp, AstNodeDType* dtypep, int depth, + const string& suffix) { dtypep = dtypep->skipRefp(); AstBasicDType* basicp = dtypep->basicp(); // Returns string to do resetting, empty to do nothing (which caller should handle) @@ -2660,8 +2662,10 @@ void EmitCImp::emitInt(AstNodeModule* modp) { if (!did) { did = true; putsDecoration("// CELLS\n"); - if (modp->isTop()) puts("// Public to allow access to /*verilator_public*/ items;\n"); - if (modp->isTop()) puts("// otherwise the application code can consider these internals.\n"); + if (modp->isTop()) { + puts("// Public to allow access to /*verilator_public*/ items;\n"); + puts("// otherwise the application code can consider these internals.\n"); + } } puts(prefixNameProtect(cellp->modp()) + "* " + cellp->nameProtect() + ";\n"); } diff --git a/src/V3EmitMk.cpp b/src/V3EmitMk.cpp index ad7d91386..284e02bc4 100644 --- a/src/V3EmitMk.cpp +++ b/src/V3EmitMk.cpp @@ -189,7 +189,7 @@ public: string cppfile = *it; of.puts("\t"+V3Os::filenameNonExt(cppfile)+" \\\n"); string dir = V3Os::filenameDir(cppfile); - if (dirs.find(dir) == dirs.end()) dirs.insert(dir); + dirs.insert(dir); } of.puts("\n"); diff --git a/src/V3FileLine.cpp b/src/V3FileLine.cpp index d27440602..7dad8ea66 100644 --- a/src/V3FileLine.cpp +++ b/src/V3FileLine.cpp @@ -120,6 +120,7 @@ void VFileContent::pushText(const string& text) { string VFileContent::getLine(int lineno) const { // Return error text rather than asserting so the user isn't left without a message + // cppcheck-suppress negativeContainerIndex if (VL_UNCOVERABLE(lineno < 0 || lineno >= (int)m_lines.size())) { if (debug() || v3Global.opt.debugCheck()) { return ("%Error-internal-contents-bad-ct"+cvtToStr(m_id) diff --git a/src/V3FileLine.h b/src/V3FileLine.h index 44ccb7ab9..dc9643d26 100644 --- a/src/V3FileLine.h +++ b/src/V3FileLine.h @@ -119,7 +119,7 @@ private: return *defFilelinep; } public: - FileLine(const string& filename) { + explicit FileLine(const string& filename) { m_lastLineno = m_firstLineno = 0; m_lastColumn = m_firstColumn = 0; m_filenameno = singleton().nameToNumber(filename); diff --git a/src/V3Gate.cpp b/src/V3Gate.cpp index f4db76775..7ecacc26a 100644 --- a/src/V3Gate.cpp +++ b/src/V3Gate.cpp @@ -453,9 +453,11 @@ private: UASSERT_OBJ(varscp, nodep, "Var didn't get varscoped in V3Scope.cpp"); GateVarVertex* vvertexp = makeVarVertex(varscp); UINFO(5," VARREF to "<setIsClock(); - // For SYNCASYNCNET - if (m_inSenItem) varscp->user2(true); + if (m_inSenItem) { + vvertexp->setIsClock(); + // For SYNCASYNCNET + varscp->user2(true); + } else if (m_activep && m_activep->hasClocked() && !nodep->lvalue()) { if (varscp->user2()) { if (!vvertexp->rstAsyncNodep()) vvertexp->rstAsyncNodep(nodep); @@ -712,7 +714,7 @@ bool GateVisitor::elimLogicOkOutputs(GateLogicVertex* consumeVertexp, for (GateVarRefList::const_iterator it = rhsVarRefs.begin(); it != rhsVarRefs.end(); ++it) { AstVarScope* vscp = (*it)->varScopep(); - if (varscopes.find(vscp) == varscopes.end()) varscopes.insert(vscp); + varscopes.insert(vscp); } for (V3GraphEdge* edgep = consumeVertexp->outBeginp(); edgep; edgep = edgep->outNextp()) { GateVarVertex* consVVertexp = dynamic_cast(edgep->top()); diff --git a/src/V3GraphDfa.cpp b/src/V3GraphDfa.cpp index 1716f8657..81af99039 100644 --- a/src/V3GraphDfa.cpp +++ b/src/V3GraphDfa.cpp @@ -599,6 +599,7 @@ public: if (debug()>=6) m_graphp->dumpDotFilePrefixed("comp_out"); } ~DfaGraphComplement() {} + VL_UNCOPYABLE(DfaGraphComplement); }; void DfaGraph::dfaComplement() { diff --git a/src/V3GraphDfa.h b/src/V3GraphDfa.h index 21009ef57..193279631 100644 --- a/src/V3GraphDfa.h +++ b/src/V3GraphDfa.h @@ -89,7 +89,7 @@ class DfaVertex : public V3GraphVertex { bool m_accepting; // Accepting state? public: // CONSTRUCTORS - DfaVertex(DfaGraph* graphp, bool start=false, bool accepting=false) + explicit DfaVertex(DfaGraph* graphp, bool start=false, bool accepting=false) : V3GraphVertex(graphp) , m_start(start), m_accepting(accepting) {} using V3GraphVertex::clone; // We are overriding, not overloading clone(V3Graph*) diff --git a/src/V3GraphPathChecker.h b/src/V3GraphPathChecker.h index 2d248363b..7b6024eee 100644 --- a/src/V3GraphPathChecker.h +++ b/src/V3GraphPathChecker.h @@ -42,8 +42,8 @@ class GraphPathChecker : GraphAlg { public: // CONSTRUCTORS - GraphPathChecker(const V3Graph* graphp, - V3EdgeFuncP edgeFuncp = V3GraphEdge::followAlwaysTrue); + explicit GraphPathChecker(const V3Graph* graphp, + V3EdgeFuncP edgeFuncp = V3GraphEdge::followAlwaysTrue); ~GraphPathChecker(); // METHODS diff --git a/src/V3GraphStream.h b/src/V3GraphStream.h index a1bd9a1bb..b949b0418 100644 --- a/src/V3GraphStream.h +++ b/src/V3GraphStream.h @@ -95,9 +95,9 @@ private: public: // CONSTRUCTORS - GraphStream(const V3Graph* graphp, - GraphWay way = GraphWay::FORWARD, - const T_Compare& lessThan = T_Compare()) + explicit GraphStream(const V3Graph* graphp, + GraphWay way = GraphWay::FORWARD, + const T_Compare& lessThan = T_Compare()) // NOTE: Perhaps REVERSE way should also reverse the sense of the // lessThan function? For now the only usage of REVERSE is not // sensitive to its lessThan at all, so it doesn't matter. diff --git a/src/V3Inline.cpp b/src/V3Inline.cpp index 68843c59c..dd32eda44 100644 --- a/src/V3Inline.cpp +++ b/src/V3Inline.cpp @@ -178,10 +178,10 @@ private: // update user4 (statement count) to reflect that: int statements = modp->user4(); LocalInstanceMap& localsr = m_instances[modp]; - for (LocalInstanceMap::iterator it = localsr.begin(); it != localsr.end(); ++it) { - AstNodeModule* childp = it->first; + for (LocalInstanceMap::iterator iti = localsr.begin(); iti != localsr.end(); ++iti) { + AstNodeModule* childp = iti->first; if (childp->user1()) { // inlining child - statements += (childp->user4() * it->second); + statements += (childp->user4() * iti->second); } } modp->user4(statements); diff --git a/src/V3LinkCells.cpp b/src/V3LinkCells.cpp index 1a49d5855..8e4ea4b29 100644 --- a/src/V3LinkCells.cpp +++ b/src/V3LinkCells.cpp @@ -385,9 +385,7 @@ private: <prettyNameQ()); } } - if (ports.find(pinp->name()) == ports.end()) { - ports.insert(pinp->name()); - } + ports.insert(pinp->name()); } // We search ports, rather than in/out declarations as they aren't resolved yet, // and it's easier to do it now than in V3LinkDot when we'd need to repeat steps. diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 30d88d6a8..0d08eea34 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -2241,7 +2241,6 @@ private: } } } else { - string baddot; VSymEnt* foundp = m_statep->findSymPrefixed(dotSymp, nodep->name(), baddot); AstVarScope* vscp = foundp ? VN_CAST(foundp->nodep(), VarScope) : NULL; if (!vscp) { diff --git a/src/V3Number.cpp b/src/V3Number.cpp index 00a043c68..b5900bc51 100644 --- a/src/V3Number.cpp +++ b/src/V3Number.cpp @@ -1540,8 +1540,8 @@ V3Number& V3Number::opShiftRS(const V3Number& lhs, const V3Number& rhs, uint32_t if (rhs.isFourState()) return setAllBitsX(); setZero(); for (int bit=32; bitwidth(); bit++) { - setBit(bit, lhs.bitIs(lbits-1)); // 0/1/X/Z + for (int sbit = 0; sbit < this->width(); sbit++) { + setBit(sbit, lhs.bitIs(lbits - 1)); // 0/1/X/Z } if (rhs.bitIs1(lbits-1)) setAllBits1(); // -1 else 0 return *this; // shift of over 2^32 must be -1/0 diff --git a/src/V3Number.h b/src/V3Number.h index 73a2f4907..a53e886ca 100644 --- a/src/V3Number.h +++ b/src/V3Number.h @@ -151,7 +151,7 @@ public: V3Number(VerilogStringLiteral, AstNode* nodep, const string& str); class String {}; V3Number(String, AstNode* nodep, const string& value) { init(nodep, 0); setString(value); } - V3Number(const V3Number* nump, int width = 1) { + explicit V3Number(const V3Number* nump, int width = 1) { init(NULL, width); m_fileline = nump->fileline(); } diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 7b3cc7735..eb56d87b2 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -182,9 +182,7 @@ void V3Options::checkParameters() { } void V3Options::addCppFile(const string& filename) { - if (m_cppFiles.find(filename) == m_cppFiles.end()) { - m_cppFiles.insert(filename); - } + m_cppFiles.insert(filename); } void V3Options::addCFlags(const string& filename) { m_cFlags.push_back(filename); @@ -193,9 +191,7 @@ void V3Options::addLdLibs(const string& filename) { m_ldLibs.push_back(filename); } void V3Options::addFuture(const string& flag) { - if (m_futures.find(flag) == m_futures.end()) { - m_futures.insert(flag); - } + m_futures.insert(flag); } bool V3Options::isFuture(const string& flag) const { return m_futures.find(flag) != m_futures.end(); @@ -204,25 +200,19 @@ bool V3Options::isLibraryFile(const string& filename) const { return m_libraryFiles.find(filename) != m_libraryFiles.end(); } void V3Options::addLibraryFile(const string& filename) { - if (m_libraryFiles.find(filename) == m_libraryFiles.end()) { - m_libraryFiles.insert(filename); - } + m_libraryFiles.insert(filename); } bool V3Options::isClocker(const string& signame) const { return m_clockers.find(signame) != m_clockers.end(); } void V3Options::addClocker(const string& signame) { - if (m_clockers.find(signame) == m_clockers.end()) { - m_clockers.insert(signame); - } + m_clockers.insert(signame); } bool V3Options::isNoClocker(const string& signame) const { return m_noClockers.find(signame) != m_noClockers.end(); } void V3Options::addNoClocker(const string& signame) { - if (m_noClockers.find(signame) == m_noClockers.end()) { - m_noClockers.insert(signame); - } + m_noClockers.insert(signame); } void V3Options::addVFile(const string& filename) { // We use a list for v files, because it's legal to have includes diff --git a/src/V3Param.cpp b/src/V3Param.cpp index 7aee4f784..583752b9a 100644 --- a/src/V3Param.cpp +++ b/src/V3Param.cpp @@ -228,9 +228,9 @@ private: // Hitting a cell adds to the appropriate level of this level-sorted list, // so since cells originally exist top->bottom we process in top->bottom order too. while (!m_todoModps.empty()) { - LevelModMap::iterator it = m_todoModps.begin(); - AstNodeModule* nodep = it->second; - m_todoModps.erase(it); + LevelModMap::iterator itm = m_todoModps.begin(); + AstNodeModule* nodep = itm->second; + m_todoModps.erase(itm); if (!nodep->user5SetOnce()) { // Process once; note clone() must clear so we do it again m_modp = nodep; UINFO(4," MOD "<num().displayed(nodep, format); + string pformat = string("%") + pos[0]; + result += constp->num().displayed(nodep, pformat); } else { switch (tolower(pos[0])) { case '%': result += "%"; break; diff --git a/src/V3Stats.cpp b/src/V3Stats.cpp index 064ed353f..27562f72f 100644 --- a/src/V3Stats.cpp +++ b/src/V3Stats.cpp @@ -204,7 +204,7 @@ private: if (m_fast && nodep->evalp()) { m_instrs = 0; m_counting = true; - if (nodep->evalp()) iterateChildrenConst(nodep->evalp()); + iterateChildrenConst(nodep->evalp()); m_counting = false; } allNodes(nodep); diff --git a/src/V3SymTable.h b/src/V3SymTable.h index da7185397..b0a504caa 100644 --- a/src/V3SymTable.h +++ b/src/V3SymTable.h @@ -163,9 +163,9 @@ public: // Suggest alternative symbol candidates without looking upward through symbol hierarchy for (IdNameMap::const_iterator it = m_idNameMap.begin(); it != m_idNameMap.end(); ++it) { - const AstNode* nodep = it->second->nodep(); - if (nodep && (!matcherp || matcherp->nodeMatch(nodep))) { - spellerp->pushCandidate(nodep->prettyName()); + const AstNode* itemp = it->second->nodep(); + if (itemp && (!matcherp || matcherp->nodeMatch(itemp))) { + spellerp->pushCandidate(itemp->prettyName()); } } } @@ -249,9 +249,9 @@ public: if (prettyName=="") prettyName = lookp->prettyName(); string scopes; for (IdNameMap::iterator it = m_idNameMap.begin(); it!=m_idNameMap.end(); ++it) { - AstNode* nodep = it->second->nodep(); - if (VN_IS(nodep, Cell) - || (VN_IS(nodep, Module) && VN_CAST(nodep, Module)->isTop())) { + AstNode* itemp = it->second->nodep(); + if (VN_IS(itemp, Cell) + || (VN_IS(itemp, Module) && VN_CAST(itemp, Module)->isTop())) { if (scopes != "") scopes += ", "; scopes += AstNode::prettyName(it->first); } diff --git a/src/V3Task.cpp b/src/V3Task.cpp index 72cb3c9e4..ac9d669c2 100644 --- a/src/V3Task.cpp +++ b/src/V3Task.cpp @@ -415,12 +415,12 @@ private: // Even if it's referencing a varref, we still make a temporary // Else task(x,x,x) might produce incorrect results - AstVarScope* outvscp + AstVarScope* tempvscp = createVarScope(portp, namePrefix+"__"+portp->shortName()); - portp->user2p(outvscp); - AstAssign* assp = new AstAssign(pinp->fileline(), - pinp, - new AstVarRef(outvscp->fileline(), outvscp, false)); + portp->user2p(tempvscp); + AstAssign* assp + = new AstAssign(pinp->fileline(), pinp, + new AstVarRef(tempvscp->fileline(), tempvscp, false)); assp->fileline()->modifyWarnOff(V3ErrorCode::BLKSEQ, true); // Ok if in <= block // Put assignment BEHIND of all other statements beginp->addNext(assp); @@ -469,7 +469,7 @@ private: // Iteration requires a back, so put under temporary node { AstBegin* tempp = new AstBegin(beginp->fileline(), "[EditWrapper]", beginp); - TaskRelinkVisitor visit (tempp); + TaskRelinkVisitor visitor(tempp); tempp->stmtsp()->unlinkFrBackWithNext(); VL_DO_DANGLING(tempp->deleteTree(), tempp); } @@ -1073,7 +1073,7 @@ private: // Iteration requires a back, so put under temporary node { AstBegin* tempp = new AstBegin(cfuncp->fileline(), "[EditWrapper]", cfuncp); - TaskRelinkVisitor visit (tempp); + TaskRelinkVisitor visitor(tempp); tempp->stmtsp()->unlinkFrBackWithNext(); VL_DO_DANGLING(tempp->deleteTree(), tempp); } diff --git a/src/V3Trace.cpp b/src/V3Trace.cpp index 864010e45..aa6f67756 100644 --- a/src/V3Trace.cpp +++ b/src/V3Trace.cpp @@ -449,9 +449,7 @@ private: break; } else { uint32_t acode = cfvertexp->activityCode(); - if (actset.find(acode) == actset.end()) { - actset.insert(acode); - } + actset.insert(acode); } } // If a trace doesn't have activity, it's constant, and we diff --git a/src/V3Unroll.cpp b/src/V3Unroll.cpp index 25408ef5b..73e8c5dd6 100644 --- a/src/V3Unroll.cpp +++ b/src/V3Unroll.cpp @@ -388,6 +388,7 @@ private: // Grab assignment AstNode* incp = NULL; // Should be last statement if (nodep->incsp()) V3Const::constifyEdit(nodep->incsp()); + // cppcheck-suppress duplicateCondition if (nodep->incsp()) incp = nodep->incsp(); else { for (incp = nodep->bodysp(); incp && incp->nextp(); incp = incp->nextp()) {} diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 8c18da24c..512bb9676 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -1138,9 +1138,9 @@ private: default: nodep->v3error("Unhandled attribute type"); } } else { - std::pair dim + std::pair dimp = nodep->fromp()->dtypep()->skipRefp()->dimensions(true); - uint32_t msbdim = dim.first + dim.second; + uint32_t msbdim = dimp.first + dimp.second; if (!nodep->dimp() || msbdim < 1) { int dim = 1; AstConst* newp = dimensionValue(nodep->fileline(), nodep->fromp()->dtypep(), @@ -2291,7 +2291,6 @@ private: userIterateChildren(nodep, WidthVP(SELF, BOTH).p()); AstClassRefDType* refp = VN_CAST(m_vup->dtypeNullp(), ClassRefDType); if (!refp) { // e.g. int a = new; - if (refp) UINFO(1, "Got refp "<v3error("new() not expected in this context"); return; } @@ -2454,9 +2453,9 @@ private: if (VN_IS(valuep, Const)) { // Forming a AstConcat will cause problems with // unsized (uncommitted sized) constants - if (AstNode* newp = WidthCommitVisitor::newIfConstCommitSize(VN_CAST(valuep, Const))) { + if (AstNode* newccp = WidthCommitVisitor::newIfConstCommitSize(VN_CAST(valuep, Const))) { VL_DO_DANGLING(pushDeletep(valuep), valuep); - valuep = newp; + valuep = newccp; } } if (!newp) newp = valuep; @@ -2574,9 +2573,10 @@ private: if (VN_IS(valuep, Const)) { // Forming a AstConcat will cause problems with // unsized (uncommitted sized) constants - if (AstNode* newp = WidthCommitVisitor::newIfConstCommitSize(VN_CAST(valuep, Const))) { + if (AstNode* newccp + = WidthCommitVisitor::newIfConstCommitSize(VN_CAST(valuep, Const))) { VL_DO_DANGLING(pushDeletep(valuep), valuep); - valuep = newp; + valuep = newccp; } } { // Packed. Convert to concat for now. @@ -3675,9 +3675,9 @@ private: if (shiftp && shiftp->num().mostSetBitP1() <= 32) { // If (number)<<96'h1, then make it into (number)<<32'h1 V3Number num (shiftp, 32, 0); num.opAssign(shiftp->num()); - AstNode* shiftp = nodep->rhsp(); - nodep->rhsp()->replaceWith(new AstConst(shiftp->fileline(), num)); - VL_DO_DANGLING(shiftp->deleteTree(), shiftp); + AstNode* shiftrhsp = nodep->rhsp(); + nodep->rhsp()->replaceWith(new AstConst(shiftrhsp->fileline(), num)); + VL_DO_DANGLING(shiftrhsp->deleteTree(), shiftrhsp); } } } diff --git a/src/V3WidthSel.cpp b/src/V3WidthSel.cpp index d6e866185..ae3e4946d 100644 --- a/src/V3WidthSel.cpp +++ b/src/V3WidthSel.cpp @@ -91,9 +91,9 @@ private: if (const AstNodeArrayDType* adtypep = VN_CAST(ddtypep, NodeArrayDType)) { fromRange = adtypep->declRange(); } - else if (const AstAssocArrayDType* adtypep = VN_CAST(ddtypep, AssocArrayDType)) { + else if (VN_IS(ddtypep, AssocArrayDType)) { } - else if (const AstQueueDType* adtypep = VN_CAST(ddtypep, QueueDType)) { + else if (VN_IS(ddtypep, QueueDType)) { } else if (const AstNodeUOrStructDType* adtypep = VN_CAST(ddtypep, NodeUOrStructDType)) { fromRange = adtypep->declRange(); diff --git a/src/VlcMain.cpp b/src/VlcMain.cpp index aa1247fa2..99e018446 100644 --- a/src/VlcMain.cpp +++ b/src/VlcMain.cpp @@ -42,9 +42,7 @@ // VlcOptions void VlcOptions::addReadFile(const string& filename) { - if (m_readFiles.find(filename) == m_readFiles.end()) { - m_readFiles.insert(filename); - } + m_readFiles.insert(filename); } string VlcOptions::version() { diff --git a/src/cppcheck_filtered b/src/cppcheck_filtered index 6bc699092..1f962ea58 100755 --- a/src/cppcheck_filtered +++ b/src/cppcheck_filtered @@ -137,6 +137,9 @@ sub _suppress { return undef if $filename eq "*"; + # Cleanup for e.g. ../V3AstNodes.h + $filename = "src/$1" if $filename =~ m!^\.\./(.*)!; + # Specific suppressions return 1 if $id eq "missingInclude" && $filename =~ m!systemc.h!; return 1 if $id eq "missingInclude" && $filename =~ m!svdpi.h!; diff --git a/src/verilog.y b/src/verilog.y index 7052e8e17..9427d1b8d 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -114,12 +114,14 @@ public: if (!rangep) return exprp; else return new AstGatePin(rangep->fileline(), exprp, rangep->cloneTree(true)); } - void endLabel(FileLine* fl, AstNode* nodep, string* endnamep) { endLabel(fl, nodep->prettyName(), endnamep); } - void endLabel(FileLine* fl, string name, string* endnamep) { - if (fl && endnamep && *endnamep != "" && name != *endnamep - && name != AstNode::prettyName(*endnamep)) { - fl->v3warn(ENDLABEL,"End label '"<<*endnamep<<"' does not match begin label '"<prettyName(), endnamep); + } + void endLabel(FileLine* fl, const string& name, string* endnamep) { + if (fl && endnamep && *endnamep != "" && name != *endnamep + && name != AstNode::prettyName(*endnamep)) { + fl->v3warn(ENDLABEL,"End label '"<<*endnamep<<"' does not match begin label '"<