Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
pfultz2 committed Nov 18, 2023
1 parent 5282581 commit c86e159
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
24 changes: 16 additions & 8 deletions lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,10 @@ static std::vector<const Token*> setDifference(const std::vector<const Token*>&
return result;
}

static bool evalSameCondition(const ProgramMemory& state, const Token* storedValue, const Token* cond, const Settings* settings)
static bool evalSameCondition(const ProgramMemory& state,
const Token* storedValue,
const Token* cond,
const Settings* settings)
{
assert(!conditionIsTrue(cond, state, settings));
ProgramMemory pm = state;
Expand All @@ -1229,17 +1232,22 @@ static bool evalSameCondition(const ProgramMemory& state, const Token* storedVal
return conditionIsTrue(cond, pm, settings);
}

static void pruneConditions(std::vector<const Token*>& conds, bool b, const std::unordered_map<nonneg int, ValueFlow::Value>& state)
static void pruneConditions(std::vector<const Token*>& conds,
bool b,
const std::unordered_map<nonneg int, ValueFlow::Value>& state)
{
conds.erase(std::remove_if(conds.begin(), conds.end(), [&](const Token* cond) {
conds.erase(std::remove_if(conds.begin(),
conds.end(),
[&](const Token* cond) {
if (cond->exprId() == 0)
return false;
auto it = state.find(cond->exprId());
if (it == state.end())
return false;
const ValueFlow::Value& v = it->second;
return isTrueOrFalse(v, !b);
}), conds.end());
}),
conds.end());
}

namespace {
Expand All @@ -1256,9 +1264,9 @@ namespace {
{
std::unordered_map<nonneg int, ValueFlow::Value> result;
auto state = *this;
for(const Token* tok:toks) {
for (const Token* tok : toks) {
ValueFlow::Value r = state.execute(tok);
if(r.isUninitValue())
if (r.isUninitValue())
continue;
result.insert(std::make_pair(tok->exprId(), r));
}
Expand Down Expand Up @@ -1294,7 +1302,7 @@ namespace {
return unknown;
std::vector<const Token*> conditions1 = flattenConditionsSorted(expr);
std::unordered_map<nonneg int, ValueFlow::Value> condValues = executeAll(conditions1);
for(const auto& p:condValues) {
for (const auto& p : condValues) {
const ValueFlow::Value& v = p.second;
if (isTrueOrFalse(v, b))
return v;
Expand Down Expand Up @@ -1599,7 +1607,7 @@ namespace {
ValueFlow::Value execute(const Token* expr)
{
depth--;
if(depth < 0)
if (depth < 0)
return unknown;
ValueFlow::Value v = executeImpl(expr);
if (!v.isUninitValue())
Expand Down
24 changes: 12 additions & 12 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7246,21 +7246,21 @@ class TestValueFlow : public TestFixture {
valueOfTok(code, "&");

code = "bool a(int *);\n"
"void fn2(int b) {\n"
" if (b) {\n"
" bool c, d, e;\n"
" if (c && d)\n"
" return;\n"
" if (e && a(&b)) {\n"
" }\n"
" }\n"
"}\n";
"void fn2(int b) {\n"
" if (b) {\n"
" bool c, d, e;\n"
" if (c && d)\n"
" return;\n"
" if (e && a(&b)) {\n"
" }\n"
" }\n"
"}\n";
valueOfTok(code, "e");

code = "void f(int a, int b, int c) {\n"
" if (c && (a || a && b))\n"
" if (a && b) {}\n"
"}\n";
" if (c && (a || a && b))\n"
" if (a && b) {}\n"
"}\n";
valueOfTok(code, "a");
}

Expand Down

0 comments on commit c86e159

Please sign in to comment.