diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 269cbef272079..bc5239209f3aa 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1554,7 +1554,7 @@ class AnnotatingParser { }; if (IsInstancePort()) - Tok->setFinalizedType(TT_VerilogInstancePortLParen); + Tok->setType(TT_VerilogInstancePortLParen); } if (!parseParens()) @@ -1730,7 +1730,7 @@ class AnnotatingParser { Tok->setType(TT_InheritanceComma); break; case Context::VerilogInstancePortList: - Tok->setFinalizedType(TT_VerilogInstancePortComma); + Tok->setType(TT_VerilogInstancePortComma); break; default: if (Style.isVerilog() && Contexts.size() == 1 && diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 5f1dd38ef1eb3..c182aaf0876d1 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -4441,7 +4441,8 @@ unsigned UnwrappedLineParser::parseVerilogHierarchyHeader() { Prev->setFinalizedType(TT_VerilogDimensionedTypeName); parseSquare(); } else if (Keywords.isVerilogIdentifier(*FormatTok) || - FormatTok->isOneOf(Keywords.kw_automatic, tok::kw_static)) { + FormatTok->isOneOf(tok::hash, tok::hashhash, tok::coloncolon, + Keywords.kw_automatic, tok::kw_static)) { nextToken(); } else { break; diff --git a/clang/unittests/Format/FormatTestVerilog.cpp b/clang/unittests/Format/FormatTestVerilog.cpp index 49d276fc78d81..e4a14ff754d1a 100644 --- a/clang/unittests/Format/FormatTestVerilog.cpp +++ b/clang/unittests/Format/FormatTestVerilog.cpp @@ -702,6 +702,18 @@ TEST_F(FormatTestVerilog, Hierarchy) { " generate\n" " endgenerate\n" "endfunction : x"); + // Type names with '::' should be recognized. + verifyFormat("function automatic x::x x\n" + " (input x);\n" + "endfunction : x"); + // Names having to do macros should be recognized. + verifyFormat("function automatic x::x x``x\n" + " (input x);\n" + "endfunction : x"); + verifyFormat("function automatic x::x `x\n" + " (input x);\n" + "endfunction : x"); + verifyNoCrash("x x(x x, x x);"); } TEST_F(FormatTestVerilog, Identifiers) { diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index bb8ee416ea2db..e1ae1770e8ebe 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -2598,6 +2598,20 @@ TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) { Tokens = Annotate("x = '{\"\"};"); ASSERT_EQ(Tokens.size(), 8u) << Tokens; EXPECT_TOKEN(Tokens[4], tok::string_literal, TT_Unknown); + + // Module headers. + Tokens = Annotate("module x();\nendmodule"); + ASSERT_EQ(Tokens.size(), 7u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_VerilogMultiLineListLParen); + Tokens = Annotate("function automatic `x x();\nendmodule"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_VerilogMultiLineListLParen); + Tokens = Annotate("function automatic x``x x();\nendmodule"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_VerilogMultiLineListLParen); + Tokens = Annotate("function automatic x::x x();\nendmodule"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_VerilogMultiLineListLParen); } TEST_F(TokenAnnotatorTest, UnderstandTableGenTokens) {