diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp index a9ea5ec9009c4..eb8658396ecde 100644 --- a/clang/lib/Format/FormatTokenLexer.cpp +++ b/clang/lib/Format/FormatTokenLexer.cpp @@ -1408,6 +1408,8 @@ FormatToken *FormatTokenLexer::getNextToken() { FormatTok->Tok.setKind(tok::identifier); } else if (Style.isTableGen() && !Keywords.isTableGenKeyword(*FormatTok)) { FormatTok->Tok.setKind(tok::identifier); + } else if (Style.isVerilog() && Keywords.isVerilogIdentifier(*FormatTok)) { + FormatTok->Tok.setKind(tok::identifier); } } else if (const bool Greater = FormatTok->is(tok::greatergreater); Greater || FormatTok->is(tok::lessless)) { diff --git a/clang/unittests/Format/FormatTestVerilog.cpp b/clang/unittests/Format/FormatTestVerilog.cpp index eee2bbdf551e6..f407fc36c3a12 100644 --- a/clang/unittests/Format/FormatTestVerilog.cpp +++ b/clang/unittests/Format/FormatTestVerilog.cpp @@ -423,6 +423,11 @@ TEST_F(FormatTestVerilog, Declaration) { verifyFormat("wire (strong1, pull0) mynet, mynet1 = enable;"); verifyFormat("wire (strong1, pull0) mynet, //\n" " mynet1 = enable;"); + + // The type or variable can be a C++ keyword. + verifyFormat("private mynet;"); + verifyFormat("switch mynet;"); + verifyFormat("wire try;"); } TEST_F(FormatTestVerilog, Delay) { diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 815c79e68dac9..4f4d8521f94d6 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -2909,6 +2909,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) { EXPECT_EQ(Tokens[0]->TokenText, R"(\busa+index\ +)"); EXPECT_TOKEN(Tokens[1], tok::semi, TT_Unknown); + + // A C++ keyword should be treated as an identifier. + Tokens = Annotate("volatile delete;"); + ASSERT_EQ(Tokens.size(), 4u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::identifier, TT_Unknown); + EXPECT_TOKEN(Tokens[1], tok::identifier, TT_StartOfName); + // An escaped newline should not be treated as an escaped identifier. Tokens = Annotate("\\\n"); ASSERT_EQ(Tokens.size(), 1u) << Tokens;