diff --git a/Makefile b/Makefile
index ad9f84ee8ce..e2a15da9dc5 100644
--- a/Makefile
+++ b/Makefile
@@ -252,10 +252,19 @@ LIBOBJ = $(libcppdir)/valueflow.o \
$(libcppdir)/token.o \
$(libcppdir)/tokenlist.o \
$(libcppdir)/utils.o \
+ $(libcppdir)/vf_array.o \
+ $(libcppdir)/vf_bitand.o \
$(libcppdir)/vf_common.o \
+ $(libcppdir)/vf_debug.o \
$(libcppdir)/vf_enumvalue.o \
+ $(libcppdir)/vf_globalconstvar.o \
+ $(libcppdir)/vf_globalstaticvar.o \
$(libcppdir)/vf_number.o \
+ $(libcppdir)/vf_pointeralias.o \
+ $(libcppdir)/vf_sameexpressions.o \
$(libcppdir)/vf_settokenvalue.o \
+ $(libcppdir)/vf_string.o \
+ $(libcppdir)/vf_unknownfunctionreturn.o \
$(libcppdir)/vfvalue.o
EXTOBJ = externals/simplecpp/simplecpp.o \
@@ -464,7 +473,7 @@ validateRules:
###### Build
-$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/addoninfo.h lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/findtoken.h lib/forwardanalyzer.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/programmemory.h lib/reverseanalyzer.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vf_analyze.h lib/vf_common.h lib/vf_enumvalue.h lib/vf_number.h lib/vf_settokenvalue.h lib/vfvalue.h
+$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/addoninfo.h lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/findtoken.h lib/forwardanalyzer.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/programmemory.h lib/reverseanalyzer.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vf_analyze.h lib/vf_array.h lib/vf_bitand.h lib/vf_common.h lib/vf_debug.h lib/vf_enumvalue.h lib/vf_globalconstvar.h lib/vf_globalstaticvar.h lib/vf_number.h lib/vf_pointeralias.h lib/vf_sameexpressions.h lib/vf_settokenvalue.h lib/vf_string.h lib/vf_unknownfunctionreturn.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/valueflow.cpp
$(libcppdir)/tokenize.o: lib/tokenize.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/astutils.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/preprocessor.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/summaries.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vfvalue.h
@@ -650,18 +659,45 @@ $(libcppdir)/tokenlist.o: lib/tokenlist.cpp externals/simplecpp/simplecpp.h lib/
$(libcppdir)/utils.o: lib/utils.cpp lib/config.h lib/utils.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/utils.cpp
-$(libcppdir)/vf_common.o: lib/vf_common.cpp lib/addoninfo.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.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
+$(libcppdir)/vf_array.o: lib/vf_array.cpp lib/astutils.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vf_array.h lib/vf_settokenvalue.h lib/vfvalue.h
+ $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_array.cpp
+
+$(libcppdir)/vf_bitand.o: lib/vf_bitand.cpp lib/config.h lib/errortypes.h lib/mathlib.h lib/sourcelocation.h lib/standards.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vf_bitand.h lib/vf_settokenvalue.h lib/vfvalue.h
+ $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_bitand.cpp
+
+$(libcppdir)/vf_common.o: lib/vf_common.cpp lib/addoninfo.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vf_common.h lib/vf_settokenvalue.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_common.cpp
+$(libcppdir)/vf_debug.o: lib/vf_debug.cpp lib/addoninfo.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vf_common.h lib/vf_debug.h lib/vfvalue.h
+ $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_debug.cpp
+
$(libcppdir)/vf_enumvalue.o: lib/vf_enumvalue.cpp lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/valueflow.h lib/vf_enumvalue.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_enumvalue.cpp
+$(libcppdir)/vf_globalconstvar.o: lib/vf_globalconstvar.cpp lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vf_globalconstvar.h lib/vf_settokenvalue.h lib/vfvalue.h
+ $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_globalconstvar.cpp
+
+$(libcppdir)/vf_globalstaticvar.o: lib/vf_globalstaticvar.cpp lib/astutils.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vf_globalstaticvar.h lib/vf_settokenvalue.h lib/vfvalue.h
+ $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_globalstaticvar.cpp
+
$(libcppdir)/vf_number.o: lib/vf_number.cpp lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vf_common.h lib/vf_number.h lib/vf_settokenvalue.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_number.cpp
+$(libcppdir)/vf_pointeralias.o: lib/vf_pointeralias.cpp lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vf_pointeralias.h lib/vf_settokenvalue.h lib/vfvalue.h
+ $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_pointeralias.cpp
+
+$(libcppdir)/vf_sameexpressions.o: lib/vf_sameexpressions.cpp lib/astutils.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vf_sameexpressions.h lib/vf_settokenvalue.h lib/vfvalue.h
+ $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_sameexpressions.cpp
+
$(libcppdir)/vf_settokenvalue.o: lib/vf_settokenvalue.cpp lib/addoninfo.h lib/astutils.h lib/calculate.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.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
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_settokenvalue.cpp
+$(libcppdir)/vf_string.o: lib/vf_string.cpp lib/config.h lib/errortypes.h lib/mathlib.h lib/sourcelocation.h lib/standards.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vf_settokenvalue.h lib/vf_string.h lib/vfvalue.h
+ $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_string.cpp
+
+$(libcppdir)/vf_unknownfunctionreturn.o: lib/vf_unknownfunctionreturn.cpp lib/addoninfo.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vf_common.h lib/vf_settokenvalue.h lib/vf_unknownfunctionreturn.h lib/vfvalue.h
+ $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_unknownfunctionreturn.cpp
+
$(libcppdir)/vfvalue.o: lib/vfvalue.cpp lib/config.h lib/errortypes.h lib/mathlib.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vfvalue.cpp
diff --git a/lib/cppcheck.vcxproj b/lib/cppcheck.vcxproj
index 1ec10c8dbe8..78171d08a45 100644
--- a/lib/cppcheck.vcxproj
+++ b/lib/cppcheck.vcxproj
@@ -87,10 +87,19 @@
+
+
+
+
+
+
+
+
+
@@ -171,10 +180,19 @@
+
+
+
+
+
+
+
+
+
diff --git a/lib/lib.pri b/lib/lib.pri
index 45e0624dbf9..b2bcdf5c70f 100644
--- a/lib/lib.pri
+++ b/lib/lib.pri
@@ -78,10 +78,19 @@ HEADERS += $${PWD}/addoninfo.h \
$${PWD}/valueptr.h \
$${PWD}/version.h \
$${PWD}/vf_analyze.h \
+ $${PWD}/vf_array.h \
+ $${PWD}/vf_bitand.h \
$${PWD}/vf_common.h \
+ $${PWD}/vf_debug.h \
$${PWD}/vf_enumvalue.h \
+ $${PWD}/vf_globalconstvar.h \
+ $${PWD}/vf_globalstaticvar.h \
$${PWD}/vf_number.h \
+ $${PWD}/vf_pointeralias.h \
+ $${PWD}/vf_sameexpressions.h \
$${PWD}/vf_settokenvalue.h \
+ $${PWD}/vf_string.h \
+ $${PWD}/vf_unknownfunctionreturn.h \
$${PWD}/vfvalue.h \
$${PWD}/xml.h
@@ -147,8 +156,17 @@ SOURCES += $${PWD}/valueflow.cpp \
$${PWD}/token.cpp \
$${PWD}/tokenlist.cpp \
$${PWD}/utils.cpp \
+ $${PWD}/vf_array.cpp \
+ $${PWD}/vf_bitand.cpp \
$${PWD}/vf_common.cpp \
+ $${PWD}/vf_debug.cpp \
$${PWD}/vf_enumvalue.cpp \
+ $${PWD}/vf_globalconstvar.cpp \
+ $${PWD}/vf_globalstaticvar.cpp \
$${PWD}/vf_number.cpp \
+ $${PWD}/vf_pointeralias.cpp \
+ $${PWD}/vf_sameexpressions.cpp \
$${PWD}/vf_settokenvalue.cpp \
+ $${PWD}/vf_string.cpp \
+ $${PWD}/vf_unknownfunctionreturn.cpp \
$${PWD}/vfvalue.cpp
diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp
index d4f0f85bb52..da7ea11a51c 100644
--- a/lib/valueflow.cpp
+++ b/lib/valueflow.cpp
@@ -124,7 +124,6 @@
#include
#include
#include
-#include
#include
#include
#include
@@ -541,75 +540,6 @@ size_t ValueFlow::getSizeOf(const ValueType &vt, const Settings &settings, int m
return 0;
}
-static void valueFlowString(TokenList &tokenlist, const Settings& settings)
-{
- for (Token *tok = tokenlist.front(); tok; tok = tok->next()) {
- if (tok->tokType() == Token::eString) {
- ValueFlow::Value strvalue;
- strvalue.valueType = ValueFlow::Value::ValueType::TOK;
- strvalue.tokvalue = tok;
- strvalue.setKnown();
- setTokenValue(tok, std::move(strvalue), settings);
- }
- }
-}
-
-static void valueFlowArray(TokenList &tokenlist, const Settings &settings)
-{
- std::map constantArrays;
-
- for (Token *tok = tokenlist.front(); tok; tok = tok->next()) {
- if (tok->varId() > 0) {
- // array
- const std::map::const_iterator it = constantArrays.find(tok->varId());
- if (it != constantArrays.end()) {
- ValueFlow::Value value;
- value.valueType = ValueFlow::Value::ValueType::TOK;
- value.tokvalue = it->second;
- value.setKnown();
- setTokenValue(tok, std::move(value), settings);
- }
-
- // const array decl
- else if (tok->variable() && tok->variable()->isArray() && tok->variable()->isConst() &&
- tok->variable()->nameToken() == tok && Token::Match(tok, "%var% [ %num%| ] = {")) {
- Token* rhstok = tok->linkAt(1)->tokAt(2);
- constantArrays[tok->varId()] = rhstok;
- tok = rhstok->link();
- }
-
- // pointer = array
- else if (tok->variable() && tok->variable()->isArray() && Token::simpleMatch(tok->astParent(), "=") &&
- astIsRHS(tok) && tok->astParent()->astOperand1() &&
- tok->astParent()->astOperand1()->variable() &&
- tok->astParent()->astOperand1()->variable()->isPointer()) {
- ValueFlow::Value value;
- value.valueType = ValueFlow::Value::ValueType::TOK;
- value.tokvalue = tok;
- value.setKnown();
- setTokenValue(tok, std::move(value), settings);
- }
- continue;
- }
-
- if (Token::Match(tok, "const %type% %var% [ %num%| ] = {")) {
- Token *vartok = tok->tokAt(2);
- Token *rhstok = vartok->linkAt(1)->tokAt(2);
- constantArrays[vartok->varId()] = rhstok;
- tok = rhstok->link();
- continue;
- }
-
- if (Token::Match(tok, "const char %var% [ %num%| ] = %str% ;")) {
- Token *vartok = tok->tokAt(2);
- Token *strtok = vartok->linkAt(1)->tokAt(2);
- constantArrays[vartok->varId()] = strtok;
- tok = strtok->next();
- continue;
- }
- }
-}
-
static bool isNonZero(const Token *tok)
{
return tok && (!tok->hasKnownIntValue() || tok->values().front().intvalue != 0);
@@ -738,104 +668,6 @@ static void valueFlowArrayElement(TokenList& tokenlist, const Settings& settings
}
}
-static void valueFlowPointerAlias(TokenList &tokenlist, const Settings& settings)
-{
- for (Token *tok = tokenlist.front(); tok; tok = tok->next()) {
- // not address of
- if (!tok->isUnaryOp("&"))
- continue;
-
- // parent should be a '='
- if (!Token::simpleMatch(tok->astParent(), "="))
- continue;
-
- // child should be some buffer or variable
- const Token *vartok = tok->astOperand1();
- while (vartok) {
- if (vartok->str() == "[")
- vartok = vartok->astOperand1();
- else if (vartok->str() == "." || vartok->str() == "::")
- vartok = vartok->astOperand2();
- else
- break;
- }
- if (!(vartok && vartok->variable() && !vartok->variable()->isPointer()))
- continue;
-
- ValueFlow::Value value;
- value.valueType = ValueFlow::Value::ValueType::TOK;
- value.tokvalue = tok;
- setTokenValue(tok, std::move(value), settings);
- }
-}
-
-static void valueFlowBitAnd(TokenList &tokenlist, const Settings& settings)
-{
- for (Token *tok = tokenlist.front(); tok; tok = tok->next()) {
- if (tok->str() != "&")
- continue;
-
- if (tok->hasKnownValue())
- continue;
-
- if (!tok->astOperand1() || !tok->astOperand2())
- continue;
-
- MathLib::bigint number;
- if (MathLib::isInt(tok->astOperand1()->str()))
- number = MathLib::toBigNumber(tok->astOperand1()->str());
- else if (MathLib::isInt(tok->astOperand2()->str()))
- number = MathLib::toBigNumber(tok->astOperand2()->str());
- else
- continue;
-
- int bit = 0;
- while (bit <= (MathLib::bigint_bits - 2) && ((((MathLib::bigint)1) << bit) < number))
- ++bit;
-
- if ((((MathLib::bigint)1) << bit) == number) {
- setTokenValue(tok, ValueFlow::Value(0), settings);
- setTokenValue(tok, ValueFlow::Value(number), settings);
- }
- }
-}
-
-static void valueFlowSameExpressions(TokenList &tokenlist, const Settings& settings)
-{
- for (Token *tok = tokenlist.front(); tok; tok = tok->next()) {
- if (tok->hasKnownIntValue())
- continue;
-
- if (!tok->astOperand1() || !tok->astOperand2())
- continue;
-
- if (tok->astOperand1()->isLiteral() || tok->astOperand2()->isLiteral())
- continue;
-
- if (!astIsIntegral(tok->astOperand1(), false) && !astIsIntegral(tok->astOperand2(), false))
- continue;
-
- ValueFlow::Value val;
-
- if (Token::Match(tok, "==|>=|<=|/")) {
- val = ValueFlow::Value(1);
- val.setKnown();
- }
-
- if (Token::Match(tok, "!=|>|<|%|-")) {
- val = ValueFlow::Value(0);
- val.setKnown();
- }
-
- if (!val.isKnown())
- continue;
-
- if (isSameExpression(false, tok->astOperand1(), tok->astOperand2(), settings, true, true, &val.errorPath)) {
- setTokenValue(tok, std::move(val), settings);
- }
- }
-}
-
static bool getExpressionRange(const Token *expr, MathLib::bigint *minvalue, MathLib::bigint *maxvalue)
{
if (expr->hasKnownIntValue()) {
@@ -1095,88 +927,6 @@ static void valueFlowImpossibleValues(TokenList& tokenList, const Settings& sett
}
}
-static void valueFlowGlobalConstVar(TokenList& tokenList, const Settings &settings)
-{
- // Get variable values...
- std::map vars;
- for (const Token* tok = tokenList.front(); tok; tok = tok->next()) {
- if (!tok->variable())
- continue;
- // Initialization...
- if (tok == tok->variable()->nameToken() &&
- !tok->variable()->isVolatile() &&
- !tok->variable()->isArgument() &&
- tok->variable()->isConst() &&
- tok->valueType() &&
- tok->valueType()->isIntegral() &&
- tok->valueType()->pointer == 0 &&
- tok->valueType()->constness == 1 &&
- Token::Match(tok, "%name% =") &&
- tok->next()->astOperand2() &&
- tok->next()->astOperand2()->hasKnownIntValue()) {
- vars[tok->variable()] = tok->next()->astOperand2()->values().front();
- }
- }
-
- // Set values..
- for (Token* tok = tokenList.front(); tok; tok = tok->next()) {
- if (!tok->variable())
- continue;
- const std::map::const_iterator var = vars.find(tok->variable());
- if (var == vars.end())
- continue;
- setTokenValue(tok, var->second, settings);
- }
-}
-
-static void valueFlowGlobalStaticVar(TokenList &tokenList, const Settings &settings)
-{
- // Get variable values...
- std::map vars;
- for (const Token *tok = tokenList.front(); tok; tok = tok->next()) {
- if (!tok->variable())
- continue;
- // Initialization...
- if (tok == tok->variable()->nameToken() &&
- tok->variable()->isStatic() &&
- !tok->variable()->isConst() &&
- tok->valueType() &&
- tok->valueType()->isIntegral() &&
- tok->valueType()->pointer == 0 &&
- tok->valueType()->constness == 0 &&
- Token::Match(tok, "%name% =") &&
- tok->next()->astOperand2() &&
- tok->next()->astOperand2()->hasKnownIntValue()) {
- vars[tok->variable()] = tok->next()->astOperand2()->values().front();
- } else {
- // If variable is written anywhere in TU then remove it from vars
- if (!tok->astParent())
- continue;
- if (Token::Match(tok->astParent(), "++|--|&") && !tok->astParent()->astOperand2())
- vars.erase(tok->variable());
- else if (tok->astParent()->isAssignmentOp()) {
- if (tok == tok->astParent()->astOperand1())
- vars.erase(tok->variable());
- else if (tok->isCpp() && Token::Match(tok->astParent()->tokAt(-2), "& %name% ="))
- vars.erase(tok->variable());
- } else if (isLikelyStreamRead(tok->astParent())) {
- vars.erase(tok->variable());
- } else if (Token::Match(tok->astParent(), "[(,]"))
- vars.erase(tok->variable());
- }
- }
-
- // Set values..
- for (Token *tok = tokenList.front(); tok; tok = tok->next()) {
- if (!tok->variable())
- continue;
- const std::map::const_iterator var = vars.find(tok->variable());
- if (var == vars.end())
- continue;
- setTokenValue(tok, var->second, settings);
- }
-}
-
static ValuePtr makeAnalyzer(const Token* exprTok, ValueFlow::Value value, const Settings& settings);
static ValuePtr makeReverseAnalyzer(const Token* exprTok, ValueFlow::Value value, const Settings& settings);
@@ -8255,18 +8005,6 @@ static void valueFlowDynamicBufferSize(const TokenList& tokenlist, const SymbolD
}
}
-static bool getMinMaxValues(const std::string &typestr, const Settings &settings, bool cpp, MathLib::bigint &minvalue, MathLib::bigint &maxvalue)
-{
- TokenList typeTokens(&settings);
- std::istringstream istr(typestr+";");
- if (!typeTokens.createTokens(istr, cpp ? Standards::Language::CPP : Standards::Language::C))
- return false;
- typeTokens.simplifyPlatformTypes();
- typeTokens.simplifyStdType();
- const ValueType &vt = ValueType::parseDecl(typeTokens.front(), settings);
- return ValueFlow::getMinMaxValues(&vt, settings.platform, minvalue, maxvalue);
-}
-
static void valueFlowSafeFunctions(const TokenList& tokenlist, const SymbolDatabase& symboldatabase, ErrorLogger& errorLogger, const Settings& settings)
{
for (const Scope *functionScope : symboldatabase.functionScopes) {
@@ -8365,54 +8103,6 @@ static void valueFlowSafeFunctions(const TokenList& tokenlist, const SymbolDatab
}
}
-static void valueFlowUnknownFunctionReturn(TokenList &tokenlist, const Settings &settings)
-{
- if (settings.checkUnknownFunctionReturn.empty())
- return;
- for (Token *tok = tokenlist.front(); tok; tok = tok->next()) {
- if (!tok->astParent() || tok->str() != "(" || !tok->previous()->isName())
- continue;
- if (settings.checkUnknownFunctionReturn.find(tok->strAt(-1)) == settings.checkUnknownFunctionReturn.end())
- continue;
- std::vector unknownValues = settings.library.unknownReturnValues(tok->astOperand1());
- if (unknownValues.empty())
- continue;
-
- // Get min/max values for return type
- const std::string &typestr = settings.library.returnValueType(tok->previous());
- MathLib::bigint minvalue, maxvalue;
- if (!getMinMaxValues(typestr, settings, tok->isCpp(), minvalue, maxvalue))
- continue;
-
- for (MathLib::bigint value : unknownValues) {
- if (value < minvalue)
- value = minvalue;
- else if (value > maxvalue)
- value = maxvalue;
- setTokenValue(tok, ValueFlow::Value(value), settings);
- }
- }
-}
-
-static void valueFlowDebug(TokenList& tokenlist, ErrorLogger& errorLogger, const Settings& settings)
-{
- if (!settings.debugnormal && !settings.debugwarnings)
- return;
- for (Token* tok = tokenlist.front(); tok; tok = tok->next()) {
- if (tok->getTokenDebug() != TokenDebug::ValueFlow)
- continue;
- if (tok->astParent() && tok->astParent()->getTokenDebug() == TokenDebug::ValueFlow)
- continue;
- for (const ValueFlow::Value& v : tok->values()) {
- std::string msg = "The value is " + debugString(v);
- ErrorPath errorPath = v.errorPath;
- errorPath.insert(errorPath.end(), v.debugPath.cbegin(), v.debugPath.cend());
- errorPath.emplace_back(tok, "");
- errorLogger.reportErr({errorPath, &tokenlist, Severity::debug, "valueFlow", msg, CWE{0}, Certainty::normal});
- }
- }
-}
-
const ValueFlow::Value *ValueFlow::valueFlowConstantFoldAST(Token *expr, const Settings &settings)
{
if (expr && expr->values().empty()) {
@@ -8636,17 +8326,17 @@ void ValueFlow::setValues(TokenList& tokenlist,
runner.run_once({
VFA(analyzeEnumValue(symboldatabase, settings)),
VFA(analyzeNumber(tokenlist, settings)),
- VFA(valueFlowString(tokenlist, settings)),
- VFA(valueFlowArray(tokenlist, settings)),
- VFA(valueFlowUnknownFunctionReturn(tokenlist, settings)),
- VFA(valueFlowGlobalConstVar(tokenlist, settings)),
+ VFA(analyzeString(tokenlist, settings)),
+ VFA(analyzeArray(tokenlist, settings)),
+ VFA(analyzeUnknownFunctionReturn(tokenlist, settings)),
+ VFA(analyzeGlobalConstVar(tokenlist, settings)),
VFA(analyzeEnumValue(symboldatabase, settings)),
- VFA(valueFlowGlobalStaticVar(tokenlist, settings)),
- VFA(valueFlowPointerAlias(tokenlist, settings)),
+ VFA(analyzeGlobalStaticVar(tokenlist, settings)),
+ VFA(analyzePointerAlias(tokenlist, settings)),
VFA(valueFlowLifetime(tokenlist, errorLogger, settings)),
VFA(valueFlowSymbolic(tokenlist, symboldatabase, errorLogger, settings)),
- VFA(valueFlowBitAnd(tokenlist, settings)),
- VFA(valueFlowSameExpressions(tokenlist, settings)),
+ VFA(analyzeBitAnd(tokenlist, settings)),
+ VFA(analyzeSameExpressions(tokenlist, settings)),
VFA(valueFlowConditionExpressions(tokenlist, symboldatabase, errorLogger, settings)),
});
@@ -8683,7 +8373,7 @@ void ValueFlow::setValues(TokenList& tokenlist,
runner.run_once({
VFA(valueFlowDynamicBufferSize(tokenlist, symboldatabase, errorLogger, settings)),
- VFA(valueFlowDebug(tokenlist, errorLogger, settings)),
+ VFA(analyzeDebug(tokenlist, errorLogger, settings)),
});
}
diff --git a/lib/vf_analyze.h b/lib/vf_analyze.h
index 41608a06ede..6ad7b910f2b 100644
--- a/lib/vf_analyze.h
+++ b/lib/vf_analyze.h
@@ -19,7 +19,16 @@
#ifndef vfAnalyzeH
#define vfAnalyzeH
+#include "vf_array.h" // IWYU pragma: export
+#include "vf_bitand.h" // IWYU pragma: export
+#include "vf_debug.h" // IWYU pragma: export
#include "vf_enumvalue.h" // IWYU pragma: export
+#include "vf_globalconstvar.h" // IWYU pragma: export
+#include "vf_globalstaticvar.h" // IWYU pragma: export
#include "vf_number.h" // IWYU pragma: export
+#include "vf_pointeralias.h" // IWYU pragma: export
+#include "vf_sameexpressions.h" // IWYU pragma: export
+#include "vf_string.h" // IWYU pragma: export
+#include "vf_unknownfunctionreturn.h" // IWYU pragma: export
#endif // vfAnalyzeH
diff --git a/lib/vf_array.cpp b/lib/vf_array.cpp
new file mode 100644
index 00000000000..1fd14a9bff4
--- /dev/null
+++ b/lib/vf_array.cpp
@@ -0,0 +1,90 @@
+/*
+ * Cppcheck - A tool for static C/C++ code analysis
+ * Copyright (C) 2007-2024 Cppcheck team.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "vf_array.h"
+
+#include "astutils.h"
+#include "config.h"
+#include "symboldatabase.h"
+#include "token.h"
+#include "tokenlist.h"
+#include "vfvalue.h"
+
+#include "vf_settokenvalue.h"
+
+#include