From 3afb0b66584d9385f02fdb73719b6ac0fc99b70b Mon Sep 17 00:00:00 2001 From: Yan <62220457+likeamahoney@users.noreply.github.com> Date: Tue, 30 Jan 2024 23:13:18 +0300 Subject: [PATCH] [slang-tidy] Fix NoOldAlwaysSyntax checker segmentation fault (#882) Co-authored-by: Yan Churkin --- tools/tidy/include/ASTHelperVisitors.h | 3 ++- tools/tidy/tests/NoOldAlwaysSyntaxTest.cpp | 24 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/tools/tidy/include/ASTHelperVisitors.h b/tools/tidy/include/ASTHelperVisitors.h index f0cb45aa5..b5c7cbc80 100644 --- a/tools/tidy/include/ASTHelperVisitors.h +++ b/tools/tidy/include/ASTHelperVisitors.h @@ -55,7 +55,8 @@ struct CollectIdentifiers : public slang::ast::ASTVisitor { 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 symbols; diff --git a/tools/tidy/tests/NoOldAlwaysSyntaxTest.cpp b/tools/tidy/tests/NoOldAlwaysSyntaxTest.cpp index 00c7d340d..ba98eaa1c 100644 --- a/tools/tidy/tests/NoOldAlwaysSyntaxTest.cpp +++ b/tools/tidy/tests/NoOldAlwaysSyntaxTest.cpp @@ -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); +}