Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,6 @@ static void valueFlowImpossibleValues(TokenList& tokenList, const Settings& sett
flipped = true;
else if (!std::equal(tokens.cbegin(), tokens.cend(), branches.cbegin(), &isSameToken))
continue;
const bool isMin = Token::Match(condTok, "<|<=") ^ flipped;
std::vector<ValueFlow::Value> values;
for (const Token* tok2 : tokens) {
if (tok2->hasKnownIntValue()) {
Expand All @@ -1083,6 +1082,7 @@ static void valueFlowImpossibleValues(TokenList& tokenList, const Settings& sett
});
}
}
const bool isMin = Token::Match(condTok, "<|<=") ^ flipped;
for (ValueFlow::Value& value : values) {
value.setImpossible();
if (isMin) {
Expand Down Expand Up @@ -2072,12 +2072,12 @@ struct LifetimeStore {
for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(argtok, settings)) {
if (!settings.certainty.isEnabled(Certainty::inconclusive) && lt.inconclusive)
continue;
ErrorPath er = errorPath;
er.insert(er.end(), lt.errorPath.cbegin(), lt.errorPath.cend());
if (!lt.token)
return false;
if (!pred(lt.token))
return false;
ErrorPath er = errorPath;
er.insert(er.end(), lt.errorPath.cbegin(), lt.errorPath.cend());
er.emplace_back(argtok, message);

ValueFlow::Value value;
Expand Down Expand Up @@ -3332,7 +3332,6 @@ static void valueFlowConditionExpressions(const TokenList& tokenlist,
Token* parenTok = tok->next();
if (!Token::simpleMatch(parenTok->link(), ") {"))
continue;
Token* blockTok = parenTok->link()->tokAt(1);
const Token* condTok = parenTok->astOperand2();
if (condTok->exprId() == 0)
continue;
Expand All @@ -3343,6 +3342,7 @@ static void valueFlowConditionExpressions(const TokenList& tokenlist,
const bool isOp = condTok->isComparisonOp() || condTok->tokType() == Token::eLogicalOp;
const bool is1 = isOp || astIsBool(condTok);

Token* blockTok = parenTok->link()->tokAt(1);
Token* startTok = blockTok;
// Inner condition
{
Expand Down Expand Up @@ -3699,8 +3699,11 @@ static void valueFlowSymbolicInfer(const SymbolDatabase& symboldatabase, const S
if (astIsFloat(tok->astOperand2(), false))
continue;

SymbolicInferModel leftModel{tok->astOperand1()};
std::vector<ValueFlow::Value> values = infer(leftModel, tok->str(), 0, tok->astOperand2()->values());
std::vector<ValueFlow::Value> values;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't an opinion but we could also write:

 std::vector<ValueFlow::Value> values = [tok](){
        SymbolicInferModel leftModel{tok->astOperand1()};
        return infer(leftModel, tok->str(), 0, tok->astOperand2()->values());
 }();

Use the syntax you like..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not find that more readable. I am also not sure fi that might introduce some overhead.

I mainly changed this because I was debugging the lifetime of the infer models at some point and was confused that two of them were alive at the same time.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok np

{
SymbolicInferModel leftModel{tok->astOperand1()};
values = infer(leftModel, tok->str(), 0, tok->astOperand2()->values());
}
if (values.empty()) {
SymbolicInferModel rightModel{tok->astOperand2()};
values = infer(rightModel, tok->str(), tok->astOperand1()->values(), 0);
Expand Down
Loading