Internals: Fix some cppcheck warnings.
This commit is contained in:
parent
09b79a731a
commit
307549e8a6
|
|
@ -411,7 +411,8 @@ CPPCHECK_H = $(wildcard \
|
||||||
$(srcdir)/src/*.h )
|
$(srcdir)/src/*.h )
|
||||||
CPPCHECK = src/cppcheck_filtered
|
CPPCHECK = src/cppcheck_filtered
|
||||||
CPPCHECK_FLAGS = --enable=all --inline-suppr \
|
CPPCHECK_FLAGS = --enable=all --inline-suppr \
|
||||||
--suppress=unusedScopedObject --suppress=cstyleCast --suppress=useInitializationList
|
--suppress=unusedScopedObject --suppress=cstyleCast --suppress=useInitializationList \
|
||||||
|
--suppress=nullPointerRedundantCheck
|
||||||
CPPCHECK_FLAGS += --xml
|
CPPCHECK_FLAGS += --xml
|
||||||
CPPCHECK_DEP = $(subst .cpp,.cppcheck,$(CPPCHECK_CPP))
|
CPPCHECK_DEP = $(subst .cpp,.cppcheck,$(CPPCHECK_CPP))
|
||||||
CPPCHECK_INC = -I$(srcdir)/include -I$(srcdir)/src/obj_dbg -I$(srcdir)/src
|
CPPCHECK_INC = -I$(srcdir)/include -I$(srcdir)/src/obj_dbg -I$(srcdir)/src
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,13 @@
|
||||||
// Static sanity checks (when get C++11 can use static_assert)
|
// Static sanity checks (when get C++11 can use static_assert)
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
|
// cppcheck-suppress unusedStructMember // Unused as is assertion
|
||||||
char vluint8_incorrect[(sizeof(vluint8_t) == 1) ? 1:-1];
|
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];
|
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];
|
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];
|
char vluint64_incorrect[(sizeof(vluint64_t) == 8) ? 1:-1];
|
||||||
} vl_static_checks_t;
|
} vl_static_checks_t;
|
||||||
|
|
||||||
|
|
@ -1374,6 +1378,7 @@ void VL_WRITEMEM_N(
|
||||||
FILE* fp = fopen(filename.c_str(), "w");
|
FILE* fp = fopen(filename.c_str(), "w");
|
||||||
if (VL_UNLIKELY(!fp)) {
|
if (VL_UNLIKELY(!fp)) {
|
||||||
VL_FATAL_MT(filename.c_str(), 0, "", "$writemem file not found");
|
VL_FATAL_MT(filename.c_str(), 0, "", "$writemem file not found");
|
||||||
|
// cppcheck-suppress resourceLeak // fp is NULL - bug in cppcheck
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1511,6 +1516,7 @@ void VL_READMEM_N(
|
||||||
if (VL_UNLIKELY(!fp)) {
|
if (VL_UNLIKELY(!fp)) {
|
||||||
// We don't report the Verilog source filename as it slow to have to pass it down
|
// 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");
|
VL_FATAL_MT(filename.c_str(), 0, "", "$readmem file not found");
|
||||||
|
// cppcheck-suppress resourceLeak // fp is NULL - bug in cppcheck
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Prep for reading
|
// Prep for reading
|
||||||
|
|
@ -2105,6 +2111,7 @@ VerilatedScope::VerilatedScope() {
|
||||||
m_funcnumMax = 0;
|
m_funcnumMax = 0;
|
||||||
m_symsp = NULL;
|
m_symsp = NULL;
|
||||||
m_varsp = NULL;
|
m_varsp = NULL;
|
||||||
|
m_type = SCOPE_OTHER;
|
||||||
}
|
}
|
||||||
|
|
||||||
VerilatedScope::~VerilatedScope() {
|
VerilatedScope::~VerilatedScope() {
|
||||||
|
|
|
||||||
|
|
@ -186,6 +186,7 @@ public:
|
||||||
m_mtaskId = 0;
|
m_mtaskId = 0;
|
||||||
m_predictTime = 0;
|
m_predictTime = 0;
|
||||||
m_startTime = 0;
|
m_startTime = 0;
|
||||||
|
m_endTime = 0;
|
||||||
m_cpu = getcpu();
|
m_cpu = getcpu();
|
||||||
}
|
}
|
||||||
void startRecord(vluint64_t time, uint32_t mtask, uint32_t predict) {
|
void startRecord(vluint64_t time, uint32_t mtask, uint32_t predict) {
|
||||||
|
|
|
||||||
|
|
@ -977,23 +977,28 @@ void AstNode::checkTree() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress unusedFunction // Debug only
|
||||||
void AstNode::dumpGdb() { // For GDB only // LCOV_EXCL_LINE
|
void AstNode::dumpGdb() { // For GDB only // LCOV_EXCL_LINE
|
||||||
dumpGdbHeader(); // LCOV_EXCL_LINE
|
dumpGdbHeader(); // LCOV_EXCL_LINE
|
||||||
cout<<" "; dump(cout); cout<<endl; // 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
|
void AstNode::dumpGdbHeader() const { // For GDB only // LCOV_EXCL_LINE
|
||||||
dumpPtrs(cout); // LCOV_EXCL_LINE
|
dumpPtrs(cout); // LCOV_EXCL_LINE
|
||||||
cout<<" Fileline = "<<fileline()<<endl; // LCOV_EXCL_LINE
|
cout<<" Fileline = "<<fileline()<<endl; // LCOV_EXCL_LINE
|
||||||
}
|
}
|
||||||
|
// cppcheck-suppress unusedFunction // Debug only
|
||||||
void AstNode::dumpTreeGdb() { // For GDB only // LCOV_EXCL_LINE
|
void AstNode::dumpTreeGdb() { // For GDB only // LCOV_EXCL_LINE
|
||||||
dumpGdbHeader(); // LCOV_EXCL_LINE
|
dumpGdbHeader(); // LCOV_EXCL_LINE
|
||||||
dumpTree(cout); // 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
|
void AstNode::dumpTreeFileGdb(const char* filenamep) { // For GDB only // LCOV_EXCL_LINE
|
||||||
string filename = filenamep ? filenamep : v3Global.debugFilename("debug.tree", 98); // LCOV_EXCL_LINE
|
string filename = filenamep ? filenamep : v3Global.debugFilename("debug.tree", 98); // LCOV_EXCL_LINE
|
||||||
v3Global.rootp()->dumpTreeFile(filename); // LCOV_EXCL_LINE
|
v3Global.rootp()->dumpTreeFile(filename); // LCOV_EXCL_LINE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cppcheck-suppress unusedFunction // Debug only
|
||||||
void AstNode::checkIter() const {
|
void AstNode::checkIter() const {
|
||||||
if (m_iterpp) {
|
if (m_iterpp) {
|
||||||
dumpPtrs(cout);
|
dumpPtrs(cout);
|
||||||
|
|
|
||||||
|
|
@ -927,9 +927,9 @@ void AstRange::dump(std::ostream& str) {
|
||||||
if (littleEndian()) str<<" [LITTLE]";
|
if (littleEndian()) str<<" [LITTLE]";
|
||||||
}
|
}
|
||||||
void AstRefDType::dump(std::ostream& str) {
|
void AstRefDType::dump(std::ostream& str) {
|
||||||
static bool s_recursing = false;
|
|
||||||
this->AstNodeDType::dump(str);
|
this->AstNodeDType::dump(str);
|
||||||
if (defp()) {
|
if (defp()) {
|
||||||
|
static bool s_recursing = false;
|
||||||
if (!s_recursing) { // Prevent infinite dump if circular typedefs
|
if (!s_recursing) { // Prevent infinite dump if circular typedefs
|
||||||
s_recursing = true;
|
s_recursing = true;
|
||||||
str<<" -> "; defp()->dump(str);
|
str<<" -> "; defp()->dump(str);
|
||||||
|
|
|
||||||
|
|
@ -1960,7 +1960,6 @@ void EmitCImp::emitSavableImp(AstNodeModule* modp) {
|
||||||
for (int de=0; de<2; ++de) {
|
for (int de=0; de<2; ++de) {
|
||||||
string classname = de ? "VerilatedDeserialize" : "VerilatedSerialize";
|
string classname = de ? "VerilatedDeserialize" : "VerilatedSerialize";
|
||||||
string funcname = de ? "__Vdeserialize" : "__Vserialize";
|
string funcname = de ? "__Vdeserialize" : "__Vserialize";
|
||||||
string writeread = de ? "read" : "write";
|
|
||||||
string op = de ? ">>" : "<<";
|
string op = de ? ">>" : "<<";
|
||||||
// NOLINTNEXTLINE(performance-inefficient-string-concatenation)
|
// NOLINTNEXTLINE(performance-inefficient-string-concatenation)
|
||||||
puts("void "+modClassName(modp)+"::"+funcname+"("+classname+"& os) {\n");
|
puts("void "+modClassName(modp)+"::"+funcname+"("+classname+"& os) {\n");
|
||||||
|
|
|
||||||
|
|
@ -362,6 +362,7 @@ public:
|
||||||
m_labelNum = 0;
|
m_labelNum = 0;
|
||||||
m_numStmts = 0;
|
m_numStmts = 0;
|
||||||
m_funcNum = 0;
|
m_funcNum = 0;
|
||||||
|
m_ofpBase = NULL;
|
||||||
iterate(nodep);
|
iterate(nodep);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1007,9 +1007,11 @@ class LinkDotFindVisitor : public AstNVisitor {
|
||||||
|| (findvarp->isIO() && nodep->isIO())); // e.g. !(output && output)
|
|| (findvarp->isIO() && nodep->isIO())); // e.g. !(output && output)
|
||||||
bool ansiBad = findvarp->isAnsi() || nodep->isAnsi(); // dup illegal with ANSI
|
bool ansiBad = findvarp->isAnsi() || nodep->isAnsi(); // dup illegal with ANSI
|
||||||
if (ansiBad || nansiBad) {
|
if (ansiBad || nansiBad) {
|
||||||
static int didAnsiWarn = false;
|
|
||||||
bool ansiWarn = ansiBad && !nansiBad;
|
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->v3error("Duplicate declaration of signal: "
|
||||||
<<nodep->prettyNameQ()<<endl
|
<<nodep->prettyNameQ()<<endl
|
||||||
<<(ansiWarn
|
<<(ansiWarn
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ void V3ParseGrammar::argWrapList(AstNodeFTaskRef* nodep) {
|
||||||
if (outp) nodep->addPinsp(outp);
|
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),
|
return new AstAssignW(fileline, new AstVarRef(fileline, name, true),
|
||||||
new AstConst(fileline, AstConst::StringToParse(),
|
new AstConst(fileline, AstConst::StringToParse(),
|
||||||
(value ? "'1" : "'0")));
|
(value ? "'1" : "'0")));
|
||||||
|
|
@ -131,7 +131,7 @@ AstNodeDType* V3ParseGrammar::createArray(AstNodeDType* basep,
|
||||||
return arrayp;
|
return arrayp;
|
||||||
}
|
}
|
||||||
|
|
||||||
AstVar* V3ParseGrammar::createVariable(FileLine* fileline, string name,
|
AstVar* V3ParseGrammar::createVariable(FileLine* fileline, const string& name,
|
||||||
AstNodeRange* arrayp, AstNode* attrsp) {
|
AstNodeRange* arrayp, AstNode* attrsp) {
|
||||||
AstNodeDType* dtypep = GRAMMARP->m_varDTypep;
|
AstNodeDType* dtypep = GRAMMARP->m_varDTypep;
|
||||||
UINFO(5," creVar "<<name<<" decl="<<GRAMMARP->m_varDecl
|
UINFO(5," creVar "<<name<<" decl="<<GRAMMARP->m_varDecl
|
||||||
|
|
|
||||||
|
|
@ -225,7 +225,6 @@ void V3ParseImp::parseFile(FileLine* fileline, const string& modfilename, bool i
|
||||||
string modname = V3Os::filenameNonExt(modfilename);
|
string modname = V3Os::filenameNonExt(modfilename);
|
||||||
|
|
||||||
UINFO(2,__FUNCTION__<<": "<<modname<<(inLibrary?" [LIB]":"")<<endl);
|
UINFO(2,__FUNCTION__<<": "<<modname<<(inLibrary?" [LIB]":"")<<endl);
|
||||||
VFileContent* contentp = new VFileContent;
|
|
||||||
m_fileline = new FileLine(fileline);
|
m_fileline = new FileLine(fileline);
|
||||||
m_fileline->newContent();
|
m_fileline->newContent();
|
||||||
m_inLibrary = inLibrary;
|
m_inLibrary = inLibrary;
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,10 @@ our $Opt_Debug;
|
||||||
autoflush STDOUT 1;
|
autoflush STDOUT 1;
|
||||||
autoflush STDERR 1;
|
autoflush STDERR 1;
|
||||||
Getopt::Long::config("no_auto_abbrev","pass_through");
|
Getopt::Long::config("no_auto_abbrev","pass_through");
|
||||||
our @Opt_Args = ("cppcheck", @ARGV);
|
our @Opt_Args = ("cppcheck", grep { $_ ne "--debug" } @ARGV);
|
||||||
if (! GetOptions(
|
if (! GetOptions(
|
||||||
# Local options
|
# Local options
|
||||||
|
"debug!" => sub { $Debug = 9; },
|
||||||
"help" => \&usage,
|
"help" => \&usage,
|
||||||
"version" => sub { print "Version $VERSION\n"; system("cppcheck","--version"); exit(0); },
|
"version" => sub { print "Version $VERSION\n"; system("cppcheck","--version"); exit(0); },
|
||||||
)) {
|
)) {
|
||||||
|
|
@ -54,6 +55,7 @@ sub process {
|
||||||
my %errs;
|
my %errs;
|
||||||
my $last_error = "";
|
my $last_error = "";
|
||||||
while (defined(my $line = $fh->getline())) {
|
while (defined(my $line = $fh->getline())) {
|
||||||
|
print ">>>$line" if $Debug;
|
||||||
$line =~ s/^\s+//;
|
$line =~ s/^\s+//;
|
||||||
$line =~ s/Checking usage of global functions\.+//; # Sometimes tacked at end-of-line
|
$line =~ s/Checking usage of global functions\.+//; # Sometimes tacked at end-of-line
|
||||||
# General gunk
|
# General gunk
|
||||||
|
|
@ -85,6 +87,7 @@ sub process {
|
||||||
# --xml-format=1
|
# --xml-format=1
|
||||||
if ($line =~ /file="([^"]+)"\s+line="(\d+)"\s+id="([^"]+)"/) {
|
if ($line =~ /file="([^"]+)"\s+line="(\d+)"\s+id="([^"]+)"/) {
|
||||||
my $file = $1; my $linenum = $2; my $id = $3;
|
my $file = $1; my $linenum = $2; my $id = $3;
|
||||||
|
#$file = $1 if $line =~ /file0="([^"]+)"/; # Still incorrect
|
||||||
$suppress = 1 if _suppress($file,$linenum,$id);
|
$suppress = 1 if _suppress($file,$linenum,$id);
|
||||||
}
|
}
|
||||||
# --xml-format=2
|
# --xml-format=2
|
||||||
|
|
@ -95,6 +98,7 @@ sub process {
|
||||||
}
|
}
|
||||||
elsif ($line =~ /<location.* file="([^"]+)"\s+line="(\d+)"/) {
|
elsif ($line =~ /<location.* file="([^"]+)"\s+line="(\d+)"/) {
|
||||||
my $file = $1; my $linenum = $2; my $id;
|
my $file = $1; my $linenum = $2; my $id;
|
||||||
|
#$file = $1 if $line =~ /file0="([^"]+)"/; # Still incorrect
|
||||||
if ($last_error =~ / id="([^"]+)"/) {
|
if ($last_error =~ / id="([^"]+)"/) {
|
||||||
$id = $1;
|
$id = $1;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -98,9 +98,9 @@ public:
|
||||||
}
|
}
|
||||||
AstRange* scrubRange(AstNodeRange* rangep);
|
AstRange* scrubRange(AstNodeRange* rangep);
|
||||||
AstNodeDType* createArray(AstNodeDType* basep, AstNodeRange* rangep, bool isPacked);
|
AstNodeDType* createArray(AstNodeDType* basep, AstNodeRange* rangep, bool isPacked);
|
||||||
AstVar* createVariable(FileLine* fileline, string name, AstNodeRange* arrayp, AstNode* attrsp);
|
AstVar* createVariable(FileLine* fileline, const string& name, AstNodeRange* arrayp, AstNode* attrsp);
|
||||||
AstNode* createSupplyExpr(FileLine* fileline, string name, int value);
|
AstNode* createSupplyExpr(FileLine* fileline, const string& name, int value);
|
||||||
AstText* createTextQuoted(FileLine* fileline, string text) {
|
AstText* createTextQuoted(FileLine* fileline, const string& text) {
|
||||||
string newtext = deQuote(fileline, text);
|
string newtext = deQuote(fileline, text);
|
||||||
return new AstText(fileline, newtext);
|
return new AstText(fileline, newtext);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue