From 98b89d0f2c8e4345afda5c4f37ea7e528959527b Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 27 Mar 2025 19:46:59 -0400 Subject: [PATCH] Fix some cppcheck warnings. No functional change intended. --- include/verilated_vpi.cpp | 5 ++--- src/V3EmitCMain.cpp | 1 - src/V3EmitMk.cpp | 4 ++-- src/V3EmitMkJson.cpp | 10 +++++----- src/V3FuncOpt.cpp | 6 +++--- src/V3LinkDot.cpp | 2 +- src/V3LinkParse.cpp | 2 +- src/V3ParseImp.cpp | 2 +- src/V3Task.cpp | 5 ++--- 9 files changed, 17 insertions(+), 20 deletions(-) diff --git a/include/verilated_vpi.cpp b/include/verilated_vpi.cpp index c4e4bf293..b97c491fb 100644 --- a/include/verilated_vpi.cpp +++ b/include/verilated_vpi.cpp @@ -2980,7 +2980,6 @@ void vl_get_value_array_vectors(unsigned index, const unsigned num, const unsign "type T is not unsigned"); // ensure logical right shift const unsigned element_size_bytes = VL_BYTES_I(packedSize); const unsigned element_size_words = VL_WORDS_I(packedSize); - const unsigned element_size_repr = (element_size_bytes + sizeof(T) - 1) / sizeof(T); if (sizeof(T) == sizeof(QData)) { for (unsigned i = 0; i < num; i++) { dst[i * 2].aval = static_cast(src[index]); @@ -3102,7 +3101,7 @@ void vl_put_value_array_rawvals(unsigned index, const unsigned num, const unsign } } -void vl_get_value_array(vpiHandle object, p_vpi_arrayvalue arrayvalue_p, PLI_INT32* index_p, +void vl_get_value_array(vpiHandle object, p_vpi_arrayvalue arrayvalue_p, const PLI_INT32* index_p, PLI_UINT32 num) { const VerilatedVpioVar* const vop = VerilatedVpioVar::castp(object); if (!vl_check_array_format(vop->varp(), arrayvalue_p, vop->fullname())) return; @@ -3328,7 +3327,7 @@ void vpi_get_value_array(vpiHandle object, p_vpi_arrayvalue arrayvalue_p, PLI_IN vl_get_value_array(object, arrayvalue_p, index_p, num); } -void vl_put_value_array(vpiHandle object, p_vpi_arrayvalue arrayvalue_p, PLI_INT32* index_p, +void vl_put_value_array(vpiHandle object, p_vpi_arrayvalue arrayvalue_p, const PLI_INT32* index_p, PLI_UINT32 num) { const VerilatedVpioVar* const vop = VerilatedVpioVar::castp(object); if (!vl_check_array_format(vop->varp(), arrayvalue_p, vop->fullname())) return; diff --git a/src/V3EmitCMain.cpp b/src/V3EmitCMain.cpp index 50c59106c..985a9cea9 100644 --- a/src/V3EmitCMain.cpp +++ b/src/V3EmitCMain.cpp @@ -50,7 +50,6 @@ private: v3Global.opt.addCFlags("-DVL_TIME_CONTEXT"); // On MSVC++ anyways // Optional main top name argument, with empty string replacement - string topArg; string topName = v3Global.opt.mainTopName(); if (topName == "-") topName = ""; diff --git a/src/V3EmitMk.cpp b/src/V3EmitMk.cpp index 429f07c44..0234bd3a4 100644 --- a/src/V3EmitMk.cpp +++ b/src/V3EmitMk.cpp @@ -50,7 +50,7 @@ private: const int m_dbgId; // Work list ID for debugging. WorkList() = delete; - WorkList(int id) + explicit WorkList(int id) : m_dbgId{id} {} }; @@ -463,7 +463,7 @@ private: public: static std::vector singleConcatenatedFilesList(std::vector inputFiles, uint64_t totalScore, - std::string groupFilePrefix) { + const std::string& groupFilePrefix) { EmitGroup group{std::move(inputFiles), totalScore, groupFilePrefix}; group.process(); return group.m_outputFiles; diff --git a/src/V3EmitMkJson.cpp b/src/V3EmitMkJson.cpp index e8ca899bc..1ab2db6e5 100644 --- a/src/V3EmitMkJson.cpp +++ b/src/V3EmitMkJson.cpp @@ -43,7 +43,8 @@ class V3EmitMkJsonEmitter final { // METHODS public: - Printer(const std::unique_ptr& of, const std::string& indent = " ") + explicit Printer(const std::unique_ptr& of, + const std::string& indent = " ") : m_of(of) , m_indent(indent) { begin(); @@ -144,7 +145,6 @@ class V3EmitMkJsonEmitter final { const std::unique_ptr of{ V3File::new_ofstream(makeDir + "/" + v3Global.opt.prefix() + ".json")}; - const string name = v3Global.opt.prefix(); const std::string trace = v3Global.opt.trace() ? (v3Global.opt.traceFormat().vcd() ? "vcd" : "fst") : "off"; @@ -257,11 +257,11 @@ class V3EmitMkJsonEmitter final { const V3HierBlock* hblockp = *it; const V3HierBlock::HierBlockSet& children = hblockp->children(); - std::vector deps; + std::vector childDeps; std::vector sources; for (const auto& childr : children) { - deps.emplace_back((childr)->hierPrefix()); + childDeps.emplace_back((childr)->hierPrefix()); sources.emplace_back(makeDir + "/" + childr->hierWrapperFilename(true)); } @@ -278,7 +278,7 @@ class V3EmitMkJsonEmitter final { cursor += cursor.begin() .put("prefix", hblockp->hierPrefix()) .put("top", hblockp->modp()->name()) - .putList("deps", deps) + .putList("deps", childDeps) .put("directory", makeDir + "/" + hblockp->hierPrefix()) .putList("sources", sources) .putList("cflags", cflags) diff --git a/src/V3FuncOpt.cpp b/src/V3FuncOpt.cpp index fd00bcf53..4e869fd6f 100644 --- a/src/V3FuncOpt.cpp +++ b/src/V3FuncOpt.cpp @@ -325,9 +325,9 @@ void V3FuncOpt::funcOptAll(AstNetlist* nodep) { V3ThreadScope threadScope; for (AstNodeModule *modp = nodep->modulesp(), *nextModp; modp; modp = nextModp) { nextModp = VN_AS(modp->nextp(), NodeModule); - for (AstNode *nodep = modp->stmtsp(), *nextNodep; nodep; nodep = nextNodep) { - nextNodep = nodep->nextp(); - if (AstCFunc* const cfuncp = VN_CAST(nodep, CFunc)) { + for (AstNode *stmtp = modp->stmtsp(), *nextStmtp; stmtp; stmtp = nextStmtp) { + nextStmtp = stmtp->nextp(); + if (AstCFunc* const cfuncp = VN_CAST(stmtp, CFunc)) { threadScope.enqueue([cfuncp]() { FuncOptVisitor::apply(cfuncp); }); } } diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index dd92ce966..86413d918 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -4283,8 +4283,8 @@ class LinkDotResolveVisitor final : public VNVisitor { } else if (m_insideClassExtParam) { return; } else { - if (foundp) UINFO(1, "Found sym node: " << foundp->nodep() << endl); if (foundp) { + UINFO(1, "Found sym node: " << foundp->nodep() << endl); nodep->v3error("Expecting a data type: " << nodep->prettyNameQ()); } else { nodep->v3error("Can't find typedef/interface: " << nodep->prettyNameQ()); diff --git a/src/V3LinkParse.cpp b/src/V3LinkParse.cpp index 3f7c7734e..6ba1c8737 100644 --- a/src/V3LinkParse.cpp +++ b/src/V3LinkParse.cpp @@ -681,7 +681,7 @@ class LinkParseVisitor final : public VNVisitor { if (nodep->genforp()) { ++m_genblkNum; if (nodep->name() == "") assignGenBlkNum = m_genblkNum; - } else if (nodep->generate() && nodep->name() == "" && assignGenBlkNum == -1 + } else if (nodep->generate() && nodep->name() == "" && (VN_IS(backp, CaseItem) || VN_IS(backp, GenIf)) && !nestedIf) { assignGenBlkNum = m_genblkAbove; } diff --git a/src/V3ParseImp.cpp b/src/V3ParseImp.cpp index 4bfc49bcb..b2126e631 100644 --- a/src/V3ParseImp.cpp +++ b/src/V3ParseImp.cpp @@ -712,7 +712,7 @@ void V3ParseImp::tokenPipelineSym() { } else { // Not found yylval.scp = nullptr; if (token == yaID__CC) { - if (!m_afterColonColon & !v3Global.opt.bboxUnsup()) { + if (!m_afterColonColon && !v3Global.opt.bboxUnsup()) { // IEEE does require this, but we may relax this as UVM breaks it, so allow // bbox for today // We'll get a parser error eventually but might not be obvious diff --git a/src/V3Task.cpp b/src/V3Task.cpp index 39447d7a0..14cf382bc 100644 --- a/src/V3Task.cpp +++ b/src/V3Task.cpp @@ -1952,9 +1952,8 @@ string V3Task::assignInternalToDpi(AstVar* portp, bool isPtr, const string& frSu const string idx = portp->name() + "__Vidx"; stmt = "for (size_t " + idx + " = 0; " + idx + " < " + cvtToStr(unpackSize) + "; ++" + idx + ") "; - stmt += (isBit ? "VL_SET_SVBV_" : "VL_SET_SVLV_") - + string{portp->dtypep()->skipRefp()->charIQWN()} + "(" + cvtToStr(portp->width()) - + ", "; + stmt += (isBit ? "VL_SET_SVBV_"s : "VL_SET_SVLV_"s) + + portp->dtypep()->skipRefp()->charIQWN() + "(" + cvtToStr(portp->width()) + ", "; stmt += toName + " + " + cvtToStr(portp->dtypep()->skipRefp()->widthWords()) + " * " + idx + ", "; if (unpackDim > 0) { // Access multi-dimensional array as a 1D array