Internals: Fix cppcheck warnings. No functional change.

This commit is contained in:
Wilson Snyder 2024-06-13 21:29:03 -04:00
parent 7de193c2e9
commit f96e99542c
13 changed files with 39 additions and 32 deletions

View File

@ -2909,7 +2909,7 @@ void VerilatedContext::statsPrintSummary() VL_MT_UNSAFE {
VL_PRINTF("- Verilator: %s at %s; walltime %0.3f s; speed %s/s\n", endwhy.c_str(),
simtime.c_str(), walltime, simtimePerf.c_str());
const double modelMB = VlOs::memUsageBytes() / 1024.0 / 1024.0;
VL_PRINTF("- Verilator: cpu %0.3f s on %d threads; alloced %0.0f MB\n", cputime,
VL_PRINTF("- Verilator: cpu %0.3f s on %u threads; alloced %0.0f MB\n", cputime,
threadsInModels(), modelMB);
}

View File

@ -48,7 +48,7 @@ public:
int width() const { return m_width; }
void* datap() const { return m_datap; }
bool set(std::string&&) const;
void emit(std::ostream& s) const;
void emit(std::ostream& s) const override;
};
class VlRandomConst final : public VlRandomExpr {
@ -61,7 +61,7 @@ public:
, m_width{width} {
assert(width <= sizeof(m_val) * 8);
}
void emit(std::ostream& s) const;
void emit(std::ostream& s) const override;
};
class VlRandomExtract final : public VlRandomExpr {
@ -72,7 +72,7 @@ public:
VlRandomExtract(std::shared_ptr<const VlRandomExpr> expr, unsigned idx)
: m_expr{expr}
, m_idx{idx} {}
void emit(std::ostream& s) const;
void emit(std::ostream& s) const override;
};
class VlRandomBinOp final : public VlRandomExpr {
@ -85,7 +85,7 @@ public:
: m_op{op}
, m_lhs{lhs}
, m_rhs{rhs} {}
void emit(std::ostream& s) const;
void emit(std::ostream& s) const override;
};
//=============================================================================

View File

@ -253,17 +253,17 @@ public:
, m_final{false}
, m_initial{false} {}
class Extends {};
VBaseOverride(Extends)
explicit VBaseOverride(Extends)
: m_extends{true}
, m_final{false}
, m_initial{false} {}
class Final {};
VBaseOverride(Final)
explicit VBaseOverride(Final)
: m_extends{false}
, m_final{true}
, m_initial{false} {}
class Initial {};
VBaseOverride(Initial)
explicit VBaseOverride(Initial)
: m_extends{false}
, m_final{false}
, m_initial{true} {}

View File

@ -2445,7 +2445,7 @@ class AstAlwaysPost final : public AstNodeProcedure {
// Like always but 'post' scheduled, e.g. for array NBA commits
public:
AstAlwaysPost(FileLine* fl)
explicit AstAlwaysPost(FileLine* fl)
: ASTGEN_SUPER_AlwaysPost(fl, nullptr) {}
ASTGEN_MEMBERS_AstAlwaysPost;
};

View File

@ -1632,10 +1632,7 @@ void AstClassRefDType::dumpSmall(std::ostream& str) const {
this->AstNodeDType::dumpSmall(str);
str << "class:" << name();
}
string AstClassRefDType::prettyDTypeName(bool) const {
return "class{}"s + prettyName();
return prettyTypeName();
}
string AstClassRefDType::prettyDTypeName(bool) const { return "class{}"s + prettyName(); }
string AstClassRefDType::name() const { return classp() ? classp()->name() : "<unlinked>"; }
void AstNodeCoverOrAssert::dump(std::ostream& str) const {
this->AstNodeStmt::dump(str);

View File

@ -64,6 +64,7 @@ public:
struct Hash final {
size_t operator()(const KeySel& key) const {
// cppcheck-suppress unreadVariable // cppcheck bug
V3Hash hash{vertexHash(key.m_fromp)};
hash += key.m_lsb;
hash += key.m_width;
@ -83,6 +84,7 @@ class KeyUnary final {
const DfgVertex* const m_source0p;
public:
// cppcheck-suppress noExplicitConstructor
KeyUnary(DfgVertex* source0p)
: m_source0p{source0p} {}
@ -110,6 +112,7 @@ public:
struct Hash final {
size_t operator()(const KeyBinary& key) const {
// cppcheck-suppress unreadVariable // cppcheck bug
V3Hash hash{vertexHash(key.m_source0p)};
hash += vertexHash(key.m_source1p);
return hash.value();
@ -137,6 +140,7 @@ public:
struct Hash final {
size_t operator()(const KeyTernary& key) const {
// cppcheck-suppress unreadVariable // cppcheck bug
V3Hash hash{vertexHash(key.m_source0p)};
hash += vertexHash(key.m_source1p);
hash += vertexHash(key.m_source2p);
@ -348,7 +352,7 @@ class V3DfgCache final {
inline CacheType<Vertex>& cacheForType();
public:
V3DfgCache(DfgGraph& dfg)
explicit V3DfgCache(DfgGraph& dfg)
: m_dfg{dfg} {}
// Find a vertex of type 'Vertex', with the given operands, or create a new one and add it.

View File

@ -27,6 +27,7 @@
VL_DEFINE_DEBUG_FUNCTIONS;
std::string V3DfgRegularizeContext::tmpNamePrefix(DfgGraph& dfg) {
// cppcheck-suppress unreadVariable // cppcheck bug
V3Hash hash{dfg.modulep()->name()};
hash += m_label;
std::string name = hash.toString();

View File

@ -2264,9 +2264,9 @@ class LinkDotResolveVisitor final : public VNVisitor {
<< "... Location of interface class's function\n"
<< interfaceSubp->warnContextSecondary());
}
const auto it = m_ifClassImpNames.find(interfaceSubp->name());
if (!existsInChild && it != m_ifClassImpNames.end()
&& it->second != interfaceSubp) { // Not exact same function from diamond
const auto itn = m_ifClassImpNames.find(interfaceSubp->name());
if (!existsInChild && itn != m_ifClassImpNames.end()
&& itn->second != interfaceSubp) { // Not exact same function from diamond
implementsClassp->v3error(
"Class " << implementsClassp->prettyNameQ() << impOrExtends
<< baseClassp->prettyNameQ()

View File

@ -81,7 +81,7 @@ class V3List final {
}
VL_ATTR_ALWINLINE
static void prefetch(T_Base* elementp, T_Base* fallbackp) {
static void prefetch(const T_Base* elementp, const T_Base* fallbackp) {
UDEBUGONLY(UASSERT(fallbackp, "Prefetch fallback pointer must be non nullptr"););
// This compiles to a branchless prefetch with cmove, with the address always valid
VL_PREFETCH_RW(elementp ? elementp : fallbackp);
@ -104,7 +104,7 @@ class V3List final {
T_Base* m_currp; // Currently iterated element, or 'nullptr' for 'end()' iterator
VL_ATTR_ALWINLINE
SimpleItertatorImpl(T_Base* elementp)
explicit SimpleItertatorImpl(T_Base* elementp)
: m_currp{elementp} {}
VL_ATTR_ALWINLINE
@ -159,7 +159,7 @@ class V3List final {
ListType& m_list; // The proxied list
UnlinkableProxy(ListType& list)
explicit UnlinkableProxy(ListType& list)
: m_list{list} {}
// Unlinkable iterator class template. This only supports enough for range based for loops.
@ -179,11 +179,11 @@ class V3List final {
T_Base* m_nextp; // Next element after current, or 'nullptr' for 'end()' iterator
VL_ATTR_ALWINLINE
UnlinkableItertatorImpl(T_Base* elementp)
explicit UnlinkableItertatorImpl(T_Base* elementp)
: m_currp{elementp}
, m_nextp{toLinks(m_currp).m_nextp} {}
VL_ATTR_ALWINLINE
UnlinkableItertatorImpl(std::nullptr_t)
explicit UnlinkableItertatorImpl(std::nullptr_t)
: m_currp{nullptr}
, m_nextp{nullptr} {}

View File

@ -110,6 +110,7 @@ class OrderMoveDomScope final {
struct Hash final {
size_t operator()(const DomScopeMapKey& key) const {
// cppcheck-suppress unreadVariable // cppcheck bug
V3Hash hash{reinterpret_cast<uint64_t>(key.m_domainp)};
hash += reinterpret_cast<uint64_t>(key.m_scopep);
return hash.value();
@ -199,7 +200,7 @@ class OrderMoveGraphSerializer final {
public:
// CONSTRUCTOR
OrderMoveGraphSerializer(OrderMoveGraph& moveGraph) {
explicit OrderMoveGraphSerializer(OrderMoveGraph& moveGraph) {
// Set V3GraphVertex::user() to the number of incoming edges (upstream dependencies)
for (V3GraphVertex& vtx : moveGraph.vertices()) {
const uint32_t nDeps = vtx.inEdges().size();

View File

@ -183,9 +183,11 @@ class PremitVisitor final : public VNVisitor {
void visit(AstWhile* nodep) override {
UINFO(4, " WHILE " << nodep << endl);
// cppcheck-suppress shadowVariable // Also restored below
START_STATEMENT_OR_RETURN(nodep);
iterateAndNextNull(nodep->precondsp());
{
// cppcheck-suppress shadowVariable // Also restored above
VL_RESTORER(m_inWhileCondp);
m_inWhileCondp = nodep;
iterateAndNextNull(nodep->condp());

View File

@ -58,7 +58,7 @@ class GatherMTaskAffinity final : VNVisitorConst {
VL_UNMOVABLE(GatherMTaskAffinity);
// VISIT
void visit(AstNodeVarRef* nodep) {
void visit(AstNodeVarRef* nodep) override {
// Cheaper than relying on emplace().second
if (nodep->user1SetOnce()) return;
AstVar* const varp = nodep->varp();
@ -74,17 +74,17 @@ class GatherMTaskAffinity final : VNVisitorConst {
affinity[m_id] = true;
}
void visit(AstCFunc* nodep) {
void visit(AstCFunc* nodep) override {
if (nodep->user1SetOnce()) return; // Prevent repeat traversals/recursion
iterateChildrenConst(nodep);
}
void visit(AstNodeCCall* nodep) {
void visit(AstNodeCCall* nodep) override {
iterateChildrenConst(nodep); // Arguments
iterateConst(nodep->funcp()); // Callee
}
void visit(AstNode* nodep) { iterateChildrenConst(nodep); }
void visit(AstNode* nodep) override { iterateChildrenConst(nodep); }
public:
static void apply(const ExecMTask* mTaskp, MTaskAffinityMap& results) {

View File

@ -187,11 +187,13 @@ private:
void visit(AstNodeFTask* nodep) override {
iterateChildren(nodep);
editDType(nodep);
AstClass* classp = VN_CAST(m_modp, Class);
if (nodep->classMethod() && nodep->pureVirtual() && classp && !classp->isInterfaceClass()
&& !classp->isVirtual()) {
nodep->v3error(
"Illegal to have 'pure virtual' in non-virtual class (IEEE 1800-2023 8.21)");
{
const AstClass* const classp = VN_CAST(m_modp, Class);
if (nodep->classMethod() && nodep->pureVirtual() && classp
&& !classp->isInterfaceClass() && !classp->isVirtual()) {
nodep->v3error(
"Illegal to have 'pure virtual' in non-virtual class (IEEE 1800-2023 8.21)");
}
}
bool extended = false;
if (const AstClass* const classp = VN_CAST(m_modp, Class)) {