1992 Commits

Author SHA1 Message Date
Owen Pan
798f2019a2
[clang-format] Don't format comments in SkipMacroDefinitionBody (#94425)
Fixes #94326.
2024-06-05 17:57:36 -07:00
Owen Pan
f06f016419 [clang-format][NFC] Add missing parens of __attribute in unit tests 2024-06-02 12:44:40 -07:00
Owen Pan
80303cb287
[clang-format] Handle attributes before lambda return arrow (#94119)
Fixes #92657.
2024-06-02 12:26:10 -07:00
Owen Pan
c5fdb5c34e
[clang-format] Insert a space between a keyword and a literal (#93632)
Fixes #93603.
2024-05-30 22:13:00 -07:00
Owen Pan
dba2aa265c
[clang-format] Add LeftWithLastLine to AlignEscapedNewlines option (#93402)
Closes #92999.
2024-05-27 15:20:58 -07:00
Owen Pan
a6d97dec89
[clang-format] Correctly annotate C++ alternative operators in C (#92880)
PR #90161 uncovered a bug that annotates C++ xor as UnaryOperator if
followed by a binary operator. This patch fixes that and all other C++
alternative operator keywords when followed by a binary operator in C.

Fixes #92688.
2024-05-21 19:16:39 -07:00
Owen Pan
d89f20058b
[clang-format] Fix a bug in formatting goto labels in macros (#92494)
Fixes #92300.
2024-05-21 01:35:31 -07:00
Owen Pan
8fe39e64c0
[clang-format] Don't always break before << between string literals (#92214)
Instead, leave the line wrapping as is.

Fixes #43887.
Fixes #44363.
2024-05-16 19:23:47 -07:00
Owen Pan
db0ed55333
[clang-format] Don't remove parentheses of fold expressions (#91045)
Fixes #90966.
2024-05-05 21:33:41 -07:00
Owen Pan
aa596fa4d9
[clang-format] Set Change.TokenLength to ColumnWidth (#90378)
Fixes #37705.
Fixes #47333.
Fixes #47624.
Fixes #58850.
Fixes #75929.
Fixes #87885.
Fixes #89916.
2024-04-28 14:06:12 -07:00
Owen Pan
315dc4bbc7
[clang-format] Add a space after a word token only if required (#90161)
Fixes #78166.
2024-04-26 19:54:36 -07:00
Owen Pan
29ecd6d50f
[clang-format] Revert breaking stream operators to previous default (#89016)
Reverts commit d68826dfbd98, which changes the previous default behavior
of always breaking before a stream insertion operator `<<` if both
operands are string literals.

Also reverts the related commits 27f547968cce and bf05be5b87fc.

See the discussion in #88483.
2024-04-17 19:51:46 -07:00
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
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
5c056b3235 [clang-format] Clean up unit tests from commit 13be0d4a34c4
- Use 1-parameter verifyFormat() to verify formatted input in LLVM style.
- Pass string literal instead of constructed StringRef to verifyFormat().
- Don't include trailing newlines if not needed.
2024-04-08 21:20:18 -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
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
579dc7f844
[clang-forma] Support PointerAlignment for pointers to members (#86253)
Fixes #85761.
2024-03-23 02:03:45 -07:00
Owen Pan
a2527e06d7 [clang-format] Put erroneously removed braces back into a unit test
See https://github.com/llvm/llvm-project/pull/85470#discussion_r1528904789
2024-03-18 20:22:42 -07:00
Owen Pan
55a02d10d9 [clang-format][NFC] Minor changes to a unit test in 8e5de66af3da
See https://github.com/llvm/llvm-project/pull/85470#discussion_r1527297517
2024-03-17 21:37:32 -07: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
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
rayroudc
76ce3c1bcf
[clang-format] Enable again some operator tests (#83380)
Multiple formatting operator tests are commented. This change enables
them again.

[PR506629](https://llvm.org/PR50629) fixed by
[D153798](https://reviews.llvm.org/D153798).

Tests in `ConfigurableSpaceBeforeParens` have the same behavior as
before [D110833](https://reviews.llvm.org/D110833).

Update the test for function declaration and definition, as changed in
[D114696](https://reviews.llvm.org/D114696).
2024-03-01 21:24:13 +01: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
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
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
92ef40874d [clang-format] Delete a redundant newline at the end of a test case
It slipped in from commit fa6025e25b57.
2024-02-16 01:47:49 -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
4af24d4ab7
[clang-format] Don't remove parentheses in macro definitions (#81444)
Closes #81399.
2024-02-12 19:20:26 -08:00
Owen Pan
7664ddf881 [clang-format][NFC] Drop "Always" in "AlwaysBreakTemplateDeclarations" 2024-02-09 20:18:24 -08:00
Owen Pan
d033799050
[clang-format] Add Leave to AlwaysBreakTemplateDeclarations (#80569)
Closes #78067.
2024-02-07 20:24:44 -08:00
sstwcw
617602d4f2 [clang-format] Handle generic selections inside parentheses (#79785)
new

```C
while (_Generic(x, //
           long: x)(x) > x) {
}
while (_Generic(x, //
           long: x)(x)) {
}
```

old

```C
while (_Generic(x, //
       long: x)(x) > x) {
}
while (_Generic(x, //
    long: x)(x)) {
}
```

In the first case above, the second line previously aligned to the open
parenthesis.  The 4 spaces did not get added by the fallback line near
the end of getNewLineColumn because there was already some indentaton.
Now the spaces get added explicitly.

In the second case above, without the fake parentheses, the second line
did not respect the outer parentheses, because the LastSpace field did
not get set without the fake parentheses.  Now the indentation of the
outer level is used instead.
2024-02-06 05:02:12 +00:00
rmarker
2562007321
[clang-format] Add Automatic and ExceptShortType options for AlwaysBreakAfterReturnType. (#78011)
The RTBS_None option in Clang-format avoids breaking after a short
return type.
However, there was an issue with the behaviour in that it wouldn't take
the leading indentation of the line into account.
This meant that the behaviour wasn't applying when intended.

In order to address this situation without breaking the existing
formatting, RTBS_None has been deprecated.
In its place are two new options for AlwaysBreakAfterReturnType.
The option RTBS_Automatic will break after the return type based on
PenaltyReturnTypeOnItsOwnLine.
The option RTBS_ExceptShortType will take the leading indentation into
account and prevent breaking after short return types.

This allows the inconsistent behaviour of RTBS_None to be avoided and
users to decide whether they want to allow breaking after short return
types or not.

Resolves #78010
2024-02-04 12:26:32 -08:00
Owen Pan
908fd09a13
[clang-format] Simplify the AfterPlacementOperator option (#79796)
Change AfterPlacementOperator to a boolean and deprecate SBPO_Never,
which meant never inserting a space except when after new/delete.

Fixes #78892.
2024-01-31 20:20:26 -08:00
Gedare Bloom
4ef646eab3
[clang-format]: Fix formatting of if statements with BlockIndent (#77699)
A bug with BlockIndent prevents line breaks within if (and else if)
clauses.

While fixing this bug, it appears that AlignAfterOpenBracket is not
designed to work with loop and if statements, but AlwaysBreak works on
if clauses. The documentation and tests are not clear on whether or not
this behavior is intended.

This PR preserves the `AlwaysBreak` behavior on `if` clauses without
supporting `BlockIndent` on `if` clauses to avoid regressions while
fixing the bug.

It may be reasonable to create an explicit option for alignment of if
(and loop) clauses intentionally for both `AlwaysBreak` and
`BlockIndent`

Fixes #54663.

Migrated from Differential Revision: https://reviews.llvm.org/D154755
See more discussion there. Addressed last open comment from the rev
about refactoring the complex conditional logic involved with the
`AlignAfterOpenBracket` line break behavior.
2024-01-22 19:01:16 -08:00
Owen Pan
3b171cb968
[clang-format] Fix a bug in ContinuationIndenter (#78921)
Fixes #76991.
2024-01-22 18:59:08 -08:00
Emilia Kond
fa6025e25b
[clang-format] Don't confuse initializer equal signs in for loops (#77712)
clang-format has logic to align declarations of multiple variables of
the same type, aligning them at the equals sign. This logic is applied
in for loops as well. However, this alignment logic also erroneously
affected the equals signs of designated initializers.

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

Fixes https://github.com/llvm/llvm-project/issues/73902
2024-01-22 14:57:37 +02:00
XDeme
a464e05109
[clang-format] Handle templated elaborated type specifier in function… (#77013)
… return type.

The behavior now is consistent with the non template version.
Enabled and updated old test.
2024-01-20 14:47:58 -08:00
XDeme
2fc2ee136c
[clang-format] Fix poor spacing in AlignArrayOfStructures: Left (#77868)
Fixes llvm/llvm-project#62904

`AlignArrayOfStructures: Left` combined with `SpacesInParentheses: true`
causes the first cell of every row to have 1 additional space.
We were only setting the first cell of the first row to be against the
left brace, now every row will be against the left brace.
2024-01-20 13:34:37 -08:00
Owen Pan
a7d7da6e45
[clang-format] Add SkipMacroDefinitionBody option (#78682)
Closes #67991.

See also: #70338

Co-authored-by: @tomekpaszek
2024-01-20 00:08:23 -08:00
Ilya Biryukov
5723fce088
[Format] Fix isStartOfName to recognize attributes (#76804)
This addresses a problem with formatting attributes. Some context:
- eaff083035c8 changed `isStartOfName` to fix problems inside
`#pragma`s, but this behavior changed formatting of attribute macros in
an undesirable way.
- efeb546865c233dfa7706ee0316c676de9f69897 changed Google format style
to fix some widely used attributes.

Instead of changing the format style, this commit specializes behavior
introduced in eaff083035c8 to `#pragma`s. This seems to work well in
both cases.

Also update the test with two `GUARDED_BY` directives. While the
formatting after efeb546865c233dfa7706ee0316c676de9f69897 seems better,
this case is rare enough to not warrant the extra complexity. We are
reverting it back to the state it had before
efeb546865c233dfa7706ee0316c676de9f69897.

---------

Co-authored-by: Owen Pan <owenpiano@gmail.com>
2024-01-15 14:57:05 +01:00
rmarker
60a9874f54
[clang-format] Add PenaltyBreakScopeResolution option. (#78015)
Resolves #78014
2024-01-14 20:55:44 +01:00
XDeme
97a9dbb649
[clang-format] Handle possible crash in getCells (#77723)
Done as requested in llvm/llvm-project#77045

I have changed the test a bit, because since the root problem was fixed,
the original test would possibly never crash.
2024-01-12 10:20:44 -08:00
XDeme
093e6bdd4b
[clang-format] Fix crash involving array designators (#77045)
Fixes llvm/llvm-project#76716
Fixes parsing of `[0]{}`. Before this patch it was begin parsed as a
lambda, now it is correctly parsed as a designator initializer.
2024-01-10 19:46:11 -08:00