[PATCH] D121559: [clang-format] Fix crash on asm block with label

Björn Schäpers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 13 14:15:29 PDT 2022


HazardyKnusperkeks created this revision.
HazardyKnusperkeks added reviewers: owenpan, MyDeveloperDay, curdeius.
HazardyKnusperkeks added a project: clang-format.
Herald added a project: All.
HazardyKnusperkeks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes https://github.com/llvm/llvm-project/issues/54349


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121559

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===================================================================
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -577,6 +577,15 @@
           << 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
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -824,8 +824,10 @@
               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);
+        if (Style.isJavaScript())
+          OpeningBrace.overwriteFixedType(TT_DictLiteral);
       }
       if (CurrentToken->is(tok::comma)) {
         if (Style.isJavaScript())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121559.414958.patch
Type: text/x-patch
Size: 1389 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220313/57a6179b/attachment-0001.bin>


More information about the cfe-commits mailing list