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
|
||||
// If the variable is a global or a member variable it might be
|
||||
// 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() &&
|
||||
Token::Match(tok3->link()->tokAt(-2), "[;{}] %var% (") &&
|
||||
!Token::Match(tok3->link()->previous(), "if|for|while|switch"))
|
||||
|
|
|
@ -2272,6 +2272,7 @@ private:
|
|||
void simplifyKnownVariablesClassMember()
|
||||
{
|
||||
// Ticket #2815
|
||||
{
|
||||
const char code[] = "char *a;\n"
|
||||
"void f(const char *s) {\n"
|
||||
" a = NULL;\n"
|
||||
|
@ -2283,6 +2284,19 @@ private:
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string tokenizeDebugListing(const std::string &code, bool simplify = false)
|
||||
|
|
Loading…
Reference in New Issue