mirror of
https://github.com/verilator/verilator.git
synced 2025-01-01 04:07:34 +00:00
Internals: Fix cppcheck warnings
This commit is contained in:
parent
8b03f2d47b
commit
89cfa0737f
@ -340,7 +340,7 @@ CPPCHECK_FLAGS = --enable=all --inline-suppr \
|
||||
--suppress=useStlAlgorithm
|
||||
CPPCHECK_FLAGS += --xml
|
||||
CPPCHECK_DEP = $(subst .cpp,.cppcheck,$(CHECK_CPP))
|
||||
CPPCHECK_INC = -I$(srcdir)/include -I$(srcdir)/src/obj_dbg -I$(srcdir)/src
|
||||
CPPCHECK_INC = -I$(srcdir)/include -I$(srcdir)/include/gtkwave -I$(srcdir)/include/vltstd -I$(srcdir)/src/obj_dbg -I$(srcdir)/src
|
||||
|
||||
cppcheck: cppcheck-1 cppcheck-2 cppcheck-3 cppcheck-4 cppcheck-5 cppcheck-6 cppcheck-7 cppcheck-8
|
||||
cppcheck-1:
|
||||
|
@ -2693,7 +2693,7 @@ std::pair<int, char**> VerilatedContextImp::argc_argv() VL_MT_SAFE_EXCLUDES(m_ar
|
||||
int in = 0;
|
||||
for (const auto& i : m_args.m_argVec) {
|
||||
s_argvp[in] = new char[i.length() + 1];
|
||||
std::strcpy(s_argvp[in], i.c_str());
|
||||
std::memcpy(s_argvp[in], i.c_str(), i.length() + 1);
|
||||
++in;
|
||||
}
|
||||
s_argvp[s_argc] = nullptr;
|
||||
|
@ -507,9 +507,9 @@ public:
|
||||
delete this; // IEEE 37.2.2 vpi_scan at end does a vpi_release_handle
|
||||
return nullptr;
|
||||
}
|
||||
const VerilatedScope::Type type = (*m_it)->type();
|
||||
const VerilatedScope::Type itype = (*m_it)->type();
|
||||
const VerilatedScope* const modp = *m_it++;
|
||||
if (type == VerilatedScope::SCOPE_MODULE) {
|
||||
if (itype == VerilatedScope::SCOPE_MODULE) {
|
||||
return (new VerilatedVpioModule{modp})->castVpiHandle();
|
||||
}
|
||||
}
|
||||
@ -523,9 +523,9 @@ class VerilatedVpioPackage final : public VerilatedVpioScope {
|
||||
public:
|
||||
explicit VerilatedVpioPackage(const VerilatedScope* modulep)
|
||||
: VerilatedVpioScope{modulep} {
|
||||
const char* fullname = m_scopep->name();
|
||||
if (std::strncmp(fullname, "TOP.", 4) == 0) fullname += 4;
|
||||
m_fullname = std::string{fullname} + "::";
|
||||
const char* sfullname = m_scopep->name();
|
||||
if (std::strncmp(sfullname, "TOP.", 4) == 0) sfullname += 4;
|
||||
m_fullname = std::string{sfullname} + "::";
|
||||
if (m_fullname == "\\$unit ::") m_fullname = "$unit::";
|
||||
m_name = std::string(m_scopep->identifier());
|
||||
if (m_name == "\\$unit ") m_name = "$unit";
|
||||
@ -558,12 +558,12 @@ public:
|
||||
delete this; // IEEE 37.2.2 vpi_scan at end does a vpi_release_handle
|
||||
return nullptr;
|
||||
}
|
||||
const VerilatedScope::Type type = (*m_it)->type();
|
||||
const VerilatedScope::Type itype = (*m_it)->type();
|
||||
const VerilatedScope* const modp = *m_it++;
|
||||
if (type == VerilatedScope::SCOPE_MODULE) {
|
||||
if (itype == VerilatedScope::SCOPE_MODULE) {
|
||||
return (new VerilatedVpioModule{modp})->castVpiHandle();
|
||||
}
|
||||
if (type == VerilatedScope::SCOPE_PACKAGE) {
|
||||
if (itype == VerilatedScope::SCOPE_PACKAGE) {
|
||||
return (new VerilatedVpioPackage{modp})->castVpiHandle();
|
||||
}
|
||||
}
|
||||
|
@ -1116,6 +1116,7 @@ bool AstNode::sameTreeIter(const AstNode* node1p, const AstNode* node2p, bool ig
|
||||
void AstNode::checkTreeIter(const AstNode* prevBackp) const VL_MT_STABLE {
|
||||
// private: Check a tree and children
|
||||
UASSERT_OBJ(prevBackp == this->backp(), this, "Back node inconsistent");
|
||||
// cppcheck-suppress danglingTempReference
|
||||
const VNTypeInfo& typeInfo = *type().typeInfo();
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
AstNode* nodep = nullptr;
|
||||
@ -1126,6 +1127,7 @@ void AstNode::checkTreeIter(const AstNode* prevBackp) const VL_MT_STABLE {
|
||||
case 4: nodep = op4p(); break;
|
||||
default: this->v3fatalSrc("Bad case"); break;
|
||||
}
|
||||
// cppcheck-suppress danglingTempReference
|
||||
const char* opName = typeInfo.m_opNamep[i - 1];
|
||||
switch (typeInfo.m_opType[i - 1]) {
|
||||
case VNTypeInfo::OP_UNUSED:
|
||||
@ -1142,7 +1144,7 @@ void AstNode::checkTreeIter(const AstNode* prevBackp) const VL_MT_STABLE {
|
||||
case VNTypeInfo::OP_LIST:
|
||||
if (const AstNode* const headp = nodep) {
|
||||
const AstNode* backp = this;
|
||||
const AstNode* tailp = headp;
|
||||
const AstNode* tailp;
|
||||
const AstNode* opp = headp;
|
||||
do {
|
||||
opp->checkTreeIter(backp);
|
||||
|
@ -125,6 +125,7 @@ public:
|
||||
constexpr VNType(en _e) VL_MT_SAFE : m_e{_e} {}
|
||||
explicit VNType(int _e)
|
||||
: m_e(static_cast<en>(_e)) {} // Need () or GCC 4.8 false warning
|
||||
// cppcheck-suppress danglingTempReference
|
||||
const VNTypeInfo* typeInfo() const VL_MT_SAFE { return &typeInfoTable[m_e]; }
|
||||
constexpr operator en() const VL_MT_SAFE { return m_e; }
|
||||
};
|
||||
|
@ -542,9 +542,8 @@ class ConstBitOpTreeVisitor final : public VNVisitorConst {
|
||||
restorer.disableRestore(); // Now all checks passed
|
||||
} else if (nodep->type() == m_rootp->type()) { // And, Or, Xor
|
||||
incrOps(nodep, __LINE__);
|
||||
VL_RESTORER(m_leafp);
|
||||
|
||||
for (const bool right : {false, true}) {
|
||||
VL_RESTORER(m_leafp);
|
||||
Restorer restorer{*this};
|
||||
LeafInfo leafInfo{m_lsb};
|
||||
m_leafp = &leafInfo;
|
||||
|
@ -237,6 +237,7 @@ class EmitCSyms final : EmitCBaseVisitorConst {
|
||||
// << scpSym << endl);
|
||||
if (v3Global.opt.vpi()) varHierarchyScopes(scpName);
|
||||
if (m_scopeNames.find(scpSym) == m_scopeNames.end()) {
|
||||
// cppcheck-suppress stlFindInsert
|
||||
m_scopeNames.emplace(scpSym,
|
||||
ScopeData{scpSym, scpPretty, 0, "SCOPE_OTHER"});
|
||||
}
|
||||
@ -341,6 +342,7 @@ class EmitCSyms final : EmitCBaseVisitorConst {
|
||||
ScopeFuncData(nodep, m_cfuncp, m_modp));
|
||||
} else {
|
||||
if (m_scopeNames.find(nodep->scopeDpiName()) == m_scopeNames.end()) {
|
||||
// cppcheck-suppress stlFindInsert
|
||||
m_scopeNames.emplace(nodep->scopeDpiName(),
|
||||
ScopeData{nodep->scopeDpiName(), nodep->scopePrettyDpiName(),
|
||||
timeunit, "SCOPE_OTHER"});
|
||||
|
@ -48,7 +48,7 @@ class GateEitherVertex VL_NOT_FINAL : public V3GraphVertex {
|
||||
bool m_dedupable = true; // True if this node should be able to be deduped
|
||||
bool m_consumed = false; // Output goes to something meaningful
|
||||
public:
|
||||
GateEitherVertex(V3Graph* graphp)
|
||||
explicit GateEitherVertex(V3Graph* graphp)
|
||||
: V3GraphVertex{graphp} {}
|
||||
~GateEitherVertex() override = default;
|
||||
|
||||
@ -811,8 +811,9 @@ class GateInline final {
|
||||
// If the consumer logic writes one of the variables that the substitution
|
||||
// is reading, then we would get a cycles, so we cannot do that.
|
||||
bool canInline = true;
|
||||
for (V3GraphEdge* edgep = dstVtxp->outBeginp(); edgep; edgep = edgep->outNextp()) {
|
||||
const GateVarVertex* const consVVertexp = edgep->top()->as<GateVarVertex>();
|
||||
for (V3GraphEdge* dedgep = dstVtxp->outBeginp(); dedgep;
|
||||
dedgep = dedgep->outNextp()) {
|
||||
const GateVarVertex* const consVVertexp = dedgep->top()->as<GateVarVertex>();
|
||||
if (readVscps.count(consVVertexp->varScp())) {
|
||||
canInline = false;
|
||||
break;
|
||||
@ -1327,7 +1328,7 @@ class GateUnused final {
|
||||
}
|
||||
}
|
||||
|
||||
GateUnused(GateGraph& graph)
|
||||
explicit GateUnused(GateGraph& graph)
|
||||
: m_graph{graph} {
|
||||
mark(); // Mark all used vertices
|
||||
remove(); // Remove unused vertices
|
||||
|
@ -456,12 +456,12 @@ private:
|
||||
clearOptimizable(nodep, "Var write & read");
|
||||
}
|
||||
m_varAux(vscp).usage |= VU_RV;
|
||||
const bool isConst = (nodep->varp()->isConst() || nodep->varp()->isParam())
|
||||
&& nodep->varp()->valuep();
|
||||
const bool varIsConst = (nodep->varp()->isConst() || nodep->varp()->isParam())
|
||||
&& nodep->varp()->valuep();
|
||||
AstNodeExpr* const valuep
|
||||
= isConst ? fetchValueNull(nodep->varp()->valuep()) : nullptr;
|
||||
= varIsConst ? fetchValueNull(nodep->varp()->valuep()) : nullptr;
|
||||
// Propagate PARAM constants for constant function analysis
|
||||
if (isConst && valuep) {
|
||||
if (varIsConst && valuep) {
|
||||
if (!m_checkOnly && optimizable()) newValue(vscp, valuep);
|
||||
} else {
|
||||
if (m_checkOnly) varRefCb(nodep);
|
||||
|
@ -58,7 +58,7 @@ class StackCountVisitor final : public VNVisitorConst {
|
||||
|
||||
public:
|
||||
// CONSTRUCTORS
|
||||
StackCountVisitor(AstNode* nodep) { iterateConstNull(nodep); }
|
||||
explicit StackCountVisitor(AstNode* nodep) { iterateConstNull(nodep); }
|
||||
~StackCountVisitor() override = default;
|
||||
|
||||
// METHODS
|
||||
|
@ -391,9 +391,8 @@ class TraceDeclVisitor final : public VNVisitor {
|
||||
} else {
|
||||
// This is a subscope: insert a placeholder to be fixed up later
|
||||
AstCell* const cellp = entry.cellp();
|
||||
FileLine* const flp = cellp->fileline();
|
||||
AstNodeStmt* const stmtp
|
||||
= new AstComment{flp, "Cell init for: " + cellp->prettyName()};
|
||||
AstNodeStmt* const stmtp = new AstComment{
|
||||
cellp->fileline(), "Cell init for: " + cellp->prettyName()};
|
||||
addToSubFunc(stmtp);
|
||||
m_cellInitPlaceholders.emplace_back(nodep, cellp, stmtp);
|
||||
}
|
||||
|
@ -4411,10 +4411,8 @@ class WidthVisitor final : public VNVisitor {
|
||||
|
||||
static bool usesDynamicScheduler(AstNode* nodep) {
|
||||
UASSERT_OBJ(nodep->dtypep()->isEvent(), nodep, "Node does not have an event dtype");
|
||||
|
||||
AstVarRef* vrefp;
|
||||
while (true) {
|
||||
vrefp = VN_CAST(nodep, VarRef);
|
||||
AstVarRef* const vrefp = VN_CAST(nodep, VarRef);
|
||||
if (vrefp) return usesDynamicScheduler(vrefp);
|
||||
if (VN_IS(nodep, MemberSel)) {
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user