Internals: cppcheck 1.90 fixes. No functional change intended.

This commit is contained in:
Wilson Snyder 2020-04-05 18:30:46 -04:00
parent ff31abe341
commit 50535a1894
23 changed files with 116 additions and 93 deletions

View File

@ -857,9 +857,12 @@ void _vl_vsformat(std::string& output, const char* formatp, va_list ap) VL_MT_SA
}
}
static inline bool _vl_vsss_eof(FILE* fp, int& floc) VL_MT_SAFE {
if (fp) return feof(fp) ? 1 : 0; // 1:0 to prevent MSVC++ warning
else return (floc<0);
static inline bool _vl_vsss_eof(FILE* fp, int floc) VL_MT_SAFE {
if (fp) {
return feof(fp) ? 1 : 0; // 1:0 to prevent MSVC++ warning
} else {
return floc < 0;
}
}
static inline void _vl_vsss_advance(FILE* fp, int& floc) VL_MT_SAFE {
if (fp) fgetc(fp);
@ -1689,7 +1692,6 @@ bool VlReadMem::get(QData& addrr, std::string& valuer) {
if (c == '_') continue; // Ignore _ e.g. inside a number
if (indata && !isxdigit(c) && c != 'x' && c != 'X') {
// printf("Got data @%lx = %s\n", m_addr, valuer.c_str());
indata = false;
ungetc(c, m_fp);
addrr = m_addr;
++m_addr;
@ -1860,8 +1862,6 @@ void VL_READMEM_N(bool hex, // Hex format, else binary
) VL_MT_SAFE {
QData addr_max = array_lsb + depth - 1;
if (start < static_cast<QData>(array_lsb)) start = array_lsb;
QData addr_end = end;
if (addr_end > addr_max) addr_end = addr_max;
VlReadMem rmem(hex, bits, filename, start, end);
if (VL_UNLIKELY(!rmem.isOpen())) return;

View File

@ -85,7 +85,9 @@ template <std::size_t T_Words> class VlWide {
WData m_storage[T_Words];
public:
// Default constructor/destructor/copy are fine
// cppcheck-suppress uninitVar
VlWide() {}
~VlWide() {}
const WData& at(size_t index) const { return m_storage[index]; }
WData& at(size_t index) { return m_storage[index]; }
WData* data() { return &m_storage[0]; }

View File

@ -142,6 +142,7 @@ void VlThreadPool::profileDump(const char* filenamep, vluint64_t ticksElapsed) {
FILE* fp = fopen(filenamep, "w");
if (VL_UNLIKELY(!fp)) {
VL_FATAL_MT(filenamep, 0, "", "+prof+threads+file file not writable");
// cppcheck-suppress resourceLeak // bug, doesn't realize fp is nullptr
return;
}

View File

@ -930,15 +930,14 @@ const char* VerilatedVpiError::strFromVpiProp(PLI_INT32 vpiVal) VL_MT_SAFE {
#define CHECK_RESULT_CSTR(got, exp) \
if (strcmp((got), (exp))) { \
std::string msg = std::string("%Error: ") \
+ "GOT = '"+((got)?(got):"<null>")+"'" \
+ " EXP = '"+((exp)?(exp):"<null>")+"'"; \
VL_FATAL_MT(__FILE__, __LINE__, "", msg.c_str()); \
std::string msg \
= std::string("%Error: ") + "GOT = '" + got + "'" + " EXP = '" + exp + "'"; \
VL_FATAL_MT(__FILE__, __LINE__, "", msg.c_str()); \
}
#define CHECK_ENUM_STR(fn, enum) \
do { \
const char* strVal = VerilatedVpiError::fn(enum); \
const char* strVal = VerilatedVpiError::fn(enum); \
CHECK_RESULT_CSTR(strVal, #enum); \
} while (0)

View File

@ -255,7 +255,8 @@ class AstClassPackage : public AstNodeModule {
AstClass* m_classp; // Class package this is under (weak pointer, hard link is other way)
public:
AstClassPackage(FileLine* fl, const string& name)
: ASTGEN_SUPER(fl, name) {}
: ASTGEN_SUPER(fl, name)
, m_classp(NULL) {}
ASTNODE_NODE_FUNCS(ClassPackage)
virtual string verilogKwd() const { return "/*class*/package"; }
virtual const char* broken() const;
@ -948,8 +949,11 @@ public:
virtual void virtRefDTypep(AstNodeDType* nodep) { refDTypep(nodep); }
// METHODS
virtual AstBasicDType* basicp() const { return NULL; }
// cppcheck-suppress csyleCast
virtual AstNodeDType* skipRefp() const { return (AstNodeDType*)this; }
// cppcheck-suppress csyleCast
virtual AstNodeDType* skipRefToConstp() const { return (AstNodeDType*)this; }
// cppcheck-suppress csyleCast
virtual AstNodeDType* skipRefToEnump() const { return (AstNodeDType*)this; }
virtual int widthAlignBytes() const { return subDTypep()->widthAlignBytes(); }
virtual int widthTotalBytes() const { return subDTypep()->widthTotalBytes(); }
@ -1111,8 +1115,11 @@ public:
virtual void virtRefDTypep(AstNodeDType* nodep) { }
virtual bool similarDType(AstNodeDType* samep) const { return this==samep; }
virtual AstBasicDType* basicp() const { return NULL; }
// cppcheck-suppress csyleCast
virtual AstNodeDType* skipRefp() const { return (AstNodeDType*)this; }
// cppcheck-suppress csyleCast
virtual AstNodeDType* skipRefToConstp() const { return (AstNodeDType*)this; }
// cppcheck-suppress csyleCast
virtual AstNodeDType* skipRefToEnump() const { return (AstNodeDType*)this; }
virtual int widthAlignBytes() const { return 1; }
virtual int widthTotalBytes() const { return 1; }
@ -1207,6 +1214,7 @@ public:
virtual AstBasicDType* basicp() const { return subDTypep()->basicp(); } // (Slow) recurse down to find basic data type
virtual AstNodeDType* skipRefp() const { return subDTypep()->skipRefp(); }
virtual AstNodeDType* skipRefToConstp() const { return subDTypep()->skipRefToConstp(); }
// cppcheck-suppress csyleCast
virtual AstNodeDType* skipRefToEnump() const { return (AstNodeDType*)this; }
virtual int widthAlignBytes() const { return subDTypep()->widthAlignBytes(); }
virtual int widthTotalBytes() const { return subDTypep()->widthTotalBytes(); }
@ -1225,7 +1233,9 @@ public:
virtual bool similarDType(AstNodeDType* samep) const { return this==samep; }
virtual AstBasicDType* basicp() const { return NULL; }
virtual AstNodeDType* skipRefp() const { return NULL; }
// cppcheck-suppress csyleCast
virtual AstNodeDType* skipRefToConstp() const { return (AstNodeDType*)this; }
// cppcheck-suppress csyleCast
virtual AstNodeDType* skipRefToEnump() const { return (AstNodeDType*)this; }
virtual int widthAlignBytes() const { return 0; }
virtual int widthTotalBytes() const { return 0; }

View File

@ -87,6 +87,7 @@ public:
}
static void addInTree(AstNode* nodep, bool linkable) {
#ifndef VL_LEAK_CHECKS
// cppcheck-suppress knownConditionTrueFalse
if (!linkable) return; // save some time, else the map will get huge!
#endif
NodeMap::iterator iter = s_nodes.find(nodep);

View File

@ -178,7 +178,7 @@ class CUseVisitor : public AstNVisitor {
if (nodep->extendsp() && nodep->extendsp()->classp()->user1()) {
string stmt = "out += \"";
if (!comma.empty()) stmt += "\", \"+ ";
comma = ", ";
// comma = ", "; // Nothing further so not needed
stmt += nodep->extendsp()->dtypep()->nameProtect();
stmt += "::to_string_middle();\n";
nodep->user1(true); // So what we extend dumps this

View File

@ -1878,9 +1878,8 @@ void EmitCStmts::displayEmit(AstNode* nodep, bool isScan) {
putbs(",");
iterate(dispp->lhsp());
putbs(",");
} else if (const AstSFormatF* dispp = VN_CAST(nodep, SFormatF)) {
} else if (VN_IS(nodep, SFormatF)) {
isStmt = false;
if (dispp) {}
puts("VL_SFORMATF_NX(");
} else {
nodep->v3fatalSrc("Unknown displayEmit node type");
@ -2916,11 +2915,13 @@ void EmitCImp::emitInt(AstNodeModule* modp) {
puts("\n// INTERNAL METHODS\n");
if (modp->isTop()) {
ofp()->putsPrivate(true); // private:
puts("static void "+protect("_eval_initial_loop")
+"("+EmitCBaseVisitor::symClassVar()+");\n");
if (v3Global.needTraceDumper() && !optSystemC()) puts("void _traceDump();");
if (v3Global.needTraceDumper()) puts("void _traceDumpOpen();");
if (v3Global.needTraceDumper()) puts("void _traceDumpClose();");
puts("static void " + protect("_eval_initial_loop") + "(" + EmitCBaseVisitor::symClassVar()
+ ");\n");
if (v3Global.needTraceDumper()) {
if (!optSystemC()) puts("void _traceDump();");
puts("void _traceDumpOpen();");
puts("void _traceDumpClose();");
}
}
if (!VN_IS(modp, Class)) {

View File

@ -116,6 +116,7 @@ public:
// ACCESSOR METHODS
void addSrcDepend(const string& filename) {
if (m_filenameSet.find(filename) == m_filenameSet.end()) {
// cppcheck-suppress stlFindInsert // cppcheck 1.90 bug
m_filenameSet.insert(filename);
DependFile df (filename, false);
df.loadStats(); // Get size now, in case changes during the run
@ -124,6 +125,7 @@ public:
}
void addTgtDepend(const string& filename) {
if (m_filenameSet.find(filename) == m_filenameSet.end()) {
// cppcheck-suppress stlFindInsert // cppcheck 1.90 bug
m_filenameSet.insert(filename);
m_filenameList.insert(DependFile(filename, true));
}

View File

@ -155,6 +155,11 @@ FileLine::FileLine(FileLine::EmptySecret) {
}
}
void FileLine::newContent() {
m_contentp = new VFileContent;
m_contentLineno = 1;
}
const string FileLine::xmlDetailedLocation() const {
return "loc=\"" +
cvtToStr(filenameLetters()) + "," +

View File

@ -115,26 +115,26 @@ private:
return *defFilelinep;
}
public:
explicit FileLine(const string& filename) {
m_lastLineno = m_firstLineno = 0;
m_lastColumn = m_firstColumn = 0;
m_filenameno = singleton().nameToNumber(filename);
m_contentLineno = 0;
m_contentp = NULL;
m_parent = NULL;
m_warnOn = defaultFileLine().m_warnOn;
}
explicit FileLine(FileLine* fromp) {
m_firstLineno = fromp->m_firstLineno;
m_firstColumn = fromp->m_firstColumn;
m_lastLineno = fromp->m_lastLineno;
m_lastColumn = fromp->m_lastColumn;
m_filenameno = fromp->m_filenameno;
m_contentLineno = fromp->m_contentLineno;
m_contentp = fromp->m_contentp;
m_parent = fromp->m_parent;
m_warnOn = fromp->m_warnOn;
}
explicit FileLine(const string& filename)
: m_firstLineno(0)
, m_firstColumn(0)
, m_lastLineno(0)
, m_lastColumn(0)
, m_filenameno(singleton().nameToNumber(filename))
, m_contentLineno(0)
, m_contentp(NULL)
, m_parent(NULL)
, m_warnOn(defaultFileLine().m_warnOn) {}
explicit FileLine(FileLine* fromp)
: m_firstLineno(fromp->m_firstLineno)
, m_firstColumn(fromp->m_firstColumn)
, m_lastLineno(fromp->m_lastLineno)
, m_lastColumn(fromp->m_lastColumn)
, m_filenameno(fromp->m_filenameno)
, m_contentLineno(fromp->m_contentLineno)
, m_contentp(fromp->m_contentp)
, m_parent(fromp->m_parent)
, m_warnOn(fromp->m_warnOn) {}
struct EmptySecret {}; // Constructor selection
explicit FileLine(EmptySecret);
FileLine* copyOrSameFileLine();
@ -144,8 +144,8 @@ public:
static void* operator new(size_t size);
static void operator delete(void* obj, size_t size);
#endif
void newContent() { m_contentp = new VFileContent; m_contentLineno = 1; }
// METHODS
void newContent();
void lineno(int num) { m_firstLineno = num; m_lastLineno = num;
m_firstColumn = m_lastColumn = 1; }
void language(V3LangCode lang) { singleton().numberToLang(m_filenameno, lang); }

View File

@ -83,22 +83,21 @@ public:
// Options
V3Options opt; // All options; let user see them directly
public:
public:
// CONSTRUCTORS
V3Global() {
m_debugFileNumber = 0;
m_widthMinUsage = VWidthMinUsage::LINT_WIDTH;
m_assertDTypesResolved = false;
m_constRemoveXs = false;
m_needC11 = false;
m_needHInlines = false;
m_needHeavy = false;
m_needTraceDumper = false;
m_dpi = false;
m_rootp = NULL; // created by makeInitNetlist() so static constructors run first
}
V3Global()
: m_rootp(NULL) // created by makeInitNetlist() so static constructors run first
, m_widthMinUsage(VWidthMinUsage::LINT_WIDTH)
, m_debugFileNumber(0)
, m_assertDTypesResolved(false)
, m_constRemoveXs(false)
, m_needC11(false)
, m_needHInlines(false)
, m_needHeavy(false)
, m_needTraceDumper(false)
, m_dpi(false) {}
AstNetlist* makeNetlist();
void boot() { UASSERT(!m_rootp,"call once"); m_rootp = makeNetlist(); }
void boot() { UASSERT(!m_rootp, "call once"); m_rootp = makeNetlist(); }
void clear();
// ACCESSORS (general)
AstNetlist* rootp() const { return m_rootp; }

View File

@ -108,7 +108,6 @@ private:
m_setRefLvalue = true;
iterateAndNextNull(nodep->filep());
iterateAndNextNull(nodep->strp());
m_setRefLvalue = false;
}
m_setRefLvalue = last_setRefLvalue;
}

View File

@ -74,6 +74,7 @@ private:
// METHODS
virtual void visit(AstVarRef* nodep) VL_OVERRIDE {
// cppcheck-suppress unreadVariable // cppcheck 1.90 bug
VarFlags flags (nodep->varp());
if (flags.m_done) {
nodep->hiername(""); // Remove this->

View File

@ -457,14 +457,14 @@ string V3Number::ascii(bool prefixed, bool cleanVerilog) const {
);
//out<<"-"<<hex<<m_value[0]<<"-";
// cppcheck-suppress konwnConditionTrueFalse
if (binary) {
out<<"b";
out<<displayed("%0b");
}
else {
if (prefixed) out<<"h";
out << "b";
out << displayed("%0b");
} else {
if (prefixed) out << "h";
// Always deal with 4 bits at once. Note no 4-state, it's above.
out<<displayed("%0h");
out << displayed("%0h");
}
return out.str();
}

View File

@ -66,6 +66,7 @@ public:
// ACCESSOR METHODS
void addIncDirUser(const string& incdir) {
if (m_incDirUserSet.find(incdir) == m_incDirUserSet.end()) {
// cppcheck-suppress stlFindInsert // cppcheck 1.90 bug
m_incDirUserSet.insert(incdir);
m_incDirUsers.push_back(incdir);
m_incDirFallbacks.remove(incdir); // User has priority over Fallback
@ -75,6 +76,7 @@ public:
void addIncDirFallback(const string& incdir) {
if (m_incDirUserSet.find(incdir) == m_incDirUserSet.end()) { // User has priority over Fallback
if (m_incDirFallbackSet.find(incdir) == m_incDirFallbackSet.end()) {
// cppcheck-suppress stlFindInsert // cppcheck 1.90 bug
m_incDirFallbackSet.insert(incdir);
m_incDirFallbacks.push_back(incdir);
}
@ -88,6 +90,7 @@ public:
void addLibExtV(const string& libext) {
if (m_libExtVSet.find(libext) == m_libExtVSet.end()) {
// cppcheck-suppress stlFindInsert // cppcheck 1.90 bug
m_libExtVSet.insert(libext);
m_libExtVs.push_back(libext);
}

View File

@ -237,14 +237,14 @@ private:
// Process interface cells, then non-interface which may ref an interface cell
for (int nonIf=0; nonIf<2; ++nonIf) {
for (CellList::iterator it=m_cellps.begin(); it!=m_cellps.end(); ++it) {
AstCell* nodep = *it;
if ((nonIf==0 && VN_IS(nodep->modp(), Iface))
|| (nonIf==1 && !VN_IS(nodep->modp(), Iface))) {
AstCell* cellp = *it;
if ((nonIf==0 && VN_IS(cellp->modp(), Iface))
|| (nonIf==1 && !VN_IS(cellp->modp(), Iface))) {
string fullName (m_modp->hierName());
if (string* genHierNamep = (string *) nodep->user5p()) {
if (string* genHierNamep = (string *) cellp->user5p()) {
fullName += *genHierNamep;
}
visitCell(nodep, fullName);
visitCell(cellp, fullName);
}
}
}

View File

@ -273,11 +273,11 @@ private:
}
public:
AstNode* fetchValueNull(AstNode* nodep) {
return (AstNode*)(nodep->user3p());
return nodep->user3p();
}
private:
AstNode* fetchOutValueNull(AstNode* nodep) {
return (AstNode*)(nodep->user2p());
return nodep->user2p();
}
AstConst* fetchConstNull(AstNode* nodep) {
return VN_CAST(fetchValueNull(nodep), Const);

View File

@ -732,19 +732,19 @@ class SplitUnpackedVarVisitor : public AstNVisitor, public SplitVarImpl {
sit->lvalue());
} else {
AstVarRef* refp = VN_CAST(sit->nodep(), VarRef);
AstUnpackArrayDType* dtypep;
AstUnpackArrayDType* adtypep;
int lsb = 0;
if (refp) {
dtypep = VN_CAST(refp->dtypep()->skipRefp(), UnpackArrayDType);
adtypep = VN_CAST(refp->dtypep()->skipRefp(), UnpackArrayDType);
} else {
AstSliceSel* selp = VN_CAST(sit->nodep(), SliceSel);
UASSERT_OBJ(selp, sit->nodep(), "Unexpected op is registered");
refp = VN_CAST(selp->fromp(), VarRef);
UASSERT_OBJ(refp, selp, "Unexpected op is registered");
dtypep = VN_CAST(selp->dtypep()->skipRefp(), UnpackArrayDType);
lsb = dtypep->lsb();
adtypep = VN_CAST(selp->dtypep()->skipRefp(), UnpackArrayDType);
lsb = adtypep->lsb();
}
AstVarRef* newrefp = createTempVar(sit->context(), refp, dtypep, varp->name(),
AstVarRef* newrefp = createTempVar(sit->context(), refp, adtypep, varp->name(),
vars, lsb, refp->lvalue(), sit->ftask());
newp = newrefp;
refp->varp()->addNextHere(newrefp->varp());

View File

@ -97,10 +97,10 @@ public:
~VSymEnt() {
// Change links so we coredump if used
#ifdef VL_DEBUG
m_nodep = (AstNode*)1;
m_fallbackp = (VSymEnt*)1;
m_parentp = (VSymEnt*)1;
m_packagep = (AstPackage*)1;
m_nodep = reinterpret_cast<AstNode*>(1);
m_fallbackp = reinterpret_cast<VSymEnt*>(1);
m_parentp = reinterpret_cast<VSymEnt*>(1);
m_packagep = reinterpret_cast<AstPackage*>(1);
#endif
}
#if defined(VL_DEBUG) && !defined(VL_LEAK_CHECKS)

View File

@ -526,14 +526,15 @@ private:
// Even if it's referencing a varref, we still make a temporary
// Else task(x,x,x) might produce incorrect results
AstVarScope* outvscp
= createVarScope(portp, namePrefix+"__"+portp->shortName());
portp->user2p(outvscp);
pinp->replaceWith(new AstVarRef(outvscp->fileline(), outvscp, true));
AstAssign* assp = new AstAssign(pinp->fileline(),
pinp,
new AstVarRef(outvscp->fileline(), outvscp, false));
assp->fileline()->modifyWarnOff(V3ErrorCode::BLKSEQ, true); // Ok if in <= block
AstVarScope* newvscp
= createVarScope(portp, namePrefix + "__" + portp->shortName());
portp->user2p(newvscp);
pinp->replaceWith(new AstVarRef(newvscp->fileline(), newvscp, true));
AstAssign* assp
= new AstAssign(pinp->fileline(), pinp,
new AstVarRef(newvscp->fileline(), newvscp, false));
assp->fileline()->modifyWarnOff(V3ErrorCode::BLKSEQ,
true); // Ok if in <= block
// Put assignment BEHIND of all other statements
beginp->addNext(assp);
}

View File

@ -1142,9 +1142,9 @@ private:
default: nodep->v3error("Unhandled attribute type");
}
} else {
std::pair<uint32_t, uint32_t> dimp
std::pair<uint32_t, uint32_t> dimpair
= nodep->fromp()->dtypep()->skipRefp()->dimensions(true);
uint32_t msbdim = dimp.first + dimp.second;
uint32_t msbdim = dimpair.first + dimpair.second;
if (!nodep->dimp() || msbdim < 1) {
int dim = 1;
AstConst* newp = dimensionValue(nodep->fileline(), nodep->fromp()->dtypep(),
@ -2457,7 +2457,6 @@ private:
if (nodep->didWidthAndSet()) return;
AstDynArrayDType* adtypep = VN_CAST(m_vup->dtypeNullp(), DynArrayDType);
if (!adtypep) { // e.g. int a = new;
if (adtypep) UINFO(1, "Got adtypep " << adtypep << endl);
nodep->v3error("dynamic new() not expected in this context (data type must be dynamic array)");
return;
}
@ -4698,11 +4697,10 @@ private:
declRange = VNumRange(); // ranged() set false
if (AstNodeArrayDType* adtypep = VN_CAST(dtypep, NodeArrayDType)) {
declRange = adtypep->declRange();
if (i<dim) dtypep = adtypep->subDTypep()->skipRefp();
if (i < dim) dtypep = adtypep->subDTypep()->skipRefp();
continue;
} else if (AstNodeUOrStructDType* adtypep = VN_CAST(dtypep, NodeUOrStructDType)) {
declRange = adtypep->declRange();
if (adtypep) {} // UNUSED
break; // Sub elements don't look like arrays and can't iterate into
} else if (AstBasicDType* adtypep = VN_CAST(dtypep, BasicDType)) {
if (adtypep->isRanged()) declRange = adtypep->declRange();

View File

@ -40,8 +40,9 @@ private:
if (m_dataSize < point) m_dataSize = (point + 64) & ~63ULL; // Keep power of two
m_dataSize *= 2;
// UINFO(9, "Realloc "<<allocSize()<<" for "<<point<<" "<<cvtToHex(m_datap)<<endl);
vluint64_t* newp = (vluint64_t*)realloc(m_datap, allocSize());
vluint64_t* newp = static_cast<vluint64_t*>(realloc(m_datap, allocSize()));
if (!newp) {
// cppcheck-suppress doubleFree // cppcheck 1.90 bug - realloc doesn't free on fail
free(m_datap);
v3fatal("Out of memory increasing buckets");
}