From 8323092a0cf7ed75b9019ad1a9d1dd2a6d8257a9 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 9 Feb 2015 21:05:27 -0500 Subject: [PATCH] Fix cppcheck warnings. No functional change. --- Makefile.in | 3 ++- include/verilated.cpp | 1 - include/verilated.h | 4 ++++ include/verilated_cov.cpp | 5 ++++- include/verilated_dpi.cpp | 2 +- include/verilated_vcd_c.cpp | 4 +--- include/verilated_vcd_c.h | 2 +- include/verilated_vpi.h | 1 + include/vltstd/svdpi.h | 4 ++-- src/V3Assert.cpp | 15 --------------- src/V3AstNodes.cpp | 1 - src/V3Case.cpp | 2 ++ src/V3Clock.cpp | 12 ------------ src/V3EmitC.cpp | 3 +-- src/V3EmitCSyms.cpp | 1 + src/V3GraphAcyc.cpp | 4 +++- src/V3GraphDfa.cpp | 2 +- src/V3Life.cpp | 4 ++-- src/V3LinkDot.cpp | 2 +- src/V3Options.cpp | 13 ++++++++++--- src/V3Param.cpp | 1 + src/V3ParseImp.h | 1 + src/V3PreProc.cpp | 1 - src/V3Simulate.h | 1 + src/V3Split.cpp | 2 +- src/V3Task.cpp | 4 +--- src/V3Tristate.cpp | 3 +-- src/V3Unknown.cpp | 2 +- src/V3Width.cpp | 7 +------ src/cppcheck_filtered | 16 +++++++++++++++- 30 files changed, 60 insertions(+), 63 deletions(-) diff --git a/Makefile.in b/Makefile.in index c2b9064df..890c683fe 100644 --- a/Makefile.in +++ b/Makefile.in @@ -406,7 +406,8 @@ endif # Use --xml flag to see the cppcheck code to use for suppression CPPCHECK = src/cppcheck_filtered -CPPCHECK_FLAGS = --enable=all --inline-suppr --suppress=unusedScopedObject --suppress=cstyleCast +CPPCHECK_FLAGS = --enable=all --inline-suppr \ + --suppress=unusedScopedObject --suppress=cstyleCast --suppress=useInitializationList CPPCHECK_FLAGS += --xml CPPCHECK_CPP = $(wildcard $(srcdir)/include/*.cpp $(srcdir)/src/*.cpp) CPPCHECK_DEP = $(subst .cpp,.cppcheck,$(CPPCHECK_CPP)) diff --git a/include/verilated.cpp b/include/verilated.cpp index 7dc0f4d8c..4129d1527 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -487,7 +487,6 @@ static inline int _vl_vsss_peek(FILE* fp, int& floc, WDataInP fromp, const stri if (floc < 0) return EOF; floc = floc & ~7; // Align to closest character if (fromp == NULL) { - int c = fstr[fstr.length()-1 - (floc>>3)]; return fstr[fstr.length()-1 - (floc>>3)]; } else { return (fromp[VL_BITWORD_I(floc)] >> VL_BITBIT_I(floc)) & 0xff; diff --git a/include/verilated.h b/include/verilated.h index ea12aa545..b531e7d58 100644 --- a/include/verilated.h +++ b/include/verilated.h @@ -1132,7 +1132,9 @@ static inline WDataOutP VL_DIVS_WWW(int lbits, WDataOutP owp,WDataInP lwp,WDataI int words = VL_WORDS_I(lbits); IData lsign = VL_SIGN_I(lbits,lwp[words-1]); IData rsign = VL_SIGN_I(lbits,rwp[words-1]); + // cppcheck-suppress variableScope IData lwstore[VL_MULS_MAX_WORDS]; // Fixed size, as MSVC++ doesn't allow [words] here + // cppcheck-suppress variableScope IData rwstore[VL_MULS_MAX_WORDS]; WDataInP ltup = lwp; WDataInP rtup = rwp; @@ -1151,7 +1153,9 @@ static inline WDataOutP VL_MODDIVS_WWW(int lbits, WDataOutP owp,WDataInP lwp,WDa int words = VL_WORDS_I(lbits); IData lsign = VL_SIGN_I(lbits,lwp[words-1]); IData rsign = VL_SIGN_I(lbits,rwp[words-1]); + // cppcheck-suppress variableScope IData lwstore[VL_MULS_MAX_WORDS]; // Fixed size, as MSVC++ doesn't allow [words] here + // cppcheck-suppress variableScope IData rwstore[VL_MULS_MAX_WORDS]; WDataInP ltup = lwp; WDataInP rtup = rwp; diff --git a/include/verilated_cov.cpp b/include/verilated_cov.cpp index f2d9bc027..f9f11f7ef 100644 --- a/include/verilated_cov.cpp +++ b/include/verilated_cov.cpp @@ -52,7 +52,10 @@ public: // But only local to this file // CONSTRUCTORS // Derived classes should call zero() in their constructor VerilatedCovImpItem() { - for (int i=0; ifileline(), - // If assertions are off, have constant propagation rip them out later - // This allows syntax errors and such to be detected normally. - (v3Global.opt.coverage() - ? (AstNode*)(new AstConst(nodep->fileline(), AstConst::LogicTrue())) - : (AstNode*)(new AstConst(nodep->fileline(), AstConst::LogicFalse()))), - nodep, NULL); - newp->user1(true); // Don't assert/cover this if - return newp; - } - AstNode* newFireAssert(AstNode* nodep, const string& message) { AstDisplay* dispp = new AstDisplay (nodep->fileline(), AstDisplayType::DT_ERROR, message, NULL, NULL); AstNode* bodysp = dispp; diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index e747b51a5..751540893 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -918,7 +918,6 @@ void AstTypeTable::dump(ostream& str) { for (DetailedMap::const_iterator it = mapr.begin(); it != mapr.end(); ++it) { AstBasicDType* dtypep = it->second; str< "; dtypep->dump(str); } diff --git a/src/V3Case.cpp b/src/V3Case.cpp index c4f2451f3..badf50b29 100644 --- a/src/V3Case.cpp +++ b/src/V3Case.cpp @@ -411,6 +411,7 @@ private: AstNode* itemexprp = ifexprp; ifexprp=NULL; if (depth == (CASE_ENCODER_GROUP_DEPTH)) { // End of group - can skip the condition itemexprp->deleteTree(); itemexprp=NULL; + // cppcheck-suppress redundantAssignment itemexprp = new AstConst(itemp->fileline(), AstConst::LogicTrue()); } AstIf* newp = new AstIf(itemp->fileline(), itemexprp, istmtsp, NULL); @@ -462,6 +463,7 @@ private: replaceCaseFast(nodep); nodep=NULL; } else { ++m_statCaseSlow; + // cppcheck-supporess uselessAssignmentPtrArg replaceCaseComplicated(nodep); nodep=NULL; } } diff --git a/src/V3Clock.cpp b/src/V3Clock.cpp index 2b51aec3f..c62267160 100644 --- a/src/V3Clock.cpp +++ b/src/V3Clock.cpp @@ -99,18 +99,6 @@ private: UINFO(4,"New Last: "<addStmtp(newvarp); - AstVarScope* newvscp = new AstVarScope(fl, m_scopep, newvarp); - m_scopep->addVarp(newvscp); - return newvscp; - } AstNode* createSenItemEquation(AstSenItem* nodep) { // We know the var is clean, and one bit, so we use binary ops // for speed instead of logical ops. diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index 54e805e6d..c2e5d62bb 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -737,7 +737,6 @@ class EmitCImp : EmitCStmts { // METHODS void doubleOrDetect(AstChangeDet* changep, bool& gotOne) { - static int addDoubleOr = 10; // Determined experimentally as best if (!changep->rhsp()) { if (!gotOne) gotOne = true; else puts(" | "); @@ -746,6 +745,7 @@ class EmitCImp : EmitCStmts { else { AstNode* lhsp = changep->lhsp(); AstNode* rhsp = changep->rhsp(); + static int addDoubleOr = 10; // Determined experimentally as best if (!lhsp->castVarRef() && !lhsp->castArraySel()) changep->v3fatalSrc("Not ref?"); if (!rhsp->castVarRef() && !rhsp->castArraySel()) changep->v3fatalSrc("Not ref?"); for (int word=0; wordlhsp()->widthWords(); word++) { @@ -2103,7 +2103,6 @@ void EmitCImp::main(AstNodeModule* modp, bool slow, bool fast) { m_modp = modp; m_slow = slow; m_fast = fast; - string filenameNoExt = v3Global.opt.makeDir()+"/"+ modClassName(modp)+(m_fast ? "" : "__Slow"); if (debug()>=5) { UINFO(0," Emitting "<dpiImport() != rhsp->dpiImport()) { + // cppcheck-suppress comparisonOfFuncReturningBoolError return lhsp->dpiImport() < rhsp->dpiImport(); } return lhsp->name() < rhsp->name(); diff --git a/src/V3GraphAcyc.cpp b/src/V3GraphAcyc.cpp index 37148fd79..504f4f09f 100644 --- a/src/V3GraphAcyc.cpp +++ b/src/V3GraphAcyc.cpp @@ -47,7 +47,8 @@ protected: public: GraphAcycVertex(V3Graph* graphp, V3GraphVertex* origVertexp) - : V3GraphVertex(graphp), m_origVertexp(origVertexp), m_onWorkList(false), m_deleted(false) { + : V3GraphVertex(graphp), m_origVertexp(origVertexp) + , m_storedRank(0), m_onWorkList(false), m_deleted(false) { } virtual ~GraphAcycVertex() {} V3GraphVertex* origVertexp() const { return m_origVertexp; } @@ -185,6 +186,7 @@ public: GraphAcyc(V3Graph* origGraphp, V3EdgeFuncP edgeFuncp) { m_origGraphp = origGraphp; m_origEdgeFuncp = edgeFuncp; + m_placeStep = 0; } ~GraphAcyc() { for (vector::iterator it = m_origEdgeDelp.begin(); it != m_origEdgeDelp.end(); ++it) { diff --git a/src/V3GraphDfa.cpp b/src/V3GraphDfa.cpp index 4af608449..23c967179 100644 --- a/src/V3GraphDfa.cpp +++ b/src/V3GraphDfa.cpp @@ -74,7 +74,7 @@ private: // METHODS DfaGraph* graphp() { return static_cast(m_graphp); } bool nfaState(V3GraphVertex* vertexp) { return vertexp->color()==0; } - bool dfaState(V3GraphVertex* vertexp) { return vertexp->color()==1; } + //bool dfaState(V3GraphVertex* vertexp) { return vertexp->color()==1; } void nextStep() { m_step++; } diff --git a/src/V3Life.cpp b/src/V3Life.cpp index 7f1bab18e..10c2afe68 100644 --- a/src/V3Life.cpp +++ b/src/V3Life.cpp @@ -163,7 +163,7 @@ public: if (debug()>4) oldassp->dumpTree(cout, " REMOVE/SAMEBLK "); entp->complexAssign(); m_statep->pushUnlinkDeletep(oldassp); oldassp=NULL; - m_statep->m_statAssnDel++; + ++m_statep->m_statAssnDel; } } } @@ -200,7 +200,7 @@ public: UINFO(4," replaceconst: "<replaceWith(constp->cloneTree(false)); varrefp->deleteTree(); varrefp=NULL; - m_statep->m_statAssnCon++; + ++m_statep->m_statAssnCon; return; // **DONE, no longer a var reference** } } diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 4280e9c15..9a5d9732a 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -1558,9 +1558,9 @@ private: string expectWhat; bool allowScope = false; bool allowVar = false; - AstPackage* packagep = NULL; if (m_ds.m_dotPos == DP_PACKAGE) { // {package}::{a} + AstPackage* packagep = NULL; expectWhat = "scope/variable"; allowScope = true; allowVar = true; diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 39b081397..8e6be3c7e 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -587,7 +587,7 @@ string V3Options::getenvVERILATOR_ROOT() { string var = getenvStr("VERILATOR_ROOT",""); if (var == "" && string(DEFENV_VERILATOR_ROOT) != "") { var = DEFENV_VERILATOR_ROOT; - setenvStr("VERILATOR_ROOT", var.c_str(), "Hardcoded at build time"); + setenvStr("VERILATOR_ROOT", var, "Hardcoded at build time"); } if (var == "") { v3fatal("$VERILATOR_ROOT needs to be in environment\n"); @@ -1074,7 +1074,6 @@ void V3Options::parseOptsFile(FileLine* fl, const string& filename, bool rel) { } string whole_file; - string::size_type pos; bool inCmt = false; while (!ifp->eof()) { string line; @@ -1107,7 +1106,7 @@ void V3Options::parseOptsFile(FileLine* fl, const string& filename, bool rel) { // Split into argument list and process // Note we don't respect quotes. It seems most simulators dont. // Woez those that expect it; we'll at least complain. - if ((pos=whole_file.find("\"")) != string::npos) { + if (whole_file.find("\"") != string::npos) { fl->v3error("Double quotes in -f files cause unspecified behavior."); } @@ -1207,7 +1206,11 @@ void V3Options::showVersion(bool verbose) { V3Options::V3Options() { m_impp = new V3OptionsImp; + m_assert = false; m_autoflush = false; + m_bboxSys = false; + m_bboxUnsup = false; + m_cdc = false; m_coverageLine = false; m_coverageToggle = false; m_coverageUnderscore = false; @@ -1215,6 +1218,7 @@ V3Options::V3Options() { m_debugCheck = false; m_exe = false; m_ignc = false; + m_inhibitSim = false; m_l2Name = true; m_lintOnly = false; m_makeDepend = true; @@ -1222,6 +1226,9 @@ V3Options::V3Options() { m_orderClockDly = true; m_outFormatOk = false; m_pinsBv = 65; + m_pinsScUint = false; + m_pinsScBigUint = false; + m_pinsUint8 = false; m_profileCFuncs = false; m_preprocOnly = false; m_preprocNoLine = false; diff --git a/src/V3Param.cpp b/src/V3Param.cpp index 6089b09a0..925804e45 100644 --- a/src/V3Param.cpp +++ b/src/V3Param.cpp @@ -340,6 +340,7 @@ private: AstNode* nextp = ep->nextp(); //May edit list ep->iterateAndNext(*this); V3Const::constifyParamsEdit(ep); ep=NULL; // ep may change + // cppcheck-suppress redundantAssignment ep = nextp; } } diff --git a/src/V3ParseImp.h b/src/V3ParseImp.h index 3602bc695..4d24c7acc 100644 --- a/src/V3ParseImp.h +++ b/src/V3ParseImp.h @@ -211,6 +211,7 @@ public: m_prevLexToken = 0; m_ahead = false; m_aheadToken = 0; + // m_aheadVal not used as m_ahead = false } ~V3ParseImp(); void parserClear(); diff --git a/src/V3PreProc.cpp b/src/V3PreProc.cpp index 8fb02d0de..880b2eee7 100644 --- a/src/V3PreProc.cpp +++ b/src/V3PreProc.cpp @@ -623,7 +623,6 @@ string V3PreProcImp::defineSubst(V3DefineRef* refp) { string out = ""; { // Parse substitution define using arguments string argName; - string prev; bool quote = false; bool backslashesc = false; // In \.....{space} block // Note we go through the loop once more at the NULL end-of-string diff --git a/src/V3Simulate.h b/src/V3Simulate.h index 93f958472..8b700cbca 100644 --- a/src/V3Simulate.h +++ b/src/V3Simulate.h @@ -600,6 +600,7 @@ private: UINFO(5," FUNCREF "<taskp()->castNodeFTask(); if (!funcp) nodep->v3fatalSrc("Not linked"); + // cppcheck-suppress redundantAssignment if (m_params) { V3Width::widthParamsEdit(funcp); } funcp=NULL; // Make sure we've sized the function funcp = nodep->taskp()->castNodeFTask(); if (!funcp) nodep->v3fatalSrc("Not linked"); // Apply function call values to function diff --git a/src/V3Split.cpp b/src/V3Split.cpp index 2fb265698..9719a9354 100644 --- a/src/V3Split.cpp +++ b/src/V3Split.cpp @@ -98,7 +98,7 @@ class SplitLogicVertex : public SplitNodeVertex { uint32_t m_splitColor; // Copied from color() when determined public: SplitLogicVertex(V3Graph* graphp, AstNode* nodep) - : SplitNodeVertex(graphp,nodep) {} + : SplitNodeVertex(graphp,nodep), m_splitColor(0) {} void splitColor(uint32_t flag) { m_splitColor=flag; } uint32_t splitColor() const { return m_splitColor; } virtual ~SplitLogicVertex() {} diff --git a/src/V3Task.cpp b/src/V3Task.cpp index 5192a3fd5..a44ef2383 100644 --- a/src/V3Task.cpp +++ b/src/V3Task.cpp @@ -548,7 +548,7 @@ private: return beginp; } - string dpiprotoName(AstNodeFTask* nodep, AstVar* rtnvarp) { + string dpiprotoName(AstNodeFTask* nodep, AstVar* rtnvarp) const { // Return fancy export-ish name for DPI function // Variable names are NOT included so differences in only IO names won't matter string dpiproto; @@ -645,8 +645,6 @@ private: } AstCFunc* makeDpiExportWrapper(AstNodeFTask* nodep, AstVar* rtnvarp) { - string dpiproto = dpiprotoName(nodep,rtnvarp); - AstCFunc* dpip = new AstCFunc(nodep->fileline(), nodep->cname(), m_scopep, diff --git a/src/V3Tristate.cpp b/src/V3Tristate.cpp index 63a82953f..f374d31a0 100644 --- a/src/V3Tristate.cpp +++ b/src/V3Tristate.cpp @@ -545,7 +545,6 @@ class TristateVisitor : public TristateBaseVisitor { } AstNode* orp = NULL; - AstNode* andp = NULL; AstNode* enp = NULL; AstNode* undrivenp = NULL; @@ -581,7 +580,7 @@ class TristateVisitor : public TristateBaseVisitor { // now append this driver to the driver logic. AstNode* ref1p = new AstVarRef(refp->fileline(), newlhsp,false); AstNode* ref2p = new AstVarRef(refp->fileline(), newenp, false); - andp = new AstAnd(refp->fileline(), ref1p, ref2p); + AstNode* andp = new AstAnd(refp->fileline(), ref1p, ref2p); // or this to the others orp = (!orp) ? andp : new AstOr(refp->fileline(), orp, andp); diff --git a/src/V3Unknown.cpp b/src/V3Unknown.cpp index f775cc095..f56d89ea5 100644 --- a/src/V3Unknown.cpp +++ b/src/V3Unknown.cpp @@ -92,7 +92,7 @@ private: UINFO(5," IM_WireRep "<convertToAlways(); pushDeletep(m_assignwp); m_assignwp=NULL; } - bool needDly = m_assigndlyp; + bool needDly = (m_assigndlyp != NULL); if (m_assigndlyp) { // Delayed assignments become normal assignments, // then the temp created becomes the delayed assignment diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 3ab59ed5c..81b4ffd5a 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -2872,9 +2872,9 @@ private: underp->replaceWith(new AstConst(nodep->fileline(), AstConst::LogicFalse())); pushDeletep(underp); underp=NULL; } else { - bool warnOn = true; // Not used bool bad = widthBad(underp,nodep->findLogicBoolDType()); if (bad) { + bool warnOn = true; // Not used if (warnOn) { if (debug()>4) nodep->backp()->dumpTree(cout," back: "); nodep->v3warn(WIDTH,"Logical Operator "<prettyTypeName() @@ -3438,11 +3438,6 @@ private: nodep->v3fatalSrc("No dtype expected at statement "<prettyTypeName()); } } - bool backRequiresUnsigned(AstNode* nodep) { - // The spec doesn't state this, but if you have an array select where the selection - // index is NOT wide enough, you do not sign extend, but always zero extend. - return (nodep->castArraySel() || nodep->castSel()); - } void checkConstantOrReplace(AstNode* nodep, const string& message) { // See also V3WidthSel::checkConstantOrReplace // Note can't call V3Const::constifyParam(nodep) here, as constify may change nodep on us! diff --git a/src/cppcheck_filtered b/src/cppcheck_filtered index 43720c4e1..6e1c6e2bd 100755 --- a/src/cppcheck_filtered +++ b/src/cppcheck_filtered @@ -47,6 +47,7 @@ sub process { my %uniq; my %errs; while (defined(my $line = $fh->getline())) { + $line =~ s/^\s+//; $line =~ s/Checking usage of global functions\.+//; # Sometimes tacked at end-of-line # General gunk next if $uniq{$line}++; @@ -62,6 +63,8 @@ sub process { # Specific suppressions next if $line =~ m!id="missingInclude" .*systemc.h!; next if $line =~ m!id="missingInclude" .*svdpi.h!; + next if $line =~ m!id="unusedFunction" .*sv! && $line =~ m!verilated_dpi.cpp!; + next if $line =~ m!id="unusedPrivateFunction" .*::debug!; # Doesn't know UINFO will use it next if $line =~ m!file=".*obj_dbg/V3ParseBison.c".* id="unreachableCode"!; # Output if ($line =~ /^cppcheck --/) { @@ -82,7 +85,8 @@ sub process { if (scalar(keys %errs)) { #my $all = join('',sort(keys %errs)); #$Self->error("Cppcheck errors:\n$all"); - die "%Error: cppcheck_filtered found errors"; + #die "%Error: cppcheck_filtered found errors\n"; + exit(1); } } @@ -93,6 +97,9 @@ sub _suppress { my $linenum = shift; my $id = shift; #print "-Suppression search $filename $linenum $id\n" if $Self->{verbose}; + + return undef if $filename eq "*"; + my $fh = IO::File->new("<$filename"); if (!$fh) { warn "%Warning: $! $filename,"; @@ -111,6 +118,13 @@ sub _suppress { } } } + if ($l == $linenum) { + if ($id eq "uselessAssignmentPtrArg" + && $line =~ /(delete|Delete|Edit).*p *= *NULL;/) { + # delete(nodep); nodep=NULL; # This is ok, it's how we prevent later using nodep + return 1; + } + } } return undef; }