Skip to content

Commit 67076ae

Browse files
dmcppcheckclaude
andcommitted
ValueFlow: compare a hash of the values when skipping unchanged functions
Skipping a function in the next iteration when its number of values did not change missed changes where a value is replaced or changes kind (possible -> known) without changing the count. For example a call whose return value got known in valueFlowFunctionReturn. Compare a hash of all values in the function instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent f7639ab commit 67076ae

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

‎lib/valueflow.cpp‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7449,7 +7449,29 @@ struct ValueFlowPassRunner {
74497449
return false;
74507450
}
74517451

7452-
// Number of values in each function scope (same order as symboldatabase.functionScopes)
7452+
static std::size_t hashValue(const ValueFlow::Value& v)
7453+
{
7454+
std::size_t h = std::hash<MathLib::bigint>{}(v.intvalue);
7455+
const auto combine = [&h](std::size_t x) {
7456+
h ^= x + 0x9e3779b97f4a7c15ULL + (h << 6) + (h >> 2);
7457+
};
7458+
combine(static_cast<std::size_t>(v.valueType));
7459+
combine(static_cast<std::size_t>(v.valueKind));
7460+
combine(static_cast<std::size_t>(v.bound));
7461+
combine(std::hash<const Token*>{}(v.tokvalue));
7462+
combine(std::hash<const Token*>{}(v.condition));
7463+
combine(std::hash<double>{}(v.floatValue));
7464+
combine(std::hash<MathLib::bigint>{}(v.varvalue));
7465+
combine(std::hash<MathLib::bigint>{}(v.path));
7466+
combine(v.varId);
7467+
combine(static_cast<std::size_t>(v.conditional));
7468+
combine(static_cast<std::size_t>(v.moveKind));
7469+
combine(static_cast<std::size_t>(v.lifetimeKind));
7470+
combine(static_cast<std::size_t>(v.lifetimeScope));
7471+
return h;
7472+
}
7473+
7474+
// Hash of the values in each function scope (same order as symboldatabase.functionScopes)
74537475
std::vector<std::size_t> getFunctionValues() const
74547476
{
74557477
const std::vector<const Scope*>& functionScopes = state.symboldatabase().functionScopes;
@@ -7458,8 +7480,12 @@ struct ValueFlowPassRunner {
74587480
const Scope* scope = functionScopes[i];
74597481
if (!scope->bodyStart)
74607482
continue;
7461-
for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next())
7462-
result[i] += tok->values().size();
7483+
std::size_t h = 0;
7484+
for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
7485+
for (const ValueFlow::Value& v : tok->values())
7486+
h += hashValue(v) * (2 * reinterpret_cast<std::uintptr_t>(tok) + 1);
7487+
}
7488+
result[i] = h;
74637489
}
74647490
return result;
74657491
}

0 commit comments

Comments
 (0)