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

2023-11-08 Thread Emilia Kond via cfe-commits

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

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

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


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

2023-11-14 Thread Emilia Kond via cfe-commits

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

A hooray for getting rid of invalid-code-generation

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


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

2023-11-17 Thread Emilia Kond via cfe-commits

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

Thanks for doing this! There were probably dozens of duplicates of this same 
crash across multiple years, so this is great

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


[clang] [clang-format] Correctly annotate braces of empty functions (PR #72733)

2023-11-19 Thread Emilia Kond via cfe-commits

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

wow!

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


[clang] [clang-format] Option to ignore PP directives (PR #70338)

2023-10-27 Thread Emilia Kond via cfe-commits

rymiel wrote:

https://github.com/llvm/llvm-project/pull/67911 is a pull request, not an 
issue, i'm not sure what you're referring to

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] Option to ignore PP directives (PR #70338)

2023-10-27 Thread Emilia Kond via cfe-commits


@@ -4648,6 +4648,10 @@ struct FormatStyle {
   /// \version 11
   std::vector WhitespaceSensitiveMacros;
 
+  /// Ignore formatting in preprocessor definitions.
+  /// \version 18
+  bool IgnorePPDefinitions;

rymiel wrote:

(this applies to not just here, but below on line 4818, and in Format.cpp, and 
in ConfigParseTest.cpp)

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][NFC] Delete TT_LambdaArrow (PR #70519)

2023-10-27 Thread Emilia Kond via cfe-commits

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

Surprised this works!

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


[clang] [clang-format] Skip PP directives when determining brace kind (PR #69473)

2023-11-02 Thread Emilia Kond via cfe-commits

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


[clang] [clang-format] Skip PP directives when determining brace kind (PR #69473)

2023-11-02 Thread Emilia Kond via cfe-commits

rymiel wrote:

Thank you for reminding me, I may have forgotten this was here!

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


[clang] [clang-format] Don't skip stringizing when determining brace kind (PR #73886)

2023-11-29 Thread Emilia Kond via cfe-commits

https://github.com/rymiel created 
https://github.com/llvm/llvm-project/pull/73886

PR #69473 introduced skipping PP directives when determining the brace kind of 
an lbrace. However, it did so by skipping to the end of the line when 
encountering a hash character. This means it also skipped to the end of line 
when encountering a macro stringizing operator, which, unlike PP directives, 
don't have effect until the end of line.

This led to cases where the rbrace could be completely skipped if it was on the 
same line as a stringizing operator.

This patch skips hash characters if we're already in a PP directive, as you 
can't define a macro inside of a macro

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

>From 95e2a2ee5d901d79430cb9b9468e1af8215b334f Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Thu, 30 Nov 2023 03:30:48 +0200
Subject: [PATCH] [clang-format] Don't skip stringizing when determining brace
 kind

PR #69473 introduced skipping PP directives when determining the brace
kind of an lbrace. However, it did so by skipping to the end of the line
when encountering a hash character. This means it also skipped to the
end of line when encountering a macro stringizing operator, which, unlike
PP directives, don't have effect until the end of line.

This led to cases where the rbrace could be completely skipped if it was
on the same line as a stringizing operator.

This patch skips hash characters if we're already in a PP directive, as
you can't define a macro inside of a macro

Fixes https://github.com/llvm/llvm-project/issues/72662
---
 clang/lib/Format/UnwrappedLineParser.cpp  |  2 +-
 clang/unittests/Format/TokenAnnotatorTest.cpp | 16 
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index a5a4419b98239e6..5f574dfeafc874b 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -496,7 +496,7 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
 do {
   NextTok = Tokens->getNextToken();
 } while (NextTok->is(tok::comment));
-while (NextTok->is(tok::hash)) {
+while (NextTok->is(tok::hash) && !Line->InPPDirective) {
   NextTok = Tokens->getNextToken();
   do {
 NextTok = Tokens->getNextToken();
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index bc734573ce0cb4d..8ad6a585d004593 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1851,6 +1851,22 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsTrailingReturnArrow) {
   EXPECT_TOKEN(Tokens[13], tok::arrow, TT_Unknown);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandHashInMacro) {
+  auto Tokens = annotate("#define Foo(Bar) \\\n"
+ "  { \\\n"
+ "#Bar \\\n"
+ "  }\n");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[6], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[9], BK_Block);
+
+  Tokens = annotate("#define Foo(Bar) \\\n"
+"  { #Bar }\n");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[6], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[9], BK_Block);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacros) {
   // '__attribute__' has special handling.
   auto Tokens = annotate("__attribute__(X) void Foo(void);");

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


[clang] [clang-format] Don't skip stringizing when determining brace kind (PR #73886)

2023-11-29 Thread Emilia Kond via cfe-commits


@@ -1851,6 +1851,22 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsTrailingReturnArrow) {
   EXPECT_TOKEN(Tokens[13], tok::arrow, TT_Unknown);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandHashInMacro) {
+  auto Tokens = annotate("#define Foo(Bar) \\\n"
+ "  { \\\n"
+ "#Bar \\\n"
+ "  }\n");

rymiel wrote:

Sorry, no, it was a leftover from other testing, thank you for catching it

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


[clang] [clang-format] Don't skip stringizing when determining brace kind (PR #73886)

2023-11-29 Thread Emilia Kond via cfe-commits

https://github.com/rymiel updated 
https://github.com/llvm/llvm-project/pull/73886

>From 95e2a2ee5d901d79430cb9b9468e1af8215b334f Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Thu, 30 Nov 2023 03:30:48 +0200
Subject: [PATCH 1/2] [clang-format] Don't skip stringizing when determining
 brace kind

PR #69473 introduced skipping PP directives when determining the brace
kind of an lbrace. However, it did so by skipping to the end of the line
when encountering a hash character. This means it also skipped to the
end of line when encountering a macro stringizing operator, which, unlike
PP directives, don't have effect until the end of line.

This led to cases where the rbrace could be completely skipped if it was
on the same line as a stringizing operator.

This patch skips hash characters if we're already in a PP directive, as
you can't define a macro inside of a macro

Fixes https://github.com/llvm/llvm-project/issues/72662
---
 clang/lib/Format/UnwrappedLineParser.cpp  |  2 +-
 clang/unittests/Format/TokenAnnotatorTest.cpp | 16 
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index a5a4419b98239e6..5f574dfeafc874b 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -496,7 +496,7 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
 do {
   NextTok = Tokens->getNextToken();
 } while (NextTok->is(tok::comment));
-while (NextTok->is(tok::hash)) {
+while (NextTok->is(tok::hash) && !Line->InPPDirective) {
   NextTok = Tokens->getNextToken();
   do {
 NextTok = Tokens->getNextToken();
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index bc734573ce0cb4d..8ad6a585d004593 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1851,6 +1851,22 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsTrailingReturnArrow) {
   EXPECT_TOKEN(Tokens[13], tok::arrow, TT_Unknown);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandHashInMacro) {
+  auto Tokens = annotate("#define Foo(Bar) \\\n"
+ "  { \\\n"
+ "#Bar \\\n"
+ "  }\n");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[6], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[9], BK_Block);
+
+  Tokens = annotate("#define Foo(Bar) \\\n"
+"  { #Bar }\n");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[6], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[9], BK_Block);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsAttributeMacros) {
   // '__attribute__' has special handling.
   auto Tokens = annotate("__attribute__(X) void Foo(void);");

>From 3037f808b23cc27f984a846bb1f9ef5cc2cd3a71 Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Thu, 30 Nov 2023 04:47:31 +0200
Subject: [PATCH 2/2] Apply suggestions from Owen's review

---
 clang/lib/Format/UnwrappedLineParser.cpp  | 2 +-
 clang/unittests/Format/TokenAnnotatorTest.cpp | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 5f574dfeafc874b..9a9a16a3caaca8b 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -496,7 +496,7 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
 do {
   NextTok = Tokens->getNextToken();
 } while (NextTok->is(tok::comment));
-while (NextTok->is(tok::hash) && !Line->InPPDirective) {
+while (NextTok->is(tok::hash) && !Line->InMacroBody) {
   NextTok = Tokens->getNextToken();
   do {
 NextTok = Tokens->getNextToken();
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 8ad6a585d004593..65b1f0f4b576598 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1855,13 +1855,13 @@ TEST_F(TokenAnnotatorTest, UnderstandHashInMacro) {
   auto Tokens = annotate("#define Foo(Bar) \\\n"
  "  { \\\n"
  "#Bar \\\n"
- "  }\n");
+ "  }");
   ASSERT_EQ(Tokens.size(), 11u) << Tokens;
   EXPECT_BRACE_KIND(Tokens[6], BK_Block);
   EXPECT_BRACE_KIND(Tokens[9], BK_Block);
 
   Tokens = annotate("#define Foo(Bar) \\\n"
-"  { #Bar }\n");
+"  { #Bar }");
   ASSERT_EQ(Tokens.size(), 11u) << Tokens;
   EXPECT_BRACE_KIND(Tokens[6], BK_Block);
   EXPECT_BRACE_KIND(Tokens[9], BK_Block);

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


[clang] [clang-format] Don't skip stringizing when determining brace kind (PR #73886)

2023-11-30 Thread Emilia Kond via cfe-commits

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


[clang] [clang-format] Add an fnmatch-like function for .clang-format-ignore (PR #76021)

2023-12-22 Thread Emilia Kond via cfe-commits

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

Are we going to use this specific implementation on all platforms for parity?
The logic on its own looks good as far as I can tell, but, for example, POSIX 
Section 2.13 mentions that a leading period (hidden files) isn't matched by `*`.
This sort of divergence from the strict POSIX spec is fine in my opinion, just 
confirming we won't cause parity issues.

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Emilia Kond via cfe-commits

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Emilia Kond via cfe-commits




rymiel wrote:

Your edits in Format.h won't show up in the documentation until after you've 
run the script in `clang/docs/tools/dump_format_style.py`

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Emilia Kond via cfe-commits


@@ -111,6 +111,9 @@ const tooling::Replacements 
&WhitespaceManager::generateReplacements() {
   alignConsecutiveDeclarations();
   alignConsecutiveBitFields();
   alignConsecutiveAssignments();
+  alignConsecutiveTableGenCondOperatorColons();
+  AlignConsecutiveTableGenBreakingDAGArgColons();
+  alignConsecutiveTableGenDefinition();

rymiel wrote:

Shouldn't these replacements be guarded behind an `isTableGen`? At the very 
least, `alignConsecutiveTableGenDefinition` aligns on TT_InheritanceColon and 
that can appear in non-tablegen code too

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Emilia Kond via cfe-commits

https://github.com/rymiel commented:

Hi, this is quite a big patch. I had a very quick look and noticed a few 
nit-picky thingy, mostly about formatting or naming and whatnot, mostly minor 
things.
However since I've never used tablegen, I'm not sure if I can actually review 
any of the logic in here, but I'll try to have another look later

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Emilia Kond via cfe-commits


@@ -111,6 +111,9 @@ const tooling::Replacements 
&WhitespaceManager::generateReplacements() {
   alignConsecutiveDeclarations();
   alignConsecutiveBitFields();
   alignConsecutiveAssignments();
+  alignConsecutiveTableGenCondOperatorColons();
+  AlignConsecutiveTableGenBreakingDAGArgColons();

rymiel wrote:

This one has different capitalization from all the others

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Emilia Kond via cfe-commits


@@ -40,6 +40,13 @@ class FormatTestTableGen : public ::testing::Test {
 EXPECT_EQ(Code.str(), format(Code)) << "Expected code is not stable";
 EXPECT_EQ(Code.str(), format(test::messUp(Code)));
   }
+
+  static void verifyFormat(llvm::StringRef Code, const FormatStyle &Style) {

rymiel wrote:

It seems like this file was never brought up to date with all the other tests 
when f8d10d5ac9ab4b45b388c74357fc82fb96562e66 happened

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Emilia Kond via cfe-commits


@@ -4753,6 +4793,13 @@ struct FormatStyle {
AlignConsecutiveMacros == R.AlignConsecutiveMacros &&
AlignConsecutiveShortCaseStatements ==
R.AlignConsecutiveShortCaseStatements &&
+   AlignConsecutiveTableGenCondOperatorColons ==
+   R.AlignConsecutiveTableGenCondOperatorColons &&
+   AlignConsecutiveTableGenBreakingDAGArgColons ==
+   R.AlignConsecutiveTableGenBreakingDAGArgColons &&
+   AlignConsecutiveTableGenDefinitions ==
+   R.AlignConsecutiveTableGenDefinitions &&
+   AlignConsecutiveMacros == R.AlignConsecutiveMacros &&

rymiel wrote:

Small copy paste error, I'm assuming, AlignConsecutiveMacros has already been 
checked.
Also, these options should be alphabetical in order

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Emilia Kond via cfe-commits


@@ -1124,6 +1130,20 @@ template <> struct MappingTraits {
 IO.mapOptional("StatementAttributeLikeMacros",
Style.StatementAttributeLikeMacros);
 IO.mapOptional("StatementMacros", Style.StatementMacros);
+IO.mapOptional("TableGenAllowBreakAfterInheritColon",
+   Style.TableGenAllowBreakAfterInheritColon);
+IO.mapOptional("TableGenAllowBreakBeforeInheritColon",
+   Style.TableGenAllowBreakBeforeInheritColon);
+IO.mapOptional("TableGenBreakInsideCondOperator",
+   Style.TableGenBreakInsideCondOperator);
+IO.mapOptional("TableGenBreakInsideDAGArgList",
+   Style.TableGenBreakInsideDAGArgList);
+IO.mapOptional("TableGenPreferBreakInsideSquareBracket",
+   Style.TableGenPreferBreakInsideSquareBracket);
+IO.mapOptional("TableGenSpaceAroundDAGArgColon",
+   Style.TableGenSpaceAroundDAGArgColon);
+IO.mapOptional("TableGenBreakingDAGArgOperators",
+   Style.TableGenBreakingDAGArgOperators);

rymiel wrote:

I'm a little confused by these undocumented style options?

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Emilia Kond via cfe-commits


@@ -272,6 +276,38 @@ void FormatTokenLexer::tryMergePreviousTokens() {
   return;
 }
   }
+  if (Style.isTableGen()) {
+if (tryMergeTokens({tok::l_square, tok::l_brace},
+   TT_TableGenMultiLineString)) {
+  Tokens.back()->Tok.setKind(tok::string_literal);
+  return;
+}
+if (Tokens.size() > 1 && Tokens.end()[-2]->is(tok::exclaim)) {
+  if (Tokens.back()->is(tok::identifier) ||
+  (Tokens.back()->is(tok::kw_if) && Tokens.back())) {
+  }
+}

rymiel wrote:

This if statement does nothing, or am I misunderstanding it?

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


[clang] [clang-format] Add common attribute macros to Google style (PR #76239)

2023-12-22 Thread Emilia Kond via cfe-commits

rymiel wrote:

Who should have the final say on the Google code style if not Google?

https://github.com/llvm/llvm-project/pull/76239
___
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-08 Thread Emilia Kond via cfe-commits


@@ -3903,6 +3903,15 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   parseParens();
   }
 
+  auto IsTemplate = [&] {
+FormatToken *Tok = InitialToken.Previous;
+while (Tok) {
+  if (Tok->is(tok::kw_template))
+return true;
+  Tok = Tok->Previous;
+}
+return false;
+  };
   // Note that parsing away template declarations here leads to incorrectly

rymiel wrote:

Just want to make sure this comment (and the 10 lines below it) still applies 
and doesn't need changing? Otherwise this is a good improvement

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-08 Thread Emilia Kond via cfe-commits

https://github.com/rymiel edited 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-08 Thread Emilia Kond via cfe-commits

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


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 crash involving array designators (PR #77045)

2024-01-09 Thread Emilia Kond via cfe-commits

https://github.com/rymiel 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] Don't allow casts in front of ampamp (PR #77704)

2024-01-10 Thread Emilia Kond via cfe-commits

https://github.com/rymiel created 
https://github.com/llvm/llvm-project/pull/77704

clang-format performs a heuristic to see if a right parenthesis is the 
parenthesis of a cast expression. This check never looked ahead to see if the 
next token is an ampamp && token. This resulted in the paren being set as an 
CastRParen, and the following ampamp got annotated as an UnaryOperator!

Since && can never be a unary operator is standard C++, this patch forbids the 
right paren from ever becoming a cast.

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

>From 05173702b3d834207af5ca40a317bb2a8425e4db Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Thu, 11 Jan 2024 01:41:12 +0200
Subject: [PATCH] [clang-format] Don't allow casts in front of ampamp

clang-format performs a heuristic to see if a right parenthesis is the
parenthesis of a cast expression. This check never looked ahead to see
if the next token is an ampamp && token. This resulted in the paren
being set as an CastRParen, and the following ampamp got annotated as an
UnaryOperator!

Since && can never be a unary operator is standard C++, this patch
forbids the right paren from ever becoming a cast.

Fixes https://github.com/llvm/llvm-project/issues/77680
---
 clang/lib/Format/TokenAnnotator.cpp   | 2 +-
 clang/unittests/Format/TokenAnnotatorTest.cpp | 5 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 8b43438c72dfe1..854e85db5be4d9 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2369,7 +2369,7 @@ class AnnotatingParser {
   }
 }
 
-if (Tok.Next->is(tok::question))
+if (Tok.Next->isOneOf(tok::question, tok::ampamp))
   return false;
 
 // `foreach((A a, B b) in someList)` should not be seen as a cast.
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index decc0785c5cde7..4f4c54b344e109 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1066,6 +1066,11 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
   EXPECT_EQ(Tokens.size(), 17u) << Tokens;
   EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
   EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("template \n"
+"concept C = (!Foo) && Bar;");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[15], tok::ampamp, TT_BinaryOperator);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {

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


[clang] [clang-format] Don't confuse initializer equal signs in for loops (PR #77712)

2024-01-10 Thread Emilia Kond via cfe-commits

https://github.com/rymiel created 
https://github.com/llvm/llvm-project/pull/77712

clang-format has logic to align declarations of multiple variables of the same 
type, aligning them at the equals sign. This logic is applied in for loops as 
well. However, this alignment logic also erroneously affected the equals signs 
of designated initializers.

This patch forbids alignment if the token 2 tokens back from the equals sign is 
a designated initializer period.

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

>From 3d7ef4670c15116c1402685e8fc0a29cadfe04f6 Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Thu, 11 Jan 2024 03:00:44 +0200
Subject: [PATCH] [clang-format] Don't confuse initializer equal signs in for
 loops

clang-format has logic to align declarations of multiple variables of
the same type, aligning them at the equals sign. This logic is applied
in for loops as well. However, this alignment logic also erroneously
affected the equals signs of designated initializers.

This patch forbids alignment if the token 2 tokens back from the equals
sign is a designated initializer period.

Fixes https://github.com/llvm/llvm-project/issues/73902
---
 clang/lib/Format/ContinuationIndenter.cpp |  4 +++-
 clang/unittests/Format/FormatTest.cpp | 12 
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 102504182c4505..ce6c17c3b7d927 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -703,7 +703,9 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
 
   if (Current.is(tok::equal) &&
   (State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) &&
-  CurrentState.VariablePos == 0) {
+  CurrentState.VariablePos == 0 &&
+  (!Previous.Previous ||
+   Previous.Previous->isNot(TT_DesignatedInitializerPeriod))) {
 CurrentState.VariablePos = State.Column;
 // Move over * and & if they are bound to the variable name.
 const FormatToken *Tok = &Previous;
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 25ef5c680af862..01678a4971caae 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -4944,6 +4944,18 @@ TEST_F(FormatTest, DesignatedInitializers) {
"[3] = cc,\n"
"[4] = dd,\n"
"[5] = ee};");
+
+  verifyFormat("for (const TestCase &test_case : {\n"
+   " TestCase{\n"
+   " .a = 1,\n"
+   " .b = 1,\n"
+   " },\n"
+   " TestCase{\n"
+   " .a = 2,\n"
+   " .b = 2,\n"
+   " },\n"
+   " }) {\n"
+   "}\n");
 }
 
 TEST_F(FormatTest, BracedInitializerIndentWidth) {

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


[llvm] [clang-tools-extra] [clang] [HLSL][Docs] Add documentation for HLSL functions (PR #75397)

2024-01-10 Thread Emilia Kond via cfe-commits


@@ -0,0 +1,321 @@
+===
+HLSL Function Calls
+===
+
+.. contents::
+   :local:
+
+Introduction
+
+
+This document describes the design and implementation of HLSL's function call
+semantics in Clang. This includes details related to argument conversion and
+parameter lifetimes.
+
+This document does not seek to serve as official documentation for HLSL's
+call semantics, but does provide an overview to assist a reader. The
+authoritative documentation for HLSL's language semantics is the `draft 
language
+specification `_.
+
+Argument Semantics
+==
+
+In HLSL, all function arguments are passed by value in and out of functions.
+HLSL has 3 keywords which denote the parameter semantics (``in``, ``out`` and
+``inout``). In a function declaration a parameter may be annotated any of the
+following ways:
+
+#.  - denotes input
+#. ``in`` - denotes input
+#. ``out`` - denotes output
+#. ``in out`` - denotes input and output
+#. ``out in`` - denotes input and output
+#. ``inout`` - denotes input and output
+
+Parameters that are exclusively input behave like C/C++ parameters that are
+passed by value.
+
+For parameters that are output (or input and output), a temporary value is
+created in the caller. The temporary value is then passed by-address. For
+output-only parameters, the temporary is uninitialized when passed (if the
+parameter is not explicitly initialized inside the function an undefined value
+is stored back to the argument expression). For parameters that are both input
+and output, the temporary is initialized from the lvalue argument expression
+through implicit  or explicit casting from the lvalue argument type to the
+parameter type.
+
+On return of the function, the values of any parameter temporaries are written
+back to the argument expression through an inverted conversion sequence (if an
+``out`` parameter was not initialized in the function, the uninitialized value
+may be written back).
+
+Parameters of constant-sized array type are also passed with value semantics.
+This requires input parameters of arrays to construct temporaries and the
+temporaries go through array-to-pointer decay when initializing parameters.
+
+Implementations are allowed to avoid unnecessary temporaries, and HLSL's strict
+no-alias rules can enable some trivial optimizations.
+
+Array Temporaries
+-
+
+Given the following example:
+
+.. code-block:: c++
+
+  void fn(float a[4]) {
+a[0] = a[1] + a[2] + a[3];
+  }
+
+  float4 main() : SV_Target {
+float arr[4] = {1, 1, 1, 1};
+fn(arr);
+return float4(arr[0], arr[1], arr[2], arr[3]);
+  }
+
+In C or C++, the array parameter decays to a pointer, so after the call to
+``fn``, the value of ``arr[0]`` is ``3``. In HLSL, the array is passed by 
value,
+so modifications inside ``fn`` do not propagate out.
+
+.. note::
+
+  DXC may pass unsized arrays directly as decayed pointers, which is an
+  unfortunate behavior divergence.
+
+Out Parameter Temporaries
+-
+
+.. code-block:: c++
+
+  void Init(inout int X, inout int Y) {
+Y = 2;
+X = 1;
+  }
+
+  void main() {
+int V;
+Init(V, V); // MSVC (or clang-cl) V == 2, Clang V == 1
+  }
+
+In the above example the ``Init`` function's behavior depends on the C++
+implementation. C++ does not define the order in which parameters are
+initialized or destroyed. In MSVC and Clang's MSVC compatibility mode, 
arguments
+are emitted right-to-left and destroyed left-to-right. This means that  the
+parameter initialization and destruction occurs in the order: {``Y``, ``X``,
+``~X``, ``~Y``}. This causes the write-back of the value of ``Y`` to occur 
last,
+so the resulting value of ``V`` is ``2``. In the Itanium C++ ABI, the  
parameter
+ordering is reversed, so the initialization and destruction occurs in the 
order:
+{``X``, ``Y``, ``~Y``, ``X``}. This causes the write-back of the value ``X`` to
+occur last, resulting in the value of ``V`` being set to ``1``.
+
+.. code-block:: c++
+
+  void Trunc(inout int3 V) { }
+
+
+  void main() {
+float3 F = {1.5, 2.6, 3.3};
+Trunc(F); // F == {1.0, 2.0, 3.0}
+  }
+
+In the above example, the argument expression ``F`` undergoes element-wise
+conversion from a float vector to an integer vector to create a temporary
+``int3``. On expiration the temporary undergoes elementwise conversion back to
+the floating point vector type ``float3``. This results in an implicit
+element-wise conversion of the vector even if the value is unused in the
+function (effectively truncating the floating point values).
+
+
+.. code-block:: c++
+
+  void UB(out int X) {}
+
+  void main() {
+int X = 7;
+UB(X); // X is undefined!
+  }
+
+In this example an initialized value is passed to an ``out`` parameter.
+Parameters marked ``out`` are not initialized by the argument expression or
+implicitly by the function.

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

2024-01-11 Thread Emilia Kond via cfe-commits


@@ -1066,6 +1066,11 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
   EXPECT_EQ(Tokens.size(), 17u) << Tokens;
   EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
   EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("template \n"
+"concept C = (!Foo) && Bar;");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[15], tok::ampamp, TT_BinaryOperator);

rymiel wrote:

TT_UnaryOperator, as outlined in the issue description

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] NEVER allow && to be an unary operator. (PR #78852)

2024-02-10 Thread Emilia Kond via cfe-commits

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


[clang] [clang-format] NEVER allow && to be an unary operator. (PR #78852)

2024-02-10 Thread Emilia Kond via cfe-commits

rymiel wrote:

I'm sorry, I do not have the time for this right now, and I'd rather not leave 
this open for no reason

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


[clang] [clang-format] Handles Elaborated type specifier for enum in trailing return (PR #80085)

2024-01-30 Thread Emilia Kond via cfe-commits

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

Thank you for the lightning fast fix!

https://github.com/llvm/llvm-project/pull/80085
___
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-31 Thread Emilia Kond via cfe-commits

https://github.com/rymiel closed 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


[flang] [libcxx] [openmp] [llvm] [clang] [lldb] [lld] [mlir] [compiler-rt] [clang-format] SpacesInSquareBrackets not working for Java (PR #77833)

2024-01-11 Thread Emilia Kond via cfe-commits

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


https://github.com/llvm/llvm-project/pull/77833
___
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-11 Thread Emilia Kond via cfe-commits

https://github.com/rymiel closed 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] Add PenaltyBreakScopeResolution option. (PR #78015)

2024-01-13 Thread Emilia Kond via cfe-commits

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


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


[clang] [clang-format] Support of TableGen identifiers beginning with a number. (PR #78571)

2024-01-18 Thread Emilia Kond via cfe-commits


@@ -804,6 +806,46 @@ void FormatTokenLexer::handleTableGenMultilineString() {
   FirstLineText, MultiLineString->OriginalColumn, Style.TabWidth, 
Encoding);
 }
 
+void FormatTokenLexer::handleTableGenNumericLikeIdentifier() {
+  FormatToken *Tok = Tokens.back();
+  // TableGen identifiers can begin with digits. Such tokens are lexed as
+  // numeric_constant now.
+  if (Tok->isNot(tok::numeric_constant))
+return;
+  StringRef Text = Tok->TokenText;
+  // Identifiers cannot begin with + or -.
+  if (Text.size() < 1 || Text[0] == '+' || Text[0] == '-')
+return;
+  // The following check is based on llvm::TGLexer::LexToken.
+  if (isdigit(Text[0])) {
+size_t I = 0;
+char NextChar = (char)0;
+// Identifiers in TalbleGen may begin with digits. Skip to first non-digit.
+do {
+  NextChar = Text[I++];
+} while (I < Text.size() && isdigit(NextChar));
+// All the characters are digits.
+if (I >= Text.size())
+  return;
+// Base character. But it does not check the first 0 and that the base is
+// the second character.

rymiel wrote:

Is the "it does not check" a behaviour of this implementation or also of the 
tablegen compiler implementation?
I noticed below in the tests you mention the lexer errors on some cases, is 
this logic meant to match that behaviour?

https://github.com/llvm/llvm-project/pull/78571
___
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-20 Thread Emilia Kond via cfe-commits

https://github.com/rymiel created 
https://github.com/llvm/llvm-project/pull/78847

If clang-format is not sure whether a `requires` keyword starts a requires 
clause or a requires expression, it looks ahead to see if any token 
disqualifies it from being a requires clause. Among these tokens was 
`decltype`, since it fell through the switch.

This patch allows decltype to exist in a require clause.

I'm not 100% sure this change won't have repercussions, but that just means we 
need more test coverage!

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

>From 79ebbdc60cfa0635c9d889823a8b37710d9a4fb5 Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Sat, 20 Jan 2024 15:44:16 +0200
Subject: [PATCH] [clang-format] Allow decltype in requires clause

If clang-format is not sure whether a `requires` keyword starts a
requires clause or a requires expression, it looks ahead to see if any
token disqualifies it from being a requires clause. Among these tokens
was `decltype`, since it fell through the switch.

This patch allows decltype to exist in a require clause.

I'm not 100% sure this change won't have repercussions, but that just means
we need more test coverage!

Fixes https://github.com/llvm/llvm-project/issues/78645
---
 clang/lib/Format/UnwrappedLineParser.cpp  |  1 +
 clang/unittests/Format/TokenAnnotatorTest.cpp | 10 ++
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c08ce86449b6ea..62a6018580a0d1 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3433,6 +3433,7 @@ bool clang::format::UnwrappedLineParser::parseRequires() {
 case tok::coloncolon:
   LastWasColonColon = true;
   break;
+case tok::kw_decltype:
 case tok::identifier:
   if (FoundType && !LastWasColonColon && OpenAngles == 0) {
 FormatTok = Tokens->setPosition(StoredPosition);
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 64b2abac5cce53..3f94c464b41343 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -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);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {

___
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-20 Thread Emilia Kond via cfe-commits


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

rymiel wrote:

So, GitHub won't actually let me leave a comment on the line I want to actually 
talk about, but I noticed a few lines above this, on line 1066, it uses 
`EXPECT_EQ` instead of `ASSERT_EQ`, which is my mistake from 4 months ago.
But then I noticed a lot of these mistakes elsewhere in the file.
This is unrelated to this patch here, but do any of you have any opinions on 
unifying these? As I understand the assert exists to avoid out-of-bound 
accesses and thus segmentation faults. Is anyone opposed to an NFC commit 
changing all the EXPECTs into ASSERTs? @llvm/pr-subscribers-clang-format 

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] NEVER allow && to be an unary operator. (PR #78852)

2024-01-20 Thread Emilia Kond via cfe-commits

https://github.com/rymiel created 
https://github.com/llvm/llvm-project/pull/78852

Simply always return false if tok::ampamp is passed into 
determineUnaryOperatorByUsage.

I've done a fix earlier regarding ampamp becoming an unary operator, this would 
technically supersede that.

I'm not sure why this hasn't been done before, I don't see any downsides.

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

>From 4171fa9282330764a35b45ac08bde8b3bfc6f2c5 Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Sat, 20 Jan 2024 17:21:40 +0200
Subject: [PATCH] [clang-format] NEVER allow && to be an unary operator.

Simply always return false if tok::ampamp is passed into
determineUnaryOperatorByUsage.

I've done a fix earlier regarding ampamp becoming an unary operator,
this would technically supersede that.

I'm not sure why this hasn't been done before, I don't see any
downsides.

Fixes https://github.com/llvm/llvm-project/issues/78789
---
 clang/lib/Format/TokenAnnotator.cpp   | 3 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 4 
 2 files changed, 7 insertions(+)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 25fcceb8786437..573e986b6939df 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2503,6 +2503,9 @@ class AnnotatingParser {
 if (!PrevToken)
   return true;
 
+if (Tok.is(tok::ampamp))
+  return false;
+
 // These keywords are deliberately not included here because they may
 // precede only one of unary star/amp and plus/minus but not both.  They 
are
 // either included in determineStarAmpUsage or 
determinePlusMinusCaretUsage.
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 64b2abac5cce53..f8d2b264ee7480 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -309,6 +309,10 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
   EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_OverloadedOperatorLParen);
   EXPECT_TOKEN(Tokens[8], tok::l_brace, TT_FunctionLBrace);
   EXPECT_TOKEN(Tokens[11], tok::amp, TT_PointerOrReference);
+
+  Tokens = annotate("if (delete && foo) {}");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::ampamp, TT_BinaryOperator);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {

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


[clang] [clang-format] NEVER allow && to be an unary operator. (PR #78852)

2024-01-20 Thread Emilia Kond via cfe-commits

rymiel wrote:

clang-format does not support that extension in the first place, there's an 
open issue for it. But I will try a few edge cases to see if it changes 
anything or if it was already broken

https://github.com/llvm/llvm-project/pull/78852
___
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-20 Thread Emilia Kond via cfe-commits

https://github.com/rymiel converted_to_draft 
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-20 Thread Emilia Kond via cfe-commits

https://github.com/rymiel ready_for_review 
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] NEVER allow && to be an unary operator. (PR #78852)

2024-01-20 Thread Emilia Kond via cfe-commits

https://github.com/rymiel converted_to_draft 
https://github.com/llvm/llvm-project/pull/78852
___
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-20 Thread Emilia Kond 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);
 }

rymiel wrote:

Thanks, but this test input never actually runs parseRequires(), but I 
constructed another case which does, I'll add both

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 Emilia Kond 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);
 }

rymiel wrote:

I found a failing edge case
`bool x = t && requires(Foo x) { x.foo(); };`
will annotate the requires as a TT_RequiresClause. I'll add extra logic in the 
lookahead to fix this

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 Emilia Kond 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);
 }

rymiel wrote:

Well, the simplest fix is to remove `case tok::r_paren:` on line 3424 which 
always led to parseRequiresClause. Surprisingly removing that breaks no tests, 
but surely @HazardyKnusperkeks you put it there for a reason? I'm not sure if 
such a fix is the best idea

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] NEVER allow && to be an unary operator. (PR #78852)

2024-01-21 Thread Emilia Kond via cfe-commits

rymiel wrote:

https://github.com/llvm/llvm-project/issues/61233

The ambiguities this syntax extension can bring are pretty much impossible or 
at least very hard to always handle, but I'll try to avoid breaking things 
which weren't already broken.

https://github.com/llvm/llvm-project/pull/78852
___
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 Emilia Kond 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);
 }

rymiel wrote:

> If I read the code right my question is why didn't `Foo` suffice 
> `FoundType && !LastWasColonColon && OpenAngles == 0` when hitting the `x`?

I'm not sure what you mean. If you're talking about `Foo x`, it 
never gets to the `x` because it reaches the `)` of the decltype first and that 
unconditionally leads to being parsed as a clause

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 Emilia Kond via cfe-commits

https://github.com/rymiel edited 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 Emilia Kond 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);
 }

rymiel 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

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 Emilia Kond via cfe-commits

https://github.com/rymiel updated 
https://github.com/llvm/llvm-project/pull/78847

>From 79ebbdc60cfa0635c9d889823a8b37710d9a4fb5 Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Sat, 20 Jan 2024 15:44:16 +0200
Subject: [PATCH 1/2] [clang-format] Allow decltype in requires clause

If clang-format is not sure whether a `requires` keyword starts a
requires clause or a requires expression, it looks ahead to see if any
token disqualifies it from being a requires clause. Among these tokens
was `decltype`, since it fell through the switch.

This patch allows decltype to exist in a require clause.

I'm not 100% sure this change won't have repercussions, but that just means
we need more test coverage!

Fixes https://github.com/llvm/llvm-project/issues/78645
---
 clang/lib/Format/UnwrappedLineParser.cpp  |  1 +
 clang/unittests/Format/TokenAnnotatorTest.cpp | 10 ++
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c08ce86449b6ea..62a6018580a0d1 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3433,6 +3433,7 @@ bool clang::format::UnwrappedLineParser::parseRequires() {
 case tok::coloncolon:
   LastWasColonColon = true;
   break;
+case tok::kw_decltype:
 case tok::identifier:
   if (FoundType && !LastWasColonColon && OpenAngles == 0) {
 FormatTok = Tokens->setPosition(StoredPosition);
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 64b2abac5cce53..3f94c464b41343 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -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);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {

>From bef8c027504e1e0c0f28da090e1859be714a3ab1 Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Mon, 22 Jan 2024 00:31:23 +0200
Subject: [PATCH 2/2] address review and add more tests

---
 clang/lib/Format/UnwrappedLineParser.cpp  |  9 +---
 clang/unittests/Format/TokenAnnotatorTest.cpp | 21 +++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 62a6018580a0d1..75721a3f79eca8 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3423,9 +3423,12 @@ bool clang::format::UnwrappedLineParser::parseRequires() 
{
   break;
 case tok::r_paren:
 case tok::pipepipe:
-  FormatTok = Tokens->setPosition(StoredPosition);
-  parseRequiresClause(RequiresToken);
-  return true;
+  if (OpenAngles == 0) {
+FormatTok = Tokens->setPosition(StoredPosition);
+parseRequiresClause(RequiresToken);
+return true;
+  }
+  break;
 case tok::eof:
   // Break out of the loop.
   Lookahead = 50;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 3f94c464b41343..a1b24dc86bf0ff 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1081,6 +1081,27 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
   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");
+  ASSERT_EQ(Tokens.size(), 36u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::kw_requires, TT_RequiresExpression);
+
+  Tokens = annotate("bool x = t && requires(decltype(t) x) { x.foo(); };");
+  ASSERT_EQ(Tokens.size(), 23u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresExpression);
+
+  Tokens = annotate("bool x = t && requires(Foo x) { x.foo(); 
};");
+  ASSERT_EQ(Tokens.size(), 26u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresExpression);
+
+  Tokens = annotate("bool x = t && requires(Foo x) { x.foo(); };");
+  ASSERT_EQ(Token

[clang] [clang-format] Fix a bug in ContinuationIndenter (PR #78921)

2024-01-21 Thread Emilia Kond via cfe-commits

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


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] Allow decltype in requires clause (PR #78847)

2024-01-22 Thread Emilia Kond via cfe-commits

https://github.com/rymiel updated 
https://github.com/llvm/llvm-project/pull/78847

>From 79ebbdc60cfa0635c9d889823a8b37710d9a4fb5 Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Sat, 20 Jan 2024 15:44:16 +0200
Subject: [PATCH 1/3] [clang-format] Allow decltype in requires clause

If clang-format is not sure whether a `requires` keyword starts a
requires clause or a requires expression, it looks ahead to see if any
token disqualifies it from being a requires clause. Among these tokens
was `decltype`, since it fell through the switch.

This patch allows decltype to exist in a require clause.

I'm not 100% sure this change won't have repercussions, but that just means
we need more test coverage!

Fixes https://github.com/llvm/llvm-project/issues/78645
---
 clang/lib/Format/UnwrappedLineParser.cpp  |  1 +
 clang/unittests/Format/TokenAnnotatorTest.cpp | 10 ++
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index c08ce86449b6ea..62a6018580a0d1 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3433,6 +3433,7 @@ bool clang::format::UnwrappedLineParser::parseRequires() {
 case tok::coloncolon:
   LastWasColonColon = true;
   break;
+case tok::kw_decltype:
 case tok::identifier:
   if (FoundType && !LastWasColonColon && OpenAngles == 0) {
 FormatTok = Tokens->setPosition(StoredPosition);
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 64b2abac5cce53..3f94c464b41343 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -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);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {

>From bef8c027504e1e0c0f28da090e1859be714a3ab1 Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Mon, 22 Jan 2024 00:31:23 +0200
Subject: [PATCH 2/3] address review and add more tests

---
 clang/lib/Format/UnwrappedLineParser.cpp  |  9 +---
 clang/unittests/Format/TokenAnnotatorTest.cpp | 21 +++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 62a6018580a0d1..75721a3f79eca8 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3423,9 +3423,12 @@ bool clang::format::UnwrappedLineParser::parseRequires() 
{
   break;
 case tok::r_paren:
 case tok::pipepipe:
-  FormatTok = Tokens->setPosition(StoredPosition);
-  parseRequiresClause(RequiresToken);
-  return true;
+  if (OpenAngles == 0) {
+FormatTok = Tokens->setPosition(StoredPosition);
+parseRequiresClause(RequiresToken);
+return true;
+  }
+  break;
 case tok::eof:
   // Break out of the loop.
   Lookahead = 50;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 3f94c464b41343..a1b24dc86bf0ff 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1081,6 +1081,27 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
   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");
+  ASSERT_EQ(Tokens.size(), 36u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::kw_requires, TT_RequiresExpression);
+
+  Tokens = annotate("bool x = t && requires(decltype(t) x) { x.foo(); };");
+  ASSERT_EQ(Tokens.size(), 23u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresExpression);
+
+  Tokens = annotate("bool x = t && requires(Foo x) { x.foo(); 
};");
+  ASSERT_EQ(Tokens.size(), 26u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresExpression);
+
+  Tokens = annotate("bool x = t && requires(Foo x) { x.foo(); };");
+  ASSERT_EQ(Token

[clang] 88d1de5 - [clang-format][NFC] Unify token size tests to use ASSERT_EQ

2024-01-22 Thread Emilia Kond via cfe-commits

Author: Emilia Kond
Date: 2024-01-22T14:53:47+02:00
New Revision: 88d1de5ec64210686d93a90529583505635d257d

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

LOG: [clang-format][NFC] Unify token size tests to use ASSERT_EQ

Added: 


Modified: 
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 88ca8a6cb39e3b..3dbf504c35ed55 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -50,7 +50,7 @@ class TokenAnnotatorTest : public ::testing::Test {
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
   auto Tokens = annotate("auto x = [](const decltype(x) &ptr) {};");
-  EXPECT_EQ(Tokens.size(), 18u) << Tokens;
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
   EXPECT_TOKEN(Tokens[7], tok::kw_decltype, TT_Unknown);
   EXPECT_TOKEN(Tokens[8], tok::l_paren, TT_TypeDeclarationParen);
   EXPECT_TOKEN(Tokens[9], tok::identifier, TT_Unknown);
@@ -58,12 +58,12 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
   EXPECT_TOKEN(Tokens[11], tok::amp, TT_PointerOrReference);
 
   Tokens = annotate("auto x = [](const decltype(x) *ptr) {};");
-  EXPECT_EQ(Tokens.size(), 18u) << Tokens;
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
   EXPECT_TOKEN(Tokens[10], tok::r_paren, TT_TypeDeclarationParen);
   EXPECT_TOKEN(Tokens[11], tok::star, TT_PointerOrReference);
 
   Tokens = annotate("#define lambda [](const decltype(x) &ptr) {}");
-  EXPECT_EQ(Tokens.size(), 17u) << Tokens;
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
   EXPECT_TOKEN(Tokens[7], tok::kw_decltype, TT_Unknown);
   EXPECT_TOKEN(Tokens[8], tok::l_paren, TT_TypeDeclarationParen);
   EXPECT_TOKEN(Tokens[9], tok::identifier, TT_Unknown);
@@ -71,7 +71,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
   EXPECT_TOKEN(Tokens[11], tok::amp, TT_PointerOrReference);
 
   Tokens = annotate("#define lambda [](const decltype(x) *ptr) {}");
-  EXPECT_EQ(Tokens.size(), 17u) << Tokens;
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
   EXPECT_TOKEN(Tokens[10], tok::r_paren, TT_TypeDeclarationParen);
   EXPECT_TOKEN(Tokens[11], tok::star, TT_PointerOrReference);
 
@@ -79,63 +79,63 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
 "  while (p < a && *p == 'a')\n"
 "p++;\n"
 "}");
-  EXPECT_EQ(Tokens.size(), 21u) << Tokens;
+  ASSERT_EQ(Tokens.size(), 21u) << Tokens;
   EXPECT_TOKEN(Tokens[10], tok::ampamp, TT_BinaryOperator);
   EXPECT_TOKEN(Tokens[11], tok::star, TT_UnaryOperator);
 
   Tokens = annotate("case *x:");
-  EXPECT_EQ(Tokens.size(), 5u) << Tokens;
+  ASSERT_EQ(Tokens.size(), 5u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::star, TT_UnaryOperator);
   Tokens = annotate("case &x:");
-  EXPECT_EQ(Tokens.size(), 5u) << Tokens;
+  ASSERT_EQ(Tokens.size(), 5u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::amp, TT_UnaryOperator);
 
   Tokens = annotate("bool b = 3 == int{3} && true;");
-  EXPECT_EQ(Tokens.size(), 13u) << Tokens;
+  ASSERT_EQ(Tokens.size(), 13u) << Tokens;
   EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_BinaryOperator);
 
   Tokens = annotate("struct {\n"
 "} *ptr;");
-  EXPECT_EQ(Tokens.size(), 7u) << Tokens;
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
   Tokens = annotate("union {\n"
 "} *ptr;");
-  EXPECT_EQ(Tokens.size(), 7u) << Tokens;
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
   Tokens = annotate("class {\n"
 "} *ptr;");
-  EXPECT_EQ(Tokens.size(), 7u) << Tokens;
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
 
   Tokens = annotate("struct {\n"
 "} &&ptr = {};");
-  EXPECT_EQ(Tokens.size(), 10u) << Tokens;
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::ampamp, TT_PointerOrReference);
   Tokens = annotate("union {\n"
 "} &&ptr = {};");
-  EXPECT_EQ(Tokens.size(), 10u) << Tokens;
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::ampamp, TT_PointerOrReference);
   Tokens = annotate("class {\n"
 "} &&ptr = {};");
-  EXPECT_EQ(Tokens.size(), 10u) << Tokens;
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::ampamp, TT_PointerOrReference);
   Tokens = annotate("int i = int{42} * 2;");
-  EXPECT_EQ(Tokens.size(), 11u) << Tokens;
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
   EXPECT_TOKEN(Tokens[7], tok::star, TT_BinaryOperator);
 
   Tokens = annotate("delete[] *ptr;");
-  EXPECT_EQ(Tokens.

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

2024-01-22 Thread Emilia Kond via cfe-commits


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

rymiel wrote:

88d1de5ec64210686d93a90529583505635d257d

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] Don't confuse initializer equal signs in for loops (PR #77712)

2024-01-22 Thread Emilia Kond via cfe-commits

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


[clang] [clang-format] Skip PP directives when determining brace kind (PR #69473)

2023-10-18 Thread Emilia Kond via cfe-commits

https://github.com/rymiel created 
https://github.com/llvm/llvm-project/pull/69473

Pull request #65409 changed the brace kind heuristic to not treat a 
preprocessor if directive as a in statement, however, this caused some 
regressions.

If the contents of a brace don't immediately determine the brace kind, the 
heuristic will look at the characters immediately before and after the closing 
brace to determine the brace type.

Unfortunately, if the closing brace was preceded by a preprocessor directive, 
for example `#endif`, the preceding token was `endif`, seen as just an 
identifier, so the braces were understood as a braced list.

This patch fixes this behaviour by skipping all preprocessor directives when 
calculating brace types. Comments were already being skipped, so now 
preprocessor lines are skipped alongside comments.

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

>From 1e4e878d251b44aa68fb8bc6422a9ec4e3de4e12 Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Wed, 18 Oct 2023 18:03:32 +0300
Subject: [PATCH] [clang-format] Skip PP directives when determining brace kind

Pull request #65409 changed the brace kind heuristic to not treat a
preprocessor if directive as a in statement, however, this caused some
regressions.

If the contents of a brace don't immediately determine the brace kind,
the heuristic will look at the characters immediately before and after
the closing brace to determine the brace type.

Unfortunately, if the closing brace was preceded by a preprocessor
directive, for example `#endif`, the preceding token was `endif`, seen
as just an identifier, so the braces were understood as a braced list.

This patch fixes this behaviour by skipping all preprocessor directives
when calculating brace types. Comments were already being skipped, so
now preprocessor lines are skipped alongside comments.

Fixes https://github.com/llvm/llvm-project/issues/68404
---
 clang/lib/Format/UnwrappedLineParser.cpp  | 23 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 15 
 2 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 708b70489a114e3..90e68e875fd462b 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -491,11 +491,19 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
   SmallVector LBraceStack;
   assert(Tok->is(tok::l_brace));
   do {
-// Get next non-comment token.
-FormatToken *NextTok;
-do {
-  NextTok = Tokens->getNextToken();
-} while (NextTok->is(tok::comment));
+// Get next non-comment, non-preprocessor token.
+FormatToken *NextTok = Tokens->getNextToken();
+while (NextTok->is(tok::comment) ||
+   (NextTok->is(tok::hash) && isOnNewLine(*NextTok))) {
+  while (NextTok->is(tok::comment))
+NextTok = Tokens->getNextToken();
+  while (NextTok->is(tok::hash) && isOnNewLine(*NextTok)) {
+ScopedMacroState MacroState(*Line, Tokens, NextTok);
+do {
+  NextTok = Tokens->getNextToken();
+} while (NextTok->isNot(tok::eof));
+  }
+}
 
 switch (Tok->Tok.getKind()) {
 case tok::l_brace:
@@ -611,12 +619,9 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
   if (Tok->isNot(TT_StatementMacro))
 break;
   [[fallthrough]];
-case tok::kw_if:
-  if (PrevTok->is(tok::hash))
-break;
-  [[fallthrough]];
 case tok::at:
 case tok::semi:
+case tok::kw_if:
 case tok::kw_while:
 case tok::kw_for:
 case tok::kw_switch:
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 2d046947996693f..8c76823fdeb6ecd 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2134,6 +2134,7 @@ TEST_F(TokenAnnotatorTest, UnderstandConstructors) {
   EXPECT_TOKEN(Tokens[11], tok::l_paren, TT_Unknown);
   EXPECT_TOKEN(Tokens[12], tok::r_paren, TT_Unknown);
   EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
+  EXPECT_BRACE_KIND(Tokens[13], BK_Block);
 
   Tokens = annotate("Class::Class() : BaseClass{}, Member{} {}");
   ASSERT_EQ(Tokens.size(), 16u) << Tokens;
@@ -2146,6 +2147,20 @@ TEST_F(TokenAnnotatorTest, UnderstandConstructors) {
   EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_Unknown);
   EXPECT_TOKEN(Tokens[12], tok::r_brace, TT_Unknown);
   EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
+  EXPECT_BRACE_KIND(Tokens[13], BK_Block);
+
+  Tokens = annotate("class Class {\n"
+"  Class() : BaseClass() {\n"
+"#if 0\n"
+"// comment\n"
+"#endif\n"
+"  }\n"
+"  Class f();\n"
+"}");
+  ASSERT_EQ(Tokens.size(), 25u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::co

[clang] [clang-format] Skip PP directives when determining brace kind (PR #69473)

2023-10-18 Thread Emilia Kond via cfe-commits

rymiel wrote:

Here's my solution to the regression I caused 
(https://github.com/llvm/llvm-project/issues/68404), but I don't think it's a 
particularly nice solution
let me know what I should change (there's some code duplication that should 
probably be extracted out)

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


[clang] [clang-format] Skip PP directives when determining brace kind (PR #69473)

2023-10-19 Thread Emilia Kond via cfe-commits


@@ -491,11 +491,19 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
   SmallVector LBraceStack;
   assert(Tok->is(tok::l_brace));
   do {
-// Get next non-comment token.
-FormatToken *NextTok;
-do {
-  NextTok = Tokens->getNextToken();
-} while (NextTok->is(tok::comment));
+// Get next non-comment, non-preprocessor token.
+FormatToken *NextTok = Tokens->getNextToken();
+while (NextTok->is(tok::comment) ||
+   (NextTok->is(tok::hash) && isOnNewLine(*NextTok))) {
+  while (NextTok->is(tok::comment))
+NextTok = Tokens->getNextToken();
+  while (NextTok->is(tok::hash) && isOnNewLine(*NextTok)) {
+ScopedMacroState MacroState(*Line, Tokens, NextTok);
+do {
+  NextTok = Tokens->getNextToken();
+} while (NextTok->isNot(tok::eof));
+  }
+}

rymiel wrote:

removing isOnNewLine causes test failures containing macro stringizing 
operators (which also uses `#`)

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


[clang] [clang-format] Skip PP directives when determining brace kind (PR #69473)

2023-10-20 Thread Emilia Kond via cfe-commits


@@ -491,11 +491,19 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
   SmallVector LBraceStack;
   assert(Tok->is(tok::l_brace));
   do {
-// Get next non-comment token.
-FormatToken *NextTok;
-do {
-  NextTok = Tokens->getNextToken();
-} while (NextTok->is(tok::comment));
+// Get next non-comment, non-preprocessor token.
+FormatToken *NextTok = Tokens->getNextToken();
+while (NextTok->is(tok::comment) ||
+   (NextTok->is(tok::hash) && isOnNewLine(*NextTok))) {
+  while (NextTok->is(tok::comment))
+NextTok = Tokens->getNextToken();
+  while (NextTok->is(tok::hash) && isOnNewLine(*NextTok)) {
+ScopedMacroState MacroState(*Line, Tokens, NextTok);
+do {
+  NextTok = Tokens->getNextToken();
+} while (NextTok->isNot(tok::eof));
+  }
+}

rymiel wrote:

Ah, sorry, I missed the fact that you gave `NewlinesBefore` as the replacement 
to `isOnNewLine`, yes, that works better, thank you

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


[clang] [clang-format] Skip PP directives when determining brace kind (PR #69473)

2023-10-20 Thread Emilia Kond via cfe-commits

https://github.com/rymiel updated 
https://github.com/llvm/llvm-project/pull/69473

>From 1e4e878d251b44aa68fb8bc6422a9ec4e3de4e12 Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Wed, 18 Oct 2023 18:03:32 +0300
Subject: [PATCH 1/2] [clang-format] Skip PP directives when determining brace
 kind

Pull request #65409 changed the brace kind heuristic to not treat a
preprocessor if directive as a in statement, however, this caused some
regressions.

If the contents of a brace don't immediately determine the brace kind,
the heuristic will look at the characters immediately before and after
the closing brace to determine the brace type.

Unfortunately, if the closing brace was preceded by a preprocessor
directive, for example `#endif`, the preceding token was `endif`, seen
as just an identifier, so the braces were understood as a braced list.

This patch fixes this behaviour by skipping all preprocessor directives
when calculating brace types. Comments were already being skipped, so
now preprocessor lines are skipped alongside comments.

Fixes https://github.com/llvm/llvm-project/issues/68404
---
 clang/lib/Format/UnwrappedLineParser.cpp  | 23 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 15 
 2 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 708b70489a114e3..90e68e875fd462b 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -491,11 +491,19 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
   SmallVector LBraceStack;
   assert(Tok->is(tok::l_brace));
   do {
-// Get next non-comment token.
-FormatToken *NextTok;
-do {
-  NextTok = Tokens->getNextToken();
-} while (NextTok->is(tok::comment));
+// Get next non-comment, non-preprocessor token.
+FormatToken *NextTok = Tokens->getNextToken();
+while (NextTok->is(tok::comment) ||
+   (NextTok->is(tok::hash) && isOnNewLine(*NextTok))) {
+  while (NextTok->is(tok::comment))
+NextTok = Tokens->getNextToken();
+  while (NextTok->is(tok::hash) && isOnNewLine(*NextTok)) {
+ScopedMacroState MacroState(*Line, Tokens, NextTok);
+do {
+  NextTok = Tokens->getNextToken();
+} while (NextTok->isNot(tok::eof));
+  }
+}
 
 switch (Tok->Tok.getKind()) {
 case tok::l_brace:
@@ -611,12 +619,9 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
   if (Tok->isNot(TT_StatementMacro))
 break;
   [[fallthrough]];
-case tok::kw_if:
-  if (PrevTok->is(tok::hash))
-break;
-  [[fallthrough]];
 case tok::at:
 case tok::semi:
+case tok::kw_if:
 case tok::kw_while:
 case tok::kw_for:
 case tok::kw_switch:
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 2d046947996693f..8c76823fdeb6ecd 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2134,6 +2134,7 @@ TEST_F(TokenAnnotatorTest, UnderstandConstructors) {
   EXPECT_TOKEN(Tokens[11], tok::l_paren, TT_Unknown);
   EXPECT_TOKEN(Tokens[12], tok::r_paren, TT_Unknown);
   EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
+  EXPECT_BRACE_KIND(Tokens[13], BK_Block);
 
   Tokens = annotate("Class::Class() : BaseClass{}, Member{} {}");
   ASSERT_EQ(Tokens.size(), 16u) << Tokens;
@@ -2146,6 +2147,20 @@ TEST_F(TokenAnnotatorTest, UnderstandConstructors) {
   EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_Unknown);
   EXPECT_TOKEN(Tokens[12], tok::r_brace, TT_Unknown);
   EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
+  EXPECT_BRACE_KIND(Tokens[13], BK_Block);
+
+  Tokens = annotate("class Class {\n"
+"  Class() : BaseClass() {\n"
+"#if 0\n"
+"// comment\n"
+"#endif\n"
+"  }\n"
+"  Class f();\n"
+"}");
+  ASSERT_EQ(Tokens.size(), 25u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::colon, TT_CtorInitializerColon);
+  EXPECT_TOKEN(Tokens[10], tok::l_brace, TT_FunctionLBrace);
+  EXPECT_BRACE_KIND(Tokens[10], BK_Block);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsConditionParens) {

>From d66e797768d3a97a15973ad780e1ab76364f581b Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Fri, 20 Oct 2023 21:26:58 +0300
Subject: [PATCH 2/2] Comments from review

Co-authored-by: Owen Pan 
---
 clang/lib/Format/UnwrappedLineParser.cpp | 19 +--
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 90e68e875fd462b..6d5d87d6606a277 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -492,17 +492,16 @@ void UnwrappedLineParser::calc

[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Emilia Kond via cfe-commits

rymiel wrote:

> I don't want to "advertise" this new style in the documentation but am 
> willing to be overruled by the majority.

But you added it to the help text?

(I'm fine with this being undocumented)

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


[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2023-10-21 Thread Emilia Kond via cfe-commits

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


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


[clang] [clang-format] Don't break between string literal operands of << (PR #69871)

2023-10-22 Thread Emilia Kond via cfe-commits


@@ -5118,10 +5118,6 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
&Line,
 return true;
   if (Left.IsUnterminatedLiteral)
 return true;
-  if (Right.is(tok::lessless) && Right.Next && Left.is(tok::string_literal) &&

rymiel wrote:

https://github.com/llvm/llvm-project/commit/2603ee0dc6003be0fbe43038b34580864d1e0c85
Here, 11 years ago

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


[clang] [clang-format] Don't alter SpacesRequiredBefore of finalized tokens (PR #69897)

2023-10-23 Thread Emilia Kond via cfe-commits

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

Thank you so much!

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


[clang] [clang-format] Skip PP directives when determining brace kind (PR #69473)

2023-10-23 Thread Emilia Kond via cfe-commits

rymiel wrote:

I didn't expect you to not want to be credited, but I'll respect your opinion! 
GitHub adds co-ownership automatically if using the web ui to commit a 
suggestion (which is what happened in that other PR you pinged me in), but in 
this case I did add it manually :)

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


[clang] [clang-format] Correctly annotate keyword operator function name (PR #66904)

2023-09-27 Thread Emilia Kond via cfe-commits

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


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


[clang] [clang-format] Fix requires misannotation with comma (PR #65908)

2023-09-27 Thread Emilia Kond via cfe-commits

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


[clang] [clang-format] Don't align ctors and dtors with other functions (PR #67618)

2023-09-28 Thread Emilia Kond via cfe-commits

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


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


[clang] [clang-format] Annotate ctors/dtors as CtorDtorDeclName instead (PR #67955)

2023-10-03 Thread Emilia Kond via cfe-commits

rymiel wrote:

https://buildkite.com/llvm-project/clang-ci/builds/4275#018af20e-3d3c-4344-b92d-88ac8b09b484
 Tests do not pass?

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


[clang] [clang-format] Allow default values for template parameters in lambda (PR #69052)

2023-10-14 Thread Emilia Kond via cfe-commits

https://github.com/rymiel created 
https://github.com/llvm/llvm-project/pull/69052

Previously, upon encountering an equals sign while parsing a lambda in the 
UnwrappedLineParser, it would fall through and fail. This caused any lambda 
template with a default argument for a template parameter to be annotated as an 
ArraySubscriptLSquare.

This patch allows equals signs in the UnwrappedLineParser if we're currently in 
a template parameter list. This resolved a FIXME that was in the lambda parsing 
function.

This patch seems deceptively easy, it's likely it doesn't solve the FIXME 
entirely, or causes other issues (the FIXME itself mentions something about 
Objective-C, which I cannot comment about). However this patch is sufficient to 
fix the below issue.

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

>From 4f532ab0ae47bce011043f41cfac3ad3e601dd41 Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Sat, 14 Oct 2023 16:52:31 +0300
Subject: [PATCH] [clang-format] Allow default values for template parameters
 in lambda

Previously, upon encountering an equals sign while parsing a lambda in
the UnwrappedLineParser, it would fall through and fail. This caused any
lambda template with a default argument for a template parameter to be
annotated as an ArraySubscriptLSquare.

This patch allows equals signs in the UnwrappedLineParser if we're
currently in a template parameter list. This resolved a FIXME that was
in the lambda parsing function.

This patch seems deceptively easy, it's likely it doesn't solve the
FIXME entirely, or causes other issues (the FIXME itself mentions
something about Objective-C, which I cannot comment about). However this
patch is sufficient to fix the below issue.

Fixes https://github.com/llvm/llvm-project/issues/68913
---
 clang/lib/Format/UnwrappedLineParser.cpp  |  9 +++--
 clang/unittests/Format/TokenAnnotatorTest.cpp | 38 +++
 2 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 82a812fc8bcc610..45a3fdbb5ba12e0 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2226,9 +2226,6 @@ bool UnwrappedLineParser::tryToParseLambda() {
 // followed by an `a->b` expression, such as:
 // ([obj func:arg] + a->b)
 // Otherwise the code below would parse as a lambda.
-//
-// FIXME: This heuristic is incorrect for C++20 generic lambdas with
-// explicit template lists: [](U &&u){}
 case tok::plus:
 case tok::minus:
 case tok::exclaim:
@@ -2268,6 +2265,12 @@ bool UnwrappedLineParser::tryToParseLambda() {
   parseRequiresClause(RequiresToken);
   break;
 }
+case tok::equal:
+  if (InTemplateParameterList) {
+nextToken();
+break;
+  }
+  return true;
 default:
   return true;
 }
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index b6d4cf166de0281..f4f382cfe8f2494 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1620,6 +1620,44 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
   EXPECT_TOKEN(Tokens[15], tok::kw_requires, TT_RequiresClause);
   EXPECT_TRUE(Tokens[19]->ClosesRequiresClause);
   EXPECT_TOKEN(Tokens[20], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  (T t) {}");
+  ASSERT_EQ(Tokens.size(), 15u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  (T t) {}");
+  ASSERT_EQ(Tokens.size(), 15u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  (T t) {}");
+  ASSERT_EQ(Tokens.size(), 15u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  (T&& t) {}");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[9], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[12], tok::ampamp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[15], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  requires Foo (T t) {}");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+ 

[clang] [clang-format] Allow default values for template parameters in lambda (PR #69052)

2023-10-16 Thread Emilia Kond via cfe-commits

https://github.com/rymiel updated 
https://github.com/llvm/llvm-project/pull/69052

>From 4f532ab0ae47bce011043f41cfac3ad3e601dd41 Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Sat, 14 Oct 2023 16:52:31 +0300
Subject: [PATCH 1/2] [clang-format] Allow default values for template
 parameters in lambda

Previously, upon encountering an equals sign while parsing a lambda in
the UnwrappedLineParser, it would fall through and fail. This caused any
lambda template with a default argument for a template parameter to be
annotated as an ArraySubscriptLSquare.

This patch allows equals signs in the UnwrappedLineParser if we're
currently in a template parameter list. This resolved a FIXME that was
in the lambda parsing function.

This patch seems deceptively easy, it's likely it doesn't solve the
FIXME entirely, or causes other issues (the FIXME itself mentions
something about Objective-C, which I cannot comment about). However this
patch is sufficient to fix the below issue.

Fixes https://github.com/llvm/llvm-project/issues/68913
---
 clang/lib/Format/UnwrappedLineParser.cpp  |  9 +++--
 clang/unittests/Format/TokenAnnotatorTest.cpp | 38 +++
 2 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 82a812fc8bcc610..45a3fdbb5ba12e0 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2226,9 +2226,6 @@ bool UnwrappedLineParser::tryToParseLambda() {
 // followed by an `a->b` expression, such as:
 // ([obj func:arg] + a->b)
 // Otherwise the code below would parse as a lambda.
-//
-// FIXME: This heuristic is incorrect for C++20 generic lambdas with
-// explicit template lists: [](U &&u){}
 case tok::plus:
 case tok::minus:
 case tok::exclaim:
@@ -2268,6 +2265,12 @@ bool UnwrappedLineParser::tryToParseLambda() {
   parseRequiresClause(RequiresToken);
   break;
 }
+case tok::equal:
+  if (InTemplateParameterList) {
+nextToken();
+break;
+  }
+  return true;
 default:
   return true;
 }
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index b6d4cf166de0281..f4f382cfe8f2494 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1620,6 +1620,44 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
   EXPECT_TOKEN(Tokens[15], tok::kw_requires, TT_RequiresClause);
   EXPECT_TRUE(Tokens[19]->ClosesRequiresClause);
   EXPECT_TOKEN(Tokens[20], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  (T t) {}");
+  ASSERT_EQ(Tokens.size(), 15u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  (T t) {}");
+  ASSERT_EQ(Tokens.size(), 15u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  (T t) {}");
+  ASSERT_EQ(Tokens.size(), 15u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  (T&& t) {}");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[9], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[12], tok::ampamp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[15], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  requires Foo (T t) {}");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[8], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[17], tok::l_brace, TT_LambdaLBrace);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsFunctionAnnotations) {

>From 819938fb70e3d6ff7558dfa565c94416ac203140 Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Mon, 16 Oct 2023 13:51:22 +0300
Subject: [PATCH 2/2] Suggestion from code review

Co-authored-by: Owen Pan 
---
 clang/lib/Format/UnwrappedLineParser.cpp | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 45a3fdbb5b

[clang] [clang-format] Allow default values for template parameters in lambda (PR #69052)

2023-10-16 Thread Emilia Kond via cfe-commits

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


[clang] [clang-format] Correctly annotate designated initializer with PP if (PR #65409)

2023-09-07 Thread Emilia Kond via cfe-commits

https://github.com/rymiel updated 
https://github.com/llvm/llvm-project/pull/65409:

>From e15868400981600b7dc68229660391a7874e67af Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Tue, 5 Sep 2023 22:44:41 +0300
Subject: [PATCH 1/2] [clang-format] Correctly annotate designated initializer
 with PP if

When encountering braces, such as those of a designated initializer,
clang-format scans ahead to see what is contained within the braces. If
it found a statement, like an if-statement of for-loop, it would deem
the braces as not an initializer, but as a block instead.

However, this heuristic incorrectly included a preprocessor `#if` line as
an if-statement. This manifested in strange results and discrepancies
between `#ifdef` and `#if defined`.

With this patch, `if` is now ignored if it is preceeded by `#`.

Fixes most of https://github.com/llvm/llvm-project/issues/56685
---
 clang/lib/Format/UnwrappedLineParser.cpp  |  2 ++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 35 +++
 2 files changed, 37 insertions(+)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 5a82b200055a874..eaebc69879b9732 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -626,6 +626,8 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
 case tok::kw_switch:
 case tok::kw_try:
 case tok::kw___try:
+  if (PrevTok->is(tok::hash))
+break;
   if (!LBraceStack.empty() && LBraceStack.back().Tok->is(BK_Unknown))
 LBraceStack.back().Tok->setBlockKind(BK_Block);
   break;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 467ade965d7c86a..ac2b60530f2fb18 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1998,6 +1998,41 @@ TEST_F(TokenAnnotatorTest, UnderstandsNestedBlocks) {
   EXPECT_BRACE_KIND(Tokens[10], BK_Block);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandDesignatedInitializers) {
+  auto Tokens = annotate("SomeStruct { .a = 1 };");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[1], BK_BracedInit);
+  EXPECT_TOKEN(Tokens[2], tok::period, TT_DesignatedInitializerPeriod);
+
+  Tokens = annotate("SomeStruct { .a = 1, .b = 2 };");
+  ASSERT_EQ(Tokens.size(), 14u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[1], BK_BracedInit);
+  EXPECT_TOKEN(Tokens[2], tok::period, TT_DesignatedInitializerPeriod);
+  EXPECT_TOKEN(Tokens[7], tok::period, TT_DesignatedInitializerPeriod);
+
+  Tokens = annotate("SomeStruct {\n"
+  "#ifdef FOO\n"
+  "  .a = 1,\n"
+  "#endif\n"
+  "  .b = 2\n"
+  "};");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[1], BK_BracedInit);
+  EXPECT_TOKEN(Tokens[5], tok::period, TT_DesignatedInitializerPeriod);
+  EXPECT_TOKEN(Tokens[12], tok::period, TT_DesignatedInitializerPeriod);
+
+  Tokens = annotate("SomeStruct {\n"
+  "#if defined FOO\n"
+  "  .a = 1,\n"
+  "#endif\n"
+  "  .b = 2\n"
+  "};");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[1], BK_BracedInit);
+  EXPECT_TOKEN(Tokens[6], tok::period, TT_DesignatedInitializerPeriod);
+  EXPECT_TOKEN(Tokens[13], tok::period, TT_DesignatedInitializerPeriod);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang

>From 88c1e108cc191ddc1c288b57ae202603d4daa962 Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Thu, 7 Sep 2023 21:34:31 +0300
Subject: [PATCH 2/2] address comments

---
 clang/lib/Format/UnwrappedLineParser.cpp  |  7 ---
 clang/unittests/Format/TokenAnnotatorTest.cpp | 20 +--
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index eaebc69879b9732..dae2742d27fcbde 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -618,16 +618,17 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
   if (Tok->isNot(TT_StatementMacro))
 break;
   [[fallthrough]];
+case tok::kw_if:
+  if (PrevTok->is(tok::hash))
+break;
+  [[fallthrough]];
 case tok::at:
 case tok::semi:
-case tok::kw_if:
 case tok::kw_while:
 case tok::kw_for:
 case tok::kw_switch:
 case tok::kw_try:
 case tok::kw___try:
-  if (PrevTok->is(tok::hash))
-break;
   if (!LBraceStack.empty() && LBraceStack.back().Tok->is(BK_Unknown))
 LBraceStack.back().Tok->setBlockKind(BK_Block);
   break;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index ac2b60530f2fb18..7ac6bd32620e3d8 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2011,22 +2011,22 @@ TEST_F(TokenAnnotatorTest, 
UnderstandDesignatedInitializers) {
   EXPECT_TOK

[clang] [clang-format] Correctly annotate designated initializer with PP if (PR #65409)

2023-09-07 Thread Emilia Kond via cfe-commits

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


[clang] [clang-format] BreakBeforeNoexceptSpecifier option added (PR #65808)

2023-09-08 Thread Emilia Kond via cfe-commits

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


[clang] [clang-format] BreakBeforeNoexceptSpecifier option added (PR #65808)

2023-09-08 Thread Emilia Kond via cfe-commits

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


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


[clang] [clang-format] BreakBeforeNoexceptSpecifier option added (PR #65808)

2023-09-08 Thread Emilia Kond via cfe-commits


@@ -593,6 +593,47 @@ struct FormatStyle {
   /// \version 3.3
   bool AllowAllParametersOfDeclarationOnNextLine;
 
+  /// Different ways to break before a noexcept specifier.
+  enum BreakBeforeNoexceptSpecifierStyle : int8_t {
+/// No line break allowed.
+/// \code
+///   void foo(int arg1,
+///double arg2) noexcept;
+///
+///   void bar(int arg1, double arg2) noexcept(
+///   noexcept(baz(arg1)) &&
+///   noexcept(baz(arg2)));
+/// \endcode
+BBNSS_Never,
+/// For a simple ``noexcept`` there is no line break allowed, but when we
+/// have a condition it is.
+/// \code
+///   void foo(int arg1,
+///double arg2) noexcept;
+///
+///   void bar(int arg1, double arg2)
+///   noexcept(noexcept(baz(arg1)) &&
+///noexcept(baz(arg2)));
+/// \endcode
+BBNSS_OnlyWithParen,
+/// Line breaks are allowed. Bute note that because of the associtated

rymiel wrote:

```suggestion
/// Line breaks are allowed. But note that because of the associated
```

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


[clang] Extension: allow recursive macros (PR #65851)

2023-09-09 Thread Emilia Kond via cfe-commits

rymiel wrote:

How would you deal with the issue of infinite loops? The following program:

```cpp
#define2 boom(X) boom(X)

boom(0)
```

Will continue to infinitely(?) consume memory until it is killed, either by the 
user or due to running out of memory on the system

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


[clang] [clang-format] Fix requires misannotation with comma (PR #65908)

2023-09-10 Thread Emilia Kond via cfe-commits

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


[clang] [clang-format] Fix requires misannotation with comma (PR #65908)

2023-09-10 Thread Emilia Kond via cfe-commits

https://github.com/rymiel created 
https://github.com/llvm/llvm-project/pull/65908:

clang-format uses a heuristic to determine if a requires() is either a requires 
clause or requires expression, based on what is in the parentheses. Part of 
this heuristic assumed that a requires clause can never contain a comma, 
however this is not the case if said comma is in the template argument of a 
type.

This patch allows commas to appear in a requires clause if an angle bracket `<` 
has been opened.

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

>From 0cfeaee5ec5c431bc15fb037f2a20c944c508c2a Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Sun, 10 Sep 2023 23:01:39 +0300
Subject: [PATCH] [clang-format] Fix requires misannotation with comma

clang-format uses a heuristic to determine if a requires() is either a
requires clause or requires expression, based on what is in the
parentheses. Part of this heuristic assumed that a requires clause can
never contain a comma, however this is not the case if said comma is in
the template argument of a type.

This patch allows commas to appear in a requires clause if an angle
bracket `<` has been opened.

Fixes https://github.com/llvm/llvm-project/issues/65904
---
 clang/lib/Format/UnwrappedLineParser.cpp  | 10 +++---
 clang/unittests/Format/TokenAnnotatorTest.cpp |  8 
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 0ff0656a92d7222..7af9a0cba221458 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3369,9 +3369,13 @@ bool clang::format::UnwrappedLineParser::parseRequires() 
{
 case tok::kw_volatile:
 case tok::kw_const:
 case tok::comma:
-  FormatTok = Tokens->setPosition(StoredPosition);
-  parseRequiresExpression(RequiresToken);
-  return false;
+  if (OpenAngles == 0) {
+FormatTok = Tokens->setPosition(StoredPosition);
+parseRequiresExpression(RequiresToken);
+return false;
+  } else {
+break;
+  }
 case tok::r_paren:
 case tok::pipepipe:
   FormatTok = Tokens->setPosition(StoredPosition);
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 434852983712940..f3cdb8a8b2cc1b4 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1016,6 +1016,14 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
   ASSERT_EQ(Tokens.size(), 22u) << Tokens;
   EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause);
   EXPECT_TOKEN(Tokens[10], tok::ampamp, TT_PointerOrReference);
+
+  Tokens = annotate("void f() & requires(true) {}");
+  EXPECT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
+
+  Tokens = annotate("void f() & requires(C) {}");
+  EXPECT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {

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


[clang] [clang-format] Fix requires misannotation with comma (PR #65908)

2023-09-10 Thread Emilia Kond via cfe-commits


@@ -3369,9 +3369,13 @@ bool clang::format::UnwrappedLineParser::parseRequires() 
{
 case tok::kw_volatile:
 case tok::kw_const:
 case tok::comma:
-  FormatTok = Tokens->setPosition(StoredPosition);
-  parseRequiresExpression(RequiresToken);
-  return false;
+  if (OpenAngles == 0) {
+FormatTok = Tokens->setPosition(StoredPosition);
+parseRequiresExpression(RequiresToken);
+return false;
+  } else {
+break;
+  }

rymiel wrote:


I realized after that i could do this. Would this be preferred?
```suggestion
  if (OpenAngles != 0)
break;
  FormatTok = Tokens->setPosition(StoredPosition);
  parseRequiresExpression(RequiresToken);
  return false;
```


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


[clang] [clang-format] Fix requires misannotation with comma (PR #65908)

2023-09-10 Thread Emilia Kond via cfe-commits

https://github.com/rymiel updated 
https://github.com/llvm/llvm-project/pull/65908:

>From 0cfeaee5ec5c431bc15fb037f2a20c944c508c2a Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Sun, 10 Sep 2023 23:01:39 +0300
Subject: [PATCH 1/2] [clang-format] Fix requires misannotation with comma

clang-format uses a heuristic to determine if a requires() is either a
requires clause or requires expression, based on what is in the
parentheses. Part of this heuristic assumed that a requires clause can
never contain a comma, however this is not the case if said comma is in
the template argument of a type.

This patch allows commas to appear in a requires clause if an angle
bracket `<` has been opened.

Fixes https://github.com/llvm/llvm-project/issues/65904
---
 clang/lib/Format/UnwrappedLineParser.cpp  | 10 +++---
 clang/unittests/Format/TokenAnnotatorTest.cpp |  8 
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 0ff0656a92d7222..7af9a0cba221458 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3369,9 +3369,13 @@ bool clang::format::UnwrappedLineParser::parseRequires() 
{
 case tok::kw_volatile:
 case tok::kw_const:
 case tok::comma:
-  FormatTok = Tokens->setPosition(StoredPosition);
-  parseRequiresExpression(RequiresToken);
-  return false;
+  if (OpenAngles == 0) {
+FormatTok = Tokens->setPosition(StoredPosition);
+parseRequiresExpression(RequiresToken);
+return false;
+  } else {
+break;
+  }
 case tok::r_paren:
 case tok::pipepipe:
   FormatTok = Tokens->setPosition(StoredPosition);
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 434852983712940..f3cdb8a8b2cc1b4 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1016,6 +1016,14 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
   ASSERT_EQ(Tokens.size(), 22u) << Tokens;
   EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause);
   EXPECT_TOKEN(Tokens[10], tok::ampamp, TT_PointerOrReference);
+
+  Tokens = annotate("void f() & requires(true) {}");
+  EXPECT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
+
+  Tokens = annotate("void f() & requires(C) {}");
+  EXPECT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {

>From 7dc5321cf79d3b59546a45040c9434dff3076844 Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Sun, 10 Sep 2023 23:27:16 +0300
Subject: [PATCH 2/2] Adjust tests

---
 clang/lib/Format/UnwrappedLineParser.cpp  |  3 +--
 clang/unittests/Format/TokenAnnotatorTest.cpp | 10 ++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 7af9a0cba221458..c88e081936094bd 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3373,9 +3373,8 @@ bool clang::format::UnwrappedLineParser::parseRequires() {
 FormatTok = Tokens->setPosition(StoredPosition);
 parseRequiresExpression(RequiresToken);
 return false;
-  } else {
-break;
   }
+  break;
 case tok::r_paren:
 case tok::pipepipe:
   FormatTok = Tokens->setPosition(StoredPosition);
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index f3cdb8a8b2cc1b4..b1e14925281546c 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1019,10 +1019,12 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
 
   Tokens = annotate("void f() & requires(true) {}");
   EXPECT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
   EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
 
   Tokens = annotate("void f() & requires(C) {}");
   EXPECT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
   EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
 }
 
@@ -1143,6 +1145,14 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresExpressions) {
   EXPECT_TOKEN(Tokens[3], tok::kw_requires, TT_RequiresExpression);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_RequiresExpressionLParen);
   EXPECT_TOKEN(Tokens[14], tok::l_brace, TT_RequiresExpressionLBrace);
+
+  Tokens = annotate("bool foo = requires(C c) {\n"
+"  { c.foo(); }\n"
+"}");
+  ASSERT_EQ(Tokens.size(), 24u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::kw_requires, TT_RequiresExpression);
+  EXPECT_TOKEN(Tokens[4], tok::l_paren, T

[clang] [clang-format] Fix requires misannotation with comma (PR #65908)

2023-09-10 Thread Emilia Kond via cfe-commits

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


[clang] [clang-format] Fix requires misannotation with comma (PR #65908)

2023-09-10 Thread Emilia Kond via cfe-commits

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


[clang] [clang-format] Fix requires misannotation with comma (PR #65908)

2023-09-10 Thread Emilia Kond via cfe-commits

https://github.com/rymiel resolved 
https://github.com/llvm/llvm-project/pull/65908
___
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 annotating `&&` enclosed in `<` and `>` (PR #65933)

2023-09-11 Thread Emilia Kond via cfe-commits

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

I'm also suspicious of if a dereference like `*j` should ever be legal in a 
template argument, but that would be a different case

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


[clang] [clang-format] Fix requires misannotation with comma (PR #65908)

2023-09-16 Thread Emilia Kond via cfe-commits

https://github.com/rymiel updated 
https://github.com/llvm/llvm-project/pull/65908

>From 0cfeaee5ec5c431bc15fb037f2a20c944c508c2a Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Sun, 10 Sep 2023 23:01:39 +0300
Subject: [PATCH 1/3] [clang-format] Fix requires misannotation with comma

clang-format uses a heuristic to determine if a requires() is either a
requires clause or requires expression, based on what is in the
parentheses. Part of this heuristic assumed that a requires clause can
never contain a comma, however this is not the case if said comma is in
the template argument of a type.

This patch allows commas to appear in a requires clause if an angle
bracket `<` has been opened.

Fixes https://github.com/llvm/llvm-project/issues/65904
---
 clang/lib/Format/UnwrappedLineParser.cpp  | 10 +++---
 clang/unittests/Format/TokenAnnotatorTest.cpp |  8 
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 0ff0656a92d7222..7af9a0cba221458 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3369,9 +3369,13 @@ bool clang::format::UnwrappedLineParser::parseRequires() 
{
 case tok::kw_volatile:
 case tok::kw_const:
 case tok::comma:
-  FormatTok = Tokens->setPosition(StoredPosition);
-  parseRequiresExpression(RequiresToken);
-  return false;
+  if (OpenAngles == 0) {
+FormatTok = Tokens->setPosition(StoredPosition);
+parseRequiresExpression(RequiresToken);
+return false;
+  } else {
+break;
+  }
 case tok::r_paren:
 case tok::pipepipe:
   FormatTok = Tokens->setPosition(StoredPosition);
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 434852983712940..f3cdb8a8b2cc1b4 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1016,6 +1016,14 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
   ASSERT_EQ(Tokens.size(), 22u) << Tokens;
   EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause);
   EXPECT_TOKEN(Tokens[10], tok::ampamp, TT_PointerOrReference);
+
+  Tokens = annotate("void f() & requires(true) {}");
+  EXPECT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
+
+  Tokens = annotate("void f() & requires(C) {}");
+  EXPECT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {

>From 7dc5321cf79d3b59546a45040c9434dff3076844 Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Sun, 10 Sep 2023 23:27:16 +0300
Subject: [PATCH 2/3] Adjust tests

---
 clang/lib/Format/UnwrappedLineParser.cpp  |  3 +--
 clang/unittests/Format/TokenAnnotatorTest.cpp | 10 ++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 7af9a0cba221458..c88e081936094bd 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3373,9 +3373,8 @@ bool clang::format::UnwrappedLineParser::parseRequires() {
 FormatTok = Tokens->setPosition(StoredPosition);
 parseRequiresExpression(RequiresToken);
 return false;
-  } else {
-break;
   }
+  break;
 case tok::r_paren:
 case tok::pipepipe:
   FormatTok = Tokens->setPosition(StoredPosition);
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index f3cdb8a8b2cc1b4..b1e14925281546c 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1019,10 +1019,12 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
 
   Tokens = annotate("void f() & requires(true) {}");
   EXPECT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
   EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
 
   Tokens = annotate("void f() & requires(C) {}");
   EXPECT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
   EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
 }
 
@@ -1143,6 +1145,14 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresExpressions) {
   EXPECT_TOKEN(Tokens[3], tok::kw_requires, TT_RequiresExpression);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_RequiresExpressionLParen);
   EXPECT_TOKEN(Tokens[14], tok::l_brace, TT_RequiresExpressionLBrace);
+
+  Tokens = annotate("bool foo = requires(C c) {\n"
+"  { c.foo(); }\n"
+"}");
+  ASSERT_EQ(Tokens.size(), 24u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::kw_requires, TT_RequiresExpression);
+  EXPECT_TOKEN(Tokens[4], tok::l_paren, TT

[clang] [clang-format] Fix requires misannotation with comma (PR #65908)

2023-09-16 Thread Emilia Kond via cfe-commits

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


[clang] [clang-format] Fix requires misannotation with comma (PR #65908)

2023-09-16 Thread Emilia Kond via cfe-commits

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


[clang] [clang-format] Fix requires misannotation with comma (PR #65908)

2023-09-16 Thread Emilia Kond via cfe-commits

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


[clang] [clang-format][NFC] Clean up signatures of some parser functions (PR #66569)

2023-09-16 Thread Emilia Kond via cfe-commits


@@ -370,9 +364,9 @@ bool UnwrappedLineParser::parseLevel(const FormatToken 
*OpeningBrace,
 else if (FormatTok->getType() == TT_MacroBlockEnd)
   kind = tok::r_brace;
 
-auto ParseDefault = [this, OpeningBrace, NextLevelLBracesType, IfKind,
+auto ParseDefault = [this, OpeningBrace, InRequiresExpression, IfKind,
  &IfLBrace, &HasDoWhile, &HasLabel, &StatementCount] {
-  parseStructuralElement(!OpeningBrace, NextLevelLBracesType, IfKind,
+  parseStructuralElement(OpeningBrace, InRequiresExpression, IfKind,

rymiel wrote:

If `InRequiresExpression` can be determined from just `OpeningBrace`, does it 
need to be passed down here?

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


[clang] [clang-format][NFC] Clean up signatures of some parser functions (PR #66569)

2023-09-16 Thread Emilia Kond via cfe-commits

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


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


[clang] [clang-format] Correctly annotate designated initializer with PP if (PR #65409)

2023-09-05 Thread Emilia Kond via cfe-commits

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


[clang] [clang-format] Correctly annotate designated initializer with PP if (PR #65409)

2023-09-05 Thread Emilia Kond via cfe-commits

https://github.com/rymiel created 
https://github.com/llvm/llvm-project/pull/65409:

When encountering braces, such as those of a designated initializer, 
clang-format scans ahead to see what is contained within the braces. If it 
found a statement, like an if-statement of for-loop, it would deem the braces 
as not an initializer, but as a block instead.

However, this heuristic incorrectly included a preprocessor `#if` line as an 
if-statement. This manifested in strange results and discrepancies between 
`#ifdef` and `#if defined`.

With this patch, `if` is now ignored if it is preceeded by `#`.

Fixes most of https://github.com/llvm/llvm-project/issues/56685

>From e15868400981600b7dc68229660391a7874e67af Mon Sep 17 00:00:00 2001
From: Emilia Kond 
Date: Tue, 5 Sep 2023 22:44:41 +0300
Subject: [PATCH] [clang-format] Correctly annotate designated initializer with
 PP if

When encountering braces, such as those of a designated initializer,
clang-format scans ahead to see what is contained within the braces. If
it found a statement, like an if-statement of for-loop, it would deem
the braces as not an initializer, but as a block instead.

However, this heuristic incorrectly included a preprocessor `#if` line as
an if-statement. This manifested in strange results and discrepancies
between `#ifdef` and `#if defined`.

With this patch, `if` is now ignored if it is preceeded by `#`.

Fixes most of https://github.com/llvm/llvm-project/issues/56685
---
 clang/lib/Format/UnwrappedLineParser.cpp  |  2 ++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 35 +++
 2 files changed, 37 insertions(+)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 5a82b200055a87..eaebc69879b973 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -626,6 +626,8 @@ void UnwrappedLineParser::calculateBraceTypes(bool 
ExpectClassBody) {
 case tok::kw_switch:
 case tok::kw_try:
 case tok::kw___try:
+  if (PrevTok->is(tok::hash))
+break;
   if (!LBraceStack.empty() && LBraceStack.back().Tok->is(BK_Unknown))
 LBraceStack.back().Tok->setBlockKind(BK_Block);
   break;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 467ade965d7c86..ac2b60530f2fb1 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1998,6 +1998,41 @@ TEST_F(TokenAnnotatorTest, UnderstandsNestedBlocks) {
   EXPECT_BRACE_KIND(Tokens[10], BK_Block);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandDesignatedInitializers) {
+  auto Tokens = annotate("SomeStruct { .a = 1 };");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[1], BK_BracedInit);
+  EXPECT_TOKEN(Tokens[2], tok::period, TT_DesignatedInitializerPeriod);
+
+  Tokens = annotate("SomeStruct { .a = 1, .b = 2 };");
+  ASSERT_EQ(Tokens.size(), 14u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[1], BK_BracedInit);
+  EXPECT_TOKEN(Tokens[2], tok::period, TT_DesignatedInitializerPeriod);
+  EXPECT_TOKEN(Tokens[7], tok::period, TT_DesignatedInitializerPeriod);
+
+  Tokens = annotate("SomeStruct {\n"
+  "#ifdef FOO\n"
+  "  .a = 1,\n"
+  "#endif\n"
+  "  .b = 2\n"
+  "};");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[1], BK_BracedInit);
+  EXPECT_TOKEN(Tokens[5], tok::period, TT_DesignatedInitializerPeriod);
+  EXPECT_TOKEN(Tokens[12], tok::period, TT_DesignatedInitializerPeriod);
+
+  Tokens = annotate("SomeStruct {\n"
+  "#if defined FOO\n"
+  "  .a = 1,\n"
+  "#endif\n"
+  "  .b = 2\n"
+  "};");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_BRACE_KIND(Tokens[1], BK_BracedInit);
+  EXPECT_TOKEN(Tokens[6], tok::period, TT_DesignatedInitializerPeriod);
+  EXPECT_TOKEN(Tokens[13], tok::period, TT_DesignatedInitializerPeriod);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang

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


[clang] [clang-format] Correctly annotate designated initializer with PP if (PR #65409)

2023-09-05 Thread Emilia Kond via cfe-commits

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


  1   2   >