From 8c480fd39e0e3d67d7cd915a7461427c0bdfdec0 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 31 Aug 2023 18:29:58 -0400 Subject: [PATCH] Internals: Fix cppcheck warnings --- include/verilated_timing.h | 4 ++++ src/V3Fork.cpp | 6 +++--- src/V3Options.h | 2 +- src/V3Premit.cpp | 2 +- src/V3Sched.h | 2 +- src/V3SchedAcyclic.cpp | 2 +- src/V3ThreadPool.h | 4 +++- src/V3Width.cpp | 16 +++++++++------- src/V3WidthSel.cpp | 1 + 9 files changed, 24 insertions(+), 15 deletions(-) diff --git a/include/verilated_timing.h b/include/verilated_timing.h index c7684fe5a..54b505e2a 100644 --- a/include/verilated_timing.h +++ b/include/verilated_timing.h @@ -102,6 +102,8 @@ class VlCoroutineHandle final { public: // CONSTRUCTORS // Construct + // non-explicit: + // cppcheck-suppress noExplicitConstructor VlCoroutineHandle(VlProcessRef process) : m_coro{nullptr} , m_process{process} { @@ -114,6 +116,8 @@ public: if (m_process) m_process->state(VlProcess::WAITING); } // Move the handle, leaving a nullptr + // non-explicit: + // cppcheck-suppress noExplicitConstructor VlCoroutineHandle(VlCoroutineHandle&& moved) : m_coro{std::exchange(moved.m_coro, nullptr)} , m_process{std::exchange(moved.m_process, nullptr)} diff --git a/src/V3Fork.cpp b/src/V3Fork.cpp index d0829181a..7229b08d2 100644 --- a/src/V3Fork.cpp +++ b/src/V3Fork.cpp @@ -358,7 +358,7 @@ private: public: // CONSTRUCTORS - DynScopeVisitor(AstNetlist* nodep) { + explicit DynScopeVisitor(AstNetlist* nodep) { // Create Dynamic scope class prototypes and objects visit(nodep); @@ -431,7 +431,7 @@ private: return taskp; } - string generateTaskName(AstNode* fromp, string kind) { + string generateTaskName(AstNode* fromp, const string& kind) { // TODO: Ensure no collisions occur return "__V" + kind + (!fromp->name().empty() ? (fromp->name() + "__") : "UNNAMED__") + cvtToHex(fromp); @@ -566,7 +566,7 @@ private: public: // CONSTRUCTORS - ForkVisitor(AstNetlist* nodep) { visit(nodep); } + explicit ForkVisitor(AstNetlist* nodep) { visit(nodep); } ~ForkVisitor() override = default; }; diff --git a/src/V3Options.h b/src/V3Options.h index dc2d011a8..702ff680b 100644 --- a/src/V3Options.h +++ b/src/V3Options.h @@ -281,7 +281,7 @@ private: bool m_traceCoverage = false; // main switch: --trace-coverage bool m_traceParams = true; // main switch: --trace-params bool m_traceStructs = false; // main switch: --trace-structs - bool m_noTraceTop; // main switch: --no-trace-top + bool m_noTraceTop = false; // main switch: --no-trace-top bool m_traceUnderscore = false; // main switch: --trace-underscore bool m_underlineZero = false; // main switch: --underline-zero; undocumented old Verilator 2 bool m_verilate = true; // main switch: --verilate diff --git a/src/V3Premit.cpp b/src/V3Premit.cpp index 6887e175d..2d1d3cfdb 100644 --- a/src/V3Premit.cpp +++ b/src/V3Premit.cpp @@ -214,7 +214,7 @@ private: } iterateAndNextNull(nodep->rhsp()); { - VL_RESTORER(m_assignLhs); + // VL_RESTORER(m_assignLhs); // Not needed; part of RESTORER_START_STATEMENT() m_assignLhs = true; iterateAndNextNull(nodep->lhsp()); } diff --git a/src/V3Sched.h b/src/V3Sched.h index ffd12dcad..526525a37 100644 --- a/src/V3Sched.h +++ b/src/V3Sched.h @@ -158,7 +158,7 @@ void transformForks(AstNetlist* const netlistp); void schedule(AstNetlist*); // Sub-steps -LogicByScope breakCycles(AstNetlist* netlistp, LogicByScope& combinationalLogic); +LogicByScope breakCycles(AstNetlist* netlistp, const LogicByScope& combinationalLogic); LogicRegions partition(LogicByScope& clockedLogic, LogicByScope& combinationalLogic, LogicByScope& hybridLogic); LogicReplicas replicateLogic(LogicRegions&); diff --git a/src/V3SchedAcyclic.cpp b/src/V3SchedAcyclic.cpp index 769383678..1416bc2e4 100644 --- a/src/V3SchedAcyclic.cpp +++ b/src/V3SchedAcyclic.cpp @@ -398,7 +398,7 @@ LogicByScope fixCuts(AstNetlist* netlistp, } // namespace -LogicByScope breakCycles(AstNetlist* netlistp, LogicByScope& combinationalLogic) { +LogicByScope breakCycles(AstNetlist* netlistp, const LogicByScope& combinationalLogic) { // Build the dataflow (dependency) graph const std::unique_ptr graphp = buildGraph(combinationalLogic); diff --git a/src/V3ThreadPool.h b/src/V3ThreadPool.h index b7c0658f4..7d21d157a 100644 --- a/src/V3ThreadPool.h +++ b/src/V3ThreadPool.h @@ -41,7 +41,7 @@ class VAnyPackagedTask final { struct PTWrapper final : PTWrapperBase { std::packaged_task m_pt; - PTWrapper(std::packaged_task&& pt) + explicit PTWrapper(std::packaged_task&& pt) : m_pt(std::move(pt)) {} void operator()() final override { m_pt(); } @@ -53,6 +53,8 @@ class VAnyPackagedTask final { public: // CONSTRUCTORS template + // non-explicit: + // cppcheck-suppress noExplicitConstructor VAnyPackagedTask(std::packaged_task&& pt) : m_ptWrapperp{std::make_unique>(std::move(pt))} {} diff --git a/src/V3Width.cpp b/src/V3Width.cpp index dbae4389d..0d5e5696d 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -2781,7 +2781,7 @@ private: VL_DO_DANGLING(pushDeletep(nodep), nodep); return true; } - if (AstNodeFTask* const methodp = VN_CAST(foundp, NodeFTask)) { + if (VN_IS(foundp, NodeFTask)) { nodep->replaceWith(new AstMethodCall{nodep->fileline(), nodep->fromp()->unlinkFrBack(), nodep->name(), nullptr}); @@ -7554,12 +7554,14 @@ AstNodeDType* V3Width::getCommonClassTypep(AstNode* nodep1, AstNode* nodep2) { // First handle cases with null values and when one class is a super class of the other. if (VN_IS(nodep1, Const)) std::swap(nodep1, nodep2); - const Castable castable - = WidthVisitor::computeCastable(nodep1->dtypep(), nodep2->dtypep(), nodep2); - if (castable == SAMEISH || castable == COMPATIBLE) { - return nodep1->dtypep(); - } else if (castable == DYNAMIC_CLASS) { - return nodep2->dtypep(); + { + const Castable castable + = WidthVisitor::computeCastable(nodep1->dtypep(), nodep2->dtypep(), nodep2); + if (castable == SAMEISH || castable == COMPATIBLE) { + return nodep1->dtypep(); + } else if (castable == DYNAMIC_CLASS) { + return nodep2->dtypep(); + } } AstClassRefDType* classDtypep1 = VN_CAST(nodep1->dtypep(), ClassRefDType); diff --git a/src/V3WidthSel.cpp b/src/V3WidthSel.cpp index f12893f40..96c88a2d5 100644 --- a/src/V3WidthSel.cpp +++ b/src/V3WidthSel.cpp @@ -248,6 +248,7 @@ private: adtypep, "Array extraction with width miscomputed " << adtypep->width() << "/" << fromRange.elements()); + // cppcheck-suppress zerodivcond const int elwidth = adtypep->width() / fromRange.elements(); AstSel* const newp = new AstSel{ nodep->fileline(), fromp,