Fixed #943 (Tokenizer: improve handling of pointer aliasing)

This commit is contained in:
Daniel Marjamäki 2010-04-25 15:12:06 +02:00
parent cda6fdb73d
commit 6bb93b5eb7
2 changed files with 21 additions and 2 deletions

View File

@ -4896,7 +4896,8 @@ bool Tokenizer::simplifyKnownVariables()
Token::Match(tok2, "%var% [ ] = %str% ;") ||
Token::Match(tok2, "%var% = %bool% ;") ||
Token::Match(tok2, "%var% = %var% ;") ||
Token::Match(tok2, "%var% = & %var% ;")))
Token::Match(tok2, "%var% = & %var% ;") ||
Token::Match(tok2, "%var% = & %var% [ 0 ] ;")))
{
const unsigned int varid = tok2->varId();
if (varid == 0)
@ -5008,7 +5009,7 @@ bool Tokenizer::simplifyKnownVariables()
}
// Variable is used in calculation..
if (Token::Match(tok3, "[=+-*/[] %varid% [?+-*/;]]", varid) ||
if (Token::Match(tok3, "[=+-*/[] %varid% [=?+-*/;]]", varid) ||
Token::Match(tok3, "[(=+-*/[] %varid% <<|>>", varid) ||
Token::Match(tok3, "<< %varid% [+-*/;])]", varid) ||
Token::Match(tok3, ">> %varid% [+-*/])]", varid))

View File

@ -192,6 +192,7 @@ private:
TEST_CASE(pointeralias1);
TEST_CASE(pointeralias2);
TEST_CASE(pointeralias3);
TEST_CASE(pointeralias4);
TEST_CASE(reduceConstness);
@ -4126,6 +4127,23 @@ private:
ASSERT_EQUALS(expected, tok(code));
}
void pointeralias4()
{
const char code[] = "void f()\n"
"{\n"
" int a[10];\n"
" int *p = &a[0];\n"
" *p = 0;\n"
"}\n";
const char expected[] = "void f ( ) "
"{"
" int a [ 10 ] ;"
" int * p ; p = & a [ 0 ] ;"
" * a = 0 ; "
"}";
ASSERT_EQUALS(expected, tok(code));
}
void reduceConstness()
{