[PATCH] D139281: [clang-format] Fix an assertion failure in block parsing

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 4 15:36:27 PST 2022


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

This assertion failure was introduced in 9ed2e68c9ae5 <https://reviews.llvm.org/rG9ed2e68c9ae5cf346f938cc095e5448c1ff60f51> and is manifested when both RemoveBracesLLVM and MacroBlockBegin are set.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139281

Files:
  clang/lib/Format/FormatToken.h
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -6602,6 +6602,13 @@
                "  x = 1;\n"
                "FOO_END(Baz)",
                Style);
+
+  Style.RemoveBracesLLVM = true;
+  verifyNoCrash("for (;;)\n"
+                "  FOO_BEGIN\n"
+                "    foo();\n"
+                "  FOO_END",
+                Style);
 }
 
 //===----------------------------------------------------------------------===//
Index: clang/lib/Format/FormatToken.h
===================================================================
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -1787,8 +1787,7 @@
 
   /// Whether the token begins a block.
   bool isBlockBegin(const FormatToken &Tok, const FormatStyle &Style) const {
-    return Tok.is(TT_MacroBlockBegin) ||
-           (Style.isVerilog() ? isVerilogBegin(Tok) : Tok.is(tok::l_brace));
+    return Style.isVerilog() ? isVerilogBegin(Tok) : Tok.is(tok::l_brace);
   }
 
 private:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139281.479948.patch
Type: text/x-patch
Size: 1111 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221204/13a7ced7/attachment.bin>


More information about the cfe-commits mailing list