Skip to content
Merged
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
5 changes: 4 additions & 1 deletion lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5643,12 +5643,15 @@ static void valueFlowForwardConst(Token* start,
if (v.tokvalue->varId() != var->declarationId())
continue;
for (ValueFlow::Value value : values) {
if (!v.isKnown() && value.isImpossible())
continue;
if (v.intvalue != 0) {
if (!value.isIntValue())
continue;
value.intvalue += v.intvalue;
}
value.valueKind = v.valueKind;
if (!value.isImpossible())
value.valueKind = v.valueKind;
value.bound = v.bound;
value.errorPath.insert(value.errorPath.end(), v.errorPath.cbegin(), v.errorPath.cend());
setTokenValue(tok, std::move(value), settings);
Expand Down
10 changes: 10 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4722,6 +4722,16 @@ class TestCondition : public TestFixture {
" (it != end) && *it;\n"
"}\n");
ASSERT_EQUALS("", errout.str());

// #12116
check("void f(int n) {\n"
" for (int i = 0; i < N; ++i) {\n"
" if (i < n) {}\n"
" else if (i > n) {}\n"
" else {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

void alwaysTrueInfer() {
Expand Down
12 changes: 12 additions & 0 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8174,6 +8174,18 @@ class TestValueFlow : public TestFixture {
" }\n"
"}\n";
ASSERT_EQUALS(true, testValueOfXImpossible(code, 4U, -1));

code = "void f(int N, int z) {\n"
" std::vector<int> a(N);\n"
" int m = -1;\n"
" m = 0;\n"
" for (int k = 0; k < N; k++) {\n"
" int x = m + k;\n"
" if (z == a[x]) {}\n"
" }\n"
"}\n";
ASSERT_EQUALS(true, testValueOfXImpossible(code, 7U, -1));
ASSERT_EQUALS(false, testValueOfXKnown(code, 7U, -1));
}

void valueFlowImpossibleUnknownConstant()
Expand Down