Fixed #6219 (valueFlowForward: better multivariable analysis needed to avoid FP)

This commit is contained in:
Daniel Marjamäki 2014-10-17 06:50:33 +02:00
parent 41a54fceba
commit 0fd6586fcc
2 changed files with 18 additions and 4 deletions

View File

@ -1131,8 +1131,12 @@ static void valueFlowAfterCondition(TokenList *tokenlist, ErrorLogger *errorLogg
isreturn |= (codeblock == 2 && isReturn(after));
}
if (!isreturn)
valueFlowForward(after->next(), top->scope()->classEnd, var, varid, values, true, tokenlist, errorLogger, settings);
if (!isreturn) {
// TODO: constValue could be true if there are no assignments in the conditional blocks and
// perhaps if there are no && and no || in the condition
bool constValue = false;
valueFlowForward(after->next(), top->scope()->classEnd, var, varid, values, constValue, tokenlist, errorLogger, settings);
}
}
}
}

View File

@ -1020,11 +1020,11 @@ private:
code = "void f(int x) {\n"
" if (x == 2) {}\n"
" if (x > 0)\n"
" a = x;\n"
" a = x;\n" // <- TODO, x can be 2
" else\n"
" b = x;\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 4U, 2));
TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 4U, 2));
ASSERT_EQUALS(false, testValueOfX(code, 6U, 2));
// condition with 2nd variable
@ -1036,6 +1036,16 @@ private:
"}";
ASSERT_EQUALS(false, testValueOfX(code, 5U, 7));
code = "void f(struct X *x) {\n"
" bool b = TRUE;\n"
" if(x) { }\n"
" else\n"
" b = FALSE;\n"
" if (b)\n"
" abc(x->value);\n" // <- x is not 0
"}\n";
ASSERT_EQUALS(false, testValueOfX(code, 7U, 0));
// In condition, after && and ||
code = "void f(int x) {\n"
" a = (x != 3 ||\n"