MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / valueFlowSymbolic

Function valueFlowSymbolic

lib/valueflow.cpp:3563–3624  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3561}
3562
3563static void valueFlowSymbolic(const TokenList& tokenlist, const SymbolDatabase& symboldatabase, ErrorLogger& errorLogger, const Settings& settings)
3564{
3565 for (const Scope* scope : symboldatabase.functionScopes) {
3566 for (auto* tok = const_cast<Token*>(scope->bodyStart); tok != scope->bodyEnd; tok = tok->next()) {
3567 if (!Token::simpleMatch(tok, "="))
3568 continue;
3569 if (tok->astParent())
3570 continue;
3571 if (!tok->astOperand1())
3572 continue;
3573 if (!tok->astOperand2())
3574 continue;
3575 if (tok->astOperand1()->hasKnownIntValue())
3576 continue;
3577 if (tok->astOperand2()->hasKnownIntValue())
3578 continue;
3579 if (tok->astOperand1()->exprId() == 0)
3580 continue;
3581 if (tok->astOperand2()->exprId() == 0)
3582 continue;
3583 if (!isConstExpression(tok->astOperand2(), settings.library))
3584 continue;
3585 if (tok->astOperand1()->valueType() && tok->astOperand2()->valueType()) {
3586 if (isTruncated(
3587 tok->astOperand2()->valueType(), tok->astOperand1()->valueType(), settings))
3588 continue;
3589 } else if (isDifferentType(tok->astOperand2(), tok->astOperand1(), settings)) {
3590 continue;
3591 }
3592 const std::set<nonneg int> rhsVarIds = getVarIds(tok->astOperand2());
3593 const std::vector<const Variable*> vars = getLHSVariables(tok);
3594 if (std::any_of(vars.cbegin(), vars.cend(), [&](const Variable* var) {
3595 if (rhsVarIds.count(var->declarationId()) > 0)
3596 return true;
3597 if (var->isLocal())
3598 return var->isStatic();
3599 return !var->isArgument();
3600 }))
3601 continue;
3602
3603 if (findAstNode(tok, [](const Token* child) {
3604 return child->isIncompleteVar();
3605 }))
3606 continue;
3607
3608 Token* start = nextAfterAstRightmostLeaf(tok);
3609 const Token* end = ValueFlow::getEndOfExprScope(tok->astOperand1(), scope);
3610
3611 ValueFlow::Value rhs = makeSymbolic(tok->astOperand2());
3612 rhs.errorPath.emplace_back(tok,
3613 tok->astOperand1()->expressionString() + " is assigned '" +
3614 tok->astOperand2()->expressionString() + "' here.");
3615 valueFlowForward(start, end, tok->astOperand1(), std::move(rhs), tokenlist, errorLogger, settings);
3616
3617 ValueFlow::Value lhs = makeSymbolic(tok->astOperand1());
3618 lhs.errorPath.emplace_back(tok,
3619 tok->astOperand1()->expressionString() + " is assigned '" +
3620 tok->astOperand2()->expressionString() + "' here.");

Callers 1

setValuesMethod · 0.85

Calls 15

isConstExpressionFunction · 0.85
isTruncatedFunction · 0.85
isDifferentTypeFunction · 0.85
getVarIdsFunction · 0.85
getLHSVariablesFunction · 0.85
findAstNodeFunction · 0.85
makeSymbolicFunction · 0.85
valueFlowForwardFunction · 0.85
nextMethod · 0.80
astParentMethod · 0.80
astOperand1Method · 0.80

Tested by

no test coverage detected