diff --git a/Makefile.in b/Makefile.in index baad8e9be..e0adba72e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -411,7 +411,8 @@ CPPCHECK_H = $(wildcard \ $(srcdir)/src/*.h ) CPPCHECK = src/cppcheck_filtered CPPCHECK_FLAGS = --enable=all --inline-suppr \ - --suppress=unusedScopedObject --suppress=cstyleCast --suppress=useInitializationList + --suppress=unusedScopedObject --suppress=cstyleCast --suppress=useInitializationList \ + --suppress=nullPointerRedundantCheck CPPCHECK_FLAGS += --xml CPPCHECK_DEP = $(subst .cpp,.cppcheck,$(CPPCHECK_CPP)) CPPCHECK_INC = -I$(srcdir)/include -I$(srcdir)/src/obj_dbg -I$(srcdir)/src diff --git a/include/verilated.cpp b/include/verilated.cpp index bde82cdcb..b4e2097c2 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -43,9 +43,13 @@ // Static sanity checks (when get C++11 can use static_assert) typedef union { + // cppcheck-suppress unusedStructMember // Unused as is assertion char vluint8_incorrect[(sizeof(vluint8_t) == 1) ? 1:-1]; + // cppcheck-suppress unusedStructMember // Unused as is assertion char vluint16_incorrect[(sizeof(vluint16_t) == 2) ? 1:-1]; + // cppcheck-suppress unusedStructMember // Unused as is assertion char vluint32_incorrect[(sizeof(vluint32_t) == 4) ? 1:-1]; + // cppcheck-suppress unusedStructMember // Unused as is assertion char vluint64_incorrect[(sizeof(vluint64_t) == 8) ? 1:-1]; } vl_static_checks_t; @@ -1374,6 +1378,7 @@ void VL_WRITEMEM_N( FILE* fp = fopen(filename.c_str(), "w"); if (VL_UNLIKELY(!fp)) { VL_FATAL_MT(filename.c_str(), 0, "", "$writemem file not found"); + // cppcheck-suppress resourceLeak // fp is NULL - bug in cppcheck return; } @@ -1511,6 +1516,7 @@ void VL_READMEM_N( if (VL_UNLIKELY(!fp)) { // We don't report the Verilog source filename as it slow to have to pass it down VL_FATAL_MT(filename.c_str(), 0, "", "$readmem file not found"); + // cppcheck-suppress resourceLeak // fp is NULL - bug in cppcheck return; } // Prep for reading @@ -2105,6 +2111,7 @@ VerilatedScope::VerilatedScope() { m_funcnumMax = 0; m_symsp = NULL; m_varsp = NULL; + m_type = SCOPE_OTHER; } VerilatedScope::~VerilatedScope() { diff --git a/include/verilated_threads.h b/include/verilated_threads.h index 363a0ce35..355aa5b3f 100644 --- a/include/verilated_threads.h +++ b/include/verilated_threads.h @@ -186,6 +186,7 @@ public: m_mtaskId = 0; m_predictTime = 0; m_startTime = 0; + m_endTime = 0; m_cpu = getcpu(); } void startRecord(vluint64_t time, uint32_t mtask, uint32_t predict) { diff --git a/src/V3Ast.cpp b/src/V3Ast.cpp index 7a553973e..30e10b309 100644 --- a/src/V3Ast.cpp +++ b/src/V3Ast.cpp @@ -977,23 +977,28 @@ void AstNode::checkTree() { } } +// cppcheck-suppress unusedFunction // Debug only void AstNode::dumpGdb() { // For GDB only // LCOV_EXCL_LINE dumpGdbHeader(); // LCOV_EXCL_LINE cout<<" "; dump(cout); cout<dumpTreeFile(filename); // LCOV_EXCL_LINE } +// cppcheck-suppress unusedFunction // Debug only void AstNode::checkIter() const { if (m_iterpp) { dumpPtrs(cout); diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index dbee11bdc..b98f9331d 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -927,9 +927,9 @@ void AstRange::dump(std::ostream& str) { if (littleEndian()) str<<" [LITTLE]"; } void AstRefDType::dump(std::ostream& str) { - static bool s_recursing = false; this->AstNodeDType::dump(str); if (defp()) { + static bool s_recursing = false; if (!s_recursing) { // Prevent infinite dump if circular typedefs s_recursing = true; str<<" -> "; defp()->dump(str); diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index 5b264c865..a9d2d6beb 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -1960,7 +1960,6 @@ void EmitCImp::emitSavableImp(AstNodeModule* modp) { for (int de=0; de<2; ++de) { string classname = de ? "VerilatedDeserialize" : "VerilatedSerialize"; string funcname = de ? "__Vdeserialize" : "__Vserialize"; - string writeread = de ? "read" : "write"; string op = de ? ">>" : "<<"; // NOLINTNEXTLINE(performance-inefficient-string-concatenation) puts("void "+modClassName(modp)+"::"+funcname+"("+classname+"& os) {\n"); diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index 517cfb8c9..468afb936 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -362,6 +362,7 @@ public: m_labelNum = 0; m_numStmts = 0; m_funcNum = 0; + m_ofpBase = NULL; iterate(nodep); } }; diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 2ed28a8a0..c0b53eab5 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -1007,9 +1007,11 @@ class LinkDotFindVisitor : public AstNVisitor { || (findvarp->isIO() && nodep->isIO())); // e.g. !(output && output) bool ansiBad = findvarp->isAnsi() || nodep->isAnsi(); // dup illegal with ANSI if (ansiBad || nansiBad) { - static int didAnsiWarn = false; bool ansiWarn = ansiBad && !nansiBad; - if (ansiWarn) { if (didAnsiWarn++) ansiWarn = false; } + if (ansiWarn) { + static int didAnsiWarn = false; + if (didAnsiWarn++) ansiWarn = false; + } nodep->v3error("Duplicate declaration of signal: " <prettyNameQ()<addPinsp(outp); } -AstNode* V3ParseGrammar::createSupplyExpr(FileLine* fileline, string name, int value) { +AstNode* V3ParseGrammar::createSupplyExpr(FileLine* fileline, const string& name, int value) { return new AstAssignW(fileline, new AstVarRef(fileline, name, true), new AstConst(fileline, AstConst::StringToParse(), (value ? "'1" : "'0"))); @@ -131,7 +131,7 @@ AstNodeDType* V3ParseGrammar::createArray(AstNodeDType* basep, return arrayp; } -AstVar* V3ParseGrammar::createVariable(FileLine* fileline, string name, +AstVar* V3ParseGrammar::createVariable(FileLine* fileline, const string& name, AstNodeRange* arrayp, AstNode* attrsp) { AstNodeDType* dtypep = GRAMMARP->m_varDTypep; UINFO(5," creVar "<newContent(); m_inLibrary = inLibrary; diff --git a/src/cppcheck_filtered b/src/cppcheck_filtered index 1f50c5c92..aa0f6dc8c 100755 --- a/src/cppcheck_filtered +++ b/src/cppcheck_filtered @@ -24,9 +24,10 @@ our $Opt_Debug; autoflush STDOUT 1; autoflush STDERR 1; Getopt::Long::config("no_auto_abbrev","pass_through"); -our @Opt_Args = ("cppcheck", @ARGV); +our @Opt_Args = ("cppcheck", grep { $_ ne "--debug" } @ARGV); if (! GetOptions( # Local options + "debug!" => sub { $Debug = 9; }, "help" => \&usage, "version" => sub { print "Version $VERSION\n"; system("cppcheck","--version"); exit(0); }, )) { @@ -46,7 +47,7 @@ sub usage { ####################################################################### sub process { - my $cmd = join(' ',@Opt_Args); + my $cmd = join(' ', @Opt_Args); print "\t$cmd\n" if $Debug; my $fh = IO::File->new("$cmd 2>&1 |"); $fh or die "%Error: '$cmd' failed: $!\n"; @@ -54,6 +55,7 @@ sub process { my %errs; my $last_error = ""; while (defined(my $line = $fh->getline())) { + print ">>>$line" if $Debug; $line =~ s/^\s+//; $line =~ s/Checking usage of global functions\.+//; # Sometimes tacked at end-of-line # General gunk @@ -85,6 +87,7 @@ sub process { # --xml-format=1 if ($line =~ /file="([^"]+)"\s+line="(\d+)"\s+id="([^"]+)"/) { my $file = $1; my $linenum = $2; my $id = $3; + #$file = $1 if $line =~ /file0="([^"]+)"/; # Still incorrect $suppress = 1 if _suppress($file,$linenum,$id); } # --xml-format=2 @@ -95,6 +98,7 @@ sub process { } elsif ($line =~ /