@@ -227,14 +227,19 @@ bool ProgramMemory::empty() const
227227}
228228
229229// NOLINTNEXTLINE(performance-unnecessary-value-param) - technically correct but we are moving the given values
230- void ProgramMemory::replace (ProgramMemory pm)
230+ void ProgramMemory::replace (ProgramMemory pm, bool skipUnknown )
231231{
232232 if (pm.empty ())
233233 return ;
234234
235235 copyOnWrite ();
236236
237237 for (auto && p : (*pm.mValues )) {
238+ if (skipUnknown) {
239+ auto it = mValues ->find (p.first );
240+ if (it != mValues ->end () && it->second .isUninitValue ())
241+ continue ;
242+ }
238243 (*mValues )[p.first ] = std::move (p.second );
239244 }
240245}
@@ -438,7 +443,8 @@ static void fillProgramMemoryFromAssignments(ProgramMemory& pm, const Token* tok
438443 if (!setvar) {
439444 if (!pm.hasValue (vartok->exprId ())) {
440445 const Token* valuetok = tok2->astOperand2 ();
441- pm.setValue (vartok, execute (valuetok, pm, settings));
446+ ProgramMemory local = state;
447+ pm.setValue (vartok, execute (valuetok, local, settings));
442448 }
443449 }
444450 } else if (Token::simpleMatch (tok2, " )" ) && tok2->link () &&
@@ -519,7 +525,7 @@ void ProgramMemoryState::replace(ProgramMemory pm, const Token* origin)
519525 if (origin)
520526 for (const auto & p : pm)
521527 origins[p.first .getExpressionId ()] = origin;
522- state.replace (std::move (pm));
528+ state.replace (std::move (pm), /* skipUnknown */ true );
523529}
524530
525531static void addVars (ProgramMemory& pm, const ProgramMemory::Map& vars)
@@ -532,13 +538,14 @@ static void addVars(ProgramMemory& pm, const ProgramMemory::Map& vars)
532538
533539void ProgramMemoryState::addState (const Token* tok, const ProgramMemory::Map& vars)
534540{
535- ProgramMemory pm = state;
536- addVars (pm , vars);
537- fillProgramMemoryFromConditions (pm , tok, settings);
538- ProgramMemory local = pm;
541+ ProgramMemory local = state;
542+ addVars (local , vars);
543+ fillProgramMemoryFromConditions (local , tok, settings);
544+ ProgramMemory pm;
539545 fillProgramMemoryFromAssignments (pm, tok, settings, local, vars);
540- addVars (pm, vars);
541- replace (std::move (pm), tok);
546+ local.replace (std::move (pm));
547+ addVars (local, vars);
548+ replace (std::move (local), tok);
542549}
543550
544551void ProgramMemoryState::assume (const Token* tok, bool b, bool isEmpty)
0 commit comments