value flow: skip scopes that don't contain variable

This commit is contained in:
Daniel Marjamäki 2014-01-10 16:13:39 +01:00
parent 81513b4346
commit acb103e214
2 changed files with 16 additions and 5 deletions

View File

@ -103,7 +103,7 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
}
break;
}
if (tok2->varId() == varid) {
// bailout: assignment
if (Token::Match(tok2->previous(), "!!* %var% =")) {
@ -130,9 +130,13 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
}
if (tok2->str() == "}") {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + " stopping on }");
break;
if (Token::findmatch(tok2->link(), "%varid%", tok2, varid)) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + " stopping on }");
break;
} else {
tok2 = tok2->link();
}
}
}
}

View File

@ -117,12 +117,19 @@ private:
ASSERT_EQUALS("[test.cpp:2]: (debug) ValueFlow bailout: no simplification of x within ?: expression\n", errout.str());
code = "void f(int x) {\n"
" int a = x;\n"
" int a =v x;\n"
" a = b ? x/2 : 20/x;\n"
" if (x == 123) {}\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 2U, 123));
code = "void f(int x, int y) {\n"
" a = x;\n"
" if (y){}\n"
" if (x==123){}\n"
"}";
ASSERT_EQUALS(true, testValueOfX(code, 2U, 123));
// bailout: if/else/etc
bailout("void f(int x) {\n"
" if (x != 123) { b = x; }\n"