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

Function valueFlowSameExpressions

lib/valueflow.cpp:884–917  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

882}
883
884static void valueFlowSameExpressions(TokenList& tokenlist, const Settings& settings)
885{
886 for (Token* tok = tokenlist.front(); tok; tok = tok->next()) {
887 if (tok->hasKnownIntValue())
888 continue;
889
890 if (!tok->astOperand1() || !tok->astOperand2())
891 continue;
892
893 if (tok->astOperand1()->isLiteral() || tok->astOperand2()->isLiteral())
894 continue;
895
896 if (!astIsIntegral(tok->astOperand1(), false) && !astIsIntegral(tok->astOperand2(), false))
897 continue;
898
899 long long val;
900
901 if (Token::Match(tok, "==|>=|<=|/|/=")) {
902 val = 1;
903 }
904 else if (Token::Match(tok, "!=|>|<|%|%=|-|-=|^|^=")) {
905 val = 0;
906 }
907 else
908 continue;
909
910 ValueFlow::Value value(val);
911 value.setKnown();
912
913 if (isSameExpression(false, tok->astOperand1(), tok->astOperand2(), settings, true, true, &value.errorPath)) {
914 setTokenValue(tok, std::move(value), settings);
915 }
916 }
917}
918
919static bool getExpressionRange(const Token* expr, MathLib::bigint* minvalue, MathLib::bigint* maxvalue)
920{

Callers 1

setValuesMethod · 0.85

Calls 8

astIsIntegralFunction · 0.85
isSameExpressionFunction · 0.85
setTokenValueFunction · 0.85
frontMethod · 0.80
nextMethod · 0.80
astOperand1Method · 0.80
astOperand2Method · 0.80
hasKnownIntValueMethod · 0.45

Tested by

no test coverage detected