Fix 12116: FP negativeContainerIndex with redundant assignment (regression) (#5602)
This commit is contained in:
parent
56bfa9f3ea
commit
18373bc64b
|
@ -5643,11 +5643,14 @@ 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;
|
||||
}
|
||||
if (!value.isImpossible())
|
||||
value.valueKind = v.valueKind;
|
||||
value.bound = v.bound;
|
||||
value.errorPath.insert(value.errorPath.end(), v.errorPath.cbegin(), v.errorPath.cend());
|
||||
|
|
|
@ -4722,6 +4722,16 @@ private:
|
|||
" (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() {
|
||||
|
|
|
@ -8174,6 +8174,18 @@ private:
|
|||
" }\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()
|
||||
|
|
Loading…
Reference in New Issue