forked from github/verilator
cppcheck fixes
This commit is contained in:
parent
4a5a56f8ef
commit
f07f6a26a8
@ -398,14 +398,17 @@ endif
|
||||
# VERILATOR_AUTHOR_SITE
|
||||
endif
|
||||
|
||||
# Use --xml flag to see the cppcheck code to use for suppression
|
||||
CPPCHECK = cppcheck
|
||||
CPPCHECK_FLAGS = --enable=all --inline-suppr --suppress=unusedScopedObject
|
||||
CPPCHECK_FLAGS = --enable=all --inline-suppr --suppress=unusedScopedObject --suppress=cstyleCast
|
||||
CPPCHECK_FLAGS += --xml
|
||||
CPPCHECK_CPP = $(wildcard $(srcdir)/include/*.cpp $(srcdir)/src/*.cpp)
|
||||
CPPCHECK_DEP = $(subst .cpp,.cppcheck,$(CPPCHECK_CPP))
|
||||
CPPCHECK_INC = -I$(srcdir)/include -I$(srcdir)/src/obj_dbg -I$(srcdir)/src
|
||||
|
||||
cppcheck: $(CPPCHECK_DEP)
|
||||
%.cppcheck: %.cpp
|
||||
$(CPPCHECK) $(CPPCHECK_FLAGS) -DVL_DEBUG=1 -I$(srcdir)/include -I$(srcdir)/src $<
|
||||
$(CPPCHECK) $(CPPCHECK_FLAGS) -DVL_DEBUG=1 $(CPPCHECK_INC) $<
|
||||
|
||||
ftp: info
|
||||
|
||||
|
@ -603,7 +603,7 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf
|
||||
_vl_vsss_read(fp,floc,fromp, tmp, "0123456789+-xXzZ?_");
|
||||
if (!tmp[0]) goto done;
|
||||
vlsint64_t ld;
|
||||
sscanf(tmp,"%" VL_PRI64 "d",&ld);
|
||||
sscanf(tmp,"%30" VL_PRI64 "d",&ld);
|
||||
VL_SET_WQ(owp,ld);
|
||||
break;
|
||||
}
|
||||
@ -624,7 +624,7 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf
|
||||
_vl_vsss_read(fp,floc,fromp, tmp, "0123456789+-xXzZ?_");
|
||||
if (!tmp[0]) goto done;
|
||||
QData ld;
|
||||
sscanf(tmp,"%" VL_PRI64 "u",&ld);
|
||||
sscanf(tmp,"%30" VL_PRI64 "u",&ld);
|
||||
VL_SET_WQ(owp,ld);
|
||||
break;
|
||||
}
|
||||
@ -977,7 +977,7 @@ IData VL_VALUEPLUSARGS_IW(int rbits, const char* prefixp, char fmt, WDataOutP rw
|
||||
break;
|
||||
case 'd':
|
||||
vlsint64_t ld;
|
||||
sscanf(dp,"%" VL_PRI64 "d",&ld);
|
||||
sscanf(dp,"%30" VL_PRI64 "d",&ld);
|
||||
VL_SET_WQ(rwp,ld);
|
||||
break;
|
||||
case 'b':
|
||||
@ -1101,6 +1101,7 @@ VerilatedModule::~VerilatedModule() {
|
||||
//======================================================================
|
||||
// VerilatedVar:: Methods
|
||||
|
||||
// cppcheck-suppress unusedFunction // Used by applications
|
||||
vluint32_t VerilatedVar::entSize() const {
|
||||
vluint32_t size = 1;
|
||||
switch (vltype()) {
|
||||
@ -1197,6 +1198,7 @@ void VerilatedScope::varInsert(int finalize, const char* namep, void* datap,
|
||||
m_varsp->insert(make_pair(namep,var));
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction // Used by applications
|
||||
VerilatedVar* VerilatedScope::varFind(const char* namep) const {
|
||||
if (VL_LIKELY(m_varsp)) {
|
||||
VerilatedVarNameMap::iterator it = m_varsp->find(namep);
|
||||
|
@ -104,9 +104,6 @@ int svHigh(const svOpenArrayHandle h, int d) {
|
||||
int svIncrement(const svOpenArrayHandle h, int d) {
|
||||
_VL_SVDPI_UNIMP(); return 0;
|
||||
}
|
||||
int svLength(const svOpenArrayHandle h, int d) {
|
||||
_VL_SVDPI_UNIMP(); return 0;
|
||||
}
|
||||
int svDimensions(const svOpenArrayHandle h) {
|
||||
_VL_SVDPI_UNIMP(); return 0;
|
||||
}
|
||||
|
@ -116,6 +116,7 @@ void VerilatedSave::open (const char* filenamep) {
|
||||
if (filenamep[0]=='|') {
|
||||
assert(0); // Not supported yet.
|
||||
} else {
|
||||
// cppcheck-suppress duplicateExpression
|
||||
m_fd = ::open (filenamep, O_CREAT|O_WRONLY|O_TRUNC|O_LARGEFILE|O_NONBLOCK
|
||||
, 0666);
|
||||
if (m_fd<0) {
|
||||
@ -137,6 +138,7 @@ void VerilatedRestore::open (const char* filenamep) {
|
||||
if (filenamep[0]=='|') {
|
||||
assert(0); // Not supported yet.
|
||||
} else {
|
||||
// cppcheck-suppress duplicateExpression
|
||||
m_fd = ::open (filenamep, O_CREAT|O_RDONLY|O_LARGEFILE
|
||||
, 0666);
|
||||
if (m_fd<0) {
|
||||
|
@ -109,7 +109,7 @@ protected:
|
||||
void trailer();
|
||||
public:
|
||||
// CREATORS
|
||||
VerilatedDeserialize() {}
|
||||
VerilatedDeserialize() { m_endp = NULL; }
|
||||
virtual ~VerilatedDeserialize() { close(); }
|
||||
// METHODS
|
||||
inline VerilatedDeserialize& read (void* __restrict datap, size_t size) {
|
||||
@ -146,7 +146,7 @@ private:
|
||||
|
||||
public:
|
||||
// CREATORS
|
||||
VerilatedSave() {}
|
||||
VerilatedSave() { m_fd=-1; }
|
||||
virtual ~VerilatedSave() { close(); }
|
||||
// METHODS
|
||||
void open(const char* filenamep); ///< Open the file; call isOpen() to see if errors
|
||||
@ -164,7 +164,7 @@ private:
|
||||
|
||||
public:
|
||||
// CREATORS
|
||||
VerilatedRestore() {}
|
||||
VerilatedRestore() { m_fd=-1; }
|
||||
virtual ~VerilatedRestore() { close(); }
|
||||
|
||||
// METHODS
|
||||
|
@ -141,6 +141,7 @@ void VerilatedVcd::openNext (bool incFilename) {
|
||||
if (m_filename[0]=='|') {
|
||||
assert(0); // Not supported yet.
|
||||
} else {
|
||||
// cppcheck-suppress duplicateExpression
|
||||
m_fd = ::open (m_filename.c_str(), O_CREAT|O_WRONLY|O_TRUNC|O_LARGEFILE|O_NONBLOCK
|
||||
, 0666);
|
||||
if (m_fd<0) {
|
||||
|
@ -274,7 +274,7 @@ class VerilatedVpi {
|
||||
static VerilatedVpi s_s; // Singleton
|
||||
|
||||
public:
|
||||
VerilatedVpi() {}
|
||||
VerilatedVpi() { m_errorInfop=NULL; }
|
||||
~VerilatedVpi() {}
|
||||
static void cbReasonAdd(VerilatedVpioCb* vop) {
|
||||
if (vop->reason() == cbValueChange) {
|
||||
@ -425,7 +425,7 @@ public:
|
||||
vl_fatal(error_info_p->file, error_info_p->line, "", error_info_p->message);
|
||||
return;
|
||||
}
|
||||
vl_fatal(error_info_p->file, error_info_p->line, "", "vpi_unsupported called without error info set");
|
||||
vl_fatal(__FILE__, __LINE__, "", "vpi_unsupported called without error info set");
|
||||
}
|
||||
static const char* strFromVpiVal(PLI_INT32 vpiVal);
|
||||
static const char* strFromVpiObjType(PLI_INT32 vpiVal);
|
||||
@ -875,7 +875,7 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) {
|
||||
val &= (1<<rem)-1;
|
||||
}
|
||||
}
|
||||
outStr[chars-i-1] = hex[val];
|
||||
outStr[chars-i-1] = hex[static_cast<int>(val)];
|
||||
}
|
||||
outStr[i]=0; // NULL terminate
|
||||
return;
|
||||
@ -1097,7 +1097,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value value_p,
|
||||
} else if (value_p->format == vpiDecStrVal) {
|
||||
char remainder[16];
|
||||
unsigned long val;
|
||||
int success = sscanf(value_p->value.str, "%lu%15s", &val, remainder);
|
||||
int success = sscanf(value_p->value.str, "%30lu%15s", &val, remainder);
|
||||
if (success < 1) {
|
||||
_VL_VPI_ERROR(__FILE__, __LINE__, "%s: Parsing failed for '%s' as value %s for %s",
|
||||
VL_FUNC, value_p->value.str, VerilatedVpiError::strFromVpiVal(value_p->format), vop->fullname());
|
||||
|
@ -62,6 +62,7 @@ private:
|
||||
nodep->displayType(AstDisplayType::DT_WRITE);
|
||||
nodep->fmtp()->text(assertDisplayMessage(nodep, prefix, nodep->fmtp()->text()));
|
||||
AstNode* timesp = nodep->fmtp()->exprsp(); if (timesp) timesp->unlinkFrBack();
|
||||
// cppcheck-suppress nullPointer
|
||||
timesp = timesp->addNext(new AstTime(nodep->fileline()));
|
||||
nodep->fmtp()->exprsp(timesp);
|
||||
if (!nodep->fmtp()->scopeNamep() && nodep->fmtp()->formatScopeTracking()) {
|
||||
|
@ -764,6 +764,7 @@ void AstNode::iterateAndNext(AstNVisitor& v, AstNUser* vup) {
|
||||
while (nodep) {
|
||||
AstNode* niterp = nodep; // This address may get stomped via m_iterpp if the node is edited
|
||||
ASTNODE_PREFETCH(nodep->m_nextp);
|
||||
// cppcheck-suppress nullPointer
|
||||
niterp->m_iterpp = &niterp;
|
||||
niterp->accept(v, vup);
|
||||
// accept may do a replaceNode and change niterp on us...
|
||||
|
@ -47,6 +47,7 @@ public:
|
||||
// enum en {...};
|
||||
// const char* ascii() const {...};
|
||||
enum en m_e;
|
||||
// cppcheck-suppress uninitVar // responsiblity of each subclass
|
||||
inline AstType () {}
|
||||
inline AstType (en _e) : m_e(_e) {}
|
||||
explicit inline AstType (int _e) : m_e(static_cast<en>(_e)) {}
|
||||
@ -782,7 +783,7 @@ protected:
|
||||
RelinkWhatEn m_chg;
|
||||
AstNode** m_iterpp;
|
||||
public:
|
||||
AstNRelinker() { m_backp=NULL; m_chg=RELINK_BAD; m_iterpp=NULL;}
|
||||
AstNRelinker() { m_oldp=NULL; m_backp=NULL; m_chg=RELINK_BAD; m_iterpp=NULL;}
|
||||
void relink(AstNode* newp);
|
||||
AstNode* oldp() const { return m_oldp; }
|
||||
void dump(ostream& str=cout) const;
|
||||
@ -1582,7 +1583,9 @@ private:
|
||||
AstNodeDType* m_refDTypep; // Elements of this type (after widthing)
|
||||
AstNode* rangenp() const { return op2p(); } // op2 = Array(s) of variable
|
||||
public:
|
||||
AstNodeArrayDType(FileLine* fl) : AstNodeDType(fl) {}
|
||||
AstNodeArrayDType(FileLine* fl) : AstNodeDType(fl) {
|
||||
m_refDTypep = NULL;
|
||||
}
|
||||
ASTNODE_BASE_FUNCS(NodeArrayDType)
|
||||
virtual void dump(ostream& str);
|
||||
virtual void dumpSmall(ostream& str);
|
||||
|
@ -153,7 +153,7 @@ private:
|
||||
AstNode* addsp = NULL;
|
||||
if (AstNode* stmtsp = nodep->stmtsp()) {
|
||||
stmtsp->unlinkFrBackWithNext();
|
||||
addsp = addsp->addNextNull(stmtsp);
|
||||
if (addsp) { addsp = addsp->addNextNull(stmtsp); } else { addsp = stmtsp; }
|
||||
}
|
||||
if (addsp) {
|
||||
nodep->replaceWith(addsp);
|
||||
|
@ -1404,6 +1404,7 @@ private:
|
||||
for (AstNodeSenItem* nextp, * senp = nodep->sensesp()->castNodeSenItem();
|
||||
senp; senp=nextp) {
|
||||
nextp=senp->nextp()->castNodeSenItem();
|
||||
// cppcheck-suppress unassignedVariable // cppcheck bug
|
||||
SenItemCmp cmp;
|
||||
if (nextp && !cmp(senp, nextp)) {
|
||||
// Something's out of order, sort it
|
||||
|
@ -294,7 +294,7 @@ protected:
|
||||
int nameToNumber(const string& filename);
|
||||
const string numberToName(int filenameno) const { return m_names[filenameno]; }
|
||||
const V3LangCode numberToLang(int filenameno) const { return m_languages[filenameno]; }
|
||||
void numberToLang(int filenameno, const V3LangCode l) { m_languages[filenameno] = l; }
|
||||
void numberToLang(int filenameno, const V3LangCode& l) { m_languages[filenameno] = l; }
|
||||
void clear() { m_namemap.clear(); m_names.clear(); m_languages.clear(); }
|
||||
void fileNameNumMapDumpXml(ostream& os);
|
||||
static const string filenameLetters(int fileno);
|
||||
|
@ -661,7 +661,7 @@ private:
|
||||
// Find under either a task or the module's vars
|
||||
VSymEnt* foundp = m_curSymp->findIdFallback(nodep->name());
|
||||
if (!foundp && m_modSymp && nodep->name() == m_modSymp->nodep()->name()) foundp = m_modSymp; // Conflicts with modname?
|
||||
AstVar* findvarp = foundp->nodep()->castVar();
|
||||
AstVar* findvarp = foundp ? foundp->nodep()->castVar() : NULL;
|
||||
bool ins=false;
|
||||
if (!foundp) {
|
||||
ins=true;
|
||||
@ -730,7 +730,7 @@ private:
|
||||
// Find under either a task or the module's vars
|
||||
VSymEnt* foundp = m_curSymp->findIdFallback(nodep->name());
|
||||
if (!foundp && m_modSymp && nodep->name() == m_modSymp->nodep()->name()) foundp = m_modSymp; // Conflicts with modname?
|
||||
AstEnumItem* findvarp = foundp->nodep()->castEnumItem();
|
||||
AstEnumItem* findvarp = foundp ? foundp->nodep()->castEnumItem() : NULL;
|
||||
bool ins=false;
|
||||
if (!foundp) {
|
||||
ins=true;
|
||||
@ -1503,7 +1503,7 @@ private:
|
||||
VSymEnt* foundp = NULL;
|
||||
AstNodeFTask* taskp = NULL;
|
||||
foundp = m_statep->findSymPrefixed(dotSymp, nodep->name(), baddot);
|
||||
taskp = foundp->nodep()->castNodeFTask(); // Maybe NULL
|
||||
taskp = foundp ? foundp->nodep()->castNodeFTask() : NULL; // Maybe NULL
|
||||
if (taskp) {
|
||||
nodep->taskp(taskp);
|
||||
nodep->packagep(foundp->packagep());
|
||||
|
@ -79,7 +79,7 @@ public:
|
||||
void pushBack (V3List<T>& listr, T newp) {
|
||||
// "this" must be a element inside of *newp
|
||||
// cppcheck-suppress thisSubtraction
|
||||
size_t offset = (vluint8_t*)(this) - (vluint8_t*)(newp);
|
||||
size_t offset = (size_t)(vluint8_t*)(this) - (size_t)(vluint8_t*)(newp);
|
||||
m_nextp = NULL;
|
||||
if (!listr.m_headp) listr.m_headp = newp;
|
||||
m_prevp = listr.m_tailp;
|
||||
@ -89,7 +89,7 @@ public:
|
||||
void pushFront (V3List<T>& listr, T newp) {
|
||||
// "this" must be a element inside of *newp
|
||||
// cppcheck-suppress thisSubtraction
|
||||
size_t offset = (vluint8_t*)(this) - (vluint8_t*)(newp);
|
||||
size_t offset = (size_t)(vluint8_t*)(this) - (size_t)(vluint8_t*)(newp);
|
||||
m_nextp = listr.m_headp;
|
||||
if (m_nextp) baseToListEnt(m_nextp,offset)->m_prevp = newp;
|
||||
listr.m_headp = newp;
|
||||
@ -100,7 +100,7 @@ public:
|
||||
void unlink (V3List<T>& listr, T oldp) {
|
||||
// "this" must be a element inside of *oldp
|
||||
// cppcheck-suppress thisSubtraction
|
||||
size_t offset = (vluint8_t*)(this) - (vluint8_t*)(oldp);
|
||||
size_t offset = (size_t)(vluint8_t*)(this) - (size_t)(vluint8_t*)(oldp);
|
||||
if (m_nextp) baseToListEnt(m_nextp,offset)->m_prevp = m_prevp;
|
||||
else listr.m_tailp = m_prevp;
|
||||
if (m_prevp) baseToListEnt(m_prevp,offset)->m_nextp = m_nextp;
|
||||
|
@ -77,7 +77,7 @@ struct V3OptionsImp {
|
||||
}
|
||||
}
|
||||
}
|
||||
void addLangExt(const string &langext, const V3LangCode lc) {
|
||||
void addLangExt(const string& langext, const V3LangCode& lc) {
|
||||
// New language extension replaces any pre-existing one.
|
||||
(void)m_langExts.erase(langext);
|
||||
m_langExts[langext] = lc;
|
||||
@ -98,7 +98,7 @@ void V3Options::addIncDirUser(const string& incdir) {
|
||||
void V3Options::addIncDirFallback(const string& incdir) {
|
||||
m_impp->addIncDirFallback(incdir);
|
||||
}
|
||||
void V3Options::addLangExt(const string &langext, const V3LangCode lc) {
|
||||
void V3Options::addLangExt(const string& langext, const V3LangCode& lc) {
|
||||
m_impp->addLangExt(langext, lc);
|
||||
}
|
||||
void V3Options::addLibExtV(const string& libext) {
|
||||
@ -1117,7 +1117,7 @@ string V3Options::parseFileArg(const string& optdir, const string& relfilename)
|
||||
//! Utility to see if we have a language extension argument and if so add it.
|
||||
bool V3Options::parseLangExt (const char* swp, //!< argument text
|
||||
const char* langswp, //!< option to match
|
||||
const V3LangCode lc) { //!< language code
|
||||
const V3LangCode& lc) { //!< language code
|
||||
int len = strlen(langswp);
|
||||
if (!strncmp(swp, langswp, len)) {
|
||||
addLangExt(swp + len, lc);
|
||||
|
@ -150,7 +150,7 @@ class V3Options {
|
||||
void addFuture(const string& flag);
|
||||
void addIncDirUser(const string& incdir); // User requested
|
||||
void addIncDirFallback(const string& incdir); // Low priority if not found otherwise
|
||||
void addLangExt(const string &langext, const V3LangCode lc);
|
||||
void addLangExt(const string& langext, const V3LangCode& lc);
|
||||
void addLibExtV(const string& libext);
|
||||
void optimize(int level);
|
||||
void showVersion(bool verbose);
|
||||
@ -158,7 +158,7 @@ class V3Options {
|
||||
bool onoff(const char* sw, const char* arg, bool& flag);
|
||||
bool suffixed(const char* sw, const char* arg);
|
||||
string parseFileArg(const string& optdir, const string& relfilename);
|
||||
bool parseLangExt(const char* swp, const char* langswp, const V3LangCode lc);
|
||||
bool parseLangExt(const char* swp, const char* langswp, const V3LangCode& lc);
|
||||
string filePathCheckOneDir(const string& modname, const string& dirname);
|
||||
|
||||
static string getenvStr(const string& envvar, const string& defaultValue);
|
||||
|
@ -94,8 +94,8 @@ private:
|
||||
if (varp->isGParam()) {
|
||||
char ch = varp->name()[0];
|
||||
ch = toupper(ch); if (ch<'A' || ch>'Z') ch='Z';
|
||||
varp->user4(usedLetter[ch]*256 + ch);
|
||||
usedLetter[ch]++;
|
||||
varp->user4(usedLetter[static_cast<int>(ch)]*256 + ch);
|
||||
usedLetter[static_cast<int>(ch)]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -225,10 +225,10 @@ public:
|
||||
VSymMap doneSyms;
|
||||
os<<"SymEnt Dump:\n";
|
||||
m_symRootp->dumpIterate(os, doneSyms, indent, 9999, "$root");
|
||||
bool first = false;
|
||||
bool first = true;
|
||||
for (SymStack::iterator it = m_symsp.begin(); it != m_symsp.end(); ++it) {
|
||||
if (doneSyms.find(*it) == doneSyms.end()) {
|
||||
if (!first++) os<<"%%Warning: SymEnt Orphans:\n";
|
||||
if (first) { first=false; os<<"%%Warning: SymEnt Orphans:\n"; }
|
||||
(*it)->dumpIterate(os, doneSyms, indent, 9999, "Orphan");
|
||||
}
|
||||
}
|
||||
|
@ -508,7 +508,7 @@ class TristateVisitor : public TristateBaseVisitor {
|
||||
continue;
|
||||
}
|
||||
|
||||
m_statTriSigs++;
|
||||
++m_statTriSigs;
|
||||
m_tgraph.didProcess(invarp);
|
||||
UINFO(8, " TRISTATE EXPANDING:" << invarp << endl);
|
||||
|
||||
|
@ -837,8 +837,8 @@ private:
|
||||
bool didchk = false;
|
||||
bool implicitParam = nodep->isParam() && bdtypep && bdtypep->implicit();
|
||||
if (implicitParam) {
|
||||
int width=0;
|
||||
if (nodep->valuep()) {
|
||||
int width=0;
|
||||
nodep->valuep()->iterateAndNext(*this,WidthVP(width,0,PRELIM).p());
|
||||
UINFO(9,"implicitParamPRELIMIV "<<nodep->valuep()<<endl);
|
||||
// Although nodep will get a different width for parameters just below,
|
||||
|
@ -63,7 +63,6 @@ public:
|
||||
AstPin* m_instParamp; // Parameters for instantiations
|
||||
AstNodeModule* m_modp; // Module
|
||||
int m_modTypeImpNum; // Implicit type number, incremented each module
|
||||
int m_uniqueAttr; // Bitmask of unique/priority keywords
|
||||
|
||||
// CONSTRUCTORS
|
||||
V3ParseGrammar() {
|
||||
|
0
test_regress/t/t_vpi_unimpl.pl
Normal file → Executable file
0
test_regress/t/t_vpi_unimpl.pl
Normal file → Executable file
Loading…
Reference in New Issue
Block a user