Author: Björn Schäpers Date: 2022-03-14T12:44:48+01:00 New Revision: 35abbf166d4ad13e4a89095307bb6e4b2e96e0b3
URL: https://github.com/llvm/llvm-project/commit/35abbf166d4ad13e4a89095307bb6e4b2e96e0b3 DIFF: https://github.com/llvm/llvm-project/commit/35abbf166d4ad13e4a89095307bb6e4b2e96e0b3.diff LOG: [clang-format] Fix crash on asm block with label Fixes https://github.com/llvm/llvm-project/issues/54349 Differential Revision: https://reviews.llvm.org/D121559 Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 8f433d78b7f74..6cf3681cdd9d5 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -824,8 +824,10 @@ class AnnotatingParser { Previous->is(tok::string_literal)) Previous->setType(TT_SelectorName); } - if (CurrentToken->is(tok::colon) || Style.isJavaScript()) + if (CurrentToken->is(tok::colon) && OpeningBrace.is(TT_Unknown)) OpeningBrace.setType(TT_DictLiteral); + else if (Style.isJavaScript()) + OpeningBrace.overwriteFixedType(TT_DictLiteral); } if (CurrentToken->is(tok::comma)) { if (Style.isJavaScript()) diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 05cf000eadb71..dd868be99f45e 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -602,6 +602,16 @@ TEST_F(TokenAnnotatorTest, RequiresDoesNotChangeParsingOfTheRest) { << I; } +TEST_F(TokenAnnotatorTest, UnderstandsAsm) { + auto Tokens = annotate("__asm{\n" + "a:\n" + "};"); + ASSERT_EQ(Tokens.size(), 7u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[1], tok::l_brace, TT_InlineASMBrace); + EXPECT_TOKEN(Tokens[4], tok::r_brace, TT_InlineASMBrace); +} + } // namespace } // namespace format } // namespace clang _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits