[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
Mon Mar 14 04:45:49 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG35abbf166d4a: [clang-format] Fix crash on asm block with label (authored by HazardyKnusperkeks).
Changed prior to commit:
https://reviews.llvm.org/D121559?vs=414958&id=415068#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D121559/new/
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
@@ -602,6 +602,16 @@
<< 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);
+ else 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.415068.patch
Type: text/x-patch
Size: 1396 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220314/2668f511/attachment.bin>
More information about the cfe-commits
mailing list