Skip to content

Commit 33c2c43

Browse files
Remove valueFlowArrayBool() (redundancy with valueFlowImpossibleValues()) (#8905)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent 1516cd2 commit 33c2c43

2 files changed

Lines changed: 2 additions & 56 deletions

File tree

‎lib/valueflow.cpp‎

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -691,57 +691,6 @@ static void valueFlowArray(TokenList& tokenlist, const Settings& settings)
691691
}
692692
}
693693

694-
static bool isNonZero(const Token* tok)
695-
{
696-
return tok && (!tok->hasKnownIntValue() || tok->getKnownIntValue() != 0);
697-
}
698-
699-
static const Token* getOtherOperand(const Token* tok)
700-
{
701-
if (!tok)
702-
return nullptr;
703-
if (!tok->astParent())
704-
return nullptr;
705-
if (tok->astParent()->astOperand1() != tok)
706-
return tok->astParent()->astOperand1();
707-
if (tok->astParent()->astOperand2() != tok)
708-
return tok->astParent()->astOperand2();
709-
return nullptr;
710-
}
711-
712-
static void valueFlowArrayBool(TokenList& tokenlist, const Settings& settings)
713-
{
714-
for (Token* tok = tokenlist.front(); tok; tok = tok->next()) {
715-
if (tok->hasKnownIntValue())
716-
continue;
717-
const Variable* var = nullptr;
718-
bool known = false;
719-
const auto val =
720-
std::find_if(tok->values().cbegin(), tok->values().cend(), std::mem_fn(&ValueFlow::Value::isTokValue));
721-
if (val == tok->values().end()) {
722-
var = tok->variable();
723-
known = true;
724-
} else {
725-
var = val->tokvalue->variable();
726-
known = val->isKnown();
727-
}
728-
if (!var)
729-
continue;
730-
if (!var->isArray() || var->isArgument() || var->getTypeName() == "std::array")
731-
continue;
732-
if (isNonZero(getOtherOperand(tok)) && Token::Match(tok->astParent(), "%comp%"))
733-
continue;
734-
// TODO: Check for function argument
735-
if ((astIsBool(tok->astParent()) && !Token::Match(tok->astParent(), "(|%name%")) ||
736-
(tok->astParent() && Token::Match(tok->astParent()->previous(), "if|while|for ("))) {
737-
ValueFlow::Value value{1};
738-
if (known)
739-
value.setKnown();
740-
setTokenValue(tok, std::move(value), settings);
741-
}
742-
}
743-
}
744-
745694
static void valueFlowArrayElement(TokenList& tokenlist, const Settings& settings)
746695
{
747696
for (Token* tok = tokenlist.front(); tok; tok = tok->next()) {
@@ -7540,7 +7489,6 @@ void ValueFlow::setValues(TokenList& tokenlist,
75407489
VFA(valueFlowSymbolicOperators(symboldatabase, settings)),
75417490
VFA(valueFlowCondition(SymbolicConditionHandler{}, tokenlist, symboldatabase, errorLogger, settings, skippedFunctions)),
75427491
VFA(valueFlowSymbolicInfer(symboldatabase, settings)),
7543-
VFA(valueFlowArrayBool(tokenlist, settings)),
75447492
VFA(valueFlowArrayElement(tokenlist, settings)),
75457493
VFA(valueFlowRightShift(tokenlist, settings)),
75467494
VFA_CPP(

‎test/cli/other_test.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,6 @@ def test_progress(tmpdir):
190190
"progress: ValueFlow::valueFlowCondition(SymbolicConditionHandler{}, tokenlist, symboldatabase, errorLogger, settings, skippedFunctions) 1 100%\n"
191191
"progress: ValueFlow::valueFlowSymbolicInfer(symboldatabase, settings) 1 0%\n"
192192
"progress: ValueFlow::valueFlowSymbolicInfer(symboldatabase, settings) 1 100%\n"
193-
"progress: ValueFlow::valueFlowArrayBool(tokenlist, settings) 1 0%\n"
194-
"progress: ValueFlow::valueFlowArrayBool(tokenlist, settings) 1 100%\n"
195193
"progress: ValueFlow::valueFlowArrayElement(tokenlist, settings) 1 0%\n"
196194
"progress: ValueFlow::valueFlowArrayElement(tokenlist, settings) 1 100%\n"
197195
"progress: ValueFlow::valueFlowRightShift(tokenlist, settings) 1 0%\n"
@@ -1069,7 +1067,7 @@ def test_showtime_top5_summary_compdb(tmp_path):
10691067

10701068

10711069
def __test_showtime_file(tmp_path, use_compdb=False, use_addons=False, use_clang_tidy=False):
1072-
exp_res = 79
1070+
exp_res = 78
10731071
# project analysis does not call Preprocessor::getConfig()
10741072
if use_compdb:
10751073
exp_res -= 1
@@ -1103,7 +1101,7 @@ def test_showtime_file_clang_tidy_compdb(tmp_path):
11031101

11041102

11051103
def __test_showtime_summary(tmp_path, use_compdb=False, use_addons=False, use_clang_tidy=False):
1106-
exp_res = 79
1104+
exp_res = 78
11071105
# project analysis does not call Preprocessor::getConfig()
11081106
if use_compdb:
11091107
exp_res -= 1

0 commit comments

Comments
 (0)