Skip to content
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

Fix #13522 FP knownConditionTrueFalse after unsigned-to-signed conversion #7179

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/vf_analyzers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ struct ValueFlowAnalyzer : Analyzer {
continue;
if (exact && v.intvalue != 0 && !isPoint)
continue;
if (astIsUnsigned(tok) != astIsUnsigned(v.tokvalue))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, it is a little too restrictive which could lead to FNs, but it will fix FPs. To fix FNs, we would need to check if the value is within the range of an unsigned value. I am not sure how to write a test case to demonstrate it though as most known values will be passed through with the afterAssign passes anyways. Need to think about it some more.

Copy link
Collaborator Author

@chrchr-github chrchr-github Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 We could also wait until after the next release, so we can see the effects in daca.

continue;
std::vector<MathLib::bigint> r;
ValueFlow::Value::Bound bound = currValue->bound;
if (match(v.tokvalue)) {
Expand Down
7 changes: 7 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4947,6 +4947,13 @@ class TestCondition : public TestFixture {
" }\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("void f(unsigned x) {\n" // #13522
" unsigned u = x;\n"
" int i = u - 0;\n"
" if (i < 0) {}\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void alwaysTrueInfer() {
Expand Down
Loading