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()))
break;
// Stop if do is found
if (tok3->str() == "do")
// Stop if a loop is found
if (pointeralias && Token::Match(tok3, "do|for|while"))
break;
// Stop if unknown function call is seen

View File

@ -1643,6 +1643,10 @@ private:
ASSERT_EQUALS(
"void foo ( ) { int n ; n = 10 ; for ( int i = 0 ; i < 10 ; ++ i ) { } }",
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() {