From 8741fd17add1fe22f33d90033a049bd12184e8cc Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Fri, 23 Aug 2024 18:24:34 -0400 Subject: [PATCH] Internals: cppcheck cleanups. No functional change intended. --- include/verilated_random.h | 4 ++++ include/verilated_types.h | 5 +++-- src/V3AstNodeOther.h | 8 ++++---- src/V3Const.cpp | 1 + src/V3Dfg.h | 6 +++--- src/V3DfgPasses.h | 2 +- src/V3DfgRegularize.cpp | 2 +- src/V3Randomize.cpp | 12 ++++++------ 8 files changed, 23 insertions(+), 17 deletions(-) diff --git a/include/verilated_random.h b/include/verilated_random.h index b53e0eb82..2612a6f2d 100644 --- a/include/verilated_random.h +++ b/include/verilated_random.h @@ -107,6 +107,10 @@ class VlRandomizer final { bool parseSolution(std::iostream& file); public: + // CONSTRUCTORS + VlRandomizer() = default; + ~VlRandomizer() = default; + // METHODS // Finds the next solution satisfying the constraints bool next(VlRNG& rngr); diff --git a/include/verilated_types.h b/include/verilated_types.h index ea831514a..2dc29cf2a 100644 --- a/include/verilated_types.h +++ b/include/verilated_types.h @@ -597,6 +597,7 @@ public: // Can't just overload operator[] or provide a "at" reference to set, // because we need to be able to insert only when the value is set T_Value& at(int32_t index) { + // cppcheck-suppress variableScope static thread_local T_Value t_throwAway; // Needs to work for dynamic arrays, so does not use T_MaxSize if (VL_UNLIKELY(index < 0 || index >= m_deque.size())) { @@ -1794,9 +1795,9 @@ public: struct VlNull final { operator bool() const { return false; } - bool operator==(void* ptr) const { return !ptr; } + bool operator==(const void* ptr) const { return !ptr; } }; -inline bool operator==(void* ptr, VlNull) { return !ptr; } +inline bool operator==(const void* ptr, VlNull) { return !ptr; } //=================================================================== // Verilog class reference container diff --git a/src/V3AstNodeOther.h b/src/V3AstNodeOther.h index 926c19719..8c69b84aa 100644 --- a/src/V3AstNodeOther.h +++ b/src/V3AstNodeOther.h @@ -2349,8 +2349,8 @@ public: && std::is_base_of::value, "Callable 'f' must have a signature compatible with 'void(AstClass*, T_Node*)', " "with 'T_Node' being a subtype of 'AstNode'"); - if (AstClassExtends* const extendsp = this->extendsp()) { - extendsp->classp()->foreachMember(f); + if (AstClassExtends* const cextendsp = this->extendsp()) { + cextendsp->classp()->foreachMember(f); } for (AstNode* stmtp = stmtsp(); stmtp; stmtp = stmtp->nextp()) { if (AstNode::privateTypeTest(stmtp)) f(this, static_cast(stmtp)); @@ -2364,8 +2364,8 @@ public: && std::is_base_of::value, "Predicate 'p' must have a signature compatible with 'bool(const AstClass*, " "const T_Node*)', with 'T_Node' being a subtype of 'AstNode'"); - if (AstClassExtends* const extendsp = this->extendsp()) { - if (extendsp->classp()->existsMember(p)) return true; + if (AstClassExtends* const cextendsp = this->extendsp()) { + if (cextendsp->classp()->existsMember(p)) return true; } for (AstNode* stmtp = stmtsp(); stmtp; stmtp = stmtp->nextp()) { if (AstNode::privateTypeTest(stmtp)) { diff --git a/src/V3Const.cpp b/src/V3Const.cpp index 54c1d3704..fc487acb3 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -548,6 +548,7 @@ class ConstBitOpTreeVisitor final : public VNVisitorConst { VL_RESTORER(m_leafp); Restorer restorer{*this}; LeafInfo leafInfo{m_lsb}; + // cppcheck-suppress danglingLifetime m_leafp = &leafInfo; AstNodeExpr* opp = right ? nodep->rhsp() : nodep->lhsp(); const bool origFailed = m_failed; diff --git a/src/V3Dfg.h b/src/V3Dfg.h index 3c476ce3f..5fab278ee 100644 --- a/src/V3Dfg.h +++ b/src/V3Dfg.h @@ -206,11 +206,11 @@ public: UDEBUGONLY(UASSERT_OBJ(isSupportedDType(nodep->dtypep()), nodep, "Unsupported dtype");); // For simplicity, all packed types are represented with a fixed type if (AstUnpackArrayDType* const typep = VN_CAST(nodep->dtypep(), UnpackArrayDType)) { - AstNodeDType* const dtypep = new AstUnpackArrayDType{ + AstNodeDType* const adtypep = new AstUnpackArrayDType{ typep->fileline(), dtypeForWidth(typep->subDTypep()->width()), typep->rangep()->cloneTree(false)}; - v3Global.rootp()->typeTablep()->addTypesp(dtypep); - return dtypep; + v3Global.rootp()->typeTablep()->addTypesp(adtypep); + return adtypep; } return dtypeForWidth(nodep->width()); } diff --git a/src/V3DfgPasses.h b/src/V3DfgPasses.h index 57f5afe47..2b1e08aa6 100644 --- a/src/V3DfgPasses.h +++ b/src/V3DfgPasses.h @@ -49,7 +49,7 @@ class V3DfgRegularizeContext final { public: VDouble0 m_temporariesIntroduced; // Number of temporaries introduced - std::string tmpNamePrefix(DfgGraph&); // Return prefix to use for given graph + std::string tmpNamePrefix(const DfgGraph&); // Return prefix to use for given graph explicit V3DfgRegularizeContext(const std::string& label) : m_label{label} {} diff --git a/src/V3DfgRegularize.cpp b/src/V3DfgRegularize.cpp index b2c836334..e521a5ebe 100644 --- a/src/V3DfgRegularize.cpp +++ b/src/V3DfgRegularize.cpp @@ -26,7 +26,7 @@ VL_DEFINE_DEBUG_FUNCTIONS; -std::string V3DfgRegularizeContext::tmpNamePrefix(DfgGraph& dfg) { +std::string V3DfgRegularizeContext::tmpNamePrefix(const DfgGraph& dfg) { // cppcheck-suppress unreadVariable // cppcheck bug V3Hash hash{dfg.modulep()->name()}; hash += m_label; diff --git a/src/V3Randomize.cpp b/src/V3Randomize.cpp index de49768b1..227fa9d53 100644 --- a/src/V3Randomize.cpp +++ b/src/V3Randomize.cpp @@ -1556,10 +1556,10 @@ class RandomizeVisitor final : public VNVisitor { if (receiverp) { // Called on a rand member variable/constraint. Set the variable/constraint's // mode - const RandomizeMode mode = {.asInt = receiverp->user1()}; - UASSERT_OBJ(mode.usesMode, ftaskRefp, "Failed to set usesMode"); + const RandomizeMode rmode = {.asInt = receiverp->user1()}; + UASSERT_OBJ(rmode.usesMode, ftaskRefp, "Failed to set usesMode"); AstCMethodHard* const atp - = new AstCMethodHard{fl, lhsp, "at", new AstConst{fl, mode.index}}; + = new AstCMethodHard{fl, lhsp, "at", new AstConst{fl, rmode.index}}; atp->dtypeSetUInt32(); m_stmtp->replaceWith(new AstAssign{fl, atp, rhsp}); } else { @@ -1571,10 +1571,10 @@ class RandomizeVisitor final : public VNVisitor { pushDeletep(m_stmtp); } else { UASSERT_OBJ(receiverp, ftaskRefp, "Should have receiver"); - const RandomizeMode mode = {.asInt = receiverp->user1()}; - UASSERT_OBJ(mode.usesMode, ftaskRefp, "Failed to set usesMode"); + const RandomizeMode rmode = {.asInt = receiverp->user1()}; + UASSERT_OBJ(rmode.usesMode, ftaskRefp, "Failed to set usesMode"); AstCMethodHard* const atp - = new AstCMethodHard{fl, lhsp, "at", new AstConst{fl, mode.index}}; + = new AstCMethodHard{fl, lhsp, "at", new AstConst{fl, rmode.index}}; atp->dtypeSetUInt32(); ftaskRefp->replaceWith(atp); VL_DO_DANGLING(pushDeletep(ftaskRefp), ftaskRefp);