From adb39ceb9887bed9d37ba1538002d859994477f7 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Tue, 29 Apr 2014 22:59:38 -0400 Subject: [PATCH] Internals: cppcheck clean and add cppcheck_filtered --- Makefile.in | 5 +- include/verilated_vpi.h | 5 +- src/V3Gate.cpp | 9 +- src/V3Inline.cpp | 2 +- src/V3OrderGraph.h | 3 +- src/V3Slice.cpp | 1 + src/V3Width.cpp | 5 +- src/cppcheck_filtered | 183 ++++++++++++++++++++++++++++++++++++++++ src/verilog.y | 2 + test_regress/driver.pl | 5 ++ 10 files changed, 210 insertions(+), 10 deletions(-) create mode 100755 src/cppcheck_filtered diff --git a/Makefile.in b/Makefile.in index 5f4f72a1a..d7cf4c9dd 100644 --- a/Makefile.in +++ b/Makefile.in @@ -120,7 +120,8 @@ DISTFILES_INC = $(INFOS) .gitignore Artistic COPYING COPYING.LESSER \ include/.*ignore \ include/vltstd/*.[chv]* \ .*attributes */.*attributes */*/.*attributes \ - src/.*ignore src/*.in src/*.cpp src/*.[chly] src/astgen src/bisonpre src/*fix \ + src/.*ignore src/*.in src/*.cpp src/*.[chly] \ + src/astgen src/bisonpre src/*fix src/cppcheck_filtered \ src/.gdbinit \ src/*.pl src/*.pod \ test_*/.*ignore test_*/Makefile* test_*/*.cpp \ @@ -400,7 +401,7 @@ endif endif # Use --xml flag to see the cppcheck code to use for suppression -CPPCHECK = cppcheck +CPPCHECK = src/cppcheck_filtered CPPCHECK_FLAGS = --enable=all --inline-suppr --suppress=unusedScopedObject --suppress=cstyleCast CPPCHECK_FLAGS += --xml CPPCHECK_CPP = $(wildcard $(srcdir)/include/*.cpp $(srcdir)/src/*.cpp) diff --git a/include/verilated_vpi.h b/include/verilated_vpi.h index af01db335..bc5865db4 100644 --- a/include/verilated_vpi.h +++ b/include/verilated_vpi.h @@ -283,7 +283,7 @@ public: virtual ~VerilatedVpioMemoryWordIter() {} static inline VerilatedVpioMemoryWordIter* castp(vpiHandle h) { return dynamic_cast((VerilatedVpio*)h); } virtual const vluint32_t type() { return vpiIterator; } - void iterationInc() { if (!(m_done = m_iteration == m_varp->array().left())) m_iteration+=m_direction; } + void iterationInc() { if (!(m_done = (m_iteration == m_varp->array().left()))) m_iteration+=m_direction; } virtual vpiHandle dovpi_scan() { vpiHandle result; if (m_done) return 0; @@ -408,7 +408,7 @@ public: } } } - for (set::iterator it=update.begin(); it!=update.end(); it++ ) { + for (set::iterator it=update.begin(); it!=update.end(); ++it) { memcpy((*it)->prevDatap(), (*it)->varDatap(), (*it)->entSize()); } } @@ -454,6 +454,7 @@ class VerilatedVpiError { public: VerilatedVpiError() : m_flag(false) { + m_buff[0] = '\0'; m_errorInfo.product = (PLI_BYTE8*)Verilated::productName(); } ~VerilatedVpiError() {} diff --git a/src/V3Gate.cpp b/src/V3Gate.cpp index b13cfd20f..f7429f108 100644 --- a/src/V3Gate.cpp +++ b/src/V3Gate.cpp @@ -929,7 +929,12 @@ private: public: // CONSTUCTORS - GateDedupeVarVisitor() {} + GateDedupeVarVisitor() { + m_assignp = NULL; + m_ifCondp = NULL; + m_always = false; + m_dedupable = true; + } // PUBLIC METHODS AstNodeVarRef* findDupe(AstNode* nodep, AstVarScope* consumerVarScopep, AstActive* activep) { m_assignp = NULL; @@ -978,7 +983,7 @@ private: AstVarScope* dupVarScopep = dupVarRefp->varScopep(); GateVarVertex* dupVvertexp = (GateVarVertex*) (dupVarScopep->user1p()); UINFO(4,"replacing " << vvertexp << " with " << dupVvertexp << endl); - m_numDeduped++; + ++m_numDeduped; // Replace all of this varvertex's consumers with dupVarRefp for (V3GraphEdge* outedgep = vvertexp->outBeginp();outedgep;) { GateLogicVertex* consumeVertexp = dynamic_cast(outedgep->top()); diff --git a/src/V3Inline.cpp b/src/V3Inline.cpp index adef465d8..bcc26ba63 100644 --- a/src/V3Inline.cpp +++ b/src/V3Inline.cpp @@ -80,7 +80,7 @@ private: if (m_modp->user2() != CIL_NOTHARD) { UINFO(4," No inline hard: "<user2(CIL_NOTHARD); - m_statUnsup++; + ++m_statUnsup; } } else { if (m_modp->user2() == CIL_MAYBE) { diff --git a/src/V3OrderGraph.h b/src/V3OrderGraph.h index 6dcb0c0f9..0bba82a46 100644 --- a/src/V3OrderGraph.h +++ b/src/V3OrderGraph.h @@ -228,7 +228,8 @@ class OrderVarVertex : public OrderEitherVertex { protected: OrderVarVertex(V3Graph* graphp, const OrderVarVertex& old) : OrderEitherVertex(graphp, old) - , m_varScp(old.m_varScp), m_pilNewVertexp(old.m_pilNewVertexp), m_isClock(old.m_isClock) {} + , m_varScp(old.m_varScp), m_pilNewVertexp(old.m_pilNewVertexp), m_isClock(old.m_isClock) + , m_isDelayed(old.m_isDelayed) {} public: OrderVarVertex(V3Graph* graphp, AstScope* scopep, AstVarScope* varScp) : OrderEitherVertex(graphp, scopep, NULL), m_varScp(varScp) diff --git a/src/V3Slice.cpp b/src/V3Slice.cpp index 4e186d3d2..b41fc250d 100644 --- a/src/V3Slice.cpp +++ b/src/V3Slice.cpp @@ -417,6 +417,7 @@ class SliceVisitor : public AstNVisitor { AstNode* lhsp = new AstArraySel(nodep->fileline(), nodep->lhsp()->cloneTree(false), index++); + // cppcheck-suppress nullPointer newp = newp->addNext(nodep->cloneType(lhsp, subp->unlinkFrBack())); } //if (debug()>=9) newp->dumpTreeAndNext(cout, "-InitArrayOut: "); diff --git a/src/V3Width.cpp b/src/V3Width.cpp index a463d620a..4c10be815 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -963,7 +963,6 @@ private: bool implicitParam = nodep->isParam() && bdtypep && bdtypep->implicit(); if (implicitParam) { if (nodep->valuep()) { - int width=0; nodep->valuep()->iterateAndNext(*this,WidthVP(nodep->dtypep(),PRELIM).p()); UINFO(9,"implicitParamPRELIMIV "<valuep()<valuep()->isDouble()) { nodep->dtypeSetDouble(); bdtypep=NULL; } else { + int width=0; AstBasicDType* valueBdtypep = nodep->valuep()->dtypep()->basicp(); bool issigned = false; if (bdtypep->isNosign()) { @@ -1473,7 +1473,7 @@ private: } if (newpatp) { pushDeletep(newpatp); newpatp=NULL; } } - if (patmap.size()) nodep->v3error("Assignment pattern with too many elements"); + if (!patmap.empty()) nodep->v3error("Assignment pattern with too many elements"); if (newp) nodep->replaceWith(newp); else nodep->v3error("Assignment pattern with no members"); //if (debug()>=9) newp->dumpTree("-apat-out: "); @@ -1920,6 +1920,7 @@ private: argp->unlinkFrBackWithNext(&handle); // Format + additional args, if any AstNode* argsp = NULL; while (AstArg* nextargp = argp->nextp()->castArg()) { + // cppcheck-suppress nullPointer argsp = argsp->addNext(nextargp->exprp()->unlinkFrBackWithNext()); // Expression goes to SFormatF nextargp->unlinkFrBack()->deleteTree(); // Remove the call's Arg wrapper } diff --git a/src/cppcheck_filtered b/src/cppcheck_filtered new file mode 100755 index 000000000..0a669da56 --- /dev/null +++ b/src/cppcheck_filtered @@ -0,0 +1,183 @@ +#!/usr/bin/perl -w +# See copyright, etc in below POD section. +###################################################################### + +require 5.006_001; +use Getopt::Long; +use IO::File; +use Pod::Usage; +use strict; +use vars qw ($Debug $VERSION); + +$VERSION = '3.857'; + +#====================================================================== +# main + +our $Opt_Debug; + +autoflush STDOUT 1; +autoflush STDERR 1; +Getopt::Long::config ("no_auto_abbrev","pass_through"); +our @Opt_Args = ("cppcheck", @ARGV); +if (! GetOptions ( + # Local options + "help" => \&usage, + "version" => sub { print "Version $VERSION\n"; system("cppcheck","--version"); exit(0); }, + )) { + die "%Error: Bad usage, try 'cppcheck_filtered --help'\n"; +} + +process(); + +#---------------------------------------------------------------------- + +sub usage { + print "Version $VERSION\n"; + pod2usage(-verbose=>2, -exitval=>2, -output=>\*STDOUT, -noperldoc=>1); + exit (1); +} + +####################################################################### + +sub process { + my $cmd = join(' ',@Opt_Args); + print "\t$cmd\n" if $Debug; + my $fh = IO::File->new("$cmd 2>&1 |"); + my %uniq; + my %errs; + while (defined(my $line = $fh->getline())) { + $line =~ s/Checking usage of global functions\.+//; # Sometimes tacked at end-of-line + # General gunk + next if $uniq{$line}++; + next if $line =~ m!^<\?xml version!; + next if $line =~ m!^!; + next if $line =~ m!^!; + next if $line =~ m!^error("Cppcheck errors:\n$all"); + die "%Error: cppcheck_filtered found errors"; + } +} + +###################################################################### + +sub _suppress { + my $filename = shift; + my $linenum = shift; + my $id = shift; + #print "-Suppression search $filename $linenum $id\n" if $Self->{verbose}; + my $fh = IO::File->new("<$filename"); + if (!$fh) { + warn "%Warning: $! $filename,"; + return undef; + } + my $l = 0; + while (defined(my $line = $fh->getline())) { + ++$l; + if ($l+1 == $linenum) { + if ($line =~ /cppcheck-suppress\s+(\S+)/) { + my $supid = $1; + if ($supid eq $id) { + return 1; + } else { + warn "%Warning: $filename: $l: Found suppress for id='$supid', not expected id='$id'\n"; + } + } + } + } + return undef; +} + +1; + +####################################################################### +__END__ + +=pod + +=head1 NAME + +cppcheck_filtered - cppcheck wrapper with post-processing + +=head1 SYNOPSIS + + cppcheck_filtered ...normal cpp check flags... + + +=head1 DESCRIPTION + +Cppcheck_Filtered is a wrapper for cppcheck that filters out unnecessary +warnings related to Verilator. + +=head1 ARGUMENTS + +Most arguments are passed through to cppcheck + +=over 4 + +=item --help + +Displays this message and program version and exits. + +=item --version + +Print the version number and exit. + +=back + +=head1 DISTRIBUTION + +This is part of the L free Verilog EDA software +tool suite. The latest version is available from CPAN and from +L. + +Copyright 2014-2014 by Wilson Snyder. This package is free software; you +can redistribute it and/or modify it under the terms of either the GNU +Lesser General Public License Version 3 or the Perl Artistic License Version 2.0. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +more details. + +=head1 AUTHORS + +Wilson Snyder + +=head1 SEE ALSO + +C + +=cut + +###################################################################### +### Local Variables: +### compile-command: "./cppcheck_filtered --xml V3Width.cpp" +### End: diff --git a/src/verilog.y b/src/verilog.y index 5e1cb0b4e..ae6f672b7 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -3672,6 +3672,8 @@ void V3ParseGrammar::argWrapList(AstNodeFTaskRef* nodep) { AstNode* outp = NULL; while (nodep->pinsp()) { AstNode* exprp = nodep->pinsp()->unlinkFrBack(); + // addNext can handle nulls: + // cppcheck-suppress nullPointer outp = outp->addNext(new AstArg(exprp->fileline(), "", exprp)); } if (outp) nodep->addPinsp(outp); diff --git a/test_regress/driver.pl b/test_regress/driver.pl index 24d308e24..77962e6d3 100755 --- a/test_regress/driver.pl +++ b/test_regress/driver.pl @@ -825,6 +825,11 @@ sub ok { return $self->{ok}; } +sub continuing { + my $self = (ref $_[0]? shift : $Self); + return !($self->errors || $self->skips || $self->unsupporteds); +} + sub errors { my $self = (ref $_[0]? shift : $Self); return $self->{errors};