Repository navigation
Fix #15288 (False positive: accessMoved in loop) #9092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,7 +69,19 @@ static bool stateCoversCondition(const Token* tok, const ProgramMemory& pm, int | |
| return true; | ||
| if (tok->varId() > 0 || Token::simpleMatch(tok, ".")) { | ||
| const ProgramMemory::Values* values = pm.getValues(tok->exprId()); | ||
| return values && !values->empty() && std::all_of(values->cbegin(), values->cend(), [](const ValueFlow::Value& v) { | ||
| if (!values || values->empty()) | ||
| return false; | ||
| // The range of a bool (not <= -1, not >= 2) does not say anything about its value, use the | ||
| // expression that the bool is known to be equal to instead | ||
| if (astIsBool(tok) && std::all_of(values->cbegin(), values->cend(), [](const ValueFlow::Value& v) { | ||
| return v.isImpossible() && (v.intvalue < 0 || v.intvalue > 1); | ||
| })) { | ||
| return std::any_of(tok->values().cbegin(), tok->values().cend(), [&](const ValueFlow::Value& v) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI review When a bool's memory only holds the impossible range values, this now returns false unless the bool's known symbolic value is covered too. In practice that hides true positives that base reports: void h3(W m, bool c) {
for (int i = 0; i < 2; i++) {
const bool b = c;
if (b) w[i] = std::move(m); else w[i] = m.flip(); // base: accessMoved 16:33, PR: nothing
}
}
void h5(W m) {
for (int i = 0; i < 3; i++) {
const bool first = i == 0;
if (!first) w[i] = std::move(m); // base: accessMoved, PR: nothing (moved at i==1 and i==2)
}
}With |
||
| return v.isSymbolicValue() && v.isKnown() && v.intvalue == 0 && | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont think ProgramMemory stores values as known. Also, why are we allowing symbolic values here? |
||
| stateCoversCondition(v.tokvalue, pm, depth - 1); | ||
| }); | ||
| } | ||
| return std::all_of(values->cbegin(), values->cend(), [](const ValueFlow::Value& v) { | ||
| return v.isIntValue(); | ||
| }); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should to filter out these values in the
all_of. And when that returns false we can check the symbolic values:I think that would be a better structure here. The
isOutOfRangeImpossibleValuecan work for bool here but we can extend it for other integers in the future.Another option would be to use
copy_ifto filter the values.