Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ bool astHasToken(const Token* root, const Token * tok)
{
if (!root)
return false;
if (root == tok)
return true;
return astHasToken(root->astOperand1(), tok) || astHasToken(root->astOperand2(), tok);
while (tok->astParent() && tok != root)
tok = tok->astParent();
return root == tok;
}

bool astHasVar(const Token * tok, nonneg int varid)
Expand Down Expand Up @@ -833,6 +833,8 @@ std::vector<ReferenceToken> followAllReferences(const Token* tok,
errors.emplace_back(var->declEndToken(), "Passed to reference.");
return {{tok, std::move(errors)}};
} else if (Token::simpleMatch(var->declEndToken(), "=")) {
if (astHasToken(var->declEndToken(), tok))
return std::vector<ReferenceToken>{};
errors.emplace_back(var->declEndToken(), "Assigned to reference.");
const Token *vartok = var->declEndToken()->astOperand2();
if (vartok == tok || (!temporary && isTemporary(true, vartok, nullptr, true) &&
Expand Down
9 changes: 9 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ class TestTokenizer : public TestFixture {
TEST_CASE(checkIfCppCast);
TEST_CASE(checkRefQualifiers);
TEST_CASE(checkConditionBlock);
TEST_CASE(checkUnknownCircularVar);

// #9052
TEST_CASE(noCrash1);
Expand Down Expand Up @@ -6845,6 +6846,14 @@ class TestTokenizer : public TestFixture {
"}\n"));
}

void checkUnknownCircularVar()
{
ASSERT_NO_THROW(tokenizeAndStringify("void execute() {\n"
" const auto &bias = GEMM_CTX_ARG_STORAGE(bias);\n"
" auto &c = GEMM_CTX_ARG_STORAGE(c);\n"
"}\n"));
}

void noCrash1() {
ASSERT_NO_THROW(tokenizeAndStringify(
"struct A {\n"
Expand Down