From aa281501c9a14a9c9e52062591e79ff0705a6039 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 11 Sep 2023 11:36:03 +0200 Subject: [PATCH] Fix #11923 FN unreadVariable (regression) (#5409) --- lib/fwdanalysis.cpp | 4 ++-- test/testunusedvar.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/fwdanalysis.cpp b/lib/fwdanalysis.cpp index 93c06c627..f3598412f 100644 --- a/lib/fwdanalysis.cpp +++ b/lib/fwdanalysis.cpp @@ -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; @@ -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; } } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 4a81d3f4b..ff6110afc 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -2641,11 +2641,11 @@ private: "}"); 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() {