Fixed #4913 (Tokenizer::simplifyKnownVariables: wrong handling of *--p=0;)

This commit is contained in:
Daniel Marjamäki 2013-08-25 08:54:33 +02:00
parent 3d9383aabb
commit acdbbeee44
2 changed files with 6 additions and 1 deletions

View File

@ -6170,7 +6170,7 @@ bool Tokenizer::simplifyKnownVariables()
break;
}
else if (tok2->previous()->str() != "*" &&
else if (tok2->previous()->str() != "*" && !Token::Match(tok2->tokAt(-2), "* --|++") &&
(Token::Match(tok2, "%var% = %bool%|%char%|%num%|%str%|%var% ;") ||
Token::Match(tok2, "%var% [ ] = %str% ;") ||
Token::Match(tok2, "%var% [ %num% ] = %str% ;") ||

View File

@ -176,6 +176,7 @@ private:
TEST_CASE(simplifyKnownVariables51); // #4409 hang
TEST_CASE(simplifyKnownVariables52); // #4728 "= x %cop%"
TEST_CASE(simplifyKnownVariables53); // references
TEST_CASE(simplifyKnownVariables54); // #4913 'x' is not 0 after *--x=0;
TEST_CASE(simplifyKnownVariablesIfEq1); // if (a==5) => a is 5 in the block
TEST_CASE(simplifyKnownVariablesIfEq2); // if (a==5) { buf[a++] = 0; }
TEST_CASE(simplifyKnownVariablesIfEq3); // #4708 - if (a==5) { buf[--a] = 0; }
@ -2732,6 +2733,10 @@ private:
ASSERT_EQUALS("void f ( ) { int * p ; p = abc ( ) ; }", tokenizeAndStringify("void f() { int *p; int *&ref=p; ref=abc(); }", true));
}
void simplifyKnownVariables54() { // #4913
ASSERT_EQUALS("void f ( int * p ) { * -- p = 0 ; * p = 0 ; }", tokenizeAndStringify("void f(int*p) { *--p=0; *p=0; }", true));
}
void simplifyKnownVariablesIfEq1() {
const char code[] = "void f(int x) {\n"
" if (x==5) {\n"