262 Commits

Author SHA1 Message Date
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
ab4c939579
[clang-format] Fix a bug in annotating TT_PointerOrReference (#136073)
Fix #135972
2025-04-18 18:12:27 -07:00
Owen Pan
c99ffe58af
[clang-format] Fix a bug in FormatToken::isObjCAccessSpecifier() (#136109)
Fix #136092
2025-04-17 19:07:14 -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
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
d3be29642f
[clang-format] Correctly annotate pointer/reference in _Generic (#133673)
Fix #133663
2025-03-31 23:16:41 -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
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
136f2574dd
[clang-format] Lex C++ only keywords as identifiers in C (#129426)
Fix #128847
2025-03-03 17:40:28 -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
13de15c9c4
[clang-format] Fix a bug in annotating StartOfName (#127545)
Also ensure we can break before ClassHeadName like StartOfName.

Fixes #127470
2025-02-18 00:15:01 -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
3063153b56
[clang-format] Fix a bug in annotating ObjCMethodSpecifier (#127159)
Fixes #58202.
2025-02-14 21:10:08 -08:00
Owen Pan
3ca9238cb0 [clang-format][NFC] Fix test case format 2025-02-11 23:58:53 -08:00
Owen Pan
8d373ceaec
[clang-format] Handle C-style cast of member function pointer type (#126340)
Fixes #125012.
2025-02-08 23:22: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
ea84474966
[clang-format] Fix annotation of Java/JavaScript keyword extends (#125038)
Uncovered in #124891.
2025-01-30 18:03:42 -08:00
Owen Pan
4fb8078887
[clang-format] Fix annotation of class name after requires clause (#125019)
Uncovered in #124891.
2025-01-30 18:02:40 -08:00
Owen Pan
1e89355dad
[clang-format] Treat f<N | M>(a) as template function call (#124438)
Fixes #123144.
2025-01-27 09:28:29 -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
Owen Pan
8e31050bc2
[clang-format] Fix a bug in annotating overloaded co_await decl (#124240)
Fixes #124223.
2025-01-24 17:57:04 -08:00
Owen Pan
a7bca1861b
[clang-format] Correctly annotate braces in macro definitions (#123279)
Fixes #123179.
2025-01-17 19:26:00 -08:00
sstwcw
fbef1f835f
[clang-format][NFC] Make formatting Verilog faster (#121139)
A regular expression was used in the lexing process. It made the program
take more than linear time with regards to the length of the input. It
looked like the entire buffer could be scanned for every token lexed.
Now the regular expression is replaced with code. Previously it took 20
minutes for the program to format 125 000 lines of code on my computer.
Now it takes 315 milliseconds.
2025-01-14 15:37:06 +00:00
Owen Pan
9e4774b934
[clang-format] Add LT_RequiresExpression and LT_SimpleRequirement (#121681)
The new line types help to annotate */&/&& in simple requirements as
binary operators.

Fixes #121675.
2025-01-06 01:46:17 -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
44b83e81b5
[clang-format] Add TT_AfterPPDirective for better annotation (#121622)
For now, we only need to annotate the token after #error or #warning.

Fixes #117706.
2025-01-04 16:22:54 -08:00
Owen Pan
1a0d0ae234
[clang-format] Add VariableTemplates option (#121318)
Closes #120148.
2025-01-01 18:24:56 -08:00
Owen Pan
b1b60d4c1d
[clang-format] Fix a bug in annotating arrows after init braces (#119958)
Fixes #59066.
2024-12-18 12:44:53 -08:00
Owen Pan
54ca1c4212
[clang-format] Fix idempotent format of hash in macro body (#118513)
Fixes #118334.
2024-12-10 16:47:21 -08:00
Owen Pan
aa2d084f9a [clang-format][NFC] Reformat testcases added in 0ff8b7916050 2024-11-23 06:31:14 -08:00
sstwcw
0ff8b79160 [clang-format] Stop crashing on slightly off Verilog module headers (#116000)
This piece of code made the program crash.

```Verilog
function pkg::t get
    (int t = 2,
     int f = 2);
```

The way the code is supposed to be parsed is that UnwrappedLineParser
should identify the function header, and then TokenAnnotator should
recognize the result.  But the code in UnwrappedLineParser would
mistakenly not recognize it due to the `::`.  Then TokenAnnotator would
recognize the comma both as TT_VerilogInstancePortComma and
TT_VerilogTypeComma.  The code for annotating the instance port comma
used `setFinalizedType`.  The program would crash when it tried to set
it to another type.

The code in UnwrappedLineParser now recognizes the `::` token.

The are other cases in which TokenAnnotator would recognize the comma as
both of those types, for example if the `function` keyword is removed.
The type is now set using `setType` instead so that the program does not
crash.  The developer no longer knows why he used `setFinalizedType`
back then.
2024-11-20 04:49:58 +00:00
Owen Pan
6ca816f88d
[clang-format] Fix a regression in parsing switch in macro call (#114506)
Fixes #114408.
2024-11-01 18:47:50 -07:00
Emilia Kond
aea60ab94d
[clang-format] Make bitwise and imply requires clause (#110942)
This patch adjusts the requires clause/expression parser to imply a
requires clause if it is preceded by a bitwise and operator `&`, and
assume it is a reference qualifier. The justification is that bitwise
operations should not be used for requires expressions.

This is a band-aid fix. The real problems lie in the lookahead heuristic
in the same method. It may be worth it to rewrite that whole heuristic
to track more state in the future, instead of just blindly marching
forward across multiple unrelated definitions, since right now, the
definition following the one with the requires clause can influence
whether the heuristic chooses clause or expression.

Fixes https://github.com/llvm/llvm-project/issues/110485
2024-10-22 13:36:28 +03:00
Owen Pan
67f576f31d
[clang-format] Handle template opener/closer in braced list (#112494)
Fixes #112487.
2024-10-17 19:56:09 -07:00
Owen Pan
ee6468494e Revert "[clang-format] Correctly annotate */& in if condition with braced init (#109505)"
This reverts commit 98281da29f7e36e22ff1e20b9cfefda8c31dbe56 which caused a
regression.

Fixes #112176.
2024-10-14 19:29:44 -07:00
Owen Pan
b5f6689dc9
[clang-format] Annotate ::operator as FunctionDeclarationName (#111115)
Fixes #111011.
2024-10-04 18:20:21 -07:00
Owen Pan
e5b05a51b8
[clang-format] Handle template closer followed by braces (#110971)
Fixes #110968.
2024-10-04 18:18:03 -07:00
Owen Pan
eaff3a7434
[clang-format] Fix a bug that misannotates binary operators */&/&& (#110945)
Fixes #110879.
2024-10-03 18:57:50 -07:00
Owen Pan
14e1fef736
[clang-format] Handle template closer followed by empty paretheses (#110408)
Fixes #109925.
2024-10-02 19:06:56 -07:00
Owen Pan
688bc958bd
[clang-format] Add TemplateNames option to help parse C++ angles (#109916)
Closes #109912.
2024-10-02 18:10:56 -07:00
Owen Pan
98281da29f
[clang-format] Correctly annotate */& in if condition with braced init (#109505)
Fixes #109371.
2024-10-02 18:07:57 -07:00
Owen Pan
6ae14c0505
[clang-format] Annotate the l_paren of function pointer types (#109229)
Fixes #109146.
2024-10-02 18:01:25 -07:00
Owen Pan
c28e268c32
[clang-format] Correctly annotate pointer/reference in if statement (#109370)
Fixes #60146.
2024-09-20 18:13:21 -07:00
Owen Pan
4fd14b9a3a
[clang-format] Correctly annotate pointer/reference in range-for loop (#109361)
Fixes #109358.
2024-09-20 18:12:09 -07:00
Owen Pan
4d18ce1dd2
[clang-format] Handle C-style cast of qualified type (#108929)
Fixes #102874.
2024-09-17 21:19:56 -07:00
kadir çetinkaya
04d71ea11b
[Format] Dont treat LBrace after extends/implements as initializer list (#108524)
This extends the fix in https://github.com/llvm/llvm-project/pull/106242
for other derived class types.
2024-09-16 20:18:39 +02:00