Skip to content

Commit 4d46b1f

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 aadc04a commit 4d46b1f

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
@@ -7422,7 +7422,29 @@ struct ValueFlowPassRunner {
74227422
return false;
74237423
}
74247424

7425-
// Number of values in each function scope (same order as symboldatabase.functionScopes)
7425+
static std::size_t hashValue(const ValueFlow::Value& v)
7426+
{
7427+
std::size_t h = std::hash<MathLib::bigint>{}(v.intvalue);
7428+
const auto combine = [&h](std::size_t x) {
7429+
h ^= x + 0x9e3779b97f4a7c15ULL + (h << 6) + (h >> 2);
7430+
};
7431+
combine(static_cast<std::size_t>(v.valueType));
7432+
combine(static_cast<std::size_t>(v.valueKind));
7433+
combine(static_cast<std::size_t>(v.bound));
7434+
combine(std::hash<const Token*>{}(v.tokvalue));
7435+
combine(std::hash<const Token*>{}(v.condition));
7436+
combine(std::hash<double>{}(v.floatValue));
7437+
combine(std::hash<MathLib::bigint>{}(v.varvalue));
7438+
combine(std::hash<MathLib::bigint>{}(v.path));
7439+
combine(v.varId);
7440+
combine(static_cast<std::size_t>(v.conditional));
7441+
combine(static_cast<std::size_t>(v.moveKind));
7442+
combine(static_cast<std::size_t>(v.lifetimeKind));
7443+
combine(static_cast<std::size_t>(v.lifetimeScope));
7444+
return h;
7445+
}
7446+
7447+
// Hash of the values in each function scope (same order as symboldatabase.functionScopes)
74267448
std::vector<std::size_t> getFunctionValues() const
74277449
{
74287450
const std::vector<const Scope*>& functionScopes = state.symboldatabase().functionScopes;
@@ -7431,8 +7453,12 @@ struct ValueFlowPassRunner {
74317453
const Scope* scope = functionScopes[i];
74327454
if (!scope->bodyStart)
74337455
continue;
7434-
for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next())
7435-
result[i] += tok->values().size();
7456+
std::size_t h = 0;
7457+
for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
7458+
for (const ValueFlow::Value& v : tok->values())
7459+
h += hashValue(v) * (2 * reinterpret_cast<std::uintptr_t>(tok) + 1);
7460+
}
7461+
result[i] = h;
74367462
}
74377463
return result;
74387464
}

0 commit comments

Comments
 (0)