| 5062 | } |
| 5063 | |
| 5064 | static void valueFlowInferCondition(TokenList& tokenlist, const Settings& settings) |
| 5065 | { |
| 5066 | for (Token* tok = tokenlist.front(); tok; tok = tok->next()) { |
| 5067 | if (!tok->astParent()) |
| 5068 | continue; |
| 5069 | if (tok->hasKnownIntValue()) |
| 5070 | continue; |
| 5071 | if (Token::Match(tok, "%comp%|-") && tok->astOperand1() && tok->astOperand2()) { |
| 5072 | if (astIsIterator(tok->astOperand1()) || astIsIterator(tok->astOperand2())) { |
| 5073 | static const std::array<ValuePtr<InferModel>, 2> iteratorModels = {EndIteratorInferModel{}, |
| 5074 | StartIteratorInferModel{}}; |
| 5075 | for (const ValuePtr<InferModel>& model : iteratorModels) { |
| 5076 | std::vector<ValueFlow::Value> result = |
| 5077 | infer(model, tok->str(), tok->astOperand1()->values(), tok->astOperand2()->values()); |
| 5078 | for (ValueFlow::Value value : result) { |
| 5079 | value.valueType = ValueFlow::Value::ValueType::INT; |
| 5080 | setTokenValue(tok, std::move(value), settings); |
| 5081 | } |
| 5082 | } |
| 5083 | } else if (isIntegralOrPointer(tok->astOperand1()) && isIntegralOrPointer(tok->astOperand2())) { |
| 5084 | std::vector<ValueFlow::Value> result = |
| 5085 | infer(makeIntegralInferModel(), tok->str(), tok->astOperand1()->values(), tok->astOperand2()->values()); |
| 5086 | for (ValueFlow::Value& value : result) { |
| 5087 | setTokenValue(tok, std::move(value), settings); |
| 5088 | } |
| 5089 | } |
| 5090 | } else if (Token::Match(tok->astParent(), "?|&&|!|%oror%") || |
| 5091 | Token::Match(tok->astParent()->previous(), "if|while (") || |
| 5092 | (astIsPointer(tok) && isUsedAsBool(tok, settings))) { |
| 5093 | std::vector<ValueFlow::Value> result = infer(makeIntegralInferModel(), "!=", tok->values(), 0); |
| 5094 | if (result.size() != 1) |
| 5095 | continue; |
| 5096 | setTokenValue(tok, std::move(result.front()), settings); |
| 5097 | } |
| 5098 | } |
| 5099 | } |
| 5100 | |
| 5101 | struct SymbolicConditionHandler : SimpleConditionHandler { |
| 5102 |
no test coverage detected