775 Commits

Author SHA1 Message Date
Lane0218
f3b7710b6b
[clang-format] Correctly annotate C compound literal braces (#173771)
Fixes https://github.com/llvm/llvm-project/issues/173583

clang-format mis-formats C compound literals used in macro bodies, e.g.
`#define getAddr(v, type) &(type){v}`, treating `{...}` as a
block/function body
and reflowing the macro with backslashes and spaces.

This change:
- Recognizes `&( ... ){ ... }` patterns in macro bodies and marks the
brace as a braced-init.
- Improves parsing stability for braced lists in macro bodies.

Tests:
- FormatTests

---------

Co-authored-by: owenca <owenpiano@gmail.com>
2026-01-11 04:27:04 +00:00
Owen Pan
4f90ce4e6e [clang-format][NFC] Minor cleanups of RemoveParentheses 2026-01-10 19:58:29 -08:00
owenca
4930e94011
[clang-format] Fix a regression in annotating star before lambda (#170969)
Fixes #170573
2025-12-06 13:32:11 -08:00
owenca
07d14cb6d3
[clang-format][NFC] Remove the parameter of parseRequires...() (#169773) 2025-11-27 13:51:27 -08:00
sstwcw
d719876c20
[clang-format] Recognize Verilog DPI export and import (#165595)
The directives should not change the indentation level. Previously the
program erroneously added an indentation level when it saw the
`function` keyword.
2025-11-13 23:52:35 +00:00
Hannes Braun
6c4f968808
[clang-format] Fix brace wrapping for Java records (#164711)
The brace wrapping for Java records should now behave similar to
classes. Before, opening braces for Java records were always placed in
the same line as the record definition.
2025-11-05 20:55:32 +01:00
Kazu Hirata
1dfbfbd637
[clang] Replace LLVM_ATTRIBUTE_UNUSED with [[maybe_unused]] (NFC) (#163914)
This patch replaces LLVM_ATTRIBUTE_UNUSED with [[maybe_unused]],
introduced as part of C++17.
2025-10-17 07:27:11 -07:00
Ruoyu Zhong
513b10df43
[clang-format] Fix formatting of requires expressions in braced initializers (#163005)
`UnwrappedLineParser::parseBracedList` had no
explicit handling for the `requires` keyword, so it would just call
`nextToken()` instead of properly parsing the `requires` expression.

This fix adds a case for `tok::kw_requires` in `parseBracedList`,
calling `parseRequiresExpression` to handle it correctly, matching the
existing behavior in `parseParens`.

Fixes https://github.com/llvm/llvm-project/issues/162984.
2025-10-12 16:43:04 -07:00
Björn Schäpers
847e1e1890
[clang-format][NFC] Introduce isNoneOf (#161021)
And apply throughout the code base.
2025-10-02 20:52:45 +02:00
owenca
4edda3d78c
[clang-format] Fix bugs in annotating arrows and square brackets (#160973)
Fixes #160518
2025-09-27 21:29:25 -07:00
Gedare Bloom
7dd2f1cc10
[clang-format] Add IndentPPDirectives Leave option (#139750)
Allow an option to leave preprocessor directive indenting as-is. This
simplifies handling mixed styles of CPP directive indentation.

Fixes #38511
2025-09-14 13:47:06 -07:00
owenca
ac771f4574
[clang-format] Fix a bug in SkipMacroDefinitionBody (#155346)
All comments before the macro definition body should be skipped.
2025-08-26 09:00:56 -07:00
owenca
0b1d353926
[clang-format] Fix a bug in SkipMacroDefinitionBody (#154787)
Fixes #154683
2025-08-22 19:37:52 -07:00
Owen Pan
c384ec431d
[clang-format] Add MacrosSkippedByRemoveParentheses option (#148345)
This allows RemoveParentheses to skip the invocations of function-like
macros.

Fixes #68354.
Fixes #147780.
2025-07-13 14:29:51 -07:00
Owen Pan
a5af874503 [clang-format][NFC] Use empty() instead of comparing size() to 0 or 1 2025-07-06 23:54:00 -07:00
Owen Pan
f2f17e563d
[clang-format][NFC] Remove \brief from comments (#145853)
This was done before in https://reviews.llvm.org/D46320
2025-06-26 19:14:34 -07:00
Owen Pan
9a894ae794
[clang-format] Parse JSON outermost l_brace as braced list brace (#143327)
See
https://github.com/llvm/llvm-project/issues/65400#issuecomment-2922181979.
2025-06-09 20:34:12 -07:00
Owen Pan
05c12b2284
[clang-format] Handle requires clause following a pointer type (#142893)
Fix #142818
2025-06-05 19:55:37 -07:00
Kazu Hirata
dfaa66281a
[Format] Remove unused includes (NFC) (#142296)
These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.
2025-05-31 19:00:34 -07:00
Owen Pan
6a1d3ea57d
[clang-format] Handle Java record (#139215)
Fix #62089
2025-05-09 18:05:16 -07:00
Owen Pan
79210feb29
[clang-format] Fix a crash on formatting missing r_paren/r_brace (#138230)
Fix #138097
2025-05-02 19:20:42 -07:00
Owen Pan
d3506ee573
[clang-format] RemoveParentheses shouldn't remove empty parentheses (#138229)
Fix #138124
2025-05-02 19:19:39 -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
0af26149e2 [clang-format][NFC] Use UnwrappedLineParser::eof() whenever possible 2025-04-25 22:16:59 -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
4f71655b64
[clang-format] Fix a bug in parsing C-style cast of lambdas (#136099)
Fix #135959
2025-04-22 21:07:31 -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
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
Owen Pan
75cbb1f0fa
[clang-format][NFC] Add FormatToken::is(tok::ObjCKeywordKind) (#134973)
This allows simplification of code that checks if a token is an
Objective-C keyword.

Also, delete the following in
UnwrappedLineParser::parseStructuralElement():
- an else-after-break in the tok::at case
- the copypasted code in the tok::objc_autoreleasepool case
2025-04-09 17:49:26 -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
Owen Pan
4fe0d74275
[clang-format] Fix a bug in annotating braces (#134039)
Fix #133873
2025-04-02 20:08:56 -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
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
a6ccda28f7 [clang-format][NFC] Use better names for a couple of data members 2025-03-05 21:45:01 -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
2d585ccecc
[clang-format] Fix a bug that changes keyword or to an identifier (#128410)
Fixes #105482
2025-02-26 18:14:26 -08:00
Owen Pan
0968df9c3a
[clang-format] Add the C language instead of treating it like C++ (#128287)
Closes #128120
2025-02-23 00:36:19 -08:00
Owen Pan
885382f437
[clang-format] Fix a bug in annotating braces (#127306)
Fixes #107616.
2025-02-16 19:30:33 -08:00
Owen Pan
6980d97946
[clang-format] Fix a bug in annotating ClassHeadName (#125326) 2025-02-01 20:20:43 -08:00
Owen Pan
1a25bea852
[clang-format] Add ClassHeadName to help annotating StartOfName (#124891)
Fixes #124574.
2025-01-30 19:33:15 -08:00
Owen Pan
14178deab0
[clang-format] Fix a crash on parsing requires clause (#125021)
Fixes #124921.
2025-01-30 18:03:04 -08:00
Owen Pan
9452ee4f75
[clang-format] Treat uppercase identifiers after struct as macros (#124397)
This restores the behavior before llvmorg-20-init.

Fixes #94184.
Fixes #117477.
Fixes #122690.
Fixes #123142.
2025-01-27 00:11:18 -08:00
Sirraide
33656932b0
[clang-format] Rename ExportBlockIndentation -> IndentExportBlock (#123493)
This renames the `ExportBlockIndentation` option and adds a config parse
test, as requested in #110381.
2025-01-21 14:13:13 +01:00
Sirraide
106c483a10
[clang-format] Improve brace wrapping and add an option to control indentation of export { ... } (#110381)
`export { ... }` blocks can get a bit long, so I thought it would make
sense to have an option that makes it so their contents are not indented
(basically the same argument as for namespaces).

This is based on the `NamespaceIndentation` option, except that there is
no option to control the behaviour of `export` blocks when nested because
nesting them doesn’t really make sense.

Additionally, brace wrapping of short `export { ... }` blocks is now controlled by the
`AllowShortBlocksOnASingleLine` option. There is no separate option just for `export`
blocks because you can just write e.g. `export int x;` instead of `export { int x; }`.

This closes #121723.
2025-01-19 00:26:40 +01:00
Owen Pan
a7bca1861b
[clang-format] Correctly annotate braces in macro definitions (#123279)
Fixes #123179.
2025-01-17 19:26:00 -08:00
Owen Pan
00934505d4
[clang-format] Add TT_CompoundRequirementLBrace for better annotation (#121539)
Also, add `ST_CompoundRequirement` to help annotating */&/&& in compound
requirement expressions as `TT_BinaryOperator`.

Fixes #121471.
2025-01-04 20:51:00 -08:00
Owen Pan
c1ea05eaf0
[clang-format] Don't break short macro call followed by l_paren (#121626)
Fixes #105658.
2025-01-04 16:24:41 -08:00