Internals: Improve cppcheck flow and fix up issues (#6311)

Added cppcheck-suppressions.txt in the repo root. You can add new
patterns in there instead of having to parse the XML output.

Also configure to add the -D__GNUC__ preprocessor macro, which makes it
understand UASSERT (it understands the 'noreturn' function attribute).

Added some case by case specific suppressions and fixed up other code,
especially in V3Ast*h and V3Dfg*.h, including code generated by astgen
that had some no-ops that irks cppcheck.

One thing it does not seem to like is `const` class members with default
initializers in the class. It will assume that's always the value, even
if overridden in the constructor. We had few so removed them.

With that a lot of files in `src/` are now clean or only have a handful
of issues. Therefore, I have also deleted cppcheck_filtered, and made it
produce human readable output straight to the terminal.

Regarding cleaning up the reported nits, I kind of got bored after
V3[A-E] so pausing here. Apologies for the merge conflicts.

Tested with cppcheck 2.13.0
This commit is contained in:
Geza Lore
2025-08-19 22:02:10 +01:00
committed by GitHub
parent 636a6b8cd2
commit a0edd4e907
44 changed files with 357 additions and 468 deletions
+4 -4
View File
@@ -216,7 +216,7 @@ class CaseVisitor final : public VNVisitor {
const uint32_t val = numval.toUInt();
uint32_t firstOverlap = 0;
AstNode* overlappedCondp = nullptr;
const AstNode* overlappedCondp = nullptr;
bool foundHit = false;
for (uint32_t i = 0; i < numCases; ++i) {
if ((i & mask) == val) {
@@ -307,7 +307,7 @@ class CaseVisitor final : public VNVisitor {
// Not done earlier, as we may now have a nullptr because it's just a ";" NOP branch
for (uint32_t i = 0; i < numCases; ++i) {
if (AstNode* const condp = m_valueItem[i]) {
AstCaseItem* caseItemp = caseItemMap[condp];
const AstCaseItem* const caseItemp = caseItemMap[condp];
UASSERT(caseItemp, "caseItemp should exist");
m_valueItem[i] = caseItemp->stmtsp();
}
@@ -325,7 +325,7 @@ class CaseVisitor final : public VNVisitor {
} else {
// Make left and right subtrees
// cexpr[msb:lsb] == 1
AstNode* tree0p = replaceCaseFastRecurse(cexprp, msb - 1, upperValue | 0);
AstNode* tree0p = replaceCaseFastRecurse(cexprp, msb - 1, upperValue);
AstNode* tree1p = replaceCaseFastRecurse(
cexprp, msb - 1, upperValue | (1UL << static_cast<uint32_t>(msb)));
@@ -548,7 +548,7 @@ class CaseVisitor final : public VNVisitor {
}
}
bool neverItem(AstCase* casep, AstConst* itemp) {
bool neverItem(const AstCase* casep, const AstConst* itemp) {
// Xs in case or casez are impossible due to two state simulations
if (casep->casex()) {
} else if (casep->casez() || casep->caseInside()) {