3239 Commits

Author SHA1 Message Date
Owen Pan
e6d7f46ce9
[clang-format] Correctly annotate user-defined conversion function call (#137914)
Fix #137770
2025-04-30 20:08:00 -07:00
Owen Pan
8effc8da29 Reland [clang-format] Add OneLineFormatOffRegex option (#137577) 2025-04-30 19:58:59 -07:00
Reid Kleckner
afd738cd90
[clang] Shard out some small gtest binaries (#138021)
@nico mentioned that FormatTests and BasicTests are small binaries with
few dependencies, so keeping them separate is nice. I broke them out as
distinct test binaries, and they are still pretty small:

$ find tools/clang/unittests/ -type f -name '*Tests' | xargs du -cksh |
sort -nr
708M    total
276M    tools/clang/unittests/AllClangUnitTests
244M    tools/clang/unittests/Interpreter/ClangReplInterpreterTests
167M
tools/clang/unittests/Interpreter/ExceptionTests/ClangReplInterpreterExceptionTests
 13M    tools/clang/unittests/Format/FormatTests
6.9M    tools/clang/unittests/Basic/BasicTests
1.1M    tools/clang/unittests/libclang/CrashTests/libclangCrashTests

I also broke out libclangCrashTests and re-enabled the failing test to
resolve llvm#137855.
2025-04-30 16:40:21 -07:00
Owen Pan
7752e0a10b Revert "[clang-format] Add OneLineFormatOffRegex option (#137577)"
This reverts commit b8bb1ccb4f9126d1bc9817be24e17f186a75a08b which triggered
an assertion failure in CodeGenTest.TestNonAlterTest.
2025-04-30 00:12:41 -07:00
Owen Pan
b8bb1ccb4f
[clang-format] Add OneLineFormatOffRegex option (#137577)
Close #54334
2025-04-29 19:22:53 -07:00
Owen Pan
d403c70ff3
[clang-format] Annotate tok::star in a*b*c as BinaryOperator (#137433)
Fix #137400
2025-04-26 12:55:00 -07:00
Owen Pan
ae07f48913
[clang-format] Correctly handle C# new modifier (#137430)
Fix #75815
2025-04-26 12:54:38 -07:00
Owen Pan
61d78d0c08
[clang-format] Correctly handle C# where clause (#137295)
Fix #74947
2025-04-25 13:08:16 -07:00
Owen Pan
82f1f5e5d4
[clang-format] Correctly identify include guards (#137112)
Fix #136814
2025-04-24 20:17:07 -07:00
Owen Pan
da8f2d5242 Revert "[clang-format] Allow breaking before kw___attribute (#128623)"
This reverts commit 8fc8a84e23471fe56214e68706addc712b5a2949, which caused a
regression.

Fixes #136675.
2025-04-22 23:49:26 -07:00
Owen Pan
afc030dd30
[clang-format] Don't test stability if JS format test fails (#136662) 2025-04-22 21:09:21 -07:00
Owen Pan
037657de7e
[clang-format] Correctly annotate kw_operator in using decls (#136545)
Fix #136541
2025-04-22 21:08:56 -07:00
Owen Pan
9efabbbbe5
[clang-format] Fix a bug in lexing C++ UDL ending in $ (#136476)
Fix #61612
2025-04-22 21:08:09 -07:00
Owen Pan
4f71655b64
[clang-format] Fix a bug in parsing C-style cast of lambdas (#136099)
Fix #135959
2025-04-22 21:07:31 -07:00
Kazu Hirata
c2d6c7cea7
[clang] Use llvm::append_range (NFC) (#136448) 2025-04-19 12:21:14 -07:00
Owen Pan
58a5c469d9
[clang-format] Fix a bug in BWACS_MultiLine (#136281)
Fixes #136266
2025-04-18 18:13:02 -07:00
Owen Pan
ab4c939579
[clang-format] Fix a bug in annotating TT_PointerOrReference (#136073)
Fix #135972
2025-04-18 18:12:27 -07:00
Owen Pan
c64f670255
[clang-format] Fix a crash in EnumTrailingComma (#135903)
Fix #135819
2025-04-18 18:11:56 -07:00
Michael Liao
77721986d8 [clang-format] Fix shared build. NFC 2025-04-17 22:49:50 -04:00
Owen Pan
c99ffe58af
[clang-format] Fix a bug in FormatToken::isObjCAccessSpecifier() (#136109)
Fix #136092
2025-04-17 19:07:14 -07:00
Owen Pan
9bd0c8726a
[clang-format] Fix a bug in BWACS_MultiLine (#135906)
Fix #51940
2025-04-16 18:48:10 -07:00
Owen Pan
c41ef751f8
[clang-format] Treat lambda in braced init as inline (#135520)
Fix #125430
2025-04-13 09:02:46 -07:00
Owen Pan
5f11d64cfb
[clang-format] Fix a bug in AlignConsecutiveDeclarations (#135516)
Fix #109768
2025-04-13 09:01:37 -07:00
Owen Pan
5f744cc630
[clang-format] Wrap and indent lambda braces in GNU style (#135479)
Fix #133135
2025-04-12 15:06:21 -07:00
Owen Pan
09c8cfe219
[clang-format][NFC] Add isJava() and isTextProto() in FormatStyle (#135466)
Also remove redundant name qualifiers format::, FormatStyle::, and
LanguageKind::.
2025-04-12 15:04:29 -07:00
sstwcw
f7617f7f90
[clang-format] Recognize TableGen paste operator on separate line (#133722)
Formatting this piece of code made the program crash.

```
class TypedVecListRegOperand<RegisterClass Reg, int lanes, string eltsize>
    : RegisterOperand<Reg, "printTypedVectorList<" # lanes # ", '"
                                                   # eltsize # "'>">;
```

The line starting with the `#` was treated as a separate preprocessor
directive line. Then the code dereferenced a null pointer when it tried
to continue parsing the first line that did not end in a semicolon.

Now the 2 problems are fixed.
2025-04-10 12:52:02 +00:00
sstwcw
ed85822027
[clang-format] Handle C++ keywords in other languages better (#132941)
There is some code to make sure that C++ keywords that are identifiers
in the other languages are not treated as keywords.  Right now, the kind
is set to identifier, and the identifier info is cleared.  The latter is
probably so that the code for identifying C++ structures does not
recognize those structures by mistake when formatting a language that
does not have those structures.  But we did not find an instance where
the language can have the sequence of tokens, the code tries to parse
the structure as if it is C++ using the identifier info instead of the
token kind, but without checking for the language setting.  However,
there are places where the code checks whether the identifier info field
is null or not.  They are places where an identifier and a keyword are
treated the same way.  For example, the name of a function in
JavaScript.  This patch removes the lines that clear the identifier
info.  This way, a C++ keyword gets treated in the same way as an
identifier in those places.

JavaScript

New

```JavaScript
async function
union(
    myparamnameiswaytooloooong) {
}
```

Old

```JavaScript
async function
    union(
        myparamnameiswaytooloooong) {
}
```

Java

New

```Java
enum union { ABC, CDE }
```

Old

```Java
enum
union { ABC, CDE }
```

This reverts commit 97dcbdef6089175c45e14fcbcf5c88b10233a79a.
2025-04-10 12:51:10 +00:00
Owen Pan
f344838389
[clang-format] Keep the space between not and a unary operator (#135035)
Also keep the space between `not` and `::`.

Based on the
[documentation](https://releases.llvm.org/20.1.0/tools/clang/docs/ClangFormatStyleOptions.html#spaceafterlogicalnot),
it can be argued that SpaceAfterLogicalNot doesn't cover the alternative
operator `not`.

Closes #125465
2025-04-09 17:52:12 -07:00
Owen Pan
aaaeb86ace
[clang-format] Merge inline short functions for BS_Whitesmiths (#134473)
Fix #126747
2025-04-05 17:03:55 -07:00
Owen Pan
d71ee7d230
[clang-format] Set C11 instead of C17 for LK_C (#134472)
Fix #134453
2025-04-05 13:35:45 -07:00
Reid Kleckner
e3c0565b74
Reapply "[cmake] Refactor clang unittest cmake" (#134195)
This reapplies 5ffd9bdb50b57 (#133545) with fixes.

The BUILD_SHARED_LIBS=ON build was fixed by adding missing LLVM
dependencies to the InterpTests binary in
unittests/AST/ByteCode/CMakeLists.txt .
2025-04-02 21:07:30 -07:00
Owen Pan
4fe0d74275
[clang-format] Fix a bug in annotating braces (#134039)
Fix #133873
2025-04-02 20:08:56 -07:00
dpalermo
03a791f703
Revert "[cmake] Refactor clang unittest cmake" (#134022)
Reverts llvm/llvm-project#133545

This change is breaking several buildbots as well as developer's builds.
Reverting to allow people to make progress.
2025-04-01 22:19:27 -05:00
Owen Pan
97dcbdef60 Revert "[clang-format] Handle C++ keywords in other languages better (#132941)"
This reverts commit ab7cee8a0ecf29fdb47c64c8d431a694d63390d2 which had
formatting errors.
2025-04-01 18:59:12 -07:00
Reid Kleckner
5ffd9bdb50
[cmake] Refactor clang unittest cmake (#133545)
Pass all the dependencies into add_clang_unittest. This is consistent
with how it is done for LLDB. I borrowed the same named argument list
structure from add_lldb_unittest. This is a necessary step towards
consolidating unit tests into fewer binaries, but seems like a good
refactoring in its own right.
2025-04-01 14:12:44 -07:00
Owen Pan
d3be29642f
[clang-format] Correctly annotate pointer/reference in _Generic (#133673)
Fix #133663
2025-03-31 23:16:41 -07:00
sstwcw
ab7cee8a0e [clang-format] Handle C++ keywords in other languages better (#132941)
There is some code to make sure that C++ keywords that are identifiers
in the other languages are not treated as keywords.  Right now, the kind
is set to identifier, and the identifier info is cleared.  The latter is
probably so that the code for identifying C++ structures does not
recognize those structures by mistake when formatting a language that
does not have those structures.  But we did not find an instance where
the language can have the sequence of tokens, the code tries to parse
the structure as if it is C++ using the identifier info instead of the
token kind, but without checking for the language setting.  However,
there are places where the code checks whether the identifier info field
is null or not.  They are places where an identifier and a keyword are
treated the same way.  For example, the name of a function in
JavaScript.  This patch removes the lines that clear the identifier
info.  This way, a C++ keyword gets treated in the same way as an
identifier in those places.

JavaScript

New

```JavaScript
async function
union(
    myparamnameiswaytooloooong) {
}
```

Old

```JavaScript
async function
    union(
        myparamnameiswaytooloooong) {
}
```

Java

New

```Java
enum union { ABC, CDE }
```

Old

```Java
enum
union { ABC, CDE }
```
2025-03-31 13:54:49 +00:00
sstwcw
cb54026d92
[clang-format] Recognize wait fork in Verilog (#132042)
before

```Verilog
wait fork
  ;
  wait fork
    ;
    wait fork
      ;
```

after

```Verilog
wait fork;
wait fork;
wait fork;
```

The `wait fork` statement should not start a block. Previously the
formatter treated the `fork` part as the start of a new block. Now the
problem is fixed.
2025-03-31 13:53:23 +00:00
Owen Pan
e5fcbfa2aa
[clang-format] Add an option for editing enum trailing commas (#133576)
Also refactor the code that removes/replaces a token.
2025-03-30 16:02:49 -07:00
Owen Pan
05fb8408de
[clang-format] Allow Language: Cpp for C files (#133033)
Fix #132832
2025-03-27 01:00:02 -07:00
Owen Pan
b8a0558dea
[clang-format] Fix a regression on annotating template angles (#132885)
Annotate the angles in `A<B != A>B` as template opener/closer as it's
unlikely that they are less/greater-than operators in this context.

Fix #132248
2025-03-27 00:57:17 -07:00
Owen Pan
2497945a95
[clang-format] Correctly annotate requires clause in && requires( (#132882)
Fix #132334
2025-03-25 08:19:43 -07:00
Owen Pan
da7f1564a8
[clang-format] Don't wrap before attributes in parameter lists (#132519)
Fix #132240
2025-03-24 19:18:13 -07:00
Owen Pan
91328dbae9
[clang-format] Correctly annotate user-defined conversion functions (#131434)
Also fix/delete existing invalid/redundant test cases.

Fix #130894
2025-03-16 16:11:39 -07:00
Jan Voung
467ad6a035
[clang-format] Add support for absl nullability macros (#130346)
Add support for formatting w/ absl nullability macros
(c52afac4f8/absl/base/nullability.h (L237)).
Example at https://godbolt.org/z/PYv19M1Gj
input:
```
std::vector<int* _Nonnull> x;
std::vector<int* absl_nonnull> y;
```

orig output:
```
std::vector<int* _Nonnull> x;
std::vector<int * absl_nonnull> y;
```

new output:
```
std::vector<int* _Nonnull> x;
std::vector<int* absl_nonnull> y;
```
credit to @ymand for the original patch
2025-03-14 00:01:35 -07:00
Owen Pan
7d4d8509cb
[clang-format] Don't remove parentheses separated from ellipsis by comma (#130471)
Also clean up `case tok::r_paren` in
`UnwrappedLineParser::parseParens()`.

Fix #130359
2025-03-10 19:42:54 -07:00
Owen Pan
3664b4e2d5
[clang-format] Remove special handling of C++ access specifiers in C (#129983)
This effectively reverts d1aed486efc6d35a81ca4acbabb4203c4b91cda9
because of
#129426.
2025-03-06 21:08:25 -08:00
Owen Pan
024362f413
[clang-format] Insert a space after kw_new by default (#129634)
This effectively reverts dbc4d281bd6954362ccfc0747893ceaae842671b.

Fix #54703
2025-03-04 21:14:07 -08:00
Owen Pan
2ca0855059
[clang-format] Fix a bug in wrapping function return type (#129374)
Fixes #113766
2025-03-03 18:15:32 -08:00
Owen Pan
136f2574dd
[clang-format] Lex C++ only keywords as identifiers in C (#129426)
Fix #128847
2025-03-03 17:40:28 -08:00