Fixed #1276 (False Uninitialized variable when using goto)
This commit is contained in:
parent
e9c8e1d8b1
commit
1552c0f7f2
|
@ -2543,6 +2543,7 @@ bool Tokenizer::simplifyTokenList()
|
|||
simplifyRedundantParanthesis();
|
||||
simplifyIfNot();
|
||||
simplifyIfNotNull();
|
||||
simplifyIfSameInnerCondition();
|
||||
simplifyComparisonOrder();
|
||||
simplifyNestedStrcat();
|
||||
simplifyWhile0();
|
||||
|
@ -3943,6 +3944,36 @@ void Tokenizer::simplifyIfNotNull()
|
|||
}
|
||||
|
||||
|
||||
void Tokenizer::simplifyIfSameInnerCondition()
|
||||
{
|
||||
// same inner condition
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
if (Token::Match(tok, "if ( %var% ) {"))
|
||||
{
|
||||
const unsigned int varid(tok->tokAt(2)->varId());
|
||||
if (!varid)
|
||||
continue;
|
||||
|
||||
for (Token *tok2 = tok->tokAt(5); tok2; tok2 = tok2->next())
|
||||
{
|
||||
if (tok2->str() == "{" || tok2->str() == "}")
|
||||
break;
|
||||
if (Token::simpleMatch(tok2, "if ("))
|
||||
{
|
||||
tok2 = tok2->tokAt(2);
|
||||
if (Token::Match(tok2, "%varid% )", varid))
|
||||
tok2->str("true");
|
||||
else if (Token::Match(tok2, "! %varid% )", varid))
|
||||
tok2->next()->varId(varid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Tokenizer::simplifyLogicalOperators()
|
||||
{
|
||||
// "if (not p)" => "if (!p)"
|
||||
|
@ -4491,6 +4522,7 @@ void Tokenizer::simplifyGoto()
|
|||
token->insertToken(tok2->str().c_str());
|
||||
token = token->next();
|
||||
token->linenr(tok2->linenr());
|
||||
token->varId(tok2->varId());
|
||||
if (token->str() == "(")
|
||||
{
|
||||
links.push_back(token);
|
||||
|
|
|
@ -182,6 +182,9 @@ private:
|
|||
*/
|
||||
void simplifyIfNotNull();
|
||||
|
||||
/** @brief simplify if (a) { if (a) .. */
|
||||
void simplifyIfSameInnerCondition();
|
||||
|
||||
/**
|
||||
* Simplify the "not" and "and" keywords to "!" and "&&"
|
||||
* accordingly.
|
||||
|
|
|
@ -55,6 +55,7 @@ private:
|
|||
TEST_CASE(removePreIncrement);
|
||||
|
||||
TEST_CASE(elseif1);
|
||||
TEST_CASE(ifa_ifa); // "if (a) { if (a) .." => "if (a) { if (1) .."
|
||||
|
||||
TEST_CASE(sizeof1);
|
||||
TEST_CASE(sizeof2);
|
||||
|
@ -615,6 +616,12 @@ private:
|
|||
}
|
||||
|
||||
|
||||
void ifa_ifa()
|
||||
{
|
||||
ASSERT_EQUALS("int a ; if ( a ) { { ab } cd }", tok("int a ; if (a) { if (a) { ab } cd }", true));
|
||||
ASSERT_EQUALS("int a ; if ( a ) { { ab } cd }", tok("int a ; if (unlikely(a)) { if (a) { ab } cd }", true));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue