value flow: more bailouts when return/break/continue/goto is reached. TODO: handle these better.

This commit is contained in:
Daniel Marjamäki 2014-01-12 15:07:58 +01:00
parent 155990cb0e
commit 3d79613f2b
2 changed files with 19 additions and 4 deletions

View File

@ -262,10 +262,16 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
!Token::Match(tok2->linkAt(-1)->previous(), "if|for|while ("))
break;
}
} else if (tok2->str() == "break") {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + " stopping on break");
break;
} else if (tok2->str() == ";") {
const Token *parent = tok2->previous();
while (parent && !Token::Match(parent, "return|break|continue|goto"))
parent = parent->astParent();
// reaching a break/continue/return
if (parent) {
if (settings->debugwarnings)
bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + " stopping on " + parent->str());
break;
}
}
}
}

View File

@ -228,6 +228,7 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (debug) ValueFlow bailout: global variable x\n", errout.str());
// bailout: switch
// TODO : handle switch/goto more intelligently
bailout("void f(int x, int y) {\n"
" switch (y) {\n"
" case 1: a=x; break;\n"
@ -235,6 +236,14 @@ private:
" };\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (debug) ValueFlow bailout: variable x stopping on break\n", errout.str());
bailout("void f(int x, int y) {\n"
" switch (y) {\n"
" case 1: a=x; return 1;\n"
" case 2: if (x==5) {} break;\n"
" };\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (debug) ValueFlow bailout: variable x stopping on return\n", errout.str());
}
void valueFlowForLoop() {