Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 0 additions & 52 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,57 +691,6 @@ static void valueFlowArray(TokenList& tokenlist, const Settings& settings)
}
}

static bool isNonZero(const Token* tok)
{
return tok && (!tok->hasKnownIntValue() || tok->getKnownIntValue() != 0);
}

static const Token* getOtherOperand(const Token* tok)
{
if (!tok)
return nullptr;
if (!tok->astParent())
return nullptr;
if (tok->astParent()->astOperand1() != tok)
return tok->astParent()->astOperand1();
if (tok->astParent()->astOperand2() != tok)
return tok->astParent()->astOperand2();
return nullptr;
}

static void valueFlowArrayBool(TokenList& tokenlist, const Settings& settings)
{
for (Token* tok = tokenlist.front(); tok; tok = tok->next()) {
if (tok->hasKnownIntValue())
continue;
const Variable* var = nullptr;
bool known = false;
const auto val =
std::find_if(tok->values().cbegin(), tok->values().cend(), std::mem_fn(&ValueFlow::Value::isTokValue));
if (val == tok->values().end()) {
var = tok->variable();
known = true;
} else {
var = val->tokvalue->variable();
known = val->isKnown();
}
if (!var)
continue;
if (!var->isArray() || var->isArgument() || var->isStlType())
continue;
if (isNonZero(getOtherOperand(tok)) && Token::Match(tok->astParent(), "%comp%"))
continue;
// TODO: Check for function argument
if ((astIsBool(tok->astParent()) && !Token::Match(tok->astParent(), "(|%name%")) ||
(tok->astParent() && Token::Match(tok->astParent()->previous(), "if|while|for ("))) {
ValueFlow::Value value{1};
if (known)
value.setKnown();
setTokenValue(tok, std::move(value), settings);
}
}
}

static void valueFlowArrayElement(TokenList& tokenlist, const Settings& settings)
{
for (Token* tok = tokenlist.front(); tok; tok = tok->next()) {
Expand Down Expand Up @@ -7536,7 +7485,6 @@ void ValueFlow::setValues(TokenList& tokenlist,
VFA(valueFlowSymbolicOperators(symboldatabase, settings)),
VFA(valueFlowCondition(SymbolicConditionHandler{}, tokenlist, symboldatabase, errorLogger, settings, skippedFunctions)),
VFA(valueFlowSymbolicInfer(symboldatabase, settings)),
VFA(valueFlowArrayBool(tokenlist, settings)),
VFA(valueFlowArrayElement(tokenlist, settings)),
VFA(valueFlowRightShift(tokenlist, settings)),
VFA_CPP(
Expand Down
6 changes: 2 additions & 4 deletions test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ def test_progress(tmpdir):
"progress: ValueFlow::valueFlowCondition(SymbolicConditionHandler{}, tokenlist, symboldatabase, errorLogger, settings, skippedFunctions) 1 100%\n"
"progress: ValueFlow::valueFlowSymbolicInfer(symboldatabase, settings) 1 0%\n"
"progress: ValueFlow::valueFlowSymbolicInfer(symboldatabase, settings) 1 100%\n"
"progress: ValueFlow::valueFlowArrayBool(tokenlist, settings) 1 0%\n"
"progress: ValueFlow::valueFlowArrayBool(tokenlist, settings) 1 100%\n"
"progress: ValueFlow::valueFlowArrayElement(tokenlist, settings) 1 0%\n"
"progress: ValueFlow::valueFlowArrayElement(tokenlist, settings) 1 100%\n"
"progress: ValueFlow::valueFlowRightShift(tokenlist, settings) 1 0%\n"
Expand Down Expand Up @@ -1069,7 +1067,7 @@ def test_showtime_top5_summary_compdb(tmp_path):


def __test_showtime_file(tmp_path, use_compdb=False, use_addons=False, use_clang_tidy=False):
exp_res = 79
exp_res = 78
# project analysis does not call Preprocessor::getConfig()
if use_compdb:
exp_res -= 1
Expand Down Expand Up @@ -1103,7 +1101,7 @@ def test_showtime_file_clang_tidy_compdb(tmp_path):


def __test_showtime_summary(tmp_path, use_compdb=False, use_addons=False, use_clang_tidy=False):
exp_res = 79
exp_res = 78
# project analysis does not call Preprocessor::getConfig()
if use_compdb:
exp_res -= 1
Expand Down
Loading