Commit Graph

3428 Commits

Author SHA1 Message Date
Owen Pan
51f1681424 [clang-format] Don't merge a short block for SBS_Never (#88238)
Also fix unit tests.

Fixes #87484.
2024-04-10 19:06:29 -07:00
Owen Pan
bcf849b1e5 [clang-format] instanceof is a keyword only in Java/JavaScript (#88085)
Fixes #87907.
2024-04-09 20:00:03 -07:00
Owen Pan
58323de2e5 [clang-format] Correctly annotate braces in macros (#87953)
Also fix unit tests and reformat polly.

Fixes #86550.
2024-04-09 19:59:36 -07:00
Owen Pan
943db678da [clang-format][NFC] Add getNextNonComment() to FormatTokenSource (#87868) 2024-04-07 13:58:49 -07:00
Owen Pan
684f27d37a [clang-format][NFC] Use is instead of getType() == 2024-04-06 01:51:45 -07:00
Owen Pan
770202343e [clang-format][NFC] Rename kind to Kind 2024-04-05 22:17:50 -07:00
Owen Pan
7c9c38eaa9 [clang-format] Fix a regression in annotating BK_BracedInit (#87450)
Fixes #86539.
2024-04-04 17:55:18 -07:00
Owen Pan
72e2e4f7dc [clang-format] Lambda parameter should be passed by const reference (#87306)
Closes #87254.
2024-04-03 09:00:23 -07:00
Owen Pan
a7f4576ff4 [clang-format] Fix a regression in annotating TrailingReturnArrow (#86624)
Fixes #86559.
2024-04-02 14:48:14 -07:00
Ameer J
13be0d4a34 [clang-format] Add BreakFunctionDefinitionParameters option (#84988)
This adds an option to break function definition parameters, putting
them on the next line after the function's opening paren.

This was a missing step towards allowing styles which require all
function definition parameters be on their own lines.

Closes #62963
2024-04-02 21:00:51 +02:00
Owen Pan
e766f87b92 [clang-format] Handle C++ Core Guidelines suppression tags (#86458)
Fixes #86451.
2024-03-27 21:22:57 -07:00
rayroudc
dd06b8e679 [clang-format] Fix anonymous reference parameter with default value (#86254)
When enabling alignment of consecutive declarations and reference right
alignment, the needed space between `& ` and ` = ` is removed in the
following use case.

Problem (does not compile)
```
int    a(const Test    &= Test());
double b();
```

Expected:
```
int    a(const Test & = Test());
double b();
```

Test command:

```
echo "int    a(const Test& = Test()); double b();" | clang-format -style="{AlignConsecutiveDeclarations: true, ReferenceAlignment: Right}"
```
2024-03-27 19:59:31 +01:00
Owen Pan
cceedc939a [clang-format] Fix a crash with AlignArrayOfStructures option (#86420)
Fixes #86109.
2024-03-24 15:22:40 -07:00
Owen Pan
47423e9827 [clang-format][NFC] Clean up IsQualifiedPointerOrReference in TokenAnnotator 2024-03-23 02:24:56 -07:00
Owen Pan
579dc7f844 [clang-forma] Support PointerAlignment for pointers to members (#86253)
Fixes #85761.
2024-03-23 02:03:45 -07:00
Hirofumi Nakamura
e54af60816 [clang-format] Added AlignConsecutiveTableGenBreakingDAGArgColons option. (#86150)
The option to specify the style of alignment of the colons inside TableGen's DAGArg.
2024-03-22 23:11:36 +09:00
Owen Pan
b2082a9817 Revert "[clang-format][NFC] Delete 100+ redundant #include lines in .cpp files"
This reverts commit b92d6dd704. See
github.com/llvm/llvm-project/commit/b92d6dd704d7#commitcomment-139992444

We should use a tool like Visual Studio to clean up the headers.
2024-03-19 21:28:22 -07:00
Owen Pan
6f31cf51df Revert "[clang-format][NFC] Eliminate the IsCpp parameter in all functions (#84599)"
This reverts c3a1eb6207 (and the related commit f3c5278efa) which makes
cleanupAroundReplacements() no longer thread-safe.
2024-03-19 18:06:59 -07:00
Hirofumi Nakamura
0c423af59c [clang-format] Add Options to break inside the TableGen DAGArg. (#83149)
Add two options to control the line break inside TableGen DAGArg.
- TableGenBreakInsideDAGArg
- TableGenBreakingDAGArgOperators
2024-03-19 00:13:59 +09:00
Benjamin Kramer
f362e12aab [clang-format] Make header self-contained
These includes were removed in 426e694589
2024-03-18 11:23:38 +01:00
scythris
8e5de66af3 [clang-format] Fix clang-format issue with 'new' and 'delete' keywords in C files (#85470)
This resolves an issue in clang-format where `new` and `delete` were
incorrectly formatted as keywords in C files. The fix modifies
`TokenAnnotator::spaceRequiredBetween` to handle `new` and `delete` when
used as identifiers for function pointers in structs in C code.
2024-03-17 21:06:32 +01:00
Owen Pan
f3c5278efa [clang-format][NFC] Don't export IsCpp in Format.h 2024-03-17 00:36:12 -07:00
Owen Pan
b92d6dd704 [clang-format][NFC] Delete 100+ redundant #include lines in .cpp files 2024-03-16 22:24:11 -07:00
Owen Pan
d33d5630b2 [clang-format] Fix a bug in SpaceInEmptyBlock option (#85508)
Fixes #84695.
2024-03-16 14:48:51 -07:00
Owen Pan
84b5178124 [clang-format] Correctly parse C++11 attributes in enum specifiers (#85498)
Fixes #85476.
2024-03-16 13:51:36 -07:00
Owen Pan
5ac784d1d0 Revert "[clang-format][NFC] Don't use clang-format style in config files"
This reverts commit c69ec700ad, which has been
obsolete since commit dec63221d5 because the clang-format style was added
in version 18.
2024-03-16 02:39:37 -07:00
Owen Pan
426e694589 [clang-format][NFC] Delete redundant and extraneous #include lines 2024-03-15 20:51:57 -07:00
Owen Pan
7c460c6205 [clang-format] Fix a bug in annotating FunctionDeclarationName (#85361)
A name is not a FunctionDeclarationName if it's preceded by an
Objective-C keyword.

Fixes #84578.
2024-03-15 19:25:41 -07:00
Owen Pan
c3a1eb6207 Reland [clang-format][NFC] Eliminate the IsCpp parameter in all functions (#84599)
Initialize IsCpp in LeftRightQualifierAlignmentFixer ctor.
2024-03-14 19:44:40 -07:00
Mehdi Amini
b0d1e32ca2 Revert "[clang-format][NFC] Eliminate the IsCpp parameter in all functions" (#85353)
Reverts llvm/llvm-project#84599

This broke the presubmit bot.
2024-03-14 19:33:11 -07:00
Owen Pan
0c07102927 [clang-format][NFC] Eliminate the IsCpp parameter in all functions (#84599) 2024-03-14 18:56:24 -07:00
Jie Fu
83fe0b1382 [clang] Fix -Wunused-lambda-capture in TokenAnnotator.cpp (NFC)
llvm-project/clang/lib/Format/TokenAnnotator.cpp:2707:43:
error: lambda capture 'this' is not used [-Werror,-Wunused-lambda-capture]
    auto IsQualifiedPointerOrReference = [this](FormatToken *T) {
                                          ^~~~
1 error generated.
2024-03-09 20:26:10 +08:00
Owen Pan
0baef3b18c [clang-format] Handle common C++ non-keyword types as such (#83709)
Fixes #83400.
2024-03-08 19:42:35 -08:00
Owen Pan
051e910b8b [clang-format][NFC] Replace Style.isCpp() with IsCpp (#83533) 2024-03-02 12:57:24 -08:00
Hirofumi Nakamura
19cec9ca12 [clang-format] Add AlignConsecutiveTableGenDefinitions option. (#83008)
To align TableGen consecutive definitions.
2024-02-27 22:31:23 +09:00
Owen Pan
b2a4f64e19 [clang-format][NFC] Skip ObjCHeaderStyleGuesser for empty code (#82957) 2024-02-26 20:46:46 -08:00
Hirofumi Nakamura
046682ef88 [clang-format] Add AlignConsecutiveTableGenCondOperatorColons option. (#82878)
To align colons inside TableGen !cond operators.
2024-02-26 22:50:51 +09:00
Owen Pan
b0d2a52c87 [clang-format][NFC] Enable RemoveSemicolon for clang-format style (#82735)
Also insert separators for decimal integers longer than 4 digits.
2024-02-23 20:03:13 -08:00
r4nt
ddb4450a46 [ClangFormat] Fix indent in child lines within a macro argument. (#82523)
When reconstructing lines from a macro expansion, make sure that lines
at different levels in the expanded code get indented correctly as part
of the macro argument.
2024-02-23 13:18:00 +01:00
Emilia Kond
2e7cacfced [clang-format] Fix crash in TokenAnnotator (#82349)
The while loop on line 3814 can cause a segmentation fault getting the
Next field on a nullptr. This is because further down, on line 3823,
there is another for loop, which assigns Tok to Tok->Next in its
initializer. This for loop has a condition to check if the result of
that isn't null. If it is, the loop is skipped and we drop back out to
the outer loop, except, now Tok is null, and we try to dereference it
without checking first.

This patch adds a defensive check that returns if Tok->Next is null
before we make it to the second for loop.

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

---------

Co-authored-by: Owen Pan <owenpiano@gmail.com>
2024-02-22 20:22:05 +02:00
Owen Pan
04fbc461e0 [clang-format] Fix RemoveSemicolon for empty functions (#82278)
Fixes #79833.
2024-02-20 21:51:51 -08:00
Owen Pan
119a72866f [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
2024-02-20 00:28:26 -08:00
rmarker
22fc2cb15d [clang-format] Fix AllowShortLambdasOnASingleLine interfering with lambda brace wrapping. (#81848)
Fix an issue where the lambda body left brace could sometimes fail to be
wrapped when AllowShortLambdasOnASingleLine is enabled.

Now, when BraceWrapping.BeforeLambdaBody is enabled, if the brace is not
wrapped, we prevent breaks in the lambda body.

Resolves #81845
2024-02-19 14:32:06 -08:00
Owen Pan
8de230093f [clang-format] Correctly annotate braces of empty ctors/dtors (#82097)
Also reformat Polly.

Fixes #79834.
2024-02-19 12:41:22 -08:00
Owen Pan
ea16a3bb4c [clang-format] Don't sort qualifiers across preprocessor directives (#81958)
Fixes #80579.
2024-02-16 23:19:31 -08:00
Hirofumi Nakamura
8c1c94e8c1 [clang-format] Support of TableGen basic format restrictions. (#81611)
- Allow/force to break the line or not.
- Allow/force to insert space or not.
2024-02-16 21:35:45 +09:00
Owen Pan
6087d7bc0a [clang-format][NFC] Sort options in Format.cpp 2024-02-14 21:40:07 -08:00
rmarker
d821650e13 [clang-format][NFC] Drop "Always" in "AlwaysBreakAfterReturnType". (#81591)
Complete the switch from "AlwaysBreakAfterReturnType" to
"BreakAfterReturnType".
2024-02-14 20:10:56 -08:00
Owen Pan
eafe98f937 [clang-format] Always add a space after #if and #elif (#81578)
Fixes #81569.
2024-02-13 22:35:52 -08:00
Owen Pan
61c83e9491 Revert "[clang-format][NFC] Make LangOpts global in namespace Format"
This reverts commit 32e65b0b8a.

It seems to break some PowerPC bots.

See https://github.com/llvm/llvm-project/pull/81390#issuecomment-1941964803.
2024-02-13 21:02:14 -08:00