patch for formatter bug 38525

2018-08-10 Thread Owen Pan via cfe-commits
Hi,

Please see the attached patch file and test case for Bug 38525
 in Formatter.

Thanks,
Owen
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp	(revision 339102)
+++ lib/Format/ContinuationIndenter.cpp	(working copy)
@@ -700,7 +700,8 @@
 // Indent relative to the RHS of the expression unless this is a simple
 // assignment without binary expression on the RHS. Also indent relative to
 // unary operators and the colons of constructor initializers.
-State.Stack.back().LastSpace = State.Column;
+if (Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None)
+  State.Stack.back().LastSpace = State.Column;
   } else if (Previous.is(TT_InheritanceColon)) {
 State.Stack.back().Indent = State.Column;
 State.Stack.back().LastSpace = State.Column;
bool BreakBeforeBinaryOperators(bool someVeryVeryLongConditionThatBarelyFitsOnALine, bool someOtherLongishConditionPart1, bool someOtherEvenLongerNestedConditionPart2)
{
	return someVeryVeryLongConditionThatBarelyFitsOnALine && (someOtherLongishConditionPart1 || someOtherEvenLongerNestedConditionPart2);
}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Fwd: patch file for bug 38557

2018-08-14 Thread Owen Pan via cfe-commits
Hi,

Attached is the patch file for Bug 38557 (
https://bugs.llvm.org/show_bug.cgi?id=38557).

Thanks,
Owen
Index: UnwrappedLineParser.cpp
===
--- UnwrappedLineParser.cpp	(revision 339102)
+++ UnwrappedLineParser.cpp	(working copy)
@@ -350,7 +350,10 @@
   break;
 case tok::kw_default: {
   unsigned StoredPosition = Tokens->getPosition();
-  FormatToken *Next = Tokens->getNextToken();
+  FormatToken *Next;
+  do {
+Next = Tokens->getNextToken();
+  } while (Next && Next->is(tok::comment));
   FormatTok = Tokens->setPosition(StoredPosition);
   if (Next && Next->isNot(tok::colon)) {
 // default not followed by ':' is not a case label; treat it like
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: Fwd: patch file for bug 38557

2018-08-14 Thread Owen Pan via cfe-commits
Hi Jonas,

Thank you very much! I just created a phabricator account and created a
revision for another bug (https://reviews.llvm.org/D50699). I don't know
exactly how to add my test case like you did for me, so I just uploaded it.
I also added the reviewers listed by bugs.llvm.org.

How do I "take over" the revision you created for me?

Thanks,
Owen

On Tue, Aug 14, 2018 at 4:16 AM Jonas Toth 
wrote:

> Hi Owen,
>
> thank you for your patch. I created a revision for it to pass review:
> https://reviews.llvm.org/D50697
>
> If you do have an phabricator account you can take over, otherwise we can
> get it into trunk for you :)
>
> All the best, Jonas
>
> Am 14.08.2018 um 12:30 schrieb Owen Pan via cfe-commits:
>
> Hi,
>
> Attached is the patch file for Bug 38557 (
> https://bugs.llvm.org/show_bug.cgi?id=38557).
>
> Thanks,
> Owen
>
>
> ___
> cfe-commits mailing 
> listcfe-comm...@lists.llvm.orghttp://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r342116 - [clang-format] Wrapped block after case label should not be merged into one line

2018-09-13 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Thu Sep 13 00:27:15 2018
New Revision: 342116

URL: http://llvm.org/viewvc/llvm-project?rev=342116&view=rev
Log:
[clang-format] Wrapped block after case label should not be merged into one line

PR38854

Differential Revision: http://reviews.llvm.org/D51719

Modified:
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp?rev=342116&r1=342115&r2=342116&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp Thu Sep 13 00:27:15 2018
@@ -323,6 +323,10 @@ private:
   kwId == clang::tok::objc_synchronized)
 return 0;
 }
+// Don't merge block with left brace wrapped after case labels
+if (TheLine->First->is(tok::l_brace) && I != AnnotatedLines.begin() &&
+I[-1]->First->isOneOf(tok::kw_case, tok::kw_default))
+  return 0;
 // Try to merge a block with left brace wrapped that wasn't yet covered
 if (TheLine->Last->is(tok::l_brace)) {
   return !Style.BraceWrapping.AfterFunction ||

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=342116&r1=342115&r2=342116&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Sep 13 00:27:15 2018
@@ -1064,6 +1064,32 @@ TEST_F(FormatTest, FormatsSwitchStatemen
"  return;\n"
"}",
getLLVMStyleWithColumns(34));
+
+  FormatStyle Style = getLLVMStyle();
+  Style.IndentCaseLabels = true;
+  Style.AllowShortBlocksOnASingleLine = false;
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterControlStatement = true;
+  EXPECT_EQ("switch (n)\n"
+"{\n"
+"  case 0:\n"
+"  {\n"
+"return false;\n"
+"  }\n"
+"  default:\n"
+"  {\n"
+"return true;\n"
+"  }\n"
+"}",
+format("switch (n) {\n"
+   "  case 0: {\n"
+   "return false;\n"
+   "  }\n"
+   "  default: {\n"
+   "return true;\n"
+   "  }\n"
+   "}",
+   Style));
 }
 
 TEST_F(FormatTest, CaseRanges) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r357851 - [clang-format] Fix Bug 41407

2019-04-06 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Sat Apr  6 16:10:11 2019
New Revision: 357851

URL: http://llvm.org/viewvc/llvm-project?rev=357851&view=rev
Log:
[clang-format] Fix Bug 41407
Differential Revision: https://reviews.llvm.org/D60359

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=357851&r1=357850&r2=357851&view=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Sat Apr  6 16:10:11 2019
@@ -1057,7 +1057,7 @@ unsigned ContinuationIndenter::getNewLin
   if (Current.is(TT_ProtoExtensionLSquare))
 return State.Stack.back().Indent;
   if (State.Stack.back().Indent == State.FirstIndent && PreviousNonComment &&
-  PreviousNonComment->isNot(tok::r_brace))
+  !PreviousNonComment->isOneOf(tok::r_brace, TT_CtorInitializerComma))
 // Ensure that we fall back to the continuation indent width instead of
 // just flushing continuations left.
 return State.Stack.back().Indent + Style.ContinuationIndentWidth;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=357851&r1=357850&r2=357851&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sat Apr  6 16:10:11 2019
@@ -11946,6 +11946,13 @@ TEST_F(FormatTest, ConstructorInitialize
   "bool smaller = 1 < 
(\n"
   "   
a);",
   Style);
+
+  Style.BreakConstructorInitializers = FormatStyle::BCIS_AfterColon;
+  verifyFormat(
+  "SomeClass::Constructor() :\n"
+  "(),\n"
+  "() {}",
+  Style);
 }
 
 TEST_F(FormatTest, BreakConstructorInitializersBeforeComma) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r357877 - [clang-format] Fix bug https://bugs.llvm.org/show_bug.cgi?id=41413

2019-04-07 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Sun Apr  7 14:05:52 2019
New Revision: 357877

URL: http://llvm.org/viewvc/llvm-project?rev=357877&view=rev
Log:
[clang-format] Fix bug https://bugs.llvm.org/show_bug.cgi?id=41413

Differential Revision: https://reviews.llvm.org/D60374

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=357877&r1=357876&r2=357877&view=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Sun Apr  7 14:05:52 2019
@@ -945,18 +945,24 @@ unsigned ContinuationIndenter::getNewLin
   return State.Stack[State.Stack.size() - 2].LastSpace;
 return State.FirstIndent;
   }
-  // Indent a closing parenthesis at the previous level if followed by a semi 
or
-  // opening brace. This allows indentations such as:
+  // Indent a closing parenthesis at the previous level if followed by a semi,
+  // const, or opening brace. This allows indentations such as:
   // foo(
   //   a,
   // );
+  // int Foo::getter(
+  // //
+  // ) const {
+  //   return foo;
+  // }
   // function foo(
   //   a,
   // ) {
   //   code(); //
   // }
   if (Current.is(tok::r_paren) && State.Stack.size() > 1 &&
-  (!Current.Next || Current.Next->isOneOf(tok::semi, tok::l_brace)))
+  (!Current.Next ||
+   Current.Next->isOneOf(tok::semi, tok::kw_const, tok::l_brace)))
 return State.Stack[State.Stack.size() - 2].LastSpace;
   if (NextNonComment->is(TT_TemplateString) && NextNonComment->closesScope())
 return State.Stack[State.Stack.size() - 2].LastSpace;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=357877&r1=357876&r2=357877&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Apr  7 14:05:52 2019
@@ -12822,6 +12822,24 @@ TEST_F(FormatTest, ConfigurableContinuat
 format("int i = longFunction(arg);", SixIndent));
 }
 
+TEST_F(FormatTest, WrappedClosingParenthesisIndent) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat(
+  "int Foo::getter(\n"
+  "//\n"
+  ") const {\n"
+  "  return foo;\n"
+  "}",
+  Style);
+  verifyFormat(
+  "void Foo::setter(\n"
+  "//\n"
+  ") {\n"
+  "  foo = 1;\n"
+  "}",
+  Style);
+}
+
 TEST_F(FormatTest, SpacesInAngles) {
   FormatStyle Spaces = getLLVMStyle();
   Spaces.SpacesInAngles = true;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r357957 - [clang-format] Add AfterCaseLabel to BraceWrapping

2019-04-08 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Mon Apr  8 16:36:25 2019
New Revision: 357957

URL: http://llvm.org/viewvc/llvm-project?rev=357957&view=rev
Log:
[clang-format] Add AfterCaseLabel to BraceWrapping

Fixes PR38686

llvm-svn: 52527

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=357957&r1=357956&r2=357957&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Mon Apr  8 16:36:25 2019
@@ -407,47 +407,46 @@ the configuration (without a prefix: ``A
   };
   void f() { bar(); }
 
+
+
 **AllowShortIfStatementsOnASingleLine** (``ShortIfStyle``)
-  Dependent on the value, ``if (a) return 0;`` can be put on a
-  single line.
+  If ``true``, ``if (a) return;`` can be put on a single line.
 
   Possible values:
 
   * ``SIS_Never`` (in configuration: ``Never``)
-Do not allow short if functions.
+Never put short ifs on the same line.
 
 .. code-block:: c++
 
-   if (a)
- return;
-   else
- return;
+  if (a)
+return ;
+  else {
+return;
+  }
 
   * ``SIS_WithoutElse`` (in configuration: ``WithoutElse``)
-Allow short if functions on the same line, as long as else
-is not a compound statement.
+Without else put short ifs on the same line only if
+the else is not a compound statement.
 
 .. code-block:: c++
 
-   if (a) return;
-   else
- return;
-
-   if (a)
- return;
-   else {
- return;
-   }
+  if (a) return;
+  else
+return;
 
   * ``SIS_Always`` (in configuration: ``Always``)
-Allow short if statements even if the else is a compound statement.
+Always put short ifs on the same line if
+the else is not a compound statement or not.
 
 .. code-block:: c++
 
-   if (a) return;
-   else {
-  return;
-   }
+  if (a) return;
+  else {
+return;
+  }
+
+
 
 **AllowShortLambdasOnASingleLine** (``ShortLambdaStyle``)
   Dependent on the value, ``auto lambda []() { return 0; }`` can be put on a
@@ -705,6 +704,23 @@ the configuration (without a prefix: ``A
   Nested configuration flags:
 
 
+  * ``bool AfterCaseLabel`` Wrap case labels.
+
+.. code-block:: c++
+
+  false:true:
+  switch (foo) {vs. switch (foo) {
+case 1: { case 1:
+  bar();  {
+  break;bar();
+}   break;
+default: {}
+  plop(); default:
+} {
+  } plop();
+  }
+}
+
   * ``bool AfterClass`` Wrap class definitions.
 
 .. code-block:: c++
@@ -1043,28 +1059,19 @@ the configuration (without a prefix: ``A
 
 .. code-block:: c++
 
-  try
-  {
+  try {
 foo();
   }
-  catch ()
-  {
+  catch () {
   }
   void foo() { bar(); }
-  class foo
-  {
+  class foo {
   };
-  if (foo())
-  {
+  if (foo()) {
   }
-  else
-  {
+  else {
   }
-  enum X : int
-  {
-A,
-B
-  };
+  enum X : int { A, B };
 
   * ``BS_GNU`` (in configuration: ``GNU``)
 Always break before braces and add an extra level of indentation to
@@ -1504,6 +1511,7 @@ the configuration (without a prefix: ``A
#endif
 
 
+
 **IndentWidth** (``unsigned``)
   The number of columns to use for indentation.
 
@@ -1954,6 +1962,7 @@ the configuration (without a prefix: ``A
 
 **SpaceAfterLogicalNot** (``bool``)
   If ``true``, a space is inserted after the logical not operator (``!``).
+
   .. code-block:: c++
 
  true:  false:
@@ -2033,6 +2042,19 @@ the configuration (without a prefix: ``A
  }
}
 
+  * ``SBPO_NonEmptyParentheses`` (in configuration: ``NonEmptyParentheses``)
+Put a space before opening parentheses only if the parentheses are not
+empty i.e. '()'
+
+.. code-block:: c++
+
+  void() {
+if (true) {
+  f();
+  g (x, y, z);
+}
+  }
+
   * ``SBPO_Always`` (in configuration: ``Always``)
 Always put a space before opening parentheses, except when it's
 prohibited by the syntax rules (in function-like macro definitions) or

Modified: cfe/trunk/include/clang/For

Re: r357877 - [clang-format] Fix bug https://bugs.llvm.org/show_bug.cgi?id=41413

2019-04-13 Thread Owen Pan via cfe-commits
Hi Paul,

Thank you for the information! I will remember to do that from now on.

Regards,

Owen

On Fri, Apr 12, 2019 at 11:34 AM  wrote:

> Hi Owen,
>
> FYI, putting a URL in the headline of the commit message takes up
> space and doesn't really describe the fix to a casual reader. The
> subject line of your Phabricator review looks like it would have
> been perfectly fine to use for the commit as well.
>
> Citing the bug in the body of the commit message is enough to let
> people track down the original report, although even there we usually
> abbreviate it to 'PR' (so PR41413 in this example).
>
> Thanks!
> --paulr
>
> > -Original Message-
> > From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf
> Of
> > Owen Pan via cfe-commits
> > Sent: Sunday, April 07, 2019 5:06 PM
> > To: cfe-commits@lists.llvm.org
> > Subject: r357877 - [clang-format] Fix bug
> > https://bugs.llvm.org/show_bug.cgi?id=41413
> >
> > Author: owenpan
> > Date: Sun Apr  7 14:05:52 2019
> > New Revision: 357877
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=357877&view=rev
> > Log:
> > [clang-format] Fix bug https://bugs.llvm.org/show_bug.cgi?id=41413
> >
> > Differential Revision: https://reviews.llvm.org/D60374
> >
> > Modified:
> > cfe/trunk/lib/Format/ContinuationIndenter.cpp
> > cfe/trunk/unittests/Format/FormatTest.cpp
> >
> > Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
> > URL: http://llvm.org/viewvc/llvm-
> >
> project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=357877&r1=357876
> > &r2=357877&view=diff
> >
> ==
> > 
> > --- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
> > +++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Sun Apr  7 14:05:52
> 2019
> > @@ -945,18 +945,24 @@ unsigned ContinuationIndenter::getNewLin
> >return State.Stack[State.Stack.size() - 2].LastSpace;
> >  return State.FirstIndent;
> >}
> > -  // Indent a closing parenthesis at the previous level if followed by a
> > semi or
> > -  // opening brace. This allows indentations such as:
> > +  // Indent a closing parenthesis at the previous level if followed by a
> > semi,
> > +  // const, or opening brace. This allows indentations such as:
> >// foo(
> >//   a,
> >// );
> > +  // int Foo::getter(
> > +  // //
> > +  // ) const {
> > +  //   return foo;
> > +  // }
> >// function foo(
> >//   a,
> >// ) {
> >//   code(); //
> >// }
> >if (Current.is(tok::r_paren) && State.Stack.size() > 1 &&
> > -  (!Current.Next || Current.Next->isOneOf(tok::semi, tok::l_brace)))
> > +  (!Current.Next ||
> > +   Current.Next->isOneOf(tok::semi, tok::kw_const, tok::l_brace)))
> >  return State.Stack[State.Stack.size() - 2].LastSpace;
> >if (NextNonComment->is(TT_TemplateString) && NextNonComment-
> > >closesScope())
> >  return State.Stack[State.Stack.size() - 2].LastSpace;
> >
> > Modified: cfe/trunk/unittests/Format/FormatTest.cpp
> > URL: http://llvm.org/viewvc/llvm-
> >
> project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=357877&r1=357876&r2=
> > 357877&view=diff
> >
> ==
> > 
> > --- cfe/trunk/unittests/Format/FormatTest.cpp (original)
> > +++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Apr  7 14:05:52 2019
> > @@ -12822,6 +12822,24 @@ TEST_F(FormatTest, ConfigurableContinuat
> >  format("int i = longFunction(arg);", SixIndent));
> >  }
> >
> > +TEST_F(FormatTest, WrappedClosingParenthesisIndent) {
> > +  FormatStyle Style = getLLVMStyle();
> > +  verifyFormat(
> > +  "int Foo::getter(\n"
> > +  "//\n"
> > +  ") const {\n"
> > +  "  return foo;\n"
> > +  "}",
> > +  Style);
> > +  verifyFormat(
> > +  "void Foo::setter(\n"
> > +  "//\n"
> > +  ") {\n"
> > +  "  foo = 1;\n"
> > +  "}",
> > +  Style);
> > +}
> > +
> >  TEST_F(FormatTest, SpacesInAngles) {
> >FormatStyle Spaces = getLLVMStyle();
> >Spaces.SpacesInAngles = true;
> >
> >
> > ___
> > cfe-commits mailing list
> > cfe-commits@lists.llvm.org
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r358710 - [clang-format] Fix incorrect formatting of keyword macro definition

2019-04-18 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Thu Apr 18 13:17:08 2019
New Revision: 358710

URL: http://llvm.org/viewvc/llvm-project?rev=358710&view=rev
Log:
[clang-format] Fix incorrect formatting of keyword macro definition

See PR39719

Differential Revision: https://reviews.llvm.org/D60853

Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=358710&r1=358709&r2=358710&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Thu Apr 18 13:17:08 2019
@@ -805,7 +805,7 @@ void UnwrappedLineParser::parsePPEndIf()
 void UnwrappedLineParser::parsePPDefine() {
   nextToken();
 
-  if (FormatTok->Tok.getKind() != tok::identifier) {
+  if (!FormatTok->Tok.getIdentifierInfo()) {
 IncludeGuard = IG_Rejected;
 IncludeGuardToken = nullptr;
 parsePPUnknown();

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=358710&r1=358709&r2=358710&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Apr 18 13:17:08 2019
@@ -2468,6 +2468,12 @@ TEST_F(FormatTest, HashInMacroDefinition
 TEST_F(FormatTest, RespectWhitespaceInMacroDefinitions) {
   EXPECT_EQ("#define A (x)", format("#define A (x)"));
   EXPECT_EQ("#define A(x)", format("#define A(x)"));
+
+  FormatStyle Style = getLLVMStyle();
+  Style.SpaceBeforeParens = FormatStyle::SBPO_Never;
+  verifyFormat("#define true ((foo)1)", Style);
+  Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
+  verifyFormat("#define false((foo)0)", Style);
 }
 
 TEST_F(FormatTest, EmptyLinesInMacroDefinitions) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r359029 - [clang-format] Fix bug in reflow of block comments containing CR/LF

2019-04-23 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Tue Apr 23 13:29:46 2019
New Revision: 359029

URL: http://llvm.org/viewvc/llvm-project?rev=359029&view=rev
Log:
[clang-format] Fix bug in reflow of block comments containing CR/LF

Fix PR36119

Differential Revision: https://reviews.llvm.org/D60996

Modified:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/lib/Format/BreakableToken.h
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/WhitespaceManager.h
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=359029&r1=359028&r2=359029&view=diff
==
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Tue Apr 23 13:29:46 2019
@@ -329,7 +329,7 @@ static bool mayReflowContent(StringRef C
 BreakableBlockComment::BreakableBlockComment(
 const FormatToken &Token, unsigned StartColumn,
 unsigned OriginalStartColumn, bool FirstInLine, bool InPPDirective,
-encoding::Encoding Encoding, const FormatStyle &Style)
+encoding::Encoding Encoding, const FormatStyle &Style, bool UseCRLF)
 : BreakableComment(Token, StartColumn, InPPDirective, Encoding, Style),
   DelimitersOnNewline(false),
   UnbreakableTailLength(Token.UnbreakableTailLength) {
@@ -338,7 +338,8 @@ BreakableBlockComment::BreakableBlockCom
 
   StringRef TokenText(Tok.TokenText);
   assert(TokenText.startswith("/*") && TokenText.endswith("*/"));
-  TokenText.substr(2, TokenText.size() - 4).split(Lines, "\n");
+  TokenText.substr(2, TokenText.size() - 4).split(Lines,
+  UseCRLF ? "\r\n" : "\n");
 
   int IndentDelta = StartColumn - OriginalStartColumn;
   Content.resize(Lines.size());
@@ -472,7 +473,7 @@ void BreakableBlockComment::adjustWhites
   // Calculate the start of the non-whitespace text in the current line.
   size_t StartOfLine = Lines[LineIndex].find_first_not_of(Blanks);
   if (StartOfLine == StringRef::npos)
-StartOfLine = Lines[LineIndex].rtrim("\r\n").size();
+StartOfLine = Lines[LineIndex].size();
 
   StringRef Whitespace = Lines[LineIndex].substr(0, StartOfLine);
   // Adjust Lines to only contain relevant text.

Modified: cfe/trunk/lib/Format/BreakableToken.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.h?rev=359029&r1=359028&r2=359029&view=diff
==
--- cfe/trunk/lib/Format/BreakableToken.h (original)
+++ cfe/trunk/lib/Format/BreakableToken.h Tue Apr 23 13:29:46 2019
@@ -359,7 +359,7 @@ public:
   BreakableBlockComment(const FormatToken &Token, unsigned StartColumn,
 unsigned OriginalStartColumn, bool FirstInLine,
 bool InPPDirective, encoding::Encoding Encoding,
-const FormatStyle &Style);
+const FormatStyle &Style, bool UseCRLF);
 
   unsigned getRangeLength(unsigned LineIndex, unsigned Offset,
   StringRef::size_type Length,

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=359029&r1=359028&r2=359029&view=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Tue Apr 23 13:29:46 2019
@@ -1810,7 +1810,7 @@ ContinuationIndenter::createBreakableTok
 }
 return llvm::make_unique(
 Current, StartColumn, Current.OriginalColumn, !Current.Previous,
-State.Line->InPPDirective, Encoding, Style);
+State.Line->InPPDirective, Encoding, Style, Whitespaces.useCRLF());
   } else if (Current.is(TT_LineComment) &&
  (Current.Previous == nullptr ||
   Current.Previous->isNot(TT_ImplicitStringLiteral))) {

Modified: cfe/trunk/lib/Format/WhitespaceManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/WhitespaceManager.h?rev=359029&r1=359028&r2=359029&view=diff
==
--- cfe/trunk/lib/Format/WhitespaceManager.h (original)
+++ cfe/trunk/lib/Format/WhitespaceManager.h Tue Apr 23 13:29:46 2019
@@ -40,6 +40,8 @@ public:
 bool UseCRLF)
   : SourceMgr(SourceMgr), Style(Style), UseCRLF(UseCRLF) {}
 
+  bool useCRLF() const { return UseCRLF; }
+
   /// Replaces the whitespace in front of \p Tok. Only call once for
   /// each \c AnnotatedToken.
   ///

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=359029&r1=359028&r2=359029&view=diff
==
--- cf

r359280 - [clang-format] Fix documentation for FixNamespaceComments

2019-04-26 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Fri Apr 26 00:05:47 2019
New Revision: 359280

URL: http://llvm.org/viewvc/llvm-project?rev=359280&view=rev
Log:
[clang-format] Fix documentation for FixNamespaceComments

Fixes PR40409

Differential Revision: https://reviews.llvm.org/D61174

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=359280&r1=359279&r2=359280&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Fri Apr 26 00:05:47 2019
@@ -1346,7 +1346,7 @@ the configuration (without a prefix: ``A
  true:  false:
  namespace a {  vs. namespace a {
  foo(); foo();
- } // namespace a;  }
+ } // namespace a   }
 
 **ForEachMacros** (``std::vector``)
   A vector of macros that should be interpreted as foreach loops

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=359280&r1=359279&r2=359280&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Fri Apr 26 00:05:47 2019
@@ -1139,7 +1139,7 @@ struct FormatStyle {
   ///true:  false:
   ///namespace a {  vs. namespace a {
   ///foo(); foo();
-  ///} // namespace a;  }
+  ///} // namespace a   }
   /// \endcode
   bool FixNamespaceComments;
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r359687 - [clang-format] Fix bug that misses some function-like macro usages

2019-05-01 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Wed May  1 08:03:41 2019
New Revision: 359687

URL: http://llvm.org/viewvc/llvm-project?rev=359687&view=rev
Log:
[clang-format] Fix bug that misses some function-like macro usages

Fixes PR41483

Differential Revision: https://reviews.llvm.org/D61297

Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=359687&r1=359686&r2=359687&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed May  1 08:03:41 2019
@@ -1335,10 +1335,15 @@ void UnwrappedLineParser::parseStructura
   // See if the following token should start a new unwrapped line.
   StringRef Text = FormatTok->TokenText;
   nextToken();
-  if (Line->Tokens.size() == 1 &&
-  // JS doesn't have macros, and within classes colons indicate fields,
-  // not labels.
-  Style.Language != FormatStyle::LK_JavaScript) {
+
+  // JS doesn't have macros, and within classes colons indicate fields, not
+  // labels.
+  if (Style.Language == FormatStyle::LK_JavaScript)
+break;
+
+  TokenCount = Line->Tokens.size();
+  if (TokenCount == 1 ||
+  (TokenCount == 2 && Line->Tokens.front().Tok->is(tok::comment))) {
 if (FormatTok->Tok.is(tok::colon) && !Line->MustBeDeclaration) {
   Line->Tokens.begin()->Tok->MustBreakBefore = true;
   parseLabel();

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=359687&r1=359686&r2=359687&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed May  1 08:03:41 2019
@@ -2584,6 +2584,12 @@ TEST_F(FormatTest, MacrosWithoutTrailing
   verifyFormat("VISIT_GL_CALL(GenBuffers, void, (GLsizei n, GLuint* buffers), "
"(n, buffers))\n",
getChromiumStyle(FormatStyle::LK_Cpp));
+
+  // See PR41483
+  EXPECT_EQ("/**/ FOO(a)\n"
+"FOO(b)",
+format("/**/ FOO(a)\n"
+   "FOO(b)"));
 }
 
 TEST_F(FormatTest, MacroCallsWithoutTrailingSemicolon) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r359711 - [clang-format] Fix a bug in AlignConsecutiveDeclarations.

2019-05-01 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Wed May  1 11:23:44 2019
New Revision: 359711

URL: http://llvm.org/viewvc/llvm-project?rev=359711&view=rev
Log:
[clang-format] Fix a bug in AlignConsecutiveDeclarations.

Fixes PR37175

Differential Revision: https://reviews.llvm.org/D61222

Modified:
cfe/trunk/lib/Format/WhitespaceManager.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/WhitespaceManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/WhitespaceManager.cpp?rev=359711&r1=359710&r2=359711&view=diff
==
--- cfe/trunk/lib/Format/WhitespaceManager.cpp (original)
+++ cfe/trunk/lib/Format/WhitespaceManager.cpp Wed May  1 11:23:44 2019
@@ -463,9 +463,21 @@ void WhitespaceManager::alignConsecutive
   [](Change const &C) {
 // tok::kw_operator is necessary for aligning operator overload
 // definitions.
-return C.Tok->is(TT_StartOfName) ||
-   C.Tok->is(TT_FunctionDeclarationName) ||
-   C.Tok->is(tok::kw_operator);
+if (C.Tok->isOneOf(TT_FunctionDeclarationName, tok::kw_operator))
+  return true;
+if (C.Tok->isNot(TT_StartOfName))
+  return false;
+// Check if there is a subsequent name that starts the same 
declaration.
+for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next) {
+  if (Next->is(tok::comment))
+continue;
+  if (!Next->Tok.getIdentifierInfo())
+break;
+  if (Next->isOneOf(TT_StartOfName, TT_FunctionDeclarationName,
+tok::kw_operator))
+return false;
+}
+return true;
   },
   Changes, /*StartAt=*/0);
 }

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=359711&r1=359710&r2=359711&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed May  1 11:23:44 2019
@@ -10581,6 +10581,13 @@ TEST_F(FormatTest, AlignConsecutiveDecla
"  unsigned c;\n"
"}",
Alignment);
+
+  // See PR37175
+  FormatStyle Style = getMozillaStyle();
+  Style.AlignConsecutiveDeclarations = true;
+  EXPECT_EQ("DECOR1 /**/ int8_t /**/ DECOR2 /**/\n"
+"foo(int a);",
+format("DECOR1 /**/ int8_t /**/ DECOR2 /**/ foo (int a);", Style));
 }
 
 TEST_F(FormatTest, LinuxBraceBreaking) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r359943 - [clang-format] Fix bug in block comment reflow that joins * and /

2019-05-03 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Fri May  3 16:15:40 2019
New Revision: 359943

URL: http://llvm.org/viewvc/llvm-project?rev=359943&view=rev
Log:
[clang-format] Fix bug in block comment reflow that joins * and /

Fixes PR41213

Differential Revision: https://reviews.llvm.org/D61276

Modified:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/lib/Format/BreakableToken.h
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=359943&r1=359942&r2=359943&view=diff
==
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Fri May  3 16:15:40 2019
@@ -65,7 +65,8 @@ static StringRef getLineCommentIndentPre
 static BreakableToken::Split
 getCommentSplit(StringRef Text, unsigned ContentStartColumn,
 unsigned ColumnLimit, unsigned TabWidth,
-encoding::Encoding Encoding, const FormatStyle &Style) {
+encoding::Encoding Encoding, const FormatStyle &Style,
+bool DecorationEndsWithStar = false) {
   LLVM_DEBUG(llvm::dbgs() << "Comment split: \"" << Text
   << "\", Column limit: " << ColumnLimit
   << ", Content start: " << ContentStartColumn << 
"\n");
@@ -123,7 +124,10 @@ getCommentSplit(StringRef Text, unsigned
 if (SpaceOffset == 1 && Text[SpaceOffset - 1] == '*')
   return BreakableToken::Split(StringRef::npos, 0);
 StringRef BeforeCut = Text.substr(0, SpaceOffset).rtrim(Blanks);
-StringRef AfterCut = Text.substr(SpaceOffset).ltrim(Blanks);
+StringRef AfterCut = Text.substr(SpaceOffset);
+// Don't trim the leading blanks if it would create a */ after the break.
+if (!DecorationEndsWithStar || AfterCut.size() <= 1 || AfterCut[1] != '/')
+  AfterCut = AfterCut.ltrim(Blanks);
 return BreakableToken::Split(BeforeCut.size(),
  AfterCut.begin() - BeforeCut.end());
   }
@@ -452,6 +456,18 @@ BreakableBlockComment::BreakableBlockCom
   });
 }
 
+BreakableToken::Split
+BreakableBlockComment::getSplit(unsigned LineIndex, unsigned TailOffset,
+   unsigned ColumnLimit, unsigned ContentStartColumn,
+   llvm::Regex &CommentPragmasRegex) const {
+  // Don't break lines matching the comment pragmas regex.
+  if (CommentPragmasRegex.match(Content[LineIndex]))
+return Split(StringRef::npos, 0);
+  return getCommentSplit(Content[LineIndex].substr(TailOffset),
+ ContentStartColumn, ColumnLimit, Style.TabWidth,
+ Encoding, Style, Decoration.endswith("*"));
+}
+
 void BreakableBlockComment::adjustWhitespace(unsigned LineIndex,
  int IndentDelta) {
   // When in a preprocessor directive, the trailing backslash in a block 
comment

Modified: cfe/trunk/lib/Format/BreakableToken.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.h?rev=359943&r1=359942&r2=359943&view=diff
==
--- cfe/trunk/lib/Format/BreakableToken.h (original)
+++ cfe/trunk/lib/Format/BreakableToken.h Fri May  3 16:15:40 2019
@@ -361,6 +361,9 @@ public:
 bool InPPDirective, encoding::Encoding Encoding,
 const FormatStyle &Style, bool UseCRLF);
 
+  Split getSplit(unsigned LineIndex, unsigned TailOffset, unsigned ColumnLimit,
+ unsigned ContentStartColumn,
+ llvm::Regex &CommentPragmasRegex) const override;
   unsigned getRangeLength(unsigned LineIndex, unsigned Offset,
   StringRef::size_type Length,
   unsigned StartColumn) const override;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=359943&r1=359942&r2=359943&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri May  3 16:15:40 2019
@@ -11150,6 +11150,24 @@ TEST_F(FormatTest, OptimizeBreakPenaltyV
   FormatStyle Style = getLLVMStyle();
   Style.ColumnLimit = 20;
 
+  // See PR41213
+  EXPECT_EQ("/*\n"
+" *\t9012345\n"
+" * /8901\n"
+" */",
+format("/*\n"
+   " *\t9012345 /8901\n"
+   " */",
+   Style));
+  EXPECT_EQ("/*\n"
+" *345678\n"
+" *\t/8901\n"
+" */",
+format("/*\n"
+   " *345678\t/8901\n"
+   " */",
+   Style));
+
   verifyFormat("int a; // the\n"
"   // comment", Style);
   EXPECT_EQ("int 

r360256 - [clang] Fix a bug that reports UTF32 (LE) files as UTF16 (LE) ones

2019-05-08 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Wed May  8 06:49:17 2019
New Revision: 360256

URL: http://llvm.org/viewvc/llvm-project?rev=360256&view=rev
Log:
[clang] Fix a bug that reports UTF32 (LE) files as UTF16 (LE) ones

Also fix a typo for the SCSU byte order mark.

Differential Revision: https://reviews.llvm.org/D61628

Modified:
cfe/trunk/lib/Basic/SourceManager.cpp

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=360256&r1=360255&r2=360256&view=diff
==
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Wed May  8 06:49:17 2019
@@ -167,16 +167,16 @@ const llvm::MemoryBuffer *ContentCache::
   // http://en.wikipedia.org/wiki/Byte_order_mark for more information.
   StringRef BufStr = Buffer.getPointer()->getBuffer();
   const char *InvalidBOM = llvm::StringSwitch(BufStr)
-.StartsWith("\xFE\xFF", "UTF-16 (BE)")
-.StartsWith("\xFF\xFE", "UTF-16 (LE)")
 .StartsWith(llvm::StringLiteral::withInnerNUL("\x00\x00\xFE\xFF"),
   "UTF-32 (BE)")
 .StartsWith(llvm::StringLiteral::withInnerNUL("\xFF\xFE\x00\x00"),
   "UTF-32 (LE)")
+.StartsWith("\xFE\xFF", "UTF-16 (BE)")
+.StartsWith("\xFF\xFE", "UTF-16 (LE)")
 .StartsWith("\x2B\x2F\x76", "UTF-7")
 .StartsWith("\xF7\x64\x4C", "UTF-1")
 .StartsWith("\xDD\x73\x66\x73", "UTF-EBCDIC")
-.StartsWith("\x0E\xFE\xFF", "SDSU")
+.StartsWith("\x0E\xFE\xFF", "SCSU")
 .StartsWith("\xFB\xEE\x28", "BOCU-1")
 .StartsWith("\x84\x31\x95\x33", "GB-18030")
 .Default(nullptr);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r360257 - [clang-format] Fix the crash when formatting unsupported encodings

2019-05-08 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Wed May  8 07:11:12 2019
New Revision: 360257

URL: http://llvm.org/viewvc/llvm-project?rev=360257&view=rev
Log:
[clang-format] Fix the crash when formatting unsupported encodings

Fixes PR33946

Differential Revision: https://reviews.llvm.org/D61559

Modified:
cfe/trunk/tools/clang-format/ClangFormat.cpp

Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=360257&r1=360256&r2=360257&view=diff
==
--- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)
+++ cfe/trunk/tools/clang-format/ClangFormat.cpp Wed May  8 07:11:12 2019
@@ -257,6 +257,36 @@ static bool format(StringRef FileName) {
   std::unique_ptr Code = std::move(CodeOrErr.get());
   if (Code->getBufferSize() == 0)
 return false; // Empty files are formatted correctly.
+
+  // Check to see if the buffer has a UTF Byte Order Mark (BOM).
+  // We only support UTF-8 with and without a BOM right now.  See
+  // https://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding
+  // for more information.
+  StringRef BufStr = Code->getBuffer();
+  const char *InvalidBOM = llvm::StringSwitch(BufStr)
+.StartsWith(llvm::StringLiteral::withInnerNUL("\x00\x00\xFE\xFF"),
+  "UTF-32 (BE)")
+.StartsWith(llvm::StringLiteral::withInnerNUL("\xFF\xFE\x00\x00"),
+  "UTF-32 (LE)")
+.StartsWith("\xFE\xFF", "UTF-16 (BE)")
+.StartsWith("\xFF\xFE", "UTF-16 (LE)")
+.StartsWith("\x2B\x2F\x76", "UTF-7")
+.StartsWith("\xF7\x64\x4C", "UTF-1")
+.StartsWith("\xDD\x73\x66\x73", "UTF-EBCDIC")
+.StartsWith("\x0E\xFE\xFF", "SCSU")
+.StartsWith("\xFB\xEE\x28", "BOCU-1")
+.StartsWith("\x84\x31\x95\x33", "GB-18030")
+.Default(nullptr);
+
+  if (InvalidBOM) {
+errs() << "error: encoding with unsupported byte order mark \""
+   << InvalidBOM << "\" detected";
+if (FileName != "-")
+  errs() << " in file '" << FileName << "'";
+errs() << ".\n";
+return true;
+  }
+
   std::vector Ranges;
   if (fillRanges(Code.get(), Ranges))
 return true;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r342708 - [clang-format] Do not merge short case labels if followed by a block.

2018-09-20 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Thu Sep 20 20:46:36 2018
New Revision: 342708

URL: http://llvm.org/viewvc/llvm-project?rev=342708&view=rev
Log:
[clang-format] Do not merge short case labels if followed by a block.

Do not allow short case labels on a single line if the label is followed by a
left brace.

Fixes PR38926.

Modified:
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp?rev=342708&r1=342707&r2=342708&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp Thu Sep 20 20:46:36 2018
@@ -428,6 +428,8 @@ private:
 if (Limit == 0 || I + 1 == E ||
 I[1]->First->isOneOf(tok::kw_case, tok::kw_default))
   return 0;
+if (I[0]->Last->is(tok::l_brace) || I[1]->First->is(tok::l_brace))
+  return 0;
 unsigned NumStmts = 0;
 unsigned Length = 0;
 bool EndsWithComment = false;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=342708&r1=342707&r2=342708&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Sep 20 20:46:36 2018
@@ -1241,6 +1241,30 @@ TEST_F(FormatTest, ShortCaseLabels) {
"  return false;\n"
"}",
Style));
+  Style.AllowShortCaseLabelsOnASingleLine = true;
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterControlStatement = true;
+  EXPECT_EQ("switch (n)\n"
+"{\n"
+"  case 0:\n"
+"  {\n"
+"return false;\n"
+"  }\n"
+"  default:\n"
+"  {\n"
+"return true;\n"
+"  }\n"
+"}",
+format("switch (n) {\n"
+   "  case 0: {\n"
+   "return false;\n"
+   "  }\n"
+   "  default:\n"
+   "  {\n"
+   "return true;\n"
+   "  }\n"
+   "}",
+   Style));
 }
 
 TEST_F(FormatTest, FormatsLabels) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r343305 - [ClangFormat] 'try' of function-try-block doesn't obey BraceWrapping

2018-09-28 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Fri Sep 28 02:17:00 2018
New Revision: 343305

URL: http://llvm.org/viewvc/llvm-project?rev=343305&view=rev
Log:
[ClangFormat] 'try' of function-try-block doesn't obey BraceWrapping

It should respond to AfterFunction, not AfterControlStatement.

Fixes PR39067

Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=343305&r1=343304&r2=343305&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Fri Sep 28 02:17:00 2018
@@ -1266,6 +1266,8 @@ void UnwrappedLineParser::parseStructura
   break;
 case tok::kw_try:
   // We arrive here when parsing function-try blocks.
+  if (Style.BraceWrapping.AfterFunction)
+addUnwrappedLine();
   parseTryCatch();
   return;
 case tok::identifier: {

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=343305&r1=343304&r2=343305&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Sep 28 02:17:00 2018
@@ -2628,6 +2628,16 @@ TEST_F(FormatTest, MacroCallsWithoutTrai
"  A(X x)\n"
"  try : t(0) {} catch (...) {}\n"
"};"));
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterControlStatement = true;
+  Style.BraceWrapping.AfterFunction = true;
+  EXPECT_EQ("void f()\n"
+"try\n"
+"{\n"
+"}",
+format("void f() try {\n"
+   "}", Style));
   EXPECT_EQ("class SomeClass {\n"
 "public:\n"
 "  SomeClass() EXCLUSIVE_LOCK_FUNCTION(mu_);\n"


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r367648 - [clang-format] Fix a bug that doesn't break braces before unions for Allman

2019-08-01 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Thu Aug  1 21:30:42 2019
New Revision: 367648

URL: http://llvm.org/viewvc/llvm-project?rev=367648&view=rev
Log:
[clang-format] Fix a bug that doesn't break braces before unions for Allman
Differential Revision: https://reviews.llvm.org/D65631

Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=367648&r1=367647&r2=367648&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu Aug  1 21:30:42 2019
@@ -640,6 +640,7 @@ static FormatStyle expandPresets(const F
 Expanded.BraceWrapping.AfterNamespace = true;
 Expanded.BraceWrapping.AfterObjCDeclaration = true;
 Expanded.BraceWrapping.AfterStruct = true;
+Expanded.BraceWrapping.AfterUnion = true;
 Expanded.BraceWrapping.AfterExternBlock = true;
 Expanded.BraceWrapping.BeforeCatch = true;
 Expanded.BraceWrapping.BeforeElse = true;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=367648&r1=367647&r2=367648&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Aug  1 21:30:42 2019
@@ -11086,6 +11086,9 @@ TEST_F(FormatTest, AllmanBraceBreaking)
"{\n"
"  int x;\n"
"};\n"
+   "union C\n"
+   "{\n"
+   "};\n"
"} // namespace a",
AllmanBraceStyle);
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r368507 - [clang-format] Add SpaceInEmptyBlock option for WebKit

2019-08-10 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Sat Aug 10 00:51:21 2019
New Revision: 368507

URL: http://llvm.org/viewvc/llvm-project?rev=368507&view=rev
Log:
[clang-format] Add SpaceInEmptyBlock option for WebKit

See PR40840

Differential Revision: https://reviews.llvm.org/D65925

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=368507&r1=368506&r2=368507&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Sat Aug 10 00:51:21 2019
@@ -192,20 +192,6 @@ the configuration (without a prefix: ``A
 
 
 
-**AlignConsecutiveMacros** (``bool``)
-  If ``true``, aligns consecutive C/C++ preprocessor macros.
-
-  This will align the C/C++ preprocessor macros of consecutive lines. This
-  will result in formattings like
-
-  .. code-block:: c++
-
-#define SHORT_NAME   42
-#define LONGER_NAME  0x007f
-#define EVEN_LONGER_NAME (2)
-#define foo(x)   (x * x)
-#define bar(y, z)(y + z)
-
 **AlignConsecutiveAssignments** (``bool``)
   If ``true``, aligns consecutive assignments.
 
@@ -230,6 +216,20 @@ the configuration (without a prefix: ``A
 float   b = 23;
 std::string ccc = 23;
 
+**AlignConsecutiveMacros** (``bool``)
+  If ``true``, aligns consecutive C/C++ preprocessor macros.
+
+  This will align C/C++ preprocessor macros of consecutive lines.
+  Will result in formattings like
+
+  .. code-block:: c++
+
+#define SHORT_NAME   42
+#define LONGER_NAME  0x007f
+#define EVEN_LONGER_NAME (2)
+#define foo(x)   (x * x)
+#define bar(y, z)(y + z)
+
 **AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``)
   Options for aligning backslashes in escaped newlines.
 
@@ -1390,24 +1390,6 @@ the configuration (without a prefix: ``A
 
   For example: BOOST_FOREACH.
 
-**TypenameMacros** (``std::vector``)
-  A vector of macros that should be interpreted as type declarations
-  instead of as function calls.
-
-  These are expected to be macros of the form:
-
-  .. code-block: c++
-
-STACK_OF(...)
-
-  In the .clang-format configuration file, this can be configured like:
-
-  .. code-block: yaml
-
-TypenameMacros: ['STACK_OF', 'LIST']
-
-  For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
-
 **IncludeBlocks** (``IncludeBlocksStyle``)
   Dependent on the value, multiple ``#include`` blocks can be sorted
   as one and divided based on category.
@@ -2134,6 +2116,15 @@ the configuration (without a prefix: ``A
  true:  false:
  for (auto v : values) {}   vs. for(auto v: values) {}
 
+**SpaceInEmptyBlock** (``bool``)
+  If ``true``, spaces will be inserted into ``{}``.
+
+  .. code-block:: c++
+
+ true:false:
+ void f() { }   vs.   void f() {}
+ while (true) { } while (true) {}
+
 **SpaceInEmptyParentheses** (``bool``)
   If ``true``, spaces may be inserted into ``()``.
 
@@ -2241,6 +2232,24 @@ the configuration (without a prefix: ``A
 **TabWidth** (``unsigned``)
   The number of columns used for tab stops.
 
+**TypenameMacros** (``std::vector``)
+  A vector of macros that should be interpreted as type declarations
+  instead of as function calls.
+
+  These are expected to be macros of the form:
+
+  .. code-block:: c++
+
+STACK_OF(...)
+
+  In the .clang-format configuration file, this can be configured like:
+
+  .. code-block:: yaml
+
+TypenameMacros: ['STACK_OF', 'LIST']
+
+  For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
+
 **UseTab** (``UseTabStyle``)
   The way to use tab characters in the resulting file.
 

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=368507&r1=368506&r2=368507&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Sat Aug 10 00:51:21 2019
@@ -1799,6 +1799,14 @@ struct FormatStyle {
   /// \endcode
   bool SpaceBeforeRangeBasedForLoopColon;
 
+  /// If ``true``, spaces will be inserted into ``{}``.
+  /// \code
+  ///true:false:
+  ///void f() { }   vs.   void f() {}
+  ///while (true) { } while (true) {}
+  /// \endcode
+  bool SpaceInEmptyBlock;
+
   /// If ``true``, spaces may be inserted into ``()``.
   /// \code
   ///true:false:
@@ -1995,6 +2003,7 @@ struct FormatStyle {
SpaceBeforeParens

r368539 - [clang-format] Expand AllowShortBlocksOnASingleLine for WebKit

2019-08-11 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Sun Aug 11 10:48:36 2019
New Revision: 368539

URL: http://llvm.org/viewvc/llvm-project?rev=368539&view=rev
Log:
[clang-format] Expand AllowShortBlocksOnASingleLine for WebKit

See PR40840

Differential Revision: https://reviews.llvm.org/D66059

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=368539&r1=368538&r2=368539&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Sun Aug 11 10:48:36 2019
@@ -344,10 +344,42 @@ the configuration (without a prefix: ``A
 int d,
 int e);
 
-**AllowShortBlocksOnASingleLine** (``bool``)
-  Allows contracting simple braced statements to a single line.
+**AllowShortBlocksOnASingleLine** (``ShortBlockStyle``)
+  Dependent on the value, ``while (true) { continue; }`` can be put on a
+  single line.
+
+  Possible values:
+
+  * ``SBS_Never`` (in configuration: ``Never``)
+Never merge blocks into a single line.
+
+.. code-block:: c++
+
+  while (true) {
+  }
+  while (true) {
+continue;
+  }
+
+  * ``SBS_Empty`` (in configuration: ``Empty``)
+Only merge empty blocks.
+
+.. code-block:: c++
+
+  while (true) {}
+  while (true) {
+continue;
+  }
+
+  * ``SBS_Always`` (in configuration: ``Always``)
+Always merge short blocks into a single line.
+
+.. code-block:: c++
+
+  while (true) {}
+  while (true) { continue; }
+
 
-  E.g., this allows ``if (a) { return; }`` to be put on a single line.
 
 **AllowShortCaseLabelsOnASingleLine** (``bool``)
   If ``true``, short case labels will be contracted to a single line.

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=368539&r1=368538&r2=368539&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Sun Aug 11 10:48:36 2019
@@ -216,10 +216,37 @@ struct FormatStyle {
   /// \endcode
   bool AllowAllParametersOfDeclarationOnNextLine;
 
-  /// Allows contracting simple braced statements to a single line.
-  ///
-  /// E.g., this allows ``if (a) { return; }`` to be put on a single line.
-  bool AllowShortBlocksOnASingleLine;
+  /// Different styles for merging short blocks containing at most one
+  /// statement.
+  enum ShortBlockStyle {
+/// Never merge blocks into a single line.
+/// \code
+///   while (true) {
+///   }
+///   while (true) {
+/// continue;
+///   }
+/// \endcode
+SBS_Never,
+/// Only merge empty blocks.
+/// \code
+///   while (true) {}
+///   while (true) {
+/// continue;
+///   }
+/// \endcode
+SBS_Empty,
+/// Always merge short blocks into a single line.
+/// \code
+///   while (true) {}
+///   while (true) { continue; }
+/// \endcode
+SBS_Always,
+  };
+
+  /// Dependent on the value, ``while (true) { continue; }`` can be put on a
+  /// single line.
+  ShortBlockStyle AllowShortBlocksOnASingleLine;
 
   /// If ``true``, short case labels will be contracted to a single line.
   /// \code

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=368539&r1=368538&r2=368539&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Sun Aug 11 10:48:36 2019
@@ -95,6 +95,16 @@ template <> struct ScalarEnumerationTrai
   }
 };
 
+template <> struct ScalarEnumerationTraits {
+  static void enumeration(IO &IO, FormatStyle::ShortBlockStyle &Value) {
+IO.enumCase(Value, "Never", FormatStyle::SBS_Never);
+IO.enumCase(Value, "false", FormatStyle::SBS_Never);
+IO.enumCase(Value, "Always", FormatStyle::SBS_Always);
+IO.enumCase(Value, "true", FormatStyle::SBS_Always);
+IO.enumCase(Value, "Empty", FormatStyle::SBS_Empty);
+  }
+};
+
 template <> struct ScalarEnumerationTraits {
   static void enumeration(IO &IO, FormatStyle::ShortFunctionStyle &Value) {
 IO.enumCase(Value, "None", FormatStyle::SFS_None);
@@ -674,7 +684,7 @@ FormatStyle getLLVMStyle(FormatStyle::La
   LLVMStyle.AllowAllConstructorInitializersOnNextLine = true;
   LLVMStyle.AllowAllParametersOfDeclarationOnNextLine = true;
   LLVMStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
-  LLVMStyle.AllowShortBloc

r369157 - [clang-format] Fix the bug that joins template closer and > or >>

2019-08-16 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Fri Aug 16 14:49:17 2019
New Revision: 369157

URL: http://llvm.org/viewvc/llvm-project?rev=369157&view=rev
Log:
[clang-format] Fix the bug that joins template closer and > or >>

Also fixes a buggy test case.

See PR42404

Differential Revision: https://reviews.llvm.org/D66332

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=369157&r1=369156&r2=369157&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Aug 16 14:49:17 2019
@@ -919,6 +919,8 @@ private:
 case tok::greater:
   if (Style.Language != FormatStyle::LK_TextProto)
 Tok->Type = TT_BinaryOperator;
+  if (Tok->Previous && Tok->Previous->is(TT_TemplateCloser))
+Tok->SpacesRequiredBefore = 1;
   break;
 case tok::kw_operator:
   if (Style.Language == FormatStyle::LK_TextProto ||

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=369157&r1=369156&r2=369157&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Aug 16 14:49:17 2019
@@ -6618,7 +6618,10 @@ TEST_F(FormatTest, UnderstandsTemplatePa
   EXPECT_EQ("auto x = [] { A>> a; };",
 format("auto x=[]{A >> a;};", getGoogleStyle()));
 
-  verifyFormat("A> a;", getChromiumStyle(FormatStyle::LK_Cpp));
+  verifyFormat("A> a;", getChromiumStyle(FormatStyle::LK_Cpp));
+
+  verifyFormat("int i = a<1> >> 1;");
+  verifyFormat("bool b = a<1> > 1;");
 
   verifyFormat("test >> a >> b;");
   verifyFormat("test << a >> b;");


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r369214 - [clang-format] Fix a bug that joins template closer and =

2019-08-18 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Sun Aug 18 11:51:39 2019
New Revision: 369214

URL: http://llvm.org/viewvc/llvm-project?rev=369214&view=rev
Log:
[clang-format] Fix a bug that joins template closer and =

Also fixes the documentation for SpaceBeforeAssignmentOperators.

See discussions at https://reviews.llvm.org/D66332

Differential Revision: https://reviews.llvm.org/D66384

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=369214&r1=369213&r2=369214&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Sun Aug 18 11:51:39 2019
@@ -2050,8 +2050,8 @@ the configuration (without a prefix: ``A
   .. code-block:: c++
 
  true:  false:
- int a = 5; vs. int a=5;
- a += 42a+=42;
+ int a = 5; vs. int a= 5;
+ a += 42;   a+= 42;
 
 **SpaceBeforeCpp11BracedList** (``bool``)
   If ``true``, a space will be inserted before a C++11 braced list

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=369214&r1=369213&r2=369214&view=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Sun Aug 18 11:51:39 2019
@@ -1738,8 +1738,8 @@ struct FormatStyle {
   /// If ``false``, spaces will be removed before assignment operators.
   /// \code
   ///true:  false:
-  ///int a = 5; vs. int a=5;
-  ///a += 42a+=42;
+  ///int a = 5; vs. int a= 5;
+  ///a += 42;   a+= 42;
   /// \endcode
   bool SpaceBeforeAssignmentOperators;
 

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=369214&r1=369213&r2=369214&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sun Aug 18 11:51:39 2019
@@ -2870,7 +2870,7 @@ bool TokenAnnotator::spaceRequiredBefore
   Left.isOneOf(tok::arrow, tok::period, tok::arrowstar, tok::periodstar) ||
   (Right.is(tok::period) && Right.isNot(TT_DesignatedInitializerPeriod)))
 return false;
-  if (!Style.SpaceBeforeAssignmentOperators &&
+  if (!Style.SpaceBeforeAssignmentOperators && Left.isNot(TT_TemplateCloser) &&
   Right.getPrecedence() == prec::Assignment)
 return false;
   if (Style.Language == FormatStyle::LK_Java && Right.is(tok::coloncolon) &&

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=369214&r1=369213&r2=369214&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Aug 18 11:51:39 2019
@@ -6620,8 +6620,15 @@ TEST_F(FormatTest, UnderstandsTemplatePa
 
   verifyFormat("A> a;", getChromiumStyle(FormatStyle::LK_Cpp));
 
-  verifyFormat("int i = a<1> >> 1;");
+  // template closer followed by a token that starts with > or =
   verifyFormat("bool b = a<1> > 1;");
+  verifyFormat("bool b = a<1> >= 1;");
+  verifyFormat("int i = a<1> >> 1;");
+  FormatStyle Style = getLLVMStyle();
+  Style.SpaceBeforeAssignmentOperators = false;
+  verifyFormat("bool b= a<1> == 1;", Style);
+  verifyFormat("a = 1;", Style);
+  verifyFormat("a >>= 1;", Style);
 
   verifyFormat("test >> a >> b;");
   verifyFormat("test << a >> b;");


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r371571 - [clang-format] Apply BAS_AlwaysBreak to C++11 braced lists

2019-09-10 Thread Owen Pan via cfe-commits
Author: owenpan
Date: Tue Sep 10 16:26:45 2019
New Revision: 371571

URL: http://llvm.org/viewvc/llvm-project?rev=371571&view=rev
Log:
[clang-format] Apply BAS_AlwaysBreak to C++11 braced lists

See PR18455.

Differential Revision: https://reviews.llvm.org/D67395

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=371571&r1=371570&r2=371571&view=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Tue Sep 10 16:26:45 2019
@@ -606,7 +606,9 @@ void ContinuationIndenter::addTokenOnCur
   // disallowing any further line breaks if there is no line break after the
   // opening parenthesis. Don't break if it doesn't conserve columns.
   if (Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak &&
-  Previous.isOneOf(tok::l_paren, TT_TemplateOpener, tok::l_square) &&
+  (Previous.isOneOf(tok::l_paren, TT_TemplateOpener, tok::l_square) ||
+   (Previous.is(tok::l_brace) && Previous.BlockKind != BK_Block &&
+Style.Cpp11BracedListStyle)) &&
   State.Column > getNewLineColumn(State) &&
   (!Previous.Previous || !Previous.Previous->isOneOf(
  tok::kw_for, tok::kw_while, tok::kw_switch)) 
&&

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=371571&r1=371570&r2=371571&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Sep 10 16:26:45 2019
@@ -7835,6 +7835,16 @@ TEST_F(FormatTest, LayoutCxx11BraceIniti
   "};",
   NoBinPacking);
 
+  NoBinPacking.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+  EXPECT_EQ("static uint8 CddDp83848Reg[] = {\n"
+"CDDDP83848_BMCR_REGISTER,\n"
+"CDDDP83848_BMSR_REGISTER,\n"
+"CDDDP83848_RBR_REGISTER};",
+format("static uint8 CddDp83848Reg[] = 
{CDDDP83848_BMCR_REGISTER,\n"
+   "
CDDDP83848_BMSR_REGISTER,\n"
+   "CDDDP83848_RBR_REGISTER};",
+   NoBinPacking));
+
   // FIXME: The alignment of these trailing comments might be bad. Then again,
   // this might be utterly useless in real code.
   verifyFormat("Constructor::Constructor()\n"


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add spaces around the Verilog implication operator (PR #71352)

2023-11-06 Thread Owen Pan via cfe-commits

https://github.com/owenca approved this pull request.


https://github.com/llvm/llvm-project/pull/71352
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add ability for clang-format-diff to exit with non-0 status (PR #70883)

2023-11-08 Thread Owen Pan via cfe-commits


@@ -325,6 +325,7 @@ output of a unified diff and reformats all contained lines 
with
   The name of the predefined style used as a fallback 
in case clang-format is invoked with-style=file, but can not
   find the .clang-formatfile to use.
 -binary BINARYlocation of binary to use for clang-format
+-non-zero-exit-code   exit with a non-zero status if formatting changes 
are necessary

owenca wrote:

```suggestion
```

https://github.com/llvm/llvm-project/pull/70883
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add ability for clang-format-diff to exit with non-0 status (PR #70883)

2023-11-08 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/70883

>From 646cabcf167facb63c78277b50ea62afbc61b3c0 Mon Sep 17 00:00:00 2001
From: Conrad Donahue 
Date: Tue, 31 Oct 2023 21:55:27 -0400
Subject: [PATCH 1/3] Add ability for clang-format-diff to exit with non-0
 status

---
 clang/docs/ClangFormat.rst| 1 +
 clang/tools/clang-format/clang-format-diff.py | 8 
 2 files changed, 9 insertions(+)

diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index f52f35550d03eb6..42864b90e408037 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -325,6 +325,7 @@ output of a unified diff and reformats all contained lines 
with
   The name of the predefined style used as a fallback 
in case clang-format is invoked with-style=file, but can not
   find the .clang-formatfile to use.
 -binary BINARYlocation of binary to use for clang-format
+-non-zero-exit-code   exit with a non-zero status if formatting changes 
are necessary
 
 To reformat all the lines in the latest Mercurial/:program:`hg` commit, do:
 
diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index 324ef5b7f6b35f6..755ef23649a2469 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -95,6 +95,12 @@ def main():
 default="clang-format",
 help="location of binary to use for clang-format",
 )
+parser.add_argument(
+"-non-zero-exit-code",
+action="store_true",
+default=False,
+help="exit with a non-zero status if formatting changes are necessary"
+)
 args = parser.parse_args()
 
 # Extract changed lines for each file.
@@ -185,6 +191,8 @@ def main():
 diff_string = "".join(diff)
 if len(diff_string) > 0:
 sys.stdout.write(diff_string)
+if args.non_zero_exit_code:
+sys.exit(1)
 
 
 if __name__ == "__main__":

>From 929ccfdae7bf8d377e20f69200826cb67fcca76a Mon Sep 17 00:00:00 2001
From: Conrad Donahue 
Date: Tue, 31 Oct 2023 22:14:50 -0400
Subject: [PATCH 2/3] Fix formatting in clang-format-diff.py

---
 clang/tools/clang-format/clang-format-diff.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index 755ef23649a2469..3d5542b65529df2 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -99,7 +99,7 @@ def main():
 "-non-zero-exit-code",
 action="store_true",
 default=False,
-help="exit with a non-zero status if formatting changes are necessary"
+help="exit with a non-zero status if formatting changes are necessary",
 )
 args = parser.parse_args()
 

>From 4a06c6596c6f721340b731b1119146a80b472d5b Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 8 Nov 2023 13:06:21 -0800
Subject: [PATCH 3/3] Update clang/tools/clang-format/clang-format-diff.py

---
 clang/tools/clang-format/clang-format-diff.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index 3d5542b65529df2..dbb18d39d460ffe 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -191,8 +191,7 @@ def main():
 diff_string = "".join(diff)
 if len(diff_string) > 0:
 sys.stdout.write(diff_string)
-if args.non_zero_exit_code:
-sys.exit(1)
+sys.exit(1)
 
 
 if __name__ == "__main__":

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add ability for clang-format-diff to exit with non-0 status (PR #70883)

2023-11-08 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/70883

>From 646cabcf167facb63c78277b50ea62afbc61b3c0 Mon Sep 17 00:00:00 2001
From: Conrad Donahue 
Date: Tue, 31 Oct 2023 21:55:27 -0400
Subject: [PATCH 1/4] Add ability for clang-format-diff to exit with non-0
 status

---
 clang/docs/ClangFormat.rst| 1 +
 clang/tools/clang-format/clang-format-diff.py | 8 
 2 files changed, 9 insertions(+)

diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index f52f35550d03eb6..42864b90e408037 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -325,6 +325,7 @@ output of a unified diff and reformats all contained lines 
with
   The name of the predefined style used as a fallback 
in case clang-format is invoked with-style=file, but can not
   find the .clang-formatfile to use.
 -binary BINARYlocation of binary to use for clang-format
+-non-zero-exit-code   exit with a non-zero status if formatting changes 
are necessary
 
 To reformat all the lines in the latest Mercurial/:program:`hg` commit, do:
 
diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index 324ef5b7f6b35f6..755ef23649a2469 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -95,6 +95,12 @@ def main():
 default="clang-format",
 help="location of binary to use for clang-format",
 )
+parser.add_argument(
+"-non-zero-exit-code",
+action="store_true",
+default=False,
+help="exit with a non-zero status if formatting changes are necessary"
+)
 args = parser.parse_args()
 
 # Extract changed lines for each file.
@@ -185,6 +191,8 @@ def main():
 diff_string = "".join(diff)
 if len(diff_string) > 0:
 sys.stdout.write(diff_string)
+if args.non_zero_exit_code:
+sys.exit(1)
 
 
 if __name__ == "__main__":

>From 929ccfdae7bf8d377e20f69200826cb67fcca76a Mon Sep 17 00:00:00 2001
From: Conrad Donahue 
Date: Tue, 31 Oct 2023 22:14:50 -0400
Subject: [PATCH 2/4] Fix formatting in clang-format-diff.py

---
 clang/tools/clang-format/clang-format-diff.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index 755ef23649a2469..3d5542b65529df2 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -99,7 +99,7 @@ def main():
 "-non-zero-exit-code",
 action="store_true",
 default=False,
-help="exit with a non-zero status if formatting changes are necessary"
+help="exit with a non-zero status if formatting changes are necessary",
 )
 args = parser.parse_args()
 

>From 4a06c6596c6f721340b731b1119146a80b472d5b Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 8 Nov 2023 13:06:21 -0800
Subject: [PATCH 3/4] Update clang/tools/clang-format/clang-format-diff.py

---
 clang/tools/clang-format/clang-format-diff.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index 3d5542b65529df2..dbb18d39d460ffe 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -191,8 +191,7 @@ def main():
 diff_string = "".join(diff)
 if len(diff_string) > 0:
 sys.stdout.write(diff_string)
-if args.non_zero_exit_code:
-sys.exit(1)
+sys.exit(1)
 
 
 if __name__ == "__main__":

>From 657cdc255913ef694a7691e2347a331047d8fd3f Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 8 Nov 2023 13:06:30 -0800
Subject: [PATCH 4/4] Update clang/docs/ClangFormat.rst

---
 clang/docs/ClangFormat.rst | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index 42864b90e408037..f52f35550d03eb6 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -325,7 +325,6 @@ output of a unified diff and reformats all contained lines 
with
   The name of the predefined style used as a fallback 
in case clang-format is invoked with-style=file, but can not
   find the .clang-formatfile to use.
 -binary BINARYlocation of binary to use for clang-format
--non-zero-exit-code   exit with a non-zero status if formatting changes 
are necessary
 
 To reformat all the lines in the latest Mercurial/:program:`hg` commit, do:
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add ability for clang-format-diff to exit with non-0 status (PR #70883)

2023-11-08 Thread Owen Pan via cfe-commits


@@ -95,6 +95,12 @@ def main():
 default="clang-format",
 help="location of binary to use for clang-format",
 )
+parser.add_argument(
+"-non-zero-exit-code",
+action="store_true",
+default=False,
+help="exit with a non-zero status if formatting changes are necessary",
+)

owenca wrote:

```suggestion
```

https://github.com/llvm/llvm-project/pull/70883
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add ability for clang-format-diff to exit with non-0 status (PR #70883)

2023-11-08 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/70883

>From 646cabcf167facb63c78277b50ea62afbc61b3c0 Mon Sep 17 00:00:00 2001
From: Conrad Donahue 
Date: Tue, 31 Oct 2023 21:55:27 -0400
Subject: [PATCH 1/5] Add ability for clang-format-diff to exit with non-0
 status

---
 clang/docs/ClangFormat.rst| 1 +
 clang/tools/clang-format/clang-format-diff.py | 8 
 2 files changed, 9 insertions(+)

diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index f52f35550d03eb6..42864b90e408037 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -325,6 +325,7 @@ output of a unified diff and reformats all contained lines 
with
   The name of the predefined style used as a fallback 
in case clang-format is invoked with-style=file, but can not
   find the .clang-formatfile to use.
 -binary BINARYlocation of binary to use for clang-format
+-non-zero-exit-code   exit with a non-zero status if formatting changes 
are necessary
 
 To reformat all the lines in the latest Mercurial/:program:`hg` commit, do:
 
diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index 324ef5b7f6b35f6..755ef23649a2469 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -95,6 +95,12 @@ def main():
 default="clang-format",
 help="location of binary to use for clang-format",
 )
+parser.add_argument(
+"-non-zero-exit-code",
+action="store_true",
+default=False,
+help="exit with a non-zero status if formatting changes are necessary"
+)
 args = parser.parse_args()
 
 # Extract changed lines for each file.
@@ -185,6 +191,8 @@ def main():
 diff_string = "".join(diff)
 if len(diff_string) > 0:
 sys.stdout.write(diff_string)
+if args.non_zero_exit_code:
+sys.exit(1)
 
 
 if __name__ == "__main__":

>From 929ccfdae7bf8d377e20f69200826cb67fcca76a Mon Sep 17 00:00:00 2001
From: Conrad Donahue 
Date: Tue, 31 Oct 2023 22:14:50 -0400
Subject: [PATCH 2/5] Fix formatting in clang-format-diff.py

---
 clang/tools/clang-format/clang-format-diff.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index 755ef23649a2469..3d5542b65529df2 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -99,7 +99,7 @@ def main():
 "-non-zero-exit-code",
 action="store_true",
 default=False,
-help="exit with a non-zero status if formatting changes are necessary"
+help="exit with a non-zero status if formatting changes are necessary",
 )
 args = parser.parse_args()
 

>From 4a06c6596c6f721340b731b1119146a80b472d5b Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 8 Nov 2023 13:06:21 -0800
Subject: [PATCH 3/5] Update clang/tools/clang-format/clang-format-diff.py

---
 clang/tools/clang-format/clang-format-diff.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index 3d5542b65529df2..dbb18d39d460ffe 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -191,8 +191,7 @@ def main():
 diff_string = "".join(diff)
 if len(diff_string) > 0:
 sys.stdout.write(diff_string)
-if args.non_zero_exit_code:
-sys.exit(1)
+sys.exit(1)
 
 
 if __name__ == "__main__":

>From 657cdc255913ef694a7691e2347a331047d8fd3f Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 8 Nov 2023 13:06:30 -0800
Subject: [PATCH 4/5] Update clang/docs/ClangFormat.rst

---
 clang/docs/ClangFormat.rst | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index 42864b90e408037..f52f35550d03eb6 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -325,7 +325,6 @@ output of a unified diff and reformats all contained lines 
with
   The name of the predefined style used as a fallback 
in case clang-format is invoked with-style=file, but can not
   find the .clang-formatfile to use.
 -binary BINARYlocation of binary to use for clang-format
--non-zero-exit-code   exit with a non-zero status if formatting changes 
are necessary
 
 To reformat all the lines in the latest Mercurial/:program:`hg` commit, do:
 

>From 02a79586ae5f5306379b6a3b1551ae4b7142accc Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 8 Nov 2023 13:08:35 -0800
Subject: [PATCH 5/5] Update clang/tools/clang-format/clang-format-diff.

[clang] [clang-format] Add ability for clang-format-diff to exit with non-0 status (PR #70883)

2023-11-08 Thread Owen Pan via cfe-commits

https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/70883
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle variable declarations in BreakAfterAttributes (PR #71755)

2023-11-08 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/71755

Also cleaned up some old test cases.

Fixes #71563.

>From 40769fdc8163e61c8a89bc983a7fa50b08ba5e04 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 8 Nov 2023 17:55:56 -0800
Subject: [PATCH] [clang-format] Handle variable declarations in
 BreakAfterAttributes

Also cleaned up some old test cases.

Fixes #71563.
---
 clang/docs/ClangFormatStyleOptions.rst |  4 +--
 clang/include/clang/Format/Format.h|  4 +--
 clang/lib/Format/TokenAnnotator.cpp| 33 --
 clang/unittests/Format/FormatTest.cpp  | 38 ++
 4 files changed, 49 insertions(+), 30 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 21342e1b89ea866..3b9c4bcf19b2c2d 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2049,8 +2049,8 @@ the configuration (without a prefix: ``Auto``).
 .. _BreakAfterAttributes:
 
 **BreakAfterAttributes** (``AttributeBreakingStyle``) 
:versionbadge:`clang-format 16` :ref:`¶ `
-  Break after a group of C++11 attributes before a function
-  declaration/definition name.
+  Break after a group of C++11 attributes before a variable/function
+  (including constructor/destructor) declaration/definition name.
 
   Possible values:
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 3e9d1915badd87f..8282f9206ddd2fd 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1449,8 +1449,8 @@ struct FormatStyle {
 ABS_Never,
   };
 
-  /// Break after a group of C++11 attributes before a function
-  /// declaration/definition name.
+  /// Break after a group of C++11 attributes before a variable/function
+  /// (including constructor/destructor) declaration/definition name.
   /// \version 16
   AttributeBreakingStyle BreakAfterAttributes;
 
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 729e7e370bf62ea..210152d0846f4f9 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2000,6 +2000,10 @@ class AnnotatingParser {
(!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
   Contexts.back().FirstStartOfName = &Current;
   Current.setType(TT_StartOfName);
+  if (auto *PrevNonComment = Current.getPreviousNonComment();
+  PrevNonComment && PrevNonComment->is(TT_StartOfName)) {
+PrevNonComment->setType(TT_Unknown);
+  }
 } else if (Current.is(tok::semi)) {
   // Reset FirstStartOfName after finding a semicolon so that a for loop
   // with multiple increment statements is not confused with a for loop
@@ -3258,7 +3262,7 @@ static bool isFunctionDeclarationName(bool IsCpp, const 
FormatToken &Current,
   if (Current.is(TT_FunctionDeclarationName))
 return true;
 
-  if (!Current.Tok.getIdentifierInfo())
+  if (!Current.Tok.getIdentifierInfo() || Current.is(TT_CtorDtorDeclName))
 return false;
 
   auto skipOperatorName = [](const FormatToken *Next) -> const FormatToken * {
@@ -3441,29 +3445,28 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
   if (AlignArrayOfStructures)
 calculateArrayInitializerColumnList(Line);
 
+  const bool IsCpp = Style.isCpp();
   bool LineIsFunctionDeclaration = false;
   FormatToken *ClosingParen = nullptr;
   for (FormatToken *Tok = Current, *AfterLastAttribute = nullptr; Tok;
Tok = Tok->Next) {
 if (Tok->Previous->EndsCppAttributeGroup)
   AfterLastAttribute = Tok;
-if (const bool IsCtorOrDtor = Tok->is(TT_CtorDtorDeclName);
-IsCtorOrDtor ||
-isFunctionDeclarationName(Style.isCpp(), *Tok, Line, ClosingParen)) {
-  if (!IsCtorOrDtor) {
-LineIsFunctionDeclaration = true;
-Tok->setFinalizedType(TT_FunctionDeclarationName);
-  }
-  if (AfterLastAttribute &&
-  mustBreakAfterAttributes(*AfterLastAttribute, Style)) {
-AfterLastAttribute->MustBreakBefore = true;
-Line.ReturnTypeWrapped = true;
-  }
-  break;
+LineIsFunctionDeclaration =
+isFunctionDeclarationName(IsCpp, *Tok, Line, ClosingParen);
+if (LineIsFunctionDeclaration)
+  Tok->setFinalizedType(TT_FunctionDeclarationName);
+else if (!Tok->isOneOf(TT_CtorDtorDeclName, TT_StartOfName))
+  continue;
+if (AfterLastAttribute &&
+mustBreakAfterAttributes(*AfterLastAttribute, Style)) {
+  AfterLastAttribute->MustBreakBefore = true;
+  Line.ReturnTypeWrapped = true;
 }
+break;
   }
 
-  if (Style.isCpp()) {
+  if (IsCpp) {
 if (!LineIsFunctionDeclaration) {
   // Annotate */&/&& in `operator` function calls as binary operators.
   for (const auto *Tok = Line.First; Tok; Tok = Tok->Next) {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
in

[clang] [clang-format] Add ability for clang-format-diff to exit with non-0 status (PR #70883)

2023-11-08 Thread Owen Pan via cfe-commits

https://github.com/owenca approved this pull request.


https://github.com/llvm/llvm-project/pull/70883
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Add ability for clang-format-diff to exit with non-0 status (PR #70883)

2023-11-08 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/70883
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle variable declarations in BreakAfterAttributes (PR #71755)

2023-11-08 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/71755

>From c85d3c4879a5ff9d6f3ab318ebd7b63410249062 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 8 Nov 2023 17:55:56 -0800
Subject: [PATCH] [clang-format] Handle variable declarations in
 BreakAfterAttributes

Also cleaned up some old test cases.

Fixes #71563.
---
 clang/docs/ClangFormatStyleOptions.rst | 13 +++--
 clang/include/clang/Format/Format.h| 13 +++--
 clang/lib/Format/TokenAnnotator.cpp| 33 --
 clang/unittests/Format/FormatTest.cpp  | 38 ++
 4 files changed, 67 insertions(+), 30 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 21342e1b89ea866..d496fc85f7ae71a 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2049,8 +2049,8 @@ the configuration (without a prefix: ``Auto``).
 .. _BreakAfterAttributes:
 
 **BreakAfterAttributes** (``AttributeBreakingStyle``) 
:versionbadge:`clang-format 16` :ref:`¶ `
-  Break after a group of C++11 attributes before a function
-  declaration/definition name.
+  Break after a group of C++11 attributes before a variable/function
+  (including constructor/destructor) declaration/definition name.
 
   Possible values:
 
@@ -2059,6 +2059,10 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
+  [[maybe_unused]]
+  const int i;
+  [[gnu::const]] [[maybe_unused]]
+  int j;
   [[nodiscard]]
   inline int f();
   [[gnu::const]] [[nodiscard]]
@@ -2069,6 +2073,9 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
+  [[maybe_unused]] const int i;
+  [[gnu::const]] [[maybe_unused]]
+  int j;
   [[nodiscard]] inline int f();
   [[gnu::const]] [[nodiscard]]
   int g();
@@ -2078,6 +2085,8 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
+  [[maybe_unused]] const int i;
+  [[gnu::const]] [[maybe_unused]] int j;
   [[nodiscard]] inline int f();
   [[gnu::const]] [[nodiscard]] int g();
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 3e9d1915badd87f..9442344000e142b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1428,6 +1428,10 @@ struct FormatStyle {
   enum AttributeBreakingStyle : int8_t {
 /// Always break after attributes.
 /// \code
+///   [[maybe_unused]]
+///   const int i;
+///   [[gnu::const]] [[maybe_unused]]
+///   int j;
 ///   [[nodiscard]]
 ///   inline int f();
 ///   [[gnu::const]] [[nodiscard]]
@@ -1436,6 +1440,9 @@ struct FormatStyle {
 ABS_Always,
 /// Leave the line breaking after attributes as is.
 /// \code
+///   [[maybe_unused]] const int i;
+///   [[gnu::const]] [[maybe_unused]]
+///   int j;
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]]
 ///   int g();
@@ -1443,14 +1450,16 @@ struct FormatStyle {
 ABS_Leave,
 /// Never break after attributes.
 /// \code
+///   [[maybe_unused]] const int i;
+///   [[gnu::const]] [[maybe_unused]] int j;
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]] int g();
 /// \endcode
 ABS_Never,
   };
 
-  /// Break after a group of C++11 attributes before a function
-  /// declaration/definition name.
+  /// Break after a group of C++11 attributes before a variable/function
+  /// (including constructor/destructor) declaration/definition name.
   /// \version 16
   AttributeBreakingStyle BreakAfterAttributes;
 
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 729e7e370bf62ea..210152d0846f4f9 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2000,6 +2000,10 @@ class AnnotatingParser {
(!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
   Contexts.back().FirstStartOfName = &Current;
   Current.setType(TT_StartOfName);
+  if (auto *PrevNonComment = Current.getPreviousNonComment();
+  PrevNonComment && PrevNonComment->is(TT_StartOfName)) {
+PrevNonComment->setType(TT_Unknown);
+  }
 } else if (Current.is(tok::semi)) {
   // Reset FirstStartOfName after finding a semicolon so that a for loop
   // with multiple increment statements is not confused with a for loop
@@ -3258,7 +3262,7 @@ static bool isFunctionDeclarationName(bool IsCpp, const 
FormatToken &Current,
   if (Current.is(TT_FunctionDeclarationName))
 return true;
 
-  if (!Current.Tok.getIdentifierInfo())
+  if (!Current.Tok.getIdentifierInfo() || Current.is(TT_CtorDtorDeclName))
 return false;
 
   auto skipOperatorName = [](const FormatToken *Next) -> const FormatToken * {
@@ -3441,29 +3445,28 @@ void 
TokenAnnotator::calculateFormattingInformation(Annotat

[clang] [clang-format] Handle variable declarations in BreakAfterAttributes (PR #71755)

2023-11-08 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/71755

>From 17921d5a1d74017128691428815ede53ac1a4d67 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 8 Nov 2023 17:55:56 -0800
Subject: [PATCH] [clang-format] Handle variable declarations in
 BreakAfterAttributes

Also cleaned up some old test cases.

Fixes #71563.
---
 clang/docs/ClangFormatStyleOptions.rst | 13 +++--
 clang/include/clang/Format/Format.h| 13 +++--
 clang/lib/Format/TokenAnnotator.cpp| 22 +--
 clang/unittests/Format/FormatTest.cpp  | 38 ++
 4 files changed, 62 insertions(+), 24 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 21342e1b89ea866..d496fc85f7ae71a 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2049,8 +2049,8 @@ the configuration (without a prefix: ``Auto``).
 .. _BreakAfterAttributes:
 
 **BreakAfterAttributes** (``AttributeBreakingStyle``) 
:versionbadge:`clang-format 16` :ref:`¶ `
-  Break after a group of C++11 attributes before a function
-  declaration/definition name.
+  Break after a group of C++11 attributes before a variable/function
+  (including constructor/destructor) declaration/definition name.
 
   Possible values:
 
@@ -2059,6 +2059,10 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
+  [[maybe_unused]]
+  const int i;
+  [[gnu::const]] [[maybe_unused]]
+  int j;
   [[nodiscard]]
   inline int f();
   [[gnu::const]] [[nodiscard]]
@@ -2069,6 +2073,9 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
+  [[maybe_unused]] const int i;
+  [[gnu::const]] [[maybe_unused]]
+  int j;
   [[nodiscard]] inline int f();
   [[gnu::const]] [[nodiscard]]
   int g();
@@ -2078,6 +2085,8 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
+  [[maybe_unused]] const int i;
+  [[gnu::const]] [[maybe_unused]] int j;
   [[nodiscard]] inline int f();
   [[gnu::const]] [[nodiscard]] int g();
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 3e9d1915badd87f..9442344000e142b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1428,6 +1428,10 @@ struct FormatStyle {
   enum AttributeBreakingStyle : int8_t {
 /// Always break after attributes.
 /// \code
+///   [[maybe_unused]]
+///   const int i;
+///   [[gnu::const]] [[maybe_unused]]
+///   int j;
 ///   [[nodiscard]]
 ///   inline int f();
 ///   [[gnu::const]] [[nodiscard]]
@@ -1436,6 +1440,9 @@ struct FormatStyle {
 ABS_Always,
 /// Leave the line breaking after attributes as is.
 /// \code
+///   [[maybe_unused]] const int i;
+///   [[gnu::const]] [[maybe_unused]]
+///   int j;
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]]
 ///   int g();
@@ -1443,14 +1450,16 @@ struct FormatStyle {
 ABS_Leave,
 /// Never break after attributes.
 /// \code
+///   [[maybe_unused]] const int i;
+///   [[gnu::const]] [[maybe_unused]] int j;
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]] int g();
 /// \endcode
 ABS_Never,
   };
 
-  /// Break after a group of C++11 attributes before a function
-  /// declaration/definition name.
+  /// Break after a group of C++11 attributes before a variable/function
+  /// (including constructor/destructor) declaration/definition name.
   /// \version 16
   AttributeBreakingStyle BreakAfterAttributes;
 
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 729e7e370bf62ea..12f2e2ded19a01c 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2000,6 +2000,10 @@ class AnnotatingParser {
(!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
   Contexts.back().FirstStartOfName = &Current;
   Current.setType(TT_StartOfName);
+  if (auto *PrevNonComment = Current.getPreviousNonComment();
+  PrevNonComment && PrevNonComment->is(TT_StartOfName)) {
+PrevNonComment->setType(TT_Unknown);
+  }
 } else if (Current.is(tok::semi)) {
   // Reset FirstStartOfName after finding a semicolon so that a for loop
   // with multiple increment statements is not confused with a for loop
@@ -3258,7 +3262,7 @@ static bool isFunctionDeclarationName(bool IsCpp, const 
FormatToken &Current,
   if (Current.is(TT_FunctionDeclarationName))
 return true;
 
-  if (!Current.Tok.getIdentifierInfo())
+  if (!Current.Tok.getIdentifierInfo() || Current.is(TT_CtorDtorDeclName))
 return false;
 
   auto skipOperatorName = [](const FormatToken *Next) -> const FormatToken * {
@@ -3441,19 +3445,19 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine 

[clang] [clang-format] Handle variable declarations in BreakAfterAttributes (PR #71755)

2023-11-08 Thread Owen Pan via cfe-commits

owenca wrote:

> However this doesn't address the second part of the linked issue (with the 
> `if`) does it?

Nope! That part is a duplicate of #64474. I was going to add a note in #71563 
before merging this PR but now just saw that @FalcoGer closed the old issue and 
opened the new one, which is essentially the same.

https://github.com/llvm/llvm-project/pull/71755
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format]: Split alignment of declarations around assignment (PR #69340)

2023-11-09 Thread Owen Pan via cfe-commits

https://github.com/owenca commented:

See https://github.com/llvm/llvm-project/issues/66857#issuecomment-1793022188. 
Can you make this a suboption, e.g. `AlignFunctionPointers`? We can add another 
(e.g. `AlignConstructorsDestructors`) for ctors and dtors in the future.

https://github.com/llvm/llvm-project/pull/69340
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle variable declarations in BreakAfterAttributes (PR #71755)

2023-11-09 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/71755

>From 17921d5a1d74017128691428815ede53ac1a4d67 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 8 Nov 2023 17:55:56 -0800
Subject: [PATCH 1/2] [clang-format] Handle variable declarations in
 BreakAfterAttributes

Also cleaned up some old test cases.

Fixes #71563.
---
 clang/docs/ClangFormatStyleOptions.rst | 13 +++--
 clang/include/clang/Format/Format.h| 13 +++--
 clang/lib/Format/TokenAnnotator.cpp| 22 +--
 clang/unittests/Format/FormatTest.cpp  | 38 ++
 4 files changed, 62 insertions(+), 24 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 21342e1b89ea866..d496fc85f7ae71a 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2049,8 +2049,8 @@ the configuration (without a prefix: ``Auto``).
 .. _BreakAfterAttributes:
 
 **BreakAfterAttributes** (``AttributeBreakingStyle``) 
:versionbadge:`clang-format 16` :ref:`¶ `
-  Break after a group of C++11 attributes before a function
-  declaration/definition name.
+  Break after a group of C++11 attributes before a variable/function
+  (including constructor/destructor) declaration/definition name.
 
   Possible values:
 
@@ -2059,6 +2059,10 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
+  [[maybe_unused]]
+  const int i;
+  [[gnu::const]] [[maybe_unused]]
+  int j;
   [[nodiscard]]
   inline int f();
   [[gnu::const]] [[nodiscard]]
@@ -2069,6 +2073,9 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
+  [[maybe_unused]] const int i;
+  [[gnu::const]] [[maybe_unused]]
+  int j;
   [[nodiscard]] inline int f();
   [[gnu::const]] [[nodiscard]]
   int g();
@@ -2078,6 +2085,8 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
+  [[maybe_unused]] const int i;
+  [[gnu::const]] [[maybe_unused]] int j;
   [[nodiscard]] inline int f();
   [[gnu::const]] [[nodiscard]] int g();
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 3e9d1915badd87f..9442344000e142b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1428,6 +1428,10 @@ struct FormatStyle {
   enum AttributeBreakingStyle : int8_t {
 /// Always break after attributes.
 /// \code
+///   [[maybe_unused]]
+///   const int i;
+///   [[gnu::const]] [[maybe_unused]]
+///   int j;
 ///   [[nodiscard]]
 ///   inline int f();
 ///   [[gnu::const]] [[nodiscard]]
@@ -1436,6 +1440,9 @@ struct FormatStyle {
 ABS_Always,
 /// Leave the line breaking after attributes as is.
 /// \code
+///   [[maybe_unused]] const int i;
+///   [[gnu::const]] [[maybe_unused]]
+///   int j;
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]]
 ///   int g();
@@ -1443,14 +1450,16 @@ struct FormatStyle {
 ABS_Leave,
 /// Never break after attributes.
 /// \code
+///   [[maybe_unused]] const int i;
+///   [[gnu::const]] [[maybe_unused]] int j;
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]] int g();
 /// \endcode
 ABS_Never,
   };
 
-  /// Break after a group of C++11 attributes before a function
-  /// declaration/definition name.
+  /// Break after a group of C++11 attributes before a variable/function
+  /// (including constructor/destructor) declaration/definition name.
   /// \version 16
   AttributeBreakingStyle BreakAfterAttributes;
 
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 729e7e370bf62ea..12f2e2ded19a01c 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2000,6 +2000,10 @@ class AnnotatingParser {
(!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
   Contexts.back().FirstStartOfName = &Current;
   Current.setType(TT_StartOfName);
+  if (auto *PrevNonComment = Current.getPreviousNonComment();
+  PrevNonComment && PrevNonComment->is(TT_StartOfName)) {
+PrevNonComment->setType(TT_Unknown);
+  }
 } else if (Current.is(tok::semi)) {
   // Reset FirstStartOfName after finding a semicolon so that a for loop
   // with multiple increment statements is not confused with a for loop
@@ -3258,7 +3262,7 @@ static bool isFunctionDeclarationName(bool IsCpp, const 
FormatToken &Current,
   if (Current.is(TT_FunctionDeclarationName))
 return true;
 
-  if (!Current.Tok.getIdentifierInfo())
+  if (!Current.Tok.getIdentifierInfo() || Current.is(TT_CtorDtorDeclName))
 return false;
 
   auto skipOperatorName = [](const FormatToken *Next) -> const FormatToken * {
@@ -3441,19 +3445,19 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedL

[clang] [clang-format] Handle variable declarations in BreakAfterAttributes (PR #71755)

2023-11-09 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/71755
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a0710e1 - Revert "[clang-format] Handle variable declarations in BreakAfterAttributes (#71755)"

2023-11-09 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-11-09T23:34:06-08:00
New Revision: a0710e162dac8eb845588779deb39f2b35e5cb88

URL: 
https://github.com/llvm/llvm-project/commit/a0710e162dac8eb845588779deb39f2b35e5cb88
DIFF: 
https://github.com/llvm/llvm-project/commit/a0710e162dac8eb845588779deb39f2b35e5cb88.diff

LOG: Revert "[clang-format] Handle variable declarations in 
BreakAfterAttributes (#71755)"

This reverts commit 5c36f4332d93c6f9bd9b01a34149a635e07a00d3 which caused a
formatting error in polly.

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index d496fc85f7ae71a..21342e1b89ea866 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2049,8 +2049,8 @@ the configuration (without a prefix: ``Auto``).
 .. _BreakAfterAttributes:
 
 **BreakAfterAttributes** (``AttributeBreakingStyle``) 
:versionbadge:`clang-format 16` :ref:`¶ `
-  Break after a group of C++11 attributes before a variable/function
-  (including constructor/destructor) declaration/definition name.
+  Break after a group of C++11 attributes before a function
+  declaration/definition name.
 
   Possible values:
 
@@ -2059,10 +2059,6 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
-  [[maybe_unused]]
-  const int i;
-  [[gnu::const]] [[maybe_unused]]
-  int j;
   [[nodiscard]]
   inline int f();
   [[gnu::const]] [[nodiscard]]
@@ -2073,9 +2069,6 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
-  [[maybe_unused]] const int i;
-  [[gnu::const]] [[maybe_unused]]
-  int j;
   [[nodiscard]] inline int f();
   [[gnu::const]] [[nodiscard]]
   int g();
@@ -2085,8 +2078,6 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
-  [[maybe_unused]] const int i;
-  [[gnu::const]] [[maybe_unused]] int j;
   [[nodiscard]] inline int f();
   [[gnu::const]] [[nodiscard]] int g();
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 9442344000e142b..3e9d1915badd87f 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1428,10 +1428,6 @@ struct FormatStyle {
   enum AttributeBreakingStyle : int8_t {
 /// Always break after attributes.
 /// \code
-///   [[maybe_unused]]
-///   const int i;
-///   [[gnu::const]] [[maybe_unused]]
-///   int j;
 ///   [[nodiscard]]
 ///   inline int f();
 ///   [[gnu::const]] [[nodiscard]]
@@ -1440,9 +1436,6 @@ struct FormatStyle {
 ABS_Always,
 /// Leave the line breaking after attributes as is.
 /// \code
-///   [[maybe_unused]] const int i;
-///   [[gnu::const]] [[maybe_unused]]
-///   int j;
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]]
 ///   int g();
@@ -1450,16 +1443,14 @@ struct FormatStyle {
 ABS_Leave,
 /// Never break after attributes.
 /// \code
-///   [[maybe_unused]] const int i;
-///   [[gnu::const]] [[maybe_unused]] int j;
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]] int g();
 /// \endcode
 ABS_Never,
   };
 
-  /// Break after a group of C++11 attributes before a variable/function
-  /// (including constructor/destructor) declaration/definition name.
+  /// Break after a group of C++11 attributes before a function
+  /// declaration/definition name.
   /// \version 16
   AttributeBreakingStyle BreakAfterAttributes;
 

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index e06b4d5a3b05eef..729e7e370bf62ea 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2000,10 +2000,6 @@ class AnnotatingParser {
(!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
   Contexts.back().FirstStartOfName = &Current;
   Current.setType(TT_StartOfName);
-  if (auto *PrevNonComment = Current.getPreviousNonComment();
-  PrevNonComment && PrevNonComment->is(TT_StartOfName)) {
-PrevNonComment->setType(TT_Unknown);
-  }
 } else if (Current.is(tok::semi)) {
   // Reset FirstStartOfName after finding a semicolon so that a for loop
   // with multiple increment statements is not confused with a for loop
@@ -3262,7 +3258,7 @@ static bool isFunctionDeclarationName(bool IsCpp, const 
FormatToken &Current,
   if (Current.is(TT_FunctionDeclarationName))
 return true;
 
-  if (!Current.Tok.getIdentifierInfo() || Current.is(TT_CtorDtorDeclName))
+  if (!Current.Tok.getIdentifierInfo())
 return false;
 
   auto skipOperatorName = [](cons

[clang] cc75e52 - [clang-format][NFC] Refactor isPointerOrReference

2023-11-10 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-11-10T01:23:05-08:00
New Revision: cc75e520162ef651977d3f6d11b0d0b92dd2be07

URL: 
https://github.com/llvm/llvm-project/commit/cc75e520162ef651977d3f6d11b0d0b92dd2be07
DIFF: 
https://github.com/llvm/llvm-project/commit/cc75e520162ef651977d3f6d11b0d0b92dd2be07.diff

LOG: [clang-format][NFC] Refactor isPointerOrReference

Added: 


Modified: 
clang/lib/Format/FormatToken.h
clang/lib/Format/QualifierAlignmentFixer.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/WhitespaceManager.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 87f6a76ec5bfd39..14a3c21ba44eaee 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -692,6 +692,10 @@ struct FormatToken {
 TT_LeadingJavaAnnotation);
   }
 
+  bool isPointerOrReference() const {
+return isOneOf(tok::star, tok::amp, tok::ampamp);
+  }
+
   bool isUnaryOperator() const {
 switch (Tok.getKind()) {
 case tok::plus:

diff  --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 77586532c851ff2..7167e50ec724eab 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -380,7 +380,7 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeLeft(
 
   // For left qualifiers preceeded by nothing, a template declaration, or 
*,&,&&
   // we only perform sorting.
-  if (!TypeToken || TypeToken->isOneOf(tok::star, tok::amp, tok::ampamp) ||
+  if (!TypeToken || TypeToken->isPointerOrReference() ||
   TypeToken->ClosesRequiresClause || TypeToken->ClosesTemplateDeclaration) 
{
 
 // Don't sort past a non-configured qualifier token.

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 729e7e370bf62ea..d648e441f23fe9e 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -405,7 +405,7 @@ class AnnotatingParser {
 // void (^ObjCBlock)(void);
 bool MightBeFunctionType = !Contexts[Contexts.size() - 2].IsExpression;
 bool ProbablyFunctionType =
-CurrentToken->isOneOf(tok::star, tok::amp, tok::ampamp, tok::caret);
+CurrentToken->isPointerOrReference() || CurrentToken->is(tok::caret);
 bool HasMultipleLines = false;
 bool HasMultipleParametersOnALine = false;
 bool MightBeObjCForRangeLoop =
@@ -422,8 +422,7 @@ class AnnotatingParser {
   FormatToken *PrevPrev = Prev->getPreviousNonComment();
   FormatToken *Next = CurrentToken->Next;
   if (PrevPrev && PrevPrev->is(tok::identifier) &&
-  PrevPrev->isNot(TT_TypeName) &&
-  Prev->isOneOf(tok::star, tok::amp, tok::ampamp) &&
+  PrevPrev->isNot(TT_TypeName) && Prev->isPointerOrReference() &&
   CurrentToken->is(tok::identifier) && Next->isNot(tok::equal)) {
 Prev->setType(TT_BinaryOperator);
 LookForDecls = false;
@@ -460,10 +459,8 @@ class AnnotatingParser {
   //   auto my_lambda = MACRO((Type *type, int i) { .. body .. });
   for (FormatToken *Tok = &OpeningParen; Tok != CurrentToken;
Tok = Tok->Next) {
-if (Tok->is(TT_BinaryOperator) &&
-Tok->isOneOf(tok::star, tok::amp, tok::ampamp)) {
+if (Tok->is(TT_BinaryOperator) && Tok->isPointerOrReference())
   Tok->setType(TT_PointerOrReference);
-}
   }
 }
 
@@ -1861,8 +1858,8 @@ class AnnotatingParser {
   if (Previous->opensScope())
 break;
   if (Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator) &&
-  Previous->isOneOf(tok::star, tok::amp, tok::ampamp) &&
-  Previous->Previous && Previous->Previous->isNot(tok::equal)) {
+  Previous->isPointerOrReference() && Previous->Previous &&
+  Previous->Previous->isNot(tok::equal)) {
 Previous->setType(TT_PointerOrReference);
   }
 }
@@ -2023,7 +2020,7 @@ class AnnotatingParser {
 } else if (isDeductionGuide(Current)) {
   // Deduction guides trailing arrow " A(...) -> A;".
   Current.setType(TT_TrailingReturnArrow);
-} else if (Current.isOneOf(tok::star, tok::amp, tok::ampamp)) {
+} else if (Current.isPointerOrReference()) {
   Current.setType(determineStarAmpUsage(
   Current,
   Contexts.back().CanBeExpression && Contexts.back().IsExpression,
@@ -3281,7 +3278,7 @@ static bool isFunctionDeclarationName(bool IsCpp, const 
FormatToken &Current,
 continue;
   }
   if ((Next->isSimpleTypeSpecifier() || Next->is(tok::identifier)) &&
-  Next->Next && Next->Next->isOneOf(tok::star, tok::amp, tok::ampamp)) 
{
+  Next->Next && Next->Next->isPointerOrReference()) {
 // For operato

[clang] f7bbb58 - Reland "[clang-format] Handle variable declarations in BreakAfterAttributes (#71755)"

2023-11-10 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-11-10T01:53:43-08:00
New Revision: f7bbb58690910a8320b0927525dfba19df69a910

URL: 
https://github.com/llvm/llvm-project/commit/f7bbb58690910a8320b0927525dfba19df69a910
DIFF: 
https://github.com/llvm/llvm-project/commit/f7bbb58690910a8320b0927525dfba19df69a910.diff

LOG: Reland "[clang-format] Handle variable declarations in 
BreakAfterAttributes (#71755)"

Also fixed another bug in isStartOfName().

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 21342e1b89ea866..d496fc85f7ae71a 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2049,8 +2049,8 @@ the configuration (without a prefix: ``Auto``).
 .. _BreakAfterAttributes:
 
 **BreakAfterAttributes** (``AttributeBreakingStyle``) 
:versionbadge:`clang-format 16` :ref:`¶ `
-  Break after a group of C++11 attributes before a function
-  declaration/definition name.
+  Break after a group of C++11 attributes before a variable/function
+  (including constructor/destructor) declaration/definition name.
 
   Possible values:
 
@@ -2059,6 +2059,10 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
+  [[maybe_unused]]
+  const int i;
+  [[gnu::const]] [[maybe_unused]]
+  int j;
   [[nodiscard]]
   inline int f();
   [[gnu::const]] [[nodiscard]]
@@ -2069,6 +2073,9 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
+  [[maybe_unused]] const int i;
+  [[gnu::const]] [[maybe_unused]]
+  int j;
   [[nodiscard]] inline int f();
   [[gnu::const]] [[nodiscard]]
   int g();
@@ -2078,6 +2085,8 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
+  [[maybe_unused]] const int i;
+  [[gnu::const]] [[maybe_unused]] int j;
   [[nodiscard]] inline int f();
   [[gnu::const]] [[nodiscard]] int g();
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 3e9d1915badd87f..9442344000e142b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1428,6 +1428,10 @@ struct FormatStyle {
   enum AttributeBreakingStyle : int8_t {
 /// Always break after attributes.
 /// \code
+///   [[maybe_unused]]
+///   const int i;
+///   [[gnu::const]] [[maybe_unused]]
+///   int j;
 ///   [[nodiscard]]
 ///   inline int f();
 ///   [[gnu::const]] [[nodiscard]]
@@ -1436,6 +1440,9 @@ struct FormatStyle {
 ABS_Always,
 /// Leave the line breaking after attributes as is.
 /// \code
+///   [[maybe_unused]] const int i;
+///   [[gnu::const]] [[maybe_unused]]
+///   int j;
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]]
 ///   int g();
@@ -1443,14 +1450,16 @@ struct FormatStyle {
 ABS_Leave,
 /// Never break after attributes.
 /// \code
+///   [[maybe_unused]] const int i;
+///   [[gnu::const]] [[maybe_unused]] int j;
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]] int g();
 /// \endcode
 ABS_Never,
   };
 
-  /// Break after a group of C++11 attributes before a function
-  /// declaration/definition name.
+  /// Break after a group of C++11 attributes before a variable/function
+  /// (including constructor/destructor) declaration/definition name.
   /// \version 16
   AttributeBreakingStyle BreakAfterAttributes;
 

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d648e441f23fe9e..9499b3f31623c4f 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1997,6 +1997,10 @@ class AnnotatingParser {
(!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
   Contexts.back().FirstStartOfName = &Current;
   Current.setType(TT_StartOfName);
+  if (auto *PrevNonComment = Current.getPreviousNonComment();
+  PrevNonComment && PrevNonComment->is(TT_StartOfName)) {
+PrevNonComment->setType(TT_Unknown);
+  }
 } else if (Current.is(tok::semi)) {
   // Reset FirstStartOfName after finding a semicolon so that a for loop
   // with multiple increment statements is not confused with a for loop
@@ -2181,8 +2185,10 @@ class AnnotatingParser {
 if (Style.isVerilog())
   return false;
 
-if (Tok.isNot(tok::identifier) || !Tok.Previous)
+if (Tok.isNot(tok::identifier) || !Tok.Previous || !Tok.Next ||
+Tok.Next->isPointerOrReference()) {
   return false;
+}
 
 if (Tok.Previous->isOneOf(TT_LeadingJavaAnnotation, Keywords.kw_instanceof,
  

[clang] 86ef9d3 - Revert "[clang-format] Handle variable declarations in BreakAfterAttributes (#71755)"

2023-11-10 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-11-10T02:03:35-08:00
New Revision: 86ef9d36519f72c06741335ce0a445ab73eb4cfb

URL: 
https://github.com/llvm/llvm-project/commit/86ef9d36519f72c06741335ce0a445ab73eb4cfb
DIFF: 
https://github.com/llvm/llvm-project/commit/86ef9d36519f72c06741335ce0a445ab73eb4cfb.diff

LOG: Revert "[clang-format] Handle variable declarations in 
BreakAfterAttributes (#71755)"

This reverts commit f7bbb58690910a8320b0927525dfba19df69a910 which caused
another formatting failure in polly.

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index d496fc85f7ae71a..21342e1b89ea866 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2049,8 +2049,8 @@ the configuration (without a prefix: ``Auto``).
 .. _BreakAfterAttributes:
 
 **BreakAfterAttributes** (``AttributeBreakingStyle``) 
:versionbadge:`clang-format 16` :ref:`¶ `
-  Break after a group of C++11 attributes before a variable/function
-  (including constructor/destructor) declaration/definition name.
+  Break after a group of C++11 attributes before a function
+  declaration/definition name.
 
   Possible values:
 
@@ -2059,10 +2059,6 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
-  [[maybe_unused]]
-  const int i;
-  [[gnu::const]] [[maybe_unused]]
-  int j;
   [[nodiscard]]
   inline int f();
   [[gnu::const]] [[nodiscard]]
@@ -2073,9 +2069,6 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
-  [[maybe_unused]] const int i;
-  [[gnu::const]] [[maybe_unused]]
-  int j;
   [[nodiscard]] inline int f();
   [[gnu::const]] [[nodiscard]]
   int g();
@@ -2085,8 +2078,6 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
-  [[maybe_unused]] const int i;
-  [[gnu::const]] [[maybe_unused]] int j;
   [[nodiscard]] inline int f();
   [[gnu::const]] [[nodiscard]] int g();
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 9442344000e142b..3e9d1915badd87f 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1428,10 +1428,6 @@ struct FormatStyle {
   enum AttributeBreakingStyle : int8_t {
 /// Always break after attributes.
 /// \code
-///   [[maybe_unused]]
-///   const int i;
-///   [[gnu::const]] [[maybe_unused]]
-///   int j;
 ///   [[nodiscard]]
 ///   inline int f();
 ///   [[gnu::const]] [[nodiscard]]
@@ -1440,9 +1436,6 @@ struct FormatStyle {
 ABS_Always,
 /// Leave the line breaking after attributes as is.
 /// \code
-///   [[maybe_unused]] const int i;
-///   [[gnu::const]] [[maybe_unused]]
-///   int j;
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]]
 ///   int g();
@@ -1450,16 +1443,14 @@ struct FormatStyle {
 ABS_Leave,
 /// Never break after attributes.
 /// \code
-///   [[maybe_unused]] const int i;
-///   [[gnu::const]] [[maybe_unused]] int j;
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]] int g();
 /// \endcode
 ABS_Never,
   };
 
-  /// Break after a group of C++11 attributes before a variable/function
-  /// (including constructor/destructor) declaration/definition name.
+  /// Break after a group of C++11 attributes before a function
+  /// declaration/definition name.
   /// \version 16
   AttributeBreakingStyle BreakAfterAttributes;
 

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 9499b3f31623c4f..d648e441f23fe9e 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1997,10 +1997,6 @@ class AnnotatingParser {
(!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
   Contexts.back().FirstStartOfName = &Current;
   Current.setType(TT_StartOfName);
-  if (auto *PrevNonComment = Current.getPreviousNonComment();
-  PrevNonComment && PrevNonComment->is(TT_StartOfName)) {
-PrevNonComment->setType(TT_Unknown);
-  }
 } else if (Current.is(tok::semi)) {
   // Reset FirstStartOfName after finding a semicolon so that a for loop
   // with multiple increment statements is not confused with a for loop
@@ -2185,10 +2181,8 @@ class AnnotatingParser {
 if (Style.isVerilog())
   return false;
 
-if (Tok.isNot(tok::identifier) || !Tok.Previous || !Tok.Next ||
-Tok.Next->isPointerOrReference()) {
+if (Tok.isNot(tok::identifier) || !Tok.Previous)
   return false;
-}
 
 if (Tok.Previous->isOneOf(TT_L

[clang] [clang-format] Handle variable declarations in BreakAfterAttributes (PR #71755)

2023-11-10 Thread Owen Pan via cfe-commits

owenca wrote:

@Meinersbur thanks for the info!

https://github.com/llvm/llvm-project/pull/71755
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [llvm] [clang-format] Handle variable declarations in BreakAfterAttributes (PR #71935)

2023-11-10 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/71935

Also fixed a bug in `isStartOfName()` and cleaned up some old test cases.

Fixed #71563.

This is a rework of #71755.

>From 17921d5a1d74017128691428815ede53ac1a4d67 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 8 Nov 2023 17:55:56 -0800
Subject: [PATCH 1/3] [clang-format] Handle variable declarations in
 BreakAfterAttributes

Also cleaned up some old test cases.

Fixes #71563.
---
 clang/docs/ClangFormatStyleOptions.rst | 13 +++--
 clang/include/clang/Format/Format.h| 13 +++--
 clang/lib/Format/TokenAnnotator.cpp| 22 +--
 clang/unittests/Format/FormatTest.cpp  | 38 ++
 4 files changed, 62 insertions(+), 24 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 21342e1b89ea866..d496fc85f7ae71a 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2049,8 +2049,8 @@ the configuration (without a prefix: ``Auto``).
 .. _BreakAfterAttributes:
 
 **BreakAfterAttributes** (``AttributeBreakingStyle``) 
:versionbadge:`clang-format 16` :ref:`¶ `
-  Break after a group of C++11 attributes before a function
-  declaration/definition name.
+  Break after a group of C++11 attributes before a variable/function
+  (including constructor/destructor) declaration/definition name.
 
   Possible values:
 
@@ -2059,6 +2059,10 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
+  [[maybe_unused]]
+  const int i;
+  [[gnu::const]] [[maybe_unused]]
+  int j;
   [[nodiscard]]
   inline int f();
   [[gnu::const]] [[nodiscard]]
@@ -2069,6 +2073,9 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
+  [[maybe_unused]] const int i;
+  [[gnu::const]] [[maybe_unused]]
+  int j;
   [[nodiscard]] inline int f();
   [[gnu::const]] [[nodiscard]]
   int g();
@@ -2078,6 +2085,8 @@ the configuration (without a prefix: ``Auto``).
 
 .. code-block:: c++
 
+  [[maybe_unused]] const int i;
+  [[gnu::const]] [[maybe_unused]] int j;
   [[nodiscard]] inline int f();
   [[gnu::const]] [[nodiscard]] int g();
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 3e9d1915badd87f..9442344000e142b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1428,6 +1428,10 @@ struct FormatStyle {
   enum AttributeBreakingStyle : int8_t {
 /// Always break after attributes.
 /// \code
+///   [[maybe_unused]]
+///   const int i;
+///   [[gnu::const]] [[maybe_unused]]
+///   int j;
 ///   [[nodiscard]]
 ///   inline int f();
 ///   [[gnu::const]] [[nodiscard]]
@@ -1436,6 +1440,9 @@ struct FormatStyle {
 ABS_Always,
 /// Leave the line breaking after attributes as is.
 /// \code
+///   [[maybe_unused]] const int i;
+///   [[gnu::const]] [[maybe_unused]]
+///   int j;
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]]
 ///   int g();
@@ -1443,14 +1450,16 @@ struct FormatStyle {
 ABS_Leave,
 /// Never break after attributes.
 /// \code
+///   [[maybe_unused]] const int i;
+///   [[gnu::const]] [[maybe_unused]] int j;
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]] int g();
 /// \endcode
 ABS_Never,
   };
 
-  /// Break after a group of C++11 attributes before a function
-  /// declaration/definition name.
+  /// Break after a group of C++11 attributes before a variable/function
+  /// (including constructor/destructor) declaration/definition name.
   /// \version 16
   AttributeBreakingStyle BreakAfterAttributes;
 
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 729e7e370bf62ea..12f2e2ded19a01c 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2000,6 +2000,10 @@ class AnnotatingParser {
(!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
   Contexts.back().FirstStartOfName = &Current;
   Current.setType(TT_StartOfName);
+  if (auto *PrevNonComment = Current.getPreviousNonComment();
+  PrevNonComment && PrevNonComment->is(TT_StartOfName)) {
+PrevNonComment->setType(TT_Unknown);
+  }
 } else if (Current.is(tok::semi)) {
   // Reset FirstStartOfName after finding a semicolon so that a for loop
   // with multiple increment statements is not confused with a for loop
@@ -3258,7 +3262,7 @@ static bool isFunctionDeclarationName(bool IsCpp, const 
FormatToken &Current,
   if (Current.is(TT_FunctionDeclarationName))
 return true;
 
-  if (!Current.Tok.getIdentifierInfo())
+  if (!Current.Tok.getIdentifierInfo() || Current.is(TT_CtorDtorDeclName))
 return false;
 
   auto skipOperatorName = [](const FormatToken 

[llvm] [clang-tools-extra] [clang] [clang-format] Handle variable declarations in BreakAfterAttributes (PR #71935)

2023-11-10 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/71935
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle control statements in BreakAfterAttributes (PR #71995)

2023-11-10 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/71995

This patch doesn't work for do-while loops.

Fixed #64474.

>From b67ea36d180e700cc6b0661e8f2390eda515c566 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 10 Nov 2023 00:21:58 -0800
Subject: [PATCH] [clang-format] Handle control statements in
 BreakAfterAttributes

This patch doesn't work for do-while loops.

Fixed #64474.
---
 clang/docs/ClangFormatStyleOptions.rst | 52 -
 clang/include/clang/Format/Format.h| 52 -
 clang/lib/Format/TokenAnnotator.cpp| 33 -
 clang/unittests/Format/FormatTest.cpp  | 64 ++
 4 files changed, 185 insertions(+), 16 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index d496fc85f7ae71a..2e9297879684aa5 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2049,8 +2049,10 @@ the configuration (without a prefix: ``Auto``).
 .. _BreakAfterAttributes:
 
 **BreakAfterAttributes** (``AttributeBreakingStyle``) 
:versionbadge:`clang-format 16` :ref:`¶ `
-  Break after a group of C++11 attributes before a variable/function
-  (including constructor/destructor) declaration/definition name.
+  Break after a group of C++11 attributes before variable or function
+  (including constructor/destructor) declaration/definition names or before
+  control statements, i.e. ``if``, ``switch`` (including ``case`` and
+  ``default``labels), ``for``, and ``while`` statements.
 
   Possible values:
 
@@ -2063,11 +2065,28 @@ the configuration (without a prefix: ``Auto``).
   const int i;
   [[gnu::const]] [[maybe_unused]]
   int j;
+
   [[nodiscard]]
   inline int f();
   [[gnu::const]] [[nodiscard]]
   int g();
 
+  [[likely]]
+  if (a)
+f();
+  else
+g();
+
+  switch (b) {
+  [[unlikely]]
+  case 1:
+++b;
+break;
+  [[likely]]
+  default:
+return;
+  }
+
   * ``ABS_Leave`` (in configuration: ``Leave``)
 Leave the line breaking after attributes as is.
 
@@ -2076,10 +2095,25 @@ the configuration (without a prefix: ``Auto``).
   [[maybe_unused]] const int i;
   [[gnu::const]] [[maybe_unused]]
   int j;
+
   [[nodiscard]] inline int f();
   [[gnu::const]] [[nodiscard]]
   int g();
 
+  [[likely]] if (a)
+f();
+  else
+g();
+
+  switch (b) {
+  [[unlikely]] case 1:
+++b;
+break;
+  [[likely]]
+  default:
+return;
+  }
+
   * ``ABS_Never`` (in configuration: ``Never``)
 Never break after attributes.
 
@@ -2087,9 +2121,23 @@ the configuration (without a prefix: ``Auto``).
 
   [[maybe_unused]] const int i;
   [[gnu::const]] [[maybe_unused]] int j;
+
   [[nodiscard]] inline int f();
   [[gnu::const]] [[nodiscard]] int g();
 
+  [[likely]] if (a)
+f();
+  else
+g();
+
+  switch (b) {
+  [[unlikely]] case 1:
+++b;
+break;
+  [[likely]] default:
+return;
+  }
+
 
 
 .. _BreakAfterJavaFieldAnnotations:
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 9442344000e142b..55ba46d45c142ab 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1432,10 +1432,27 @@ struct FormatStyle {
 ///   const int i;
 ///   [[gnu::const]] [[maybe_unused]]
 ///   int j;
+///
 ///   [[nodiscard]]
 ///   inline int f();
 ///   [[gnu::const]] [[nodiscard]]
 ///   int g();
+///
+///   [[likely]]
+///   if (a)
+/// f();
+///   else
+/// g();
+///
+///   switch (b) {
+///   [[unlikely]]
+///   case 1:
+/// ++b;
+/// break;
+///   [[likely]]
+///   default:
+/// return;
+///   }
 /// \endcode
 ABS_Always,
 /// Leave the line breaking after attributes as is.
@@ -1443,23 +1460,54 @@ struct FormatStyle {
 ///   [[maybe_unused]] const int i;
 ///   [[gnu::const]] [[maybe_unused]]
 ///   int j;
+///
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]]
 ///   int g();
+///
+///   [[likely]] if (a)
+/// f();
+///   else
+/// g();
+///
+///   switch (b) {
+///   [[unlikely]] case 1:
+/// ++b;
+/// break;
+///   [[likely]]
+///   default:
+/// return;
+///   }
 /// \endcode
 ABS_Leave,
 /// Never break after attributes.
 /// \code
 ///   [[maybe_unused]] const int i;
 ///   [[gnu::const]] [[maybe_unused]] int j;
+///
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]] int g();
+///
+///   [[likely]] if (a)
+/// f();
+///   else
+/// g();
+///
+///   switch (b) {
+///   [[unl

[clang] [clang-format][NFC] Simplify parseBracedList() (PR #72010)

2023-11-10 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/72010

None

>From f3f303d80a40b9ce8a13721cfa108b4094b8b2c3 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 10 Nov 2023 17:34:06 -0800
Subject: [PATCH] [clang-format][NFC] Simplify parseBracedList()

---
 clang/lib/Format/UnwrappedLineParser.cpp | 36 +---
 clang/lib/Format/UnwrappedLineParser.h   |  3 +-
 2 files changed, 15 insertions(+), 24 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 018bc6c165485e2..e6a333fdc4e42ce 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2017,8 +2017,7 @@ void UnwrappedLineParser::parseStructuralElement(
   } else if (Style.Language == FormatStyle::LK_Proto &&
  FormatTok->is(tok::less)) {
 nextToken();
-parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
-/*ClosingBraceKind=*/tok::greater);
+parseBracedList();
   }
   break;
 case tok::l_square:
@@ -2379,9 +2378,10 @@ bool UnwrappedLineParser::tryToParseChildBlock() {
   return true;
 }
 
-bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons,
-  bool IsEnum,
-  tok::TokenKind ClosingBraceKind) {
+bool UnwrappedLineParser::parseBracedList(bool IsEnum) {
+  const auto *OpeningBrace = FormatTok->getPreviousNonComment();
+  const bool IsAngleBracket = OpeningBrace && OpeningBrace->is(tok::less);
+
   bool HasError = false;
 
   // FIXME: Once we have an expression parser in the UnwrappedLineParser,
@@ -2403,7 +2403,7 @@ bool UnwrappedLineParser::parseBracedList(bool 
ContinueOnSemicolons,
 parseChildBlock();
   }
 }
-if (FormatTok->Tok.getKind() == ClosingBraceKind) {
+if (FormatTok->is(IsAngleBracket ? tok::greater : tok::r_brace)) {
   if (IsEnum && !Style.AllowShortEnumsOnASingleLine)
 addUnwrappedLine();
   nextToken();
@@ -2434,14 +2434,9 @@ bool UnwrappedLineParser::parseBracedList(bool 
ContinueOnSemicolons,
   parseBracedList();
   break;
 case tok::less:
-  if (Style.Language == FormatStyle::LK_Proto ||
-  ClosingBraceKind == tok::greater) {
-nextToken();
-parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
-/*ClosingBraceKind=*/tok::greater);
-  } else {
-nextToken();
-  }
+  nextToken();
+  if (IsAngleBracket)
+parseBracedList();
   break;
 case tok::semi:
   // JavaScript (or more precisely TypeScript) can have semicolons in 
braced
@@ -2453,8 +2448,8 @@ bool UnwrappedLineParser::parseBracedList(bool 
ContinueOnSemicolons,
 break;
   }
   HasError = true;
-  if (!ContinueOnSemicolons)
-return !HasError;
+  if (!IsEnum)
+return false;
   nextToken();
   break;
 case tok::comma:
@@ -3618,8 +3613,7 @@ void UnwrappedLineParser::parseConstraintExpression() {
 return;
 
   nextToken();
-  parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
-  /*ClosingBraceKind=*/tok::greater);
+  parseBracedList();
   break;
 
 default:
@@ -3650,8 +3644,7 @@ void UnwrappedLineParser::parseConstraintExpression() {
   nextToken();
   if (FormatTok->is(tok::less)) {
 nextToken();
-parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
-/*ClosingBraceKind=*/tok::greater);
+parseBracedList();
   }
   TopLevelParensAllowed = false;
   break;
@@ -3732,8 +3725,7 @@ bool UnwrappedLineParser::parseEnum() {
 addUnwrappedLine();
 Line->Level += 1;
   }
-  bool HasError = !parseBracedList(/*ContinueOnSemicolons=*/true,
-   /*IsEnum=*/true);
+  bool HasError = !parseBracedList(/*IsEnum=*/true);
   if (!Style.AllowShortEnumsOnASingleLine)
 Line->Level -= 1;
   if (HasError) {
diff --git a/clang/lib/Format/UnwrappedLineParser.h 
b/clang/lib/Format/UnwrappedLineParser.h
index c31f25fdd8f83c9..61ec04578955ce6 100644
--- a/clang/lib/Format/UnwrappedLineParser.h
+++ b/clang/lib/Format/UnwrappedLineParser.h
@@ -151,8 +151,7 @@ class UnwrappedLineParser {
   bool *HasDoWhile = nullptr,
   bool *HasLabel = nullptr);
   bool tryToParseBracedList();
-  bool parseBracedList(bool ContinueOnSemicolons = false, bool IsEnum = false,
-   tok::TokenKind ClosingBraceKind = tok::r_brace);
+  bool parseBracedList(bool IsEnum = false);
   bool parseParens(TokenType AmpAmpTokenType = TT_Unknown);
   void parseSquare(bool LambdaIntroducer = false);
   void keepAncestorBraces();

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org

[clang] [clang-format] Handle control statements in BreakAfterAttributes (PR #71995)

2023-11-11 Thread Owen Pan via cfe-commits


@@ -1432,34 +1432,82 @@ struct FormatStyle {
 ///   const int i;
 ///   [[gnu::const]] [[maybe_unused]]
 ///   int j;
+///
 ///   [[nodiscard]]
 ///   inline int f();
 ///   [[gnu::const]] [[nodiscard]]
 ///   int g();
+///
+///   [[likely]]
+///   if (a)
+/// f();
+///   else
+/// g();
+///
+///   switch (b) {
+///   [[unlikely]]
+///   case 1:
+/// ++b;
+/// break;
+///   [[likely]]
+///   default:
+/// return;
+///   }
 /// \endcode
 ABS_Always,
 /// Leave the line breaking after attributes as is.
 /// \code
 ///   [[maybe_unused]] const int i;
 ///   [[gnu::const]] [[maybe_unused]]
 ///   int j;
+///
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]]
 ///   int g();
+///
+///   [[likely]] if (a)
+/// f();
+///   else
+/// g();
+///
+///   switch (b) {
+///   [[unlikely]] case 1:
+/// ++b;
+/// break;
+///   [[likely]]
+///   default:
+/// return;
+///   }
 /// \endcode
 ABS_Leave,
 /// Never break after attributes.
 /// \code
 ///   [[maybe_unused]] const int i;
 ///   [[gnu::const]] [[maybe_unused]] int j;
+///
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]] int g();
+///
+///   [[likely]] if (a)
+/// f();
+///   else
+/// g();
+///
+///   switch (b) {
+///   [[unlikely]] case 1:
+/// ++b;
+/// break;
+///   [[likely]] default:
+/// return;
+///   }
 /// \endcode
 ABS_Never,
   };
 
-  /// Break after a group of C++11 attributes before a variable/function
-  /// (including constructor/destructor) declaration/definition name.
+  /// Break after a group of C++11 attributes before variable or function
+  /// (including constructor/destructor) declaration/definition names or before
+  /// control statements, i.e. ``if``, ``switch`` (including ``case`` and
+  /// ``default``labels), ``for``, and ``while`` statements.

owenca wrote:

```suggestion
  /// ``default`` labels), ``for``, and ``while`` statements.
```

https://github.com/llvm/llvm-project/pull/71995
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle control statements in BreakAfterAttributes (PR #71995)

2023-11-11 Thread Owen Pan via cfe-commits


@@ -2049,8 +2049,10 @@ the configuration (without a prefix: ``Auto``).
 .. _BreakAfterAttributes:
 
 **BreakAfterAttributes** (``AttributeBreakingStyle``) 
:versionbadge:`clang-format 16` :ref:`¶ `
-  Break after a group of C++11 attributes before a variable/function
-  (including constructor/destructor) declaration/definition name.
+  Break after a group of C++11 attributes before variable or function
+  (including constructor/destructor) declaration/definition names or before
+  control statements, i.e. ``if``, ``switch`` (including ``case`` and
+  ``default``labels), ``for``, and ``while`` statements.

owenca wrote:

```suggestion
  ``default`` labels), ``for``, and ``while`` statements.
```

https://github.com/llvm/llvm-project/pull/71995
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle control statements in BreakAfterAttributes (PR #71995)

2023-11-11 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/71995

>From b67ea36d180e700cc6b0661e8f2390eda515c566 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 10 Nov 2023 00:21:58 -0800
Subject: [PATCH 1/2] [clang-format] Handle control statements in
 BreakAfterAttributes

This patch doesn't work for do-while loops.

Fixed #64474.
---
 clang/docs/ClangFormatStyleOptions.rst | 52 -
 clang/include/clang/Format/Format.h| 52 -
 clang/lib/Format/TokenAnnotator.cpp| 33 -
 clang/unittests/Format/FormatTest.cpp  | 64 ++
 4 files changed, 185 insertions(+), 16 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index d496fc85f7ae71a..2e9297879684aa5 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2049,8 +2049,10 @@ the configuration (without a prefix: ``Auto``).
 .. _BreakAfterAttributes:
 
 **BreakAfterAttributes** (``AttributeBreakingStyle``) 
:versionbadge:`clang-format 16` :ref:`¶ `
-  Break after a group of C++11 attributes before a variable/function
-  (including constructor/destructor) declaration/definition name.
+  Break after a group of C++11 attributes before variable or function
+  (including constructor/destructor) declaration/definition names or before
+  control statements, i.e. ``if``, ``switch`` (including ``case`` and
+  ``default``labels), ``for``, and ``while`` statements.
 
   Possible values:
 
@@ -2063,11 +2065,28 @@ the configuration (without a prefix: ``Auto``).
   const int i;
   [[gnu::const]] [[maybe_unused]]
   int j;
+
   [[nodiscard]]
   inline int f();
   [[gnu::const]] [[nodiscard]]
   int g();
 
+  [[likely]]
+  if (a)
+f();
+  else
+g();
+
+  switch (b) {
+  [[unlikely]]
+  case 1:
+++b;
+break;
+  [[likely]]
+  default:
+return;
+  }
+
   * ``ABS_Leave`` (in configuration: ``Leave``)
 Leave the line breaking after attributes as is.
 
@@ -2076,10 +2095,25 @@ the configuration (without a prefix: ``Auto``).
   [[maybe_unused]] const int i;
   [[gnu::const]] [[maybe_unused]]
   int j;
+
   [[nodiscard]] inline int f();
   [[gnu::const]] [[nodiscard]]
   int g();
 
+  [[likely]] if (a)
+f();
+  else
+g();
+
+  switch (b) {
+  [[unlikely]] case 1:
+++b;
+break;
+  [[likely]]
+  default:
+return;
+  }
+
   * ``ABS_Never`` (in configuration: ``Never``)
 Never break after attributes.
 
@@ -2087,9 +2121,23 @@ the configuration (without a prefix: ``Auto``).
 
   [[maybe_unused]] const int i;
   [[gnu::const]] [[maybe_unused]] int j;
+
   [[nodiscard]] inline int f();
   [[gnu::const]] [[nodiscard]] int g();
 
+  [[likely]] if (a)
+f();
+  else
+g();
+
+  switch (b) {
+  [[unlikely]] case 1:
+++b;
+break;
+  [[likely]] default:
+return;
+  }
+
 
 
 .. _BreakAfterJavaFieldAnnotations:
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 9442344000e142b..55ba46d45c142ab 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1432,10 +1432,27 @@ struct FormatStyle {
 ///   const int i;
 ///   [[gnu::const]] [[maybe_unused]]
 ///   int j;
+///
 ///   [[nodiscard]]
 ///   inline int f();
 ///   [[gnu::const]] [[nodiscard]]
 ///   int g();
+///
+///   [[likely]]
+///   if (a)
+/// f();
+///   else
+/// g();
+///
+///   switch (b) {
+///   [[unlikely]]
+///   case 1:
+/// ++b;
+/// break;
+///   [[likely]]
+///   default:
+/// return;
+///   }
 /// \endcode
 ABS_Always,
 /// Leave the line breaking after attributes as is.
@@ -1443,23 +1460,54 @@ struct FormatStyle {
 ///   [[maybe_unused]] const int i;
 ///   [[gnu::const]] [[maybe_unused]]
 ///   int j;
+///
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]]
 ///   int g();
+///
+///   [[likely]] if (a)
+/// f();
+///   else
+/// g();
+///
+///   switch (b) {
+///   [[unlikely]] case 1:
+/// ++b;
+/// break;
+///   [[likely]]
+///   default:
+/// return;
+///   }
 /// \endcode
 ABS_Leave,
 /// Never break after attributes.
 /// \code
 ///   [[maybe_unused]] const int i;
 ///   [[gnu::const]] [[maybe_unused]] int j;
+///
 ///   [[nodiscard]] inline int f();
 ///   [[gnu::const]] [[nodiscard]] int g();
+///
+///   [[likely]] if (a)
+/// f();
+///   else
+/// g();
+///
+///   switch (b) {
+///   [[unlikely]] case 1:
+/// ++b;
+/// break;
+ 

[clang] [clang-format] Remove special handling of comments after brace/paren (PR #71672)

2023-11-11 Thread Owen Pan via cfe-commits


@@ -802,7 +802,10 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
   Previous.isNot(TT_ObjCMethodExpr) && Previous.isNot(TT_RequiresClause) &&
   !(Current.MacroParent && Previous.MacroParent) &&
   (Current.isNot(TT_LineComment) ||
-   Previous.isOneOf(BK_BracedInit, TT_VerilogMultiLineListLParen))) {
+   (Previous.is(BK_BracedInit) &&
+(!Style.Cpp11BracedListStyle || !Previous.Previous ||
+ Previous.Previous->isNot(tok::identifier))) ||

owenca wrote:

Is this inconsistent with the 
[documentation](https://clang.llvm.org/docs/ClangFormatStyleOptions.html#cpp11bracedliststyle)
 which says, "If there is no name, a zero-length name is assumed."

https://github.com/llvm/llvm-project/pull/71672
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format][NFC] Simplify parseBracedList() (PR #72010)

2023-11-11 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/72010

>From f3f303d80a40b9ce8a13721cfa108b4094b8b2c3 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 10 Nov 2023 17:34:06 -0800
Subject: [PATCH 1/2] [clang-format][NFC] Simplify parseBracedList()

---
 clang/lib/Format/UnwrappedLineParser.cpp | 36 +---
 clang/lib/Format/UnwrappedLineParser.h   |  3 +-
 2 files changed, 15 insertions(+), 24 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 018bc6c165485e2..e6a333fdc4e42ce 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2017,8 +2017,7 @@ void UnwrappedLineParser::parseStructuralElement(
   } else if (Style.Language == FormatStyle::LK_Proto &&
  FormatTok->is(tok::less)) {
 nextToken();
-parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
-/*ClosingBraceKind=*/tok::greater);
+parseBracedList();
   }
   break;
 case tok::l_square:
@@ -2379,9 +2378,10 @@ bool UnwrappedLineParser::tryToParseChildBlock() {
   return true;
 }
 
-bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons,
-  bool IsEnum,
-  tok::TokenKind ClosingBraceKind) {
+bool UnwrappedLineParser::parseBracedList(bool IsEnum) {
+  const auto *OpeningBrace = FormatTok->getPreviousNonComment();
+  const bool IsAngleBracket = OpeningBrace && OpeningBrace->is(tok::less);
+
   bool HasError = false;
 
   // FIXME: Once we have an expression parser in the UnwrappedLineParser,
@@ -2403,7 +2403,7 @@ bool UnwrappedLineParser::parseBracedList(bool 
ContinueOnSemicolons,
 parseChildBlock();
   }
 }
-if (FormatTok->Tok.getKind() == ClosingBraceKind) {
+if (FormatTok->is(IsAngleBracket ? tok::greater : tok::r_brace)) {
   if (IsEnum && !Style.AllowShortEnumsOnASingleLine)
 addUnwrappedLine();
   nextToken();
@@ -2434,14 +2434,9 @@ bool UnwrappedLineParser::parseBracedList(bool 
ContinueOnSemicolons,
   parseBracedList();
   break;
 case tok::less:
-  if (Style.Language == FormatStyle::LK_Proto ||
-  ClosingBraceKind == tok::greater) {
-nextToken();
-parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
-/*ClosingBraceKind=*/tok::greater);
-  } else {
-nextToken();
-  }
+  nextToken();
+  if (IsAngleBracket)
+parseBracedList();
   break;
 case tok::semi:
   // JavaScript (or more precisely TypeScript) can have semicolons in 
braced
@@ -2453,8 +2448,8 @@ bool UnwrappedLineParser::parseBracedList(bool 
ContinueOnSemicolons,
 break;
   }
   HasError = true;
-  if (!ContinueOnSemicolons)
-return !HasError;
+  if (!IsEnum)
+return false;
   nextToken();
   break;
 case tok::comma:
@@ -3618,8 +3613,7 @@ void UnwrappedLineParser::parseConstraintExpression() {
 return;
 
   nextToken();
-  parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
-  /*ClosingBraceKind=*/tok::greater);
+  parseBracedList();
   break;
 
 default:
@@ -3650,8 +3644,7 @@ void UnwrappedLineParser::parseConstraintExpression() {
   nextToken();
   if (FormatTok->is(tok::less)) {
 nextToken();
-parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
-/*ClosingBraceKind=*/tok::greater);
+parseBracedList();
   }
   TopLevelParensAllowed = false;
   break;
@@ -3732,8 +3725,7 @@ bool UnwrappedLineParser::parseEnum() {
 addUnwrappedLine();
 Line->Level += 1;
   }
-  bool HasError = !parseBracedList(/*ContinueOnSemicolons=*/true,
-   /*IsEnum=*/true);
+  bool HasError = !parseBracedList(/*IsEnum=*/true);
   if (!Style.AllowShortEnumsOnASingleLine)
 Line->Level -= 1;
   if (HasError) {
diff --git a/clang/lib/Format/UnwrappedLineParser.h 
b/clang/lib/Format/UnwrappedLineParser.h
index c31f25fdd8f83c9..61ec04578955ce6 100644
--- a/clang/lib/Format/UnwrappedLineParser.h
+++ b/clang/lib/Format/UnwrappedLineParser.h
@@ -151,8 +151,7 @@ class UnwrappedLineParser {
   bool *HasDoWhile = nullptr,
   bool *HasLabel = nullptr);
   bool tryToParseBracedList();
-  bool parseBracedList(bool ContinueOnSemicolons = false, bool IsEnum = false,
-   tok::TokenKind ClosingBraceKind = tok::r_brace);
+  bool parseBracedList(bool IsEnum = false);
   bool parseParens(TokenType AmpAmpTokenType = TT_Unknown);
   void parseSquare(bool LambdaIntroducer = false);
   void keepAncestorBraces();

>From 085ca85a4e4ab7f1eb83ca9f79e01d5e45fe0d4d Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 11 Nov 2023 21:02:26 -080

[clang] [clang-format] Handle control statements in BreakAfterAttributes (PR #71995)

2023-11-12 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/71995
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format][NFC] Simplify parseBracedList() (PR #72010)

2023-11-12 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/72010
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a699ab5 - [clang-format][NFC] Remove redundant Block/Line Comment in is()

2023-11-13 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-11-13T02:14:37-08:00
New Revision: a699ab5adbefc4fa0d63edac8a137b0073576018

URL: 
https://github.com/llvm/llvm-project/commit/a699ab5adbefc4fa0d63edac8a137b0073576018
DIFF: 
https://github.com/llvm/llvm-project/commit/a699ab5adbefc4fa0d63edac8a137b0073576018.diff

LOG: [clang-format][NFC] Remove redundant Block/Line Comment in is()

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 3a829cdedb77fc7..8fffdccd35c059b 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1428,8 +1428,8 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
 return CurrentState.Indent - Current.Tok.getLength() -
Current.SpacesRequiredBefore;
   }
-  if (Current.isOneOf(tok::comment, TT_BlockComment, TT_LineComment) &&
-  NextNonComment->isBinaryOperator() && CurrentState.UnindentOperator) {
+  if (Current.is(tok::comment) && NextNonComment->isBinaryOperator() &&
+  CurrentState.UnindentOperator) {
 return CurrentState.Indent - NextNonComment->Tok.getLength() -
NextNonComment->SpacesRequiredBefore;
   }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix a bug in aligning comments in vector of structs (PR #72099)

2023-11-13 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/72099

Fixed #71825.

>From eab0253833b7a5910cec573cabf86bb6a1abf6ef Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 13 Nov 2023 02:37:30 -0800
Subject: [PATCH] [clang-format] Fix a bug in aligning comments in vector of
 structs

Fixed #71825.
---
 clang/lib/Format/WhitespaceManager.cpp | 2 +-
 clang/unittests/Format/FormatTest.cpp  | 5 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 764a068912e780a..32d8b97cc8dadb1 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1465,7 +1465,7 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
   // Account for the added token lengths
   Changes[j].Spaces = InitialSpaces - InitialTokenLength;
 }
-  } else if (C.Tok->is(tok::comment)) {
+  } else if (C.Tok->is(tok::comment) && C.Tok->NewlinesBefore == 0) {
 // Trailing comments stay at a space past the last token
 C.Spaces = Changes[i - 1].Tok->is(tok::comma) ? 1 : 2;
   } else if (C.Tok->is(tok::l_brace)) {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 21df86bf2eace55..f531e6da6a5c31b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -21076,6 +21076,11 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresLeftAlignment) {
"{7,  5,  \"!!\"   }\n"
"};",
Style);
+  verifyFormat("Foo foo = {\n"
+   "// comment\n"
+   "{1, 2}\n"
+   "};",
+   Style);
 
   Style.ColumnLimit = 20;
   // FIXME: unstable test case

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix a bug in aligning comments in vector of structs (PR #72099)

2023-11-13 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/72099
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Skip alignArrayInitializers() for 1-row matrices (PR #72166)

2023-11-13 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/72166

Fixed #68431.

>From 7442d202cdd0e22dba178731be01517aa8257d40 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 13 Nov 2023 14:04:32 -0800
Subject: [PATCH] [clang-format] Skip alignArrayInitializers() for 1-row
 matrices

Fixed #68431.
---
 clang/lib/Format/WhitespaceManager.h  | 2 +-
 clang/unittests/Format/FormatTest.cpp | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/WhitespaceManager.h 
b/clang/lib/Format/WhitespaceManager.h
index df7e9add1cd446f..42af671c16586f7 100644
--- a/clang/lib/Format/WhitespaceManager.h
+++ b/clang/lib/Format/WhitespaceManager.h
@@ -202,7 +202,7 @@ class WhitespaceManager {
 // Determine if every row in the array
 // has the same number of columns.
 bool isRectangular() const {
-  if (CellCounts.empty())
+  if (CellCounts.size() < 2)
 return false;
 
   for (auto NumberOfColumns : CellCounts)
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index f531e6da6a5c31b..849f70e5295b36e 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -20875,6 +20875,7 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresRightAlignment) {
"};",
Style);
   // TODO: Fix the indentations below when this option is fully functional.
+#if 0
   verifyFormat("int a[][] = {\n"
"{\n"
" {0, 2}, //\n"
@@ -20882,6 +20883,7 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresRightAlignment) {
"}\n"
"};",
Style);
+#endif
   Style.ColumnLimit = 100;
   verifyFormat(
   "test demo[] = {\n"

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a852869 - [clang-format] Fix a bug in parsing function/variable names

2023-11-13 Thread Owen Pan via cfe-commits

Author: Gedare Bloom
Date: 2023-11-13T19:35:28-08:00
New Revision: a852869398af71141d9422ab3e53a11433a3791f

URL: 
https://github.com/llvm/llvm-project/commit/a852869398af71141d9422ab3e53a11433a3791f
DIFF: 
https://github.com/llvm/llvm-project/commit/a852869398af71141d9422ab3e53a11433a3791f.diff

LOG: [clang-format] Fix a bug in parsing function/variable names

Function and variable names are not detected when there is a
__attribute__((x)) preceding the name.

Fixes #64137.

Differential Revision: https://reviews.llvm.org/D156370

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 03f3c3583f2ec44..aebea9d8695ffc3 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2246,8 +2246,9 @@ class AnnotatingParser {
  
PreviousNotConst->MatchingParen->Previous->isNot(tok::kw_template);
 }
 
-if (PreviousNotConst->is(tok::r_paren) &&
-PreviousNotConst->is(TT_TypeDeclarationParen)) {
+if ((PreviousNotConst->is(tok::r_paren) &&
+ PreviousNotConst->is(TT_TypeDeclarationParen)) ||
+PreviousNotConst->is(TT_AttributeRParen)) {
   return true;
 }
 

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index f531e6da6a5c31b..a12a20359c2fad2 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -16394,8 +16394,10 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
 
   verifyFormat("int f ();", SpaceFuncDecl);
   verifyFormat("void f(int a, T b) {}", SpaceFuncDecl);
+  verifyFormat("void __attribute__((asdf)) f(int a, T b) {}", SpaceFuncDecl);
   verifyFormat("A::A() : a(1) {}", SpaceFuncDecl);
   verifyFormat("void f () __attribute__((asdf));", SpaceFuncDecl);
+  verifyFormat("void __attribute__((asdf)) f ();", SpaceFuncDecl);
   verifyFormat("#define A(x) x", SpaceFuncDecl);
   verifyFormat("#define A (x) x", SpaceFuncDecl);
   verifyFormat("#if defined(x)\n"
@@ -16429,8 +16431,10 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
 
   verifyFormat("int f();", SpaceFuncDef);
   verifyFormat("void f (int a, T b) {}", SpaceFuncDef);
+  verifyFormat("void __attribute__((asdf)) f (int a, T b) {}", SpaceFuncDef);
   verifyFormat("A::A() : a(1) {}", SpaceFuncDef);
   verifyFormat("void f() __attribute__((asdf));", SpaceFuncDef);
+  verifyFormat("void __attribute__((asdf)) f();", SpaceFuncDef);
   verifyFormat("#define A(x) x", SpaceFuncDef);
   verifyFormat("#define A (x) x", SpaceFuncDef);
   verifyFormat("#if defined(x)\n"

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index ed730307074963f..b4b42fc82238f8a 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2313,6 +2313,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsJavaScript) {
 TEST_F(TokenAnnotatorTest, UnderstandsAttributes) {
   auto Tokens = annotate("bool foo __attribute__((unused));");
   ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::identifier, TT_StartOfName);
   EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_AttributeLParen);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_Unknown);
   EXPECT_TOKEN(Tokens[6], tok::r_paren, TT_Unknown);
@@ -2323,6 +2324,22 @@ TEST_F(TokenAnnotatorTest, UnderstandsAttributes) {
   EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_AttributeLParen);
   EXPECT_TOKEN(Tokens[5], tok::r_paren, TT_AttributeRParen);
 
+  Tokens = annotate("bool __attribute__((unused)) foo;");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_AttributeLParen);
+  EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[5], tok::r_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[6], tok::r_paren, TT_AttributeRParen);
+  EXPECT_TOKEN(Tokens[7], tok::identifier, TT_StartOfName);
+
+  Tokens = annotate("void __attribute__((x)) Foo();");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_AttributeLParen);
+  EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[5], tok::r_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[6], tok::r_paren, TT_AttributeRParen);
+  EXPECT_TOKEN(Tokens[7], tok::identifier, TT_FunctionDeclarationName);
+
   FormatStyle Style = getLLVMStyle();
   Style.AttributeMacros.push_back("FOO");
   Tokens = annotate("bool foo FOO(unused);", Style);



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle constrained auto in QualifierAlignment (PR #72251)

2023-11-14 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/72251

Fixed #69610.

>From 8e61a470fc7e4cf11a6cf285668a7f9eca72702c Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Tue, 14 Nov 2023 05:05:14 -0800
Subject: [PATCH] [clang-format] Handle constrained auto in QualifierAlignment

Fixed #69610.
---
 clang/lib/Format/QualifierAlignmentFixer.cpp  |  5 +
 clang/unittests/Format/QualifierFixerTest.cpp | 10 ++
 2 files changed, 15 insertions(+)

diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 7167e50ec724eab..72464d367153934 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -345,6 +345,8 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
 TypeToken = Next->getNextNonComment()->getNextNonComment();
   }
 }
+if (Next->is(tok::kw_auto))
+  TypeToken = Next;
 
 // Place the Qualifier at the end of the list of qualifiers.
 while (isQualifier(TypeToken->getNextNonComment())) {
@@ -446,6 +448,9 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeLeft(
 return false;
   }
 
+  if (Tok->endsSequence(tok::kw_auto, tok::identifier))
+return false;
+
   return true;
 };
 
diff --git a/clang/unittests/Format/QualifierFixerTest.cpp 
b/clang/unittests/Format/QualifierFixerTest.cpp
index 73814e7414f5e7d..a56323a88f4a04d 100644
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -352,6 +352,11 @@ TEST_F(QualifierFixerTest, RightQualifier) {
   verifyFormat("auto const &ir = i;", "const auto &ir = i;", Style);
   verifyFormat("auto const *ip = &i;", "const auto *ip = &i;", Style);
 
+  verifyFormat("void f(Concept auto const &x);",
+   "void f(const Concept auto &x);", Style);
+  verifyFormat("void f(std::integral auto const &x);",
+   "void f(const std::integral auto &x);", Style);
+
   verifyFormat("Foo const> P;\n#if 0\n#else\n#endif",
"Foo> P;\n#if 0\n#else\n#endif", Style);
 
@@ -653,6 +658,11 @@ TEST_F(QualifierFixerTest, LeftQualifier) {
   verifyFormat("const auto &ir = i;", "auto const &ir = i;", Style);
   verifyFormat("const auto *ip = &i;", "auto const *ip = &i;", Style);
 
+  verifyFormat("void f(const Concept auto &x);",
+   "void f(Concept auto const &x);", Style);
+  verifyFormat("void f(const std::integral auto &x);",
+   "void f(std::integral auto const &x);", Style);
+
   verifyFormat("Foo> P;\n#if 0\n#else\n#endif",
"Foo const> P;\n#if 0\n#else\n#endif", Style);
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix a bug in `git-clang-format --binary` (PR #74293)

2023-12-04 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/74293
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Remove duplicates in @property using std::set (PR #74235)

2023-12-04 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/74235
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format][NFC] Use `prog` in clang-format-diff.py (PR #74399)

2023-12-04 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/74399

This is a minor improvement to #73491.

>From ee039e7c50751fabdbaadae73a0a09bc905620f2 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 4 Dec 2023 17:33:47 -0800
Subject: [PATCH] [clang-format][NFC] Use `prog` in clang-format-diff.py

This is a minor improvement to #73491.
---
 clang/tools/clang-format/clang-format-diff.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index b25ee8f433751..946e28163420d 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -37,9 +37,8 @@
 
 
 def main():
-basename = os.path.basename(sys.argv[0])
 parser = argparse.ArgumentParser(
-description=__doc__.format(clang_format_diff=basename),
+description=__doc__.format(clang_format_diff='%(prog)s'),
 formatter_class=argparse.RawDescriptionHelpFormatter,
 )
 parser.add_argument(

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format][NFC] Use `prog` in clang-format-diff.py (PR #74399)

2023-12-04 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/74399

>From ee039e7c50751fabdbaadae73a0a09bc905620f2 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 4 Dec 2023 17:33:47 -0800
Subject: [PATCH 1/2] [clang-format][NFC] Use `prog` in clang-format-diff.py

This is a minor improvement to #73491.
---
 clang/tools/clang-format/clang-format-diff.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index b25ee8f433751..946e28163420d 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -37,9 +37,8 @@
 
 
 def main():
-basename = os.path.basename(sys.argv[0])
 parser = argparse.ArgumentParser(
-description=__doc__.format(clang_format_diff=basename),
+description=__doc__.format(clang_format_diff='%(prog)s'),
 formatter_class=argparse.RawDescriptionHelpFormatter,
 )
 parser.add_argument(

>From d8b2dab602b41deda70abd0f219ca88d5fd69c36 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 4 Dec 2023 17:41:58 -0800
Subject: [PATCH 2/2] Use double quotes instead.

---
 clang/tools/clang-format/clang-format-diff.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index 946e28163420d..9f3538608aaba 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -38,7 +38,7 @@
 
 def main():
 parser = argparse.ArgumentParser(
-description=__doc__.format(clang_format_diff='%(prog)s'),
+description=__doc__.format(clang_format_diff="%(prog)s"),
 formatter_class=argparse.RawDescriptionHelpFormatter,
 )
 parser.add_argument(

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format][NFC] Use `prog` in clang-format-diff.py (PR #74399)

2023-12-05 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/74399

>From ee039e7c50751fabdbaadae73a0a09bc905620f2 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 4 Dec 2023 17:33:47 -0800
Subject: [PATCH 1/3] [clang-format][NFC] Use `prog` in clang-format-diff.py

This is a minor improvement to #73491.
---
 clang/tools/clang-format/clang-format-diff.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index b25ee8f433751..946e28163420d 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -37,9 +37,8 @@
 
 
 def main():
-basename = os.path.basename(sys.argv[0])
 parser = argparse.ArgumentParser(
-description=__doc__.format(clang_format_diff=basename),
+description=__doc__.format(clang_format_diff='%(prog)s'),
 formatter_class=argparse.RawDescriptionHelpFormatter,
 )
 parser.add_argument(

>From d8b2dab602b41deda70abd0f219ca88d5fd69c36 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 4 Dec 2023 17:41:58 -0800
Subject: [PATCH 2/3] Use double quotes instead.

---
 clang/tools/clang-format/clang-format-diff.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index 946e28163420d..9f3538608aaba 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -38,7 +38,7 @@
 
 def main():
 parser = argparse.ArgumentParser(
-description=__doc__.format(clang_format_diff='%(prog)s'),
+description=__doc__.format(clang_format_diff="%(prog)s"),
 formatter_class=argparse.RawDescriptionHelpFormatter,
 )
 parser.add_argument(

>From 6ff8c2870bfb093cc5a02d0f6caa5c869cf5ec29 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Tue, 5 Dec 2023 00:51:16 -0800
Subject: [PATCH 3/3] Remove now unneeded `import os`.

---
 clang/tools/clang-format/clang-format-diff.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index 9f3538608aaba..0a2c24743678d 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -25,7 +25,6 @@
 
 import argparse
 import difflib
-import os
 import re
 import subprocess
 import sys

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format][NFC] Use `prog` in clang-format-diff.py (PR #74399)

2023-12-05 Thread Owen Pan via cfe-commits

owenca wrote:

> You can remove the useless `import os` then :-)

Good catch!

https://github.com/llvm/llvm-project/pull/74399
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [clang-tools-extra] [flang] [libc] [clang-format] Add "three dot" diff option to git-clang-format (PR #74230)

2023-12-05 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/74230

>From ae4097b53b90e31802be0be5c8a81fb74c81efc9 Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sat, 2 Dec 2023 23:46:58 -0800
Subject: [PATCH 1/3] [clang-format] Add "three dot" diff option to
 git-clang-format

This patch adds in the ability to do a "three dot" git-clang-format
between two commits. This looks at the diff between the second commit
and the common merge base rather than comparing at the point of the
specified commits. This is needed to improve the reliability of the LLVM
code formatting CI action which currently breaks in some cases where
files have been modified in the upstream tree and when the person
created their branch, leaving phantom formatting diffs that weren't
touched by the PR author.

Part of a fix for #73873
---
 clang/tools/clang-format/git-clang-format | 19 +++
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/clang/tools/clang-format/git-clang-format 
b/clang/tools/clang-format/git-clang-format
index 6e827e17b4ee2..4fe4671482e3f 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -132,6 +132,10 @@ def main():
  help='passed to clang-format'),
   p.add_argument('-v', '--verbose', action='count', default=0,
  help='print extra information')
+  p.add_argument('--diff_from_common_commit', action='store_true',
+ help=('diff from the last common commit for commits in '
+  'separate branches rather than the exact point of the '
+  'commits'))
   # We gather all the remaining positional arguments into 'args' since we need
   # to use some heuristics to determine whether or not  was present.
   # However, to print pretty messages, we make use of metavar and help.
@@ -154,7 +158,10 @@ def main():
 if len(commits) > 2:
   die('at most two commits allowed; %d given' % len(commits))
   opts.binary=os.path.abspath(opts.binary)
-  changed_lines = compute_diff_and_extract_lines(commits, files, opts.staged)
+  changed_lines = compute_diff_and_extract_lines(commits,
+ files,
+ opts.staged,
+ opts.diff_from_common_commit)
   if opts.verbose >= 1:
 ignored_files = set(changed_lines)
   filter_by_extension(changed_lines, opts.extensions.lower().split(','))
@@ -302,9 +309,9 @@ def get_object_type(value):
   return convert_string(stdout.strip())
 
 
-def compute_diff_and_extract_lines(commits, files, staged):
+def compute_diff_and_extract_lines(commits, files, staged, diff_common_commit):
   """Calls compute_diff() followed by extract_lines()."""
-  diff_process = compute_diff(commits, files, staged)
+  diff_process = compute_diff(commits, files, staged, diff_common_commit)
   changed_lines = extract_lines(diff_process.stdout)
   diff_process.stdout.close()
   diff_process.wait()
@@ -314,7 +321,7 @@ def compute_diff_and_extract_lines(commits, files, staged):
   return changed_lines
 
 
-def compute_diff(commits, files, staged):
+def compute_diff(commits, files, staged, diff_common_commit):
   """Return a subprocess object producing the diff from `commits`.
 
   The return value's `stdin` file object will produce a patch with the
@@ -328,6 +335,10 @@ def compute_diff(commits, files, staged):
 git_tool = 'diff-tree'
   elif staged:
 extra_args += ['--cached']
+
+  if len(commits) > 1 and diff_common_commit:
+commits = [f'{commits[0]}...{commits[1]}']
+
   cmd = ['git', git_tool, '-p', '-U0'] + extra_args + commits + ['--']
   cmd.extend(files)
   p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)

>From 4584ebc58337f04290a5c753f585426c8c6f739f Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Sun, 3 Dec 2023 13:08:16 -0800
Subject: [PATCH 2/3] Add early exit when flag is specified with invalid
 parameters

---
 clang/tools/clang-format/git-clang-format | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/tools/clang-format/git-clang-format 
b/clang/tools/clang-format/git-clang-format
index 4fe4671482e3f..51ae8739bee0e 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -157,6 +157,8 @@ def main():
   else:
 if len(commits) > 2:
   die('at most two commits allowed; %d given' % len(commits))
+  if len(commits) < 2 and opts.diff_from_common_commit:
+die('--diff_from_common_commit is only allowed when two commits are given')
   opts.binary=os.path.abspath(opts.binary)
   changed_lines = compute_diff_and_extract_lines(commits,
  files,

>From a8b385070845ba20f63f1e0c6835ff9bc609548f Mon Sep 17 00:00:00 2001
From: Aiden Grossman 
Date: Tue, 5 Dec 2023 17:42:12 -0800
Subject: [PATCH 3/3] Address reviewer feedback

---
 clang/tools/clang-forma

[clang] [compiler-rt] [llvm] [clang-tools-extra] [flang] [libc] [clang-format] Add "three dot" diff option to git-clang-format (PR #74230)

2023-12-05 Thread Owen Pan via cfe-commits

https://github.com/owenca approved this pull request.


https://github.com/llvm/llvm-project/pull/74230
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format][NFC] Refactor getting first/last non-comment of line (PR #74570)

2023-12-05 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/74570

None

>From a37925ae51d95e91d32ec50bc39a9b6e5b13c571 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Tue, 5 Dec 2023 23:31:28 -0800
Subject: [PATCH] [clang-format][NFC] Refactor getting first/last non-comment
 of line

---
 clang/lib/Format/TokenAnnotator.h   |  5 +
 clang/lib/Format/UnwrappedLineFormatter.cpp | 19 ++-
 2 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.h 
b/clang/lib/Format/TokenAnnotator.h
index 58e2cf79f488f..05a6daa87d803 100644
--- a/clang/lib/Format/TokenAnnotator.h
+++ b/clang/lib/Format/TokenAnnotator.h
@@ -156,6 +156,11 @@ class AnnotatedLine {
 return First->is(tok::comment) ? First->getNextNonComment() : First;
   }
 
+  FormatToken *getLastNonComment() const {
+assert(Last);
+return Last->is(tok::comment) ? Last->getPreviousNonComment() : Last;
+  }
+
   FormatToken *First;
   FormatToken *Last;
 
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 40730cd53529e..b4930c2e4621d 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -346,14 +346,10 @@ class LineJoiner {
 return false;
 
   // Check if the found line starts a record.
-  const FormatToken *LastNonComment = Line->Last;
+  const auto *LastNonComment = Line->getLastNonComment();
+  // There must be another token (usually `{`), because we chose a
+  // non-PPDirective and non-comment line that has a smaller level.
   assert(LastNonComment);
-  if (LastNonComment->is(tok::comment)) {
-LastNonComment = LastNonComment->getPreviousNonComment();
-// There must be another token (usually `{`), because we chose a
-// non-PPDirective and non-comment line that has a smaller level.
-assert(LastNonComment);
-  }
   return isRecordLBrace(*LastNonComment);
 }
   }
@@ -363,12 +359,9 @@ class LineJoiner {
 
 bool MergeShortFunctions = ShouldMergeShortFunctions();
 
-const FormatToken *FirstNonComment = TheLine->First;
-if (FirstNonComment->is(tok::comment)) {
-  FirstNonComment = FirstNonComment->getNextNonComment();
-  if (!FirstNonComment)
-return 0;
-}
+const auto *FirstNonComment = TheLine->getFirstNonComment();
+if (!FirstNonComment)
+  return 0;
 // FIXME: There are probably cases where we should use FirstNonComment
 // instead of TheLine->First.
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format][NFC] Refactor getting first/last non-comment of line (PR #74570)

2023-12-06 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/74570
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle merging functions containing only a block comment (PR #74651)

2023-12-06 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/74651

Fixed #41854.

>From 40859e0887fd53bbb02be213fcacf3d6d1a5a487 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 6 Dec 2023 12:01:19 -0800
Subject: [PATCH] [clang-format] Handle merging functions containing only a
 block comment

Fixed #41854.
---
 clang/lib/Format/UnwrappedLineFormatter.cpp   | 15 ---
 clang/unittests/Format/FormatTest.cpp | 13 +
 clang/unittests/Format/FormatTestComments.cpp | 15 ---
 3 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index b4930c2e4621d..56077499c39d5 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -411,9 +411,16 @@ class LineJoiner {
   }
 }
 
+const auto *LastNonComment = TheLine->getLastNonComment();
+assert(LastNonComment);
+// FIXME: There are probably cases where we should use LastNonComment
+// instead of TheLine->Last.
+
 // Try to merge a function block with left brace unwrapped.
-if (TheLine->Last->is(TT_FunctionLBrace) && TheLine->First != 
TheLine->Last)
+if (LastNonComment->is(TT_FunctionLBrace) &&
+TheLine->First != LastNonComment) {
   return MergeShortFunctions ? tryMergeSimpleBlock(I, E, Limit) : 0;
+}
 // Try to merge a control statement block with left brace unwrapped.
 if (TheLine->Last->is(tok::l_brace) && FirstNonComment != TheLine->Last &&
 FirstNonComment->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for,
@@ -789,7 +796,8 @@ class LineJoiner {
   }
 }
 
-if (Line.Last->is(tok::l_brace)) {
+if (const auto *LastNonComment = Line.getLastNonComment();
+LastNonComment && LastNonComment->is(tok::l_brace)) {
   if (IsSplitBlock && Line.First == Line.Last &&
   I > AnnotatedLines.begin() &&
   (I[-1]->endsWith(tok::kw_else) || IsCtrlStmt(*I[-1]))) {
@@ -805,7 +813,8 @@ class LineJoiner {
 
   if (ShouldMerge()) {
 // We merge empty blocks even if the line exceeds the column limit.
-Tok->SpacesRequiredBefore = Style.SpaceInEmptyBlock ? 1 : 0;
+Tok->SpacesRequiredBefore =
+(Style.SpaceInEmptyBlock || Line.Last->is(tok::comment)) ? 1 : 0;
 Tok->CanBreakBefore = true;
 return 1;
   } else if (Limit != 0 && !Line.startsWithNamespace() &&
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 8782cb7c49cad..24b2fd599dc39 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -13950,6 +13950,19 @@ TEST_F(FormatTest, 
PullTrivialFunctionDefinitionsIntoSingleLine) {
"  void f() { int i; } \\\n"
"  int j;",
getLLVMStyleWithColumns(23));
+
+  verifyFormat(
+  "void (\n"
+  "aa,\n"
+  "aa) {}");
+
+  constexpr StringRef Code{"void foo() { /* Empty */ }"};
+  verifyFormat(Code);
+  verifyFormat(Code, "void foo() { /* Empty */\n"
+ "}");
+  verifyFormat(Code, "void foo() {\n"
+ "/* Empty */\n"
+ "}");
 }
 
 TEST_F(FormatTest, PullEmptyFunctionDefinitionsIntoSingleLine) {
diff --git a/clang/unittests/Format/FormatTestComments.cpp 
b/clang/unittests/Format/FormatTestComments.cpp
index 9770d5090703c..c249f4d9333fd 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -386,15 +386,16 @@ TEST_F(FormatTestComments, UnderstandsBlockComments) {
   "  /* Leading comment for bb... */ b);",
   format("f(a,   \n"
  "/* Leading comment for bb... */   b);"));
-  EXPECT_EQ(
+
+  verifyFormat(
   "void (\n"
   "aa,\n"
-  "aa) { /*aaa*/\n"
-  "}",
-  format("void  (\n"
- "  aa  ,\n"
- "aa) {   
/*aaa*/\n"
- "}"));
+  "aa) { /*aaa*/ }",
+  "void  (\n"
+  "  aa  ,\n"
+  "aa) {   /*aaa*/\n"
+  "}");
+
   verifyFormat("f(/* aa = */\n"
"  );");
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle merging functions containing only a block comment (PR #74651)

2023-12-06 Thread Owen Pan via cfe-commits


@@ -411,9 +411,16 @@ class LineJoiner {
   }
 }
 
+const auto *LastNonComment = TheLine->getLastNonComment();
+assert(LastNonComment);
+// FIXME: There are probably cases where we should use LastNonComment

owenca wrote:

No. This is new from this patch.

https://github.com/llvm/llvm-project/pull/74651
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle merging functions containing only a block comment (PR #74651)

2023-12-06 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/74651
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b683709 - [clang-format] Fix a possible crash in `AlignAfterOpenBracket: BlockIndent`

2023-12-06 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-12-06T17:40:41-08:00
New Revision: b683709ea6eec7d0a388bd50c571774c9b9ffdb7

URL: 
https://github.com/llvm/llvm-project/commit/b683709ea6eec7d0a388bd50c571774c9b9ffdb7
DIFF: 
https://github.com/llvm/llvm-project/commit/b683709ea6eec7d0a388bd50c571774c9b9ffdb7.diff

LOG: [clang-format] Fix a possible crash in `AlignAfterOpenBracket: BlockIndent`

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index cb7dc5f3dd9ba..9e4e939503dfe 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1259,7 +1259,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
   }
   if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
   (Current.is(tok::r_paren) ||
-   (Current.is(tok::r_brace) &&
+   (Current.is(tok::r_brace) && Current.MatchingParen &&
 Current.MatchingParen->is(BK_BracedInit))) &&
   State.Stack.size() > 1) {
 return State.Stack[State.Stack.size() - 2].LastSpace;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format][NFC] Clean up the driver and getStyle() in Format.cpp (PR #74794)

2023-12-07 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/74794

None

>From fb239719267ec97905ebb339176b5f7015de04eb Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 7 Dec 2023 17:42:45 -0800
Subject: [PATCH] [clang-format][NFC] Clean up ClangFormat.cpp and getStyle()
 in Format.cpp

---
 clang/lib/Format/Format.cpp  | 95 
 clang/tools/clang-format/ClangFormat.cpp | 40 +-
 2 files changed, 65 insertions(+), 70 deletions(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index b09487435adb2..8feee7457fc31 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3955,10 +3955,7 @@ llvm::Expected getStyle(StringRef 
StyleName, StringRef FileName,
  StringRef FallbackStyleName,
  StringRef Code, llvm::vfs::FileSystem *FS,
  bool AllowUnknownOptions) {
-  if (!FS)
-FS = llvm::vfs::getRealFileSystem().get();
   FormatStyle Style = getLLVMStyle(guessLanguage(FileName, Code));
-
   FormatStyle FallbackStyle = getNoStyle();
   if (!getPredefinedStyle(FallbackStyleName, Style.Language, &FallbackStyle))
 return make_string_error("Invalid fallback style: " + FallbackStyleName);
@@ -3974,14 +3971,18 @@ llvm::Expected getStyle(StringRef 
StyleName, StringRef FileName,
AllowUnknownOptions)) {
   return make_string_error("Error parsing -style: " + ec.message());
 }
-if (Style.InheritsParentConfig) {
-  ChildFormatTextToApply.emplace_back(
-  llvm::MemoryBuffer::getMemBuffer(StyleName, Source, false));
-} else {
+
+if (!Style.InheritsParentConfig)
   return Style;
-}
+
+ChildFormatTextToApply.emplace_back(
+llvm::MemoryBuffer::getMemBuffer(StyleName, Source, false));
   }
 
+  if (!FS)
+FS = llvm::vfs::getRealFileSystem().get();
+  assert(FS);
+
   // User provided clang-format file using -style=file:path/to/format/file.
   if (!Style.InheritsParentConfig &&
   StyleName.starts_with_insensitive("file:")) {
@@ -4015,18 +4016,12 @@ llvm::Expected getStyle(StringRef 
StyleName, StringRef FileName,
   return Style;
   }
 
-  // Reset possible inheritance
-  Style.InheritsParentConfig = false;
-
-  // Look for .clang-format/_clang-format file in the file's parent 
directories.
-  SmallString<128> UnsuitableConfigFiles;
   SmallString<128> Path(FileName);
   if (std::error_code EC = FS->makeAbsolute(Path))
 return make_string_error(EC.message());
 
-  llvm::SmallVector FilesToLookFor;
-  FilesToLookFor.push_back(".clang-format");
-  FilesToLookFor.push_back("_clang-format");
+  // Reset possible inheritance
+  Style.InheritsParentConfig = false;
 
   auto dropDiagnosticHandler = [](const llvm::SMDiagnostic &, void *) {};
 
@@ -4040,9 +4035,14 @@ llvm::Expected getStyle(StringRef 
StyleName, StringRef FileName,
 }
   };
 
+  // Look for .clang-format/_clang-format file in the file's parent 
directories.
+  llvm::SmallVector FilesToLookFor;
+  FilesToLookFor.push_back(".clang-format");
+  FilesToLookFor.push_back("_clang-format");
+
+  SmallString<128> UnsuitableConfigFiles;
   for (StringRef Directory = Path; !Directory.empty();
Directory = llvm::sys::path::parent_path(Directory)) {
-
 auto Status = FS->status(Directory);
 if (!Status ||
 Status->getType() != llvm::sys::fs::file_type::directory_file) {
@@ -4055,50 +4055,51 @@ llvm::Expected getStyle(StringRef 
StyleName, StringRef FileName,
   llvm::sys::path::append(ConfigFile, F);
   LLVM_DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n");
 
-  Status = FS->status(ConfigFile.str());
-
-  if (Status &&
-  (Status->getType() == llvm::sys::fs::file_type::regular_file)) {
-llvm::ErrorOr> Text =
-loadAndParseConfigFile(ConfigFile, FS, &Style, 
AllowUnknownOptions);
-if (auto EC = Text.getError()) {
-  if (EC == ParseError::Unsuitable) {
-if (!UnsuitableConfigFiles.empty())
-  UnsuitableConfigFiles.append(", ");
-UnsuitableConfigFiles.append(ConfigFile);
-continue;
-  }
+  Status = FS->status(ConfigFile);
+  if (!Status ||
+  Status->getType() != llvm::sys::fs::file_type::regular_file) {
+continue;
+  }
+
+  llvm::ErrorOr> Text =
+  loadAndParseConfigFile(ConfigFile, FS, &Style, AllowUnknownOptions);
+  if (auto EC = Text.getError()) {
+if (EC != ParseError::Unsuitable) {
   return make_string_error("Error reading " + ConfigFile + ": " +
EC.message());
 }
-LLVM_DEBUG(llvm::dbgs()
-   << "Using configuration file " << ConfigFile << "\n");
+if (!UnsuitableConfigFiles.empty())
+  UnsuitableConfigFiles.append(", ");
+UnsuitableConfigFiles.append(ConfigFile);
+   

[clang] [clang-format][NFC] Clean up the driver and getStyle() in Format.cpp (PR #74794)

2023-12-08 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/74794
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Skip alignArrayInitializers() for 1-row matrices (PR #72166)

2023-11-14 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/72166

>From 7442d202cdd0e22dba178731be01517aa8257d40 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 13 Nov 2023 14:04:32 -0800
Subject: [PATCH 1/2] [clang-format] Skip alignArrayInitializers() for 1-row
 matrices

Fixed #68431.
---
 clang/lib/Format/WhitespaceManager.h  | 2 +-
 clang/unittests/Format/FormatTest.cpp | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/WhitespaceManager.h 
b/clang/lib/Format/WhitespaceManager.h
index df7e9add1cd446f..42af671c16586f7 100644
--- a/clang/lib/Format/WhitespaceManager.h
+++ b/clang/lib/Format/WhitespaceManager.h
@@ -202,7 +202,7 @@ class WhitespaceManager {
 // Determine if every row in the array
 // has the same number of columns.
 bool isRectangular() const {
-  if (CellCounts.empty())
+  if (CellCounts.size() < 2)
 return false;
 
   for (auto NumberOfColumns : CellCounts)
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index f531e6da6a5c31b..849f70e5295b36e 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -20875,6 +20875,7 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresRightAlignment) {
"};",
Style);
   // TODO: Fix the indentations below when this option is fully functional.
+#if 0
   verifyFormat("int a[][] = {\n"
"{\n"
" {0, 2}, //\n"
@@ -20882,6 +20883,7 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresRightAlignment) {
"}\n"
"};",
Style);
+#endif
   Style.ColumnLimit = 100;
   verifyFormat(
   "test demo[] = {\n"

>From f5b66210c3fa7e56dd1796ce33c5cf5f70070ad4 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Tue, 14 Nov 2023 15:08:27 -0800
Subject: [PATCH 2/2] Fixed the commented out (via #if 0) test case.

---
 clang/unittests/Format/FormatTest.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 849f70e5295b36e..6eeba086ef98919 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -20879,7 +20879,7 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresRightAlignment) {
   verifyFormat("int a[][] = {\n"
"{\n"
" {0, 2}, //\n"
-   " {1, 2}  //\n"
+   " {1, 2}  //\n"
"}\n"
"};",
Style);

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Skip alignArrayInitializers() for 1-row matrices (PR #72166)

2023-11-14 Thread Owen Pan via cfe-commits


@@ -20875,13 +20875,15 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresRightAlignment) {
"};",
Style);
   // TODO: Fix the indentations below when this option is fully functional.
+#if 0

owenca wrote:

Because it's wrong as the TODO comment says.

This patch doesn't fix it and would format it as:
```
int a[][] = {
{
 {0, 2}, //
{1, 2}  //
}
};
```
Nevertheless, I just changed it to what it ought to look like.

https://github.com/llvm/llvm-project/pull/72166
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle constrained auto in QualifierAlignment (PR #72251)

2023-11-14 Thread Owen Pan via cfe-commits


@@ -345,6 +345,8 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
 TypeToken = Next->getNextNonComment()->getNextNonComment();
   }
 }
+if (Next->is(tok::kw_auto))

owenca wrote:

```suggestion

if (Next->is(tok::kw_auto))
```

https://github.com/llvm/llvm-project/pull/72251
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle constrained auto in QualifierAlignment (PR #72251)

2023-11-14 Thread Owen Pan via cfe-commits

https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/72251
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle constrained auto in QualifierAlignment (PR #72251)

2023-11-14 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/72251

>From 8e61a470fc7e4cf11a6cf285668a7f9eca72702c Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Tue, 14 Nov 2023 05:05:14 -0800
Subject: [PATCH 1/2] [clang-format] Handle constrained auto in
 QualifierAlignment

Fixed #69610.
---
 clang/lib/Format/QualifierAlignmentFixer.cpp  |  5 +
 clang/unittests/Format/QualifierFixerTest.cpp | 10 ++
 2 files changed, 15 insertions(+)

diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 7167e50ec724eab..72464d367153934 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -345,6 +345,8 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
 TypeToken = Next->getNextNonComment()->getNextNonComment();
   }
 }
+if (Next->is(tok::kw_auto))
+  TypeToken = Next;
 
 // Place the Qualifier at the end of the list of qualifiers.
 while (isQualifier(TypeToken->getNextNonComment())) {
@@ -446,6 +448,9 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeLeft(
 return false;
   }
 
+  if (Tok->endsSequence(tok::kw_auto, tok::identifier))
+return false;
+
   return true;
 };
 
diff --git a/clang/unittests/Format/QualifierFixerTest.cpp 
b/clang/unittests/Format/QualifierFixerTest.cpp
index 73814e7414f5e7d..a56323a88f4a04d 100644
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -352,6 +352,11 @@ TEST_F(QualifierFixerTest, RightQualifier) {
   verifyFormat("auto const &ir = i;", "const auto &ir = i;", Style);
   verifyFormat("auto const *ip = &i;", "const auto *ip = &i;", Style);
 
+  verifyFormat("void f(Concept auto const &x);",
+   "void f(const Concept auto &x);", Style);
+  verifyFormat("void f(std::integral auto const &x);",
+   "void f(const std::integral auto &x);", Style);
+
   verifyFormat("Foo const> P;\n#if 0\n#else\n#endif",
"Foo> P;\n#if 0\n#else\n#endif", Style);
 
@@ -653,6 +658,11 @@ TEST_F(QualifierFixerTest, LeftQualifier) {
   verifyFormat("const auto &ir = i;", "auto const &ir = i;", Style);
   verifyFormat("const auto *ip = &i;", "auto const *ip = &i;", Style);
 
+  verifyFormat("void f(const Concept auto &x);",
+   "void f(Concept auto const &x);", Style);
+  verifyFormat("void f(const std::integral auto &x);",
+   "void f(std::integral auto const &x);", Style);
+
   verifyFormat("Foo> P;\n#if 0\n#else\n#endif",
"Foo const> P;\n#if 0\n#else\n#endif", Style);
 

>From 0a5a39d757400328f95ad5a851c9d247bdc8321b Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Tue, 14 Nov 2023 15:33:34 -0800
Subject: [PATCH 2/2] Update clang/lib/Format/QualifierAlignmentFixer.cpp

---
 clang/lib/Format/QualifierAlignmentFixer.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 72464d367153934..e2fab1c1e3c2a37 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -345,6 +345,7 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
 TypeToken = Next->getNextNonComment()->getNextNonComment();
   }
 }
+
 if (Next->is(tok::kw_auto))
   TypeToken = Next;
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix more bugs in isStartOfName() (PR #72336)

2023-11-14 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/72336

Fixed #72264.

>From 832b6dccb1a8b0d3af4c3970c6c85f97e9cf3283 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Tue, 14 Nov 2023 19:21:11 -0800
Subject: [PATCH] [clang-format] Fix more bugs in isStartOfName()

Fixed #72264.
---
 clang/lib/Format/TokenAnnotator.cpp   |  7 ++-
 clang/unittests/Format/TokenAnnotatorTest.cpp | 14 ++
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 03f3c3583f2ec44..b71f6daa4e14392 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2018,10 +2018,6 @@ class AnnotatingParser {
(!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
   Contexts.back().FirstStartOfName = &Current;
   Current.setType(TT_StartOfName);
-  if (auto *PrevNonComment = Current.getPreviousNonComment();
-  PrevNonComment && PrevNonComment->is(TT_StartOfName)) {
-PrevNonComment->setType(TT_Unknown);
-  }
 } else if (Current.is(tok::semi)) {
   // Reset FirstStartOfName after finding a semicolon so that a for loop
   // with multiple increment statements is not confused with a for loop
@@ -2210,7 +2206,8 @@ class AnnotatingParser {
   return false;
 
 if (const auto *NextNonComment = Tok.getNextNonComment();
-!NextNonComment || NextNonComment->isPointerOrReference()) {
+!NextNonComment || NextNonComment->isPointerOrReference() ||
+NextNonComment->isOneOf(tok::identifier, tok::string_literal)) {
   return false;
 }
 
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index ed730307074963f..1c0fe60c45c7a87 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2373,6 +2373,20 @@ TEST_F(TokenAnnotatorTest, UnderstandsDoWhile) {
   EXPECT_TOKEN(Tokens[4], tok::kw_while, TT_DoWhile);
 }
 
+TEST_F(TokenAnnotatorTest, NotStartOfName) {
+  auto Tokens = annotate("#pragma clang diagnostic push");
+  ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_Unknown);
+
+  Tokens = annotate("#pragma clang diagnostic ignored 
\"-Wzero-length-array\"");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_Unknown);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle constrained auto in QualifierAlignment (PR #72251)

2023-11-15 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/72251
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix more bugs in isStartOfName() (PR #72336)

2023-11-15 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/72336
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle lambdas in QualifierAlignment (PR #72456)

2023-11-15 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/72456

Fixed #62780.

>From 5aae5d3c5b976d91548219aba4fb9c937d0fbbcc Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 15 Nov 2023 16:13:46 -0800
Subject: [PATCH] [clang-format] Handle lambdas in QualifierAlignment

Fixed #62780.
---
 clang/lib/Format/QualifierAlignmentFixer.cpp  | 12 +---
 clang/lib/Format/QualifierAlignmentFixer.h|  4 
 clang/unittests/Format/QualifierFixerTest.cpp |  6 ++
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index e2fab1c1e3c2a37..84941746f0df71b 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -535,14 +535,21 @@ LeftRightQualifierAlignmentFixer::analyze(
 SmallVectorImpl &AnnotatedLines,
 FormatTokenLexer &Tokens) {
   tooling::Replacements Fixes;
-  const AdditionalKeywords &Keywords = Tokens.getKeywords();
-  const SourceManager &SourceMgr = Env.getSourceManager();
   AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
+  fixQualifierAlignment(AnnotatedLines, Tokens, Fixes);
+  return {Fixes, 0};
+}
 
+void LeftRightQualifierAlignmentFixer::fixQualifierAlignment(
+SmallVectorImpl &AnnotatedLines, FormatTokenLexer &Tokens,
+tooling::Replacements &Fixes) {
+  const AdditionalKeywords &Keywords = Tokens.getKeywords();
+  const SourceManager &SourceMgr = Env.getSourceManager();
   tok::TokenKind QualifierToken = getTokenFromQualifier(Qualifier);
   assert(QualifierToken != tok::identifier && "Unrecognised Qualifier");
 
   for (AnnotatedLine *Line : AnnotatedLines) {
+fixQualifierAlignment(Line->Children, Tokens, Fixes);
 if (!Line->Affected || Line->InPPDirective)
   continue;
 FormatToken *First = Line->First;
@@ -565,7 +572,6 @@ LeftRightQualifierAlignmentFixer::analyze(
   }
 }
   }
-  return {Fixes, 0};
 }
 
 void prepareLeftRightOrderingForQualifierAlignmentFixer(
diff --git a/clang/lib/Format/QualifierAlignmentFixer.h 
b/clang/lib/Format/QualifierAlignmentFixer.h
index a72d135179f1ece..e922d8005595103 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.h
+++ b/clang/lib/Format/QualifierAlignmentFixer.h
@@ -52,6 +52,10 @@ class LeftRightQualifierAlignmentFixer : public 
TokenAnalyzer {
 
   static tok::TokenKind getTokenFromQualifier(const std::string &Qualifier);
 
+  void fixQualifierAlignment(SmallVectorImpl &AnnotatedLines,
+ FormatTokenLexer &Tokens,
+ tooling::Replacements &Fixes);
+
   const FormatToken *analyzeRight(const SourceManager &SourceMgr,
   const AdditionalKeywords &Keywords,
   tooling::Replacements &Fixes,
diff --git a/clang/unittests/Format/QualifierFixerTest.cpp 
b/clang/unittests/Format/QualifierFixerTest.cpp
index a56323a88f4a04d..324366ca7f5e511 100644
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -357,6 +357,9 @@ TEST_F(QualifierFixerTest, RightQualifier) {
   verifyFormat("void f(std::integral auto const &x);",
"void f(const std::integral auto &x);", Style);
 
+  verifyFormat("auto lambda = [] { int const i = 0; };",
+   "auto lambda = [] { const int i = 0; };", Style);
+
   verifyFormat("Foo const> P;\n#if 0\n#else\n#endif",
"Foo> P;\n#if 0\n#else\n#endif", Style);
 
@@ -663,6 +666,9 @@ TEST_F(QualifierFixerTest, LeftQualifier) {
   verifyFormat("void f(const std::integral auto &x);",
"void f(std::integral auto const &x);", Style);
 
+  verifyFormat("auto lambda = [] { const int i = 0; };",
+   "auto lambda = [] { int const i = 0; };", Style);
+
   verifyFormat("Foo> P;\n#if 0\n#else\n#endif",
"Foo const> P;\n#if 0\n#else\n#endif", Style);
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix crashes in AlignArrayOfStructures (PR #72520)

2023-11-16 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/72520

Fixed #55493.
Fixed #68431.

>From efdf321e9447e8b3f1c27ccdf6da842107deb6dd Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 16 Nov 2023 06:36:41 -0800
Subject: [PATCH] [clang-format] Fix crashes in AlignArrayOfStructures

Fixed #55493.
Fixed #68431.
---
 clang/lib/Format/WhitespaceManager.cpp |  4 +++-
 clang/lib/Format/WhitespaceManager.h   |  2 +-
 clang/unittests/Format/FormatTest.cpp  | 18 ++
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 32d8b97cc8dadb1..3bc6915b8df0a70 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1316,6 +1316,8 @@ void 
WhitespaceManager::alignArrayInitializersRightJustified(
 auto Offset = std::distance(Cells.begin(), CellIter);
 for (const auto *Next = CellIter->NextColumnElement; Next;
  Next = Next->NextColumnElement) {
+  if (RowCount >= CellDescs.CellCounts.size())
+break;
   auto *Start = (Cells.begin() + RowCount * CellDescs.CellCounts[0]);
   auto *End = Start + Offset;
   ThisNetWidth = getNetWidth(Start, End, CellDescs.InitialSpaces);
@@ -1379,7 +1381,7 @@ void 
WhitespaceManager::alignArrayInitializersLeftJustified(
 auto Offset = std::distance(Cells.begin(), CellIter);
 for (const auto *Next = CellIter->NextColumnElement; Next;
  Next = Next->NextColumnElement) {
-  if (RowCount > CellDescs.CellCounts.size())
+  if (RowCount >= CellDescs.CellCounts.size())
 break;
   auto *Start = (Cells.begin() + RowCount * CellDescs.CellCounts[0]);
   auto *End = Start + Offset;
diff --git a/clang/lib/Format/WhitespaceManager.h 
b/clang/lib/Format/WhitespaceManager.h
index df7e9add1cd446f..69398fe411502f1 100644
--- a/clang/lib/Format/WhitespaceManager.h
+++ b/clang/lib/Format/WhitespaceManager.h
@@ -317,7 +317,7 @@ class WhitespaceManager {
 auto Offset = std::distance(CellStart, CellStop);
 for (const auto *Next = CellStop->NextColumnElement; Next;
  Next = Next->NextColumnElement) {
-  if (RowCount > MaxRowCount)
+  if (RowCount >= MaxRowCount)
 break;
   auto Start = (CellStart + RowCount * CellCount);
   auto End = Start + Offset;
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index a12a20359c2fad2..cd4c93e8427723f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -21140,6 +21140,24 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresLeftAlignment) {
   "that really, in any just world, ought to be split over multiple "
   "lines\"},{-1, 93463, \"world\"},{7, 5, \"!!\"},};",
   Style);
+
+  Style.ColumnLimit = 25;
+  verifyNoCrash("Type object[X][Y] = {\n"
+"{{val}, {val}, {val}},\n"
+"{{val}, {val}, // some comment\n"
+"   {val}}\n"
+"};",
+Style);
+
+  Style.ColumnLimit = 120;
+  verifyNoCrash(
+  "T v[] {\n"
+  "{ A::aaa, "
+  "A::, 1, 0.0f, "
+  "\""
+  "\" },\n"
+  "};",
+  Style);
 }
 
 TEST_F(FormatTest, UnderstandsPragmas) {

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Skip alignArrayInitializers() for 1-row matrices (PR #72166)

2023-11-16 Thread Owen Pan via cfe-commits

https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/72166
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle lambdas in QualifierAlignment (PR #72456)

2023-11-16 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/72456
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix crashes in AlignArrayOfStructures (PR #72520)

2023-11-16 Thread Owen Pan via cfe-commits


@@ -1316,6 +1316,8 @@ void 
WhitespaceManager::alignArrayInitializersRightJustified(
 auto Offset = std::distance(Cells.begin(), CellIter);
 for (const auto *Next = CellIter->NextColumnElement; Next;
  Next = Next->NextColumnElement) {
+  if (RowCount >= CellDescs.CellCounts.size())
+break;

owenca wrote:

I intentionally made it the same as lines 1384-1385 below so that lines 
1315-1323 would remain copy-pasted from lines 1380-1388. This will make future 
refactoring easier.

https://github.com/llvm/llvm-project/pull/72520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix crashes in AlignArrayOfStructures (PR #72520)

2023-11-16 Thread Owen Pan via cfe-commits

https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/72520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix crashes in AlignArrayOfStructures (PR #72520)

2023-11-16 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/72520

>From efdf321e9447e8b3f1c27ccdf6da842107deb6dd Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 16 Nov 2023 06:36:41 -0800
Subject: [PATCH 1/2] [clang-format] Fix crashes in AlignArrayOfStructures

Fixed #55493.
Fixed #68431.
---
 clang/lib/Format/WhitespaceManager.cpp |  4 +++-
 clang/lib/Format/WhitespaceManager.h   |  2 +-
 clang/unittests/Format/FormatTest.cpp  | 18 ++
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 32d8b97cc8dadb1..3bc6915b8df0a70 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1316,6 +1316,8 @@ void 
WhitespaceManager::alignArrayInitializersRightJustified(
 auto Offset = std::distance(Cells.begin(), CellIter);
 for (const auto *Next = CellIter->NextColumnElement; Next;
  Next = Next->NextColumnElement) {
+  if (RowCount >= CellDescs.CellCounts.size())
+break;
   auto *Start = (Cells.begin() + RowCount * CellDescs.CellCounts[0]);
   auto *End = Start + Offset;
   ThisNetWidth = getNetWidth(Start, End, CellDescs.InitialSpaces);
@@ -1379,7 +1381,7 @@ void 
WhitespaceManager::alignArrayInitializersLeftJustified(
 auto Offset = std::distance(Cells.begin(), CellIter);
 for (const auto *Next = CellIter->NextColumnElement; Next;
  Next = Next->NextColumnElement) {
-  if (RowCount > CellDescs.CellCounts.size())
+  if (RowCount >= CellDescs.CellCounts.size())
 break;
   auto *Start = (Cells.begin() + RowCount * CellDescs.CellCounts[0]);
   auto *End = Start + Offset;
diff --git a/clang/lib/Format/WhitespaceManager.h 
b/clang/lib/Format/WhitespaceManager.h
index df7e9add1cd446f..69398fe411502f1 100644
--- a/clang/lib/Format/WhitespaceManager.h
+++ b/clang/lib/Format/WhitespaceManager.h
@@ -317,7 +317,7 @@ class WhitespaceManager {
 auto Offset = std::distance(CellStart, CellStop);
 for (const auto *Next = CellStop->NextColumnElement; Next;
  Next = Next->NextColumnElement) {
-  if (RowCount > MaxRowCount)
+  if (RowCount >= MaxRowCount)
 break;
   auto Start = (CellStart + RowCount * CellCount);
   auto End = Start + Offset;
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index a12a20359c2fad2..cd4c93e8427723f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -21140,6 +21140,24 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresLeftAlignment) {
   "that really, in any just world, ought to be split over multiple "
   "lines\"},{-1, 93463, \"world\"},{7, 5, \"!!\"},};",
   Style);
+
+  Style.ColumnLimit = 25;
+  verifyNoCrash("Type object[X][Y] = {\n"
+"{{val}, {val}, {val}},\n"
+"{{val}, {val}, // some comment\n"
+"   {val}}\n"
+"};",
+Style);
+
+  Style.ColumnLimit = 120;
+  verifyNoCrash(
+  "T v[] {\n"
+  "{ A::aaa, "
+  "A::, 1, 0.0f, "
+  "\""
+  "\" },\n"
+  "};",
+  Style);
 }
 
 TEST_F(FormatTest, UnderstandsPragmas) {

>From 4a73cc6c52be6824d34f4ba5608a008a3dfdedf0 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 16 Nov 2023 18:46:23 -0800
Subject: [PATCH 2/2] Added tests from #54815 and #55269.

---
 clang/unittests/Format/FormatTest.cpp | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index cd4c93e8427723f..a579746fd4b68e8 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -20709,6 +20709,12 @@ TEST_F(FormatTest, CatchExceptionReferenceBinding) {
 TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) {
   auto Style = getLLVMStyle();
   Style.AlignArrayOfStructures = FormatStyle::AIAS_Right;
+
+  verifyNoCrash("f({\n"
+"table({}, table({{\"\", false}}, {}))\n"
+"});",
+Style);
+
   Style.AlignConsecutiveAssignments.Enabled = true;
   Style.AlignConsecutiveDeclarations.Enabled = true;
   verifyFormat("struct test demo[] = {\n"
@@ -21142,6 +21148,15 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresLeftAlignment) {
   Style);
 
   Style.ColumnLimit = 25;
+  verifyNoCrash("Type foo{\n"
+"{\n"
+"1,  // A\n"
+"2,  // B\n"
+"3,  // C\n"
+"},\n"
+"\"hello\",\n"
+"};",
+Style);
   ve

[clang] [clang-format] Fix crashes in AlignArrayOfStructures (PR #72520)

2023-11-17 Thread Owen Pan via cfe-commits


@@ -1316,6 +1316,8 @@ void 
WhitespaceManager::alignArrayInitializersRightJustified(
 auto Offset = std::distance(Cells.begin(), CellIter);
 for (const auto *Next = CellIter->NextColumnElement; Next;
  Next = Next->NextColumnElement) {
+  if (RowCount >= CellDescs.CellCounts.size())
+break;

owenca wrote:

The same/similar code appeared twice in this file and once in the header file. 
If I were to refactor it, I might not use the same for-loop, so I'll leave it 
as is for now. (There are also much more cleanup that can be done with this 
option, but I don't know if it's worthwhile as it's so buggy even after 
@mydeveloperday limited it to matrices.)

https://github.com/llvm/llvm-project/pull/72520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix crashes in AlignArrayOfStructures (PR #72520)

2023-11-17 Thread Owen Pan via cfe-commits

https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/72520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix crashes in AlignArrayOfStructures (PR #72520)

2023-11-17 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/72520

>From efdf321e9447e8b3f1c27ccdf6da842107deb6dd Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 16 Nov 2023 06:36:41 -0800
Subject: [PATCH 1/3] [clang-format] Fix crashes in AlignArrayOfStructures

Fixed #55493.
Fixed #68431.
---
 clang/lib/Format/WhitespaceManager.cpp |  4 +++-
 clang/lib/Format/WhitespaceManager.h   |  2 +-
 clang/unittests/Format/FormatTest.cpp  | 18 ++
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 32d8b97cc8dadb1..3bc6915b8df0a70 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1316,6 +1316,8 @@ void 
WhitespaceManager::alignArrayInitializersRightJustified(
 auto Offset = std::distance(Cells.begin(), CellIter);
 for (const auto *Next = CellIter->NextColumnElement; Next;
  Next = Next->NextColumnElement) {
+  if (RowCount >= CellDescs.CellCounts.size())
+break;
   auto *Start = (Cells.begin() + RowCount * CellDescs.CellCounts[0]);
   auto *End = Start + Offset;
   ThisNetWidth = getNetWidth(Start, End, CellDescs.InitialSpaces);
@@ -1379,7 +1381,7 @@ void 
WhitespaceManager::alignArrayInitializersLeftJustified(
 auto Offset = std::distance(Cells.begin(), CellIter);
 for (const auto *Next = CellIter->NextColumnElement; Next;
  Next = Next->NextColumnElement) {
-  if (RowCount > CellDescs.CellCounts.size())
+  if (RowCount >= CellDescs.CellCounts.size())
 break;
   auto *Start = (Cells.begin() + RowCount * CellDescs.CellCounts[0]);
   auto *End = Start + Offset;
diff --git a/clang/lib/Format/WhitespaceManager.h 
b/clang/lib/Format/WhitespaceManager.h
index df7e9add1cd446f..69398fe411502f1 100644
--- a/clang/lib/Format/WhitespaceManager.h
+++ b/clang/lib/Format/WhitespaceManager.h
@@ -317,7 +317,7 @@ class WhitespaceManager {
 auto Offset = std::distance(CellStart, CellStop);
 for (const auto *Next = CellStop->NextColumnElement; Next;
  Next = Next->NextColumnElement) {
-  if (RowCount > MaxRowCount)
+  if (RowCount >= MaxRowCount)
 break;
   auto Start = (CellStart + RowCount * CellCount);
   auto End = Start + Offset;
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index a12a20359c2fad2..cd4c93e8427723f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -21140,6 +21140,24 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresLeftAlignment) {
   "that really, in any just world, ought to be split over multiple "
   "lines\"},{-1, 93463, \"world\"},{7, 5, \"!!\"},};",
   Style);
+
+  Style.ColumnLimit = 25;
+  verifyNoCrash("Type object[X][Y] = {\n"
+"{{val}, {val}, {val}},\n"
+"{{val}, {val}, // some comment\n"
+"   {val}}\n"
+"};",
+Style);
+
+  Style.ColumnLimit = 120;
+  verifyNoCrash(
+  "T v[] {\n"
+  "{ A::aaa, "
+  "A::, 1, 0.0f, "
+  "\""
+  "\" },\n"
+  "};",
+  Style);
 }
 
 TEST_F(FormatTest, UnderstandsPragmas) {

>From 4a73cc6c52be6824d34f4ba5608a008a3dfdedf0 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 16 Nov 2023 18:46:23 -0800
Subject: [PATCH 2/3] Added tests from #54815 and #55269.

---
 clang/unittests/Format/FormatTest.cpp | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index cd4c93e8427723f..a579746fd4b68e8 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -20709,6 +20709,12 @@ TEST_F(FormatTest, CatchExceptionReferenceBinding) {
 TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) {
   auto Style = getLLVMStyle();
   Style.AlignArrayOfStructures = FormatStyle::AIAS_Right;
+
+  verifyNoCrash("f({\n"
+"table({}, table({{\"\", false}}, {}))\n"
+"});",
+Style);
+
   Style.AlignConsecutiveAssignments.Enabled = true;
   Style.AlignConsecutiveDeclarations.Enabled = true;
   verifyFormat("struct test demo[] = {\n"
@@ -21142,6 +21148,15 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresLeftAlignment) {
   Style);
 
   Style.ColumnLimit = 25;
+  verifyNoCrash("Type foo{\n"
+"{\n"
+"1,  // A\n"
+"2,  // B\n"
+"3,  // C\n"
+"},\n"
+"\"hello\",\n"
+"};",
+Style);
   ve

[clang] [clang-format] Fix crashes in AlignArrayOfStructures (PR #72520)

2023-11-17 Thread Owen Pan via cfe-commits

owenca wrote:

We probably should backport it to 17.0.6. What do you all think? @tru 

https://github.com/llvm/llvm-project/pull/72520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix crashes in AlignArrayOfStructures (PR #72520)

2023-11-17 Thread Owen Pan via cfe-commits

owenca wrote:

> @owenca I picked da1b1fba5cfd41521a840202d8cf4c3796c5e10b on top of the 17.x 
> branch and my test case was not fixed, it still crashes in the same way as 
> described in #72628

Thanks for trying it on 17.x. We can't backport it then.

https://github.com/llvm/llvm-project/pull/72520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix crashes in AlignArrayOfStructures (PR #72520)

2023-11-17 Thread Owen Pan via cfe-commits

https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/72520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix crashes in AlignArrayOfStructures (PR #72520)

2023-11-17 Thread Owen Pan via cfe-commits


@@ -20709,6 +20709,18 @@ TEST_F(FormatTest, CatchExceptionReferenceBinding) {
 TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) {
   auto Style = getLLVMStyle();
   Style.AlignArrayOfStructures = FormatStyle::AIAS_Right;
+
+  verifyNoCrash("f({\n"
+"table({}, table({{\"\", false}}, {}))\n"
+"});",
+Style);
+  verifyNoCrash("Bar a[1] = {\n"
+"#define buf(a, b) \\\n"
+"  { #a, #b },\n"
+"{ Test, bar }\n"
+"};",
+Style);

owenca wrote:

```suggestion
  verifyNoCrash("f({\n"
"table({}, table({{\"\", false}}, {}))\n"
"});",
Style);
```

https://github.com/llvm/llvm-project/pull/72520
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   5   6   7   8   9   10   >