[PATCH] D124036: [clang-format] Don't skip PP lines if original line was a PP line when trying to merge lines

Arthur Eubanks via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 19 13:06:01 PDT 2022


aeubanks created this revision.
Herald added a project: All.
aeubanks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes a crash introduced in D123737 <https://reviews.llvm.org/D123737> where LastNonComment would be null.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124036

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -13393,6 +13393,12 @@
                "    return 1;            \\\n"
                "  return 2;",
                ShortMergedIf);
+
+  verifyFormat("//\n"
+               "#define a \\\n"
+               "  if      \\\n"
+               "  0",
+               getChromiumStyle(FormatStyle::LK_Cpp));
 }
 
 TEST_F(FormatTest, FormatStarDependingOnContext) {
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -308,7 +308,8 @@
           // Find the last line with lower level.
           auto J = I - 1;
           for (; J != AnnotatedLines.begin(); --J)
-            if (!(*J)->InPPDirective && (*J)->Level < TheLine->Level)
+            if ((TheLine->InPPDirective || !(*J)->InPPDirective) &&
+                (*J)->Level < TheLine->Level)
               break;
           if ((*J)->Level >= TheLine->Level)
             return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124036.423714.patch
Type: text/x-patch
Size: 1207 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220419/dd0a47b9/attachment.bin>


More information about the cfe-commits mailing list