Skip to content

Commit

Permalink
Fix #11923 FN unreadVariable (regression) (#5409)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Sep 11, 2023
1 parent 639a413 commit aa28150
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/fwdanalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ bool FwdAnalysis::unusedValue(const Token *expr, const Token *startToken, const

bool FwdAnalysis::possiblyAliased(const Token *expr, const Token *startToken) const
{
if (expr->isUnaryOp("*"))
if (expr->isUnaryOp("*") && !expr->astOperand1()->isUnaryOp("&"))
return true;

const bool macro = false;
Expand Down Expand Up @@ -540,7 +540,7 @@ bool FwdAnalysis::possiblyAliased(const Token *expr, const Token *startToken) co
continue;

for (const Token *subexpr = expr; subexpr; subexpr = subexpr->astOperand1()) {
if (isSameExpression(mCpp, macro, subexpr, addrOf, mLibrary, pure, followVar))
if (subexpr != addrOf && isSameExpression(mCpp, macro, subexpr, addrOf, mLibrary, pure, followVar))
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2641,11 +2641,11 @@ class TestUnusedVar : public TestFixture {
"}");
TODO_ASSERT_EQUALS("[test.cpp:4]: (style) Variable '*(b+i)' is assigned a value that is never used.\n", "", errout.str());

functionVariableUsage("void f() {\n" // #11832
functionVariableUsage("void f() {\n" // #11832, #11923
" int b;\n"
" *(&b) = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (style) Variable '*(&b)' is assigned a value that is never used.\n", errout.str());
}

void localvar8() {
Expand Down

0 comments on commit aa28150

Please sign in to comment.