From ae7b70fae9182c34e56706b9258f4decc0d0389d Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 25 Dec 2024 16:29:59 +0100 Subject: [PATCH 1/3] valueflow.cpp: do not create object until necessary in `LifetimeStore::byVal()` --- lib/valueflow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 070aa56742e..9fae6152f93 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2391,12 +2391,12 @@ struct LifetimeStore { for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(tok3, settings)) { if (!settings.certainty.isEnabled(Certainty::inconclusive) && lt.inconclusive) continue; - ErrorPath er = v.errorPath; - er.insert(er.end(), lt.errorPath.cbegin(), lt.errorPath.cend()); if (!lt.token) return false; if (!pred(lt.token)) return false; + ErrorPath er = v.errorPath; + er.insert(er.end(), lt.errorPath.cbegin(), lt.errorPath.cend()); er.emplace_back(argtok, message); er.insert(er.end(), errorPath.cbegin(), errorPath.cend()); From bd10ed4935a123dccb0799702d15af10c559ea1c Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 25 Dec 2024 16:54:34 +0100 Subject: [PATCH 2/3] valueflow.cpp: exit early in `LifetimeStore::byVal()` to avoid unnecessary object creation --- lib/valueflow.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 9fae6152f93..fd5f4afd842 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -2362,6 +2362,11 @@ struct LifetimeStore { for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(argtok, settings)) { if (!settings.certainty.isEnabled(Certainty::inconclusive) && lt.inconclusive) continue; + + const Variable* var = lt.token->variable(); + if (!var || !var->isArgument()) + continue; + ValueFlow::Value value; value.valueType = ValueFlow::Value::ValueType::LIFETIME; value.tokvalue = lt.token; @@ -2369,12 +2374,8 @@ struct LifetimeStore { value.errorPath = er; value.lifetimeKind = type; value.setInconclusive(inconclusive || lt.inconclusive); - const Variable* var = lt.token->variable(); - if (var && var->isArgument()) { - value.lifetimeScope = ValueFlow::Value::LifetimeScope::Argument; - } else { - continue; - } + value.lifetimeScope = ValueFlow::Value::LifetimeScope::Argument; + // Don't add the value a second time if (std::find(tok->values().cbegin(), tok->values().cend(), value) != tok->values().cend()) continue; From 612dae13b00d8cefa313e16fd798e27af57a0f0b Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 10 Jun 2025 12:01:26 +0200 Subject: [PATCH 3/3] valueflow.cpp: avoid unnecessary object creation in `valueFlowFunctionDefaultParameter()` --- lib/valueflow.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index fd5f4afd842..9799bb3e852 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -5890,11 +5890,12 @@ static void valueFlowFunctionDefaultParameter(const TokenList& tokenlist, const const std::list &values = var->nameToken()->tokAt(2)->values(); std::list argvalues; for (const ValueFlow::Value &value : values) { + if (!value.isKnown()) + continue; ValueFlow::Value v(value); v.defaultArg = true; - v.changeKnownToPossible(); - if (v.isPossible()) - argvalues.push_back(std::move(v)); + v.setPossible(); + argvalues.push_back(std::move(v)); } if (!argvalues.empty()) valueFlowInjectParameter(tokenlist, errorLogger, settings, var, scope, argvalues);