Skip to content

Commit 4bbaae3

Browse files
committed
Fix #15000: Propagate integral cast ranges with path-safe value flow
1 parent edf0fd6 commit 4bbaae3

32 files changed

Lines changed: 5844 additions & 629 deletions

‎.selfcheck_suppressions‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ functionStatic:*/gui/ui_*.h
4949
# --debug-warnings suppressions
5050
valueFlowBailout
5151
valueFlowBailoutIncompleteVar
52-
valueFlowMaxIterations:gui/resultstree.cpp
5352
autoNoType:externals/simplecpp/simplecpp.cpp
5453
autoNoType:cli/*.cpp
5554
autoNoType:lib/*.cpp

‎Makefile‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ $(libcppdir)/addoninfo.o: lib/addoninfo.cpp externals/picojson/picojson.h lib/ad
499499
$(libcppdir)/analyzerinfo.o: lib/analyzerinfo.cpp externals/tinyxml2/tinyxml2.h lib/analyzerinfo.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/mathlib.h lib/path.h lib/platform.h lib/refthunk.h lib/standards.h lib/utils.h lib/xml.h
500500
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/analyzerinfo.cpp
501501

502-
$(libcppdir)/astutils.o: lib/astutils.cpp lib/astutils.h lib/check.h lib/checkclass.h lib/checkers.h lib/checkimpl.h lib/config.h lib/errortypes.h lib/findtoken.h lib/infer.h lib/library.h lib/mathlib.h lib/platform.h lib/refthunk.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vfvalue.h
502+
$(libcppdir)/astutils.o: lib/astutils.cpp lib/astutils.h lib/check.h lib/checkclass.h lib/checkers.h lib/checkimpl.h lib/config.h lib/errortypes.h lib/findtoken.h lib/infer.h lib/library.h lib/mathlib.h lib/platform.h lib/refthunk.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vf_common.h lib/vfvalue.h
503503
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/astutils.cpp
504504

505505
$(libcppdir)/check64bit.o: lib/check64bit.cpp lib/check.h lib/check64bit.h lib/checkers.h lib/checkimpl.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/refthunk.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
@@ -520,7 +520,7 @@ $(libcppdir)/checkbufferoverrun.o: lib/checkbufferoverrun.cpp externals/tinyxml2
520520
$(libcppdir)/checkclass.o: lib/checkclass.cpp externals/tinyxml2/tinyxml2.h lib/astutils.h lib/check.h lib/checkclass.h lib/checkers.h lib/checkimpl.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/refthunk.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h lib/xml.h
521521
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checkclass.cpp
522522

523-
$(libcppdir)/checkcondition.o: lib/checkcondition.cpp lib/astutils.h lib/check.h lib/checkcondition.h lib/checkers.h lib/checkimpl.h lib/checkother.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/refthunk.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
523+
$(libcppdir)/checkcondition.o: lib/checkcondition.cpp lib/astutils.h lib/check.h lib/checkcondition.h lib/checkers.h lib/checkimpl.h lib/checkother.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/refthunk.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vf_common.h lib/vfvalue.h
524524
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checkcondition.cpp
525525

526526
$(libcppdir)/checkers.o: lib/checkers.cpp lib/checkers.h lib/config.h
@@ -688,10 +688,10 @@ $(libcppdir)/utils.o: lib/utils.cpp lib/config.h lib/utils.h
688688
$(libcppdir)/vf_analyzers.o: lib/vf_analyzers.cpp lib/analyzer.h lib/astutils.h lib/calculate.h lib/checkers.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/programmemory.h lib/refthunk.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vf_analyzers.h lib/vf_common.h lib/vf_settokenvalue.h lib/vfvalue.h
689689
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_analyzers.cpp
690690

691-
$(libcppdir)/vf_common.o: lib/vf_common.cpp lib/astutils.h lib/checkers.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/refthunk.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/vf_common.h lib/vf_settokenvalue.h lib/vfvalue.h
691+
$(libcppdir)/vf_common.o: lib/vf_common.cpp lib/astutils.h lib/checkers.h lib/config.h lib/errortypes.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/refthunk.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/vf_common.h lib/vf_settokenvalue.h lib/vfvalue.h
692692
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_common.cpp
693693

694-
$(libcppdir)/vf_settokenvalue.o: lib/vf_settokenvalue.cpp lib/astutils.h lib/calculate.h lib/checkers.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/refthunk.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/valueflow.h lib/vf_common.h lib/vf_settokenvalue.h lib/vfvalue.h
694+
$(libcppdir)/vf_settokenvalue.o: lib/vf_settokenvalue.cpp lib/astutils.h lib/calculate.h lib/checkers.h lib/config.h lib/errortypes.h lib/infer.h lib/library.h lib/mathlib.h lib/platform.h lib/refthunk.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vf_common.h lib/vf_settokenvalue.h lib/vfvalue.h
695695
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_settokenvalue.cpp
696696

697697
$(libcppdir)/vfvalue.o: lib/vfvalue.cpp lib/config.h lib/errortypes.h lib/mathlib.h lib/smallvector.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/vfvalue.h
@@ -961,7 +961,7 @@ test/testutils.o: test/testutils.cpp lib/check.h lib/checkers.h lib/color.h lib/
961961
test/testvaarg.o: test/testvaarg.cpp lib/check.h lib/checkers.h lib/checkimpl.h lib/checkvaarg.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/refthunk.h lib/settings.h lib/standards.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h
962962
$(CXX) ${INCLUDE_FOR_TEST} ${CFLAGS_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testvaarg.cpp
963963

964-
test/testvalueflow.o: test/testvalueflow.cpp lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/refthunk.h lib/settings.h lib/smallvector.h lib/standards.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
964+
test/testvalueflow.o: test/testvalueflow.cpp lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/refthunk.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueptr.h lib/vf_common.h lib/vfvalue.h test/fixture.h test/helpers.h
965965
$(CXX) ${INCLUDE_FOR_TEST} ${CFLAGS_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testvalueflow.cpp
966966

967967
test/testvarid.o: test/testvarid.cpp lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/refthunk.h lib/settings.h lib/smallvector.h lib/standards.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h

‎lib/astutils.cpp‎

Lines changed: 97 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "utils.h"
3434
#include "valueflow.h"
3535
#include "valueptr.h"
36+
#include "vf_common.h"
3637
#include "vfvalue.h"
3738

3839
#include "checkclass.h"
@@ -42,6 +43,7 @@
4243
#include <functional>
4344
#include <initializer_list>
4445
#include <iterator>
46+
#include <limits>
4547
#include <list>
4648
#include <set>
4749
#include <type_traits>
@@ -835,6 +837,17 @@ bool astIsRHS(const Token* tok)
835837
return parent->astOperand2() == tok;
836838
}
837839

840+
std::string invertOperatorForOperandSwap(std::string op)
841+
{
842+
if (op.empty())
843+
return op;
844+
if (op[0] == '<')
845+
op[0] = '>';
846+
else if (op[0] == '>')
847+
op[0] = '<';
848+
return op;
849+
}
850+
838851
template<class T, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*> )>
839852
static T* getCondTokImpl(T* tok)
840853
{
@@ -952,56 +965,66 @@ const Token *findNextTokenFromBreak(const Token *breakToken)
952965
return nullptr;
953966
}
954967

955-
bool extractForLoopValues(const Token *forToken,
956-
nonneg int &varid,
957-
bool &knownInitValue,
958-
MathLib::bigint &initValue,
959-
bool &partialCond,
960-
MathLib::bigint &stepValue,
961-
MathLib::bigint &lastValue)
968+
ForLoopValues extractForLoopValues(const Token *forToken)
962969
{
970+
ForLoopValues values;
963971
if (!Token::simpleMatch(forToken, "for (") || !Token::simpleMatch(forToken->next()->astOperand2(), ";"))
964-
return false;
972+
return values;
965973
const Token *initExpr = forToken->next()->astOperand2()->astOperand1();
966974
const Token *condExpr = forToken->next()->astOperand2()->astOperand2()->astOperand1();
967975
const Token *incExpr = forToken->next()->astOperand2()->astOperand2()->astOperand2();
968976
if (!initExpr || !initExpr->isBinaryOp() || initExpr->str() != "=" || !Token::Match(initExpr->astOperand1(), "%var%"))
969-
return false;
970-
std::vector<MathLib::bigint> minInitValue =
971-
getMinValue(makeIntegralInferModel(), initExpr->astOperand2()->values());
972-
if (minInitValue.empty()) {
973-
const ValueFlow::Value* v = initExpr->astOperand2()->getMinValue(true);
974-
if (v)
975-
minInitValue.push_back(v->intvalue);
977+
return values;
978+
const Token* const initToken = initExpr->astOperand2();
979+
const std::vector<MathLib::bigint> minInitValue =
980+
getMinValue(makeIntegralInferModel(), initToken->values());
981+
values.initValueSource = getMinValueSource(makeIntegralInferModel(), initToken->values());
982+
values.hasMinimum = !minInitValue.empty();
983+
if (values.hasMinimum) {
984+
values.knownInitValue = initToken->hasKnownIntValue();
985+
values.initValue = minInitValue.front();
986+
if (values.knownInitValue && values.initValueSource &&
987+
values.initValueSource->bound != ValueFlow::Value::Bound::Point) {
988+
const auto it = std::find_if(initToken->values().cbegin(),
989+
initToken->values().cend(),
990+
[&](const ValueFlow::Value& value) {
991+
return value.isIntValue() && !value.isImpossible() && !value.isInconclusive() &&
992+
value.bound == ValueFlow::Value::Bound::Point && value.intvalue == values.initValue;
993+
});
994+
if (it != initToken->values().cend())
995+
values.initValueSource = &*it;
996+
}
976997
}
977-
if (minInitValue.empty())
978-
return false;
979-
varid = initExpr->astOperand1()->varId();
980-
knownInitValue = initExpr->astOperand2()->hasKnownIntValue();
981-
initValue = minInitValue.front();
982-
partialCond = Token::Match(condExpr, "%oror%|&&");
983-
visitAstNodes(condExpr, [varid, &condExpr](const Token *tok) {
998+
values.varid = initExpr->astOperand1()->varId();
999+
values.partialCond = Token::Match(condExpr, "%oror%|&&");
1000+
visitAstNodes(condExpr, [&](const Token *tok) {
9841001
if (Token::Match(tok, "%oror%|&&"))
9851002
return ChildrenToVisit::op1_and_op2;
986-
if (Token::Match(tok, "<|<=") && tok->isBinaryOp() && tok->astOperand1()->varId() == varid && tok->astOperand2()->hasKnownIntValue()) {
1003+
if (Token::Match(tok, "<|<=") && tok->isBinaryOp() && tok->astOperand1()->varId() == values.varid &&
1004+
tok->astOperand2()->hasKnownIntValue()) {
9871005
if (Token::Match(condExpr, "%oror%|&&") || tok->astOperand2()->getKnownIntValue() < condExpr->astOperand2()->getKnownIntValue())
9881006
condExpr = tok;
9891007
}
9901008
return ChildrenToVisit::none;
9911009
});
992-
if (!Token::Match(condExpr, "<|<=") || !condExpr->isBinaryOp() || condExpr->astOperand1()->varId() != varid || !condExpr->astOperand2()->hasKnownIntValue())
993-
return false;
994-
if (!incExpr || !incExpr->isUnaryOp("++") || incExpr->astOperand1()->varId() != varid)
995-
return false;
996-
stepValue = 1;
997-
if (condExpr->str() == "<")
998-
lastValue = condExpr->astOperand2()->getKnownIntValue() - 1;
999-
else
1000-
lastValue = condExpr->astOperand2()->getKnownIntValue();
1001-
return true;
1010+
if (!Token::Match(condExpr, "<|<=") || !condExpr->isBinaryOp() || condExpr->astOperand1()->varId() != values.varid ||
1011+
!condExpr->astOperand2()->hasKnownIntValue())
1012+
return values;
1013+
if (!incExpr || !incExpr->isUnaryOp("++") || incExpr->astOperand1()->varId() != values.varid)
1014+
return values;
1015+
values.stepValue = 1;
1016+
if (condExpr->str() == "<") {
1017+
const MathLib::bigint limit = condExpr->astOperand2()->getKnownIntValue();
1018+
if (limit == std::numeric_limits<MathLib::bigint>::min())
1019+
return values;
1020+
values.lastValue = limit - 1;
1021+
} else {
1022+
values.lastValue = condExpr->astOperand2()->getKnownIntValue();
1023+
}
1024+
values.valid = true;
1025+
return values;
10021026
}
10031027

1004-
10051028
static const Token * getVariableInitExpression(const Variable * var)
10061029
{
10071030
if (!var)
@@ -1476,6 +1499,22 @@ static inline bool isDifferentKnownValues(const Token * const tok1, const Token
14761499
});
14771500
}
14781501

1502+
// Like isDifferentKnownValues(), but the two constants are read as they compare against 'exprTok'.
1503+
static bool isDifferentKnownValues(const Token* tok1, const Token* tok2, const Token* exprTok, const Settings& settings)
1504+
{
1505+
return compareKnownValue(tok1, tok2, [&](const ValueFlow::Value& v1, const ValueFlow::Value& v2, bool sameLifetime) {
1506+
if (!v1.isIntValue() || !v2.isIntValue()) {
1507+
bool equal = v1.equalValue(v2);
1508+
if (v1.isIteratorValue())
1509+
equal &= sameLifetime;
1510+
return !equal;
1511+
}
1512+
const MathLib::bigint value1 = ValueFlow::castConstantToOperandType(tok1, exprTok, v1.intvalue, settings);
1513+
const MathLib::bigint value2 = ValueFlow::castConstantToOperandType(tok2, exprTok, v2.intvalue, settings);
1514+
return value1 != value2;
1515+
});
1516+
}
1517+
14791518
static inline bool isSameConstantValue(bool macro, const Token* tok1, const Token* tok2)
14801519
{
14811520
if (tok1 == nullptr || tok2 == nullptr)
@@ -1903,9 +1942,9 @@ bool isOppositeCond(bool isNot, const Token * const cond1, const Token * const c
19031942
if (!isNot) {
19041943
if (cond1->str() == "==" && cond2->str() == "==") {
19051944
if (isSameExpression(true, cond1->astOperand1(), cond2->astOperand1(), settings, pure, followVar, errors))
1906-
return isDifferentKnownValues(cond1->astOperand2(), cond2->astOperand2());
1945+
return isDifferentKnownValues(cond1->astOperand2(), cond2->astOperand2(), cond1->astOperand1(), settings);
19071946
if (isSameExpression(true, cond1->astOperand2(), cond2->astOperand2(), settings, pure, followVar, errors))
1908-
return isDifferentKnownValues(cond1->astOperand1(), cond2->astOperand1());
1947+
return isDifferentKnownValues(cond1->astOperand1(), cond2->astOperand1(), cond1->astOperand2(), settings);
19091948
}
19101949

19111950
if (Library::isContainerYield(cond1, Library::Container::Yield::EMPTY, "empty") &&
@@ -2011,10 +2050,16 @@ bool isOppositeCond(bool isNot, const Token * const cond1, const Token * const c
20112050
const ValueFlow::Value &rhsValue1 = value1->values().front();
20122051
const ValueFlow::Value &rhsValue2 = value2->values().front();
20132052

2053+
// The operands are compared in their common type. When one side is an unsigned constant and the
2054+
// other a signed expression, the comparison happens in the unsigned domain, so the constant must be
2055+
// read as that expression's type would see it: 0xFFFFFFFFu is -1 for an 'int' operand.
2056+
const MathLib::bigint bound1 = ValueFlow::castConstantToOperandType(value1, expr1, rhsValue1.intvalue, settings);
2057+
const MathLib::bigint bound2 = ValueFlow::castConstantToOperandType(value2, expr2, rhsValue2.intvalue, settings);
2058+
20142059
if (op1 == "<" || op1 == "<=")
2015-
return (op2 == "==" || op2 == ">" || op2 == ">=") && (rhsValue1.intvalue < rhsValue2.intvalue);
2060+
return (op2 == "==" || op2 == ">" || op2 == ">=") && (bound1 < bound2);
20162061
if (op1 == ">=" || op1 == ">")
2017-
return (op2 == "==" || op2 == "<" || op2 == "<=") && (rhsValue1.intvalue > rhsValue2.intvalue);
2062+
return (op2 == "==" || op2 == "<" || op2 == "<=") && (bound1 > bound2);
20182063

20192064
return false;
20202065
}
@@ -3934,6 +3979,20 @@ const Token *skipUnreachableBranch(const Token *tok)
39343979
return tok;
39353980
}
39363981

3982+
bool isInUnreachableBranch(const Token *tok)
3983+
{
3984+
for (const Scope *scope = tok->scope(); scope; scope = scope->nestedIn) {
3985+
if (scope->type != ScopeType::eIf && scope->type != ScopeType::eElse)
3986+
continue;
3987+
const Token *body = scope->bodyStart;
3988+
if (!body || body->str() != "{" || scope->bodyEnd != body->link())
3989+
continue;
3990+
if (skipUnreachableBranch(body) != body)
3991+
return true;
3992+
}
3993+
return false;
3994+
}
3995+
39373996
bool isEscapeKeyword(const Token *tok, const Settings &settings)
39383997
{
39393998
if (!tok)

‎lib/astutils.h‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ std::vector<ValueType> getParentValueTypes(const Token* tok,
213213
bool astIsLHS(const Token* tok);
214214
bool astIsRHS(const Token* tok);
215215

216+
/** The comparison operator that tests the left operand, i.e. the one with the operands exchanged. */
217+
std::string invertOperatorForOperandSwap(std::string op);
218+
216219
Token* getCondTok(Token* tok);
217220
const Token* getCondTok(const Token* tok);
218221

@@ -230,15 +233,22 @@ const Token* getCondTokFromEnd(const Token* endBlock);
230233
const Token *findNextTokenFromBreak(const Token *breakToken);
231234

232235
/**
233-
* Extract for loop values: loopvar varid, init value, step value, last value (inclusive)
236+
* The values of a for loop that can be extracted: loop variable id, init value, step value,
237+
* last value (inclusive). `initValueSource` identifies the fact supplying the minimum.
234238
*/
235-
bool extractForLoopValues(const Token *forToken,
236-
nonneg int &varid,
237-
bool &knownInitValue,
238-
MathLib::bigint &initValue,
239-
bool &partialCond,
240-
MathLib::bigint &stepValue,
241-
MathLib::bigint &lastValue);
239+
struct ForLoopValues {
240+
bool valid = false;
241+
bool hasMinimum = false;
242+
bool knownInitValue = false;
243+
bool partialCond = false;
244+
nonneg int varid = 0;
245+
MathLib::bigint initValue = 0;
246+
MathLib::bigint stepValue = 0;
247+
MathLib::bigint lastValue = 0;
248+
const ValueFlow::Value* initValueSource = nullptr;
249+
};
250+
251+
ForLoopValues extractForLoopValues(const Token *forToken);
242252

243253
bool precedes(const Token * tok1, const Token * tok2);
244254
bool succeeds(const Token* tok1, const Token* tok2);
@@ -466,6 +476,9 @@ bool isUnreachableOperand(const Token *tok);
466476

467477
const Token *skipUnreachableBranch(const Token *tok);
468478

479+
/** Is 'tok' inside a branch that skipUnreachableBranch() proves unreachable? */
480+
bool isInUnreachableBranch(const Token *tok);
481+
469482
bool isEscapeKeyword(const Token *tok, const Settings &settings);
470483

471484
#endif // astutilsH

0 commit comments

Comments
 (0)