Tokenizer::simplifyKnownVariables: Added bailout when pointer alias is simplified and loop is encountered

This commit is contained in:
Daniel Marjamäki 2016-12-11 19:12:23 +01:00
parent e0d4720e19
commit d4f2512421
2 changed files with 6 additions and 2 deletions

View File

@ -6471,8 +6471,8 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
if (pointeralias && Token::Match(tok3, ("!!= " + value).c_str())) if (pointeralias && Token::Match(tok3, ("!!= " + value).c_str()))
break; break;
// Stop if do is found // Stop if a loop is found
if (tok3->str() == "do") if (pointeralias && Token::Match(tok3, "do|for|while"))
break; break;
// Stop if unknown function call is seen // Stop if unknown function call is seen

View File

@ -1643,6 +1643,10 @@ private:
ASSERT_EQUALS( ASSERT_EQUALS(
"void foo ( ) { int n ; n = 10 ; for ( int i = 0 ; i < 10 ; ++ i ) { } }", "void foo ( ) { int n ; n = 10 ; for ( int i = 0 ; i < 10 ; ++ i ) { } }",
simplifyKnownVariables(code)); simplifyKnownVariables(code));
ASSERT_EQUALS(
"void foo ( int i ) { int n ; n = i ; for ( i = 0 ; i < n ; ++ i ) { } }",
simplifyKnownVariables("void foo(int i) { int n = i; for (i = 0; i < n; ++i) { } }"));
} }
void simplifyKnownVariables22() { void simplifyKnownVariables22() {