[clang] [clang-format]: Fix formatting of if statements with BlockIndent (PR #77699)

2024-01-22 Thread Owen Pan via cfe-commits

https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/77699
___
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 ContinuationIndenter (PR #78921)

2024-01-22 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-01-22 Thread Owen Pan via cfe-commits


@@ -4842,19 +4842,19 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (Right.isNot(tok::l_paren)) {
+if (Right.isOneOf(tok::identifier, tok::numeric_constant)) {
   // The alternative operators for ~ and ! are "compl" and "not".
   // If they are used instead, we do not want to combine them with
   // the token to the right, unless that is a left paren.
   if (Left.is(tok::exclaim) && Left.TokenText == "not")
 return true;
   if (Left.is(tok::tilde) && Left.TokenText == "compl")
 return true;
-  // Lambda captures allow for a lone &, so "&]" needs to be properly
-  // handled.
-  if (Left.is(tok::amp) && Right.is(tok::r_square))
-return Style.SpacesInSquareBrackets;
 }
+// Lambda captures allow for a lone &, so "&]" needs to be properly
+// handled.
+if (Left.is(tok::amp) && Right.is(tok::r_square))
+  return Style.SpacesInSquareBrackets;
 return (Style.SpaceAfterLogicalNot && Left.is(tok::exclaim)) ||
Right.is(TT_BinaryOperator);

owenca wrote:

```suggestion
return Style.SpaceAfterLogicalNot && Left.is(tok::exclaim);
```
Would this suffice?

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-01-22 Thread Owen Pan via cfe-commits


@@ -24160,6 +24160,14 @@ TEST_F(FormatTest, AlternativeOperators) {
   verifyFormat("int a compl(5);");
   verifyFormat("int a not(5);");
 
+  verifyFormat("v(not)");
+  verifyFormat("v(not!)");
+  verifyFormat("Symbol(not, None)");
+  verifyFormat("Symbol(not!, None)");
+
+  verifyFormat("assert(!\"fail\")");
+  verifyFormat("assert(not\"fail\")");

owenca wrote:

We should drop  them as they are invalid code (i.e. trigger compiler warnings).

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-01-22 Thread Owen Pan via cfe-commits


@@ -4842,19 +4842,19 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (Right.isNot(tok::l_paren)) {
+if (Right.isOneOf(tok::identifier, tok::numeric_constant)) {
   // The alternative operators for ~ and ! are "compl" and "not".
   // If they are used instead, we do not want to combine them with
   // the token to the right, unless that is a left paren.

owenca wrote:

The comment needs to be updated.

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


[clang] [clang-format] BreakAfterAttributes did not take into account gnu attributes (PR #78102)

2024-01-22 Thread Owen Pan via cfe-commits

owenca wrote:

> You either have to use a new option, or adapt the documentation. Latter 
> clearly only refers to `C++11 attributes`, which `__attribute__(())` isn't.
> 
> I don't think a new option is needed.
> 
> When you are already at it, you may also consider handling `__declspec()`.

+1.

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


[clang] Improved is simple type specifier (PR #78903)

2024-01-22 Thread Owen Pan via cfe-commits

owenca wrote:

> Here's the sort of approach I"m looking at @owenca

Can you restore the clang-format files for this pull request? I'll open another 
PR that depends on this one.

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


[clang] [flang] [lld] [clang-tools-extra] [llvm] [libcxx] [lldb] [mlir] [compiler-rt] [clang-format] Add ShortReturnTypeColumn option. (PR #78011)

2024-01-21 Thread Owen Pan via cfe-commits

owenca wrote:

> @mydeveloperday, do you have an opinion on this pull request? It addresses 
> #78010 with minimal changes, or are you interested in exploring other 
> possibilities?

It's weird to add such a top-level option to fix a bug and keep the current 
behavior. See 
https://github.com/llvm/llvm-project/issues/78010#issuecomment-1903300176.

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


[clang] [clang-format] Allow decltype in requires clause (PR #78847)

2024-01-21 Thread Owen Pan via cfe-commits


@@ -1071,6 +1071,16 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
 "concept C = (!Foo) && Bar;");
   ASSERT_EQ(Tokens.size(), 19u) << Tokens;
   EXPECT_TOKEN(Tokens[15], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("void f() & requires(C) {}");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("auto f() -> int& requires(C) {}");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[7], tok::kw_requires, TT_RequiresClause);
 }

owenca wrote:

> The fix I would originally do was just look behind again and see if the ) 
> belongs to a decltype, I just also tried removing the case entirely, and was 
> surprised it works. If you prefer, I can follow my original plan and add an 
> extra check for decltype

In general, I prefer to not include code that can't be reached by test cases as 
the code is likely superfluous. Because @HazardyKnusperkeks is ok with its 
removal, wouldn't be better to just do that?

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


[clang] [clang-format] Allow decltype in requires clause (PR #78847)

2024-01-21 Thread Owen Pan via cfe-commits


@@ -1071,6 +1071,37 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
 "concept C = (!Foo) && Bar;");
   ASSERT_EQ(Tokens.size(), 19u) << Tokens;
   EXPECT_TOKEN(Tokens[15], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("void f() & requires(C) {}");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("auto f() -> int& requires(C) {}");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[7], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("int foo(auto t) {\n"
+"if (requires (decltype(t) x) {x.foo();}) {\n"
+"return 1;\n"
+"}\n"
+"return 0;\n"
+"}\n");

owenca wrote:

Do we need the newline?

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


[clang] [clang-format] Allow decltype in requires clause (PR #78847)

2024-01-21 Thread Owen Pan via cfe-commits


@@ -1071,6 +1071,16 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
 "concept C = (!Foo) && Bar;");

owenca wrote:

+1. You don't even need to create a pull request for this kind of NFC changes.

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


[clang] [clang-format] Add SpacesInParensOption for attributes and filtering for repeated parens (PR #77522)

2024-01-21 Thread Owen Pan via cfe-commits

owenca wrote:

> > It seems adding a boolean sub-option that targets double pairs of 
> > parentheses as I suggested before is feasible although a better name than 
> > `ConsecutiveParentheses` may be needed.
> 
> I'm fine to fix but request a concrete suggestion or proposal before I spend 
> much more time on this. It might also work to suppress optionally the 
> additional space on the first/last parenthesis pair, for these special 
> "paired" parens. I think the way I already worked this patch is the right way 
> to go to preserve backward compatibility while still allowing control over 
> the repeated parentheses.
> 
> Looks like it is called `MultipleParentheses` in the `RemoveParentheses` 
> option. I should rename to that.

My idea was:
- Keep the existing boolean suboptions and add a new one. Let's call it 
`ExceptDoubleParentheses` for now.
- If it's set to true, assuming all other suboptions are set to true, the above 
examples would be formatted as:
```
__attribute__(( noreturn ))
__attribute__(( __aligned__( x ) ))

if (( i = j ))
if ( ( i = j ) && ( k > 3 ) ) // not affected by ExceptDoubleParentheses

decltype(( x ))

while ( ( ( i + 1 ) * j - 2 ) * k > 3 ) // not affected by 
ExceptDoubleParentheses
```
- If it's set to false, assuming all other suboptions are set to true, the 
above examples would be formatted as:
```
__attribute__( ( noreturn ) )
__attribute__( ( __aligned__( x ) ) )

if ( ( i = j ) )
if ( ( i = j ) && ( k > 3 ) ) // not affected by ExceptDoubleParentheses

decltype( ( x ) )

while ( ( ( i + 1 ) * j - 2 ) * k > 3 ) // not affected by 
ExceptDoubleParentheses
```

This way, we would avoid making all suboptions an `enum` and repeating 
`NonConsecutive` in every suboption.

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


[clang] [clang-format]: Fix formatting of if statements with BlockIndent (PR #77699)

2024-01-21 Thread Owen Pan via cfe-commits

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


https://github.com/llvm/llvm-project/pull/77699
___
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 ContinuationIndenter (PR #78921)

2024-01-21 Thread Owen Pan via cfe-commits

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

Fixes #76991.

>From bc3f566b7c512434179241796a2d7d4ac3e7b381 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 21 Jan 2024 17:14:53 -0800
Subject: [PATCH] [clang-format] Fix a bug in ContinuationIndenter

Fixes #76991.
---
 clang/lib/Format/ContinuationIndenter.cpp | 3 ++-
 clang/lib/Format/WhitespaceManager.h  | 2 +-
 clang/unittests/Format/FormatTest.cpp | 7 +++
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index e6eaaa9ab45706..c204cc81331521 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -738,7 +738,8 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
, bool DryRun,
 
   if (!DryRun) {
 Whitespaces.replaceWhitespace(Current, /*Newlines=*/0, Spaces,
-  State.Column + Spaces + PPColumnCorrection);
+  State.Column + Spaces + PPColumnCorrection,
+  /*IsAligned=*/false, 
State.Line->InMacroBody);
   }
 
   // If "BreakBeforeInheritanceComma" mode, don't break within the inheritance
diff --git a/clang/lib/Format/WhitespaceManager.h 
b/clang/lib/Format/WhitespaceManager.h
index dc6f60e5deeedf..8ac73305871ae7 100644
--- a/clang/lib/Format/WhitespaceManager.h
+++ b/clang/lib/Format/WhitespaceManager.h
@@ -55,7 +55,7 @@ class WhitespaceManager {
   /// this replacement. It is needed for determining how \p Spaces is turned
   /// into tabs and spaces for some format styles.
   void replaceWhitespace(FormatToken , unsigned Newlines, unsigned Spaces,
- unsigned StartOfTokenColumn, bool isAligned = false,
+ unsigned StartOfTokenColumn, bool IsAligned = false,
  bool InPPDirective = false);
 
   /// Adds information about an unchangeable token's whitespace.
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 3fb55ae2c1f413..a42a254d61d419 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -21203,6 +21203,13 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresLeftAlignment) {
"});",
Style);
 
+  Style.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign;
+  verifyFormat("#define FOO \\\n"
+   "  int foo[][2] = { \\\n"
+   "  {0, 1} \\\n"
+   "  };",
+   Style);
+
   Style.Cpp11BracedListStyle = false;
   verifyFormat("struct test demo[] = {\n"
"  { 56, 23,\"hello\" },\n"

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


[clang] [clang-format] Add SpacesInParensOption for attributes and filtering for repeated parens (PR #77522)

2024-01-21 Thread Owen Pan via cfe-commits

owenca wrote:

> > Would `__attribute__((noreturn))`, `if ((i = j))`, `decltype((x))`, and 
> > `while (((i + 1) * j - 2) * k > 3)` be formatted as `__attribute__(( 
> > noreturn ))`, `if (( i = j ))`, `decltype(( x ))`, and `while ( ( ( i + 1 ) 
> > * j - 2 ) * k > 3 )`, respectively?
> 
> Almost, it would also be `if ( ( i = j ) )`, Although repeated parens are 
> typically removed. So a better example is `if ( ( i = j ) && ( k > 3 ) )`
> 
> We don't have `decltype` in our C code base. I can add support for it as an 
> option if desired.
> 
> We also have cases such as `__attribute__(( __aligned__( x ) ))`

I'm ok with all of the above except for `if ( ( i = j ) )`, which should be 
formatted as `if (( i = j ))` because the extra pair of parentheses is not 
superfluous. This is similar to `decltype(( x))`, and the`RemoveParentheses` 
option doesn't strip the extra pair for either.

It seems adding a boolean sub-option that targets double pairs of parentheses 
as I suggested before is feasible although a better name than 
`ConsecutiveParentheses` may be needed.

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


[clang] [clang-format] Add SpacesInParensOption for attributes and filtering for repeated parens (PR #77522)

2024-01-20 Thread Owen Pan via cfe-commits

owenca wrote:

> The code is [self-hosted](https://git.rtems.org/rtems/) and [mirrored on 
> GitHub](https://github.com/RTEMS/rtems) with a [documented style 
> guide](https://docs.rtems.org/branches/master/eng/coding-formatting.html). In 
> addition, I have been and will continue to be willing to provide bug fix and 
> other maintenance support to clang-format based on the changes submitted to 
> support these style needs.
> 
> At the moment, I need to satisfy a particular style rule that requires me to 
> add spaces inside of conditional and compound expressions.

It seems the RTEMS style guide you linked above doesn't have any examples for 
conditional expressions and compound expressions, and by _conditional 
expressions_ I assume it means conditionals of control statements rather than 
ternary [conditional 
expressions](https://www.ibm.com/docs/en/zos/3.1.0?topic=operators-conditional-expressions).

Would `__attribute__((noreturn))`, `if ((i = j))`, `decltype((x))`, and `while 
(((i + 1) * j - 2) * k > 3)` be formatted as `__attribute__(( noreturn ))`, `if 
(( i = j ))`, `decltype(( x ))`, and `while ( ( ( i + 1 ) * j - 2 ) * k > 3 )`, 
respectively?

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


[clang] [clang-format] Handle templated elaborated type specifier in function… (PR #77013)

2024-01-20 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Handle templated elaborated type specifier in function… (PR #77013)

2024-01-20 Thread Owen Pan via cfe-commits


@@ -3873,6 +3873,9 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   const FormatToken  = *FormatTok;
   nextToken();
 
+  auto IsNonMacroIdentifier = [](FormatToken *Tok) {

owenca wrote:

Nit:
```suggestion
  auto IsNonMacroIdentifier = [](const FormatToken *Tok) {
```

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


[clang] [clang-format]: Fix formatting of if statements with BlockIndent (PR #77699)

2024-01-20 Thread Owen Pan via cfe-commits


@@ -768,15 +768,25 @@ void 
ContinuationIndenter::addTokenOnCurrentLine(LineState , bool DryRun,
   // parenthesis by disallowing any further line breaks if there is no line
   // break after the opening parenthesis. Don't break if it doesn't conserve
   // columns.
+  const auto IsOpeningBracket = [&](const FormatToken ) {
+const auto IsStartOfBracedList = [&]() {
+  return Tok.is(tok::l_brace) && Tok.isNot(BK_Block) &&
+ Style.Cpp11BracedListStyle;
+};
+if (Tok.isOneOf(tok::l_paren, TT_TemplateOpener, tok::l_square) ||
+IsStartOfBracedList()) {
+  if (!Tok.Previous)
+return true;
+  if (Tok.Previous->isIf())
+return Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak;
+  return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
+tok::kw_switch);
+}
+return false;

owenca wrote:

```suggestion
if (!Tok.isOneOf(tok::l_paren, TT_TemplateOpener, tok::l_square) &&
!IsStartOfBracedList()) {
  return false;
}
if (!Tok.Previous)
  return true;
if (Tok.Previous->isIf())
  return Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak;
return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
  tok::kw_switch);
```

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


[clang] [clang-format]: Fix formatting of if statements with BlockIndent (PR #77699)

2024-01-20 Thread Owen Pan via cfe-commits


@@ -768,15 +768,25 @@ void 
ContinuationIndenter::addTokenOnCurrentLine(LineState , bool DryRun,
   // parenthesis by disallowing any further line breaks if there is no line
   // break after the opening parenthesis. Don't break if it doesn't conserve
   // columns.
+  const auto IsOpeningBracket = [&](const FormatToken ) {
+const auto IsStartOfBracedList = [&]() {

owenca wrote:

```suggestion
  auto IsOpeningBracket = [&](const FormatToken ) {
auto IsStartOfBracedList = [&]() {
```

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


[clang] [clang-format] Add SpacesInParensOption for attributes and filtering for repeated parens (PR #77522)

2024-01-20 Thread Owen Pan via cfe-commits

owenca wrote:

> Covering all double parens in a single sub-option is not precise enough for 
> code bases that may want to have `__attribute__(( x ))` but also allow `if ( 
> ( x ) )`.

We should not go overboard with supporting all kinds of options/suboptions 
imaginable. I don't think we should support spaces between consecutive parens 
in the first place, which was likely a bug.

We can't just disregard the long-standing 
[policy](https://clang.llvm.org/docs/ClangFormatStyleOptions.html#adding-additional-style-options)
 on adding new options. If anyone thinks that policy is outdated, they should 
go through the RFC process and get it updated.

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


[clang] [clang-format] Handle templated elaborated type specifier in function… (PR #77013)

2024-01-20 Thread Owen Pan via cfe-commits


@@ -14583,9 +14583,10 @@ TEST_F(FormatTest, 
UnderstandContextOfRecordTypeKeywords) {
   verifyFormat("template <> struct X < 15, i<3 && 42 < 50 && 33 < 28> {};");
   verifyFormat("int i = SomeFunction(a b);");
 
-  // FIXME:
-  // This now gets parsed incorrectly as class definition.
-  // verifyFormat("class A f() {\n}\nint n;");
+  verifyFormat("class A f() {}\nint n;");
+  verifyFormat("template  class A f() {}\nint n;");
+
+  verifyFormat("template <> class Foo F() {\n} n;");

owenca wrote:

Please wrap after newlines.

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


[clang] [clang-format] Fix poor spacing in `AlignArrayOfStructures: Left` (PR #77868)

2024-01-20 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Fix poor spacing in `AlignArrayOfStructures: Left` (PR #77868)

2024-01-20 Thread Owen Pan via cfe-commits

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


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


[clang] [clang-format] Fix poor spacing in `AlignArrayOfStructures: Left` (PR #77868)

2024-01-20 Thread Owen Pan via cfe-commits


@@ -1366,11 +1366,12 @@ void 
WhitespaceManager::alignArrayInitializersLeftJustified(
   auto  = CellDescs.Cells;
   // Now go through and fixup the spaces.
   auto *CellIter = Cells.begin();
-  // The first cell needs to be against the left brace.
-  if (Changes[CellIter->Index].NewlinesBefore == 0)
-Changes[CellIter->Index].Spaces = BracePadding;
-  else
-Changes[CellIter->Index].Spaces = CellDescs.InitialSpaces;
+  // The first cell of every row needs to be against the left brace.
+  for (const auto *Next = CellIter; Next; Next = Next->NextColumnElement)
+if (Changes[Next->Index].NewlinesBefore == 0)
+  Changes[Next->Index].Spaces = BracePadding;
+else
+  Changes[Next->Index].Spaces = CellDescs.InitialSpaces;

owenca wrote:

```suggestion
  for (const auto *Next = CellIter; Next; Next = Next->NextColumnElement) {
auto  = Changes[Next->Index];
Change.Spaces = Change.NewlinesBefore == 0 ? BracePadding : 
CellDescs.InitialSpaces;
  }
```

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


[clang] [clang-format] Add MainIncludeChar option. (PR #78752)

2024-01-20 Thread Owen Pan via cfe-commits


@@ -0,0 +1,27 @@
+// Test the combination of regrouped include directives, via regexes and

owenca wrote:

> Ok I will move them there, thanks :) Should I remove these lit tests or are 
> they complementary?

Please remove them from the lit tests.

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


[clang] [llvm] [clang-tools-extra] [clang-format] Option to ignore macro definitions (PR #70338)

2024-01-20 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Add SkipMacroDefinitionBody option (PR #78682)

2024-01-20 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Add SkipMacroDefinitionBody option (PR #78682)

2024-01-19 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Add SkipMacroDefinitionBody option (PR #78682)

2024-01-19 Thread Owen Pan via cfe-commits

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

Closes #67991.

Co-authored-by: @tomekpaszek

>From 620e614b242055c3b8cbd81efd9bbc64a0ee4e56 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 18 Jan 2024 23:34:13 -0800
Subject: [PATCH] [clang-format] Option to ignore macro definitions

---
 clang/docs/ClangFormatStyleOptions.rst |   5 +
 clang/docs/ReleaseNotes.rst|   1 +
 clang/include/clang/Format/Format.h|   5 +
 clang/lib/Format/Format.cpp|   2 +
 clang/lib/Format/UnwrappedLineParser.cpp   |   9 ++
 clang/unittests/Format/ConfigParseTest.cpp |   1 +
 clang/unittests/Format/FormatTest.cpp  | 132 +
 7 files changed, 155 insertions(+)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 8bc13e45bf2f5f..4dc0de3a90f265 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4999,6 +4999,11 @@ the configuration (without a prefix: ``Auto``).
int bar;   int bar;
  } // namespace b   } // namespace b
 
+.. _SkipMacroDefinitionBody:
+
+**SkipMacroDefinitionBody** (``Boolean``) :versionbadge:`clang-format 18` 
:ref:`¶ `
+  Do not format macro definition body.
+
 .. _SortIncludes:
 
 **SortIncludes** (``SortIncludesOptions``) :versionbadge:`clang-format 3.8` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b400d75095421c..1045fd6b92346b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1202,6 +1202,7 @@ clang-format
 - Add ``PenaltyBreakScopeResolution`` option.
 - Add ``.clang-format-ignore`` files.
 - Add ``AlignFunctionPointers`` sub-option for 
``AlignConsecutiveDeclarations``.
+- Add ``SkipMacroDefinitionBody`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 6fd7947bd21791..bc9eecd42f9ebf 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3932,6 +3932,10 @@ struct FormatStyle {
   /// \version 13
   unsigned ShortNamespaceLines;
 
+  /// Do not format macro definition body.
+  /// \version 18
+  bool SkipMacroDefinitionBody;
+
   /// Include sorting options.
   enum SortIncludesOptions : int8_t {
 /// Includes are never sorted.
@@ -4895,6 +4899,7 @@ struct FormatStyle {
RequiresExpressionIndentation == R.RequiresExpressionIndentation &&
SeparateDefinitionBlocks == R.SeparateDefinitionBlocks &&
ShortNamespaceLines == R.ShortNamespaceLines &&
+   SkipMacroDefinitionBody == R.SkipMacroDefinitionBody &&
SortIncludes == R.SortIncludes &&
SortJavaStaticImport == R.SortJavaStaticImport &&
SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 7c2f4dcf3d2308..ff326dc784783b 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1085,6 +1085,7 @@ template <> struct MappingTraits {
Style.RequiresExpressionIndentation);
 IO.mapOptional("SeparateDefinitionBlocks", Style.SeparateDefinitionBlocks);
 IO.mapOptional("ShortNamespaceLines", Style.ShortNamespaceLines);
+IO.mapOptional("SkipMacroDefinitionBody", Style.SkipMacroDefinitionBody);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
 IO.mapOptional("SortJavaStaticImport", Style.SortJavaStaticImport);
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
@@ -1556,6 +1557,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.RequiresExpressionIndentation = FormatStyle::REI_OuterScope;
   LLVMStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Leave;
   LLVMStyle.ShortNamespaceLines = 1;
+  LLVMStyle.SkipMacroDefinitionBody = false;
   LLVMStyle.SortIncludes = FormatStyle::SI_CaseSensitive;
   LLVMStyle.SortJavaStaticImport = FormatStyle::SJSIO_Before;
   LLVMStyle.SortUsingDeclarations = FormatStyle::SUD_LexicographicNumeric;
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 50d41c9f57a670..c08ce86449b6ea 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1170,6 +1170,15 @@ void UnwrappedLineParser::parsePPDefine() {
   assert((int)Line->PPLevel >= 0);
   Line->InMacroBody = true;
 
+  if (Style.SkipMacroDefinitionBody) {
+do {
+  FormatTok->Finalized = true;
+  nextToken();
+} while (!eof());
+addUnwrappedLine();
+return;
+  }
+
   if (FormatTok->is(tok::identifier) &&
   Tokens->peekNextToken()->is(tok::colon)) {
 nextToken();
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index 172aaab5988ce5..2a8d79359a49b4 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ 

[clang-tools-extra] [clang] [llvm] [clang-format] Option to ignore macro definitions (PR #70338)

2024-01-18 Thread Owen Pan via cfe-commits

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

>From 25ca978ef9caf372997f2ebf227fb2b2ca443aa0 Mon Sep 17 00:00:00 2001
From: Tomek Paszek 
Date: Sat, 11 Nov 2023 19:38:00 +0100
Subject: [PATCH 01/15] Added an option to ignore macro definitions.

---
 clang/include/clang/Format/Format.h |  5 +
 clang/lib/Format/Format.cpp |  2 ++
 clang/lib/Format/UnwrappedLineFormatter.cpp |  2 ++
 clang/unittests/Format/ConfigParseTest.cpp  |  3 ++-
 clang/unittests/Format/FormatTest.cpp   | 16 
 5 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 37cb3b5cc06732..fce68d70f4dd69 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2512,6 +2512,10 @@ struct FormatStyle {
   /// 
`_
   /// \version 13
   std::vector IfMacros;
+  
+  /// Ignore formatting in preprocessor definitions.
+  /// \version 18
+  bool IgnorePPDefinitions;
 
   /// Specify whether access modifiers should have their own indentation level.
   ///
@@ -4790,6 +4794,7 @@ struct FormatStyle {
R.IncludeStyle.IncludeIsMainRegex &&
IncludeStyle.IncludeIsMainSourceRegex ==
R.IncludeStyle.IncludeIsMainSourceRegex &&
+   IgnorePPDefinitions == R.IgnorePPDefinitions &&
IndentAccessModifiers == R.IndentAccessModifiers &&
IndentCaseBlocks == R.IndentCaseBlocks &&
IndentCaseLabels == R.IndentCaseLabels &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index db0cb8a3108495..a6e451595527e7 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1002,6 +1002,7 @@ template <> struct MappingTraits {
 IO.mapOptional("FixNamespaceComments", Style.FixNamespaceComments);
 IO.mapOptional("ForEachMacros", Style.ForEachMacros);
 IO.mapOptional("IfMacros", Style.IfMacros);
+IO.mapOptional("IgnorePPDefinitions", Style.IgnorePPDefinitions);
 IO.mapOptional("IncludeBlocks", Style.IncludeStyle.IncludeBlocks);
 IO.mapOptional("IncludeCategories", Style.IncludeStyle.IncludeCategories);
 IO.mapOptional("IncludeIsMainRegex", 
Style.IncludeStyle.IncludeIsMainRegex);
@@ -1507,6 +1508,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.ForEachMacros.push_back("Q_FOREACH");
   LLVMStyle.ForEachMacros.push_back("BOOST_FOREACH");
   LLVMStyle.IfMacros.push_back("KJ_IF_MAYBE");
+  LLVMStyle.IgnorePPDefinitions = false;
   LLVMStyle.IncludeStyle.IncludeCategories = {
   {"^\"(llvm|llvm-c|clang|clang-c)/", 2, 0, false},
   {"^(<|\"(gtest|gmock|isl|json)/)", 3, 0, false},
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 280485d9a90d1b..bbf6383ff7673f 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1355,6 +1355,8 @@ unsigned UnwrappedLineFormatter::format(
 bool FixIndentation = (FixBadIndentation || ContinueFormatting) &&
   Indent != TheLine.First->OriginalColumn;
 bool ShouldFormat = TheLine.Affected || FixIndentation;
+if (Style.IgnorePPDefinitions && TheLine.Type == LT_PreprocessorDirective)
+  ShouldFormat = false;
 // We cannot format this line; if the reason is that the line had a
 // parsing error, remember that.
 if (ShouldFormat && TheLine.Type == LT_Invalid && Status) {
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index 0c9f68f303d865..fa4e1469e8cc13 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -167,6 +167,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(DerivePointerAlignment);
   CHECK_PARSE_BOOL_FIELD(DerivePointerAlignment, "DerivePointerBinding");
   CHECK_PARSE_BOOL(DisableFormat);
+  CHECK_PARSE_BOOL(IgnorePPDefinitions);
   CHECK_PARSE_BOOL(IndentAccessModifiers);
   CHECK_PARSE_BOOL(IndentCaseLabels);
   CHECK_PARSE_BOOL(IndentCaseBlocks);
@@ -199,7 +200,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(SpaceBeforeRangeBasedForLoopColon);
   CHECK_PARSE_BOOL(SpaceBeforeSquareBrackets);
   CHECK_PARSE_BOOL(VerilogBreakBetweenInstancePorts);
-
+  
   CHECK_PARSE_NESTED_BOOL(AlignConsecutiveShortCaseStatements, Enabled);
   CHECK_PARSE_NESTED_BOOL(AlignConsecutiveShortCaseStatements,
   AcrossEmptyLines);
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 420afe5992f2a0..e04ffc146404f1 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24219,6 +24219,22 @@ TEST_F(FormatTest, WhitespaceSensitiveMacros) {
   

[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-01-16 Thread Owen Pan via cfe-commits

owenca wrote:

This should work:
```
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4402,9 +4402,17 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
   if (Left.Finalized)
 return Right.hasWhitespaceBefore();
 
-  // Never ever merge two words.
-  if (Keywords.isWordLike(Right) && Keywords.isWordLike(Left))
-return true;
+  if (Style.isVerilog()) {
+if (Keywords.isWordLike(Left) && Keywords.isWordLike(Right))
+  return true;
+  } else {
+auto IsWordOrNumber = [](const auto ) {
+  return Tok.Tok.getIdentifierInfo() || Tok.is(tok::numeric_constant);
+};
+// Never ever merge two words/numbers.
+if (IsWordOrNumber(Left) && IsWordOrNumber(Right))
+  return true;
+  }
 
   // Leave a space between * and /* to avoid C4138 `comment end` found outside
   // of comment.
@@ -4842,21 +4850,11 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (Right.isNot(tok::l_paren)) {
-  // The alternative operators for ~ and ! are "compl" and "not".
-  // If they are used instead, we do not want to combine them with
-  // the token to the right, unless that is a left paren.
-  if (Left.is(tok::exclaim) && Left.TokenText == "not")
-return true;
-  if (Left.is(tok::tilde) && Left.TokenText == "compl")
-return true;
-  // Lambda captures allow for a lone &, so "&]" needs to be properly
-  // handled.
-  if (Left.is(tok::amp) && Right.is(tok::r_square))
-return Style.SpacesInSquareBrackets;
-}
-return (Style.SpaceAfterLogicalNot && Left.is(tok::exclaim)) ||
-   Right.is(TT_BinaryOperator);
+// Lambda captures allow for a lone &, so "&]" needs to be properly
+// handled.
+if (Left.is(tok::amp) && Right.is(tok::r_square))
+  return Style.SpacesInSquareBrackets;
+return Style.SpaceAfterLogicalNot && Left.is(tok::exclaim);
   }
 
   // If the next token is a binary operator or a selector name, we have
```

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-01-15 Thread Owen Pan via cfe-commits

owenca wrote:

> I think this is kind of too specific.

+1.

> Also I agree with [#78166 
> (comment)](https://github.com/llvm/llvm-project/issues/78166#issuecomment-1892311219)
>  that `WhitespaceSensitiveMacros` should be used.

I don't think we should require that the option be used.

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


[clang] [clang-format] adds a space after not inside macros (PR #78176)

2024-01-15 Thread Owen Pan via cfe-commits


@@ -4842,7 +4842,7 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 return true;
   }
   if (Left.is(TT_UnaryOperator)) {
-if (Right.isNot(tok::l_paren)) {
+if (!Right.isOneOf(tok::r_paren, tok::l_paren, tok::exclaim)) {

owenca wrote:

> The only exception I see are identifiers and numeric literals (as they will 
> combine the tokens together):
> 
> ```c++
> v(not x)
> v(not 1)
> v(not 123.f)
> ```

+1.

> Should this condition be something like `if (Right.isOneOf(tok::ident, /*... 
> numeric literals*/))`? Or will this cause us to not add spaces in undesired 
> places?
> 
> If we can avoid those spaces for only a limited set of tokens, I would 
> probably limit this to `tok::lparen` and `tok::rparen`, the rest seems much 
> less likely.

We should come up with a more general fix.

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


[clang] [clang-format][NFC] Use FileCheck for clang-format-ignore lit test (PR #77977)

2024-01-14 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Optimize processing .clang-format-ignore files (PR #76733)

2024-01-12 Thread Owen Pan via cfe-commits

owenca wrote:

See #77977.

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


[clang] [clang-format][NFC] Use FileCheck for clang-format-ignore lit test (PR #77977)

2024-01-12 Thread Owen Pan via cfe-commits

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

None

>From 4f516c1ee4ab99af2c3135ca161a82e6428d3ee9 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 12 Jan 2024 12:30:17 -0800
Subject: [PATCH] [clang-format][NFC] Use FileCheck for clang-format-ignore lit
 test

---
 clang/test/Format/clang-format-ignore.cpp | 46 ---
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/clang/test/Format/clang-format-ignore.cpp 
b/clang/test/Format/clang-format-ignore.cpp
index 5a2267b302d22f..fb49fa9dd52c65 100644
--- a/clang/test/Format/clang-format-ignore.cpp
+++ b/clang/test/Format/clang-format-ignore.cpp
@@ -6,41 +6,45 @@
 // RUN: echo "level*/*.c*" >> .clang-format-ignore
 // RUN: echo "*/*2/foo.*" >> .clang-format-ignore
 // RUN: touch foo.cc
-// RUN: clang-format -verbose .clang-format-ignore foo.cc 2> %t.stderr
-// RUN: not grep Formatting %t.stderr
+// RUN: clang-format -verbose .clang-format-ignore foo.cc 2>&1 \
+// RUN:   | FileCheck %s -allow-empty
 
 // RUN: cd level1
 // RUN: touch bar.cc baz.c
-// RUN: clang-format -verbose bar.cc baz.c 2> %t.stderr
-// RUN: not grep Formatting %t.stderr
+// RUN: clang-format -verbose bar.cc baz.c 2>&1 | FileCheck %s -allow-empty
 
 // RUN: cd level2
 // RUN: touch foo.c foo.js
-// RUN: clang-format -verbose foo.c foo.js 2> %t.stderr
-// RUN: not grep Formatting %t.stderr
+// RUN: clang-format -verbose foo.c foo.js 2>&1 | FileCheck %s -allow-empty
+
+// CHECK-NOT: Formatting
 
 // RUN: touch .clang-format-ignore
-// RUN: clang-format -verbose foo.c foo.js 2> %t.stderr
-// RUN: grep -Fx "Formatting [1/2] foo.c" %t.stderr
-// RUN: grep -Fx "Formatting [2/2] foo.js" %t.stderr
+// RUN: clang-format -verbose foo.c foo.js 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=CHECK2 -match-full-lines
+// CHECK2: Formatting [1/2] foo.c
+// CHECK2-NEXT: Formatting [2/2] foo.js
 
 // RUN: echo "*.js" > .clang-format-ignore
-// RUN: clang-format -verbose foo.c foo.js 2> %t.stderr
-// RUN: grep -Fx "Formatting [1/2] foo.c" %t.stderr
-// RUN: not grep -F foo.js %t.stderr
+// RUN: clang-format -verbose foo.c foo.js 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=CHECK3 -match-full-lines
+// CHECK3: Formatting [1/2] foo.c
+// CHECK3-NOT: foo.js
 
 // RUN: cd ../..
-// RUN: clang-format -verbose *.cc level1/*.c* level1/level2/foo.* 2> %t.stderr
-// RUN: grep -x "Formatting \[1/5] .*foo\.c" %t.stderr
-// RUN: not grep -F foo.js %t.stderr
+// RUN: clang-format -verbose *.cc level1/*.c* level1/level2/foo.* 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=CHECK4 -match-full-lines
+// CHECK4: {{Formatting \[1/5] .*foo\.c}}
+// CHECK4-NOT: foo.js
 
 // RUN: rm .clang-format-ignore
-// RUN: clang-format -verbose *.cc level1/*.c* level1/level2/foo.* 2> %t.stderr
-// RUN: grep -x "Formatting \[1/5] .*foo\.cc" %t.stderr
-// RUN: grep -x "Formatting \[2/5] .*bar\.cc" %t.stderr
-// RUN: grep -x "Formatting \[3/5] .*baz\.c" %t.stderr
-// RUN: grep -x "Formatting \[4/5] .*foo\.c" %t.stderr
-// RUN: not grep -F foo.js %t.stderr
+// RUN: clang-format -verbose *.cc level1/*.c* level1/level2/foo.* 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=CHECK5 -match-full-lines
+// CHECK5: {{Formatting \[1/5] .*foo\.cc}}
+// CHECK5-NEXT: {{Formatting \[2/5] .*bar\.cc}}
+// CHECK5-NEXT: {{Formatting \[3/5] .*baz\.c}}
+// CHECK5-NEXT: {{Formatting \[4/5] .*foo\.c}}
+// CHECK5-NOT: foo.js
 
 // RUN: cd ..
 // RUN: rm -r %t.dir

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


[clang] [clang-format] Handle possible crash in `getCells` (PR #77723)

2024-01-12 Thread Owen Pan via cfe-commits

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


[clang] [Format] Fix isStartOfName to recognize attributes (PR #76804)

2024-01-12 Thread Owen Pan via cfe-commits

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


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


[clang] [clang-format] Add SpaceInParensOption for __attribute__ keyword (PR #77522)

2024-01-11 Thread Owen Pan via cfe-commits

owenca wrote:

> The __attribute((specifier-list)) currently is formatted based on the 
> SpacesInParensOptions.Other (previously, SpacesInParentheses). This change 
> allows finer control over addition of spaces between the consecutive parens, 
> and between the inner parens and the list of attribute specifiers.
> 
> Differential Revision: https://reviews.llvm.org/D155529
> 
> This is migrated from Phabricator, see more discussion there.

I expressed my opinion there:

> I would have no problem if this new option is extended to handle all double 
> parens, e.g. if (( i = j )), decltype(( x )), etc.

So I still prefer that we have a boolean suboption (e.g. 
`ConsecutiveParentheses`) that covers all double parens.

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


[clang] [clang-format] Optimize processing .clang-format-ignore files (PR #76733)

2024-01-10 Thread Owen Pan via cfe-commits

owenca wrote:

> This still breaks tests on win: http://45.33.8.238/win/88113/step_7.txt

I didn't get any email for the failure. Is this a regular LLVM buildbot?

If it chokes on `grep -Fx`, can you (or whoever has access to it) install a 
POSIX-compliant grep? It seems all other Windows buildbots got no problems.

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


[clang] [clang-format] Don't allow casts in front of ampamp (PR #77704)

2024-01-10 Thread Owen Pan via cfe-commits

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


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


[clang] [clang-format] Handle possible crash in `getCells` (PR #77723)

2024-01-10 Thread Owen Pan via cfe-commits

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


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


[clang] [clang-format] Fix crash involving array designators (PR #77045)

2024-01-10 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Fix crash involving array designators (PR #77045)

2024-01-10 Thread Owen Pan via cfe-commits

owenca wrote:

> While I was trying to find a minimal reproducer to the bug, I accidentally 
> found that this patch fix another crash, and doesn't fix the linked issue.

Can you open another pull request to 
[fix](https://github.com/llvm/llvm-project/pull/77045#discussion_r1442578220) 
the other crash?
```
```

https://github.com/llvm/llvm-project/pull/77045
___
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)

2024-01-10 Thread Owen Pan via cfe-commits

https://github.com/owenca closed 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] Don't apply severe penalty if no possible column formats (PR #76675)

2024-01-10 Thread Owen Pan via cfe-commits

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


[clang] [ClangFormat] Fix formatting bugs. (PR #76245)

2024-01-10 Thread Owen Pan via cfe-commits

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


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


[clang] [clang-format] Do not update cursor pos if no includes replacement (PR #77456)

2024-01-10 Thread Owen Pan via cfe-commits

owenca wrote:

> The change is done  Is the code formatting check broken?

See 
[here](https://github.com/llvm/llvm-project/pull/76059#issuecomment-1865850011).

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


[clang] c69ec70 - [clang-format][NFC] Don't use clang-format style in config files

2024-01-10 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2024-01-10T00:58:35-08:00
New Revision: c69ec700adec315b3daa55742f2ef655242fa297

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

LOG: [clang-format][NFC] Don't use clang-format style in config files

The current CI doesn't use the latest clang-format and fails most
clang-format patches on the code formatting check. This patch
temporarily removes the clang-format style from the .clang-format
files.

Added: 


Modified: 
clang/include/clang/Format/.clang-format
clang/lib/Format/.clang-format
clang/tools/clang-format/.clang-format
clang/unittests/Format/.clang-format

Removed: 




diff  --git a/clang/include/clang/Format/.clang-format 
b/clang/include/clang/Format/.clang-format
index d7331b3c8cf02e..f95602cab0f7fc 100644
--- a/clang/include/clang/Format/.clang-format
+++ b/clang/include/clang/Format/.clang-format
@@ -1 +1,6 @@
-BasedOnStyle: clang-format
+BasedOnStyle: LLVM
+InsertBraces: true
+InsertNewlineAtEOF: true
+LineEnding: LF
+RemoveBracesLLVM: true
+RemoveParentheses: ReturnStatement

diff  --git a/clang/lib/Format/.clang-format b/clang/lib/Format/.clang-format
index d7331b3c8cf02e..f95602cab0f7fc 100644
--- a/clang/lib/Format/.clang-format
+++ b/clang/lib/Format/.clang-format
@@ -1 +1,6 @@
-BasedOnStyle: clang-format
+BasedOnStyle: LLVM
+InsertBraces: true
+InsertNewlineAtEOF: true
+LineEnding: LF
+RemoveBracesLLVM: true
+RemoveParentheses: ReturnStatement

diff  --git a/clang/tools/clang-format/.clang-format 
b/clang/tools/clang-format/.clang-format
index d7331b3c8cf02e..f95602cab0f7fc 100644
--- a/clang/tools/clang-format/.clang-format
+++ b/clang/tools/clang-format/.clang-format
@@ -1 +1,6 @@
-BasedOnStyle: clang-format
+BasedOnStyle: LLVM
+InsertBraces: true
+InsertNewlineAtEOF: true
+LineEnding: LF
+RemoveBracesLLVM: true
+RemoveParentheses: ReturnStatement

diff  --git a/clang/unittests/Format/.clang-format 
b/clang/unittests/Format/.clang-format
index d7331b3c8cf02e..f95602cab0f7fc 100644
--- a/clang/unittests/Format/.clang-format
+++ b/clang/unittests/Format/.clang-format
@@ -1 +1,6 @@
-BasedOnStyle: clang-format
+BasedOnStyle: LLVM
+InsertBraces: true
+InsertNewlineAtEOF: true
+LineEnding: LF
+RemoveBracesLLVM: true
+RemoveParentheses: ReturnStatement



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


[clang] [clang-format] Optimize processing .clang-format-ignore files (PR #76733)

2024-01-10 Thread Owen Pan via cfe-commits

owenca wrote:

Relanded as b53628a52d19. (See 
[here](https://github.com/llvm/llvm-project/commit/42ec976184acd40436acd7104ad715c60ca3e7ed#commitcomment-136674701)).

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


[clang] b53628a - Reland "[clang-format] Optimize processing .clang-format-ignore files"

2024-01-09 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2024-01-09T21:34:21-08:00
New Revision: b53628a52d1947c51e250d6fa4ff5dd12b737aa0

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

LOG: Reland "[clang-format] Optimize processing .clang-format-ignore files"

(42ec976184ac was reverted by 26993f61673e due to a use-after-scope bug.)

Reuse the patterns governing the previous input file being formatted if
the current input file is from the same directory.

Added: 


Modified: 
clang/docs/ClangFormat.rst
clang/test/Format/clang-format-ignore.cpp
clang/tools/clang-format/ClangFormat.cpp

Removed: 




diff  --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index 8d4017b29fb8ee..819d9ee9f9cde1 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -131,6 +131,9 @@ An easy way to create the ``.clang-format`` file is:
 
 Available style options are described in :doc:`ClangFormatStyleOptions`.
 
+.clang-format-ignore
+
+
 You can create ``.clang-format-ignore`` files to make ``clang-format`` ignore
 certain files. A ``.clang-format-ignore`` file consists of patterns of file 
path
 names. It has the following format:
@@ -141,7 +144,8 @@ names. It has the following format:
 * A non-comment line is a single pattern.
 * The slash (``/``) is used as the directory separator.
 * A pattern is relative to the directory of the ``.clang-format-ignore`` file
-  (or the root directory if the pattern starts with a slash).
+  (or the root directory if the pattern starts with a slash). Patterns
+  containing drive names (e.g. ``C:``) are not supported.
 * Patterns follow the rules specified in `POSIX 2.13.1, 2.13.2, and Rule 1 of
   2.13.3 `_.

diff  --git a/clang/test/Format/clang-format-ignore.cpp 
b/clang/test/Format/clang-format-ignore.cpp
index 0d6396a64a668d..5a2267b302d22f 100644
--- a/clang/test/Format/clang-format-ignore.cpp
+++ b/clang/test/Format/clang-format-ignore.cpp
@@ -21,13 +21,26 @@
 
 // RUN: touch .clang-format-ignore
 // RUN: clang-format -verbose foo.c foo.js 2> %t.stderr
-// RUN: grep "Formatting \[1/2] foo.c" %t.stderr
-// RUN: grep "Formatting \[2/2] foo.js" %t.stderr
+// RUN: grep -Fx "Formatting [1/2] foo.c" %t.stderr
+// RUN: grep -Fx "Formatting [2/2] foo.js" %t.stderr
 
 // RUN: echo "*.js" > .clang-format-ignore
 // RUN: clang-format -verbose foo.c foo.js 2> %t.stderr
-// RUN: grep "Formatting \[1/2] foo.c" %t.stderr
-// RUN: not grep "Formatting \[2/2] foo.js" %t.stderr
+// RUN: grep -Fx "Formatting [1/2] foo.c" %t.stderr
+// RUN: not grep -F foo.js %t.stderr
 
-// RUN: cd ../../..
-// RUN: rm -rf %t.dir
+// RUN: cd ../..
+// RUN: clang-format -verbose *.cc level1/*.c* level1/level2/foo.* 2> %t.stderr
+// RUN: grep -x "Formatting \[1/5] .*foo\.c" %t.stderr
+// RUN: not grep -F foo.js %t.stderr
+
+// RUN: rm .clang-format-ignore
+// RUN: clang-format -verbose *.cc level1/*.c* level1/level2/foo.* 2> %t.stderr
+// RUN: grep -x "Formatting \[1/5] .*foo\.cc" %t.stderr
+// RUN: grep -x "Formatting \[2/5] .*bar\.cc" %t.stderr
+// RUN: grep -x "Formatting \[3/5] .*baz\.c" %t.stderr
+// RUN: grep -x "Formatting \[4/5] .*foo\.c" %t.stderr
+// RUN: not grep -F foo.js %t.stderr
+
+// RUN: cd ..
+// RUN: rm -r %t.dir

diff  --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index be34dbbe886a15..49ab7677a3ee9c 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -571,6 +571,11 @@ static int dumpConfig(bool IsSTDIN) {
   return 0;
 }
 
+using String = SmallString<128>;
+static String IgnoreDir; // Directory of .clang-format-ignore file.
+static String PrevDir;   // Directory of previous `FilePath`.
+static SmallVector Patterns; // Patterns in .clang-format-ignore file.
+
 // Check whether `FilePath` is ignored according to the nearest
 // .clang-format-ignore file based on the rules below:
 // - A blank line is skipped.
@@ -586,33 +591,50 @@ static bool isIgnored(StringRef FilePath) {
   if (!is_regular_file(FilePath))
 return false;
 
-  using namespace llvm::sys::path;
-  SmallString<128> Path, AbsPath{FilePath};
+  String Path;
+  String AbsPath{FilePath};
 
+  using namespace llvm::sys::path;
   make_absolute(AbsPath);
   remove_dots(AbsPath, /*remove_dot_dot=*/true);
 
-  StringRef IgnoreDir{AbsPath};
-  do {
-IgnoreDir = parent_path(IgnoreDir);
-if (IgnoreDir.empty())
+  if (StringRef Dir{parent_path(AbsPath)}; PrevDir != Dir) {
+PrevDir = Dir;
+
+for (;;) {
+  Path = Dir;
+  append(Path, ".clang-format-ignore");
+  if (is_regular_file(Path))
+break;
+  Dir = parent_path(Dir);
+  if 

[clang] [clang-format] Fix crash involving array designators (PR #77045)

2024-01-09 Thread Owen Pan via cfe-commits

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


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


[clang] [clang-format] Fix crash involving array designators (PR #77045)

2024-01-09 Thread Owen Pan via cfe-commits


@@ -2315,6 +2315,8 @@ bool UnwrappedLineParser::tryToParseLambdaIntroducer() {
 if (Next->is(tok::greater))
   return false;
   }
+  if (tok::isLiteral(FormatTok->Tok.getKind()))
+return false;

owenca wrote:

You are right! Then how about the following?
```
  if (FormatTok->is(tok::l_square) || tok::isLiteral(FormatTok->Tok.getKind()))
```
The main point is to return as early as possible.

https://github.com/llvm/llvm-project/pull/77045
___
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)

2024-01-09 Thread Owen Pan via cfe-commits


@@ -1079,6 +1079,7 @@ clang-format
 - Add ``ObjCPropertyAttributeOrder`` which can be used to sort ObjC property
   attributes (like ``nonatomic, strong, nullable``).
 - Add ``.clang-format-ignore`` files.
+- Add ``AlignFunctionPointers`` sub-option for 
``AlignConsecutiveDeclarations''.

owenca wrote:

```suggestion
- Add ``AlignFunctionPointers`` sub-option for ``AlignConsecutiveDeclarations``.
```

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]: Split alignment of declarations around assignment (PR #69340)

2024-01-09 Thread Owen Pan via cfe-commits

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


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] [ClangFormat] Fix formatting bugs. (PR #76245)

2024-01-09 Thread Owen Pan via cfe-commits


@@ -255,6 +255,41 @@ TEST_F(FormatTestMacroExpansion,
  Style);
 }
 
+TEST_F(FormatTestMacroExpansion, CommaAsOperator) {
+  FormatStyle Style = getGoogleStyle();
+  Style.ColumnLimit = 42;
+  Style.Macros.push_back("MACRO(a, b, c)=a=(b); if(x) c");
+  verifyFormat("MACRO(auto a,\n"
+   "  longfunction(first, second,\n"
+   "   third),\n"
+   "  fourth);",
+   Style);
+}
+
+TEST_F(FormatTestMacroExpansion, ForcedBreakDiffers) {
+  FormatStyle Style = getGoogleStyle();
+  Style.ColumnLimit = 40;
+  Style.Macros.push_back("MACRO(a, b)=a=(b)");
+  verifyFormat("//\n"
+   "MACRO(const type variable,\n"
+   "  functtioncall(\n"
+   "  first, longsecondarg, third));\n",

owenca wrote:

```suggestion
   "  first, longsecondarg, third));",
```

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


[clang] [ClangFormat] Fix formatting bugs. (PR #76245)

2024-01-09 Thread Owen Pan via cfe-commits


@@ -255,6 +255,41 @@ TEST_F(FormatTestMacroExpansion,
  Style);
 }
 
+TEST_F(FormatTestMacroExpansion, CommaAsOperator) {
+  FormatStyle Style = getGoogleStyle();
+  Style.ColumnLimit = 42;
+  Style.Macros.push_back("MACRO(a, b, c)=a=(b); if(x) c");
+  verifyFormat("MACRO(auto a,\n"
+   "  longfunction(first, second,\n"
+   "   third),\n"
+   "  fourth);",
+   Style);
+}
+
+TEST_F(FormatTestMacroExpansion, ForcedBreakDiffers) {
+  FormatStyle Style = getGoogleStyle();
+  Style.ColumnLimit = 40;
+  Style.Macros.push_back("MACRO(a, b)=a=(b)");
+  verifyFormat("//\n"
+   "MACRO(const type variable,\n"
+   "  functtioncall(\n"
+   "  first, longsecondarg, third));\n",
+   Style);
+}
+
+TEST_F(FormatTestMacroExpansion,
+   PreferNotBreakingBetweenReturnTypeAndFunction) {
+  FormatStyle Style = getGoogleStyle();
+  Style.ColumnLimit = 22;
+  Style.Macros.push_back("MOCK_METHOD(r, n, a)=r n a");
+  // In the expanded code, we parse a full function signature, and afterwards
+  // know that we prefer not to break before the function name.
+  verifyFormat("MOCK_METHOD(\n"
+   "type, variable,\n"
+   "(type));\n",

owenca wrote:

Ditto.

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


[clang] [ClangFormat] Fix formatting bugs. (PR #76245)

2024-01-09 Thread Owen Pan via cfe-commits


@@ -255,6 +255,41 @@ TEST_F(FormatTestMacroExpansion,
  Style);
 }
 
+TEST_F(FormatTestMacroExpansion, CommaAsOperator) {
+  FormatStyle Style = getGoogleStyle();
+  Style.ColumnLimit = 42;
+  Style.Macros.push_back("MACRO(a, b, c)=a=(b); if(x) c");
+  verifyFormat("MACRO(auto a,\n"
+   "  longfunction(first, second,\n"
+   "   third),\n"
+   "  fourth);",
+   Style);
+}
+
+TEST_F(FormatTestMacroExpansion, ForcedBreakDiffers) {
+  FormatStyle Style = getGoogleStyle();
+  Style.ColumnLimit = 40;

owenca wrote:

Ditto.

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


[clang] [ClangFormat] Fix formatting bugs. (PR #76245)

2024-01-09 Thread Owen Pan via cfe-commits


@@ -255,6 +255,41 @@ TEST_F(FormatTestMacroExpansion,
  Style);
 }
 
+TEST_F(FormatTestMacroExpansion, CommaAsOperator) {
+  FormatStyle Style = getGoogleStyle();
+  Style.ColumnLimit = 42;
+  Style.Macros.push_back("MACRO(a, b, c)=a=(b); if(x) c");
+  verifyFormat("MACRO(auto a,\n"
+   "  longfunction(first, second,\n"
+   "   third),\n"
+   "  fourth);",
+   Style);
+}
+
+TEST_F(FormatTestMacroExpansion, ForcedBreakDiffers) {
+  FormatStyle Style = getGoogleStyle();
+  Style.ColumnLimit = 40;
+  Style.Macros.push_back("MACRO(a, b)=a=(b)");
+  verifyFormat("//\n"
+   "MACRO(const type variable,\n"
+   "  functtioncall(\n"
+   "  first, longsecondarg, third));\n",
+   Style);
+}
+
+TEST_F(FormatTestMacroExpansion,
+   PreferNotBreakingBetweenReturnTypeAndFunction) {
+  FormatStyle Style = getGoogleStyle();
+  Style.ColumnLimit = 22;

owenca wrote:

Ditto.

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


[clang] [ClangFormat] Fix formatting bugs. (PR #76245)

2024-01-09 Thread Owen Pan via cfe-commits


@@ -255,6 +255,41 @@ TEST_F(FormatTestMacroExpansion,
  Style);
 }
 
+TEST_F(FormatTestMacroExpansion, CommaAsOperator) {
+  FormatStyle Style = getGoogleStyle();
+  Style.ColumnLimit = 42;

owenca wrote:

```suggestion
  FormatStyle Style = getGoogleStyleWithColumns(42);
```

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


[clang] [clang-format] Fix crash involving array designators (PR #77045)

2024-01-09 Thread Owen Pan via cfe-commits

owenca wrote:

Please add an assertion in `WhitespaceManager.h`:
```
--- a/clang/lib/Format/WhitespaceManager.h
+++ b/clang/lib/Format/WhitespaceManager.h
@@ -282,6 +282,7 @@ private:
 for (auto PrevIter = Start; PrevIter != End; ++PrevIter) {
   // If we broke the line the initial spaces are already
   // accounted for.
+  assert(PrevIter->Index) < Changes.size();
   if (Changes[PrevIter->Index].NewlinesBefore > 0)
 NetWidth = 0;
   NetWidth +=
```

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


[clang] [clang-format] Fix crash involving array designators (PR #77045)

2024-01-09 Thread Owen Pan via cfe-commits


@@ -2315,6 +2315,8 @@ bool UnwrappedLineParser::tryToParseLambdaIntroducer() {
 if (Next->is(tok::greater))
   return false;
   }
+  if (tok::isLiteral(FormatTok->Tok.getKind()))
+return false;

owenca wrote:

```suggestion
```
Instead, I would change line 2311 to:
```
  if (FormatTok->isOneOf(tok::l_square, tok::numeric_constant))
```

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


[clang] [clang-format] Don't apply severe penalty if no possible column formats (PR #76675)

2024-01-09 Thread Owen Pan via cfe-commits

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


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


[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-08 Thread Owen Pan via cfe-commits


@@ -1444,16 +1444,26 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
   } else if (C.Tok->is(tok::comma)) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
-if (C.Tok->getNextNonComment()->isNot(tok::r_brace)) // dangling comma
+
+if (const auto *Next = C.Tok->getNextNonComment();
+Next && Next->isNot(tok::r_brace)) { // Dangling comma.
   ++Cell;
+}
   }
 } else if (Depth == 1) {
   if (C.Tok == MatchingParen) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
 Cells.push_back(CellDescription{i, ++Cell, i + 1, false, nullptr});
-CellCounts.push_back(C.Tok->Previous->isNot(tok::comma) ? Cell + 1
-: Cell);
+CellCounts.push_back(
+C.Tok->Previous->isNot(tok::comma) &&
+// When dealing with C array designators. There is a
+// possibility of some nested array not having an `=`.
+// When this happens we make the cells non rectangular,
+// avoiding an access out of bound later on.
+MatchingParen->MatchingParen->Previous->isNot(tok::equal)

owenca wrote:

Yep, so we should fix that instead. :)

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


[clang] [Format] Fix isStartOfName to recognize attributes (PR #76804)

2024-01-08 Thread Owen Pan via cfe-commits


@@ -8498,9 +8498,6 @@ TEST_F(FormatTest, 
BreaksFunctionDeclarationsWithTrailingTokens) {
"__attribute__((unused));");
 
   Style = getGoogleStyle();
-  ASSERT_THAT(Style.AttributeMacros,

owenca wrote:

Please also delete line 10:
```
#include "gmock/gmock.h"
```

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


[clang] [Format] Fix isStartOfName to recognize attributes (PR #76804)

2024-01-08 Thread Owen Pan via cfe-commits


@@ -2209,7 +2209,8 @@ class AnnotatingParser {
 (!NextNonComment && !Line.InMacroBody) ||
 (NextNonComment &&
  (NextNonComment->isPointerOrReference() ||
-  NextNonComment->isOneOf(tok::identifier, tok::string_literal {
+  (Line.InPragmaDirective &&
+   NextNonComment->isOneOf(tok::identifier, tok::string_literal) {

owenca wrote:

```suggestion
  NextNonComment->is(tok::string_literal) ||
  (Line.InPragmaDirective && NextNonComment->is(tok::identifier) {
```

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


[clang] [Format] Fix isStartOfName to recognize attributes (PR #76804)

2024-01-08 Thread Owen Pan via cfe-commits

owenca wrote:

> > can you also add a test to clang/unittests/Format/TokenAnnotatorTest.cpp 
> > that ensures trailing attribute-like macros receive `StartOfName` 
> > annotation to make sure we don't regress the signal in the future?
> 
> ok, that opened a whole can of worms.
> 
> ```
>  Tokens = annotate("void foo GUARDED_BY(x)");
> ```
> 
> gets annotated as
> 
> ```
> {(void, "void" , Unknown),
>   (identifier, "foo" , StartOfName),
>   (identifier, "GUARDED_BY" , FunctionDeclarationName),
>   (l_paren, "(" , Unknown),
>   (identifier, "x" , Unknown),
>   (r_paren, ")" , Unknown),
>   (eof, "" , Unknown)}
> ```
> 
> I expected to get some heuristics for attributes, but instead `GUARDED_BY` 
> gets annotated as a function declaration name. It feels that the current 
> behavior is a result of two mistakes cancelling each other out. I don't think 
> adding a unit test like this is warranted, even if formatting behavior is 
> actually correct.
> 
> @owenca what are your thoughts on this change and whether we should add a 
> test here?

We usually add a FIXME test wrapped in a `#if 0` block:
```
// FIXME: ...
#if 0
Tokens = annotate("void foo GUARDED_BY(x);");
...
Tokens = annotate("void foo GUARDED_BY(x) {}");
...
#endif
```

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


[clang] [Format] Fix isStartOfName to recognize attributes (PR #76804)

2024-01-08 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Break after string literals with trailing line breaks (PR #76795)

2024-01-08 Thread Owen Pan via cfe-commits

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


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


[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-08 Thread Owen Pan via cfe-commits


@@ -1444,16 +1444,26 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
   } else if (C.Tok->is(tok::comma)) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
-if (C.Tok->getNextNonComment()->isNot(tok::r_brace)) // dangling comma
+
+if (const auto *Next = C.Tok->getNextNonComment();
+Next && Next->isNot(tok::r_brace)) { // Dangling comma.
   ++Cell;
+}
   }
 } else if (Depth == 1) {
   if (C.Tok == MatchingParen) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
 Cells.push_back(CellDescription{i, ++Cell, i + 1, false, nullptr});
-CellCounts.push_back(C.Tok->Previous->isNot(tok::comma) ? Cell + 1
-: Cell);
+CellCounts.push_back(
+C.Tok->Previous->isNot(tok::comma) &&
+// When dealing with C array designators. There is a
+// possibility of some nested array not having an `=`.
+// When this happens we make the cells non rectangular,
+// avoiding an access out of bound later on.
+MatchingParen->MatchingParen->Previous->isNot(tok::equal)

owenca wrote:

This seems a little hacky. We should probably investigate a bit more to find 
the root cause.

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


[clang] [clang-format] Break after string literals with trailing line breaks (PR #76795)

2024-01-06 Thread Owen Pan via cfe-commits


@@ -2499,6 +2499,15 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   EXPECT_BRACE_KIND(Tokens[6], BK_Block);
 }
 
+TEST_F(TokenAnnotatorTest, StreamOperator) {
+  auto Tokens = annotate("\"foo\\n\" << aux << \"foo\\n\" << \"foo\";");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_FALSE(Tokens[1]->MustBreakBefore);
+  EXPECT_FALSE(Tokens[3]->MustBreakBefore);
+  // Only break between string literals if the former ends with \n.
+  EXPECT_TRUE(Tokens[5]->MustBreakBefore);
+}
+

owenca wrote:

Ok, let’s keep it then.

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


[clang] [clang-tools-extra] [llvm] [mlir] [emacs] Fix Emacs library formatting (PR #76110)

2024-01-06 Thread Owen Pan via cfe-commits

owenca wrote:

@darkfeline I'm ok with adding the Version comment in 
clang/tools/clang-format/clang-format.el, but you may have to explicitly 
request others to review the rest of the patch.

https://github.com/llvm/llvm-project/pull/76110
___
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)

2024-01-06 Thread Owen Pan via cfe-commits


@@ -76,40 +76,49 @@ template <> struct 
MappingTraits {
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/false, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));

owenca wrote:

```suggestion
 /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
```

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]: Split alignment of declarations around assignment (PR #69340)

2024-01-06 Thread Owen Pan via cfe-commits


@@ -978,7 +978,14 @@ void WhitespaceManager::alignConsecutiveDeclarations() {
 
   AlignTokens(
   Style,
-  [](Change const ) {
+  [&](Change const ) {
+if (Style.AlignConsecutiveDeclarations.AlignFunctionPointers) {
+  for (FormatToken *Prev = C.Tok->Previous; Prev; Prev = 
Prev->Previous)

owenca wrote:

```suggestion
  for (const auto *Prev = C.Tok->Previous; Prev; Prev = Prev->Previous)
```

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]: Split alignment of declarations around assignment (PR #69340)

2024-01-06 Thread Owen Pan via cfe-commits


@@ -225,6 +225,22 @@ struct FormatStyle {
 ///   bbb = 2;
 /// \endcode
 bool AlignCompound;
+/// Only for ``AlignConsecutiveDeclarations``. Whether function pointers
+/// are aligned.

owenca wrote:

```suggestion
/// Only for ``AlignConsecutiveDeclarations``. Whether function pointers are
/// aligned.
```
Please regenerate the rst file after reflowing the comment.

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]: Split alignment of declarations around assignment (PR #69340)

2024-01-06 Thread Owen Pan via cfe-commits


@@ -76,40 +76,49 @@ template <> struct 
MappingTraits {
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/false, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
 IO.enumCase(Value, "Consecutive",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));

owenca wrote:

Ditto.

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]: Split alignment of declarations around assignment (PR #69340)

2024-01-06 Thread Owen Pan via cfe-commits

https://github.com/owenca edited 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]: Split alignment of declarations around assignment (PR #69340)

2024-01-06 Thread Owen Pan via cfe-commits


@@ -76,40 +76,49 @@ template <> struct 
MappingTraits {
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/false, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
 IO.enumCase(Value, "Consecutive",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
 IO.enumCase(Value, "AcrossEmptyLines",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/true,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
-IO.enumCase(Value, "AcrossComments",
-FormatStyle::AlignConsecutiveStyle({/*Enabled=*/true,
-/*AcrossEmptyLines=*/false,
-/*AcrossComments=*/true,
-/*AlignCompound=*/false,
-/*PadOperators=*/true}));
-IO.enumCase(Value, "AcrossEmptyLinesAndComments",
-FormatStyle::AlignConsecutiveStyle({/*Enabled=*/true,
-/*AcrossEmptyLines=*/true,
-/*AcrossComments=*/true,
-/*AlignCompound=*/false,
-/*PadOperators=*/true}));
+IO.enumCase(
+Value, "AcrossComments",
+FormatStyle::AlignConsecutiveStyle({/*Enabled=*/true,
+/*AcrossEmptyLines=*/false,
+/*AcrossComments=*/true,
+/*AlignCompound=*/false,
+/*AlignFunctionPointers=*/false,
+/*PadOperators=*/true}));
+IO.enumCase(
+Value, "AcrossEmptyLinesAndComments",
+FormatStyle::AlignConsecutiveStyle({/*Enabled=*/true,
+/*AcrossEmptyLines=*/true,
+/*AcrossComments=*/true,
+/*AlignCompound=*/false,
+/*AlignFunctionPointers=*/false,
+/*PadOperators=*/true}));
 
 // For backward compatibility.
 IO.enumCase(Value, "true",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));

owenca wrote:

Ditto.

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]: Split alignment of declarations around assignment (PR #69340)

2024-01-06 Thread Owen Pan via cfe-commits


@@ -76,40 +76,49 @@ template <> struct 
MappingTraits {
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/false, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
 IO.enumCase(Value, "Consecutive",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
 IO.enumCase(Value, "AcrossEmptyLines",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/true,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
-IO.enumCase(Value, "AcrossComments",
-FormatStyle::AlignConsecutiveStyle({/*Enabled=*/true,
-/*AcrossEmptyLines=*/false,
-/*AcrossComments=*/true,
-/*AlignCompound=*/false,
-/*PadOperators=*/true}));
-IO.enumCase(Value, "AcrossEmptyLinesAndComments",
-FormatStyle::AlignConsecutiveStyle({/*Enabled=*/true,
-/*AcrossEmptyLines=*/true,
-/*AcrossComments=*/true,
-/*AlignCompound=*/false,
-/*PadOperators=*/true}));
+IO.enumCase(
+Value, "AcrossComments",
+FormatStyle::AlignConsecutiveStyle({/*Enabled=*/true,
+/*AcrossEmptyLines=*/false,
+/*AcrossComments=*/true,
+/*AlignCompound=*/false,
+/*AlignFunctionPointers=*/false,
+/*PadOperators=*/true}));
+IO.enumCase(
+Value, "AcrossEmptyLinesAndComments",
+FormatStyle::AlignConsecutiveStyle({/*Enabled=*/true,
+/*AcrossEmptyLines=*/true,
+/*AcrossComments=*/true,
+/*AlignCompound=*/false,
+/*AlignFunctionPointers=*/false,
+/*PadOperators=*/true}));
 
 // For backward compatibility.
 IO.enumCase(Value, "true",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
 IO.enumCase(Value, "false",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/false, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));

owenca wrote:

Ditto.

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]: Split alignment of declarations around assignment (PR #69340)

2024-01-06 Thread Owen Pan via cfe-commits


@@ -76,40 +76,49 @@ template <> struct 
MappingTraits {
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/false, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
 IO.enumCase(Value, "Consecutive",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));
 IO.enumCase(Value, "AcrossEmptyLines",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/true,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AlignFunctionPointers=*/false,
  /*PadOperators=*/true}));

owenca wrote:

Ditto.

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]: Split alignment of declarations around assignment (PR #69340)

2024-01-06 Thread Owen Pan via cfe-commits

https://github.com/owenca commented:

Please also update the release notes. LGTM otherwise.

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]: Split alignment of declarations around assignment (PR #69340)

2024-01-05 Thread Owen Pan via cfe-commits

owenca wrote:

> @owenca this waits for re-review

Can you rebase the patch?

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] Break after string literals with trailing line breaks (PR #76795)

2024-01-05 Thread Owen Pan via cfe-commits


@@ -2499,6 +2499,15 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   EXPECT_BRACE_KIND(Tokens[6], BK_Block);
 }
 
+TEST_F(TokenAnnotatorTest, StreamOperator) {
+  auto Tokens = annotate("\"foo\\n\" << aux << \"foo\\n\" << \"foo\";");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_FALSE(Tokens[1]->MustBreakBefore);
+  EXPECT_FALSE(Tokens[3]->MustBreakBefore);
+  // Only break between string literals if the former ends with \n.
+  EXPECT_TRUE(Tokens[5]->MustBreakBefore);
+}
+

owenca wrote:

I understand, but `TokenAnnotatorTest` is mainly for testing token types and 
has never been used for checking `MustBreakBefore` and other similar token 
attributes. @HazardyKnusperkeks @rymiel @mydeveloperday what do you think?

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


[clang] [clang-format] Break after string literals with trailing line breaks (PR #76795)

2024-01-05 Thread Owen Pan via cfe-commits


@@ -5151,6 +5151,14 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
,
 return true;
   if (Left.IsUnterminatedLiteral)
 return true;
+  // FIXME: Breaking after newlines seems useful in general. Turn this into an
+  // option and recognize more cases like endl etc, and break independent of
+  // what comes after operator lessless.
+  if (Right.is(tok::lessless) && Right.Next &&
+  Right.Next->is(tok::string_literal) && Left.is(tok::string_literal) &&
+  Left.TokenText.ends_with("\\n\"")) {

owenca wrote:

We can also handle `\n` and `endl` now. For example:
```suggestion
  Right.Next->is(tok::string_literal) &&
  ((Left.is(tok::string_literal) && Left.TokenText.ends_with("\\n\"")) ||
   Left.TokenText == "'\\n'" || Left.TokenText == "endl")) {
```

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


[clang] [clang-format] Break after string literals with trailing line breaks (PR #76795)

2024-01-05 Thread Owen Pan via cfe-commits


@@ -2499,6 +2499,15 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   EXPECT_BRACE_KIND(Tokens[6], BK_Block);
 }
 
+TEST_F(TokenAnnotatorTest, StreamOperator) {
+  auto Tokens = annotate("\"foo\\n\" << aux << \"foo\\n\" << \"foo\";");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_FALSE(Tokens[1]->MustBreakBefore);
+  EXPECT_FALSE(Tokens[3]->MustBreakBefore);
+  // Only break between string literals if the former ends with \n.
+  EXPECT_TRUE(Tokens[5]->MustBreakBefore);
+}
+

owenca wrote:

Can you delete this test or move it to FormatTest.cpp?

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


[clang] [clang-format] Break after string literals with trailing line breaks (PR #76795)

2024-01-05 Thread Owen Pan via cfe-commits


@@ -5151,6 +5151,14 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
,
 return true;
   if (Left.IsUnterminatedLiteral)
 return true;
+  // FIXME: Breaking after newlines seems useful in general. Turn this into an
+  // option and Recognize more cases like endl etc, and break independent of
+  // what comes after operator lessless.
+  if (Right.is(tok::lessless) && Right.Next && Left.is(tok::string_literal) &&
+  Right.Next->is(tok::string_literal) &&

owenca wrote:

```suggestion
  // option and recognize more cases like endl etc, and break independent of
  // what comes after operator lessless.
  if (Right.is(tok::lessless) && Right.Next &&
  Right.Next->is(tok::string_literal) && Left.is(tok::string_literal) &&
```

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


[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-05 Thread Owen Pan via cfe-commits


@@ -1444,7 +1444,8 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
   } else if (C.Tok->is(tok::comma)) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
-if (C.Tok->getNextNonComment()->isNot(tok::r_brace)) // dangling comma
+const FormatToken *Next = C.Tok->getNextNonComment();
+if (Next && Next->isNot(tok::r_brace)) // dangling comma
   ++Cell;

owenca wrote:

```suggestion
if (const auto *Next = C.Tok->getNextNonComment();
Next && Next->isNot(tok::r_brace)) { // dangling comma
  ++Cell;
}
```

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


[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-05 Thread Owen Pan via cfe-commits


@@ -21084,6 +21084,12 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresLeftAlignment) {
   "};",
   Style);
 
+  verifyNoCrash("Foo f[] = {\n"
+"[0] = { 1, },\n"
+"[1] { 1, },\n"
+"};",
+Style);

owenca wrote:

We should also add it to `CatchAlignArrayOfStructuresRightAlignment`.

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


[clang] [clang-format] Add .clang-format-ignore for ignoring files (PR #76327)

2024-01-04 Thread Owen Pan via cfe-commits

owenca wrote:

Actually, it's commit 42ec976184ac. Please see 
[here](https://github.com/llvm/llvm-project/pull/76733#issuecomment-1876707005).

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


[clang] [clang-format] Optimize processing .clang-format-ignore files (PR #76733)

2024-01-04 Thread Owen Pan via cfe-commits

owenca wrote:

It had passed my local tests (x64 Native Tools Command Prompt for VS 2022) and 
the buildkite win build, so I wonder if it has something to do with the grep in 
the failed buildbot (only 
https://lab.llvm.org/buildbot/#/builders/123/builds/23808 so far) as I only 
used the POSIX options -F and -x. Should I turn it off for Windows like we did 
to 
[style-on-command-line.cpp](https://github.com/llvm/llvm-project/blob/8c72ff716b3e4b298695fa3faf6add860c6dbcb2/clang/test/Format/style-on-command-line.cpp#L50)?

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


[clang] [clang-format] Optimize processing .clang-format-ignore files (PR #76733)

2024-01-03 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Optimize processing .clang-format-ignore files (PR #76733)

2024-01-03 Thread Owen Pan via cfe-commits

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

>From 7f8da18dc59706df8f1ee15d22076b4794881579 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 1 Jan 2024 19:10:30 -0800
Subject: [PATCH 1/2] [clang-format] Optimize processing .clang-format-ignore
 files

Reuse the patterns governing the previous input file being formatted if the
the current input file is from the same directory.
---
 clang/docs/ClangFormat.rst|  6 ++-
 clang/test/Format/clang-format-ignore.cpp | 17 +-
 clang/tools/clang-format/ClangFormat.cpp  | 65 ---
 3 files changed, 65 insertions(+), 23 deletions(-)

diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index 8d4017b29fb8ee..819d9ee9f9cde1 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -131,6 +131,9 @@ An easy way to create the ``.clang-format`` file is:
 
 Available style options are described in :doc:`ClangFormatStyleOptions`.
 
+.clang-format-ignore
+
+
 You can create ``.clang-format-ignore`` files to make ``clang-format`` ignore
 certain files. A ``.clang-format-ignore`` file consists of patterns of file 
path
 names. It has the following format:
@@ -141,7 +144,8 @@ names. It has the following format:
 * A non-comment line is a single pattern.
 * The slash (``/``) is used as the directory separator.
 * A pattern is relative to the directory of the ``.clang-format-ignore`` file
-  (or the root directory if the pattern starts with a slash).
+  (or the root directory if the pattern starts with a slash). Patterns
+  containing drive names (e.g. ``C:``) are not supported.
 * Patterns follow the rules specified in `POSIX 2.13.1, 2.13.2, and Rule 1 of
   2.13.3 `_.
diff --git a/clang/test/Format/clang-format-ignore.cpp 
b/clang/test/Format/clang-format-ignore.cpp
index 0d6396a64a668d..4d0c4073308edc 100644
--- a/clang/test/Format/clang-format-ignore.cpp
+++ b/clang/test/Format/clang-format-ignore.cpp
@@ -29,5 +29,18 @@
 // RUN: grep "Formatting \[1/2] foo.c" %t.stderr
 // RUN: not grep "Formatting \[2/2] foo.js" %t.stderr
 
-// RUN: cd ../../..
-// RUN: rm -rf %t.dir
+// RUN: cd ../..
+// RUN: clang-format -verbose *.cc level1/*.c* level1/level2/foo.* 2> %t.stderr
+// RUN: grep "Formatting \[1/5] level1/level2/foo.c" %t.stderr
+// RUN: not grep "Formatting \[2/5] level1/level2/foo.js" %t.stderr
+
+// RUN: rm .clang-format-ignore
+// RUN: clang-format -verbose *.cc level1/*.c* level1/level2/foo.* 2> %t.stderr
+// RUN: grep "Formatting \[1/5] foo.cc" %t.stderr
+// RUN: grep "Formatting \[2/5] level1/bar.cc" %t.stderr
+// RUN: grep "Formatting \[3/5] level1/baz.c" %t.stderr
+// RUN: grep "Formatting \[4/5] level1/level2/foo.c" %t.stderr
+// RUN: not grep "Formatting \[5/5] level1/level2/foo.js" %t.stderr
+
+// RUN: cd ..
+// RUN: rm -r %t.dir
diff --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index be34dbbe886a15..787e56a6eccc0e 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -571,6 +571,11 @@ static int dumpConfig(bool IsSTDIN) {
   return 0;
 }
 
+using String = SmallString<128>;
+static String IgnoreDir; // Directory of .clang-format-ignore file.
+static StringRef PrevDir;// Directory of previous `FilePath`.
+static SmallVector Patterns; // Patterns in .clang-format-ignore file.
+
 // Check whether `FilePath` is ignored according to the nearest
 // .clang-format-ignore file based on the rules below:
 // - A blank line is skipped.
@@ -586,33 +591,50 @@ static bool isIgnored(StringRef FilePath) {
   if (!is_regular_file(FilePath))
 return false;
 
-  using namespace llvm::sys::path;
-  SmallString<128> Path, AbsPath{FilePath};
+  String Path;
+  String AbsPath{FilePath};
 
+  using namespace llvm::sys::path;
   make_absolute(AbsPath);
   remove_dots(AbsPath, /*remove_dot_dot=*/true);
 
-  StringRef IgnoreDir{AbsPath};
-  do {
-IgnoreDir = parent_path(IgnoreDir);
-if (IgnoreDir.empty())
+  if (StringRef Dir{parent_path(AbsPath)}; PrevDir != Dir) {
+PrevDir = Dir;
+
+for (;;) {
+  Path = Dir;
+  append(Path, ".clang-format-ignore");
+  if (is_regular_file(Path))
+break;
+  Dir = parent_path(Dir);
+  if (Dir.empty())
+return false;
+}
+
+IgnoreDir = convert_to_slash(Dir);
+
+std::ifstream IgnoreFile{Path.c_str()};
+if (!IgnoreFile.good())
   return false;
 
-Path = IgnoreDir;
-append(Path, ".clang-format-ignore");
-  } while (!is_regular_file(Path));
+Patterns.clear();
 
-  std::ifstream IgnoreFile{Path.c_str()};
-  if (!IgnoreFile.good())
-return false;
+for (std::string Line; std::getline(IgnoreFile, Line);) {
+  if (const auto Pattern{StringRef{Line}.trim()};
+  // Skip empty and comment lines.
+  !Pattern.empty() && 

[clang] [clang-format] Optimize processing .clang-format-ignore files (PR #76733)

2024-01-03 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Optimize processing .clang-format-ignore files (PR #76733)

2024-01-02 Thread Owen Pan via cfe-commits

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

Reuse the patterns governing the previous input file being formatted if the the 
current input file is from the same directory.

>From 7f8da18dc59706df8f1ee15d22076b4794881579 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 1 Jan 2024 19:10:30 -0800
Subject: [PATCH] [clang-format] Optimize processing .clang-format-ignore files

Reuse the patterns governing the previous input file being formatted if the
the current input file is from the same directory.
---
 clang/docs/ClangFormat.rst|  6 ++-
 clang/test/Format/clang-format-ignore.cpp | 17 +-
 clang/tools/clang-format/ClangFormat.cpp  | 65 ---
 3 files changed, 65 insertions(+), 23 deletions(-)

diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index 8d4017b29fb8ee..819d9ee9f9cde1 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -131,6 +131,9 @@ An easy way to create the ``.clang-format`` file is:
 
 Available style options are described in :doc:`ClangFormatStyleOptions`.
 
+.clang-format-ignore
+
+
 You can create ``.clang-format-ignore`` files to make ``clang-format`` ignore
 certain files. A ``.clang-format-ignore`` file consists of patterns of file 
path
 names. It has the following format:
@@ -141,7 +144,8 @@ names. It has the following format:
 * A non-comment line is a single pattern.
 * The slash (``/``) is used as the directory separator.
 * A pattern is relative to the directory of the ``.clang-format-ignore`` file
-  (or the root directory if the pattern starts with a slash).
+  (or the root directory if the pattern starts with a slash). Patterns
+  containing drive names (e.g. ``C:``) are not supported.
 * Patterns follow the rules specified in `POSIX 2.13.1, 2.13.2, and Rule 1 of
   2.13.3 `_.
diff --git a/clang/test/Format/clang-format-ignore.cpp 
b/clang/test/Format/clang-format-ignore.cpp
index 0d6396a64a668d..4d0c4073308edc 100644
--- a/clang/test/Format/clang-format-ignore.cpp
+++ b/clang/test/Format/clang-format-ignore.cpp
@@ -29,5 +29,18 @@
 // RUN: grep "Formatting \[1/2] foo.c" %t.stderr
 // RUN: not grep "Formatting \[2/2] foo.js" %t.stderr
 
-// RUN: cd ../../..
-// RUN: rm -rf %t.dir
+// RUN: cd ../..
+// RUN: clang-format -verbose *.cc level1/*.c* level1/level2/foo.* 2> %t.stderr
+// RUN: grep "Formatting \[1/5] level1/level2/foo.c" %t.stderr
+// RUN: not grep "Formatting \[2/5] level1/level2/foo.js" %t.stderr
+
+// RUN: rm .clang-format-ignore
+// RUN: clang-format -verbose *.cc level1/*.c* level1/level2/foo.* 2> %t.stderr
+// RUN: grep "Formatting \[1/5] foo.cc" %t.stderr
+// RUN: grep "Formatting \[2/5] level1/bar.cc" %t.stderr
+// RUN: grep "Formatting \[3/5] level1/baz.c" %t.stderr
+// RUN: grep "Formatting \[4/5] level1/level2/foo.c" %t.stderr
+// RUN: not grep "Formatting \[5/5] level1/level2/foo.js" %t.stderr
+
+// RUN: cd ..
+// RUN: rm -r %t.dir
diff --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index be34dbbe886a15..787e56a6eccc0e 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -571,6 +571,11 @@ static int dumpConfig(bool IsSTDIN) {
   return 0;
 }
 
+using String = SmallString<128>;
+static String IgnoreDir; // Directory of .clang-format-ignore file.
+static StringRef PrevDir;// Directory of previous `FilePath`.
+static SmallVector Patterns; // Patterns in .clang-format-ignore file.
+
 // Check whether `FilePath` is ignored according to the nearest
 // .clang-format-ignore file based on the rules below:
 // - A blank line is skipped.
@@ -586,33 +591,50 @@ static bool isIgnored(StringRef FilePath) {
   if (!is_regular_file(FilePath))
 return false;
 
-  using namespace llvm::sys::path;
-  SmallString<128> Path, AbsPath{FilePath};
+  String Path;
+  String AbsPath{FilePath};
 
+  using namespace llvm::sys::path;
   make_absolute(AbsPath);
   remove_dots(AbsPath, /*remove_dot_dot=*/true);
 
-  StringRef IgnoreDir{AbsPath};
-  do {
-IgnoreDir = parent_path(IgnoreDir);
-if (IgnoreDir.empty())
+  if (StringRef Dir{parent_path(AbsPath)}; PrevDir != Dir) {
+PrevDir = Dir;
+
+for (;;) {
+  Path = Dir;
+  append(Path, ".clang-format-ignore");
+  if (is_regular_file(Path))
+break;
+  Dir = parent_path(Dir);
+  if (Dir.empty())
+return false;
+}
+
+IgnoreDir = convert_to_slash(Dir);
+
+std::ifstream IgnoreFile{Path.c_str()};
+if (!IgnoreFile.good())
   return false;
 
-Path = IgnoreDir;
-append(Path, ".clang-format-ignore");
-  } while (!is_regular_file(Path));
+Patterns.clear();
 
-  std::ifstream IgnoreFile{Path.c_str()};
-  if (!IgnoreFile.good())
-return false;
+for (std::string Line; std::getline(IgnoreFile, Line);) {
+  if 

[clang] [ClangFormat] Fix formatting bugs. (PR #76245)

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


@@ -2919,6 +2912,12 @@ class ExpressionParser {
 
   void addFakeParenthesis(FormatToken *Start, prec::Level Precedence,
   FormatToken *End = nullptr) {
+// Do not assign fake parenthesis to tokens that are part of an
+// unexpanded macro call. The line within the macro call contains
+// the parenthesis and commas, and we will not find operators within
+// that structure.
+if (Start->MacroParent) return;

owenca wrote:

Please run git-clang-format locally. See 
[here](https://github.com/llvm/llvm-project/pull/76059#issuecomment-1865850011).

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


[clang] [ClangFormat] Fix formatting bugs. (PR #76245)

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


@@ -255,6 +255,44 @@ TEST_F(FormatTestMacroExpansion,
  Style);
 }
 
+TEST_F(FormatTestMacroExpansion, CommaAsOperator) {
+  FormatStyle Style = getGoogleStyle();
+  Style.Macros.push_back("ASSIGN_OR_RETURN(a, b, c)=a=(b); if(x) c");
+  verifyFormat(R"(ASSIGN_OR_RETURN(auto reader,
+ logs::proxy::Reader::NewReader(log_filename, access_options,
+reader_options),
+ _ << aa << aa << a
+   <<  << aaa << );
+)", Style);
+}
+
+TEST_F(FormatTestMacroExpansion, ForcedBreakDiffers) {
+  FormatStyle Style = getGoogleStyle();
+  Style.Macros.push_back("ASSIGN_OR_RETURN(a, b)=a=(b)");
+  EXPECT_EQ(R"(

owenca wrote:

Can you use the 1-argument version of `verifyFormat()` instead?

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


[clang] [ClangFormat] Fix formatting bugs. (PR #76245)

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


@@ -255,6 +255,44 @@ TEST_F(FormatTestMacroExpansion,
  Style);
 }
 
+TEST_F(FormatTestMacroExpansion, CommaAsOperator) {
+  FormatStyle Style = getGoogleStyle();
+  Style.Macros.push_back("ASSIGN_OR_RETURN(a, b, c)=a=(b); if(x) c");
+  verifyFormat(R"(ASSIGN_OR_RETURN(auto reader,

owenca wrote:

It's hard to read the test cases with raw strings. Can you set `ColumnLimit` to 
60 so that we don't have to use raw strings?

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


[clang] [ClangFormat] Fix formatting bugs. (PR #76245)

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


@@ -416,10 +421,15 @@ struct FormatToken {
   /// to another one please use overwriteFixedType, or even better remove the
   /// need to reassign the type.
   void setFinalizedType(TokenType T) {
+if (MacroCtx && MacroCtx->Role == MR_UnexpandedArg)
+  return;
+

owenca wrote:

Remove this empty line to be consistent with lines 431-432 below?

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


[clang] bd3d358 - [clang-format][doc] Add the link to POSIX 2.13

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

Author: Owen Pan
Date: 2023-12-30T01:32:10-08:00
New Revision: bd3d358ec68f686a280ae628f9074fdff1f10fe9

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

LOG: [clang-format][doc] Add the link to POSIX 2.13

Added: 


Modified: 
clang/docs/ClangFormat.rst

Removed: 




diff  --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index 158a14af39732e..8d4017b29fb8ee 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -142,8 +142,9 @@ names. It has the following format:
 * The slash (``/``) is used as the directory separator.
 * A pattern is relative to the directory of the ``.clang-format-ignore`` file
   (or the root directory if the pattern starts with a slash).
-* Patterns follow the rules specified in POSIX 2.13.1, 2.13.2, and Rule 1 of
-  2.13.3.
+* Patterns follow the rules specified in `POSIX 2.13.1, 2.13.2, and Rule 1 of
+  2.13.3 `_.
 * A pattern is negated if it starts with a bang (``!``).
 
 To match all files in a directory, use e.g. ``foo/bar/*``. To match all files 
in



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


<    2   3   4   5   6   7   8   9   10   11   >