Redundant assignments: Fix false positive when reassignment expression contains assembler

This commit is contained in:
Daniel Marjamäki 2019-08-24 20:15:52 +02:00
parent 0dfda5eb4a
commit 324e5e581b
2 changed files with 20 additions and 0 deletions

View File

@ -1331,6 +1331,15 @@ static bool nonLocal(const Variable* var, bool deref)
return !var || (!var->isLocal() && !var->isArgument()) || (deref && var->isArgument() && var->isPointer()) || var->isStatic() || var->isReference() || var->isExtern();
}
static bool hasGccCompoundStatement(const Token *tok)
{
if (!tok)
return false;
if (tok->str() == "{" && Token::simpleMatch(tok->previous(), "( {"))
return true;
return hasGccCompoundStatement(tok->astOperand1()) || hasGccCompoundStatement(tok->astOperand2());
}
static bool hasFunctionCall(const Token *tok)
{
if (!tok)
@ -1688,6 +1697,9 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const
return Result(Result::Type::READ);
continue;
}
// ({ .. })
if (hasGccCompoundStatement(parent->astParent()->astOperand2()))
return Result(Result::Type::BAILOUT);
const bool reassign = isSameExpression(mCpp, false, expr, parent, mLibrary, false, false, nullptr);
if (reassign)
return Result(Result::Type::WRITE, parent->astParent());

View File

@ -6172,6 +6172,14 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
// ({ })
check("void f() {\n"
" int x;\n"
" x = 321;\n"
" x = ({ asm(123); })\n"
"}");
ASSERT_EQUALS("", errout.str());
// from #3103 (avoid a false negative)
check("int foo(){\n"
" int x;\n"