value flow: refactoring. broke out function for skipping value simplifications in expressions.
This commit is contained in:
parent
85dcb14813
commit
eaf8c83db5
|
@ -72,6 +72,16 @@ static bool bailoutFunctionPar(const Token *tok)
|
||||||
return arg && !arg->isConst() && arg->isReference();
|
return arg && !arg->isConst() && arg->isReference();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const Token * skipValueInConditionalExpression(const Token *tok)
|
||||||
|
{
|
||||||
|
while (tok && !Token::Match(tok, "%oror%|&&|?|:")) {
|
||||||
|
while (Token::Match(tok->astParent(), "%oror%|&&|?") && tok->astParent()->astOperand1() == tok)
|
||||||
|
tok = tok->astParent();
|
||||||
|
tok = tok->astParent();
|
||||||
|
}
|
||||||
|
return tok;
|
||||||
|
}
|
||||||
|
|
||||||
static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLogger, const Settings *settings)
|
static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLogger, const Settings *settings)
|
||||||
{
|
{
|
||||||
for (Token *tok = tokenlist->front(); tok; tok = tok->next()) {
|
for (Token *tok = tokenlist->front(); tok; tok = tok->next()) {
|
||||||
|
@ -149,15 +159,8 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip if variable is conditionally used in ?: expression.
|
// skip if variable is conditionally used in ?: expression
|
||||||
const Token *parent = tok2;
|
if (const Token *parent = skipValueInConditionalExpression(tok2)) {
|
||||||
while (parent && !Token::Match(parent, "%oror%|&&|?|:")) {
|
|
||||||
while (Token::Match(parent->astParent(), "%oror%|&&|?") &&
|
|
||||||
parent->astParent()->astOperand1() == parent)
|
|
||||||
parent = parent->astParent();
|
|
||||||
parent = parent->astParent();
|
|
||||||
}
|
|
||||||
if (parent) {
|
|
||||||
if (settings->debugwarnings)
|
if (settings->debugwarnings)
|
||||||
bailout(tokenlist,
|
bailout(tokenlist,
|
||||||
errorLogger,
|
errorLogger,
|
||||||
|
|
|
@ -113,6 +113,13 @@ private:
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 2U, 0));
|
ASSERT_EQUALS(true, testValueOfX(code, 2U, 0));
|
||||||
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
|
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
|
||||||
|
|
||||||
|
code = "void f(int *x) {\n"
|
||||||
|
" if ((x=ret())&&\n"
|
||||||
|
" (*x==0));\n" // <- x is not 0
|
||||||
|
" if (x==0) {}\n"
|
||||||
|
"}";
|
||||||
|
ASSERT_EQUALS(false, testValueOfX(code, 3U, 0));
|
||||||
|
|
||||||
// function calls
|
// function calls
|
||||||
code = "void f(int x) {\n"
|
code = "void f(int x) {\n"
|
||||||
" a = x;\n"
|
" a = x;\n"
|
||||||
|
|
Loading…
Reference in New Issue