Tokenizer::simplifyKnownVariables : Fixed TODO test case when simplifying pointer alias in function call

This commit is contained in:
Daniel Marjamäki 2010-11-06 13:24:33 +01:00
parent 13c2a73d3f
commit c39fbb86db
2 changed files with 30 additions and 7 deletions

View File

@ -5981,6 +5981,26 @@ bool Tokenizer::simplifyKnownVariables()
ret = true; ret = true;
} }
// Variable is used in function call..
if (Token::Match(tok3, "%var% ( %varid% ,", varid))
{
const char * const functionName[] =
{
"memcmp","memcpy","memmove","memset",
"strcmp","strcpy","strncpy","strdup"
};
for (unsigned int i = 0; i < (sizeof(functionName) / sizeof(*functionName)); ++i)
{
if (tok3->str() == functionName[i])
{
Token *par1 = tok3->next()->next();
par1->str(value);
par1->varId(valueVarId);
break;
}
}
}
// Variable is used in calculation.. // Variable is used in calculation..
if (((tok3->previous()->varId() > 0) && Token::Match(tok3, "& %varid%", varid)) || if (((tok3->previous()->varId() > 0) && Token::Match(tok3, "& %varid%", varid)) ||
Token::Match(tok3, "[=+-*/[] %varid% [=?+-*/;])]", varid) || Token::Match(tok3, "[=+-*/[] %varid% [=?+-*/;])]", varid) ||

View File

@ -5252,15 +5252,18 @@ private:
} }
{ {
const char code[] = "int a[10];\n" const char code[] = "void f() {\n"
"int *b = a;\n" " int a[10];\n"
"memset(b,0,sizeof(a));"; " int *b = a;\n"
" memset(b,0,sizeof(a));\n"
"}";
const char expected[] = "int a [ 10 ] ; " const char expected[] = "void f ( ) {"
"int * b ; b = a ; " " int a [ 10 ] ;"
"memset ( a , 0 , 40 ) ;"; " memset ( a , 0 , 40 ) ; "
"}";
TODO_ASSERT_EQUALS(expected, tok(code)); ASSERT_EQUALS(expected, tok(code));
} }
} }