Internal: cppcheck fixes. No functional change intended.

This commit is contained in:
Wilson Snyder 2022-11-27 05:52:40 -05:00
parent 4b3731d318
commit 833780fac1
40 changed files with 175 additions and 121 deletions

View File

@ -302,34 +302,56 @@ install-all: installbin installman installdata install-msg
install-here: installman info install-here: installman info
# Use --xml flag to see the cppcheck code to use for suppression # Use --xml flag to see the cppcheck code to use for suppression
CPPCHECK_CPP = $(wildcard \ CPPCHECK1_CPP = $(wildcard $(srcdir)/include/*.cpp)
$(srcdir)/examples/*/*.cpp \ CPPCHECK2_CPP = $(wildcard $(srcdir)/examples/*/*.cpp)
$(srcdir)/include/*.cpp \ CPPCHECK3_CPP = $(wildcard $(srcdir)/src/Vlc*.cpp)
$(srcdir)/src/*.cpp ) CPPCHECK4_CPP = $(wildcard $(srcdir)/src/V3[A-D]*.cpp $(srcdir)/src/Verilator*.cpp)
CPPCHECK_H = $(wildcard \ CPPCHECK5_CPP = $(wildcard $(srcdir)/src/V3[E-I]*.cpp)
CPPCHECK6_CPP = $(wildcard $(srcdir)/src/V3[P-Z]*.cpp)
CPPCHECK7_CPP = $(wildcard $(srcdir)/src/V3[L-R]*.cpp)
CPPCHECK8_CPP = $(wildcard $(srcdir)/src/V3[S-Z]*.cpp)
CHECK_CPP = $(CPPCHECK1_CPP) $(CPPCHECK2_CPP) $(CPPCHECK3_CPP) $(CPPCHECK4_CPP) \
$(CPPCHECK5_CPP) $(CPPCHECK6_CPP) $(CPPCHECK7_CPP) $(CPPCHECK8_CPP)
CHECK_H = $(wildcard \
$(srcdir)/include/*.h \ $(srcdir)/include/*.h \
$(srcdir)/src/*.h ) $(srcdir)/src/*.h )
CPPCHECK_YL = $(wildcard \ CHECK_YL = $(wildcard \
$(srcdir)/src/*.y \ $(srcdir)/src/*.y \
$(srcdir)/src/*.l ) $(srcdir)/src/*.l )
CPPCHECK = src/cppcheck_filtered cppcheck CPPCHECK = src/cppcheck_filtered cppcheck
CPPCHECK_FLAGS = --enable=all --inline-suppr \ CPPCHECK_FLAGS = --enable=all --inline-suppr \
--suppress=unusedScopedObject --suppress=cstyleCast --suppress=useInitializationList \ --suppress=cstyleCast --suppress=useInitializationList \
--suppress=nullPointerRedundantCheck --suppress=nullPointer --suppress=nullPointerRedundantCheck --suppress=ctunullpointer \
--suppress=unusedFunction --suppress=unusedScopedObject \
--suppress=useStlAlgorithm
CPPCHECK_FLAGS += --xml CPPCHECK_FLAGS += --xml
CPPCHECK_DEP = $(subst .cpp,.cppcheck,$(CPPCHECK_CPP)) 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)/src/obj_dbg -I$(srcdir)/src
cppcheck: $(CPPCHECK_DEP) cppcheck: cppcheck-1 cppcheck-2 cppcheck-3 cppcheck-4 cppcheck-5 cppcheck-6 cppcheck-7 cppcheck-8
%.cppcheck: %.cpp cppcheck-1:
$(CPPCHECK) $(CPPCHECK_FLAGS) -DVL_DEBUG=1 -DVL_CPPCHECK=1 $(CPPCHECK_INC) $< $(CPPCHECK) $(CPPCHECK_FLAGS) -DVL_DEBUG=1 -DVL_CPPCHECK=1 $(CPPCHECK_INC) $(CPPCHECK1_CPP)
cppcheck-2:
$(CPPCHECK) $(CPPCHECK_FLAGS) -DVL_DEBUG=1 -DVL_CPPCHECK=1 $(CPPCHECK_INC) $(CPPCHECK2_CPP)
cppcheck-3:
$(CPPCHECK) $(CPPCHECK_FLAGS) -DVL_DEBUG=1 -DVL_CPPCHECK=1 $(CPPCHECK_INC) $(CPPCHECK3_CPP)
cppcheck-4:
$(CPPCHECK) $(CPPCHECK_FLAGS) -DVL_DEBUG=1 -DVL_CPPCHECK=1 $(CPPCHECK_INC) $(CPPCHECK4_CPP)
cppcheck-5:
$(CPPCHECK) $(CPPCHECK_FLAGS) -DVL_DEBUG=1 -DVL_CPPCHECK=1 $(CPPCHECK_INC) $(CPPCHECK5_CPP)
cppcheck-6:
$(CPPCHECK) $(CPPCHECK_FLAGS) -DVL_DEBUG=1 -DVL_CPPCHECK=1 $(CPPCHECK_INC) $(CPPCHECK6_CPP)
cppcheck-7:
$(CPPCHECK) $(CPPCHECK_FLAGS) -DVL_DEBUG=1 -DVL_CPPCHECK=1 $(CPPCHECK_INC) $(CPPCHECK7_CPP)
cppcheck-8:
$(CPPCHECK) $(CPPCHECK_FLAGS) -DVL_DEBUG=1 -DVL_CPPCHECK=1 $(CPPCHECK_INC) $(CPPCHECK8_CPP)
CLANGTIDY = clang-tidy CLANGTIDY = clang-tidy
CLANGTIDY_FLAGS = -config='' \ CLANGTIDY_FLAGS = -config='' \
-header-filter='.*' \ -header-filter='.*' \
-checks='-fuchsia-*,-cppcoreguidelines-avoid-c-arrays,-cppcoreguidelines-init-variables,-cppcoreguidelines-avoid-goto,-modernize-avoid-c-arrays,-readability-magic-numbers,-readability-simplify-boolean-expr,-cppcoreguidelines-macro-usage' \ -checks='-fuchsia-*,-cppcoreguidelines-avoid-c-arrays,-cppcoreguidelines-init-variables,-cppcoreguidelines-avoid-goto,-modernize-avoid-c-arrays,-readability-magic-numbers,-readability-simplify-boolean-expr,-cppcoreguidelines-macro-usage' \
CLANGTIDY_DEP = $(subst .cpp,.cpp.tidy,$(CPPCHECK_CPP)) CLANGTIDY_DEP = $(subst .cpp,.cpp.tidy,$(CHECK_CPP))
CLANGTIDY_DEFS = -DVL_DEBUG=1 -DVL_CPPCHECK=1 CLANGTIDY_DEFS = -DVL_DEBUG=1 -DVL_CPPCHECK=1
clang-tidy: $(CLANGTIDY_DEP) clang-tidy: $(CLANGTIDY_DEP)
@ -350,7 +372,7 @@ format: clang-format yapf format-pl-exec
CLANGFORMAT = clang-format-14 CLANGFORMAT = clang-format-14
CLANGFORMAT_FLAGS = -i CLANGFORMAT_FLAGS = -i
CLANGFORMAT_FILES = $(CPPCHECK_CPP) $(CPPCHECK_H) $(CPPCHECK_YL) test_regress/t/*.c* test_regress/t/*.h CLANGFORMAT_FILES = $(CHECK_CPP) $(CHECK_H) $(CHECK_YL) test_regress/t/*.c* test_regress/t/*.h
clang-format: clang-format:
@$(CLANGFORMAT) --version | egrep 14.0 > /dev/null \ @$(CLANGFORMAT) --version | egrep 14.0 > /dev/null \

View File

@ -491,11 +491,11 @@ WDataOutP VL_POW_WWW(int obits, int, int rbits, WDataOutP owp, const WDataInP lw
// obits==lbits, rbits can be different // obits==lbits, rbits can be different
owp[0] = 1; owp[0] = 1;
for (int i = 1; i < VL_WORDS_I(obits); i++) owp[i] = 0; for (int i = 1; i < VL_WORDS_I(obits); i++) owp[i] = 0;
// cppcheck-suppress variableScope // cppcheck-has-bug-suppress variableScope
VlWide<VL_MULS_MAX_WORDS> powstore; // Fixed size, as MSVC++ doesn't allow [words] here VlWide<VL_MULS_MAX_WORDS> powstore; // Fixed size, as MSVC++ doesn't allow [words] here
VlWide<VL_MULS_MAX_WORDS> lastpowstore; // Fixed size, as MSVC++ doesn't allow [words] here VlWide<VL_MULS_MAX_WORDS> lastpowstore; // Fixed size, as MSVC++ doesn't allow [words] here
VlWide<VL_MULS_MAX_WORDS> lastoutstore; // Fixed size, as MSVC++ doesn't allow [words] here VlWide<VL_MULS_MAX_WORDS> lastoutstore; // Fixed size, as MSVC++ doesn't allow [words] here
// cppcheck-suppress variableScope // cppcheck-has-bug-suppress variableScope
VL_ASSIGN_W(obits, powstore, lwp); VL_ASSIGN_W(obits, powstore, lwp);
for (int bit = 0; bit < rbits; bit++) { for (int bit = 0; bit < rbits; bit++) {
if (bit > 0) { // power = power*power if (bit > 0) { // power = power*power
@ -1227,7 +1227,7 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf
_vl_vsss_skipspace(fp, floc, fromp, fstr); _vl_vsss_skipspace(fp, floc, fromp, fstr);
_vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, "+-.0123456789eE"); _vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, "+-.0123456789eE");
if (!t_tmp[0]) goto done; if (!t_tmp[0]) goto done;
// cppcheck-suppress unusedStructMember // It's used // cppcheck-has-bug-suppress unusedStructMember, unreadVariable
union { union {
double r; double r;
int64_t ld; int64_t ld;
@ -1682,7 +1682,7 @@ IData VL_VALUEPLUSARGS_INW(int rbits, const std::string& ld, WDataOutP rwp) VL_M
inPct = true; inPct = true;
} else if (!inPct) { // Normal text } else if (!inPct) { // Normal text
prefix += *posp; prefix += *posp;
} else if (inPct && posp[0] == '0') { // %0 } else if (*posp == '0') { // %0
} else { // Format character } else { // Format character
switch (std::tolower(*posp)) { switch (std::tolower(*posp)) {
case '%': case '%':
@ -1906,7 +1906,7 @@ VlReadMem::VlReadMem(bool hex, int bits, const std::string& filename, QData star
if (VL_UNLIKELY(!m_fp)) { if (VL_UNLIKELY(!m_fp)) {
// We don't report the Verilog source filename as it slow to have to pass it down // We don't report the Verilog source filename as it slow to have to pass it down
VL_WARN_MT(filename.c_str(), 0, "", "$readmem file not found"); VL_WARN_MT(filename.c_str(), 0, "", "$readmem file not found");
// cppcheck-suppress resourceLeak // m_fp is nullptr - bug in cppcheck // cppcheck-has-bug-suppress resourceLeak // m_fp is nullptr
return; return;
} }
} }
@ -2044,7 +2044,7 @@ VlWriteMem::VlWriteMem(bool hex, int bits, const std::string& filename, QData st
m_fp = std::fopen(filename.c_str(), "w"); m_fp = std::fopen(filename.c_str(), "w");
if (VL_UNLIKELY(!m_fp)) { if (VL_UNLIKELY(!m_fp)) {
VL_FATAL_MT(filename.c_str(), 0, "", "$writemem file not found"); VL_FATAL_MT(filename.c_str(), 0, "", "$writemem file not found");
// cppcheck-suppress resourceLeak // m_fp is nullptr - bug in cppcheck // cppcheck-has-bug-suppress resourceLeak // m_fp is nullptr
return; return;
} }
} }
@ -2227,6 +2227,7 @@ static const char* vl_time_str(int scale) VL_PURE {
double vl_time_multiplier(int scale) VL_PURE { double vl_time_multiplier(int scale) VL_PURE {
// Return timescale multipler -18 to +18 // Return timescale multipler -18 to +18
// For speed, this does not check for illegal values // For speed, this does not check for illegal values
// cppcheck-has-bug-suppress arrayIndexOutOfBoundsCond
if (scale < 0) { if (scale < 0) {
static const double neg10[] = {1.0, static const double neg10[] = {1.0,
0.1, 0.1,
@ -2247,6 +2248,7 @@ double vl_time_multiplier(int scale) VL_PURE {
0.0000000000000001, 0.0000000000000001,
0.00000000000000001, 0.00000000000000001,
0.000000000000000001}; 0.000000000000000001};
// cppcheck-has-bug-suppress arrayIndexOutOfBoundsCond
return neg10[-scale]; return neg10[-scale];
} else { } else {
static const double pow10[] = {1.0, static const double pow10[] = {1.0,
@ -2268,6 +2270,7 @@ double vl_time_multiplier(int scale) VL_PURE {
10000000000000000.0, 10000000000000000.0,
100000000000000000.0, 100000000000000000.0,
1000000000000000000.0}; 1000000000000000000.0};
// cppcheck-has-bug-suppress arrayIndexOutOfBoundsCond
return pow10[scale]; return pow10[scale];
} }
} }
@ -2754,6 +2757,7 @@ VerilatedSyms::VerilatedSyms(VerilatedContext* contextp)
: _vm_contextp__(contextp ? contextp : Verilated::threadContextp()) { : _vm_contextp__(contextp ? contextp : Verilated::threadContextp()) {
VerilatedContext::checkMagic(_vm_contextp__); VerilatedContext::checkMagic(_vm_contextp__);
Verilated::threadContextp(_vm_contextp__); Verilated::threadContextp(_vm_contextp__);
// cppcheck-has-bug-suppress noCopyConstructor
__Vm_evalMsgQp = new VerilatedEvalMsgQueue; __Vm_evalMsgQp = new VerilatedEvalMsgQueue;
} }

View File

@ -274,6 +274,7 @@ extern uint64_t vl_time_stamp64() VL_ATTR_WEAK;
extern double sc_time_stamp() VL_ATTR_WEAK; // Verilator 4.032 and newer extern double sc_time_stamp() VL_ATTR_WEAK; // Verilator 4.032 and newer
inline uint64_t vl_time_stamp64() { inline uint64_t vl_time_stamp64() {
// clang9.0.1 requires & although we really do want the weak symbol value // clang9.0.1 requires & although we really do want the weak symbol value
// cppcheck-suppress duplicateValueTernary
return VL_LIKELY(&sc_time_stamp) ? static_cast<uint64_t>(sc_time_stamp()) : 0; return VL_LIKELY(&sc_time_stamp) ? static_cast<uint64_t>(sc_time_stamp()) : 0;
} }
# endif # endif
@ -593,6 +594,7 @@ static inline IData VL_REDAND_IW(int lbits, WDataInP const lwp) VL_PURE {
EData combine = lwp[0]; EData combine = lwp[0];
for (int i = 1; i < words - 1; ++i) combine &= lwp[i]; for (int i = 1; i < words - 1; ++i) combine &= lwp[i];
combine &= ~VL_MASK_E(lbits) | lwp[words - 1]; combine &= ~VL_MASK_E(lbits) | lwp[words - 1];
// cppcheck-has-bug-suppress knownConditionTrueFalse
return ((~combine) == 0); return ((~combine) == 0);
} }
@ -1024,12 +1026,14 @@ static inline WDataOutP VL_MULS_WWW(int lbits, WDataOutP owp, WDataInP const lwp
if (lneg) { // Negate lhs if (lneg) { // Negate lhs
lwusp = lwstore; lwusp = lwstore;
VL_NEGATE_W(words, lwstore, lwp); VL_NEGATE_W(words, lwstore, lwp);
// cppcheck-has-bug-suppress unreadVariable
lwstore[words - 1] &= VL_MASK_E(lbits); // Clean it lwstore[words - 1] &= VL_MASK_E(lbits); // Clean it
} }
const EData rneg = VL_SIGN_E(lbits, rwp[words - 1]); const EData rneg = VL_SIGN_E(lbits, rwp[words - 1]);
if (rneg) { // Negate rhs if (rneg) { // Negate rhs
rwusp = rwstore; rwusp = rwstore;
VL_NEGATE_W(words, rwstore, rwp); VL_NEGATE_W(words, rwstore, rwp);
// cppcheck-has-bug-suppress unreadVariable
rwstore[words - 1] &= VL_MASK_E(lbits); // Clean it rwstore[words - 1] &= VL_MASK_E(lbits); // Clean it
} }
VL_MUL_W(words, owp, lwusp, rwusp); VL_MUL_W(words, owp, lwusp, rwusp);

View File

@ -362,7 +362,7 @@ public: // But only for verilated*.cpp
private: private:
VerilatedFpList fdToFpList(IData fdi) VL_REQUIRES(m_fdMutex) { VerilatedFpList fdToFpList(IData fdi) VL_REQUIRES(m_fdMutex) {
VerilatedFpList fp; VerilatedFpList fp;
// cppcheck-suppress integeroverflow shifttoomanybitssigned // cppverilator-suppress integerOverflow shiftTooManyBitsSigned
if ((fdi & (1 << 31)) != 0) { if ((fdi & (1 << 31)) != 0) {
// Non-MCD case // Non-MCD case
const IData idx = fdi & VL_MASK_I(31); const IData idx = fdi & VL_MASK_I(31);

View File

@ -852,6 +852,7 @@ void AstNode::iterateAndNext(VNVisitor& v) {
#ifdef VL_DEBUG // Otherwise too hot of a function for debug #ifdef VL_DEBUG // Otherwise too hot of a function for debug
UASSERT_OBJ(!(nodep && !nodep->m_backp), nodep, "iterateAndNext node has no back"); UASSERT_OBJ(!(nodep && !nodep->m_backp), nodep, "iterateAndNext node has no back");
#endif #endif
// cppcheck-suppress knownConditionTrueFalse
if (nodep) ASTNODE_PREFETCH(nodep->m_nextp); if (nodep) ASTNODE_PREFETCH(nodep->m_nextp);
while (nodep) { // effectively: if (!this) return; // Callers rely on this while (nodep) { // effectively: if (!this) return; // Callers rely on this
if (nodep->m_nextp) ASTNODE_PREFETCH(nodep->m_nextp->m_nextp); if (nodep->m_nextp) ASTNODE_PREFETCH(nodep->m_nextp->m_nextp);

View File

@ -1464,9 +1464,11 @@ public:
string emitC() override { string emitC() override {
return m_reset ? "VL_RAND_RESET_%nq(%nw, %P)" return m_reset ? "VL_RAND_RESET_%nq(%nw, %P)"
: seedp() : seedp()
? (urandom() ? "VL_URANDOM_SEEDED_%nq%lq(%li)" : "VL_RANDOM_SEEDED_%nq%lq(%li)") // cppcheck-has-bug-suppress knownConditionTrueFalse
: isWide() ? "VL_RANDOM_%nq(%nw, %P)" // ? (urandom() ? "VL_URANDOM_SEEDED_%nq%lq(%li)" //
: "VL_RANDOM_%nq()"; : "VL_RANDOM_SEEDED_%nq%lq(%li)")
: (isWide() ? "VL_RANDOM_%nq(%nw, %P)" //
: "VL_RANDOM_%nq()");
} }
bool cleanOut() const override { return false; } bool cleanOut() const override { return false; }
bool isGateOptimizable() const override { return false; } bool isGateOptimizable() const override { return false; }

View File

@ -1193,6 +1193,7 @@ AstVarScope* AstConstPool::findTable(AstInitArray* initp) {
UASSERT_OBJ(VN_IS(valuep, Const), valuep, "Const pool table entry must be Const"); UASSERT_OBJ(VN_IS(valuep, Const), valuep, "Const pool table entry must be Const");
} }
// Try to find an existing table with the same content // Try to find an existing table with the same content
// cppcheck-has-bug-suppress unreadVariable
const V3Hash hash = V3Hasher::uncachedHash(initp); const V3Hash hash = V3Hasher::uncachedHash(initp);
const auto& er = m_tables.equal_range(hash.value()); const auto& er = m_tables.equal_range(hash.value());
for (auto it = er.first; it != er.second; ++it) { for (auto it = er.first; it != er.second; ++it) {
@ -1222,6 +1223,7 @@ static bool sameInit(const AstConst* ap, const AstConst* bp) {
AstVarScope* AstConstPool::findConst(AstConst* initp, bool mergeDType) { AstVarScope* AstConstPool::findConst(AstConst* initp, bool mergeDType) {
// Try to find an existing constant with the same value // Try to find an existing constant with the same value
// cppcheck-has-bug-suppress unreadVariable
const V3Hash hash = initp->num().toHash(); const V3Hash hash = initp->num().toHash();
const auto& er = m_consts.equal_range(hash.value()); const auto& er = m_consts.equal_range(hash.value());
for (auto it = er.first; it != er.second; ++it) { for (auto it = er.first; it != er.second; ++it) {

View File

@ -255,12 +255,14 @@ private:
// There's no space for a IF. We know upperValue is thus down to a specific // There's no space for a IF. We know upperValue is thus down to a specific
// exact value, so just return the tree value // exact value, so just return the tree value
// Note can't clone here, as we're going to check for equivalence above // Note can't clone here, as we're going to check for equivalence above
return m_valueItem[upperValue]; AstNode* const foundp = m_valueItem[upperValue];
return foundp;
} else { } else {
// Make left and right subtrees // Make left and right subtrees
// cexpr[msb:lsb] == 1 // cexpr[msb:lsb] == 1
AstNode* tree0p = replaceCaseFastRecurse(cexprp, msb - 1, upperValue | 0); AstNode* tree0p = replaceCaseFastRecurse(cexprp, msb - 1, upperValue | 0);
AstNode* tree1p = replaceCaseFastRecurse(cexprp, msb - 1, upperValue | (1UL << msb)); AstNode* tree1p = replaceCaseFastRecurse(
cexprp, msb - 1, upperValue | (1UL << static_cast<uint32_t>(msb)));
if (tree0p == tree1p) { if (tree0p == tree1p) {
// Same logic on both sides, so we can just return one of 'em // Same logic on both sides, so we can just return one of 'em

View File

@ -558,8 +558,7 @@ private:
} // Fully computed } // Fully computed
std::set<AstSenTree*> senouts; // List of all sensitivities for new signal std::set<AstSenTree*> senouts; // List of all sensitivities for new signal
if (const CdcLogicVertex* const vvertexp = dynamic_cast<CdcLogicVertex*>(vertexp)) { if (dynamic_cast<CdcLogicVertex*>(vertexp)) {
if (vvertexp) {} // Unused
} else if (const CdcVarVertex* const vvertexp = dynamic_cast<CdcVarVertex*>(vertexp)) { } else if (const CdcVarVertex* const vvertexp = dynamic_cast<CdcVarVertex*>(vertexp)) {
// If primary I/O, give it domain of the input // If primary I/O, give it domain of the input
const AstVar* const varp = vvertexp->varScp()->varp(); const AstVar* const varp = vvertexp->varScp()->varp();

View File

@ -101,10 +101,10 @@ class DfgGraph final {
DfgGraph* m_graphp; // The referenced graph DfgGraph* m_graphp; // The referenced graph
public: public:
UserDataInUse(DfgGraph* graphp) explicit UserDataInUse(DfgGraph* graphp)
: m_graphp{graphp} {} : m_graphp{graphp} {}
VL_UNCOPYABLE(UserDataInUse); VL_UNCOPYABLE(UserDataInUse);
UserDataInUse(UserDataInUse&& that) { explicit UserDataInUse(UserDataInUse&& that) {
UASSERT(that.m_graphp, "Moving from empty"); UASSERT(that.m_graphp, "Moving from empty");
m_graphp = vlstd::exchange(that.m_graphp, nullptr); m_graphp = vlstd::exchange(that.m_graphp, nullptr);
} }
@ -353,6 +353,7 @@ public:
UDEBUGONLY(UASSERT_OBJ(userCurrent, this, "DfgVertex user data used without reserving");); UDEBUGONLY(UASSERT_OBJ(userCurrent, this, "DfgVertex user data used without reserving"););
if (m_userCnt != userCurrent) { if (m_userCnt != userCurrent) {
m_userCnt = userCurrent; m_userCnt = userCurrent;
// cppcheck-has-bug-suppress uninitvar
VL_ATTR_UNUSED T* const resultp = new (storagep) T{}; VL_ATTR_UNUSED T* const resultp = new (storagep) T{};
UDEBUGONLY(UASSERT_OBJ(resultp == storagep, this, "Something is odd");); UDEBUGONLY(UASSERT_OBJ(resultp == storagep, this, "Something is odd"););
} }

View File

@ -89,7 +89,7 @@ class SplitIntoComponents final {
} }
} }
SplitIntoComponents(DfgGraph& dfg, std::string label) SplitIntoComponents(DfgGraph& dfg, const std::string& label)
: m_dfg{dfg} : m_dfg{dfg}
, m_prefix{dfg.name() + (label.empty() ? "" : "-") + label + "-component-"} { , m_prefix{dfg.name() + (label.empty() ? "" : "-") + label + "-component-"} {
// Component number is stored as DfgVertex::user<size_t>() // Component number is stored as DfgVertex::user<size_t>()
@ -356,6 +356,7 @@ class ExtractCyclicComponents final {
// Unlink the source edge (source is reconnected by 'relink' // Unlink the source edge (source is reconnected by 'relink'
edge.unlinkSource(); edge.unlinkSource();
// Apply the fixup // Apply the fixup
// cppcheck-has-bug-suppress constVariable
DfgVertexVar& clone = getClone(vtx, sourceComponent); DfgVertexVar& clone = getClone(vtx, sourceComponent);
relink(*(clone.as<T_Vertex>()), source, idx); relink(*(clone.as<T_Vertex>()), source, idx);
}); });
@ -517,7 +518,7 @@ class ExtractCyclicComponents final {
} }
// CONSTRUCTOR - entry point // CONSTRUCTOR - entry point
explicit ExtractCyclicComponents(DfgGraph& dfg, std::string label) explicit ExtractCyclicComponents(DfgGraph& dfg, const std::string& label)
: m_dfg{dfg} : m_dfg{dfg}
, m_prefix{dfg.name() + (label.empty() ? "" : "-") + label + "-component-"} { , m_prefix{dfg.name() + (label.empty() ? "" : "-") + label + "-component-"} {
// VertexState is stored as user data // VertexState is stored as user data

View File

@ -283,7 +283,7 @@ void V3DfgPasses::optimize(DfgGraph& dfg, V3DfgOptimizationContext& ctx) {
int passNumber = 0; int passNumber = 0;
const auto apply = [&](int dumpLevel, const string name, std::function<void()> pass) { const auto apply = [&](int dumpLevel, const string& name, std::function<void()> pass) {
pass(); pass();
if (dumpDfg() >= dumpLevel) { if (dumpDfg() >= dumpLevel) {
const string strippedName = VString::removeWhitespace(name); const string strippedName = VString::removeWhitespace(name);

View File

@ -322,10 +322,8 @@ class EmitCSyms final : EmitCBaseVisitor {
// UINFO(9,"scnameins sp "<<nodep->name()<<" sp "<<nodep->scopePrettySymName() // UINFO(9,"scnameins sp "<<nodep->name()<<" sp "<<nodep->scopePrettySymName()
// <<" ss"<<name<<endl); // <<" ss"<<name<<endl);
const int timeunit = m_modp ? m_modp->timeunit().powerOfTen() : 0; const int timeunit = m_modp ? m_modp->timeunit().powerOfTen() : 0;
if (m_scopeNames.find(name) == m_scopeNames.end()) { m_scopeNames.emplace(
m_scopeNames.emplace( name, ScopeData(name, nodep->scopePrettySymName(), timeunit, "SCOPE_OTHER"));
name, ScopeData(name, nodep->scopePrettySymName(), timeunit, "SCOPE_OTHER"));
}
if (nodep->dpiExport()) { if (nodep->dpiExport()) {
UASSERT_OBJ(m_cfuncp, nodep, "ScopeName not under DPI function"); UASSERT_OBJ(m_cfuncp, nodep, "ScopeName not under DPI function");
m_scopeFuncs.insert(std::make_pair(name + " " + m_cfuncp->name(), m_scopeFuncs.insert(std::make_pair(name + " " + m_cfuncp->name(),
@ -984,7 +982,7 @@ void EmitCSyms::emitDpiHdr() {
const string filename = v3Global.opt.makeDir() + "/" + topClassName() + "__Dpi.h"; const string filename = v3Global.opt.makeDir() + "/" + topClassName() + "__Dpi.h";
AstCFile* const cfilep = newCFile(filename, false /*slow*/, false /*source*/); AstCFile* const cfilep = newCFile(filename, false /*slow*/, false /*source*/);
cfilep->support(true); cfilep->support(true);
V3OutCFile hf(filename); V3OutCFile hf{filename};
m_ofp = &hf; m_ofp = &hf;
m_ofp->putsHeader(); m_ofp->putsHeader();
@ -1029,6 +1027,7 @@ void EmitCSyms::emitDpiHdr() {
puts("#endif\n"); puts("#endif\n");
ofp()->putsEndGuard(); ofp()->putsEndGuard();
m_ofp = nullptr;
} }
//###################################################################### //######################################################################
@ -1083,6 +1082,7 @@ void EmitCSyms::emitDpiImp() {
puts("\n"); puts("\n");
} }
} }
m_ofp = nullptr;
} }
//###################################################################### //######################################################################

View File

@ -740,10 +740,7 @@ public:
// Emit to an output file // Emit to an output file
class EmitVFileVisitor final : public EmitVBaseVisitor { class EmitVFileVisitor final : public EmitVBaseVisitor {
// MEMBERS
V3OutFile* m_ofp;
// METHODS // METHODS
V3OutFile* ofp() const { return m_ofp; }
void puts(const string& str) override { ofp()->puts(str); } void puts(const string& str) override { ofp()->puts(str); }
void putbs(const string& str) override { ofp()->putbs(str); } void putbs(const string& str) override { ofp()->putbs(str); }
void putfs(AstNode*, const string& str) override { putbs(str); } void putfs(AstNode*, const string& str) override { putbs(str); }
@ -751,9 +748,9 @@ class EmitVFileVisitor final : public EmitVBaseVisitor {
void putsNoTracking(const string& str) override { ofp()->putsNoTracking(str); } void putsNoTracking(const string& str) override { ofp()->putsNoTracking(str); }
public: public:
EmitVFileVisitor(AstNode* nodep, V3OutFile* ofp, bool trackText, bool suppressUnknown) EmitVFileVisitor(AstNode* nodep, V3OutVFile* ofp, bool trackText, bool suppressUnknown)
: EmitVBaseVisitor{suppressUnknown, nullptr} : EmitVBaseVisitor{suppressUnknown, nullptr} {
, m_ofp{ofp} { m_ofp = ofp;
m_trackText = trackText; m_trackText = trackText;
iterate(nodep); iterate(nodep);
} }

View File

@ -184,6 +184,7 @@ void V3Error::suppressThisWarning() {
string V3Error::warnMore() { return string(msgPrefix().size(), ' '); } string V3Error::warnMore() { return string(msgPrefix().size(), ' '); }
// cppcheck-has-bug-suppress constParameter
void V3Error::v3errorEnd(std::ostringstream& sstr, const string& extra) { void V3Error::v3errorEnd(std::ostringstream& sstr, const string& extra) {
#if defined(__COVERITY__) || defined(__cppcheck__) #if defined(__COVERITY__) || defined(__cppcheck__)
if (s_errorCode == V3ErrorCode::EC_FATAL) __coverity_panic__(x); if (s_errorCode == V3ErrorCode::EC_FATAL) __coverity_panic__(x);

View File

@ -122,20 +122,16 @@ class V3FileDependImp final {
public: public:
// ACCESSOR METHODS // ACCESSOR METHODS
void addSrcDepend(const string& filename) { void addSrcDepend(const string& filename) {
if (m_filenameSet.find(filename) == m_filenameSet.end()) { const auto itFoundPair = m_filenameSet.insert(filename);
// cppcheck-suppress stlFindInsert // cppcheck 1.90 bug if (itFoundPair.second) {
m_filenameSet.insert(filename);
DependFile df{filename, false}; DependFile df{filename, false};
df.loadStats(); // Get size now, in case changes during the run df.loadStats(); // Get size now, in case changes during the run
m_filenameList.insert(df); m_filenameList.insert(df);
} }
} }
void addTgtDepend(const string& filename) { void addTgtDepend(const string& filename) {
if (m_filenameSet.find(filename) == m_filenameSet.end()) { const auto itFoundPair = m_filenameSet.insert(filename);
// cppcheck-suppress stlFindInsert // cppcheck 1.90 bug if (itFoundPair.second) m_filenameList.insert(DependFile{filename, true});
m_filenameSet.insert(filename);
m_filenameList.insert(DependFile{filename, true});
}
} }
void writeDepend(const string& filename); void writeDepend(const string& filename);
std::vector<string> getAllDeps() const; std::vector<string> getAllDeps() const;
@ -424,7 +420,7 @@ private:
} }
} }
} }
// cppcheck-suppress unusedFunction unusedPrivateFunction // cppverilator-suppress unusedFunction unusedPrivateFunction
string readFilterLine() { string readFilterLine() {
// Slow, but we don't need it much // Slow, but we don't need it much
UINFO(9, "readFilterLine\n"); UINFO(9, "readFilterLine\n");
@ -446,7 +442,7 @@ private:
UINFO(6, "filter-line-in: " << line); UINFO(6, "filter-line-in: " << line);
return line; return line;
} }
// cppcheck-suppress unusedFunction unusedPrivateFunction // cppverilator-suppress unusedFunction unusedPrivateFunction
void writeFilter(const string& out) { void writeFilter(const string& out) {
if (debug() >= 6) { if (debug() >= 6) {
UINFO(6, "filter-out: " << out); UINFO(6, "filter-out: " << out);

View File

@ -242,8 +242,9 @@ class V3OutCFile VL_NOT_FINAL : public V3OutFile {
int m_guard = false; // Created header guard int m_guard = false; // Created header guard
int m_private; // 1 = Most recently emitted private:, 2 = public: int m_private; // 1 = Most recently emitted private:, 2 = public:
public: public:
explicit V3OutCFile(const string& filename) explicit V3OutCFile(const string& filename,
: V3OutFile{filename, V3OutFormatter::LA_C} { V3OutFormatter::Language lang = V3OutFormatter::LA_C)
: V3OutFile{filename, lang} {
resetPrivate(); resetPrivate();
} }
~V3OutCFile() override = default; ~V3OutCFile() override = default;
@ -279,10 +280,10 @@ public:
} }
}; };
class V3OutVFile final : public V3OutFile { class V3OutVFile final : public V3OutCFile {
public: public:
explicit V3OutVFile(const string& filename) explicit V3OutVFile(const string& filename)
: V3OutFile{filename, V3OutFormatter::LA_VERILOG} {} : V3OutCFile{filename, V3OutFormatter::LA_VERILOG} {}
~V3OutVFile() override = default; ~V3OutVFile() override = default;
virtual void putsHeader() { puts("// Verilated -*- Verilog -*-\n"); } virtual void putsHeader() { puts("// Verilated -*- Verilog -*-\n"); }
}; };

View File

@ -379,6 +379,7 @@ bool FileLine::warnIsOff(V3ErrorCode code) const VL_MT_SAFE {
return false; return false;
} }
// cppverilator-suppress constParameter
void FileLine::v3errorEnd(std::ostringstream& sstr, const string& extra) { void FileLine::v3errorEnd(std::ostringstream& sstr, const string& extra) {
std::ostringstream nsstr; std::ostringstream nsstr;
if (lastLineno()) nsstr << this; if (lastLineno()) nsstr << this;

View File

@ -128,6 +128,7 @@ V3GraphEdge* V3GraphVertex::findConnectingEdgep(GraphWay way, const V3GraphVerte
return nullptr; return nullptr;
} }
// cppcheck-has-bug-suppress constParameter
void V3GraphVertex::v3errorEnd(std::ostringstream& str) const { void V3GraphVertex::v3errorEnd(std::ostringstream& str) const {
std::ostringstream nsstr; std::ostringstream nsstr;
nsstr << str.str(); nsstr << str.str();
@ -300,7 +301,7 @@ void V3Graph::dump(std::ostream& os) {
} }
} }
void V3Graph::dumpEdge(std::ostream& os, V3GraphVertex* vertexp, V3GraphEdge* edgep) { void V3Graph::dumpEdge(std::ostream& os, const V3GraphVertex* vertexp, const V3GraphEdge* edgep) {
if (edgep->weight() && (edgep->fromp() == vertexp || edgep->top() == vertexp)) { if (edgep->weight() && (edgep->fromp() == vertexp || edgep->top() == vertexp)) {
os << "\t\t"; os << "\t\t";
if (edgep->fromp() == vertexp) os << "-> " << edgep->top()->name(); if (edgep->fromp() == vertexp) os << "-> " << edgep->top()->name();

View File

@ -88,7 +88,7 @@ protected:
friend class GraphAcyc; friend class GraphAcyc;
// METHODS // METHODS
double orderDFSIterate(V3GraphVertex* vertexp); double orderDFSIterate(V3GraphVertex* vertexp);
void dumpEdge(std::ostream& os, V3GraphVertex* vertexp, V3GraphEdge* edgep); void dumpEdge(std::ostream& os, const V3GraphVertex* vertexp, const V3GraphEdge* edgep);
void verticesUnlink() { m_vertices.reset(); } void verticesUnlink() { m_vertices.reset(); }
// ACCESSORS // ACCESSORS

View File

@ -197,8 +197,8 @@ private:
&& !nodep->internal()) { && !nodep->internal()) {
// We only complain once per file, otherwise library-like files // We only complain once per file, otherwise library-like files
// have a huge mess of warnings // have a huge mess of warnings
if (m_declfnWarned.find(nodep->fileline()->filename()) == m_declfnWarned.end()) { const auto itFoundPair = m_declfnWarned.insert(nodep->fileline()->filename());
m_declfnWarned.insert(nodep->fileline()->filename()); if (itFoundPair.second) {
nodep->v3warn(DECLFILENAME, "Filename '" nodep->v3warn(DECLFILENAME, "Filename '"
<< nodep->fileline()->filebasenameNoExt() << nodep->fileline()->filebasenameNoExt()
<< "' does not match " << nodep->typeName() << "' does not match " << nodep->typeName()

View File

@ -1140,7 +1140,7 @@ class LinkDotFindVisitor final : public VNVisitor {
bool ins = false; bool ins = false;
if (!foundp) { if (!foundp) {
ins = true; ins = true;
} else if (!findvarp && foundp && m_curSymp->findIdFlat(nodep->name())) { } else if (!findvarp && m_curSymp->findIdFlat(nodep->name())) {
nodep->v3error("Unsupported in C: Variable has same name as " nodep->v3error("Unsupported in C: Variable has same name as "
<< LinkDotState::nodeTextType(foundp->nodep()) << ": " << LinkDotState::nodeTextType(foundp->nodep()) << ": "
<< nodep->prettyNameQ()); << nodep->prettyNameQ());

View File

@ -267,10 +267,8 @@ void V3LinkLevel::wrapTopCell(AstNetlist* rootp) {
varp->protect(false); varp->protect(false);
newmodp->addStmtsp(varp); newmodp->addStmtsp(varp);
varp->sigPublic(true); // User needs to be able to get to it... varp->sigPublic(true); // User needs to be able to get to it...
if (oldvarp->isIO()) { oldvarp->primaryIO(false);
oldvarp->primaryIO(false); varp->primaryIO(true);
varp->primaryIO(true);
}
if (varp->direction().isRefOrConstRef()) { if (varp->direction().isRefOrConstRef()) {
varp->v3warn(E_UNSUPPORTED, varp->v3warn(E_UNSUPPORTED,
"Unsupported: ref/const ref as primary input/output: " "Unsupported: ref/const ref as primary input/output: "

View File

@ -491,7 +491,10 @@ private:
// Close pending merge, if there is one at the end of the whole sub-tree list // Close pending merge, if there is one at the end of the whole sub-tree list
if (m_mgFirstp) mergeEnd(); if (m_mgFirstp) mergeEnd();
m_stmtPropertiesp = nullptr;
} while (!m_workQueuep->empty()); } while (!m_workQueuep->empty());
m_workQueuep = nullptr;
} }
// Skip past AstArraySel and AstWordSel with const index // Skip past AstArraySel and AstWordSel with const index
@ -716,6 +719,7 @@ private:
iterateAndNextNull(recursivep->elsesp()); iterateAndNextNull(recursivep->elsesp());
// Close a pending merge to ensure merge state is // Close a pending merge to ensure merge state is
// reset as expected at the end of this function // reset as expected at the end of this function
// cppcheck-has-bug-suppress knownConditionTrueFalse
if (m_mgFirstp) mergeEnd(); if (m_mgFirstp) mergeEnd();
} }
} }

View File

@ -75,9 +75,9 @@ public:
// ACCESSOR METHODS // ACCESSOR METHODS
void addIncDirUser(const string& incdir) { void addIncDirUser(const string& incdir) {
if (m_incDirUserSet.find(incdir) == m_incDirUserSet.end()) { const auto itFoundPair = m_incDirUserSet.insert(incdir);
if (itFoundPair.second) {
// cppcheck-suppress stlFindInsert // cppcheck 1.90 bug // cppcheck-suppress stlFindInsert // cppcheck 1.90 bug
m_incDirUserSet.insert(incdir);
m_incDirUsers.push_back(incdir); m_incDirUsers.push_back(incdir);
m_incDirFallbacks.remove(incdir); // User has priority over Fallback m_incDirFallbacks.remove(incdir); // User has priority over Fallback
m_incDirFallbackSet.erase(incdir); // User has priority over Fallback m_incDirFallbackSet.erase(incdir); // User has priority over Fallback
@ -86,11 +86,8 @@ public:
void addIncDirFallback(const string& incdir) { void addIncDirFallback(const string& incdir) {
if (m_incDirUserSet.find(incdir) if (m_incDirUserSet.find(incdir)
== m_incDirUserSet.end()) { // User has priority over Fallback == m_incDirUserSet.end()) { // User has priority over Fallback
if (m_incDirFallbackSet.find(incdir) == m_incDirFallbackSet.end()) { const auto itFoundPair = m_incDirFallbackSet.insert(incdir);
// cppcheck-suppress stlFindInsert // cppcheck 1.90 bug if (itFoundPair.second) m_incDirFallbacks.push_back(incdir);
m_incDirFallbackSet.insert(incdir);
m_incDirFallbacks.push_back(incdir);
}
} }
} }
void addLangExt(const string& langext, const V3LangCode& lc) { void addLangExt(const string& langext, const V3LangCode& lc) {
@ -100,11 +97,8 @@ public:
} }
void addLibExtV(const string& libext) { void addLibExtV(const string& libext) {
if (m_libExtVSet.find(libext) == m_libExtVSet.end()) { const auto itFoundPair = m_libExtVSet.insert(libext);
// cppcheck-suppress stlFindInsert // cppcheck 1.90 bug if (itFoundPair.second) m_libExtVs.push_back(libext);
m_libExtVSet.insert(libext);
m_libExtVs.push_back(libext);
}
} }
V3OptionsImp() = default; V3OptionsImp() = default;
~V3OptionsImp() = default; ~V3OptionsImp() = default;

View File

@ -155,6 +155,7 @@ string V3Os::filenameNonExt(const string& filename) {
string V3Os::filenameSubstitute(const string& filename) { string V3Os::filenameSubstitute(const string& filename) {
string out; string out;
// cppcheck-has-bug-suppress unusedLabel
enum : uint8_t { NONE, PAREN, CURLY } brackets = NONE; enum : uint8_t { NONE, PAREN, CURLY } brackets = NONE;
for (string::size_type pos = 0; pos < filename.length(); ++pos) { for (string::size_type pos = 0; pos < filename.length(); ++pos) {
if ((filename[pos] == '$') && (pos + 1 < filename.length())) { if ((filename[pos] == '$') && (pos + 1 < filename.length())) {

View File

@ -342,8 +342,10 @@ class ParamProcessor final {
// particularly robust for type parameters. We should really have a type // particularly robust for type parameters. We should really have a type
// equivalence predicate function. // equivalence predicate function.
const string key = paramValueKey(nodep); const string key = paramValueKey(nodep);
// cppcheck-has-bug-suppress unreadVariable
V3Hash hash = V3Hasher::uncachedHash(nodep); V3Hash hash = V3Hasher::uncachedHash(nodep);
// Force hash collisions -- for testing only // Force hash collisions -- for testing only
// cppcheck-has-bug-suppress unreadVariable
if (VL_UNLIKELY(v3Global.opt.debugCollision())) hash = V3Hash{}; if (VL_UNLIKELY(v3Global.opt.debugCollision())) hash = V3Hash{};
int num; int num;
const auto it = m_valueMap.find(hash); const auto it = m_valueMap.find(hash);

View File

@ -142,7 +142,7 @@ class V3ParseImp final {
static V3ParseImp* s_parsep; // Current THIS, bison() isn't class based static V3ParseImp* s_parsep; // Current THIS, bison() isn't class based
FileLine* m_lexFileline = nullptr; // Filename/linenumber currently active for lexing FileLine* m_lexFileline = nullptr; // Filename/linenumber currently active for lexing
FileLine* m_bisonLastFileline; // Filename/linenumber of last token FileLine* m_bisonLastFileline = nullptr; // Filename/linenumber of last token
bool m_inLibrary = false; // Currently reading a library vs. regular file bool m_inLibrary = false; // Currently reading a library vs. regular file
int m_lexKwdDepth = 0; // Inside a `begin_keywords int m_lexKwdDepth = 0; // Inside a `begin_keywords

View File

@ -87,6 +87,7 @@ public:
void reinsert(AstNode* nodep, VSymEnt* parentp = nullptr) { void reinsert(AstNode* nodep, VSymEnt* parentp = nullptr) {
reinsert(nodep, parentp, nodep->name()); reinsert(nodep, parentp, nodep->name());
} }
// cppcheck-suppress passedByValue
void reinsert(AstNode* nodep, VSymEnt* parentp, string name) { void reinsert(AstNode* nodep, VSymEnt* parentp, string name) {
if (!parentp) parentp = symCurrentp(); if (!parentp) parentp = symCurrentp();
if (name == "") { // New name with space in name so can't collide with users if (name == "") { // New name with space in name so can't collide with users

View File

@ -176,7 +176,7 @@ public: // Used only by V3PreLex.cpp and V3PreProc.cpp
int m_enterExit = 0; // For VL_LINE, the enter/exit level int m_enterExit = 0; // For VL_LINE, the enter/exit level
int m_protLength = 0; // unencoded length for BASE64 int m_protLength = 0; // unencoded length for BASE64
int m_protBytes = 0; // decoded length for BASE64 int m_protBytes = 0; // decoded length for BASE64
Enctype m_encType; // encoding type for `pragma protect Enctype m_encType{}; // encoding type for `pragma protect
// CONSTRUCTORS // CONSTRUCTORS
V3PreLex(V3PreProcImp* preimpp, FileLine* filelinep) V3PreLex(V3PreProcImp* preimpp, FileLine* filelinep)

View File

@ -90,6 +90,7 @@ private:
iterateChildren(nodep); iterateChildren(nodep);
// cppcheck-has-bug-suppress unreadVariable
const V3Hash hash = V3Hasher::uncachedHash(m_cfilep); const V3Hash hash = V3Hasher::uncachedHash(m_cfilep);
m_hashValuep->addText(fl, cvtToStr(hash.value()) + ";\n"); m_hashValuep->addText(fl, cvtToStr(hash.value()) + ";\n");
m_cHashValuep->addText(fl, cvtToStr(hash.value()) + "U;\n"); m_cHashValuep->addText(fl, cvtToStr(hash.value()) + "U;\n");

View File

@ -493,12 +493,12 @@ const TriggerKit createTriggers(AstNetlist* netlistp, AstCFunc* const initFuncp,
// Add the initialization statements // Add the initialization statements
if (initialTrigsp) { if (initialTrigsp) {
AstVarScope* const vscp = scopeTopp->createTemp("__V" + name + "DidInit", 1); AstVarScope* const tempVscp = scopeTopp->createTemp("__V" + name + "DidInit", 1);
AstVarRef* const condp = new AstVarRef{flp, vscp, VAccess::READ}; AstVarRef* const condp = new AstVarRef{flp, tempVscp, VAccess::READ};
AstIf* const ifp = new AstIf{flp, new AstNot{flp, condp}}; AstIf* const ifp = new AstIf{flp, new AstNot{flp, condp}};
funcp->addStmtsp(ifp); funcp->addStmtsp(ifp);
ifp->branchPred(VBranchPred::BP_UNLIKELY); ifp->branchPred(VBranchPred::BP_UNLIKELY);
ifp->addThensp(setVar(vscp, 1)); ifp->addThensp(setVar(tempVscp, 1));
ifp->addThensp(initialTrigsp); ifp->addThensp(initialTrigsp);
} }
@ -574,10 +574,10 @@ std::pair<AstVarScope*, AstNodeStmt*> makeEvalLoop(AstNetlist* netlistp, const s
// If we exceeded the iteration limit, die // If we exceeded the iteration limit, die
{ {
const uint32_t limit = v3Global.opt.convergeLimit(); const uint32_t limit = v3Global.opt.convergeLimit();
AstVarRef* const refp = new AstVarRef{flp, counterp, VAccess::READ}; AstVarRef* const counterRefp = new AstVarRef{flp, counterp, VAccess::READ};
AstConst* const constp = new AstConst{flp, AstConst::DTyped{}, counterp->dtypep()}; AstConst* const constp = new AstConst{flp, AstConst::DTyped{}, counterp->dtypep()};
constp->num().setLong(limit); constp->num().setLong(limit);
AstNodeExpr* const condp = new AstGt{flp, refp, constp}; AstNodeExpr* const condp = new AstGt{flp, counterRefp, constp};
AstIf* const failp = new AstIf{flp, condp}; AstIf* const failp = new AstIf{flp, condp};
failp->branchPred(VBranchPred::BP_UNLIKELY); failp->branchPred(VBranchPred::BP_UNLIKELY);
ifp->addThensp(failp); ifp->addThensp(failp);
@ -588,9 +588,9 @@ std::pair<AstVarScope*, AstNodeStmt*> makeEvalLoop(AstNetlist* netlistp, const s
const string& line = cvtToStr(locp->lineno()); const string& line = cvtToStr(locp->lineno());
const auto add = [&](const string& text) { blockp->addText(flp, text, true); }; const auto add = [&](const string& text) { blockp->addText(flp, text, true); };
add("#ifdef VL_DEBUG\n"); add("#ifdef VL_DEBUG\n");
AstCCall* const callp = new AstCCall{flp, trigDumpp}; AstCCall* const newcallp = new AstCCall{flp, trigDumpp};
callp->dtypeSetVoid(); newcallp->dtypeSetVoid();
blockp->addNodesp(callp->makeStmt()); blockp->addNodesp(newcallp->makeStmt());
add("#endif\n"); add("#endif\n");
add("VL_FATAL_MT(\"" + file + "\", " + line + ", \"\", "); add("VL_FATAL_MT(\"" + file + "\", " + line + ", \"\", ");
add("\"" + name + " region did not converge.\");\n"); add("\"" + name + " region did not converge.\");\n");

View File

@ -296,7 +296,6 @@ void transformForks(AstNetlist* const netlistp) {
AstVarScope* const vscp = refp->varScopep(); AstVarScope* const vscp = refp->varScopep();
if (!vscp->user2p()) { if (!vscp->user2p()) {
// Clone the var to the new function // Clone the var to the new function
AstVar* const varp = refp->varp();
AstVar* const newvarp AstVar* const newvarp
= new AstVar{varp->fileline(), VVarType::BLOCKTEMP, varp->name(), varp}; = new AstVar{varp->fileline(), VVarType::BLOCKTEMP, varp->name(), varp};
newvarp->funcLocal(true); newvarp->funcLocal(true);
@ -308,7 +307,7 @@ void transformForks(AstNetlist* const netlistp) {
vscp->user2p(newvscp); vscp->user2p(newvscp);
callp->addArgsp(new AstVarRef{refp->fileline(), vscp, VAccess::READ}); callp->addArgsp(new AstVarRef{refp->fileline(), vscp, VAccess::READ});
} }
auto* const newvscp = VN_AS(vscp->user2p(), VarScope); AstVarScope* const newvscp = VN_AS(vscp->user2p(), VarScope);
refp->varScopep(newvscp); refp->varScopep(newvscp);
refp->varp(newvscp->varp()); refp->varp(newvscp->varp());
}); });

View File

@ -244,7 +244,7 @@ public:
} }
// CONSTRUCTOR // CONSTRUCTOR
SenExprBuilder(AstScope* scopep) explicit SenExprBuilder(AstScope* scopep)
: m_scopep{scopep} {} : m_scopep{scopep} {}
}; };

View File

@ -382,7 +382,7 @@ private:
int unrollCount() const { int unrollCount() const {
return m_params ? v3Global.opt.unrollCount() * 16 : v3Global.opt.unrollCount(); return m_params ? v3Global.opt.unrollCount() * 16 : v3Global.opt.unrollCount();
} }
bool jumpingOver(AstNode* nodep) const { bool jumpingOver(const AstNode* nodep) const {
// True to jump over this node - all visitors must call this up front // True to jump over this node - all visitors must call this up front
return (m_jumpp && m_jumpp->labelp() != nodep); return (m_jumpp && m_jumpp->labelp() != nodep);
} }

View File

@ -675,6 +675,7 @@ class SplitUnpackedVarVisitor final : public VNVisitor, public SplitVarImpl {
setContextAndIterate(assignp, nodes[1]); setContextAndIterate(assignp, nodes[1]);
} }
} }
// cppcheck-has-bug-suppress constParameter
size_t collapse(UnpackRefMap& refs) { size_t collapse(UnpackRefMap& refs) {
size_t numSplit = 0; size_t numSplit = 0;
for (const auto& pair : refs) { for (const auto& pair : refs) {

View File

@ -121,8 +121,9 @@ class StatsReport final {
const V3Statistic* repp = &(*it); const V3Statistic* repp = &(*it);
if (repp->stage() != "*" && repp->printit()) { if (repp->stage() != "*" && repp->printit()) {
if (maxWidth < repp->name().length()) maxWidth = repp->name().length(); if (maxWidth < repp->name().length()) maxWidth = repp->name().length();
if (stageInt.find(repp->stage()) == stageInt.end()) { const auto itFoundPair = stageInt.emplace(repp->stage(), stage);
stageInt.emplace(repp->stage(), stage++); if (itFoundPair.second) {
++stage;
stages.push_back(repp->stage()); stages.push_back(repp->stage());
} }
byName.emplace(repp->name(), repp); byName.emplace(repp->name(), repp);

View File

@ -486,10 +486,8 @@ void V3TSP::tspSort(const V3TSP::StateVec& states, V3TSP::StateVec* resultp) {
for (V3TSP::StateVec::iterator it = prelim_result.begin(); it != prelim_result.end(); for (V3TSP::StateVec::iterator it = prelim_result.begin(); it != prelim_result.end();
++it) { ++it) {
const TspStateBase* const elemp = *it; const TspStateBase* const elemp = *it;
if (seen.find(elemp) == seen.end()) { const auto itFoundPair = seen.insert(elemp);
seen.insert(elemp); if (itFoundPair.second) resultp->push_back(elemp);
resultp->push_back(elemp);
}
} }
} }

View File

@ -1055,7 +1055,8 @@ def write_ast_op_checks(filename):
backp = tailp = opp; backp = tailp = opp;
opp = {next}; opp = {next};
}} while (opp); }} while (opp);
if (headp && tailp) {{}} // Prevent unused // cppcheck-suppress knownConditionTrueFalse
if (false && headp && tailp) {{}} // Prevent unused
UASSERT_OBJ(headp->m_headtailp == tailp, headp, "Tail in headtailp is inconsistent"); UASSERT_OBJ(headp->m_headtailp == tailp, headp, "Tail in headtailp is inconsistent");
UASSERT_OBJ(tailp->m_headtailp == headp, tailp, "Head in headtailp is inconsistent"); UASSERT_OBJ(tailp->m_headtailp == headp, tailp, "Head in headtailp is inconsistent");
}} }}

View File

@ -20,7 +20,6 @@ def process(cppcheck_args):
if Args.debug: if Args.debug:
print("\t" + cmd) print("\t" + cmd)
fh = os.popen(cmd) fh = os.popen(cmd)
uniq = {}
errs = False errs = False
last_error = "" last_error = ""
for line in fh: for line in fh:
@ -30,27 +29,23 @@ def process(cppcheck_args):
line = re.sub(r'^\s+', '', line) line = re.sub(r'^\s+', '', line)
# Sometimes tacked at end-of-line # Sometimes tacked at end-of-line
line = re.sub(r'Checking usage of global functions\.+', '', line) line = re.sub(r'Checking usage of global functions\.+', '', line)
# General gunk line = re.sub(r' file0="[^"]+"', r'', line)
if line in uniq:
continue
uniq[line] = 1
if re.search(r'^<\?xml version', line): if re.search(r'^<\?xml version', line):
continue continue
if re.search(r'^<cppcheck', line): if re.search(r'^<cppcheck', line):
continue continue
if re.search(r'^<results', line):
continue
if re.search(r'^</results>', line):
continue
if re.search(r'^<errors', line): if re.search(r'^<errors', line):
continue continue
if re.search(r'^</error>', line): if re.search(r'^</error>', line):
continue continue
if re.search(r'^</errors>', line): if re.search(r'^</errors>', line):
continue continue
# --suppress=unmatchedSuppression doesn't work if re.search(r'^<results', line):
if re.search(r'^<error.*id="unmatchedSuppression"', line): continue
if re.search(r'^</results>', line):
continue
if re.search(r'^<symbol>', line):
continue continue
# An earlier id line is more specific # An earlier id line is more specific
if re.search(r'Cppcheck cannot find all the include files', line): if re.search(r'Cppcheck cannot find all the include files', line):
@ -64,11 +59,6 @@ def process(cppcheck_args):
if re.search(r'^\s+$', line): if re.search(r'^\s+$', line):
continue continue
# Specific suppressions (see _suppress also)
# Doesn't know UINFO will use it
if re.search(r'id="unusedPrivateFunction" .*::debug', line):
continue
# Output # Output
if re.search(r'^cppcheck --', line): if re.search(r'^cppcheck --', line):
if Args.debug: if Args.debug:
@ -87,7 +77,7 @@ def process(cppcheck_args):
match = re.search(r'<location.* file="([^"]+)"\s+line="(\d+)"', line) match = re.search(r'<location.* file="([^"]+)"\s+line="(\d+)"', line)
if match: if match:
file = match.group(1) file = match.group(1)
linenum = match.group(2) linenum = int(match.group(2))
match = re.search(r' id="([^"]+)"', last_error) match = re.search(r' id="([^"]+)"', last_error)
eid = match.group(1) if match else '?' eid = match.group(1) if match else '?'
if _suppress(file, linenum, eid): if _suppress(file, linenum, eid):
@ -95,7 +85,7 @@ def process(cppcheck_args):
if file == "*": if file == "*":
suppress = True suppress = True
if not suppress: if not suppress:
print(file + ":" + linenum + ": " + last_error) print("%s:%s: %s" % (file, linenum, last_error))
suppress = True suppress = True
if not suppress: if not suppress:
@ -121,16 +111,42 @@ def _suppress(filename, linenum, eid):
filename = re.sub(r'^\.\./(.*)', r'src/\1', filename) filename = re.sub(r'^\.\./(.*)', r'src/\1', filename)
# Specific suppressions # Specific suppressions
if eid == 'asctimeCalled' and re.search(r'gtkwave/', filename):
return True
if eid == 'constParameter' and re.search(r'gtkwave/', filename):
return True
if eid == 'ctuOneDefinitionRuleViolation' and re.search(
r'vltstd/', filename):
return True
if eid == 'duplicateConditionalAssign' and re.search(
r'gtkwave/', filename):
return True
if eid == 'knownConditionTrueFalse' and re.search(r'gtkwave/', filename):
return True
if eid == 'missingInclude' and re.search(r'systemc.h', filename): if eid == 'missingInclude' and re.search(r'systemc.h', filename):
return True return True
if eid == 'missingInclude' and re.search(r'svdpi.h', filename): if eid == 'missingInclude' and re.search(r'svdpi.h', filename):
return True return True
if eid == 'shiftNegativeLHS' and re.search(r'gtkwave/', filename):
return True
if eid == 'shiftTooManyBits' and re.search(r'gtkwave/', filename):
return True
if eid == 'shiftTooManyBitsSigned' and re.search(r'gtkwave/', filename):
return True
if eid == 'nullPointerArithmetic' and re.search(r'gtkwave/', filename):
return True
if eid == 'unmatchedSuppression':
return True
if eid == 'unusedFunction' and re.search(r'verilated_dpi.cpp', filename): if eid == 'unusedFunction' and re.search(r'verilated_dpi.cpp', filename):
return True return True
if eid == 'unusedFunction' and re.search(r'verilated_vpi.cpp', filename): if eid == 'unusedFunction' and re.search(r'verilated_vpi.cpp', filename):
return True return True
if eid == 'unreachableCode' and re.search(r'V3ParseBison.c', filename): if eid == 'unreachableCode' and re.search(r'V3ParseBison.c', filename):
return True return True
if eid == 'unreadVariable' and re.search(r'gtkwave/', filename):
return True
if eid == 'uselessAssignmentPtrArg' and re.search(r'gtkwave/', filename):
return True
if eid == 'variableScope' and re.search(r'fstapi.c', filename): if eid == 'variableScope' and re.search(r'fstapi.c', filename):
return True return True
@ -143,10 +159,12 @@ def _suppress(filename, linenum, eid):
lineno = 0 lineno = 0
for line in fh: for line in fh:
lineno += 1 lineno += 1
if lineno + 1 == linenum: if ((lineno + 1) == linenum):
match = re.search(r'cppcheck-suppress((\s+\S+)+)', line) match = re.search(
r'(cppcheck|cppcheck-has-bug|cppverilator)-suppress((\s+\S+)+)',
line)
if match: if match:
for supid in match.group(1).split(): for supid in match.group(2).split():
if (supid == eid or (eid in SuppressMap if (supid == eid or (eid in SuppressMap
and supid == SuppressMap[eid])): and supid == SuppressMap[eid])):
return True return True