Fix issue 9894: ValueFlow: wrong known value below while with assignment (#2804)
* Fix issue 9894: ValueFlow: wrong known value below while with assignment
This commit is contained in:
parent
ebb5ff0e19
commit
bb7164171c
|
@ -4510,9 +4510,10 @@ struct ValueFlowConditionHandler {
|
||||||
if (Token::simpleMatch(top->link(), ") {")) {
|
if (Token::simpleMatch(top->link(), ") {")) {
|
||||||
Token *after = top->link()->linkAt(1);
|
Token *after = top->link()->linkAt(1);
|
||||||
const Token* unknownFunction = nullptr;
|
const Token* unknownFunction = nullptr;
|
||||||
bool dead_if = isReturnScope(after, &settings->library, &unknownFunction) ||
|
const bool isWhile =
|
||||||
(tok->astParent() && Token::simpleMatch(tok->astParent()->previous(), "while (") &&
|
tok->astParent() && Token::simpleMatch(tok->astParent()->previous(), "while (");
|
||||||
!isBreakScope(after));
|
bool dead_if = (!isBreakScope(after) && isWhile) ||
|
||||||
|
(isReturnScope(after, &settings->library, &unknownFunction) && !isWhile);
|
||||||
bool dead_else = false;
|
bool dead_else = false;
|
||||||
|
|
||||||
if (!dead_if && unknownFunction) {
|
if (!dead_if && unknownFunction) {
|
||||||
|
|
|
@ -2478,6 +2478,20 @@ private:
|
||||||
" return x;\n"
|
" return x;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
ASSERT_EQUALS(false, testValueOfXImpossible(code, 8U, 0));
|
ASSERT_EQUALS(false, testValueOfXImpossible(code, 8U, 0));
|
||||||
|
|
||||||
|
code = "bool c();\n"
|
||||||
|
"long f() {\n"
|
||||||
|
" bool stop = false;\n"
|
||||||
|
" while (!stop) {\n"
|
||||||
|
" if (c())\n"
|
||||||
|
" stop = true;\n"
|
||||||
|
" break;\n"
|
||||||
|
" }\n"
|
||||||
|
" int x = !stop;\n"
|
||||||
|
" return x;\n"
|
||||||
|
"}\n";
|
||||||
|
ASSERT_EQUALS(false, testValueOfXImpossible(code, 10U, 1));
|
||||||
|
ASSERT_EQUALS(false, testValueOfXKnown(code, 10U, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void valueFlowAfterConditionExpr() {
|
void valueFlowAfterConditionExpr() {
|
||||||
|
|
Loading…
Reference in New Issue