From 6bb93b5eb7342a872ce2df4ea8b5b1a65740844e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 25 Apr 2010 15:12:06 +0200 Subject: [PATCH] Fixed #943 (Tokenizer: improve handling of pointer aliasing) --- lib/tokenize.cpp | 5 +++-- test/testsimplifytokens.cpp | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 9551b2302..cb4537668 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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)) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index d0882eacc..a2f3ea89e 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -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() {