54 Commits

Author SHA1 Message Date
Owen Pan
5ccbea9f48
[clang-format][NFC] Replace size() with empty() (#147164) 2025-07-06 14:19:30 -07:00
Owen Pan
01b288fe6a
[clang-format] Improve QualifierAlignment in guessing macros (#145468)
Fixes #145388
2025-06-25 00:01:06 -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
eb6ca1242c
[clang-format] Hanlde qualified type name for QualifierAlignment (#125327)
Fixes #125178.
2025-02-04 01:33:44 -08:00
Owen Pan
3bd8b02aa0
[clang-format] Handle leading C++11 attribute in QualifierAlignment (#123690)
Fixes #123573.
2025-01-21 21:22:13 -08:00
Owen Pan
40acaa394f
[clang-format] Fix a crash in QualifierAlignment: Right (#120821)
Fixes #120793.
2024-12-21 17:16:29 -08:00
Owen Pan
364f988d3f Reland "[clang-format] Fix FormatToken::isSimpleTypeSpecifier() (#91712)"
Remove FormatToken::isSimpleTypeSpecifier() and call
Token::isSimpleTypeSpecifier(LangOpts) instead.
2024-05-13 21:54:23 -07:00
Owen Pan
c72e94382c
[clang-format][NFC] Move LeftRightQualifierAlignmentFixer::is...() (#91930)
Move static member functions LeftRightQualifierAlignmentFixer::is...()
out of the class so that #91712 can reland.
2024-05-13 19:19:15 -07:00
Owen Pan
1fadb2b0c8 Revert "[clang-format] Fix FormatToken::isSimpleTypeSpecifier() (#91712)"
This reverts commits e62ce1f8842c, 5cd280433e8e, and de641e289269 due to
buildbot failures.
2024-05-12 23:15:35 -07:00
Owen Pan
626025ac77 Revert "[clang-format] Fix buildbot failures"
This reverts commit 0869204cff22831d0bb19a82c99bf85e4deb4ae3, which caused a
buildbot failure:
https://lab.llvm.org/buildbot/#/builders/5/builds/43322
2024-05-12 18:35:35 -07:00
Owen Pan
0869204cff [clang-format] Fix buildbot failures
This effectively reverts 5cd280433e8e and changes to QualifierFixerTest.cpp
from e62ce1f8842c.

Failed buidbots:
https://lab.llvm.org/buildbot/#/builders/236/builds/11223
https://lab.llvm.org/buildbot/#/builders/239/builds/6968
2024-05-11 15:23:35 -07:00
Owen Pan
e62ce1f884
[clang-format] Fix FormatToken::isSimpleTypeSpecifier() (#91712)
Remove FormatToken::isSimpleTypeSpecifier() and call
Token::isSimpleTypeSpecifier(LangOpts) instead.
2024-05-10 19:27:02 -07:00
Owen Pan
b2082a9817 Revert "[clang-format][NFC] Delete 100+ redundant #include lines in .cpp files"
This reverts commit b92d6dd704d789240685a336ad8b25a9f381b4cc. 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 c3a1eb6207d8 (and the related commit f3c5278efa3b) which makes
cleanupAroundReplacements() no longer thread-safe.
2024-03-19 18:06:59 -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
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
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
ea16a3bb4c
[clang-format] Don't sort qualifiers across preprocessor directives (#81958)
Fixes #80579.
2024-02-16 23:19:31 -08:00
Owen Pan
f0ad9ea36a
[clang-format] Handle lambdas in QualifierAlignment (#72456)
Fixed #62780.
2023-11-16 15:00:09 -08:00
Owen Pan
b04664be6f
[clang-format] Handle constrained auto in QualifierAlignment (#72251)
Fixed #69610.
2023-11-15 14:28:37 -08:00
Owen Pan
cc75e52016 [clang-format][NFC] Refactor isPointerOrReference 2023-11-10 01:23:05 -08:00
Owen Pan
77b2fc8ad9 [clang-format][NFC] Reformat and fix file mode
Fix file mode errors introduced in 2c9372e78d7c and format errors in
https://reviews.llvm.org/D155239.
2023-08-30 18:35:24 -07:00
MyDeveloperDay
2c9372e78d
[clang-format] Rename qualifier file comments (#64354)
* [clang-format] rename the file comments to match the file name

* [clang-format] rename the file comments to match the file name

* Remove extraneous space

* [clang-format] NFC remove EOF

---------

Co-authored-by: paul_hoad <paul_hoad@amat.com>
2023-08-26 16:48:52 +01:00
Owen Pan
91c4db0061 [clang-format][NFC] Replace !is() with isNot()
Differential Revision: https://reviews.llvm.org/D158571
2023-08-24 01:27:24 -07:00
Owen Pan
875b881186 [clang-format][NFC] Remove redundant parentheses in the source code
Reformat the source code with RemoveParentheses set to ReturnStatement.
2023-07-11 17:05:00 -07:00
Sedenion
899c867794 [clang-format] Fixed bad performance with enabled qualifier fixer.
This fixes github issue #57117: If the "QualifierAlignment"
option of clang-format is set to anything else but "Leave", the
"QualifierAlignmentFixer" pass gets enabled. This pass scales
quadratically with the number of preprocessor branches, i.e.
with the number of elements in TokenAnalyzer::UnwrappedLines.
The reason is that QualifierAlignmentFixer::process() generates
the UnwrappedLines, but then QualifierAlignmentFixer::analyze()
calls LeftRightQualifierAlignmentFixer::process() several times
(once for each qualifier) which again each time generates the
UnwrappedLines.

This commit gets rid of this double loop by registering the
individual LeftRightQualifierAlignmentFixer passes directly in
the top most container of passes (local variable "Passes" in
reformat()).
With this change, the original example in the github issue #57117
now takes only around 3s instead of >300s to format.

Since QualifierAlignmentFixer::analyze() got deleted, we also
no longer have the code with the NonNoOpFixes. This causes
replacements that end up not changing anything to appear in the
list of final replacements. There is a unit test to check that
this does not happen: QualifierFixerTest.NoOpQualifierReplacements.
However, it got broken at some point in time. So this commit
fixes the test. To keep the behavior that no no-op replacements
should appear from the qualifier fixer, the corresponding code
from QualifierAlignmentFixer::analyze() was moved to the top
reformat() function. Thus, is now done for **every** replacement
of every formatting pass. If no-op replacements are a problem
for the qualifier fixer, then it seems to be a good idea to
filter them out always.

See
https://github.com/llvm/llvm-project/issues/57117#issuecomment-1546716934
for some more details.

Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D153228
2023-07-03 11:54:33 +01:00
Colin Ogilvie
f3dcd3ad99 [clang-format] Correctly limit formatted ranges when specifying qualifier alignment
The qualifier alignment fixer appeared to ignore any ranges specified for limiting formatting.
This change ensures that it only formats affected lines to avoid unexpected changes.

Fixes #54888.

Differential Revision: https://reviews.llvm.org/D149643
2023-05-04 02:59:05 -07:00
Alexander Hederstaf
cd7ab4b5c1 [clang-format] Improve QualifierAlignment
Qualifiers were not moved for non-pointer non-simple types.
Add additional support for many special cases such as templates,
requires clauses, long qualified names.

Fixes https://github.com/llvm/llvm-project/issues/57154 and
https://github.com/llvm/llvm-project/issues/60898

Reviewed By: MyDeveloperDay, HazardyKnusperkeks

Differential Revision: https://reviews.llvm.org/D144709
2023-03-27 15:18:29 +01:00
Emilia Dreamer
393e197cd6
[clang-format] Don't move qualifiers past pointers-to-member
Previously, given a pointer-to-member type such as `Foo const Bar::*`,
clang-format would see the `const Bar::` part as a regular type name
with scope resolution operators, and with `QualifierAlignment: Right` it
would attempt to "fix" it, resulting in `Foo Bar::const *`, a syntax
error.

This patch no longer allows qualifiers to be moved across `::*`.

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

Reviewed By: owenpan, MyDeveloperDay, HazardyKnusperkeks

Differential Revision: https://reviews.llvm.org/D144537
2023-02-25 12:19:20 +02:00
Micah Weston
4cafc3727b [clang-format] Add 'friend' to QualifierOrder
For cases of defining friend functions, qualifier ordering can
allow multiple positions for the 'friend' token.

Closes #59450.

Differential Revision: https://reviews.llvm.org/D139801
2022-12-22 02:02:09 -08:00
Kazu Hirata
538401da1d [Format] Use std::optional in QualifierAlignmentFixer.cpp (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-09 23:09:06 -08:00
Kazu Hirata
258531b7ac Remove redundant initialization of Optional (NFC) 2022-08-20 21:18:28 -07:00
Marek Kurdej
d4d28f2ace [clang-format] Fix QualifierAlignment with global namespace qualified types.
Fixes https://github.com/llvm/llvm-project/issues/55610.

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D126096
2022-05-26 15:02:33 +02:00
owenca
bebf7bdf9a [clang-format][NFC] Insert/remove braces in clang/lib/Format/
Differential Revision: https://reviews.llvm.org/D126157
2022-05-24 19:06:04 -07:00
Owen Pan
492cb7bf91 [clang-format] Fix a crash in qualifier alignment
Related to #54513.
2022-04-01 17:30:59 -07:00
owenca
eee536dd31 [clang-format] Don't format qualifiers in PPDirective
Fixes #54513

Differential Revision: https://reviews.llvm.org/D122548
2022-03-28 14:28:14 -07:00
mydeveloperday
28bb040ded [clang-format] QualifierOrder does not reorder template arguments
https://github.com/llvm/llvm-project/issues/53981

Reorder the qualifiers inside the template argument. This should handle the simple cases of

```
<const T>
<T const>
```

But only by relaxing that single letter capital variables are not possible macros

Fixes: #53981

Reviewed By: HazardyKnusperkeks, curdeius

Differential Revision: https://reviews.llvm.org/D120710
2022-03-05 18:08:25 +00:00
Marek Kurdej
46f6c834d9 [clang-format] Fix QualifierOrder breaking the code with requires clause.
Fixes https://github.com/llvm/llvm-project/issues/53962.

Given the config:
```
BasedOnStyle: LLVM
QualifierAlignment: Custom
QualifierOrder: ['constexpr', 'type']
```

The code:
```
template <typename F>
  requires std::invocable<F>
constexpr constructor();
```
was incorrectly formatted to:
```
template <typename F>
  requires
constexpr std::invocable<F> constructor();
```
because we considered `std::invocable<F> constexpr` as a type, not recognising the requires clause.

This patch avoids moving the qualifier across the boundary of the requires clause (checking `ClosesRequiresClause`).

Reviewed By: HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D120309
2022-02-24 10:16:10 +01:00
Marek Kurdej
e329b5866f [clang-format] Honour "// clang-format off" when using QualifierOrder.
Fixes https://github.com/llvm/llvm-project/issues/53643.

Reviewed By: MyDeveloperDay, HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D119218
2022-02-09 22:15:20 +01:00
Marek Kurdej
06e42590a5 [clang-format] Comment unused parameters. NFC. 2022-02-08 09:33:55 +01:00
Marek Kurdej
7d6397348e [clang-format] Fix typo. NFC. 2022-02-08 09:33:54 +01:00
Marek Kurdej
d079995dd0 [clang-format] Elide unnecessary braces. NFC. 2022-02-02 15:28:53 +01:00
Marek Kurdej
ea2112ea15 [clang-format] Remove unused assignment. NFC.
Fixes scan-build reported warning: https://llvm.org/reports/scan-build/report-QualifierAlignmentFixer.cpp-analyzeRight-55-191910.html#EndPath.
2022-01-24 08:34:24 +01:00
Marek Kurdej
4681ae9353 [clang-format] Use range-for loops. NFC.
* Avoid if check on every element of the loop when printing symbols.
2022-01-07 16:06:11 +01:00
mydeveloperday
031d3ece3f [clang-format] Fix a crash (assertion) in qualifier alignment when matching template closer is null
https://github.com/llvm/llvm-project/issues/53008

```
template <class Id> using A = quantity /**/<kind<Id>, 1>;
```

the presence of the comment between identifier and template opener seems to be causing the qualifier alignment to fail

Reviewed By: curdeius

Fixes: #53008

Differential Revision: https://reviews.llvm.org/D116726
2022-01-06 19:40:39 +00:00
Manuel Klimek
c2271926a4 Make clang-format fuzz through Lexing with asserts enabled.
Makes clang-format bail out if an in-memory source file with an
unsupported BOM is handed in instead of creating source locations that
are violating clang's assumptions.

In the future, we should add support to better transport error messages
like this through clang-format instead of printing to stderr and not
creating any changes.
2021-11-19 14:44:06 +01:00
Kazu Hirata
e567f37dab [clang] Use llvm::is_contained (NFC) 2021-10-13 20:41:55 -07:00
Marek Kurdej
2c60cfc05f [format] [docs] Fix typos and clarify QualifierAlignment/QualifierOrder documentation. 2021-09-30 09:42:34 +02:00