Fixed #2225 (false positive: variable is assigned a value that is never used '*(stack[0])+=arg')
This commit is contained in:
parent
1842a122da
commit
22a4dd2cc3
|
@ -4467,7 +4467,7 @@ void Tokenizer::simplifyCompoundAssignment()
|
||||||
// "a+=b" => "a = a + b"
|
// "a+=b" => "a = a + b"
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
if (Token::Match(tok, "[;{}:] *| %var%"))
|
if (Token::Match(tok, "[;{}:] *| (| %var%"))
|
||||||
{
|
{
|
||||||
if (tok->str() == ":")
|
if (tok->str() == ":")
|
||||||
{
|
{
|
||||||
|
@ -4481,24 +4481,31 @@ void Tokenizer::simplifyCompoundAssignment()
|
||||||
if (tok->strAt(1) == "*")
|
if (tok->strAt(1) == "*")
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
|
|
||||||
// variable..
|
if (tok->strAt(1) == "(")
|
||||||
tok = tok->tokAt(2);
|
|
||||||
while (Token::Match(tok, ". %var%") || (tok && tok->str() == "["))
|
|
||||||
{
|
{
|
||||||
if (tok->str() != "[")
|
tok = tok->next()->link()->next();
|
||||||
tok = tok->tokAt(2);
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
// variable..
|
||||||
|
tok = tok->tokAt(2);
|
||||||
|
while (Token::Match(tok, ". %var%") || (tok && tok->str() == "["))
|
||||||
{
|
{
|
||||||
// goto "]"
|
if (tok->str() != "[")
|
||||||
tok = tok->next();
|
tok = tok->tokAt(2);
|
||||||
while (tok && !Token::Match(tok, "++|--|(|[|]"))
|
|
||||||
tok = tok->next();
|
|
||||||
if (!tok)
|
|
||||||
break;
|
|
||||||
else if (tok->str() == "]")
|
|
||||||
tok = tok->next();
|
|
||||||
else
|
else
|
||||||
break;
|
{
|
||||||
|
// goto "]"
|
||||||
|
tok = tok->next();
|
||||||
|
while (tok && !Token::Match(tok, "++|--|(|[|]"))
|
||||||
|
tok = tok->next();
|
||||||
|
if (!tok)
|
||||||
|
break;
|
||||||
|
else if (tok->str() == "]")
|
||||||
|
tok = tok->next();
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!tok)
|
if (!tok)
|
||||||
|
@ -4526,15 +4533,18 @@ void Tokenizer::simplifyCompoundAssignment()
|
||||||
// simplify the compound assignment..
|
// simplify the compound assignment..
|
||||||
tok->str("=");
|
tok->str("=");
|
||||||
tok->insertToken(op);
|
tok->insertToken(op);
|
||||||
Token *tokend = 0;
|
std::stack<Token *> tokend;
|
||||||
for (const Token *tok2 = tok->previous(); tok2 && tok2 != tok1; tok2 = tok2->previous())
|
for (const Token *tok2 = tok->previous(); tok2 && tok2 != tok1; tok2 = tok2->previous())
|
||||||
{
|
{
|
||||||
tok->insertToken(tok2->str());
|
tok->insertToken(tok2->str());
|
||||||
tok->next()->varId(tok2->varId());
|
tok->next()->varId(tok2->varId());
|
||||||
if (Token::simpleMatch(tok->next(), "]"))
|
if (Token::Match(tok->next(), "]|)"))
|
||||||
tokend = tok->next();
|
tokend.push(tok->next());
|
||||||
else if (Token::simpleMatch(tok->next(), "["))
|
else if (Token::Match(tok->next(), "(|["))
|
||||||
Token::createMutualLinks(tok->next(), tokend);
|
{
|
||||||
|
Token::createMutualLinks(tok->next(), tokend.top());
|
||||||
|
tokend.pop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4694,6 +4694,7 @@ private:
|
||||||
ASSERT_EQUALS("{ x = x >> y ; }", tokenizeAndStringify("{ x >>= y;}"));
|
ASSERT_EQUALS("{ x = x >> y ; }", tokenizeAndStringify("{ x >>= y;}"));
|
||||||
|
|
||||||
ASSERT_EQUALS("; * p = * p + y ;", tokenizeAndStringify("; *p += y;"));
|
ASSERT_EQUALS("; * p = * p + y ;", tokenizeAndStringify("; *p += y;"));
|
||||||
|
ASSERT_EQUALS("; * ( p [ 0 ] ) = * ( p [ 0 ] ) + y ;", tokenizeAndStringify("; *(p[0]) += y;"));
|
||||||
|
|
||||||
ASSERT_EQUALS("case 0 : x = x + y ; break ;", tokenizeAndStringify("case 0: x += y; break;"));
|
ASSERT_EQUALS("case 0 : x = x + y ; break ;", tokenizeAndStringify("case 0: x += y; break;"));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue