Revert "Fixed #7619 (False positive: Redundant assignment)"
There is a crash I need to look into.
This commit is contained in:
parent
399fef17ca
commit
a5af5b2d08
|
@ -473,7 +473,6 @@ static bool checkExceptionHandling(const Token* tok)
|
||||||
|
|
||||||
void CheckOther::checkRedundantAssignment()
|
void CheckOther::checkRedundantAssignment()
|
||||||
{
|
{
|
||||||
// TODO: Rewrite this messy checker.
|
|
||||||
const bool printPerformance = mSettings->isEnabled(Settings::PERFORMANCE);
|
const bool printPerformance = mSettings->isEnabled(Settings::PERFORMANCE);
|
||||||
const bool printStyle = mSettings->isEnabled(Settings::STYLE);
|
const bool printStyle = mSettings->isEnabled(Settings::STYLE);
|
||||||
const bool printWarning = mSettings->isEnabled(Settings::WARNING);
|
const bool printWarning = mSettings->isEnabled(Settings::WARNING);
|
||||||
|
@ -492,7 +491,6 @@ void CheckOther::checkRedundantAssignment()
|
||||||
std::map<unsigned int, const Token*> memAssignments;
|
std::map<unsigned int, const Token*> memAssignments;
|
||||||
std::map<unsigned int, std::set<unsigned int> > membervars;
|
std::map<unsigned int, std::set<unsigned int> > membervars;
|
||||||
std::set<unsigned int> initialized;
|
std::set<unsigned int> initialized;
|
||||||
std::map<unsigned int, std::set<unsigned int>> dependencies;
|
|
||||||
const Token* writtenArgumentsEnd = nullptr;
|
const Token* writtenArgumentsEnd = nullptr;
|
||||||
|
|
||||||
for (const Token* tok = scope.bodyStart->next(); tok && tok != scope.bodyEnd; tok = tok->next()) {
|
for (const Token* tok = scope.bodyStart->next(); tok && tok != scope.bodyEnd; tok = tok->next()) {
|
||||||
|
@ -505,18 +503,15 @@ void CheckOther::checkRedundantAssignment()
|
||||||
break;
|
break;
|
||||||
varAssignments.clear();
|
varAssignments.clear();
|
||||||
memAssignments.clear();
|
memAssignments.clear();
|
||||||
dependencies.clear();
|
|
||||||
} else if (tok->str() == "{" && tok->strAt(-1) != "{" && tok->strAt(-1) != "=" && tok->strAt(-4) != "case" && tok->strAt(-3) != "default") { // conditional or non-executable inner scope: Skip it and reset status
|
} else if (tok->str() == "{" && tok->strAt(-1) != "{" && tok->strAt(-1) != "=" && tok->strAt(-4) != "case" && tok->strAt(-3) != "default") { // conditional or non-executable inner scope: Skip it and reset status
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
varAssignments.clear();
|
varAssignments.clear();
|
||||||
memAssignments.clear();
|
memAssignments.clear();
|
||||||
dependencies.clear();
|
|
||||||
} else if (Token::Match(tok, "for|if|while (")) {
|
} else if (Token::Match(tok, "for|if|while (")) {
|
||||||
tok = tok->linkAt(1);
|
tok = tok->linkAt(1);
|
||||||
} else if (Token::Match(tok, "break|return|continue|throw|goto|asm")) {
|
} else if (Token::Match(tok, "break|return|continue|throw|goto|asm")) {
|
||||||
varAssignments.clear();
|
varAssignments.clear();
|
||||||
memAssignments.clear();
|
memAssignments.clear();
|
||||||
dependencies.clear();
|
|
||||||
} else if (Token::Match(tok, "%var% = [ & ] (")) {
|
} else if (Token::Match(tok, "%var% = [ & ] (")) {
|
||||||
const unsigned int lambdaId = tok->varId();
|
const unsigned int lambdaId = tok->varId();
|
||||||
const Token *lambdaParams = tok->tokAt(5);
|
const Token *lambdaParams = tok->tokAt(5);
|
||||||
|
@ -528,38 +523,29 @@ void CheckOther::checkRedundantAssignment()
|
||||||
usedByLambda[lambdaId].insert(tok2->varId());
|
usedByLambda[lambdaId].insert(tok2->varId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (tok->tokType() == Token::eVariable && !Token::Match(tok, "%var% (")) {
|
} else if (tok->tokType() == Token::eVariable && !Token::Match(tok, "%name% (")) {
|
||||||
const Token *eq = tok;
|
const Token *eq = nullptr;
|
||||||
while (Token::Match(eq->astParent(), ".|::|["))
|
for (const Token *tok2 = tok; tok2; tok2 = tok2->next()) {
|
||||||
eq = eq->astParent();
|
if (Token::Match(tok2, "[([]")) {
|
||||||
if (Token::simpleMatch(eq->astParent(), "=") && eq == eq->astParent()->astOperand1())
|
// bail out if there is a variable in rhs - we only track 1 variable
|
||||||
eq = eq->astParent();
|
bool bailout = false;
|
||||||
else
|
for (const Token *tok3 = tok2->link(); tok3 != tok2; tok3 = tok3->previous()) {
|
||||||
eq = nullptr;
|
if (tok3->varId()) {
|
||||||
|
const Variable *var = tok3->variable();
|
||||||
if (eq) {
|
if (!var || !var->isConst() || var->isReference() || var->isPointer()) {
|
||||||
for (const Token *tok2 = tok->next(); tok2 != eq; tok2 = tok2->next()) {
|
bailout = true;
|
||||||
if (tok2->str() == "[")
|
|
||||||
tok2 = tok2->link();
|
|
||||||
else if (tok2->str() == "]") {
|
|
||||||
eq = nullptr;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (bailout)
|
||||||
if (eq) {
|
break;
|
||||||
bool arrayIndex = false;
|
tok2 = tok2->link();
|
||||||
for (const Token *tok2 = tok->next(); tok2 != eq; tok2 = tok2->next()) {
|
} else if (Token::Match(tok2, "[)];,]"))
|
||||||
if (tok2->str() == "[")
|
break;
|
||||||
arrayIndex = true;
|
else if (tok2->str() == "=") {
|
||||||
if (arrayIndex && tok2->varId() != 0)
|
eq = tok2;
|
||||||
dependencies[tok2->varId()].insert(tok->varId());
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
for (unsigned int varId : dependencies[tok->varId()]) {
|
|
||||||
varAssignments.erase(varId);
|
|
||||||
memAssignments.erase(varId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue