Tokenizer: Fixed Tokenizer::simplifyKnownVariable bug when the variable is re-assigned in a loop

This commit is contained in:
Daniel Marjamäki 2010-01-24 19:27:39 +01:00
parent 7ce4825f95
commit 6d9740adea
2 changed files with 10 additions and 1 deletions

View File

@ -4079,7 +4079,7 @@ bool Tokenizer::simplifyKnownVariables()
for (const Token *tok4 = tok3; tok4 && tok4 != endpar; tok4 = tok4->next())
{
if (Token::Match(tok4, "++|-- %varid%", varid) ||
Token::Match(tok4, "%varid% ++|--", varid))
Token::Match(tok4, "%varid% ++|--|=", varid))
{
bailout = true;
break;

View File

@ -93,6 +93,7 @@ private:
TEST_CASE(simplifyKnownVariables16);
TEST_CASE(simplifyKnownVariables17);
TEST_CASE(simplifyKnownVariables18);
TEST_CASE(simplifyKnownVariables19);
TEST_CASE(match1);
@ -979,6 +980,14 @@ private:
simplifyKnownVariables(code));
}
void simplifyKnownVariables19()
{
const char code[] = "void f ( ) { int i=0; do { if (i>0) { a(); } i=b(); } while (i != 12); }";
ASSERT_EQUALS(
"void f ( ) { int i ; i = 0 ; do { if ( 0 < i ) { a ( ) ; } i = b ( ) ; } while ( i != 12 ) ; }",
simplifyKnownVariables(code));
}
void match1()
{
// Match "%var% | %var%"