Skip to content

Commit 1b11009

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 e2c7689 commit 1b11009

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
@@ -7369,7 +7369,29 @@ struct ValueFlowPassRunner {
73697369
return false;
73707370
}
73717371

7372-
// Number of values in each function scope (same order as symboldatabase.functionScopes)
7372+
static std::size_t hashValue(const ValueFlow::Value& v)
7373+
{
7374+
std::size_t h = std::hash<MathLib::bigint>{}(v.intvalue);
7375+
const auto combine = [&h](std::size_t x) {
7376+
h ^= x + 0x9e3779b97f4a7c15ULL + (h << 6) + (h >> 2);
7377+
};
7378+
combine(static_cast<std::size_t>(v.valueType));
7379+
combine(static_cast<std::size_t>(v.valueKind));
7380+
combine(static_cast<std::size_t>(v.bound));
7381+
combine(std::hash<const Token*>{}(v.tokvalue));
7382+
combine(std::hash<const Token*>{}(v.condition));
7383+
combine(std::hash<double>{}(v.floatValue));
7384+
combine(std::hash<MathLib::bigint>{}(v.varvalue));
7385+
combine(std::hash<MathLib::bigint>{}(v.path));
7386+
combine(v.varId);
7387+
combine(static_cast<std::size_t>(v.conditional));
7388+
combine(static_cast<std::size_t>(v.moveKind));
7389+
combine(static_cast<std::size_t>(v.lifetimeKind));
7390+
combine(static_cast<std::size_t>(v.lifetimeScope));
7391+
return h;
7392+
}
7393+
7394+
// Hash of the values in each function scope (same order as symboldatabase.functionScopes)
73737395
std::vector<std::size_t> getFunctionValues() const
73747396
{
73757397
const std::vector<const Scope*>& functionScopes = state.symboldatabase().functionScopes;
@@ -7378,8 +7400,12 @@ struct ValueFlowPassRunner {
73787400
const Scope* scope = functionScopes[i];
73797401
if (!scope->bodyStart)
73807402
continue;
7381-
for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next())
7382-
result[i] += tok->values().size();
7403+
std::size_t h = 0;
7404+
for (const Token* tok = scope->bodyStart; tok != scope->bodyEnd; tok = tok->next()) {
7405+
for (const ValueFlow::Value& v : tok->values())
7406+
h += hashValue(v) * (2 * reinterpret_cast<std::uintptr_t>(tok) + 1);
7407+
}
7408+
result[i] = h;
73837409
}
73847410
return result;
73857411
}

0 commit comments

Comments
 (0)