FwdAnalysis: fix FP in loop

This commit is contained in:
Daniel Marjamäki 2018-12-16 16:43:04 +01:00
parent 152df1bf00
commit 46a0172480
2 changed files with 12 additions and 12 deletions

View File

@ -1104,20 +1104,12 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const
conditionEnd = conditionStart->link();
}
if (conditionStart && conditionEnd) {
bool write = false;
bool used = false;
for (const Token *condTok = conditionStart; condTok != conditionEnd; condTok = condTok->next()) {
if (Token::Match(condTok, "=|++|--")) {
visitAstNodes(condTok->astOperand1(),
[&](const Token *writeTok) {
if (exprVarIds.find(writeTok->varId()) != exprVarIds.end())
write = true;
return write ? ChildrenToVisit::done : ChildrenToVisit::op1_and_op2;
});
if (write)
break;
}
if (exprVarIds.find(condTok->varId()) != exprVarIds.end())
used = true;
}
if (write)
if (used)
return Result(Result::Type::BAILOUT);
}

View File

@ -2153,6 +2153,14 @@ private:
" while (x < 10) { x = x + 1; }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
functionVariableUsage("void fun()\n"
"{\n"
" int status = 0;\n"
" for (ind = 0; ((ind < nrArgs) && (status < 10)); ind++)\n"
" status = x;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void localvaralias1() {