Fix cppcheck warnings. No functional change intended.

This commit is contained in:
Wilson Snyder 2020-12-23 15:21:33 -05:00
parent 941e5c659a
commit b7a533109d
19 changed files with 38 additions and 41 deletions

View File

@ -2367,7 +2367,7 @@ static void removeCb(Verilated::VoidPCb cb, void* datap, VoidPCbList& cbs) {
std::pair<Verilated::VoidPCb, void*> pair(cb, datap); std::pair<Verilated::VoidPCb, void*> pair(cb, datap);
cbs.remove(pair); cbs.remove(pair);
} }
static void runCallbacks(VoidPCbList& cbs) VL_MT_SAFE { static void runCallbacks(const VoidPCbList& cbs) VL_MT_SAFE {
for (const auto& i : cbs) i.first(i.second); for (const auto& i : cbs) i.first(i.second);
} }

View File

@ -61,7 +61,7 @@ private:
std::function<void()> m_cb; ///< Lambda to execute when message received std::function<void()> m_cb; ///< Lambda to execute when message received
public: public:
// CONSTRUCTORS // CONSTRUCTORS
VerilatedMsg(const std::function<void()>& cb) explicit VerilatedMsg(const std::function<void()>& cb)
: m_mtaskId{Verilated::mtaskId()} : m_mtaskId{Verilated::mtaskId()}
, m_cb{cb} {} , m_cb{cb} {}
~VerilatedMsg() = default; ~VerilatedMsg() = default;

View File

@ -81,9 +81,9 @@ class VerilatedVarProps VL_NOT_FINAL {
std::vector<VerilatedRange> m_unpacked; // Unpacked array ranges std::vector<VerilatedRange> m_unpacked; // Unpacked array ranges
void initUnpacked(const int* ulims) { void initUnpacked(const int* ulims) {
for (int i = 0; i < m_udims; ++i) { for (int i = 0; i < m_udims; ++i) {
const int left = ulims ? ulims[2 * i + 0] : 0; const int uleft = ulims ? ulims[2 * i + 0] : 0;
const int right = ulims ? ulims[2 * i + 1] : 0; const int uright = ulims ? ulims[2 * i + 1] : 0;
m_unpacked.emplace_back(left, right); m_unpacked.emplace_back(uleft, uright);
} }
} }
// CONSTRUCTORS // CONSTRUCTORS

View File

@ -272,7 +272,7 @@ public:
m_entSize = varp->entSize(); m_entSize = varp->entSize();
m_varDatap = varp->datap(); m_varDatap = varp->datap();
} }
VerilatedVpioVar(const VerilatedVpioVar* varp) { explicit VerilatedVpioVar(const VerilatedVpioVar* varp) {
if (varp) { if (varp) {
m_varp = varp->m_varp; m_varp = varp->m_varp;
m_scopep = varp->m_scopep; m_scopep = varp->m_scopep;

View File

@ -130,7 +130,6 @@ string AstNode::encodeName(const string& namein) {
// Then we also won't need to save the table of hased values // Then we also won't need to save the table of hased values
VName vname{out}; VName vname{out};
return vname.hashedName(); return vname.hashedName();
return out;
} }
string AstNode::encodeNumber(vlsint64_t num) { string AstNode::encodeNumber(vlsint64_t num) {

View File

@ -727,11 +727,13 @@ AstNodeDType* AstNodeDType::dtypeDimensionp(int dimension) {
} else if (AstBasicDType* adtypep = VN_CAST(dtypep, BasicDType)) { } else if (AstBasicDType* adtypep = VN_CAST(dtypep, BasicDType)) {
// AstBasicDType - nothing below, return null // AstBasicDType - nothing below, return null
if (adtypep->isRanged()) { if (adtypep->isRanged()) {
// cppcheck-suppress unreadVariable // Cppcheck bug - thinks dim isn't used
if ((dim++) == dimension) return adtypep; if ((dim++) == dimension) return adtypep;
} }
return nullptr; return nullptr;
} else if (AstNodeUOrStructDType* adtypep = VN_CAST(dtypep, NodeUOrStructDType)) { } else if (AstNodeUOrStructDType* adtypep = VN_CAST(dtypep, NodeUOrStructDType)) {
if (adtypep->packed()) { if (adtypep->packed()) {
// cppcheck-suppress unreadVariable // Cppcheck bug - thinks dim isn't used
if ((dim++) == dimension) return adtypep; if ((dim++) == dimension) return adtypep;
} }
return nullptr; return nullptr;

View File

@ -1976,6 +1976,7 @@ private:
m_attrSFormat = false; m_attrSFormat = false;
m_attrSplitVar = false; m_attrSplitVar = false;
m_fileDescr = false; m_fileDescr = false;
m_isRand = false;
m_isConst = false; m_isConst = false;
m_isStatic = false; m_isStatic = false;
m_isPulldown = false; m_isPulldown = false;
@ -4588,7 +4589,7 @@ public:
class AstDisableFork final : public AstNodeStmt { class AstDisableFork final : public AstNodeStmt {
// A "disable fork" statement // A "disable fork" statement
public: public:
AstDisableFork(FileLine* fl) explicit AstDisableFork(FileLine* fl)
: ASTGEN_SUPER(fl) {} : ASTGEN_SUPER(fl) {}
ASTNODE_NODE_FUNCS(DisableFork) ASTNODE_NODE_FUNCS(DisableFork)
}; };
@ -4596,7 +4597,7 @@ public:
class AstWaitFork final : public AstNodeStmt { class AstWaitFork final : public AstNodeStmt {
// A "wait fork" statement // A "wait fork" statement
public: public:
AstWaitFork(FileLine* fl) explicit AstWaitFork(FileLine* fl)
: ASTGEN_SUPER(fl) {} : ASTGEN_SUPER(fl) {}
ASTNODE_NODE_FUNCS(WaitFork) ASTNODE_NODE_FUNCS(WaitFork)
}; };
@ -4649,7 +4650,7 @@ class AstJumpBlock final : public AstNodeStmt {
// Parents: {statement list} // Parents: {statement list}
// Children: {statement list, with JumpGo and JumpLabel below} // Children: {statement list, with JumpGo and JumpLabel below}
private: private:
AstJumpLabel* m_labelp; // [After V3Jump] Pointer to declaration AstJumpLabel* m_labelp = nullptr; // [After V3Jump] Pointer to declaration
int m_labelNum = 0; // Set by V3EmitCSyms to tell final V3Emit what to increment int m_labelNum = 0; // Set by V3EmitCSyms to tell final V3Emit what to increment
public: public:
// After construction must call ->labelp to associate with appropriate label // After construction must call ->labelp to associate with appropriate label
@ -4835,7 +4836,7 @@ class AstConsDynArray final : public AstNodeMath {
// Parents: math // Parents: math
// Children: expression (elements or other queues) // Children: expression (elements or other queues)
public: public:
AstConsDynArray(FileLine* fl, AstNode* lhsp = nullptr, AstNode* rhsp = nullptr) explicit AstConsDynArray(FileLine* fl, AstNode* lhsp = nullptr, AstNode* rhsp = nullptr)
: ASTGEN_SUPER(fl) { : ASTGEN_SUPER(fl) {
setNOp1p(lhsp); setNOp1p(lhsp);
setNOp2p(rhsp); setNOp2p(rhsp);
@ -4857,7 +4858,7 @@ class AstConsQueue final : public AstNodeMath {
// Parents: math // Parents: math
// Children: expression (elements or other queues) // Children: expression (elements or other queues)
public: public:
AstConsQueue(FileLine* fl, AstNode* lhsp = nullptr, AstNode* rhsp = nullptr) explicit AstConsQueue(FileLine* fl, AstNode* lhsp = nullptr, AstNode* rhsp = nullptr)
: ASTGEN_SUPER(fl) { : ASTGEN_SUPER(fl) {
setNOp1p(lhsp); setNOp1p(lhsp);
setNOp2p(rhsp); setNOp2p(rhsp);
@ -5121,7 +5122,7 @@ class AstPrintTimeScale final : public AstNodeStmt {
string m_name; // Parent module name string m_name; // Parent module name
VTimescale m_timeunit; // Parent module time unit VTimescale m_timeunit; // Parent module time unit
public: public:
AstPrintTimeScale(FileLine* fl) explicit AstPrintTimeScale(FileLine* fl)
: ASTGEN_SUPER(fl) {} : ASTGEN_SUPER(fl) {}
ASTNODE_NODE_FUNCS(PrintTimeScale) ASTNODE_NODE_FUNCS(PrintTimeScale)
virtual void name(const string& name) override { m_name = name; } virtual void name(const string& name) override { m_name = name; }

View File

@ -224,6 +224,7 @@ private:
AstNode* node1p = it->second; AstNode* node1p = it->second;
AstCFunc* cfunc1p = VN_CAST(node1p, CFunc); AstCFunc* cfunc1p = VN_CAST(node1p, CFunc);
if (!cfunc1p) continue; if (!cfunc1p) continue;
// cppcheck-suppress compareBoolExpressionWithInt
if (cfunc1p->slow() != slow) continue; if (cfunc1p->slow() != slow) continue;
V3Hash hashval = it->first; V3Hash hashval = it->first;
UASSERT_OBJ(!hashval.isIllegal(), node1p, "Illegal (unhashed) nodes"); UASSERT_OBJ(!hashval.isIllegal(), node1p, "Illegal (unhashed) nodes");

View File

@ -311,9 +311,6 @@ class EmitMkHierVerilation final {
} }
of.puts("\n"); of.puts("\n");
} }
void emitOpts(V3OutMkFile& of, const V3StringList& opts) const {
for (const string& i : opts) { of.puts("\t\t" + i + " \\\n"); }
}
void emitLaunchVerilator(V3OutMkFile& of, const string& argsFile) const { void emitLaunchVerilator(V3OutMkFile& of, const string& argsFile) const {
of.puts("\t@$(MAKE) -C $(VM_HIER_RUN_DIR) -f " + m_makefile of.puts("\t@$(MAKE) -C $(VM_HIER_RUN_DIR) -f " + m_makefile
+ " hier_launch_verilator \\\n"); + " hier_launch_verilator \\\n");
@ -420,5 +417,5 @@ void V3EmitMk::emitmk() {
void V3EmitMk::emitHierVerilation(const V3HierBlockPlan* planp) { void V3EmitMk::emitHierVerilation(const V3HierBlockPlan* planp) {
UINFO(2, __FUNCTION__ << ": " << endl); UINFO(2, __FUNCTION__ << ": " << endl);
EmitMkHierVerilation emitter(planp); EmitMkHierVerilation{planp};
} }

View File

@ -584,12 +584,12 @@ protected:
} }
return true; return true;
} }
static size_t listSize(StrList& sl) { static size_t listSize(const StrList& sl) {
size_t out = 0; size_t out = 0;
for (const string& i : sl) out += i.length(); for (const string& i : sl) out += i.length();
return out; return out;
} }
static string listString(StrList& sl) { static string listString(const StrList& sl) {
string out; string out;
for (const string& i : sl) out += i; for (const string& i : sl) out += i;
return out; return out;

View File

@ -52,7 +52,7 @@ template <typename T> class VRestorer {
const T m_saved; // Value saved, for later restore const T m_saved; // Value saved, for later restore
public: public:
VRestorer(T& permr) explicit VRestorer(T& permr)
: m_ref(permr) : m_ref(permr)
, m_saved(permr) {} , m_saved(permr) {}
~VRestorer() { m_ref = m_saved; } ~VRestorer() { m_ref = m_saved; }

View File

@ -344,7 +344,7 @@ void V3HierBlockPlan::createPlan(AstNetlist* nodep) {
} }
std::unique_ptr<V3HierBlockPlan> planp(new V3HierBlockPlan()); std::unique_ptr<V3HierBlockPlan> planp(new V3HierBlockPlan());
{ HierBlockUsageCollectVisitor visitor(planp.get(), nodep); } { HierBlockUsageCollectVisitor{planp.get(), nodep}; }
V3Stats::addStat("HierBlock, Hierarchical blocks", planp->m_blocks.size()); V3Stats::addStat("HierBlock, Hierarchical blocks", planp->m_blocks.size());

View File

@ -1283,9 +1283,9 @@ class LinkDotFindVisitor final : public AstNVisitor {
VL_DO_DANGLING(argp->unlinkFrBackWithNext()->deleteTree(), argp); VL_DO_DANGLING(argp->unlinkFrBackWithNext()->deleteTree(), argp);
} }
// Type depends on the method used, let V3Width figure it out later // Type depends on the method used, let V3Width figure it out later
const auto indexArgRefp = new AstLambdaArgRef(argFl, name + "__DOT__index", true);
const auto valueArgRefp = new AstLambdaArgRef(argFl, name, false);
if (nodep->exprp()) { // Else empty expression and pretend no "with" if (nodep->exprp()) { // Else empty expression and pretend no "with"
const auto indexArgRefp = new AstLambdaArgRef(argFl, name + "__DOT__index", true);
const auto valueArgRefp = new AstLambdaArgRef(argFl, name, false);
const auto newp = new AstWith(nodep->fileline(), indexArgRefp, valueArgRefp, const auto newp = new AstWith(nodep->fileline(), indexArgRefp, valueArgRefp,
nodep->exprp()->unlinkFrBackWithNext()); nodep->exprp()->unlinkFrBackWithNext());
funcrefp->addPinsp(newp); funcrefp->addPinsp(newp);
@ -2087,9 +2087,9 @@ private:
} else { } else {
auto cextp = VN_CAST(classp->extendsp(), ClassExtends); auto cextp = VN_CAST(classp->extendsp(), ClassExtends);
UASSERT_OBJ(cextp, nodep, "Bad super extends link"); UASSERT_OBJ(cextp, nodep, "Bad super extends link");
auto classp = cextp->classp(); auto sclassp = cextp->classp();
UASSERT_OBJ(classp, nodep, "Bad superclass"); UASSERT_OBJ(sclassp, nodep, "Bad superclass");
m_ds.m_dotSymp = m_statep->getNodeSym(classp); m_ds.m_dotSymp = m_statep->getNodeSym(sclassp);
UINFO(8, " super. " << m_ds.ascii() << endl); UINFO(8, " super. " << m_ds.ascii() << endl);
} }
} }

View File

@ -516,7 +516,8 @@ string V3Number::ascii(bool prefixed, bool cleanVerilog) const {
bool binary = (isFourState() bool binary = (isFourState()
#ifdef V3NUMBER_ASCII_BINARY #ifdef V3NUMBER_ASCII_BINARY
|| 1 // cppcheck-suppress konwnConditionTrueFalse
|| true
#endif #endif
); );
// out<<"-"<<hex<<m_value[0]<<"-"; // out<<"-"<<hex<<m_value[0]<<"-";

View File

@ -722,7 +722,7 @@ public:
} }
// CONSTRUCTORS // CONSTRUCTORS
ParamProcessor(AstNetlist* nodep) explicit ParamProcessor(AstNetlist* nodep)
: m_hierBlocks{v3Global.opt.hierBlocks(), nodep} { : m_hierBlocks{v3Global.opt.hierBlocks(), nodep} {
for (AstNodeModule* modp = nodep->modulesp(); modp; for (AstNodeModule* modp = nodep->modulesp(); modp;
modp = VN_CAST(modp->nextp(), NodeModule)) { modp = VN_CAST(modp->nextp(), NodeModule)) {

View File

@ -1317,7 +1317,6 @@ int V3PreProcImp::getStateToken() {
// Convert any newlines to spaces, so we don't get a // Convert any newlines to spaces, so we don't get a
// multiline "..." without \ escapes. // multiline "..." without \ escapes.
// The spec is silent about this either way; simulators vary // The spec is silent about this either way; simulators vary
string::size_type pos;
std::replace(out.begin(), out.end(), '\n', ' '); std::replace(out.begin(), out.end(), '\n', ' ');
unputString(string("\"") + out + "\""); unputString(string("\"") + out + "\"");
statePop(); statePop();

View File

@ -54,10 +54,10 @@ private:
// If member is rand and of class type, mark its class // If member is rand and of class type, mark its class
if (VN_IS(memberp, Var) && VN_CAST(memberp, Var)->isRand()) { if (VN_IS(memberp, Var) && VN_CAST(memberp, Var)->isRand()) {
if (auto* classRefp = VN_CAST(memberp->dtypep(), ClassRefDType)) { if (auto* classRefp = VN_CAST(memberp->dtypep(), ClassRefDType)) {
auto* classp = classRefp->classp(); auto* rclassp = classRefp->classp();
markMembers(classp); markMembers(rclassp);
markDerived(classp); markDerived(rclassp);
classRefp->classp()->user1(true); rclassp->user1(true);
} }
} }
} }
@ -158,10 +158,10 @@ private:
StructDType)) { StructDType)) {
AstNodeStmt* stmtsp = nullptr; AstNodeStmt* stmtsp = nullptr;
offset += memberp ? memberp->lsb() : 0; offset += memberp ? memberp->lsb() : 0;
for (auto* memberp = structDtp->membersp(); memberp; for (auto* smemberp = structDtp->membersp(); smemberp;
memberp = VN_CAST(memberp->nextp(), MemberDType)) { smemberp = VN_CAST(smemberp->nextp(), MemberDType)) {
auto* randp = newRandStmtsp(fl, stmtsp ? varrefp->cloneTree(false) : varrefp, auto* randp = newRandStmtsp(fl, stmtsp ? varrefp->cloneTree(false) : varrefp,
offset, memberp); offset, smemberp);
if (stmtsp) { if (stmtsp) {
stmtsp->addNext(randp); stmtsp->addNext(randp);
} else { } else {

View File

@ -411,8 +411,8 @@ private:
VL_RESTORER(m_alwaysCombp); VL_RESTORER(m_alwaysCombp);
{ {
AstNode::user2ClearTree(); AstNode::user2ClearTree();
if (nodep->keyword() == VAlwaysKwd::ALWAYS_COMB) UINFO(9, " " << nodep << endl);
if (nodep->keyword() == VAlwaysKwd::ALWAYS_COMB) { if (nodep->keyword() == VAlwaysKwd::ALWAYS_COMB) {
UINFO(9, " " << nodep << endl);
m_alwaysCombp = nodep; m_alwaysCombp = nodep;
} else { } else {
m_alwaysCombp = nullptr; m_alwaysCombp = nullptr;

View File

@ -288,10 +288,7 @@ static void UNSUPREAL(FileLine* fileline) {
//====================================================================== //======================================================================
void yyerror(const char* errmsg) { void yyerror(const char* errmsg) { PARSEP->bisonLastFileline()->v3error(errmsg); }
PARSEP->bisonLastFileline()->v3error(errmsg);
static const char* const colonmsg = "syntax error, unexpected";
}
void yyerrorf(const char* format, ...) { void yyerrorf(const char* format, ...) {
const int maxlen = 2000; const int maxlen = 2000;