Fix #9828 False positive: unreadVariable alias (#3744)

This commit is contained in:
chrchr-github 2022-01-24 21:52:45 +01:00 committed by GitHub
parent 9d6e5c2a05
commit d05e43ce15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -3318,7 +3318,7 @@ bool FwdAnalysis::possiblyAliased(const Token *expr, const Token *startToken) co
const bool pure = false; const bool pure = false;
const bool followVar = false; const bool followVar = false;
for (const Token *tok = startToken; tok; tok = tok->previous()) { for (const Token *tok = startToken; tok; tok = tok->previous()) {
if (tok->str() == "{" && tok->scope()->type == Scope::eFunction) if (tok->str() == "{" && tok->scope()->type == Scope::eFunction && !(tok->astParent() && tok->astParent()->str() == ","))
break; break;
if (Token::Match(tok, "%name% (") && !Token::Match(tok, "if|while|for")) { if (Token::Match(tok, "%name% (") && !Token::Match(tok, "if|while|for")) {

View File

@ -141,6 +141,7 @@ private:
TEST_CASE(localvaralias16); TEST_CASE(localvaralias16);
TEST_CASE(localvaralias17); // ticket #8911 TEST_CASE(localvaralias17); // ticket #8911
TEST_CASE(localvaralias18); // ticket #9234 - iterator TEST_CASE(localvaralias18); // ticket #9234 - iterator
TEST_CASE(localvaralias19); // ticket #9828
TEST_CASE(localvarasm); TEST_CASE(localvarasm);
TEST_CASE(localvarstatic); TEST_CASE(localvarstatic);
TEST_CASE(localvarextern); TEST_CASE(localvarextern);
@ -4388,6 +4389,21 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void localvaralias19() { // #9828
functionVariableUsage("void f() {\n"
" bool b0{}, b1{};\n"
" struct {\n"
" bool* pb;\n"
" int val;\n"
" } Map[] = { {&b0, 0}, {&b1, 1} };\n"
" b0 = true;\n"
" for (auto & m : Map)\n"
" if (m.pb && *m.pb)\n"
" m.val = 1;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void localvarasm() { void localvarasm() {
functionVariableUsage("void foo(int &b)\n" functionVariableUsage("void foo(int &b)\n"