Skip to content

Commit 676c07c

Browse files
committed
avoid some unnecessary Token::hasKnownIntValue() calls
1 parent b3fd6cc commit 676c07c

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

lib/astutils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,11 +1656,11 @@ bool isSameExpression(bool macro, const Token *tok1, const Token *tok2, const Se
16561656
const Token* varTok1 = nullptr;
16571657
const Token* varTok2 = exprTok;
16581658
const ValueFlow::Value* value = nullptr;
1659-
if (condTok->astOperand1()->hasKnownIntValue()) {
1660-
value = condTok->astOperand1()->getKnownValue(ValueFlow::Value::ValueType::INT);
1659+
if (const ValueFlow::Value* v_int = condTok->astOperand1()->getKnownValue(ValueFlow::Value::ValueType::INT)) {
1660+
value = v_int;
16611661
varTok1 = condTok->astOperand2();
1662-
} else if (condTok->astOperand2()->hasKnownIntValue()) {
1663-
value = condTok->astOperand2()->getKnownValue(ValueFlow::Value::ValueType::INT);
1662+
} else if (const ValueFlow::Value* v_int = condTok->astOperand2()->getKnownValue(ValueFlow::Value::ValueType::INT)) {
1663+
value = v_int;
16641664
varTok1 = condTok->astOperand1();
16651665
}
16661666
const bool exprIsNot = Token::simpleMatch(exprTok, "!");

lib/checkbufferoverrun.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ static std::vector<ValueFlow::Value> getOverrunIndexValues(const Token* tok,
267267
? ValueFlow::isOutOfBounds(makeSizeValue(size, path), indexTokens[i])
268268
: std::vector<ValueFlow::Value>{};
269269
if (values.empty()) {
270-
if (indexTokens[i]->hasKnownIntValue())
271-
indexValues.push_back(*indexTokens[i]->getKnownValue(ValueFlow::Value::ValueType::INT));
270+
if (const ValueFlow::Value* v = indexTokens[i]->getKnownValue(ValueFlow::Value::ValueType::INT))
271+
indexValues.push_back(*v);
272272
else
273273
indexValues.push_back(ValueFlow::Value::unknown());
274274
continue;

lib/valueflow.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ static void parseCompareEachInt(
317317
const std::function<void(const Token* varTok, ValueFlow::Value true_value, ValueFlow::Value false_value)>& each)
318318
{
319319
parseCompareEachInt(tok, each, [](const Token* t) -> std::vector<ValueFlow::Value> {
320-
if (t->hasKnownIntValue())
321-
return {*t->getKnownValue(ValueFlow::Value::ValueType::INT)};
320+
if (const ValueFlow::Value* v = t->getKnownValue(ValueFlow::Value::ValueType::INT))
321+
return {*v};
322322
std::vector<ValueFlow::Value> result;
323323
std::copy_if(t->values().cbegin(), t->values().cend(), std::back_inserter(result), [&](const ValueFlow::Value& v) {
324324
if (v.path < 1)
@@ -767,12 +767,12 @@ static void valueFlowArrayElement(TokenList& tokenlist, const Settings& settings
767767
if (index < 0 || index >= args.size())
768768
continue;
769769
const Token* arg = args[static_cast<std::size_t>(index)];
770-
if (!arg->hasKnownIntValue())
771-
continue;
772770
const ValueFlow::Value* v = arg->getKnownValue(ValueFlow::Value::ValueType::INT);
773-
result.intvalue = v->intvalue;
774-
result.errorPath.insert(result.errorPath.end(), v->errorPath.cbegin(), v->errorPath.cend());
775-
setTokenValue(tok, std::move(result), settings);
771+
if (v) {
772+
result.intvalue = v->intvalue;
773+
result.errorPath.insert(result.errorPath.end(), v->errorPath.cbegin(), v->errorPath.cend());
774+
setTokenValue(tok, std::move(result), settings);
775+
}
776776
}
777777
}
778778
}
@@ -1065,8 +1065,8 @@ static void valueFlowImpossibleValues(TokenList& tokenList, const Settings& sett
10651065
continue;
10661066
std::vector<ValueFlow::Value> values;
10671067
for (const Token* tok2 : tokens) {
1068-
if (tok2->hasKnownIntValue()) {
1069-
values.emplace_back(*tok2->getKnownValue(ValueFlow::Value::ValueType::INT));
1068+
if (const ValueFlow::Value* v = tok2->getKnownValue(ValueFlow::Value::ValueType::INT)) {
1069+
values.emplace_back(*v);
10701070
} else {
10711071
ValueFlow::Value symValue{};
10721072
symValue.valueType = ValueFlow::Value::ValueType::SYMBOLIC;
@@ -3606,12 +3606,12 @@ static void valueFlowSymbolicOperators(const SymbolDatabase& symboldatabase, con
36063606
continue;
36073607
const ValueFlow::Value* constant = nullptr;
36083608
const Token* vartok = nullptr;
3609-
if (tok->astOperand1()->hasKnownIntValue()) {
3610-
constant = tok->astOperand1()->getKnownValue(ValueFlow::Value::ValueType::INT);
3609+
if (const ValueFlow::Value* v = tok->astOperand1()->getKnownValue(ValueFlow::Value::ValueType::INT)) {
3610+
constant = v;
36113611
vartok = tok->astOperand2();
36123612
}
3613-
if (tok->astOperand2()->hasKnownIntValue()) {
3614-
constant = tok->astOperand2()->getKnownValue(ValueFlow::Value::ValueType::INT);
3613+
if (const ValueFlow::Value* v = tok->astOperand2()->getKnownValue(ValueFlow::Value::ValueType::INT)) {
3614+
constant = v;
36153615
vartok = tok->astOperand1();
36163616
}
36173617
if (!constant)

0 commit comments

Comments
 (0)