Skip to content

Commit

Permalink
[slang-tidy] Fix NoOldAlwaysSyntax checker segmentation fault
Browse files Browse the repository at this point in the history
  • Loading branch information
Yan Churkin committed Jan 30, 2024
1 parent de03987 commit 1416be9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tools/tidy/include/ASTHelperVisitors.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ struct CollectIdentifiers : public slang::ast::ASTVisitor<CollectIdentifiers, fa
/// ASTVisitor that will collect all LHS assignment symbols under a node
struct CollectLHSSymbols : public slang::ast::ASTVisitor<CollectLHSSymbols, true, true> {
void handle(const slang::ast::AssignmentExpression& expression) {
symbols.push_back(expression.left().getSymbolReference());
if (const auto symbol = expression.left().getSymbolReference(); symbol)
symbols.push_back(symbol);
}

std::vector<const slang::ast::Symbol*> symbols;
Expand Down
24 changes: 24 additions & 0 deletions tools/tidy/tests/NoOldAlwaysSyntaxTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,27 @@ endmodule
bool result = visitor->check(root);
CHECK(result);
}

TEST_CASE("NoOldAlwaysSyntax: composite lhs") {
auto tree = SyntaxTree::fromText(R"(
module top();
logic n;
always @(*) begin
{n} = 1;
end
endmodule
)");

Compilation compilation;
compilation.addSyntaxTree(tree);
compilation.getAllDiagnostics();
auto& root = compilation.getRoot();

TidyConfig config;
Registry::setConfig(config);
Registry::setSourceManager(compilation.getSourceManager());
auto visitor = Registry::create("NoOldAlwaysSyntax");
bool result = visitor->check(root);
CHECK(result);
}

0 comments on commit 1416be9

Please sign in to comment.