Internals: cppcheck clean and add cppcheck_filtered

This commit is contained in:
Wilson Snyder 2014-04-29 22:59:38 -04:00
parent 84b91b19ca
commit adb39ceb98
10 changed files with 210 additions and 10 deletions

View File

@ -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)

View File

@ -283,7 +283,7 @@ public:
virtual ~VerilatedVpioMemoryWordIter() {}
static inline VerilatedVpioMemoryWordIter* castp(vpiHandle h) { return dynamic_cast<VerilatedVpioMemoryWordIter*>((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<VerilatedVpioVar*>::iterator it=update.begin(); it!=update.end(); it++ ) {
for (set<VerilatedVpioVar*>::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() {}

View File

@ -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<GateLogicVertex*>(outedgep->top());

View File

@ -80,7 +80,7 @@ private:
if (m_modp->user2() != CIL_NOTHARD) {
UINFO(4," No inline hard: "<<reason<<" "<<m_modp<<endl);
m_modp->user2(CIL_NOTHARD);
m_statUnsup++;
++m_statUnsup;
}
} else {
if (m_modp->user2() == CIL_MAYBE) {

View File

@ -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)

View File

@ -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: ");

View File

@ -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 "<<nodep->valuep()<<endl);
// Although nodep will get a different width for parameters just below,
@ -972,6 +971,7 @@ private:
if (nodep->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
}

183
src/cppcheck_filtered Executable file
View File

@ -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!^<results>!;
next if $line =~ m!^</results>!;
next if $line =~ m!^<error.*id="unmatchedSuppression"!; # --suppress=unmatchedSuppression doesn't work
next if $line =~ m!Cppcheck cannot find all the include files!; # An earlier id line is more specific
next if $line =~ m!^Checking !;
next if $line =~ m!^make.*Entering directory !;
next if $line =~ m!^make.*Leaving directory !;
next if $line =~ m!^\s+$!g;
# Specific suppressions
next if $line =~ m!id="missingInclude" .*systemc.h!;
next if $line =~ m!id="missingInclude" .*svdpi.h!;
next if $line =~ m!file=".*obj_dbg/V3ParseBison.c".* id="unreachableCode"!;
# Output
if ($line =~ /^cppcheck --/) {
print $line if $Debug;
} else {
my $suppress;
if ($line =~ /file="([^"]+)"\s+line="(\d+)"\s+id="([^"]+)"/) {
my $file = $1; my $linenum = $2; my $id = $3;
$suppress = 1 if _suppress($file,$linenum,$id);
}
if (!$suppress) {
my $eline = "%Error: cppcheck: $line";
print $eline;
$errs{$eline}++;
}
}
}
if (scalar(keys %errs)) {
#my $all = join('',sort(keys %errs));
#$Self->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<http://www.veripool.org/> free Verilog EDA software
tool suite. The latest version is available from CPAN and from
L<http://www.veripool.org/>.
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 <wsnyder@wsnyder.org>
=head1 SEE ALSO
C<cppcheck>
=cut
######################################################################
### Local Variables:
### compile-command: "./cppcheck_filtered --xml V3Width.cpp"
### End:

View File

@ -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);

View File

@ -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};