[clang] [clang-format] Enable again some operator tests (PR #83380)

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

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


[clang] [clang-format] Enable again some operator tests (PR #83380)

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


@@ -16671,9 +16667,8 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
SpaceFuncDecl);
   verifyFormat("int f () throw(Deprecated);", SpaceFuncDecl);
   verifyFormat("typedef void (*cb)(int);", SpaceFuncDecl);
-  // FIXME these tests regressed behaviour.
-  // verifyFormat("T A::operator() ();", SpaceFuncDecl);
-  // verifyFormat("X A::operator++ (T);", SpaceFuncDecl);
+  verifyFormat("T A::operator()();", SpaceFuncDecl);
+  verifyFormat("X A::operator++(T);", SpaceFuncDecl);

owenca wrote:

It seems that D114696 restored the space in `operator` function declarations 
and definitions.

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


[clang] [clang-format] Enable again some operator tests (PR #83380)

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


@@ -16797,7 +16792,7 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
   verifyFormat("int f() throw (Deprecated);", SomeSpace2);
   verifyFormat("typedef void (*cb) (int);", SomeSpace2);
   verifyFormat("T A::operator()();", SomeSpace2);
-  // verifyFormat("X A::operator++ (T);", SomeSpace2);
+  verifyFormat("X A::operator++ (T);", SomeSpace2);

owenca wrote:

Nvm.

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


[clang] [clang-format] Enable again some operator tests (PR #83380)

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


@@ -16710,7 +16705,7 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
   verifyFormat("typedef void (*cb)(int);", SpaceFuncDef);
   verifyFormat("T A::operator()();", SpaceFuncDef);
   verifyFormat("X A::operator++(T);", SpaceFuncDef);
-  // verifyFormat("T A::operator() () {}", SpaceFuncDef);
+  verifyFormat("T A::operator()() {}", SpaceFuncDef);

owenca wrote:

Why is the space removed?

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


[clang] [clang-format] Enable again some operator tests (PR #83380)

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


@@ -16797,7 +16792,7 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
   verifyFormat("int f() throw (Deprecated);", SomeSpace2);
   verifyFormat("typedef void (*cb) (int);", SomeSpace2);
   verifyFormat("T A::operator()();", SomeSpace2);
-  // verifyFormat("X A::operator++ (T);", SomeSpace2);
+  verifyFormat("X A::operator++ (T);", SomeSpace2);

owenca wrote:

Shouldn't the space be removed here?

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


[clang] [clang-format] Enable again some operator tests (PR #83380)

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


@@ -16671,9 +16667,8 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
SpaceFuncDecl);
   verifyFormat("int f () throw(Deprecated);", SpaceFuncDecl);
   verifyFormat("typedef void (*cb)(int);", SpaceFuncDecl);
-  // FIXME these tests regressed behaviour.
-  // verifyFormat("T A::operator() ();", SpaceFuncDecl);
-  // verifyFormat("X A::operator++ (T);", SpaceFuncDecl);
+  verifyFormat("T A::operator()();", SpaceFuncDecl);
+  verifyFormat("X A::operator++(T);", SpaceFuncDecl);

owenca wrote:

Why are the spaces removed?

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


[clang] [clang-format] Limit how much work guessLanguage() can do (PR #78925)

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

owenca wrote:

> > @HighCommander4 I got a better idea. It seems that we don't need to add the 
> > parameter! See #82957. I think all you need to do is to call `getStyle()` 
> > with the default `""` for the `StringRef Code` argument to skip the 
> > Objective-C guesser.
> 
> Thanks. That does seem simpler, and seems like it should work just as well 
> since the language guesser is the only thing that uses the `Code` argument.

I've merged #82957.

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


[clang] [clang-format] Add a parameter to getStyle() and guessLanguage() (PR #82911)

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

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


[clang] [clang-format][NFC] Skip ObjCHeaderStyleGuesser for empty code (PR #82957)

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

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


[clang] [clang-format] Add a parameter to getStyle() and guessLanguage() (PR #82911)

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

owenca wrote:

I will abandon this pull request if #82957 gets approved.

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


[clang] [clang-format] Add a parameter to getStyle() and guessLanguage() (PR #82911)

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

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


[clang] [clang-format] Limit how much work guessLanguage() can do (PR #78925)

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

owenca wrote:

@HighCommander4 I got a better idea. It seems that we don't need to add the 
parameter! See #82957. I think all you need to do is to call `getStyle()` with 
the default `""` for the `StringRef Code` argument to skip the Objective-C 
guesser.

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


[clang] [clang-format][NFC] Skip ObjCHeaderStyleGuesser for empty code (PR #82957)

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

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

None

>From 9334d008b4c7ae13fdeb674a6bb9b4dc62c6a1dd Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 25 Feb 2024 20:58:25 -0800
Subject: [PATCH] [clang-format][NFC] Skip ObjCHeaderStyleGuesser for empty
 code

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

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 2f6b52510099a7..00ffc6718e052b 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3920,7 +3920,7 @@ FormatStyle::LanguageKind guessLanguage(StringRef 
FileName, StringRef Code) {
 auto Extension = llvm::sys::path::extension(FileName);
 // If there's no file extension (or it's .h), we need to check the contents
 // of the code to see if it contains Objective-C.
-if (Extension.empty() || Extension == ".h") {
+if (!Code.empty() && (Extension.empty() || Extension == ".h")) {
   auto NonEmptyFileName = FileName.empty() ? "guess.h" : FileName;
   Environment Env(Code, NonEmptyFileName, /*Ranges=*/{});
   ObjCHeaderStyleGuesser Guesser(Env, getLLVMStyle());

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


[clang] 085f9b0 - [clang-format][doc] Update documentation for RemoveSemicolon

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

Author: Owen Pan
Date: 2024-02-25T16:08:37-08:00
New Revision: 085f9b0d146fc99bbb0e193593aad696fc50a056

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

LOG: [clang-format][doc] Update documentation for RemoveSemicolon

Added: 


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

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index fdf7bfaeaa4ec7..6515b166001910 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4844,7 +4844,8 @@ the configuration (without a prefix: ``Auto``).
 .. _RemoveSemicolon:
 
 **RemoveSemicolon** (``Boolean``) :versionbadge:`clang-format 16` :ref:`¶ 
`
-  Remove semicolons after the closing brace of a non-empty function.
+  Remove semicolons after the closing braces of functions and
+  constructors/destructors.
 
   .. warning::
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index e9b2160a7b9243..47923e06d2c2d1 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3771,7 +3771,8 @@ struct FormatStyle {
   /// \version 17
   RemoveParenthesesStyle RemoveParentheses;
 
-  /// Remove semicolons after the closing brace of a non-empty function.
+  /// Remove semicolons after the closing braces of functions and
+  /// constructors/destructors.
   /// \warning
   ///  Setting this option to ``true`` could lead to incorrect code formatting
   ///  due to clang-format's lack of complete semantic information. As such,



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


[clang] [clang-format] Limit how much work guessLanguage() can do (PR #78925)

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

owenca wrote:

@HighCommander4 see #82911

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


[clang] [clang-format] Add a parameter to getStyle() and guessLanguage() (PR #82911)

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

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

Add a boolean parameter GuessObjC that defaults to true. This allows e.g.
clangd to bypass ObjCHeaderStyleGuesser.process() by passing false for the
parameter.

>From bd85fd1dff5ac7b72913ed175daec3809896e6c0 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 25 Feb 2024 00:00:23 -0800
Subject: [PATCH] [clang-format] Add a parameter to getStyle() and
 guessLanguage()

Add a boolean parameter GuessObjC that defaults to true. This allows e.g.
clangd to bypass ObjCHeaderStyleGuesser.process() by passing false for the
parameter.
---
 clang/include/clang/Format/Format.h | 13 +++--
 clang/lib/Format/Format.cpp |  9 +
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index e9b2160a7b9243..af635a89d21312 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5228,19 +5228,20 @@ extern const char *DefaultFallbackStyle;
 /// \param[in] AllowUnknownOptions If true, unknown format options only
 /// emit a warning. If false, errors are emitted on unknown format
 /// options.
+/// \param[in] GuessObjC If true, guess and see if the language is Objective-C.
 ///
 /// \returns FormatStyle as specified by ``StyleName``. If ``StyleName`` is
 /// "file" and no file is found, returns ``FallbackStyle``. If no style could 
be
 /// determined, returns an Error.
-llvm::Expected getStyle(StringRef StyleName, StringRef FileName,
- StringRef FallbackStyle,
- StringRef Code = "",
- llvm::vfs::FileSystem *FS = nullptr,
- bool AllowUnknownOptions = false);
+llvm::Expected
+getStyle(StringRef StyleName, StringRef FileName, StringRef FallbackStyle,
+ StringRef Code = "", llvm::vfs::FileSystem *FS = nullptr,
+ bool AllowUnknownOptions = false, bool GuessObjC = true);
 
 // Guesses the language from the ``FileName`` and ``Code`` to be formatted.
 // Defaults to FormatStyle::LK_Cpp.
-FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code);
+FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code,
+bool GuessObjC = true);
 
 // Returns a string representation of ``Language``.
 inline StringRef getLanguageName(FormatStyle::LanguageKind Language) {
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 2f6b52510099a7..f5190745165ef6 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3914,13 +3914,14 @@ static FormatStyle::LanguageKind 
getLanguageByFileName(StringRef FileName) {
   return FormatStyle::LK_Cpp;
 }
 
-FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code) {
+FormatStyle::LanguageKind guessLanguage(StringRef FileName, StringRef Code,
+bool GuessObjC) {
   const auto GuessedLanguage = getLanguageByFileName(FileName);
   if (GuessedLanguage == FormatStyle::LK_Cpp) {
 auto Extension = llvm::sys::path::extension(FileName);
 // If there's no file extension (or it's .h), we need to check the contents
 // of the code to see if it contains Objective-C.
-if (Extension.empty() || Extension == ".h") {
+if (GuessObjC && (Extension.empty() || Extension == ".h")) {
   auto NonEmptyFileName = FileName.empty() ? "guess.h" : FileName;
   Environment Env(Code, NonEmptyFileName, /*Ranges=*/{});
   ObjCHeaderStyleGuesser Guesser(Env, getLLVMStyle());
@@ -3952,8 +3953,8 @@ loadAndParseConfigFile(StringRef ConfigFile, 
llvm::vfs::FileSystem *FS,
 llvm::Expected getStyle(StringRef StyleName, StringRef FileName,
  StringRef FallbackStyleName,
  StringRef Code, llvm::vfs::FileSystem *FS,
- bool AllowUnknownOptions) {
-  FormatStyle Style = getLLVMStyle(guessLanguage(FileName, Code));
+ bool AllowUnknownOptions, bool GuessObjC) 
{
+  FormatStyle Style = getLLVMStyle(guessLanguage(FileName, Code, GuessObjC));
   FormatStyle FallbackStyle = getNoStyle();
   if (!getPredefinedStyle(FallbackStyleName, Style.Language, ))
 return make_string_error("Invalid fallback style: " + FallbackStyleName);

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


[clang] [clang-format][NFC] Enable RemoveSemicolon for clang-format style (PR #82735)

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

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


[clang] [ClangFormat] Fix indent in child lines within a macro argument. (PR #82523)

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


@@ -420,6 +420,8 @@ struct UnwrappedLineNode {
   SmallVector Children;
 };
 
+std::ostream <<(std::ostream , const UnwrappedLine );
+

owenca wrote:

Ah, thanks for the explanation.

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


[clang] [ClangFormat] Fix indent in child lines within a macro argument. (PR #82523)

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


@@ -90,6 +90,12 @@ class ScopedDeclarationState {
 
 } // end anonymous namespace
 
+std::ostream <<(std::ostream , const UnwrappedLine ) {
+  llvm::raw_os_ostream OS(Stream);
+  printLine(OS, Line);
+  return Stream;
+}
+

owenca wrote:

Delete.

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


[clang] [ClangFormat] Fix indent in child lines within a macro argument. (PR #82523)

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


@@ -287,6 +287,21 @@ TEST_F(FormatTestMacroExpansion,
Style);
 }
 
+TEST_F(FormatTestMacroExpansion, IndentChildrenWithinMacroCall) {
+  FormatStyle Style = getGoogleStyleWithColumns(22);
+  Style.Macros.push_back("MACRO(a, b)=a=(b)");
+  verifyFormat("void f() {\n"
+   "  MACRO(a b, call([] {\n"
+   "  if (expr) {\n"
+   "indent();\n"
+   "  }\n"
+   "}));\n"
+   "}"
+
+   ,

owenca wrote:

```suggestion
   "}",
```

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


[clang] [ClangFormat] Fix indent in child lines within a macro argument. (PR #82523)

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


@@ -19,6 +19,7 @@
 #include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/Support/Debug.h"
+#include 

owenca wrote:

Not needed explicitly.

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


[clang] [ClangFormat] Fix indent in child lines within a macro argument. (PR #82523)

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


@@ -420,6 +420,8 @@ struct UnwrappedLineNode {
   SmallVector Children;
 };
 
+std::ostream <<(std::ostream , const UnwrappedLine );
+

owenca wrote:

Delete.

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


[clang] [clang-format] Limit how much work guessLanguage() can do (PR #78925)

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

owenca wrote:

> > If we add a `bool GuessObjC` parameter to `guessLanguage()`, would that 
> > solve the problem?
> 
> I assume you mean making it so that when clangd calls into `guessLanguage()`, 
> the ObjC guessing algorithm is skipped entirely.

I'm not familiar with clangd use cases, but I thought the `GuessObjC` flag 
would allow clangd to skip the guessing ObjC part for those "users who merely 
use these libraries (and so may open them in the editor to look at the header, 
but will not try to format it)". If it wouldn't work as you pointed out, then 
we probably need a new ObjC guesser that only relies on the lexer, similar to 
what's done in 
[IntegerLiteralSeparatorFixer::process()](https://github.com/llvm/llvm-project/blob/afd469023aad10786eaea3d444047a558ad8d5c1/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp#L45).

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


[clang] [clang-format][NFC] Enable RemoveSemicolon for clang-format style (PR #82735)

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

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

Also insert separators for decimal integers longer than 4 digits.

>From e0a9d61283276bddda8231b599697cf4d497ff0a Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 22 Feb 2024 20:56:47 -0800
Subject: [PATCH] [clang-format][NFC] Enable RemoveSemicolon for clang-format
 style

Also insert separators for decimal integers longer than 4 digits.

Reformat clang-format source with the new options.
---
 clang/lib/Format/Format.cpp | 5 -
 clang/lib/Format/FormatToken.cpp| 2 +-
 clang/lib/Format/UnwrappedLineFormatter.cpp | 4 ++--
 clang/unittests/Format/FormatTest.cpp   | 2 +-
 4 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 10ab406a15c6e1..2f6b52510099a7 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1591,7 +1591,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.PenaltyBreakScopeResolution = 500;
   LLVMStyle.PenaltyBreakString = 1000;
   LLVMStyle.PenaltyBreakTemplateDeclaration = prec::Relational;
-  LLVMStyle.PenaltyExcessCharacter = 100;
+  LLVMStyle.PenaltyExcessCharacter = 1'000'000;
   LLVMStyle.PenaltyIndentedWhitespace = 0;
   LLVMStyle.PenaltyReturnTypeOnItsOwnLine = 60;
 
@@ -1914,9 +1914,12 @@ FormatStyle getClangFormatStyle() {
   FormatStyle Style = getLLVMStyle();
   Style.InsertBraces = true;
   Style.InsertNewlineAtEOF = true;
+  Style.IntegerLiteralSeparator.Decimal = 3;
+  Style.IntegerLiteralSeparator.DecimalMinDigits = 5;
   Style.LineEnding = FormatStyle::LE_LF;
   Style.RemoveBracesLLVM = true;
   Style.RemoveParentheses = FormatStyle::RPS_ReturnStatement;
+  Style.RemoveSemicolon = true;
   return Style;
 }
 
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index b791c5a26bbe3a..56a7b2d6387765 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -137,7 +137,7 @@ unsigned CommaSeparatedList::formatAfterToken(LineState 
,
   // bin-packed. Add a severe penalty to this so that column layouts are
   // preferred if possible.
   if (!Format)
-return 1;
+return 10'000;
 
   // Format the entire list.
   unsigned Penalty = 0;
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index adeb072434873f..fb31980ab9f491 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1221,7 +1221,7 @@ class OptimizingLineFormatter : public LineFormatter {
 // While not empty, take first element and follow edges.
 while (!Queue.empty()) {
   // Quit if we still haven't found a solution by now.
-  if (Count > 2500)
+  if (Count > 25'000'000)
 return 0;
 
   Penalty = Queue.top().first.first;
@@ -1235,7 +1235,7 @@ class OptimizingLineFormatter : public LineFormatter {
 
   // Cut off the analysis of certain solutions if the analysis gets too
   // complex. See description of IgnoreStackForComparison.
-  if (Count > 5)
+  if (Count > 50'000)
 Node->State.IgnoreStackForComparison = true;
 
   if (!Seen.insert(>State).second) {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index b8dc01f55b4faa..d9752c73e34e79 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -21669,7 +21669,7 @@ TEST_F(FormatTest, BreakPenaltyAfterCastLParen) {
"int));",
 
Style);
-  Style.PenaltyBreakOpenParenthesis = 10;
+  Style.PenaltyBreakOpenParenthesis = 100'000;
   verifyFormat("foo((int)\n"
");",
"foo((\n"

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


[clang] [clang-format] Fix crash in TokenAnnotator (PR #82349)

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

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


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


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

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

owenca wrote:

> As a side note, I tried adding these two tests but they fail, meaning the 
> cursor is still incorrectly computed with CRLF when replacing lines.
> 
> This is due to adding lines between the include groups (with Regroup option), 
> as this new line is added with only the character `\n` (while the line break 
> between include lines is right because the include line itself contains a 
> trailing `\r`). I am not sure how to fix this correctly because I do not want 
> to break things by trimming the include line and I do not think 
> `sortCppIncludes` should manage whitespaces (`WhitespaceManager` seems to be 
> the correct class to handle this?). Maybe the cursor should be updated when 
> replacing these whitespaces?
> 
> ```c++
> TEST_F(
>SortIncludesTest,
>
> CalculatesCorrectCursorPositionWhenNewLineReplacementsWithRegroupingAndCRLF) {
>   Style.IncludeBlocks   = Style.IBS_Regroup;
>   FmtStyle.LineEnding   = FormatStyle::LE_CRLF;
>   Style.IncludeCategories = {
>   {"^\"a\"", 0, 0, false}, {"^\"b\"", 1, 1, false}, {".*", 2, 2, false}};
>   std::string Code = "#include \"a\"\r\n" // Start of line: 0
>  "#include \"b\"\r\n" // Start of line: 14
>  "#include \"c\"\r\n" // Start of line: 28
>  "\r\n"   // Start of line: 42
>  "int i;";// Start of line: 44
>   std::string Expected = "#include \"a\"\r\n" // Start of line: 0
>  "\r\n"   // Start of line: 14
>  "#include \"b\"\r\n" // Start of line: 16
>  "\r\n"   // Start of line: 30
>  "#include \"c\"\r\n" // Start of line: 32
>  "\r\n"   // Start of line: 46
>  "int i;";// Start of line: 48
>   EXPECT_EQ(Expected, sort(Code));
>   EXPECT_EQ(0u, newCursor(Code, 0));
>   EXPECT_EQ(15u, newCursor(Code, 14)); // FIXME: should expect 16, caused by 
> \r
>   EXPECT_EQ(30u, newCursor(Code, 28)); // FIXME: should expect 32, caused by 
> \r
>   EXPECT_EQ(44u, newCursor(Code, 42)); // FIXME: should expect 46, caused by 
> \r
>   EXPECT_EQ(46u, newCursor(Code, 44)); // FIXME: should expect 48, caused by 
> \r
> }
> 
> TEST_F(
>SortIncludesTest,
>
> CalculatesCorrectCursorPositionWhenNoNewLineReplacementsWithRegroupingAndCRLF)
>  {
>   Style.IncludeBlocks = Style.IBS_Regroup;
>   FmtStyle.LineEnding = FormatStyle::LE_CRLF;
>   Style.IncludeCategories = {
>   {"^\"a\"", 0, 0, false}, {"^\"b\"", 1, 1, false}, {".*", 2, 2, false}};
>   std::string Code = "#include \"a\"\r\n" // Start of line: 0
>  "\r\n"   // Start of line: 14
>  "#include \"c\"\r\n" // Start of line: 16
>  "\r\n"   // Start of line: 30
>  "#include \"b\"\r\n" // Start of line: 32
>  "\r\n"   // Start of line: 46
>  "int i;";// Start of line: 48
>   std::string Expected = "#include \"a\"\r\n" // Start of line: 0
>  "\r\n"   // Start of line: 14
>  "#include \"b\"\r\n" // Start of line: 16
>  "\r\n"   // Start of line: 30
>  "#include \"c\"\r\n" // Start of line: 32
>  "\r\n"   // Start of line: 46
>  "int i;";// Start of line: 48
>   EXPECT_EQ(Expected, sort(Code));
>   EXPECT_EQ(0u, newCursor(Code, 0));
>   EXPECT_EQ(14u, newCursor(Code, 14));
>   EXPECT_EQ(30u, newCursor(Code, 16)); // FIXME: should expect 32, caused by 
> \r
>   EXPECT_EQ(30u, newCursor(Code, 30));
>   EXPECT_EQ(15u, newCursor(Code, 32)); // FIXME: should expect 15, caused by 
> \r
>   EXPECT_EQ(44u, newCursor(Code, 46)); // FIXME: should expect 46, caused by 
> \r
>   EXPECT_EQ(46u, newCursor(Code, 48)); // FIXME: should expect 48, caused by 
> \r
> }
> ```

With my suggested fix, these tests should also pass.

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


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

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


@@ -3134,20 +3135,24 @@ static void sortCppIncludes(const FormatStyle ,
 }
 result += Includes[Index].Text;
 if (Cursor && CursorIndex == Index)
-  *Cursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
+  NewCursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
 CurrentCategory = Includes[Index].Category;
   }
 
-  if (Cursor && *Cursor >= IncludesEndOffset)
-*Cursor += result.size() - IncludesBlockSize;
-
   // If the #includes are out of order, we generate a single replacement fixing
   // the entire range of blocks. Otherwise, no replacement is generated.
   if (replaceCRLF(result) == replaceCRLF(std::string(Code.substr(
  IncludesBeginOffset, IncludesBlockSize {
 return;
   }
 
+  if (Cursor) {
+if (NewCursor != UINT_MAX)
+  *Cursor = NewCursor;
+else if (*Cursor >= IncludesEndOffset)
+  *Cursor += result.size() - IncludesBlockSize;
+  }
+

owenca wrote:

```suggestion
```

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


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

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

https://github.com/owenca commented:

`git diff Format.cpp` output:
```
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3116,6 +3116,7 @@ static void sortCppIncludes(const FormatStyle ,
 return;
   }
 
+  const auto OldCursor = Cursor ? *Cursor : 0;
   std::string result;
   for (unsigned Index : Indices) {
 if (!result.empty()) {
@@ -3139,6 +3140,8 @@ static void sortCppIncludes(const FormatStyle ,
   // the entire range of blocks. Otherwise, no replacement is generated.
   if (replaceCRLF(result) == replaceCRLF(std::string(Code.substr(
  IncludesBeginOffset, IncludesBlockSize {
+if (Cursor)
+  *Cursor = OldCursor;
 return;
   }
 
```

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


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

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


@@ -3134,20 +3135,24 @@ static void sortCppIncludes(const FormatStyle ,
 }
 result += Includes[Index].Text;
 if (Cursor && CursorIndex == Index)
-  *Cursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
+  NewCursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;

owenca wrote:

```suggestion
  *Cursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
```
i.e. undo the change.

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


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

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


@@ -3134,20 +3135,24 @@ static void sortCppIncludes(const FormatStyle ,
 }
 result += Includes[Index].Text;
 if (Cursor && CursorIndex == Index)
-  *Cursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
+  NewCursor = IncludesBeginOffset + result.size() - CursorToEOLOffset;
 CurrentCategory = Includes[Index].Category;
   }
 
-  if (Cursor && *Cursor >= IncludesEndOffset)
-*Cursor += result.size() - IncludesBlockSize;
-
   // If the #includes are out of order, we generate a single replacement fixing
   // the entire range of blocks. Otherwise, no replacement is generated.
   if (replaceCRLF(result) == replaceCRLF(std::string(Code.substr(
  IncludesBeginOffset, IncludesBlockSize {
 return;

owenca wrote:

```suggestion
if (Cursor)
  *Cursor = OldCursor;
return;
```

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


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

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

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


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

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


@@ -3123,6 +3123,7 @@ static void sortCppIncludes(const FormatStyle ,
   }
 
   std::string result;
+  unsigned NewCursor = UINT_MAX;

owenca wrote:

```suggestion
  const auto OldCursor = Cursor ? *Cursor : 0;
```

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


[clang] [clang-format] Limit how much work guessLanguage() can do (PR #78925)

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

owenca wrote:

> However, for clangd users, a crucial difference between `guessLanguage()` vs. 
> other code in libFormat that uses `UnwrappedLineParser`, is that 
> `guessLanguage()` gets called as soon as a file is opened in the editor, 
> while the other code is only called if the user explicitly tries to format 
> the file.
> 
> For the files affected by this OOM (single-file libraries like 
> [miniaudio](https://github.com/mackron/miniaudio/blob/master/miniaudio.h), 
> [mathlink](https://github.com/clangd/clangd/issues/1384), 
> [minilzo](http://www.oberhumer.com/opensource/lzo/#minilzo), 
> [blis](https://github.com/llvm/llvm-project/issues/60151), where the large 
> number of configuration-related preprocessor branches and the large number of 
> lines in the file conspire to make the combined length of all permutations 
> intractable to work with), the number of users who merely **use** these 
> libraries (and so may open them in the editor to look at the header, but will 
> not try to format it) far exceeds the number of users who actually 
> **develop** these libraries (who would edit and format the header). Thus, by 
> avoiding the problem in `guessLanguage()`, we would resolve the issue for 
> >99% of clangd users that run into it, which would be a significant 
> improvement.

If we add a `bool GuessObjC` parameter to `guessLanguage()`, would that solve 
the problem?

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


[clang] [clang-format] Fix crash in TokenAnnotator (PR #82349)

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


@@ -13503,6 +13503,9 @@ TEST_F(FormatTest, IncorrectCodeUnbalancedBraces) {
   verifyFormat("{");
   verifyFormat("#})");
   verifyNoCrash("(/**/[:!] ?[).");
+  verifyNoCrash("struct X{"
+"  operator iunt("

owenca wrote:

```suggestion
  verifyNoCrash("struct X {\n"
"  operator iunt(\n"
```

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


[clang] [clang-format] Fix crash in TokenAnnotator (PR #82349)

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


@@ -3817,7 +3817,7 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine ) const {
 do {
   Tok = Tok->Next;
 } while (Tok && Tok->isNot(TT_OverloadedOperatorLParen));
-if (!Tok)
+if (!Tok || !Tok->Next)

owenca wrote:

```suggestion
if (!Tok || !Tok->MatchingParen)
```
Otherwise, it would still crash if the unmatched `l_paren` is not the last 
token on the line, e.g.:
```
struct Foo {
  operator foo(bar
};

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


[clang] [clang-format] Fix RemoveSemicolon for empty functions (PR #82278)

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

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


[clang] [clang-format] Limit how much work guessLanguage() can do (PR #78925)

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

owenca wrote:

> > couldn't we just use the .clang-format-ignore file to say... hey don't 
> > bother with this file, we can't do it...
> 
> I think that's a good solution for avoiding the OOM when actually trying to 
> format the file, in combination with this patch for avoiding the OOM in 
> `guessLanguage()`.
> 
> The reason this is such a severe issue for clangd is that clangd calls into 
> `guessLanguage()` whenever a file is opened, thereby triggering the OOM for 
> any downstream user of such a single-header library who happens to open the 
> header in their editor, not just developers of the library itself. Those 
> users have no reason to try to format the library header, so this would solve 
> what's otherwise a puzzling hang for them with no configuration required.

The OOM is not limited to `guessLanguage()`. (See 119a72866f0e for an 
improvement to the performance of `guessLanguage()`.) It occurs even if you 
rename the header files to .cpp files and clang-format the renamed files 
directly. I'm with @mydeveloperday on this and believe a more general solution 
is needed.

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


[clang] 119a728 - [clang-format][NFC] Remove redundant calls to guessIsObjC()

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

Author: Owen Pan
Date: 2024-02-20T00:28:26-08:00
New Revision: 119a72866f0e143127355fe6e03f57c4f8bab1ae

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

LOG: [clang-format][NFC] Remove redundant calls to guessIsObjC()

Running clang-format on the following input
```
int lambdas() {
  return [&] {
  return [&] {
  return [&] {
  return [&] {
  return [&] {
  return [&] {
  return [&] { return 3; } ();
  } (); } (); } (); } (); } (); } (); }
```
will finish instantly if you pass clang-format a .cpp input with this
content, but hang for tens of seconds if you pass the same via stdin
or a .h file.

Adding some debug statements showed that guessIsObjC was getting called
tens of millions of times in a manner that scales very rapidly with the
amount of nesting (if clang-format just takes a few seconds with that
input passed on stdin, try adding a couple more levels of nesting).

This change moves the recursive guessIsObjC call one level of nesting
out of an inner loop whose iterations don't affect the input to the
recursive call. This resolves the performance issue.

Authored-by: davidvc1 and Uran198

Differential Revision: https://reviews.llvm.org/D114837
Differential Revision: https://reviews.llvm.org/D47515

Added: 


Modified: 
clang/lib/Format/Format.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index e67b2101f5821b..2c815128b1a59d 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -2948,9 +2948,9 @@ class ObjCHeaderStyleGuesser : public TokenAnalyzer {
  << getTokenTypeName(FormatTok->getType()) << "\n");
   return true;
 }
-if (guessIsObjC(SourceManager, Line->Children, Keywords))
-  return true;
   }
+  if (guessIsObjC(SourceManager, Line->Children, Keywords))
+return true;
 }
 return false;
   }



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


[clang] [clang-format] Fix AllowShortLambdasOnASingleLine interfering with lambda brace wrapping. (PR #81848)

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

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


[clang] [clang-format] Fix RemoveSemicolon for empty functions (PR #82278)

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

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


[clang] [clang-format] Fix RemoveSemicolon for empty ctors/dtors (PR #82278)

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

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

Fixes #79833.

>From 4bcf6dba8b97096801be550c4a8d1626ed57e475 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 19 Feb 2024 13:11:29 -0800
Subject: [PATCH] [clang-format] Fix RemoveSemicolon for empty ctors/dtors

Fixes #79833.
---
 clang/lib/Format/Format.cpp   | 23 ---
 clang/unittests/Format/FormatTest.cpp | 19 +--
 2 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index e67b2101f5821b..d6ecb3ecad1f9b 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -2261,27 +2261,36 @@ class SemiRemover : public TokenAnalyzer {
   FormatTokenLexer ) override {
 AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
 tooling::Replacements Result;
-removeSemi(AnnotatedLines, Result);
+removeSemi(Annotator, AnnotatedLines, Result);
 return {Result, 0};
   }
 
 private:
-  void removeSemi(SmallVectorImpl ,
+  void removeSemi(TokenAnnotator ,
+  SmallVectorImpl ,
   tooling::Replacements ) {
+auto PrecededByFunctionRBrace = [](const FormatToken ) {
+  const auto *Prev = Tok.Previous;
+  if (!Prev || Prev->isNot(tok::r_brace))
+return false;
+  const auto *LBrace = Prev->MatchingParen;
+  return LBrace && LBrace->is(TT_FunctionLBrace);
+};
 const auto  = Env.getSourceManager();
 const auto End = Lines.end();
 for (auto I = Lines.begin(); I != End; ++I) {
   const auto Line = *I;
-  removeSemi(Line->Children, Result);
+  removeSemi(Annotator, Line->Children, Result);
   if (!Line->Affected)
 continue;
+  Annotator.calculateFormattingInformation(*Line);
   const auto NextLine = I + 1 == End ? nullptr : I[1];
   for (auto Token = Line->First; Token && !Token->Finalized;
Token = Token->Next) {
-if (!Token->Optional)
-  continue;
-if (Token->isNot(tok::semi))
+if (Token->isNot(tok::semi) ||
+(!Token->Optional && !PrecededByFunctionRBrace(*Token))) {
   continue;
+}
 auto Next = Token->Next;
 assert(Next || Token == Line->Last);
 if (!Next && NextLine)
@@ -3677,7 +3686,7 @@ reformat(const FormatStyle , StringRef Code,
   FormatStyle S = Expanded;
   S.RemoveSemicolon = true;
   Passes.emplace_back([&, S = std::move(S)](const Environment ) {
-return SemiRemover(Env, S).process(/*SkipAnnotation=*/true);
+return SemiRemover(Env, S).process();
   });
 }
 
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index d9e369296eed16..b60f1e27e30b0c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26707,13 +26707,20 @@ TEST_F(FormatTest, RemoveSemicolon) {
 
   verifyIncompleteFormat("class C final [[deprecated(l]] {});", Style);
 
-  // These tests are here to show a problem that may not be easily
-  // solved, our implementation to remove semicolons is only as good
-  // as our FunctionLBrace detection and this fails for empty braces
-  // because we can't distringuish this from a bracelist.
-  // We will enable when that is resolved.
-#if 0
   verifyFormat("void main() {}", "void main() {};", Style);
+
+  verifyFormat("struct Foo {\n"
+   "  Foo() {}\n"
+   "  ~Foo() {}\n"
+   "};",
+   "struct Foo {\n"
+   "  Foo() {};\n"
+   "  ~Foo() {};\n"
+   "};",
+   Style);
+
+// We can't (and probably shouldn't) support the following.
+#if 0
   verifyFormat("void foo() {} //\n"
"int bar;",
"void foo() {}; //\n"

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


[clang] [polly] [clang-format] Correctly annotate block braces of empty ctors/dtors (PR #82097)

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

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


[clang] [polly] [clang-format] Correctly annotate block braces of empty ctors/dtors (PR #82097)

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

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

>From f02c1acefe642065cae01ced98b168ce33b98d47 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 16 Feb 2024 23:27:12 -0800
Subject: [PATCH 1/2] [clang-format] Correctly annotate block braces of empty
 ctors/dtors

Also reformat polly.

Fixes #79834.
---
 clang/lib/Format/TokenAnnotator.cpp   | 20 +--
 clang/unittests/Format/TokenAnnotatorTest.cpp | 14 +
 polly/lib/Exchange/JSONExporter.cpp   |  2 +-
 polly/lib/Transform/DeLICM.cpp|  2 +-
 polly/lib/Transform/FlattenSchedule.cpp   |  2 +-
 polly/lib/Transform/ForwardOpTree.cpp |  2 +-
 6 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index ac876bf4442e95..932b520bd68ece 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3754,10 +3754,11 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine ) const {
   for (AnnotatedLine *ChildLine : Line.Children)
 calculateFormattingInformation(*ChildLine);
 
-  Line.First->TotalLength =
-  Line.First->IsMultiline ? Style.ColumnLimit
-  : Line.FirstStartColumn + 
Line.First->ColumnWidth;
-  FormatToken *Current = Line.First->Next;
+  auto *First = Line.First;
+  First->TotalLength = First->IsMultiline
+   ? Style.ColumnLimit
+   : Line.FirstStartColumn + First->ColumnWidth;
+  FormatToken *Current = First->Next;
   bool InFunctionDecl = Line.MightBeFunctionDecl;
   bool AlignArrayOfStructures =
   (Style.AlignArrayOfStructures != FormatStyle::AIAS_None &&
@@ -3779,16 +3780,15 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine ) const {
 if (const bool IsCtorOrDtor = Tok->is(TT_CtorDtorDeclName);
 IsCtorOrDtor ||
 isFunctionDeclarationName(Style.isCpp(), *Tok, Line, ClosingParen)) {
-  if (!IsCtorOrDtor) {
-LineIsFunctionDeclaration = true;
+  if (!IsCtorOrDtor)
 Tok->setFinalizedType(TT_FunctionDeclarationName);
-  }
+  LineIsFunctionDeclaration = true;
   SeenName = true;
   break;
 }
   }
 
-  if (IsCpp && LineIsFunctionDeclaration &&
+  if (IsCpp && (LineIsFunctionDeclaration || First->is(TT_CtorDtorDeclName)) &&
   Line.endsWith(tok::semi, tok::r_brace)) {
 auto *Tok = Line.Last->Previous;
 while (Tok->isNot(tok::r_brace))
@@ -3811,7 +3811,7 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine ) const {
   if (IsCpp) {
 if (!LineIsFunctionDeclaration) {
   // Annotate */&/&& in `operator` function calls as binary operators.
-  for (const auto *Tok = Line.First; Tok; Tok = Tok->Next) {
+  for (const auto *Tok = First; Tok; Tok = Tok->Next) {
 if (Tok->isNot(tok::kw_operator))
   continue;
 do {
@@ -3948,7 +3948,7 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine ) const {
 
   calculateUnbreakableTailLengths(Line);
   unsigned IndentLevel = Line.Level;
-  for (Current = Line.First; Current; Current = Current->Next) {
+  for (Current = First; Current; Current = Current->Next) {
 if (Current->Role)
   Current->Role->precomputeFormattingInfos(Current);
 if (Current->MatchingParen &&
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 3b36e407228195..c736dac8dabf21 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2678,6 +2678,20 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   EXPECT_TOKEN(Tokens[4], tok::l_brace, TT_FunctionLBrace);
   EXPECT_BRACE_KIND(Tokens[4], BK_Block);
   EXPECT_BRACE_KIND(Tokens[6], BK_Block);
+
+  Tokens = annotate("struct Foo {\n"
+"  Foo() {};\n"
+"  ~Foo() {};\n"
+"};");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_CtorDtorDeclName);
+  EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_FunctionLBrace);
+  EXPECT_BRACE_KIND(Tokens[6], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[7], BK_Block);
+  EXPECT_TOKEN(Tokens[10], tok::identifier, TT_CtorDtorDeclName);
+  EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
+  EXPECT_BRACE_KIND(Tokens[13], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[14], BK_Block);
 }
 
 TEST_F(TokenAnnotatorTest, StreamOperator) {
diff --git a/polly/lib/Exchange/JSONExporter.cpp 
b/polly/lib/Exchange/JSONExporter.cpp
index 74d4e6c7993fa3..845e4c78ab5475 100644
--- a/polly/lib/Exchange/JSONExporter.cpp
+++ b/polly/lib/Exchange/JSONExporter.cpp
@@ -842,7 +842,7 @@ class JSONImporterPrinterLegacyPass final : public ScopPass 
{
 public:
   static char ID;
 
-  JSONImporterPrinterLegacyPass() : JSONImporterPrinterLegacyPass(outs()){};
+  JSONImporterPrinterLegacyPass() : 

[clang] [polly] [clang-format] Correctly annotate block braces of empty ctors/dtors (PR #82097)

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

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

Also reformat polly.

Fixes #79834.

>From f02c1acefe642065cae01ced98b168ce33b98d47 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 16 Feb 2024 23:27:12 -0800
Subject: [PATCH] [clang-format] Correctly annotate block braces of empty
 ctors/dtors

Also reformat polly.

Fixes #79834.
---
 clang/lib/Format/TokenAnnotator.cpp   | 20 +--
 clang/unittests/Format/TokenAnnotatorTest.cpp | 14 +
 polly/lib/Exchange/JSONExporter.cpp   |  2 +-
 polly/lib/Transform/DeLICM.cpp|  2 +-
 polly/lib/Transform/FlattenSchedule.cpp   |  2 +-
 polly/lib/Transform/ForwardOpTree.cpp |  2 +-
 6 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index ac876bf4442e95..932b520bd68ece 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3754,10 +3754,11 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine ) const {
   for (AnnotatedLine *ChildLine : Line.Children)
 calculateFormattingInformation(*ChildLine);
 
-  Line.First->TotalLength =
-  Line.First->IsMultiline ? Style.ColumnLimit
-  : Line.FirstStartColumn + 
Line.First->ColumnWidth;
-  FormatToken *Current = Line.First->Next;
+  auto *First = Line.First;
+  First->TotalLength = First->IsMultiline
+   ? Style.ColumnLimit
+   : Line.FirstStartColumn + First->ColumnWidth;
+  FormatToken *Current = First->Next;
   bool InFunctionDecl = Line.MightBeFunctionDecl;
   bool AlignArrayOfStructures =
   (Style.AlignArrayOfStructures != FormatStyle::AIAS_None &&
@@ -3779,16 +3780,15 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine ) const {
 if (const bool IsCtorOrDtor = Tok->is(TT_CtorDtorDeclName);
 IsCtorOrDtor ||
 isFunctionDeclarationName(Style.isCpp(), *Tok, Line, ClosingParen)) {
-  if (!IsCtorOrDtor) {
-LineIsFunctionDeclaration = true;
+  if (!IsCtorOrDtor)
 Tok->setFinalizedType(TT_FunctionDeclarationName);
-  }
+  LineIsFunctionDeclaration = true;
   SeenName = true;
   break;
 }
   }
 
-  if (IsCpp && LineIsFunctionDeclaration &&
+  if (IsCpp && (LineIsFunctionDeclaration || First->is(TT_CtorDtorDeclName)) &&
   Line.endsWith(tok::semi, tok::r_brace)) {
 auto *Tok = Line.Last->Previous;
 while (Tok->isNot(tok::r_brace))
@@ -3811,7 +3811,7 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine ) const {
   if (IsCpp) {
 if (!LineIsFunctionDeclaration) {
   // Annotate */&/&& in `operator` function calls as binary operators.
-  for (const auto *Tok = Line.First; Tok; Tok = Tok->Next) {
+  for (const auto *Tok = First; Tok; Tok = Tok->Next) {
 if (Tok->isNot(tok::kw_operator))
   continue;
 do {
@@ -3948,7 +3948,7 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine ) const {
 
   calculateUnbreakableTailLengths(Line);
   unsigned IndentLevel = Line.Level;
-  for (Current = Line.First; Current; Current = Current->Next) {
+  for (Current = First; Current; Current = Current->Next) {
 if (Current->Role)
   Current->Role->precomputeFormattingInfos(Current);
 if (Current->MatchingParen &&
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 3b36e407228195..c736dac8dabf21 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2678,6 +2678,20 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   EXPECT_TOKEN(Tokens[4], tok::l_brace, TT_FunctionLBrace);
   EXPECT_BRACE_KIND(Tokens[4], BK_Block);
   EXPECT_BRACE_KIND(Tokens[6], BK_Block);
+
+  Tokens = annotate("struct Foo {\n"
+"  Foo() {};\n"
+"  ~Foo() {};\n"
+"};");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_CtorDtorDeclName);
+  EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_FunctionLBrace);
+  EXPECT_BRACE_KIND(Tokens[6], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[7], BK_Block);
+  EXPECT_TOKEN(Tokens[10], tok::identifier, TT_CtorDtorDeclName);
+  EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
+  EXPECT_BRACE_KIND(Tokens[13], BK_Block);
+  EXPECT_BRACE_KIND(Tokens[14], BK_Block);
 }
 
 TEST_F(TokenAnnotatorTest, StreamOperator) {
diff --git a/polly/lib/Exchange/JSONExporter.cpp 
b/polly/lib/Exchange/JSONExporter.cpp
index 74d4e6c7993fa3..845e4c78ab5475 100644
--- a/polly/lib/Exchange/JSONExporter.cpp
+++ b/polly/lib/Exchange/JSONExporter.cpp
@@ -842,7 +842,7 @@ class JSONImporterPrinterLegacyPass final : public ScopPass 
{
 public:
   static char ID;
 
-  JSONImporterPrinterLegacyPass() : JSONImporterPrinterLegacyPass(outs()){};
+  

[clang] [clang-format] Don't sort qualifiers across preprocessor directives (PR #81958)

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

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


[clang] [clang-format] Don't sort qualifiers across preprocessor directives (PR #81958)

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

owenca wrote:

> LGTM, as long as someone doesn't say it should be
> 
> ```c++
> #if FOO
>constexpr
> #endif
>inline
>int i = 0;
> ```
> 
> but I think this change is fine..I would rather we didn't try and support 
> that.. thank you.

Yep! Otherwise, you would have to handle the following, given that the order is 
`[const, inline, constexpr, type]`:
```c++
inline
#if FOO
constexpr /* foo */
#else
const /* bar */
#endif
int i = 0;
```

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


[clang] [clang-format] Fix AllowShortLambdasOnASingleLine interfering with lambda brace wrapping. (PR #81848)

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


@@ -22893,6 +22893,19 @@ TEST_F(FormatTest, FormatsLambdas) {
LLVMWithBeforeLambdaBody);
   verifyFormat("FctWithTwoParams_SLS_All([]() { return 43; }, 87);",
LLVMWithBeforeLambdaBody);
+  verifyFormat(
+  "FctWithTwoParams_SLS_All(\n"
+  "87, []() { return LongLineThatWillForceBothParamsToNewLine(); 
});\n",

owenca wrote:

```suggestion
  "87, []() { return LongLineThatWillForceBothParamsToNewLine(); });",
```

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


[clang] [clang-format] Fix AllowShortLambdasOnASingleLine interfering with lambda brace wrapping. (PR #81848)

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

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


[clang] [clang-format] Fix AllowShortLambdasOnASingleLine interfering with lambda brace wrapping. (PR #81848)

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

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


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


[clang] 92ef408 - [clang-format] Delete a redundant newline at the end of a test case

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

Author: Owen Pan
Date: 2024-02-16T01:47:49-08:00
New Revision: 92ef40874d58d4fca4b7657c31ab2538e1301f26

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

LOG: [clang-format] Delete a redundant newline at the end of a test case

It slipped in from commit fa6025e25b57.

Added: 


Modified: 
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index b0687eaecb10fe..d9e369296eed16 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -5019,7 +5019,7 @@ TEST_F(FormatTest, DesignatedInitializers) {
" .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


[clang] [clang-format] Don't sort qualifiers across preprocessor directives (PR #81958)

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

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

Fixes #80579.

>From 13614f5760a26ba6134abdd555176a1aa2ed3974 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 15 Feb 2024 17:37:44 -0800
Subject: [PATCH] [clang-format] Don't sort qualifiers across preprocessor
 directives

Fixes #80579.
---
 clang/lib/Format/QualifierAlignmentFixer.cpp  |  2 ++
 clang/unittests/Format/QualifierFixerTest.cpp | 13 +
 2 files changed, 15 insertions(+)

diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 84941746f0df71..0c63d330b5aed4 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -561,6 +561,8 @@ void 
LeftRightQualifierAlignmentFixer::fixQualifierAlignment(
 
 for (const auto *Tok = First; Tok && Tok != Last && Tok->Next;
  Tok = Tok->Next) {
+  if (Tok->MustBreakBefore)
+break;
   if (Tok->is(tok::comment))
 continue;
   if (RightAlign) {
diff --git a/clang/unittests/Format/QualifierFixerTest.cpp 
b/clang/unittests/Format/QualifierFixerTest.cpp
index 0aa755acfc8213..43476aea66337b 100644
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -1177,6 +1177,19 @@ TEST_F(QualifierFixerTest, 
DontPushQualifierThroughNonSpecifiedTypes) {
   verifyFormat("const inline static Foo;", Style);
 }
 
+TEST_F(QualifierFixerTest, QualifiersBrokenUpByPPDirectives) {
+  auto Style = getLLVMStyle();
+  Style.QualifierAlignment = FormatStyle::QAS_Custom;
+  Style.QualifierOrder = {"constexpr", "inline", "type"};
+
+  verifyFormat("inline\n"
+   "#if FOO\n"
+   "constexpr\n"
+   "#endif\n"
+   "int i = 0;",
+   Style);
+}
+
 TEST_F(QualifierFixerTest, UnsignedQualifier) {
 
   FormatStyle Style = getLLVMStyle();

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


[clang] 6087d7b - [clang-format][NFC] Sort options in Format.cpp

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

Author: Owen Pan
Date: 2024-02-14T21:40:07-08:00
New Revision: 6087d7bc0a9d7d4ad2c94a131c2bc427b767c9d7

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

LOG: [clang-format][NFC] Sort options in Format.cpp

Added: 


Modified: 
clang/lib/Format/Format.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 56cd9495920c7b..e67b2101f5821b 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1406,29 +1406,28 @@ static void expandPresetsSpacesInParens(FormatStyle 
) {
 
 FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
   FormatStyle LLVMStyle;
-  LLVMStyle.InheritsParentConfig = false;
-  LLVMStyle.Language = Language;
   LLVMStyle.AccessModifierOffset = -2;
-  LLVMStyle.AlignEscapedNewlines = FormatStyle::ENAS_Right;
   LLVMStyle.AlignAfterOpenBracket = FormatStyle::BAS_Align;
   LLVMStyle.AlignArrayOfStructures = FormatStyle::AIAS_None;
-  LLVMStyle.AlignOperands = FormatStyle::OAS_Align;
   LLVMStyle.AlignConsecutiveAssignments = {};
-  LLVMStyle.AlignConsecutiveAssignments.Enabled = false;
-  LLVMStyle.AlignConsecutiveAssignments.AcrossEmptyLines = false;
   LLVMStyle.AlignConsecutiveAssignments.AcrossComments = false;
+  LLVMStyle.AlignConsecutiveAssignments.AcrossEmptyLines = false;
   LLVMStyle.AlignConsecutiveAssignments.AlignCompound = false;
   LLVMStyle.AlignConsecutiveAssignments.AlignFunctionPointers = false;
+  LLVMStyle.AlignConsecutiveAssignments.Enabled = false;
   LLVMStyle.AlignConsecutiveAssignments.PadOperators = true;
   LLVMStyle.AlignConsecutiveBitFields = {};
   LLVMStyle.AlignConsecutiveDeclarations = {};
   LLVMStyle.AlignConsecutiveMacros = {};
   LLVMStyle.AlignConsecutiveShortCaseStatements = {};
+  LLVMStyle.AlignEscapedNewlines = FormatStyle::ENAS_Right;
+  LLVMStyle.AlignOperands = FormatStyle::OAS_Align;
   LLVMStyle.AlignTrailingComments = {};
   LLVMStyle.AlignTrailingComments.Kind = FormatStyle::TCAS_Always;
   LLVMStyle.AlignTrailingComments.OverEmptyLines = 0;
   LLVMStyle.AllowAllArgumentsOnNextLine = true;
   LLVMStyle.AllowAllParametersOfDeclarationOnNextLine = true;
+  LLVMStyle.AllowBreakBeforeNoexceptSpecifier = FormatStyle::BBNSS_Never;
   LLVMStyle.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Never;
   LLVMStyle.AllowShortCaseLabelsOnASingleLine = false;
   LLVMStyle.AllowShortCompoundRequirementOnASingleLine = true;
@@ -1439,11 +1438,10 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.AllowShortLoopsOnASingleLine = false;
   LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
   LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
-  LLVMStyle.BreakTemplateDeclarations = FormatStyle::BTDS_MultiLine;
   LLVMStyle.AttributeMacros.push_back("__capability");
-  LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
   LLVMStyle.BinPackArguments = true;
   LLVMStyle.BinPackParameters = true;
+  LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
   LLVMStyle.BracedInitializerIndentWidth = std::nullopt;
   LLVMStyle.BraceWrapping = {/*AfterCaseLabel=*/false,
  /*AfterClass=*/false,
@@ -1472,11 +1470,11 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach;
   LLVMStyle.BreakBeforeConceptDeclarations = FormatStyle::BBCDS_Always;
   LLVMStyle.BreakBeforeInlineASMColon = FormatStyle::BBIAS_OnlyMultiline;
-  LLVMStyle.AllowBreakBeforeNoexceptSpecifier = FormatStyle::BBNSS_Never;
   LLVMStyle.BreakBeforeTernaryOperators = true;
   LLVMStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
   LLVMStyle.BreakInheritanceList = FormatStyle::BILS_BeforeColon;
   LLVMStyle.BreakStringLiterals = true;
+  LLVMStyle.BreakTemplateDeclarations = FormatStyle::BTDS_MultiLine;
   LLVMStyle.ColumnLimit = 80;
   LLVMStyle.CommentPragmas = "^ IWYU pragma:";
   LLVMStyle.CompactNamespaces = false;
@@ -1493,22 +1491,23 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.ForEachMacros.push_back("Q_FOREACH");
   LLVMStyle.ForEachMacros.push_back("BOOST_FOREACH");
   LLVMStyle.IfMacros.push_back("KJ_IF_MAYBE");
+  LLVMStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
   LLVMStyle.IncludeStyle.IncludeCategories = {
   {"^\"(llvm|llvm-c|clang|clang-c)/", 2, 0, false},
   {"^(<|\"(gtest|gmock|isl|json)/)", 3, 0, false},
   {".*", 1, 0, false}};
   LLVMStyle.IncludeStyle.IncludeIsMainRegex = "(Test)?$";
-  LLVMStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
   LLVMStyle.IncludeStyle.MainIncludeChar = tooling::IncludeStyle::MICD_Quote;
   LLVMStyle.IndentAccessModifiers = false;
-  LLVMStyle.IndentCaseLabels = false;
   

[clang] [clang-format][NFC] Drop "Always" in "AlwaysBreakAfterReturnType". (PR #81591)

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

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


[clang] [clang-format][NFC] Drop "Always" in "AlwaysBreakAfterReturnType". (PR #81591)

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

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


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


[clang] [clang-format][NFC] Drop "Always" in "AlwaysBreakAfterReturnType". (PR #81591)

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


@@ -1130,14 +1129,13 @@ template <> struct MappingTraits {
 // AlwaysBreakAfterReturnType was not, initialize the latter from the
 // former for backwards compatibility.

owenca wrote:

```suggestion
// BreakAfterReturnType was not, initialize the latter from the former for
// backwards compatibility.
```

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


[clang] [clang-format][NFC] Drop "Always" in "AlwaysBreakAfterReturnType". (PR #81591)

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


@@ -1871,10 +1869,10 @@ FormatStyle getWebKitStyle() {
 FormatStyle getGNUStyle() {
   FormatStyle Style = getLLVMStyle();
   Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_All;
-  Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
   Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
   Style.BreakBeforeBraces = FormatStyle::BS_GNU;
   Style.BreakBeforeTernaryOperators = true;
+  Style.BreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;

owenca wrote:

Not sorted.

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


[clang] [clang-format] Always add a space after #if and #elif (PR #81578)

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

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


[clang] 61c83e9 - Revert "[clang-format][NFC] Make LangOpts global in namespace Format"

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

Author: Owen Pan
Date: 2024-02-13T21:02:14-08:00
New Revision: 61c83e9491b2be71a54b255cdb11f65365245953

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

LOG: Revert "[clang-format][NFC] Make LangOpts global in namespace Format"

This reverts commit 32e65b0b8a743678974c7ca7913c1d6c41bb0772.

It seems to break some PowerPC bots.

See https://github.com/llvm/llvm-project/pull/81390#issuecomment-1941964803.

Added: 


Modified: 
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/FormatTokenLexer.h
clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
clang/lib/Format/TokenAnalyzer.cpp
clang/lib/Format/TokenAnalyzer.h

Removed: 




diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index 492e7e96dd22e6..036f7e6a4efc1e 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -13,7 +13,11 @@
 
//===--===//
 
 #include "FormatTokenLexer.h"
-#include "TokenAnalyzer.h"
+#include "FormatToken.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Format/Format.h"
+#include "llvm/Support/Regex.h"
 
 namespace clang {
 namespace format {
@@ -24,12 +28,12 @@ FormatTokenLexer::FormatTokenLexer(
 llvm::SpecificBumpPtrAllocator ,
 IdentifierTable )
 : FormatTok(nullptr), IsFirstToken(true), StateStack({LexerState::NORMAL}),
-  Column(Column), TrailingWhitespace(0), SourceMgr(SourceMgr), ID(ID),
+  Column(Column), TrailingWhitespace(0),
+  LangOpts(getFormattingLangOpts(Style)), SourceMgr(SourceMgr), ID(ID),
   Style(Style), IdentTable(IdentTable), Keywords(IdentTable),
   Encoding(Encoding), Allocator(Allocator), FirstInLineIndex(0),
   FormattingDisabled(false), MacroBlockBeginRegex(Style.MacroBlockBegin),
   MacroBlockEndRegex(Style.MacroBlockEnd) {
-  assert(LangOpts.CPlusPlus);
   Lex.reset(new Lexer(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts));
   Lex->SetKeepWhitespaceMode(true);
 
@@ -1438,7 +1442,7 @@ void FormatTokenLexer::readRawToken(FormatToken ) {
 
 void FormatTokenLexer::resetLexer(unsigned Offset) {
   StringRef Buffer = SourceMgr.getBufferData(ID);
-  assert(LangOpts.CPlusPlus);
+  LangOpts = getFormattingLangOpts(Style);
   Lex.reset(new Lexer(SourceMgr.getLocForStartOfFile(ID), LangOpts,
   Buffer.begin(), Buffer.begin() + Offset, Buffer.end()));
   Lex->SetKeepWhitespaceMode(true);

diff  --git a/clang/lib/Format/FormatTokenLexer.h 
b/clang/lib/Format/FormatTokenLexer.h
index ca91c5b7d20d4e..65dd733bd53352 100644
--- a/clang/lib/Format/FormatTokenLexer.h
+++ b/clang/lib/Format/FormatTokenLexer.h
@@ -17,9 +17,14 @@
 
 #include "Encoding.h"
 #include "FormatToken.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Format/Format.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/StringSet.h"
+#include "llvm/Support/Regex.h"
 
 #include 
 
@@ -115,6 +120,7 @@ class FormatTokenLexer {
   unsigned Column;
   unsigned TrailingWhitespace;
   std::unique_ptr Lex;
+  LangOptions LangOpts;
   const SourceManager 
   FileID ID;
   const FormatStyle 

diff  --git a/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp 
b/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
index 3c2ceddd5599cf..87823ae32b1138 100644
--- a/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ b/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -79,7 +79,7 @@ IntegerLiteralSeparatorFixer::process(const Environment ,
   AffectedRangeManager AffectedRangeMgr(SourceMgr, Env.getCharRanges());
 
   const auto ID = Env.getFileID();
-  assert(LangOpts.CPlusPlus);
+  const auto LangOpts = getFormattingLangOpts(Style);
   Lexer Lex(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts);
   Lex.SetCommentRetentionState(true);
 

diff  --git a/clang/lib/Format/TokenAnalyzer.cpp 
b/clang/lib/Format/TokenAnalyzer.cpp
index f9d1fdb86f1ae9..bd648c430f9b0a 100644
--- a/clang/lib/Format/TokenAnalyzer.cpp
+++ b/clang/lib/Format/TokenAnalyzer.cpp
@@ -35,8 +35,6 @@
 namespace clang {
 namespace format {
 
-LangOptions LangOpts;
-
 // FIXME: Instead of printing the diagnostic we should store it and have a
 // better way to return errors through the format APIs.
 class FatalDiagnosticConsumer : public DiagnosticConsumer {
@@ -101,11 +99,9 @@ TokenAnalyzer::TokenAnalyzer(const Environment , const 
FormatStyle )
 
 std::pair
 TokenAnalyzer::process(bool SkipAnnotation) {
-  LangOpts = getFormattingLangOpts(Style);
-
   tooling::Replacements Result;
   llvm::SpecificBumpPtrAllocator Allocator;
-  IdentifierTable 

[clang] [clang-format] Always add a space after #if and #elif (PR #81578)

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

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


[clang] [clang-format] Always insert a space between #if and l_paren (PR #81578)

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

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

>From 02d2d44046a4cf6ca8c5bb1897b6677c01d81974 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Tue, 13 Feb 2024 00:03:19 -0800
Subject: [PATCH] [clang-format] Always add a space after #if and #elif

Fixes #81569.
---
 clang/lib/Format/TokenAnnotator.cpp   | 2 ++
 clang/unittests/Format/FormatTest.cpp | 4 
 2 files changed, 6 insertions(+)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index b9a000faae7cf7..08a49bc17f13f3 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1856,6 +1856,8 @@ class AnnotatingParser {
 case tok::pp_elif:
   Contexts.back().IsExpression = true;
   next();
+  if (CurrentToken)
+CurrentToken->SpacesRequiredBefore = true;
   parseLine();
   break;
 default:
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 13937a15fdaee2..79cd521b6a9998 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -16491,6 +16491,10 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
   verifyFormat("T A::operator()();", NoSpace);
   verifyFormat("X A::operator++(T);", NoSpace);
   verifyFormat("auto lambda = []() { return 0; };", NoSpace);
+  verifyFormat("#if (foo || bar) && baz\n"
+   "#elif ((a || b) && c) || d\n"
+   "#endif",
+   NoSpace);
 
   FormatStyle Space = getLLVMStyle();
   Space.SpaceBeforeParens = FormatStyle::SBPO_Always;

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


[clang] [clang-format] Always insert a space between #if and l_paren (PR #81578)

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

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

Fixes #81569.

>From 2292ccb78839a90a15215b11c473fcbfc47aa00c Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Tue, 13 Feb 2024 00:03:19 -0800
Subject: [PATCH] [clang-format] Always insert a space between #if and l_paren

Fixes #81569.
---
 clang/lib/Format/TokenAnnotator.cpp   | 2 ++
 clang/unittests/Format/FormatTest.cpp | 4 
 2 files changed, 6 insertions(+)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index b9a000faae7cf7..981147da18ca29 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1856,6 +1856,8 @@ class AnnotatingParser {
 case tok::pp_elif:
   Contexts.back().IsExpression = true;
   next();
+  if (CurrentToken && CurrentToken->is(tok::l_paren))
+CurrentToken->SpacesRequiredBefore = true;
   parseLine();
   break;
 default:
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 13937a15fdaee2..79cd521b6a9998 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -16491,6 +16491,10 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
   verifyFormat("T A::operator()();", NoSpace);
   verifyFormat("X A::operator++(T);", NoSpace);
   verifyFormat("auto lambda = []() { return 0; };", NoSpace);
+  verifyFormat("#if (foo || bar) && baz\n"
+   "#elif ((a || b) && c) || d\n"
+   "#endif",
+   NoSpace);
 
   FormatStyle Space = getLLVMStyle();
   Space.SpaceBeforeParens = FormatStyle::SBPO_Always;

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


[clang] [clang-format] Rename option AlwaysBreakAfterReturnType. (PR #80827)

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

owenca wrote:

Feel free to open another PR if you're interested.  

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


[clang] [clang-format] Rename option AlwaysBreakAfterReturnType. (PR #80827)

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

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


[clang] [clang-format] Rename option AlwaysBreakAfterReturnType. (PR #80827)

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

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

>From 3c3e167711dccfcc0a56c5b465b20c17854451a4 Mon Sep 17 00:00:00 2001
From: rmarker 
Date: Tue, 6 Feb 2024 21:53:20 +1030
Subject: [PATCH 1/2] [clang-format] Rename option AlwaysBreakAfterReturnType.

---
 clang/docs/ClangFormatStyleOptions.rst | 221 +++--
 clang/docs/ReleaseNotes.rst|   2 +
 clang/include/clang/Format/Format.h|   7 +-
 clang/lib/Format/Format.cpp|   5 +-
 clang/unittests/Format/ConfigParseTest.cpp |  17 ++
 5 files changed, 141 insertions(+), 111 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 5deeff0db239a8..fdf7bfaeaa4ec7 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1531,114 +1531,8 @@ the configuration (without a prefix: ``Auto``).
 
 .. _AlwaysBreakAfterReturnType:
 
-**AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``) 
:versionbadge:`clang-format 3.8` :ref:`¶ `
-  The function declaration return type breaking style to use.
-
-  Possible values:
-
-  * ``RTBS_None`` (in configuration: ``None``)
-This is **deprecated**. See ``Automatic`` below.
-
-  * ``RTBS_Automatic`` (in configuration: ``Automatic``)
-Break after return type based on ``PenaltyReturnTypeOnItsOwnLine``.
-
-.. code-block:: c++
-
-  class A {
-int f() { return 0; };
-  };
-  int f();
-  int f() { return 1; }
-  int
-  LongName::AnotherLongName();
-
-  * ``RTBS_ExceptShortType`` (in configuration: ``ExceptShortType``)
-Same as ``Automatic`` above, except that there is no break after short
-return types.
-
-.. code-block:: c++
-
-  class A {
-int f() { return 0; };
-  };
-  int f();
-  int f() { return 1; }
-  int LongName::
-  AnotherLongName();
-
-  * ``RTBS_All`` (in configuration: ``All``)
-Always break after the return type.
-
-.. code-block:: c++
-
-  class A {
-int
-f() {
-  return 0;
-};
-  };
-  int
-  f();
-  int
-  f() {
-return 1;
-  }
-  int
-  LongName::AnotherLongName();
-
-  * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
-Always break after the return types of top-level functions.
-
-.. code-block:: c++
-
-  class A {
-int f() { return 0; };
-  };
-  int
-  f();
-  int
-  f() {
-return 1;
-  }
-  int
-  LongName::AnotherLongName();
-
-  * ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
-Always break after the return type of function definitions.
-
-.. code-block:: c++
-
-  class A {
-int
-f() {
-  return 0;
-};
-  };
-  int f();
-  int
-  f() {
-return 1;
-  }
-  int
-  LongName::AnotherLongName();
-
-  * ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
-Always break after the return type of top-level definitions.
-
-.. code-block:: c++
-
-  class A {
-int f() { return 0; };
-  };
-  int f();
-  int
-  f() {
-return 1;
-  }
-  int
-  LongName::AnotherLongName();
-
-
+**AlwaysBreakAfterReturnType** (``deprecated``) :versionbadge:`clang-format 
3.8` :ref:`¶ `
+  This option is renamed to ``BreakAfterReturnType``.
 
 .. _AlwaysBreakBeforeMultilineStrings:
 
@@ -2219,6 +2113,117 @@ the configuration (without a prefix: ``Auto``).
  @Mock
  DataLoad loader;
 
+.. _BreakAfterReturnType:
+
+**BreakAfterReturnType** (``ReturnTypeBreakingStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  The function declaration return type breaking style to use.
+
+  Possible values:
+
+  * ``RTBS_None`` (in configuration: ``None``)
+This is **deprecated**. See ``Automatic`` below.
+
+  * ``RTBS_Automatic`` (in configuration: ``Automatic``)
+Break after return type based on ``PenaltyReturnTypeOnItsOwnLine``.
+
+.. code-block:: c++
+
+  class A {
+int f() { return 0; };
+  };
+  int f();
+  int f() { return 1; }
+  int
+  LongName::AnotherLongName();
+
+  * ``RTBS_ExceptShortType`` (in configuration: ``ExceptShortType``)
+Same as ``Automatic`` above, except that there is no break after short
+return types.
+
+.. code-block:: c++
+
+  class A {
+int f() { return 0; };
+  };
+  int f();
+  int f() { return 1; }
+  int LongName::
+  AnotherLongName();
+
+  * ``RTBS_All`` (in configuration: ``All``)
+Always break after the return type.
+
+.. code-block:: c++
+
+  class A {
+int
+f() {
+  return 0;
+};
+  };
+  int
+  f();
+  int
+  f() {
+return 1;
+  }
+  int
+  LongName::AnotherLongName();
+
+  * ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
+Always break 

[clang] [clang-format] Don't remove parentheses in macro definitions (PR #81444)

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

owenca wrote:

> Any hope that this lands in 18.1? Thanks anyway!

Most likely.

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


[clang] [clang-format] Don't remove parentheses in macro definitions (PR #81444)

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

owenca wrote:

/cherry-pick 4af24d4ab765

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


[clang] [clang-format] Don't remove parentheses in macro definitions (PR #81444)

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

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


[clang] [clang-format] Don't remove parentheses in macro definitions (PR #81444)

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

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


[clang] [clang-format] Rename option AlwaysBreakAfterReturnType. (PR #80827)

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


@@ -677,6 +677,23 @@ TEST(ConfigParseTest, ParsesConfiguration) {
   "  AfterControlStatement: false",
   BraceWrapping.AfterControlStatement, FormatStyle::BWACS_Never);
 
+  Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_All;
+  CHECK_PARSE("BreakAfterReturnType: None", AlwaysBreakAfterReturnType,
+  FormatStyle::RTBS_None);
+  CHECK_PARSE("BreakAfterReturnType: Automatic", AlwaysBreakAfterReturnType,
+  FormatStyle::RTBS_Automatic);
+  CHECK_PARSE("BreakAfterReturnType: ExceptShortType",
+  AlwaysBreakAfterReturnType, FormatStyle::RTBS_ExceptShortType);
+  CHECK_PARSE("BreakAfterReturnType: All", AlwaysBreakAfterReturnType,
+  FormatStyle::RTBS_All);
+  CHECK_PARSE("BreakAfterReturnType: TopLevel", AlwaysBreakAfterReturnType,
+  FormatStyle::RTBS_TopLevel);
+  CHECK_PARSE("BreakAfterReturnType: AllDefinitions",
+  AlwaysBreakAfterReturnType, FormatStyle::RTBS_AllDefinitions);
+  CHECK_PARSE("BreakAfterReturnType: TopLevelDefinitions",
+  AlwaysBreakAfterReturnType,
+  FormatStyle::RTBS_TopLevelDefinitions);
+  // For backward compatibility:
   Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_All;

owenca wrote:

Redundant.

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


[clang] 7f40c5c - Reland "[clang-format] Update FormatToken::isSimpleTypeSpecifier() (#80241)"

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

Author: Owen Pan
Date: 2024-02-12T00:10:24-08:00
New Revision: 7f40c5cc4e15a0a67b031f13370afc342a5dc14b

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

LOG: Reland "[clang-format] Update FormatToken::isSimpleTypeSpecifier() 
(#80241)"

Added: 


Modified: 
clang/lib/Format/FormatToken.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatToken.cpp 
b/clang/lib/Format/FormatToken.cpp
index b791c5a26bbe3a..33bcde3c25ece9 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -14,9 +14,7 @@
 
 #include "FormatToken.h"
 #include "ContinuationIndenter.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/Debug.h"
-#include 
+#include "TokenAnalyzer.h"
 
 namespace clang {
 namespace format {
@@ -34,41 +32,9 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
-// FIXME: This is copy from Sema. Put it in a common place and remove
-// duplication.
 bool FormatToken::isSimpleTypeSpecifier() const {
-  switch (Tok.getKind()) {
-  case tok::kw_short:
-  case tok::kw_long:
-  case tok::kw___int64:
-  case tok::kw___int128:
-  case tok::kw_signed:
-  case tok::kw_unsigned:
-  case tok::kw_void:
-  case tok::kw_char:
-  case tok::kw_int:
-  case tok::kw_half:
-  case tok::kw_float:
-  case tok::kw_double:
-  case tok::kw___bf16:
-  case tok::kw__Float16:
-  case tok::kw___float128:
-  case tok::kw___ibm128:
-  case tok::kw_wchar_t:
-  case tok::kw_bool:
-#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
-#include "clang/Basic/TransformTypeTraits.def"
-  case tok::annot_typename:
-  case tok::kw_char8_t:
-  case tok::kw_char16_t:
-  case tok::kw_char32_t:
-  case tok::kw_typeof:
-  case tok::kw_decltype:
-  case tok::kw__Atomic:
-return true;
-  default:
-return false;
-  }
+  assert(LangOpts.CPlusPlus);
+  return Tok.isSimpleTypeSpecifier(LangOpts);
 }
 
 bool FormatToken::isTypeOrIdentifier() const {



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


[clang] 33108fa - Reverted due to wrong commit message

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

Author: Owen Pan
Date: 2024-02-12T00:07:47-08:00
New Revision: 33108fae9020cb49577fc3ee0aed219cc581f82a

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

LOG: Reverted due to wrong commit message

This reverts commit f5d71b79fe978f1e70f4a41adfd15f65dec6e210.

Added: 


Modified: 
clang/lib/Format/FormatToken.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatToken.cpp 
b/clang/lib/Format/FormatToken.cpp
index 33bcde3c25ece..b791c5a26bbe3 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -14,7 +14,9 @@
 
 #include "FormatToken.h"
 #include "ContinuationIndenter.h"
-#include "TokenAnalyzer.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/Debug.h"
+#include 
 
 namespace clang {
 namespace format {
@@ -32,9 +34,41 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// FIXME: This is copy from Sema. Put it in a common place and remove
+// duplication.
 bool FormatToken::isSimpleTypeSpecifier() const {
-  assert(LangOpts.CPlusPlus);
-  return Tok.isSimpleTypeSpecifier(LangOpts);
+  switch (Tok.getKind()) {
+  case tok::kw_short:
+  case tok::kw_long:
+  case tok::kw___int64:
+  case tok::kw___int128:
+  case tok::kw_signed:
+  case tok::kw_unsigned:
+  case tok::kw_void:
+  case tok::kw_char:
+  case tok::kw_int:
+  case tok::kw_half:
+  case tok::kw_float:
+  case tok::kw_double:
+  case tok::kw___bf16:
+  case tok::kw__Float16:
+  case tok::kw___float128:
+  case tok::kw___ibm128:
+  case tok::kw_wchar_t:
+  case tok::kw_bool:
+#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
+#include "clang/Basic/TransformTypeTraits.def"
+  case tok::annot_typename:
+  case tok::kw_char8_t:
+  case tok::kw_char16_t:
+  case tok::kw_char32_t:
+  case tok::kw_typeof:
+  case tok::kw_decltype:
+  case tok::kw__Atomic:
+return true;
+  default:
+return false;
+  }
 }
 
 bool FormatToken::isTypeOrIdentifier() const {



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


[clang] f5d71b7 - Reland "[clang-format][NFC] Make LangOpts global in namespace Format (#81390)"

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

Author: Owen Pan
Date: 2024-02-12T00:04:34-08:00
New Revision: f5d71b79fe978f1e70f4a41adfd15f65dec6e210

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

LOG: Reland "[clang-format][NFC] Make LangOpts global in namespace Format 
(#81390)"

Added: 


Modified: 
clang/lib/Format/FormatToken.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatToken.cpp 
b/clang/lib/Format/FormatToken.cpp
index b791c5a26bbe3..33bcde3c25ece 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -14,9 +14,7 @@
 
 #include "FormatToken.h"
 #include "ContinuationIndenter.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/Debug.h"
-#include 
+#include "TokenAnalyzer.h"
 
 namespace clang {
 namespace format {
@@ -34,41 +32,9 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
-// FIXME: This is copy from Sema. Put it in a common place and remove
-// duplication.
 bool FormatToken::isSimpleTypeSpecifier() const {
-  switch (Tok.getKind()) {
-  case tok::kw_short:
-  case tok::kw_long:
-  case tok::kw___int64:
-  case tok::kw___int128:
-  case tok::kw_signed:
-  case tok::kw_unsigned:
-  case tok::kw_void:
-  case tok::kw_char:
-  case tok::kw_int:
-  case tok::kw_half:
-  case tok::kw_float:
-  case tok::kw_double:
-  case tok::kw___bf16:
-  case tok::kw__Float16:
-  case tok::kw___float128:
-  case tok::kw___ibm128:
-  case tok::kw_wchar_t:
-  case tok::kw_bool:
-#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
-#include "clang/Basic/TransformTypeTraits.def"
-  case tok::annot_typename:
-  case tok::kw_char8_t:
-  case tok::kw_char16_t:
-  case tok::kw_char32_t:
-  case tok::kw_typeof:
-  case tok::kw_decltype:
-  case tok::kw__Atomic:
-return true;
-  default:
-return false;
-  }
+  assert(LangOpts.CPlusPlus);
+  return Tok.isSimpleTypeSpecifier(LangOpts);
 }
 
 bool FormatToken::isTypeOrIdentifier() const {



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


[clang] [clang-format] Don't remove parentheses in macro definitions (PR #81444)

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

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

Closes #81399.

>From 9d91878e9cb65ab67de8251976ee748ed03fc2b6 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 11 Feb 2024 23:28:25 -0800
Subject: [PATCH] [clang-format] Don't remove parentheses in macro definitions

Closes #81399.
---
 clang/lib/Format/UnwrappedLineParser.cpp | 2 +-
 clang/unittests/Format/FormatTest.cpp| 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index d4f9b3f9df524e..e660a1dfff968e 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2515,7 +2515,7 @@ bool UnwrappedLineParser::parseParens(TokenType 
AmpAmpTokenType) {
 parseChildBlock();
   break;
 case tok::r_paren:
-  if (!MightBeStmtExpr &&
+  if (!MightBeStmtExpr && !Line->InMacroBody &&
   Style.RemoveParentheses > FormatStyle::RPS_Leave) {
 const auto *Prev = LeftParen->Previous;
 const auto *Next = Tokens->peekNextToken();
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 7b65c8d6e21b00..13937a15fdaee2 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26972,6 +26972,7 @@ TEST_F(FormatTest, RemoveParentheses) {
   EXPECT_EQ(Style.RemoveParentheses, FormatStyle::RPS_Leave);
 
   Style.RemoveParentheses = FormatStyle::RPS_MultipleParentheses;
+  verifyFormat("#define Foo(...) foo((__VA_ARGS__))", Style);
   verifyFormat("int x __attribute__((aligned(16))) = 0;", Style);
   verifyFormat("decltype((foo->bar)) baz;", Style);
   verifyFormat("class __declspec(dllimport) X {};",
@@ -27006,6 +27007,7 @@ TEST_F(FormatTest, RemoveParentheses) {
   verifyFormat("return (({ 0; }));", "return ((({ 0; })));", Style);
 
   Style.RemoveParentheses = FormatStyle::RPS_ReturnStatement;
+  verifyFormat("#define Return0 return (0);", Style);
   verifyFormat("return 0;", "return (0);", Style);
   verifyFormat("co_return 0;", "co_return ((0));", Style);
   verifyFormat("return 0;", "return (((0)));", Style);

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


[clang] 0091893 - [clang-format] Undo the change to TestLexer() in commit 32e65b0b8a74

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

Author: Owen Pan
Date: 2024-02-11T22:51:18-08:00
New Revision: 00918933fc4e181fe3c74006d81d7a598c2227b3

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

LOG: [clang-format] Undo the change to TestLexer() in commit 32e65b0b8a74

We can't skip calling getFormattingLangOpts() because LangOpts is not
initialized in the unit tests.

Added: 


Modified: 
clang/unittests/Format/TestLexer.h

Removed: 




diff  --git a/clang/unittests/Format/TestLexer.h 
b/clang/unittests/Format/TestLexer.h
index 6a3d0bdedcee0a..8b5949b32fc9ed 100644
--- a/clang/unittests/Format/TestLexer.h
+++ b/clang/unittests/Format/TestLexer.h
@@ -61,9 +61,7 @@ class TestLexer : public UnwrappedLineConsumer {
 std::vector> ,
 FormatStyle Style = getLLVMStyle())
   : Allocator(Allocator), Buffers(Buffers), Style(Style),
-SourceMgr("test.cpp", ""), IdentTable(LangOpts) {
-assert(LangOpts.CPlusPlus);
-  }
+SourceMgr("test.cpp", ""), IdentTable(getFormattingLangOpts(Style)) {}
 
   TokenList lex(llvm::StringRef Code) {
 FormatTokenLexer Lex = getNewLexer(Code);



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


[clang] 32e65b0 - Reland "[clang-format][NFC] Make LangOpts global in namespace Format (#81390)"

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

Author: Owen Pan
Date: 2024-02-11T22:01:23-08:00
New Revision: 32e65b0b8a743678974c7ca7913c1d6c41bb0772

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

LOG: Reland "[clang-format][NFC] Make LangOpts global in namespace Format 
(#81390)"

Restore getFormattingLangOpts().

Added: 


Modified: 
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/FormatTokenLexer.h
clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
clang/lib/Format/TokenAnalyzer.cpp
clang/lib/Format/TokenAnalyzer.h
clang/unittests/Format/TestLexer.h

Removed: 




diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index a87d0ba3dbbf9b..a57659fd422720 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -13,11 +13,7 @@
 
//===--===//
 
 #include "FormatTokenLexer.h"
-#include "FormatToken.h"
-#include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/SourceManager.h"
-#include "clang/Format/Format.h"
-#include "llvm/Support/Regex.h"
+#include "TokenAnalyzer.h"
 
 namespace clang {
 namespace format {
@@ -28,12 +24,12 @@ FormatTokenLexer::FormatTokenLexer(
 llvm::SpecificBumpPtrAllocator ,
 IdentifierTable )
 : FormatTok(nullptr), IsFirstToken(true), StateStack({LexerState::NORMAL}),
-  Column(Column), TrailingWhitespace(0),
-  LangOpts(getFormattingLangOpts(Style)), SourceMgr(SourceMgr), ID(ID),
+  Column(Column), TrailingWhitespace(0), SourceMgr(SourceMgr), ID(ID),
   Style(Style), IdentTable(IdentTable), Keywords(IdentTable),
   Encoding(Encoding), Allocator(Allocator), FirstInLineIndex(0),
   FormattingDisabled(false), MacroBlockBeginRegex(Style.MacroBlockBegin),
   MacroBlockEndRegex(Style.MacroBlockEnd) {
+  assert(LangOpts.CPlusPlus);
   Lex.reset(new Lexer(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts));
   Lex->SetKeepWhitespaceMode(true);
 
@@ -1442,7 +1438,7 @@ void FormatTokenLexer::readRawToken(FormatToken ) {
 
 void FormatTokenLexer::resetLexer(unsigned Offset) {
   StringRef Buffer = SourceMgr.getBufferData(ID);
-  LangOpts = getFormattingLangOpts(Style);
+  assert(LangOpts.CPlusPlus);
   Lex.reset(new Lexer(SourceMgr.getLocForStartOfFile(ID), LangOpts,
   Buffer.begin(), Buffer.begin() + Offset, Buffer.end()));
   Lex->SetKeepWhitespaceMode(true);

diff  --git a/clang/lib/Format/FormatTokenLexer.h 
b/clang/lib/Format/FormatTokenLexer.h
index 65dd733bd53352..ca91c5b7d20d4e 100644
--- a/clang/lib/Format/FormatTokenLexer.h
+++ b/clang/lib/Format/FormatTokenLexer.h
@@ -17,14 +17,9 @@
 
 #include "Encoding.h"
 #include "FormatToken.h"
-#include "clang/Basic/LangOptions.h"
-#include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/SourceManager.h"
-#include "clang/Format/Format.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/StringSet.h"
-#include "llvm/Support/Regex.h"
 
 #include 
 
@@ -120,7 +115,6 @@ class FormatTokenLexer {
   unsigned Column;
   unsigned TrailingWhitespace;
   std::unique_ptr Lex;
-  LangOptions LangOpts;
   const SourceManager 
   FileID ID;
   const FormatStyle 

diff  --git a/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp 
b/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
index 87823ae32b1138..3c2ceddd5599cf 100644
--- a/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ b/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -79,7 +79,7 @@ IntegerLiteralSeparatorFixer::process(const Environment ,
   AffectedRangeManager AffectedRangeMgr(SourceMgr, Env.getCharRanges());
 
   const auto ID = Env.getFileID();
-  const auto LangOpts = getFormattingLangOpts(Style);
+  assert(LangOpts.CPlusPlus);
   Lexer Lex(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts);
   Lex.SetCommentRetentionState(true);
 

diff  --git a/clang/lib/Format/TokenAnalyzer.cpp 
b/clang/lib/Format/TokenAnalyzer.cpp
index bd648c430f9b0a..f9d1fdb86f1ae9 100644
--- a/clang/lib/Format/TokenAnalyzer.cpp
+++ b/clang/lib/Format/TokenAnalyzer.cpp
@@ -35,6 +35,8 @@
 namespace clang {
 namespace format {
 
+LangOptions LangOpts;
+
 // FIXME: Instead of printing the diagnostic we should store it and have a
 // better way to return errors through the format APIs.
 class FatalDiagnosticConsumer : public DiagnosticConsumer {
@@ -99,9 +101,11 @@ TokenAnalyzer::TokenAnalyzer(const Environment , const 
FormatStyle )
 
 std::pair
 TokenAnalyzer::process(bool SkipAnnotation) {
+  LangOpts = getFormattingLangOpts(Style);
+
   tooling::Replacements Result;
   llvm::SpecificBumpPtrAllocator Allocator;
-  IdentifierTable IdentTable(getFormattingLangOpts(Style));
+  IdentifierTable IdentTable(LangOpts);
   FormatTokenLexer 

[clang] 3dc8ef6 - Revert "[clang-format][NFC] Make LangOpts global in namespace Format (#81390)"

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

Author: Owen Pan
Date: 2024-02-11T13:08:28-08:00
New Revision: 3dc8ef677d7d05116a0bf6524eb38b02ca6ba042

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

LOG: Revert "[clang-format][NFC] Make LangOpts global in namespace Format 
(#81390)"

This reverts commit 03f571995b4f0c260254955afd16ec44d0764794.

We can't hide getFormattingLangOpts() as it's used by other tools.

Added: 


Modified: 
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/FormatTokenLexer.h
clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
clang/lib/Format/TokenAnalyzer.cpp
clang/lib/Format/TokenAnalyzer.h
clang/unittests/Format/TestLexer.h

Removed: 




diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index b7e82464d691be..d9c18e5ec1dc30 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -14,6 +14,7 @@
 #ifndef LLVM_CLANG_FORMAT_FORMAT_H
 #define LLVM_CLANG_FORMAT_FORMAT_H
 
+#include "clang/Basic/LangOptions.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "clang/Tooling/Inclusions/IncludeStyle.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -5178,6 +5179,11 @@ tooling::Replacements sortUsingDeclarations(const 
FormatStyle ,
 ArrayRef Ranges,
 StringRef FileName = "");
 
+/// Returns the ``LangOpts`` that the formatter expects you to set.
+///
+/// \param Style determines specific settings for lexing mode.
+LangOptions getFormattingLangOpts(const FormatStyle  = getLLVMStyle());
+
 /// Description to be used for help text for a ``llvm::cl`` option for
 /// specifying format style. The description is closely related to the 
operation
 /// of ``getStyle()``.

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 8431d3cfb14432..d2cc466744acbd 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3823,6 +3823,36 @@ tooling::Replacements sortUsingDeclarations(const 
FormatStyle ,
   return UsingDeclarationsSorter(*Env, Style).process().first;
 }
 
+LangOptions getFormattingLangOpts(const FormatStyle ) {
+  LangOptions LangOpts;
+
+  FormatStyle::LanguageStandard LexingStd = Style.Standard;
+  if (LexingStd == FormatStyle::LS_Auto)
+LexingStd = FormatStyle::LS_Latest;
+  if (LexingStd == FormatStyle::LS_Latest)
+LexingStd = FormatStyle::LS_Cpp20;
+  LangOpts.CPlusPlus = 1;
+  LangOpts.CPlusPlus11 = LexingStd >= FormatStyle::LS_Cpp11;
+  LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp14;
+  LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp17;
+  LangOpts.CPlusPlus20 = LexingStd >= FormatStyle::LS_Cpp20;
+  LangOpts.Char8 = LexingStd >= FormatStyle::LS_Cpp20;
+  // Turning on digraphs in standards before C++0x is error-prone, because e.g.
+  // the sequence "<::" will be unconditionally treated as "[:".
+  // Cf. Lexer::LexTokenInternal.
+  LangOpts.Digraphs = LexingStd >= FormatStyle::LS_Cpp11;
+
+  LangOpts.LineComment = 1;
+  bool AlternativeOperators = Style.isCpp();
+  LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;
+  LangOpts.Bool = 1;
+  LangOpts.ObjC = 1;
+  LangOpts.MicrosoftExt = 1;// To get kw___try, kw___finally.
+  LangOpts.DeclSpecKeyword = 1; // To get __declspec.
+  LangOpts.C99 = 1; // To get kw_restrict for non-underscore-prefixed restrict.
+  return LangOpts;
+}
+
 const char *StyleOptionHelpDescription =
 "Set coding style.  can be:\n"
 "1. A preset: LLVM, GNU, Google, Chromium, Microsoft,\n"

diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index a57659fd422720..a87d0ba3dbbf9b 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -13,7 +13,11 @@
 
//===--===//
 
 #include "FormatTokenLexer.h"
-#include "TokenAnalyzer.h"
+#include "FormatToken.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Format/Format.h"
+#include "llvm/Support/Regex.h"
 
 namespace clang {
 namespace format {
@@ -24,12 +28,12 @@ FormatTokenLexer::FormatTokenLexer(
 llvm::SpecificBumpPtrAllocator ,
 IdentifierTable )
 : FormatTok(nullptr), IsFirstToken(true), StateStack({LexerState::NORMAL}),
-  Column(Column), TrailingWhitespace(0), SourceMgr(SourceMgr), ID(ID),
+  Column(Column), TrailingWhitespace(0),
+  LangOpts(getFormattingLangOpts(Style)), SourceMgr(SourceMgr), ID(ID),
   Style(Style), IdentTable(IdentTable), Keywords(IdentTable),
   Encoding(Encoding), Allocator(Allocator), FirstInLineIndex(0),
   FormattingDisabled(false), 

[clang] [clang-format][NFC] Make LangOpts global in namespace Format (PR #81390)

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

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


[clang] 5aec939 - [clang-format][NFC] Keep Operator== sorted in Format.h

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

Author: Owen Pan
Date: 2024-02-11T02:15:57-08:00
New Revision: 5aec9392674572fa5a06283173a6a739742d261d

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

LOG: [clang-format][NFC] Keep Operator== sorted in Format.h

Added: 


Modified: 
clang/include/clang/Format/Format.h

Removed: 




diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index ab56cc8b6f9135..d9c18e5ec1dc30 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4822,7 +4822,6 @@ struct FormatStyle {
AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType &&
AlwaysBreakBeforeMultilineStrings ==
R.AlwaysBreakBeforeMultilineStrings &&
-   BreakTemplateDeclarations == R.BreakTemplateDeclarations &&
AttributeMacros == R.AttributeMacros &&
BinPackArguments == R.BinPackArguments &&
BinPackParameters == R.BinPackParameters &&
@@ -4840,6 +4839,7 @@ struct FormatStyle {
BreakConstructorInitializers == R.BreakConstructorInitializers &&
BreakInheritanceList == R.BreakInheritanceList &&
BreakStringLiterals == R.BreakStringLiterals &&
+   BreakTemplateDeclarations == R.BreakTemplateDeclarations &&
ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas 
&&
CompactNamespaces == R.CompactNamespaces &&
ConstructorInitializerIndentWidth ==



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


[clang] [clang-format][NFC] Make LangOpts global in namespace Format (PR #81390)

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

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

>From 37a6723b2c9b95c0556ca53992192795e74c27ce Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 10 Feb 2024 17:14:19 -0800
Subject: [PATCH 1/3] [clang-format][NFC] Make LangOpts global in namespace
 Format

---
 clang/include/clang/Format/Format.h   |  6 +---
 clang/lib/Format/Format.cpp   | 30 
 clang/lib/Format/FormatTokenLexer.cpp |  6 ++--
 clang/lib/Format/FormatTokenLexer.h   |  2 --
 .../Format/IntegerLiteralSeparatorFixer.cpp   |  2 +-
 clang/lib/Format/TokenAnalyzer.cpp| 36 ++-
 clang/unittests/Format/TestLexer.h|  4 ++-
 7 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index ab56cc8b6f9135..bede7e88cdbc7a 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -14,7 +14,6 @@
 #ifndef LLVM_CLANG_FORMAT_FORMAT_H
 #define LLVM_CLANG_FORMAT_FORMAT_H
 
-#include "clang/Basic/LangOptions.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "clang/Tooling/Inclusions/IncludeStyle.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -5179,10 +5178,7 @@ tooling::Replacements sortUsingDeclarations(const 
FormatStyle ,
 ArrayRef Ranges,
 StringRef FileName = "");
 
-/// Returns the ``LangOpts`` that the formatter expects you to set.
-///
-/// \param Style determines specific settings for lexing mode.
-LangOptions getFormattingLangOpts(const FormatStyle  = getLLVMStyle());
+extern LangOptions LangOpts;
 
 /// Description to be used for help text for a ``llvm::cl`` option for
 /// specifying format style. The description is closely related to the 
operation
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index d2cc466744acbd..8431d3cfb14432 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3823,36 +3823,6 @@ tooling::Replacements sortUsingDeclarations(const 
FormatStyle ,
   return UsingDeclarationsSorter(*Env, Style).process().first;
 }
 
-LangOptions getFormattingLangOpts(const FormatStyle ) {
-  LangOptions LangOpts;
-
-  FormatStyle::LanguageStandard LexingStd = Style.Standard;
-  if (LexingStd == FormatStyle::LS_Auto)
-LexingStd = FormatStyle::LS_Latest;
-  if (LexingStd == FormatStyle::LS_Latest)
-LexingStd = FormatStyle::LS_Cpp20;
-  LangOpts.CPlusPlus = 1;
-  LangOpts.CPlusPlus11 = LexingStd >= FormatStyle::LS_Cpp11;
-  LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp14;
-  LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp17;
-  LangOpts.CPlusPlus20 = LexingStd >= FormatStyle::LS_Cpp20;
-  LangOpts.Char8 = LexingStd >= FormatStyle::LS_Cpp20;
-  // Turning on digraphs in standards before C++0x is error-prone, because e.g.
-  // the sequence "<::" will be unconditionally treated as "[:".
-  // Cf. Lexer::LexTokenInternal.
-  LangOpts.Digraphs = LexingStd >= FormatStyle::LS_Cpp11;
-
-  LangOpts.LineComment = 1;
-  bool AlternativeOperators = Style.isCpp();
-  LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;
-  LangOpts.Bool = 1;
-  LangOpts.ObjC = 1;
-  LangOpts.MicrosoftExt = 1;// To get kw___try, kw___finally.
-  LangOpts.DeclSpecKeyword = 1; // To get __declspec.
-  LangOpts.C99 = 1; // To get kw_restrict for non-underscore-prefixed restrict.
-  return LangOpts;
-}
-
 const char *StyleOptionHelpDescription =
 "Set coding style.  can be:\n"
 "1. A preset: LLVM, GNU, Google, Chromium, Microsoft,\n"
diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index a87d0ba3dbbf9b..e517e413ec91fb 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -28,12 +28,12 @@ FormatTokenLexer::FormatTokenLexer(
 llvm::SpecificBumpPtrAllocator ,
 IdentifierTable )
 : FormatTok(nullptr), IsFirstToken(true), StateStack({LexerState::NORMAL}),
-  Column(Column), TrailingWhitespace(0),
-  LangOpts(getFormattingLangOpts(Style)), SourceMgr(SourceMgr), ID(ID),
+  Column(Column), TrailingWhitespace(0), SourceMgr(SourceMgr), ID(ID),
   Style(Style), IdentTable(IdentTable), Keywords(IdentTable),
   Encoding(Encoding), Allocator(Allocator), FirstInLineIndex(0),
   FormattingDisabled(false), MacroBlockBeginRegex(Style.MacroBlockBegin),
   MacroBlockEndRegex(Style.MacroBlockEnd) {
+  assert(LangOpts.CPlusPlus);
   Lex.reset(new Lexer(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts));
   Lex->SetKeepWhitespaceMode(true);
 
@@ -1442,7 +1442,7 @@ void FormatTokenLexer::readRawToken(FormatToken ) {
 
 void FormatTokenLexer::resetLexer(unsigned Offset) {
   StringRef Buffer = SourceMgr.getBufferData(ID);
-  LangOpts = getFormattingLangOpts(Style);
+  assert(LangOpts.CPlusPlus);
   Lex.reset(new Lexer(SourceMgr.getLocForStartOfFile(ID), 

[clang] [clang-format][NFC] Make LangOpts global in namespace Format (PR #81390)

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

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

>From 37a6723b2c9b95c0556ca53992192795e74c27ce Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 10 Feb 2024 17:14:19 -0800
Subject: [PATCH 1/2] [clang-format][NFC] Make LangOpts global in namespace
 Format

---
 clang/include/clang/Format/Format.h   |  6 +---
 clang/lib/Format/Format.cpp   | 30 
 clang/lib/Format/FormatTokenLexer.cpp |  6 ++--
 clang/lib/Format/FormatTokenLexer.h   |  2 --
 .../Format/IntegerLiteralSeparatorFixer.cpp   |  2 +-
 clang/lib/Format/TokenAnalyzer.cpp| 36 ++-
 clang/unittests/Format/TestLexer.h|  4 ++-
 7 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index ab56cc8b6f9135..bede7e88cdbc7a 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -14,7 +14,6 @@
 #ifndef LLVM_CLANG_FORMAT_FORMAT_H
 #define LLVM_CLANG_FORMAT_FORMAT_H
 
-#include "clang/Basic/LangOptions.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "clang/Tooling/Inclusions/IncludeStyle.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -5179,10 +5178,7 @@ tooling::Replacements sortUsingDeclarations(const 
FormatStyle ,
 ArrayRef Ranges,
 StringRef FileName = "");
 
-/// Returns the ``LangOpts`` that the formatter expects you to set.
-///
-/// \param Style determines specific settings for lexing mode.
-LangOptions getFormattingLangOpts(const FormatStyle  = getLLVMStyle());
+extern LangOptions LangOpts;
 
 /// Description to be used for help text for a ``llvm::cl`` option for
 /// specifying format style. The description is closely related to the 
operation
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index d2cc466744acbd..8431d3cfb14432 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3823,36 +3823,6 @@ tooling::Replacements sortUsingDeclarations(const 
FormatStyle ,
   return UsingDeclarationsSorter(*Env, Style).process().first;
 }
 
-LangOptions getFormattingLangOpts(const FormatStyle ) {
-  LangOptions LangOpts;
-
-  FormatStyle::LanguageStandard LexingStd = Style.Standard;
-  if (LexingStd == FormatStyle::LS_Auto)
-LexingStd = FormatStyle::LS_Latest;
-  if (LexingStd == FormatStyle::LS_Latest)
-LexingStd = FormatStyle::LS_Cpp20;
-  LangOpts.CPlusPlus = 1;
-  LangOpts.CPlusPlus11 = LexingStd >= FormatStyle::LS_Cpp11;
-  LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp14;
-  LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp17;
-  LangOpts.CPlusPlus20 = LexingStd >= FormatStyle::LS_Cpp20;
-  LangOpts.Char8 = LexingStd >= FormatStyle::LS_Cpp20;
-  // Turning on digraphs in standards before C++0x is error-prone, because e.g.
-  // the sequence "<::" will be unconditionally treated as "[:".
-  // Cf. Lexer::LexTokenInternal.
-  LangOpts.Digraphs = LexingStd >= FormatStyle::LS_Cpp11;
-
-  LangOpts.LineComment = 1;
-  bool AlternativeOperators = Style.isCpp();
-  LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;
-  LangOpts.Bool = 1;
-  LangOpts.ObjC = 1;
-  LangOpts.MicrosoftExt = 1;// To get kw___try, kw___finally.
-  LangOpts.DeclSpecKeyword = 1; // To get __declspec.
-  LangOpts.C99 = 1; // To get kw_restrict for non-underscore-prefixed restrict.
-  return LangOpts;
-}
-
 const char *StyleOptionHelpDescription =
 "Set coding style.  can be:\n"
 "1. A preset: LLVM, GNU, Google, Chromium, Microsoft,\n"
diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index a87d0ba3dbbf9b..e517e413ec91fb 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -28,12 +28,12 @@ FormatTokenLexer::FormatTokenLexer(
 llvm::SpecificBumpPtrAllocator ,
 IdentifierTable )
 : FormatTok(nullptr), IsFirstToken(true), StateStack({LexerState::NORMAL}),
-  Column(Column), TrailingWhitespace(0),
-  LangOpts(getFormattingLangOpts(Style)), SourceMgr(SourceMgr), ID(ID),
+  Column(Column), TrailingWhitespace(0), SourceMgr(SourceMgr), ID(ID),
   Style(Style), IdentTable(IdentTable), Keywords(IdentTable),
   Encoding(Encoding), Allocator(Allocator), FirstInLineIndex(0),
   FormattingDisabled(false), MacroBlockBeginRegex(Style.MacroBlockBegin),
   MacroBlockEndRegex(Style.MacroBlockEnd) {
+  assert(LangOpts.CPlusPlus);
   Lex.reset(new Lexer(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts));
   Lex->SetKeepWhitespaceMode(true);
 
@@ -1442,7 +1442,7 @@ void FormatTokenLexer::readRawToken(FormatToken ) {
 
 void FormatTokenLexer::resetLexer(unsigned Offset) {
   StringRef Buffer = SourceMgr.getBufferData(ID);
-  LangOpts = getFormattingLangOpts(Style);
+  assert(LangOpts.CPlusPlus);
   Lex.reset(new Lexer(SourceMgr.getLocForStartOfFile(ID), 

[clang] [clang-format][NFC] Make LangOpts global in namespace Format (PR #81390)

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

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

None

>From 37a6723b2c9b95c0556ca53992192795e74c27ce Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 10 Feb 2024 17:14:19 -0800
Subject: [PATCH] [clang-format][NFC] Make LangOpts global in namespace Format

---
 clang/include/clang/Format/Format.h   |  6 +---
 clang/lib/Format/Format.cpp   | 30 
 clang/lib/Format/FormatTokenLexer.cpp |  6 ++--
 clang/lib/Format/FormatTokenLexer.h   |  2 --
 .../Format/IntegerLiteralSeparatorFixer.cpp   |  2 +-
 clang/lib/Format/TokenAnalyzer.cpp| 36 ++-
 clang/unittests/Format/TestLexer.h|  4 ++-
 7 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index ab56cc8b6f9135..bede7e88cdbc7a 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -14,7 +14,6 @@
 #ifndef LLVM_CLANG_FORMAT_FORMAT_H
 #define LLVM_CLANG_FORMAT_FORMAT_H
 
-#include "clang/Basic/LangOptions.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "clang/Tooling/Inclusions/IncludeStyle.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -5179,10 +5178,7 @@ tooling::Replacements sortUsingDeclarations(const 
FormatStyle ,
 ArrayRef Ranges,
 StringRef FileName = "");
 
-/// Returns the ``LangOpts`` that the formatter expects you to set.
-///
-/// \param Style determines specific settings for lexing mode.
-LangOptions getFormattingLangOpts(const FormatStyle  = getLLVMStyle());
+extern LangOptions LangOpts;
 
 /// Description to be used for help text for a ``llvm::cl`` option for
 /// specifying format style. The description is closely related to the 
operation
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index d2cc466744acbd..8431d3cfb14432 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3823,36 +3823,6 @@ tooling::Replacements sortUsingDeclarations(const 
FormatStyle ,
   return UsingDeclarationsSorter(*Env, Style).process().first;
 }
 
-LangOptions getFormattingLangOpts(const FormatStyle ) {
-  LangOptions LangOpts;
-
-  FormatStyle::LanguageStandard LexingStd = Style.Standard;
-  if (LexingStd == FormatStyle::LS_Auto)
-LexingStd = FormatStyle::LS_Latest;
-  if (LexingStd == FormatStyle::LS_Latest)
-LexingStd = FormatStyle::LS_Cpp20;
-  LangOpts.CPlusPlus = 1;
-  LangOpts.CPlusPlus11 = LexingStd >= FormatStyle::LS_Cpp11;
-  LangOpts.CPlusPlus14 = LexingStd >= FormatStyle::LS_Cpp14;
-  LangOpts.CPlusPlus17 = LexingStd >= FormatStyle::LS_Cpp17;
-  LangOpts.CPlusPlus20 = LexingStd >= FormatStyle::LS_Cpp20;
-  LangOpts.Char8 = LexingStd >= FormatStyle::LS_Cpp20;
-  // Turning on digraphs in standards before C++0x is error-prone, because e.g.
-  // the sequence "<::" will be unconditionally treated as "[:".
-  // Cf. Lexer::LexTokenInternal.
-  LangOpts.Digraphs = LexingStd >= FormatStyle::LS_Cpp11;
-
-  LangOpts.LineComment = 1;
-  bool AlternativeOperators = Style.isCpp();
-  LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;
-  LangOpts.Bool = 1;
-  LangOpts.ObjC = 1;
-  LangOpts.MicrosoftExt = 1;// To get kw___try, kw___finally.
-  LangOpts.DeclSpecKeyword = 1; // To get __declspec.
-  LangOpts.C99 = 1; // To get kw_restrict for non-underscore-prefixed restrict.
-  return LangOpts;
-}
-
 const char *StyleOptionHelpDescription =
 "Set coding style.  can be:\n"
 "1. A preset: LLVM, GNU, Google, Chromium, Microsoft,\n"
diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index a87d0ba3dbbf9b..e517e413ec91fb 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -28,12 +28,12 @@ FormatTokenLexer::FormatTokenLexer(
 llvm::SpecificBumpPtrAllocator ,
 IdentifierTable )
 : FormatTok(nullptr), IsFirstToken(true), StateStack({LexerState::NORMAL}),
-  Column(Column), TrailingWhitespace(0),
-  LangOpts(getFormattingLangOpts(Style)), SourceMgr(SourceMgr), ID(ID),
+  Column(Column), TrailingWhitespace(0), SourceMgr(SourceMgr), ID(ID),
   Style(Style), IdentTable(IdentTable), Keywords(IdentTable),
   Encoding(Encoding), Allocator(Allocator), FirstInLineIndex(0),
   FormattingDisabled(false), MacroBlockBeginRegex(Style.MacroBlockBegin),
   MacroBlockEndRegex(Style.MacroBlockEnd) {
+  assert(LangOpts.CPlusPlus);
   Lex.reset(new Lexer(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts));
   Lex->SetKeepWhitespaceMode(true);
 
@@ -1442,7 +1442,7 @@ void FormatTokenLexer::readRawToken(FormatToken ) {
 
 void FormatTokenLexer::resetLexer(unsigned Offset) {
   StringRef Buffer = SourceMgr.getBufferData(ID);
-  LangOpts = getFormattingLangOpts(Style);
+  assert(LangOpts.CPlusPlus);
   Lex.reset(new Lexer(SourceMgr.getLocForStartOfFile(ID), 

[clang] [clang-format] Rename option AlwaysBreakAfterReturnType. (PR #80827)

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

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


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


[clang] [clang-format] Add BreakAfterReturnType option to deprecate AlwaysBreakAfterReturnType. (PR #80827)

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

owenca wrote:

See the follow-up commit 7664ddf88112 to #81093.

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


[clang] 7664ddf - [clang-format][NFC] Drop "Always" in "AlwaysBreakTemplateDeclarations"

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

Author: Owen Pan
Date: 2024-02-09T20:18:24-08:00
New Revision: 7664ddf8811242295abb837640cad8dd8cefb5e8

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

LOG: [clang-format][NFC] Drop "Always" in "AlwaysBreakTemplateDeclarations"

Added: 


Modified: 
clang/include/clang/Format/Format.h
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/Format.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/ConfigParseTest.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index b4969aa2b6fbe1..ab56cc8b6f9135 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1078,7 +1078,7 @@ struct FormatStyle {
   /// This option is renamed to ``BreakTemplateDeclarations``.
   /// \version 3.4
   /// @deprecated
-  BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations;
+  // BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations;
 
   /// A vector of strings that should be interpreted as attributes/qualifiers
   /// instead of identifiers. This can be useful for language extensions or
@@ -2296,7 +2296,7 @@ struct FormatStyle {
 
   /// The template declaration breaking style to use.
   /// \version 19
-  // BreakTemplateDeclarationsStyle BreakTemplateDeclarations;
+  BreakTemplateDeclarationsStyle BreakTemplateDeclarations;
 
   /// If ``true``, consecutive namespace declarations will be on the same
   /// line. If ``false``, each namespace is declared on a new line.
@@ -4822,8 +4822,7 @@ struct FormatStyle {
AlwaysBreakAfterReturnType == R.AlwaysBreakAfterReturnType &&
AlwaysBreakBeforeMultilineStrings ==
R.AlwaysBreakBeforeMultilineStrings &&
-   AlwaysBreakTemplateDeclarations ==
-   R.AlwaysBreakTemplateDeclarations &&
+   BreakTemplateDeclarations == R.BreakTemplateDeclarations &&
AttributeMacros == R.AttributeMacros &&
BinPackArguments == R.BinPackArguments &&
BinPackParameters == R.BinPackParameters &&

diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 7fd04b23abdca6..0b2ef97af44d83 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -569,9 +569,8 @@ bool ContinuationIndenter::mustBreak(const LineState 
) {
   return true;
 }
   }
-  return Style.AlwaysBreakTemplateDeclarations != FormatStyle::BTDS_No &&
- (Style.AlwaysBreakTemplateDeclarations !=
-  FormatStyle::BTDS_Leave ||
+  return Style.BreakTemplateDeclarations != FormatStyle::BTDS_No &&
+ (Style.BreakTemplateDeclarations != FormatStyle::BTDS_Leave ||
   Current.NewlinesBefore > 0);
 }
 if (Previous.is(TT_FunctionAnnotationRParen) &&

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c5a89490e9287d..d2cc466744acbd 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -878,7 +878,7 @@ template <> struct MappingTraits {
   IO.mapOptional("AlignEscapedNewlinesLeft", Style.AlignEscapedNewlines);
   IO.mapOptional("AllowAllConstructorInitializersOnNextLine", OnNextLine);
   IO.mapOptional("AlwaysBreakTemplateDeclarations",
- Style.AlwaysBreakTemplateDeclarations);
+ Style.BreakTemplateDeclarations);
   IO.mapOptional("BreakBeforeInheritanceComma",
  BreakBeforeInheritanceComma);
   IO.mapOptional("BreakConstructorInitializersBeforeComma",
@@ -972,7 +972,7 @@ template <> struct MappingTraits {
 IO.mapOptional("BreakInheritanceList", Style.BreakInheritanceList);
 IO.mapOptional("BreakStringLiterals", Style.BreakStringLiterals);
 IO.mapOptional("BreakTemplateDeclarations",
-   Style.AlwaysBreakTemplateDeclarations);
+   Style.BreakTemplateDeclarations);
 IO.mapOptional("ColumnLimit", Style.ColumnLimit);
 IO.mapOptional("CommentPragmas", Style.CommentPragmas);
 IO.mapOptional("CompactNamespaces", Style.CompactNamespaces);
@@ -1441,7 +1441,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_None;
   LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
   LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
-  LLVMStyle.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_MultiLine;
+  LLVMStyle.BreakTemplateDeclarations = FormatStyle::BTDS_MultiLine;
   LLVMStyle.AttributeMacros.push_back("__capability");
   LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
   

[clang] [clang-format] Rename option AlwaysBreakTemplateDeclarations (PR #81093)

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

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


[clang] [clang-format] Rename option AlwaysBreakTemplateDeclarations (PR #81093)

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

owenca wrote:

> I'd go contrary to your 
> [comment](https://github.com/llvm/llvm-project/pull/80827#issuecomment-1935386091)
>  and rename the attribute. Because otherwise you still have the contradiction 
> within the code.

I was not against renaming the attribute there. I just wanted it to be done in 
a separate NFC patch.

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


[clang] 02362b1 - [clang-format] Check token size in QualifierFixerTest.cpp

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

Author: Owen Pan
Date: 2024-02-09T02:14:50-08:00
New Revision: 02362b1ad1c07a01714b195d769400dd40dbfd04

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

LOG: [clang-format] Check token size in QualifierFixerTest.cpp

Added: 


Modified: 
clang/unittests/Format/QualifierFixerTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/QualifierFixerTest.cpp 
b/clang/unittests/Format/QualifierFixerTest.cpp
index 324366ca7f5e5..0aa755acfc821 100644
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -1055,6 +1055,7 @@ TEST_F(QualifierFixerTest, IsQualifierType) {
 
   auto Tokens = annotate(
   "const static inline auto restrict int double long constexpr friend");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
 
   EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
   Tokens[0], ConfiguredTokens));
@@ -1089,6 +1090,7 @@ TEST_F(QualifierFixerTest, IsQualifierType) {
   EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[9]));
 
   auto NotTokens = annotate("for while do Foo Bar ");
+  ASSERT_EQ(NotTokens.size(), 6u) << Tokens;
 
   EXPECT_FALSE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
   NotTokens[0], ConfiguredTokens));
@@ -1120,6 +1122,7 @@ TEST_F(QualifierFixerTest, IsQualifierType) {
 TEST_F(QualifierFixerTest, IsMacro) {
 
   auto Tokens = annotate("INT INTPR Foo int");
+  ASSERT_EQ(Tokens.size(), 5u) << Tokens;
 
   EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isPossibleMacro(Tokens[0]));
   EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isPossibleMacro(Tokens[1]));



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


[clang] 245d772 - Revert "[clang-format] Fix an out-of-bounds bug uncovered by 763139afc19d"

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

Author: Owen Pan
Date: 2024-02-09T01:53:47-08:00
New Revision: 245d7727d51548c3d5d867b69b1f9b1efff2502e

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

LOG: Revert "[clang-format] Fix an out-of-bounds bug uncovered by 763139afc19d"

This reverts commit 173e674ba55eb93e8af43f2eece7feffe9954b34.

Actually, NotTokens[5] in QualifierFixerTest.cpp is not out of bounds.

Added: 


Modified: 
clang/unittests/Format/QualifierFixerTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/QualifierFixerTest.cpp 
b/clang/unittests/Format/QualifierFixerTest.cpp
index 4e1768dc117273..324366ca7f5e51 100644
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -1100,6 +1100,8 @@ TEST_F(QualifierFixerTest, IsQualifierType) {
   NotTokens[3], ConfiguredTokens));
   EXPECT_FALSE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
   NotTokens[4], ConfiguredTokens));
+  EXPECT_FALSE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
+  NotTokens[5], ConfiguredTokens));
 
   EXPECT_FALSE(
   LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[0]));
@@ -,6 +1113,8 @@ TEST_F(QualifierFixerTest, IsQualifierType) {
   LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[3]));
   EXPECT_FALSE(
   LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[4]));
+  EXPECT_FALSE(
+  LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[5]));
 }
 
 TEST_F(QualifierFixerTest, IsMacro) {



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


[clang] 5609bd8 - Revert "[clang-format] Update FormatToken::isSimpleTypeSpecifier() (#80241)"

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

Author: Owen Pan
Date: 2024-02-09T01:52:41-08:00
New Revision: 5609bd83c3bd39a7522b05b32decc9e3c8ad08ae

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

LOG: Revert "[clang-format] Update FormatToken::isSimpleTypeSpecifier() 
(#80241)"

This reverts commit 763139afc19ddf2e0f0265dc828ce8e5fbe92530.

It seems that LangOpts is not initialized before use.

Added: 


Modified: 
clang/include/clang/Format/Format.h
clang/lib/Format/FormatToken.cpp
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/FormatTokenLexer.h

Removed: 




diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index bb63d33dfe6d5d..cb14d98825400b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5175,8 +5175,6 @@ tooling::Replacements sortUsingDeclarations(const 
FormatStyle ,
 ArrayRef Ranges,
 StringRef FileName = "");
 
-extern LangOptions LangOpts;
-
 /// Returns the ``LangOpts`` that the formatter expects you to set.
 ///
 /// \param Style determines specific settings for lexing mode.

diff  --git a/clang/lib/Format/FormatToken.cpp 
b/clang/lib/Format/FormatToken.cpp
index 69f751db896302..b791c5a26bbe3a 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -34,8 +34,41 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// FIXME: This is copy from Sema. Put it in a common place and remove
+// duplication.
 bool FormatToken::isSimpleTypeSpecifier() const {
-  return Tok.isSimpleTypeSpecifier(LangOpts);
+  switch (Tok.getKind()) {
+  case tok::kw_short:
+  case tok::kw_long:
+  case tok::kw___int64:
+  case tok::kw___int128:
+  case tok::kw_signed:
+  case tok::kw_unsigned:
+  case tok::kw_void:
+  case tok::kw_char:
+  case tok::kw_int:
+  case tok::kw_half:
+  case tok::kw_float:
+  case tok::kw_double:
+  case tok::kw___bf16:
+  case tok::kw__Float16:
+  case tok::kw___float128:
+  case tok::kw___ibm128:
+  case tok::kw_wchar_t:
+  case tok::kw_bool:
+#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
+#include "clang/Basic/TransformTypeTraits.def"
+  case tok::annot_typename:
+  case tok::kw_char8_t:
+  case tok::kw_char16_t:
+  case tok::kw_char32_t:
+  case tok::kw_typeof:
+  case tok::kw_decltype:
+  case tok::kw__Atomic:
+return true;
+  default:
+return false;
+  }
 }
 
 bool FormatToken::isTypeOrIdentifier() const {

diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index 31b2b7ef77f81c..a87d0ba3dbbf9b 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -22,20 +22,18 @@
 namespace clang {
 namespace format {
 
-LangOptions LangOpts;
-
 FormatTokenLexer::FormatTokenLexer(
 const SourceManager , FileID ID, unsigned Column,
 const FormatStyle , encoding::Encoding Encoding,
 llvm::SpecificBumpPtrAllocator ,
 IdentifierTable )
 : FormatTok(nullptr), IsFirstToken(true), StateStack({LexerState::NORMAL}),
-  Column(Column), TrailingWhitespace(0), SourceMgr(SourceMgr), ID(ID),
+  Column(Column), TrailingWhitespace(0),
+  LangOpts(getFormattingLangOpts(Style)), SourceMgr(SourceMgr), ID(ID),
   Style(Style), IdentTable(IdentTable), Keywords(IdentTable),
   Encoding(Encoding), Allocator(Allocator), FirstInLineIndex(0),
   FormattingDisabled(false), MacroBlockBeginRegex(Style.MacroBlockBegin),
   MacroBlockEndRegex(Style.MacroBlockEnd) {
-  LangOpts = getFormattingLangOpts(Style);
   Lex.reset(new Lexer(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts));
   Lex->SetKeepWhitespaceMode(true);
 
@@ -1444,6 +1442,7 @@ void FormatTokenLexer::readRawToken(FormatToken ) {
 
 void FormatTokenLexer::resetLexer(unsigned Offset) {
   StringRef Buffer = SourceMgr.getBufferData(ID);
+  LangOpts = getFormattingLangOpts(Style);
   Lex.reset(new Lexer(SourceMgr.getLocForStartOfFile(ID), LangOpts,
   Buffer.begin(), Buffer.begin() + Offset, Buffer.end()));
   Lex->SetKeepWhitespaceMode(true);

diff  --git a/clang/lib/Format/FormatTokenLexer.h 
b/clang/lib/Format/FormatTokenLexer.h
index 52838f1d8a17f5..65dd733bd53352 100644
--- a/clang/lib/Format/FormatTokenLexer.h
+++ b/clang/lib/Format/FormatTokenLexer.h
@@ -120,6 +120,7 @@ class FormatTokenLexer {
   unsigned Column;
   unsigned TrailingWhitespace;
   std::unique_ptr Lex;
+  LangOptions LangOpts;
   const SourceManager 
   FileID ID;
   const FormatStyle 



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


[clang] 173e674 - [clang-format] Fix an out-of-bounds bug uncovered by 763139afc19d

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

Author: Owen Pan
Date: 2024-02-09T00:21:09-08:00
New Revision: 173e674ba55eb93e8af43f2eece7feffe9954b34

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

LOG: [clang-format] Fix an out-of-bounds bug uncovered by 763139afc19d

Added: 


Modified: 
clang/unittests/Format/QualifierFixerTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/QualifierFixerTest.cpp 
b/clang/unittests/Format/QualifierFixerTest.cpp
index 324366ca7f5e51..4e1768dc117273 100644
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -1100,8 +1100,6 @@ TEST_F(QualifierFixerTest, IsQualifierType) {
   NotTokens[3], ConfiguredTokens));
   EXPECT_FALSE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
   NotTokens[4], ConfiguredTokens));
-  EXPECT_FALSE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
-  NotTokens[5], ConfiguredTokens));
 
   EXPECT_FALSE(
   LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[0]));
@@ -1113,8 +,6 @@ TEST_F(QualifierFixerTest, IsQualifierType) {
   LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[3]));
   EXPECT_FALSE(
   LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[4]));
-  EXPECT_FALSE(
-  LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[5]));
 }
 
 TEST_F(QualifierFixerTest, IsMacro) {



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


[clang] [clang-format][docs] Fix version (PR #81185)

2024-02-08 Thread Owen Pan via cfe-commits
=?utf-8?q?Bj=C3=B6rn_Sch=C3=A4pers?= 
Message-ID:
In-Reply-To: 


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

Good catch!

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


[clang] [clang-format] Add BreakAfterReturnType option to deprecate AlwaysBreakAfterReturnType. (PR #80827)

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


@@ -1010,7 +1010,8 @@ struct FormatStyle {
   /// \version 3.7
   DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType;
 
-  /// The function declaration return type breaking style to use.
+  /// The function declaration return type breaking style to use.  This
+  /// option is **deprecated** and is retained for backwards compatibility.
   /// \version 3.8
   ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;

owenca wrote:

+1, but see 
https://github.com/llvm/llvm-project/pull/80827#issuecomment-1935386091.

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


[clang] [clang-format] Add BreakAfterReturnType option to deprecate AlwaysBreakAfterReturnType. (PR #80827)

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

owenca wrote:

@rmarker we only need to change the user-facing part and should leave the 
internal naming unchanged (at least in this patch) in order to have the 
smallest diff possible. I've added the support for deprecating/renaming 
top-level struct-type options to `dump_format_style.py` in #81093.

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


[clang] [clang-format] Rename option AlwaysBreakTemplateDeclarations (PR #81093)

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

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

>From b9463c6664227edd6e579840292389909be04ab2 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 7 Feb 2024 22:43:15 -0800
Subject: [PATCH 1/3] [clang-format] Rename option
 AlwaysBreakTemplateDeclarations

Drop the "Always" prefix to remove the self-contradiction.
---
 clang/docs/ClangFormatStyleOptions.rst | 117 +++--
 clang/docs/tools/dump_format_style.py  |   7 ++
 clang/include/clang/Format/Format.h|   7 +-
 clang/lib/Format/Format.cpp|   6 +-
 clang/unittests/Format/ConfigParseTest.cpp |  13 +++
 5 files changed, 91 insertions(+), 59 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 0a8cc18c5b4cb5..f3da652e691451 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1659,62 +1659,8 @@ the configuration (without a prefix: ``Auto``).
 
 .. _AlwaysBreakTemplateDeclarations:
 
-**AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) 
:versionbadge:`clang-format 3.4` :ref:`¶ `
-  The template declaration breaking style to use.
-
-  Possible values:
-
-  * ``BTDS_Leave`` (in configuration: ``Leave``)
-Do not change the line breaking before the declaration.
-
-.. code-block:: c++
-
-   template 
-   T foo() {
-   }
-   template  T foo(int a,
-   int b) {
-   }
-
-  * ``BTDS_No`` (in configuration: ``No``)
-Do not force break before declaration.
-``PenaltyBreakTemplateDeclaration`` is taken into account.
-
-.. code-block:: c++
-
-   template  T foo() {
-   }
-   template  T foo(int a,
-   int b) {
-   }
-
-  * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
-Force break after template declaration only when the following
-declaration spans multiple lines.
-
-.. code-block:: c++
-
-   template  T foo() {
-   }
-   template 
-   T foo(int a,
- int b) {
-   }
-
-  * ``BTDS_Yes`` (in configuration: ``Yes``)
-Always break after template declaration.
-
-.. code-block:: c++
-
-   template 
-   T foo() {
-   }
-   template 
-   T foo(int a,
- int b) {
-   }
-
-
+**AlwaysBreakTemplateDeclarations** (``deprecated``) 
:versionbadge:`clang-format 3.4` :ref:`¶ `
+  This option is renamed to ``BreakTemplateDeclarations``.
 
 .. _AttributeMacros:
 
@@ -3014,6 +2960,65 @@ the configuration (without a prefix: ``Auto``).
  string x =
  "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
 
+.. _BreakTemplateDeclarations:
+
+**BreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  The template declaration breaking style to use.
+
+  Possible values:
+
+  * ``BTDS_Leave`` (in configuration: ``Leave``)
+Do not change the line breaking before the declaration.
+
+.. code-block:: c++
+
+   template 
+   T foo() {
+   }
+   template  T foo(int a,
+   int b) {
+   }
+
+  * ``BTDS_No`` (in configuration: ``No``)
+Do not force break before declaration.
+``PenaltyBreakTemplateDeclaration`` is taken into account.
+
+.. code-block:: c++
+
+   template  T foo() {
+   }
+   template  T foo(int a,
+   int b) {
+   }
+
+  * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
+Force break after template declaration only when the following
+declaration spans multiple lines.
+
+.. code-block:: c++
+
+   template  T foo() {
+   }
+   template 
+   T foo(int a,
+ int b) {
+   }
+
+  * ``BTDS_Yes`` (in configuration: ``Yes``)
+Always break after template declaration.
+
+.. code-block:: c++
+
+   template 
+   T foo() {
+   }
+   template 
+   T foo(int a,
+ int b) {
+   }
+
+
+
 .. _ColumnLimit:
 
 **ColumnLimit** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ 
`
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index e41891f07de2e3..203e9450ed3767 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -308,6 +308,7 @@ class State:
 enum = None
 nested_struct = None
 version = None
+deprecated = False
 
 for line in self.header:
 self.lineno += 1
@@ -327,6 +328,8 @@ class State:
 match = re.match(r"/// 

[clang] [clang-format] Update FormatToken::isSimpleTypeSpecifier() (PR #80241)

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

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


[clang] [clang-format] Fix a regression in dumping the config (PR #80628)

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

owenca wrote:

/cherry-pick 8f6e13e6da84

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


[clang] [clang-format] Fix a regression in dumping the config (PR #80628)

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

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


[clang] [clang-format] Rename option AlwaysBreakTemplateDeclarations (PR #81093)

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

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

>From b9463c6664227edd6e579840292389909be04ab2 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 7 Feb 2024 22:43:15 -0800
Subject: [PATCH 1/2] [clang-format] Rename option
 AlwaysBreakTemplateDeclarations

Drop the "Always" prefix to remove the self-contradiction.
---
 clang/docs/ClangFormatStyleOptions.rst | 117 +++--
 clang/docs/tools/dump_format_style.py  |   7 ++
 clang/include/clang/Format/Format.h|   7 +-
 clang/lib/Format/Format.cpp|   6 +-
 clang/unittests/Format/ConfigParseTest.cpp |  13 +++
 5 files changed, 91 insertions(+), 59 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 0a8cc18c5b4cb5..f3da652e691451 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1659,62 +1659,8 @@ the configuration (without a prefix: ``Auto``).
 
 .. _AlwaysBreakTemplateDeclarations:
 
-**AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) 
:versionbadge:`clang-format 3.4` :ref:`¶ `
-  The template declaration breaking style to use.
-
-  Possible values:
-
-  * ``BTDS_Leave`` (in configuration: ``Leave``)
-Do not change the line breaking before the declaration.
-
-.. code-block:: c++
-
-   template 
-   T foo() {
-   }
-   template  T foo(int a,
-   int b) {
-   }
-
-  * ``BTDS_No`` (in configuration: ``No``)
-Do not force break before declaration.
-``PenaltyBreakTemplateDeclaration`` is taken into account.
-
-.. code-block:: c++
-
-   template  T foo() {
-   }
-   template  T foo(int a,
-   int b) {
-   }
-
-  * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
-Force break after template declaration only when the following
-declaration spans multiple lines.
-
-.. code-block:: c++
-
-   template  T foo() {
-   }
-   template 
-   T foo(int a,
- int b) {
-   }
-
-  * ``BTDS_Yes`` (in configuration: ``Yes``)
-Always break after template declaration.
-
-.. code-block:: c++
-
-   template 
-   T foo() {
-   }
-   template 
-   T foo(int a,
- int b) {
-   }
-
-
+**AlwaysBreakTemplateDeclarations** (``deprecated``) 
:versionbadge:`clang-format 3.4` :ref:`¶ `
+  This option is renamed to ``BreakTemplateDeclarations``.
 
 .. _AttributeMacros:
 
@@ -3014,6 +2960,65 @@ the configuration (without a prefix: ``Auto``).
  string x =
  "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
 
+.. _BreakTemplateDeclarations:
+
+**BreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  The template declaration breaking style to use.
+
+  Possible values:
+
+  * ``BTDS_Leave`` (in configuration: ``Leave``)
+Do not change the line breaking before the declaration.
+
+.. code-block:: c++
+
+   template 
+   T foo() {
+   }
+   template  T foo(int a,
+   int b) {
+   }
+
+  * ``BTDS_No`` (in configuration: ``No``)
+Do not force break before declaration.
+``PenaltyBreakTemplateDeclaration`` is taken into account.
+
+.. code-block:: c++
+
+   template  T foo() {
+   }
+   template  T foo(int a,
+   int b) {
+   }
+
+  * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
+Force break after template declaration only when the following
+declaration spans multiple lines.
+
+.. code-block:: c++
+
+   template  T foo() {
+   }
+   template 
+   T foo(int a,
+ int b) {
+   }
+
+  * ``BTDS_Yes`` (in configuration: ``Yes``)
+Always break after template declaration.
+
+.. code-block:: c++
+
+   template 
+   T foo() {
+   }
+   template 
+   T foo(int a,
+ int b) {
+   }
+
+
+
 .. _ColumnLimit:
 
 **ColumnLimit** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ 
`
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index e41891f07de2e3..203e9450ed3767 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -308,6 +308,7 @@ class State:
 enum = None
 nested_struct = None
 version = None
+deprecated = False
 
 for line in self.header:
 self.lineno += 1
@@ -327,6 +328,8 @@ class State:
 match = re.match(r"/// 

[clang] [clang-format] Rename option AlwaysBreakTemplateDeclarations (PR #81093)

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

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

Drop the "Always" prefix to remove the self-contradiction.

>From b9463c6664227edd6e579840292389909be04ab2 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 7 Feb 2024 22:43:15 -0800
Subject: [PATCH] [clang-format] Rename option AlwaysBreakTemplateDeclarations

Drop the "Always" prefix to remove the self-contradiction.
---
 clang/docs/ClangFormatStyleOptions.rst | 117 +++--
 clang/docs/tools/dump_format_style.py  |   7 ++
 clang/include/clang/Format/Format.h|   7 +-
 clang/lib/Format/Format.cpp|   6 +-
 clang/unittests/Format/ConfigParseTest.cpp |  13 +++
 5 files changed, 91 insertions(+), 59 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 0a8cc18c5b4cb5..f3da652e691451 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1659,62 +1659,8 @@ the configuration (without a prefix: ``Auto``).
 
 .. _AlwaysBreakTemplateDeclarations:
 
-**AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) 
:versionbadge:`clang-format 3.4` :ref:`¶ `
-  The template declaration breaking style to use.
-
-  Possible values:
-
-  * ``BTDS_Leave`` (in configuration: ``Leave``)
-Do not change the line breaking before the declaration.
-
-.. code-block:: c++
-
-   template 
-   T foo() {
-   }
-   template  T foo(int a,
-   int b) {
-   }
-
-  * ``BTDS_No`` (in configuration: ``No``)
-Do not force break before declaration.
-``PenaltyBreakTemplateDeclaration`` is taken into account.
-
-.. code-block:: c++
-
-   template  T foo() {
-   }
-   template  T foo(int a,
-   int b) {
-   }
-
-  * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
-Force break after template declaration only when the following
-declaration spans multiple lines.
-
-.. code-block:: c++
-
-   template  T foo() {
-   }
-   template 
-   T foo(int a,
- int b) {
-   }
-
-  * ``BTDS_Yes`` (in configuration: ``Yes``)
-Always break after template declaration.
-
-.. code-block:: c++
-
-   template 
-   T foo() {
-   }
-   template 
-   T foo(int a,
- int b) {
-   }
-
-
+**AlwaysBreakTemplateDeclarations** (``deprecated``) 
:versionbadge:`clang-format 3.4` :ref:`¶ `
+  This option is renamed to ``BreakTemplateDeclarations``.
 
 .. _AttributeMacros:
 
@@ -3014,6 +2960,65 @@ the configuration (without a prefix: ``Auto``).
  string x =
  "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
 
+.. _BreakTemplateDeclarations:
+
+**BreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `
+  The template declaration breaking style to use.
+
+  Possible values:
+
+  * ``BTDS_Leave`` (in configuration: ``Leave``)
+Do not change the line breaking before the declaration.
+
+.. code-block:: c++
+
+   template 
+   T foo() {
+   }
+   template  T foo(int a,
+   int b) {
+   }
+
+  * ``BTDS_No`` (in configuration: ``No``)
+Do not force break before declaration.
+``PenaltyBreakTemplateDeclaration`` is taken into account.
+
+.. code-block:: c++
+
+   template  T foo() {
+   }
+   template  T foo(int a,
+   int b) {
+   }
+
+  * ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
+Force break after template declaration only when the following
+declaration spans multiple lines.
+
+.. code-block:: c++
+
+   template  T foo() {
+   }
+   template 
+   T foo(int a,
+ int b) {
+   }
+
+  * ``BTDS_Yes`` (in configuration: ``Yes``)
+Always break after template declaration.
+
+.. code-block:: c++
+
+   template 
+   T foo() {
+   }
+   template 
+   T foo(int a,
+ int b) {
+   }
+
+
+
 .. _ColumnLimit:
 
 **ColumnLimit** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ 
`
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index e41891f07de2e3..203e9450ed3767 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -308,6 +308,7 @@ class State:
 enum = None
 nested_struct = None
 version = None
+deprecated = False
 
 for line in self.header:
 self.lineno += 1
@@ -327,6 +328,8 @@ class State:

[clang] [clang-format] Fix a regression in dumping the config (PR #80628)

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

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


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