Skip to content

Commit d7ddf77

Browse files
committed
Fix unit tests
1 parent 417e0a7 commit d7ddf77

2 files changed

Lines changed: 41 additions & 11 deletions

File tree

lib/programmemory.cpp

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,19 @@ bool ProgramMemory::empty() const
207207
}
208208

209209
// NOLINTNEXTLINE(performance-unnecessary-value-param) - technically correct but we are moving the given values
210-
void ProgramMemory::replace(ProgramMemory pm)
210+
void ProgramMemory::replace(ProgramMemory pm, bool skipUnknown)
211211
{
212212
if (pm.empty())
213213
return;
214214

215215
copyOnWrite();
216216

217217
for (auto&& p : (*pm.mValues)) {
218+
if(skipUnknown) {
219+
auto it = mValues->find(p.first);
220+
if(it != mValues->end() && it->second.isUninitValue())
221+
continue;
222+
}
218223
(*mValues)[p.first] = std::move(p.second);
219224
}
220225
}
@@ -407,7 +412,8 @@ static void fillProgramMemoryFromAssignments(ProgramMemory& pm, const Token* tok
407412
if (!setvar) {
408413
if (!pm.hasValue(vartok->exprId())) {
409414
const Token* valuetok = tok2->astOperand2();
410-
pm.setValue(vartok, execute(valuetok, pm, settings));
415+
ProgramMemory local = state;
416+
pm.setValue(vartok, execute(valuetok, local, settings));
411417
}
412418
}
413419
} else if (tok2->exprId() > 0 && Token::Match(tok2, ".|(|[|*|%var%") && !pm.hasValue(tok2->exprId()) &&
@@ -478,7 +484,7 @@ void ProgramMemoryState::replace(ProgramMemory pm, const Token* origin)
478484
if (origin)
479485
for (const auto& p : pm)
480486
origins[p.first.getExpressionId()] = origin;
481-
state.replace(std::move(pm));
487+
state.replace(std::move(pm), true);
482488
}
483489

484490
static void addVars(ProgramMemory& pm, const ProgramMemory::Map& vars)
@@ -492,26 +498,50 @@ static void addVars(ProgramMemory& pm, const ProgramMemory::Map& vars)
492498
static void debugPrint(const ProgramMemory& pm)
493499
{
494500
for(auto&& p:pm) {
495-
std::cout << p.first->expressionString() << " => " << p.second.toString() << std::endl;
501+
if(p.first.tok)
502+
std::cout << p.first->expressionString();
503+
else
504+
std::cout << p.first.exprid;
505+
std::cout << " => " << p.second.toString() << std::endl;
496506
}
497507
}
498508

499509
void ProgramMemoryState::addState(const Token* tok, const ProgramMemory::Map& vars)
500510
{
501-
std::cout << "**************************************************************\n";
502-
std::cout << "addState: " << tok->expressionString() << std::endl;
503-
std::cout << "Before:\n";
504-
debugPrint(state);
511+
// std::cout << "**************************************************************\n";
512+
// std::cout << "addState: " << tok->expressionString() << std::endl;
513+
// std::cout << "Before:\n";
514+
// debugPrint(state);
505515
#if 1
516+
// ProgramMemory local = state;
517+
// addVars(local, vars);
518+
// fillProgramMemoryFromConditions(local, tok, settings);
519+
// ProgramMemory pm;
520+
// fillProgramMemoryFromAssignments(pm, tok, settings, local, vars);
521+
// local.replace(std::move(pm));
522+
// addVars(local, vars);
523+
// replace(std::move(local), tok);
524+
506525
ProgramMemory local = state;
507526
addVars(local, vars);
508527
fillProgramMemoryFromConditions(local, tok, settings);
509528
ProgramMemory pm;
510529
fillProgramMemoryFromAssignments(pm, tok, settings, local, vars);
511530
local.replace(std::move(pm));
531+
// ProgramMemory local2 = local;
532+
// fillProgramMemoryFromAssignments(local, tok, settings, local2, vars);
512533
addVars(local, vars);
513534
replace(std::move(local), tok);
514535
#else
536+
// ProgramMemory pm = state;
537+
// addVars(pm, vars);
538+
// for(int i =0;i<4;i++) {
539+
// fillProgramMemoryFromConditions(pm, tok, settings);
540+
// ProgramMemory local = pm;
541+
// fillProgramMemoryFromAssignments(pm, tok, settings, local, vars);
542+
// }
543+
// replace(std::move(pm), tok);
544+
515545
ProgramMemory pm = state;
516546
addVars(pm, vars);
517547
fillProgramMemoryFromConditions(pm, tok, settings);
@@ -520,8 +550,8 @@ void ProgramMemoryState::addState(const Token* tok, const ProgramMemory::Map& va
520550
addVars(pm, vars);
521551
replace(std::move(pm), tok);
522552
#endif
523-
std::cout << "After:\n";
524-
debugPrint(state);
553+
// std::cout << "After:\n";
554+
// debugPrint(state);
525555
}
526556

527557
void ProgramMemoryState::assume(const Token* tok, bool b, bool isEmpty)

lib/programmemory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ struct CPPCHECKLIB ProgramMemory {
130130

131131
bool empty() const;
132132

133-
void replace(ProgramMemory pm);
133+
void replace(ProgramMemory pm, bool skipUnknown = false);
134134

135135
Map::const_iterator begin() const {
136136
return mValues->cbegin();

0 commit comments

Comments
 (0)