Skip to content

Commit d9a054c

Browse files
authored
ProgramMemory: avoid unnecessary insertion in setValue() (#7770)
`subexpr` might have been the same as `expr` and thus overwrote the previously added value.
1 parent 478055e commit d9a054c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/programmemory.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ std::size_t ExprIdToken::Hash::operator()(ExprIdToken etok) const
6161
void ProgramMemory::setValue(const Token* expr, const ValueFlow::Value& value) {
6262
copyOnWrite();
6363

64-
(*mValues)[expr] = value;
6564
ValueFlow::Value subvalue = value;
6665
const Token* subexpr = solveExprValue(
6766
expr,
@@ -74,6 +73,8 @@ void ProgramMemory::setValue(const Token* expr, const ValueFlow::Value& value) {
7473
return {};
7574
},
7675
subvalue);
76+
if (expr != subexpr)
77+
(*mValues)[expr] = value;
7778
if (subexpr)
7879
(*mValues)[subexpr] = std::move(subvalue);
7980
}

0 commit comments

Comments
 (0)