Added TODO test case for the simplifyKnownVariables to better simplify local variables
This commit is contained in:
parent
2d1b7285d2
commit
40a14736b7
|
@ -6873,6 +6873,8 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign
|
||||||
// Stop if unknown function call is seen
|
// Stop if unknown function call is seen
|
||||||
// If the variable is a global or a member variable it might be
|
// If the variable is a global or a member variable it might be
|
||||||
// changed by the function call
|
// changed by the function call
|
||||||
|
// TODO: don't bail out if the variable is a local variable,
|
||||||
|
// then it can't be changed by the function call.
|
||||||
if (tok3->str() == ")" && tok3->link() &&
|
if (tok3->str() == ")" && tok3->link() &&
|
||||||
Token::Match(tok3->link()->tokAt(-2), "[;{}] %var% (") &&
|
Token::Match(tok3->link()->tokAt(-2), "[;{}] %var% (") &&
|
||||||
!Token::Match(tok3->link()->previous(), "if|for|while|switch"))
|
!Token::Match(tok3->link()->previous(), "if|for|while|switch"))
|
||||||
|
|
|
@ -2272,15 +2272,29 @@ private:
|
||||||
void simplifyKnownVariablesClassMember()
|
void simplifyKnownVariablesClassMember()
|
||||||
{
|
{
|
||||||
// Ticket #2815
|
// Ticket #2815
|
||||||
const char code[] = "char *a;\n"
|
{
|
||||||
"void f(const char *s) {\n"
|
const char code[] = "char *a;\n"
|
||||||
" a = NULL;\n"
|
"void f(const char *s) {\n"
|
||||||
" x();\n"
|
" a = NULL;\n"
|
||||||
" memcpy(a, s, 10);\n" // <- don't simplify "a" here
|
" x();\n"
|
||||||
"}\n";
|
" memcpy(a, s, 10);\n" // <- don't simplify "a" here
|
||||||
|
"}\n";
|
||||||
|
|
||||||
const std::string s(tokenizeAndStringify(code, true));
|
const std::string s(tokenizeAndStringify(code, true));
|
||||||
ASSERT_EQUALS(true, s.find("memcpy ( a , s , 10 ) ;") != std::string::npos);
|
ASSERT_EQUALS(true, s.find("memcpy ( a , s , 10 ) ;") != std::string::npos);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the variable is local then perform simplification..
|
||||||
|
{
|
||||||
|
const char code[] = "void f(const char *s) {\n"
|
||||||
|
" char *a = NULL;\n"
|
||||||
|
" x();\n"
|
||||||
|
" memcpy(a, s, 10);\n" // <- simplify "a"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
const std::string s(tokenizeAndStringify(code, true));
|
||||||
|
TODO_ASSERT_EQUALS(true, false, s.find("memcpy ( 0 , s , 10 ) ;") != std::string::npos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue