Redundant assignments: Fix false positive when reassignment expression contains assembler
This commit is contained in:
parent
0dfda5eb4a
commit
324e5e581b
|
@ -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();
|
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)
|
static bool hasFunctionCall(const Token *tok)
|
||||||
{
|
{
|
||||||
if (!tok)
|
if (!tok)
|
||||||
|
@ -1688,6 +1697,9 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const
|
||||||
return Result(Result::Type::READ);
|
return Result(Result::Type::READ);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// ({ .. })
|
||||||
|
if (hasGccCompoundStatement(parent->astParent()->astOperand2()))
|
||||||
|
return Result(Result::Type::BAILOUT);
|
||||||
const bool reassign = isSameExpression(mCpp, false, expr, parent, mLibrary, false, false, nullptr);
|
const bool reassign = isSameExpression(mCpp, false, expr, parent, mLibrary, false, false, nullptr);
|
||||||
if (reassign)
|
if (reassign)
|
||||||
return Result(Result::Type::WRITE, parent->astParent());
|
return Result(Result::Type::WRITE, parent->astParent());
|
||||||
|
|
|
@ -6172,6 +6172,14 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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)
|
// from #3103 (avoid a false negative)
|
||||||
check("int foo(){\n"
|
check("int foo(){\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
|
|
Loading…
Reference in New Issue