Internals: Fix some cppcheck warnings.

This commit is contained in:
Wilson Snyder 2019-10-06 08:20:02 -04:00
parent 09b79a731a
commit 307549e8a6
12 changed files with 32 additions and 13 deletions

View File

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

View File

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

View File

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

View File

@ -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<<endl; // LCOV_EXCL_LINE
}
// cppcheck-suppress unusedFunction // Debug only
void AstNode::dumpGdbHeader() const { // For GDB only // LCOV_EXCL_LINE
dumpPtrs(cout); // LCOV_EXCL_LINE
cout<<" Fileline = "<<fileline()<<endl; // LCOV_EXCL_LINE
}
// cppcheck-suppress unusedFunction // Debug only
void AstNode::dumpTreeGdb() { // For GDB only // LCOV_EXCL_LINE
dumpGdbHeader(); // LCOV_EXCL_LINE
dumpTree(cout); // LCOV_EXCL_LINE
}
// cppcheck-suppress unusedFunction // Debug only
void AstNode::dumpTreeFileGdb(const char* filenamep) { // For GDB only // LCOV_EXCL_LINE
string filename = filenamep ? filenamep : v3Global.debugFilename("debug.tree", 98); // LCOV_EXCL_LINE
v3Global.rootp()->dumpTreeFile(filename); // LCOV_EXCL_LINE
}
// cppcheck-suppress unusedFunction // Debug only
void AstNode::checkIter() const {
if (m_iterpp) {
dumpPtrs(cout);

View File

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

View File

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

View File

@ -362,6 +362,7 @@ public:
m_labelNum = 0;
m_numStmts = 0;
m_funcNum = 0;
m_ofpBase = NULL;
iterate(nodep);
}
};

View File

@ -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: "
<<nodep->prettyNameQ()<<endl
<<(ansiWarn

View File

@ -79,7 +79,7 @@ void V3ParseGrammar::argWrapList(AstNodeFTaskRef* nodep) {
if (outp) nodep->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 "<<name<<" decl="<<GRAMMARP->m_varDecl

View File

@ -225,7 +225,6 @@ void V3ParseImp::parseFile(FileLine* fileline, const string& modfilename, bool i
string modname = V3Os::filenameNonExt(modfilename);
UINFO(2,__FUNCTION__<<": "<<modname<<(inLibrary?" [LIB]":"")<<endl);
VFileContent* contentp = new VFileContent;
m_fileline = new FileLine(fileline);
m_fileline->newContent();
m_inLibrary = inLibrary;

View File

@ -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 =~ /<location.* file="([^"]+)"\s+line="(\d+)"/) {
my $file = $1; my $linenum = $2; my $id;
#$file = $1 if $line =~ /file0="([^"]+)"/; # Still incorrect
if ($last_error =~ / id="([^"]+)"/) {
$id = $1;
} else {

View File

@ -98,9 +98,9 @@ public:
}
AstRange* scrubRange(AstNodeRange* rangep);
AstNodeDType* createArray(AstNodeDType* basep, AstNodeRange* rangep, bool isPacked);
AstVar* createVariable(FileLine* fileline, string name, AstNodeRange* arrayp, AstNode* attrsp);
AstNode* createSupplyExpr(FileLine* fileline, string name, int value);
AstText* createTextQuoted(FileLine* fileline, string text) {
AstVar* createVariable(FileLine* fileline, const string& name, AstNodeRange* arrayp, AstNode* attrsp);
AstNode* createSupplyExpr(FileLine* fileline, const string& name, int value);
AstText* createTextQuoted(FileLine* fileline, const string& text) {
string newtext = deQuote(fileline, text);
return new AstText(fileline, newtext);
}