[PATCH] D121596: [clang-format] Fix crash with ObjC Blocks
Björn Schäpers via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 14 05:21:18 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/54367
Fixes https://github.com/llvm/llvm-project/issues/54368
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D121596
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
@@ -612,6 +612,22 @@
EXPECT_TOKEN(Tokens[4], tok::r_brace, TT_InlineASMBrace);
}
+TEST_F(TokenAnnotatorTest, UnderstandsObjCBlock) {
+ auto Tokens = annotate("int (^)() = ^ ()\n"
+ " external_source_symbol() { //\n"
+ " return 1;\n"
+ "};");
+ ASSERT_EQ(Tokens.size(), 21u) << Tokens;
+ EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_ObjCBlockLParen);
+ EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_ObjCBlockLBrace);
+
+ Tokens = annotate("int *p = ^int*(){ //\n"
+ " return nullptr;\n"
+ "}();");
+ ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+ EXPECT_TOKEN(Tokens[9], tok::l_brace, TT_ObjCBlockLBrace);
+}
+
} // namespace
} // namespace format
} // namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -783,7 +783,7 @@
OpeningBrace.ParentBracket = Contexts.back().ContextKind;
if (Contexts.back().CaretFound)
- OpeningBrace.setType(TT_ObjCBlockLBrace);
+ OpeningBrace.overwriteFixedType(TT_ObjCBlockLBrace);
Contexts.back().CaretFound = false;
ScopedContextCreator ContextCreator(*this, tok::l_brace, 1);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121596.415070.patch
Type: text/x-patch
Size: 1537 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220314/4c2b8583/attachment.bin>
More information about the cfe-commits
mailing list