10640 Commits

Author SHA1 Message Date
Matheus Izvekov
1d73b2c10d
[clang] don't create type source info for vardecl created for structured bindings (#153923)
These are implicit vardecls which its type was never written in source
code. Don't create a TypeLoc and give it a fake source location.

The fake as-written type also didn't match the actual type, which after
fixing this gives some unrelated test churn on a CFG dump, since
statement printing prefers type source info if thats available.

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

This is a regression introduced in
https://github.com/llvm/llvm-project/pull/147835

This regression was never released, so no release notes are added.
2025-08-16 02:04:31 -03:00
Yanzuo Liu
3b27d50cc7
[LLVM][utils] Add script which clears release notes (#153593)
The script copies `ReleaseNotesTemplate.txt` to corresponding
`ReleaseNotes.rst`/`.md` to clear release notes.

The suffix of `ReleaseNotesTemplate.txt` must be `.txt`. If it is
`.rst`/`.md`, it will be treated as a documentation source file when
building documentation.
2025-08-15 19:00:08 +08:00
Erick Velez
4f007041a8
[clang-doc] place HTML/JSON output inside their own directories (#150655)
Instead of just outputting everything into the designated root folder,
HTML and JSON output will be placed in html/ and json/ directories.
2025-08-14 12:21:40 -07:00
Carlos Galvez
3b6d8798ba
[clang-tidy][doc] Improve documentation of the -line-filter flag (#153372)
Fixes #25589

Co-authored-by: Carlos Gálvez <carlos.galvez@zenseact.com>
2025-08-14 07:55:20 +02:00
flovent
76d2f0fe47
[clang-tidy] readability-container-size-empty: Correctly generating fix hints when size method is called from implicit this (#152486)
Correctly generating fix hints when size method is called from implicit
this.

Closes #152387.

---------

Co-authored-by: Baranov Victor <bar.victor.2002@gmail.com>
Co-authored-by: EugeneZelenko <eugene.zelenko@gmail.com>
2025-08-10 12:20:51 +03:00
Matheus Izvekov
91cdd35008
[clang] Improve nested name specifier AST representation (#147835)
This is a major change on how we represent nested name qualifications in
the AST.

* The nested name specifier itself and how it's stored is changed. The
prefixes for types are handled within the type hierarchy, which makes
canonicalization for them super cheap, no memory allocation required.
Also translating a type into nested name specifier form becomes a no-op.
An identifier is stored as a DependentNameType. The nested name
specifier gains a lightweight handle class, to be used instead of
passing around pointers, which is similar to what is implemented for
TemplateName. There is still one free bit available, and this handle can
be used within a PointerUnion and PointerIntPair, which should keep
bit-packing aficionados happy.
* The ElaboratedType node is removed, all type nodes in which it could
previously apply to can now store the elaborated keyword and name
qualifier, tail allocating when present.
* TagTypes can now point to the exact declaration found when producing
these, as opposed to the previous situation of there only existing one
TagType per entity. This increases the amount of type sugar retained,
and can have several applications, for example in tracking module
ownership, and other tools which care about source file origins, such as
IWYU. These TagTypes are lazily allocated, in order to limit the
increase in AST size.

This patch offers a great performance benefit.

It greatly improves compilation time for
[stdexec](https://github.com/NVIDIA/stdexec). For one datapoint, for
`test_on2.cpp` in that project, which is the slowest compiling test,
this patch improves `-c` compilation time by about 7.2%, with the
`-fsyntax-only` improvement being at ~12%.

This has great results on compile-time-tracker as well:

![image](https://github.com/user-attachments/assets/700dce98-2cab-4aa8-97d1-b038c0bee831)

This patch also further enables other optimziations in the future, and
will reduce the performance impact of template specialization resugaring
when that lands.

It has some other miscelaneous drive-by fixes.

About the review: Yes the patch is huge, sorry about that. Part of the
reason is that I started by the nested name specifier part, before the
ElaboratedType part, but that had a huge performance downside, as
ElaboratedType is a big performance hog. I didn't have the steam to go
back and change the patch after the fact.

There is also a lot of internal API changes, and it made sense to remove
ElaboratedType in one go, versus removing it from one type at a time, as
that would present much more churn to the users. Also, the nested name
specifier having a different API avoids missing changes related to how
prefixes work now, which could make existing code compile but not work.

How to review: The important changes are all in
`clang/include/clang/AST` and `clang/lib/AST`, with also important
changes in `clang/lib/Sema/TreeTransform.h`.

The rest and bulk of the changes are mostly consequences of the changes
in API.

PS: TagType::getDecl is renamed to `getOriginalDecl` in this patch, just
for easier to rebasing. I plan to rename it back after this lands.

Fixes #136624
Fixes https://github.com/llvm/llvm-project/issues/43179
Fixes https://github.com/llvm/llvm-project/issues/68670
Fixes https://github.com/llvm/llvm-project/issues/92757
2025-08-09 05:06:53 -03:00
Mythreya Kuricheti
fc44a4fcd3
[clangd][NFC] Improve printing of completion items in gtest failures (#152671) 2025-08-09 03:28:02 -04:00
tcottin
2c4b876fa8
[clangd] introduce doxygen parser (#150790)
Followup work of #140498 to continue the work on clangd/clangd#529

Introduce the use of the Clang doxygen parser to parse the documentation
of hovered code.

- ASTContext independent doxygen parsing
- Parsing doxygen commands to markdown for hover information

Note: after this PR I have planned another patch to rearrange the
information shown in the hover info.
This PR is just for the basic introduction of doxygen parsing for hover
information.

---------

Co-authored-by: Maksim Ivanov <emaxx@google.com>
2025-08-08 16:07:36 +02:00
Harald-R
ff0093cecd
[clangd] Use resolved path when checking AngledHeaders/QuotedHeaders in IncludeInserter (#148371)
This makes IncludeInserter's behavior consistent with include-cleaner,
as discussed in https://github.com/llvm/llvm-project/pull/140594.
2025-08-08 03:57:28 -04:00
Andrey
2d4bac8675
Reland "[clang-tidy] fix bugprone-narrowing-conversions false positive for conditional expression" (#151874)
This is another attempt to merge previously
[reverted](https://github.com/llvm/llvm-project/pull/139474#issuecomment-3148339124)
PR #139474. The added tests
`narrowing-conversions-conditional-expressions.c[pp]` failed on
[different (non x86_64)
platforms](https://github.com/llvm/llvm-project/pull/139474#issuecomment-3148334280)
because the expected warning is implementation-defined. That's why the
test must explicitly specify target (the line `// RUN: -- -target
x86_64-unknown-linux`).
2025-08-08 07:51:36 +03:00
Arthur Eubanks
266a1a819a
[clang-tools-extra][test] Fix missed %T removals from #151538 (#152345)
These tests are failing on our bots presumably due to these missing %T
replacements.
2025-08-06 11:07:09 -07:00
kadir çetinkaya
be8ef3dfbd
[include-cleaner] Respect language when tracking IWYU pragmas on stdlib headers (#152142)
In absence we were associating all the IWYU pragmas with C++ versions of stdlib headers, which would result in false negatives when querying them from a C source file.
2025-08-05 16:24:01 +02:00
Carlos Galvez
940f37aa70
[clang-tidy] Print type information to performance-unnecessary-* checks (#152101)
Useful when the check warns on template functions to know which type
it's complaining about. Otherwise, since the instantiation stack is not
printed, it's very hard to tell.

Co-authored-by: Carlos Gálvez <carlos.galvez@zenseact.com>
2025-08-05 13:11:59 +02:00
Baranov Victor
c5e6938c67
[clang-tidy][docs][NFC] Add limitation of variable lifetimes in performance-unnecessary-copy-initialization (#151862)
Addresses https://github.com/llvm/llvm-project/issues/150189.
2025-08-05 10:41:15 +03:00
Baranov Victor
0cf7377a1e
[clang-tidy][docs][NFC] Make uniform "Limitations" sections across all checks (#151863) 2025-08-05 10:40:55 +03:00
frayien
147bce7858
[clangd] textDocument/documentLink to support include statements with macro argument (#137550)
See issue https://github.com/clangd/clangd/issues/2375

The clangd textDocument/documentLink request does not support include
statements with macro argument and fails by returning an invalid range.

This PR adds support for macro argument by detecting what form of
include statement is currently being processed and returning a range
accordingly

First time contributing to LLVM, so if you have advice, questions or if
I messed up procedure please tell me !

---------

Co-authored-by: Adrien Garbani <garbani.adrien@frayien.fr>
2025-08-04 11:37:37 +02:00
Nicolas van Kempen
408fe1d369
[NFC][run-clang-tidy] Add minor type hints (#151873)
This script passes
```
python3 -m mypy --strict clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
```
2025-08-03 09:51:54 -07:00
Connector Switch
8b7f81f2de
[NFC] Fix assignment typo. (#151864) 2025-08-03 22:32:00 +08:00
tigbr
b16fe132c6
[clang-tidy] Fix bugprone-tagged-union-member-count false-positive (#135831)
This patch implements a fix for the false-positive case described in
[issue #134840](https://github.com/llvm/llvm-project/issues/134840) for
the
[bugprone-tagged-union-member-count](https://clang.llvm.org/extra/clang-tidy/checks/bugprone/tagged-union-member-count.html)
clang-tidy check.

The example given in the linked issue was the following:

```C
#include <pthread.h>

typedef enum {
  MYENUM_ONE,
  MYENUM_TWO,
} myEnumT;

typedef struct {
  pthread_mutex_t mtx;       
  myEnumT         my_enum;
} myTypeT;
```

The
[bugprone-tagged-union-member-count](https://clang.llvm.org/extra/clang-tidy/checks/bugprone/tagged-union-member-count.html)
check emits the following a warning for this struct:

```
<source>:8:9: warning: tagged union has more data members (3) than tags (2)! [bugprone-tagged-union-member-count]
    8 | typedef struct {
      |         ^
1 warning generated.
```

The issue is that `pthread_mutex_t` can be a union behind a typedef like
the following:

```C
typedef union
{
  struct __pthread_mutex_s __data;
  char __size[__SIZEOF_PTHREAD_MUTEX_T];
  long int __align;
} pthread_mutex_t;
```

From the checker's point of view therefore `myTypeT` contains a data
member with an enum type and another data member with a union type and
starts analyzing it like a user-defined tagged union.

The proposed solution is that the types from system headers and the std
namespace are no longer candidates to be the enum part or the union part
of a user-defined tagged union. This filtering for enums and the std
namespace may not be strictly necessary in this example, however I added
it preemptively out of (perhaps unnecessary) caution.

Fixes https://github.com/llvm/llvm-project/issues/134840.
2025-08-03 14:33:29 +03:00
Baranov Victor
e44a14e9ac
Revert "[clang-tidy] fix bugprone-narrowing-conversions false positive for conditional expression" (#151859)
Reverts llvm/llvm-project#139474 due to lit test failures on `arm`
platforms.
2025-08-03 13:59:58 +03:00
Andrey
c3902e46b7
[clang-tidy] fix bugprone-narrowing-conversions false positive for conditional expression (#139474)
Let's consider the following code from the issue #139467:
```c
void test(int cond, char c) {
    char ret = cond > 0 ? ':' : c;
}
```
Initializer of `ret` looks the following:
```
-ImplicitCastExpr 'char' <IntegralCast>
 `-ConditionalOperator 'int'
   |-BinaryOperator 'int' '>'
   | |-ImplicitCastExpr 'int' <LValueToRValue>
   | | `-DeclRefExpr 'int' lvalue ParmVar 'cond' 'int'
   | `-IntegerLiteral 'int' 0
   |-CharacterLiteral 'int' 58
   `-ImplicitCastExpr 'int' <IntegralCast>
     `-ImplicitCastExpr 'char' <LValueToRValue>
       `-DeclRefExpr 'char' lvalue ParmVar 'c' 'char'
```
So it could be seen that `RHS` of the conditional operator is
`DeclRefExpr 'c'` which is casted to `int` and then the whole
conditional expression is casted to 'char'. But this last conversion is
not narrowing, because `RHS` was `char` _initially_. We should just
remove the cast from `char` to `int` before the narrowing conversion
check.

Fixes #139467
2025-08-03 13:39:39 +03:00
Baranov Victor
5325f2b930
[clang-tidy][NFC] Enable 'performance-move-const-arg' in '.clang-tidy' config (#148549)
Set `performance-move-const-arg.CheckTriviallyCopyableMove` option to
`false` because "trivially copyable" is too strict and give warning for
e.g. `MixData` class:
1fbfa333f6/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp (L389)
Here:

1fbfa333f6/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp (L504-L505)
I find `std::move` here useful.
2025-08-03 13:18:24 +03:00
Baranov Victor
f72b3ec852
[clang-tidy] Add 'enable-check-profiling' with aggregated results to 'run-clang-tidy' (#151011)
Add new option `enable-check-profiling` to `run-clang-tidy` for seamless
integration of `clang-tidy`'s `enable-check-profiling` option.
`run-clang-tidy` will post aggregated results report in the same style
as `clang-tidy`.


This PR will help users to benchmark their `clang-tidy` runs easily.
Also, `clang-tidy` developers could build benchmark infrastructure in
the future.
2025-08-03 11:22:13 +03:00
Jouni
1da76b42ae
[clangd][NFC] Make some local variables HeaderSourceSwitch.cpp const and constexpr (#143193) 2025-08-03 00:23:19 -04:00
timon-ul
7de0da40c0
[clangd] Support invoking call hierarchy on enum constants (#147042)
Fixes https://github.com/clangd/clangd/issues/2203
2025-08-03 00:18:47 -04:00
Kazu Hirata
02b89b8f47
[clang-tidy] Use llvm::none_of (NFC) (#151801)
We can pass a range to llvm::none_if.
2025-08-02 08:09:41 -07:00
Carlos Galvez
0e40051565
[clang-tidy] Skip declarations in system headers in RenamerClangTidyC… (#151772)
…heck

One typically only wants to perform renaming operations in user code,
not in system headers (which are out of the user's control). Let's skip
those altogether.

This leads to performance improvements in clang-tidy. As a benchmark, I
run all checks on a .cpp file that #includes all C++ standard headers.

On trunk:

```
Suppressed 213362 warnings (213362 in non-user code).

real	0m14.422s
user	0m14.236s
sys	0m0.184s
```

On this patch:

```
Suppressed 75411 warnings (75411 in non-user code).

real	0m12.472s
user	0m12.334s
sys	0m0.136s
```

Co-authored-by: Carlos Gálvez <carlos.galvez@zenseact.com>
2025-08-02 12:20:25 +02:00
James Y Knight
4205da0f13
NFC: Clean up of IntrusiveRefCntPtr construction from raw pointers. (#151782)
This commit handles the following types:
- clang::ExternalASTSource
- clang::TargetInfo
- clang::ASTContext
- clang::SourceManager
- clang::FileManager

Part of cleanup #151026
2025-08-01 22:23:30 -04:00
Victor Chernyakin
89c1da6f78
[clang-tidy][NFC] Enable readability-avoid-return-with-void-value check in the codebase (#151356) 2025-08-01 18:28:44 +03:00
James Y Knight
c7f3437507
NFC: Clean up of IntrusiveRefCntPtr construction from raw pointers. (#151545)
Handles clang::DiagnosticsEngine and clang::DiagnosticIDs.

For DiagnosticIDs, this mostly migrates from `new DiagnosticIDs` to
convenience method `DiagnosticIDs::create()`.

Part of cleanup https://github.com/llvm/llvm-project/issues/151026
2025-07-31 15:07:35 -04:00
Aiden Grossman
5d489b82a1
[clang-tools-extra] Remove %T from lit tests (#151538)
%T has been deprecated for about seven years since it is not unique to
each test and can thus lead to races. This patch removes uses of %T from
clang-tools-extra with the eventual goal of removing support for %T from
lit.
2025-07-31 10:27:15 -07:00
Balázs Kéri
6f2cf6b0ac
[clang-tidy] Add check 'bugprone-invalid-enum-default-initialization' (#136823) 2025-07-31 09:00:34 +02:00
Mythreya Kuricheti
3466cdb769
[clang][CodeComplete] skip explicit obj param when creating signature string (#146649)
Fixes clangd/clangd#2284
2025-07-31 02:12:25 -04:00
Christian Kandeler
33e978fbfa
[clangd] Make inline friend functions appear in document symbols (#150629)
Otherwise, that definition would not show up in the document outline.
2025-07-30 10:43:32 +02:00
Austin
28c2c1e06e
[clang-tools-extra] using wrapper llvm::sort(nfc) (#150998)
using wrapper llvm::sort(nfc)
2025-07-29 09:57:02 +08:00
Jacques Pienaar
18302d02fb
[clang-tidy][mlir] Make rewrite more conservative. (#150757)
Don't create a fix where object invoked on is a temporary object as
create method requires a reference.
2025-07-28 11:18:52 -07:00
Baghirov Feyruz
f0c90dfcd8
Rename 'free' in warning messages to 'release' (#150935)
Changed the warning message:

- **From**: 'Attempt to free released memory'
   **To**: 'Attempt to release already released memory'
- **From**: 'Attempt to free non-owned memory'
   **To**: 'Attempt to release non-owned memory'
- **From**: 'Use of memory after it is freed' 
   **To**: 'Use of memory after it is released'

All connected tests and their expectations have been changed
accordingly.

Inspired by [this
PR](https://github.com/llvm/llvm-project/pull/147542#discussion_r2195197922)
2025-07-28 18:02:56 +02:00
Juan Besa
4d259de2ae
[clang-tidy] Add IgnoreAliasing option to readability-qualified-auto check (#147060)
`readability-qualified-auto` check currently looks at the unsugared
type, skipping any typedefs, to determine if the variable is a
pointer-type. This may not be the desired behaviour, in particular when
the type depends on compilation flags.
For example

```
 #if CONDITION
      using Handler = int *;
  #else
      using Handler = uint64_t;
  #endif
```

A more common example is some implementations of `std::array` use
pointers as iterators.

This introduces the IgnoreAliasing option so that
`readability-qualified-auto` does not look beyond typedefs.

---------

Co-authored-by: juanbesa <juanbesa@devvm33299.lla0.facebook.com>
Co-authored-by: Kazu Hirata <kazu@google.com>
Co-authored-by: EugeneZelenko <eugene.zelenko@gmail.com>
Co-authored-by: Baranov Victor <bar.victor.2002@gmail.com>
2025-07-28 18:20:02 +03:00
Marco Maia
4072a6b85b
Reland "[clangd] Add tweak to override pure virtuals" (#150788)
This relands commit
7355ea3f6b.

The original commit was reverted in
bfd73a5161
because it was breaking the buildbot.

The issue has now been resolved by
38f82534bb.

Original PR: https://github.com/llvm/llvm-project/pull/139348
Original commit message:
<blockquote>

closes https://github.com/clangd/clangd/issues/1037 
closes https://github.com/clangd/clangd/issues/2240

Example:

```c++
class Base {
public:
  virtual void publicMethod() = 0;

protected:
  virtual auto privateMethod() const -> int = 0;
};

// Before:
//                        // cursor here
class Derived : public Base{}^ ;

// After:
class Derived : public Base {
public:
  void publicMethod() override {
    // TODO: Implement this pure virtual method.
    static_assert(false, "Method `publicMethod` is not implemented.");
  }

protected:
  auto privateMethod() const -> int override {
    // TODO: Implement this pure virtual method.
    static_assert(false, "Method `privateMethod` is not implemented.");
  }
};
```


https://github.com/user-attachments/assets/79de40d9-1004-4c2e-8f5c-be1fb074c6de

</blockquote>
2025-07-28 09:31:12 +02:00
Danny Mösch
0afb30311d
[clang-tidy] Add handling of type aliases in use-designated-initializers check (#150842)
Resolves #150782.
2025-07-28 07:37:16 +02:00
Congcong Cai
59fdd97fe6 [clang-tidy][NFC] typo in UseUsingCheck 2025-07-27 10:11:06 +08:00
Michał Górny
fa79c23ecc
[clang-tidy] Fix linking regression in clangTidyLLVMModule (#150769)
Fix the regression introduced in #149148 that incorrectly explicitly
linked `clangTransformer` when dylib was used. As a result, the
executables linking to `clangTidyLLVMModule` would end up linking both
the dylib and a number of static clang libraries, leading to complete
mayhem and undecipherable segmentation faults.

Signed-off-by: Michał Górny <mgorny@gentoo.org>
2025-07-26 17:22:18 +02:00
Erick Velez
4df8f72608
[clang-doc] add code comments to comment template (#150648)
Serializes Doxygen code comments in HTML templates. Modifies the
basic-project to add a code example.
2025-07-25 13:10:15 -07:00
Erick Velez
63c2b8a5b3
[clang-doc] add return comments to comment template (#150647)
Serialize return comments in HTML templates.
2025-07-25 12:32:04 -07:00
Erick Velez
8059482051
[clang-doc] add param comments to comment template (#150571)
Serializes parameter comments for all descriptions.
We do not support Doxygen's parameter checking, which warns if a documented parameter is not actually present.
2025-07-25 11:16:04 -07:00
Erick Velez
237a485c81
[clang-doc] generate comments for functions (#150570)
Change the function partial to enable comments to be generated for
functions. This only enables the brief comments in the basic project.
2025-07-25 10:40:48 -07:00
Erick Velez
2ca8cf922f
[clang-doc] remove nesting of text comments inside paragraphs (#150451)
Text comments were unnecessarily nested inside Paragraph comments as a
Children array. If they're at the top level, we can also avoid more
nesting in templates.
2025-07-24 19:49:54 -07:00
Erick Velez
78a4634ef0
[clang-doc] enable comments in class templates (#149848)
The Mustache basic project has comments in its headers but the comments were not
serialized. Now we serialize \brief and paragraph comments for classes
and add that output to the basic project test.
2025-07-24 19:16:28 -07:00
Erick Velez
f361dd7400
[clang-doc] separate comments into categories (#149590)
Comment categories will allow better comment organization in HTML.
Before, comments would just be serialized in whatever order they were
written, so groups like params or notes wouldn't be in the same
sections.
2025-07-24 18:35:58 -07:00
tcottin
51994891e3
[clangd] Improve Markup Rendering (#140498)
This is a preparation for fixing clangd/clangd#529.

It changes the Markup rendering to markdown and plaintext.

- Properly separate paragraphs using an empty line between
- Dont escape markdown syntax for markdown output except for HTML
- Dont do any formatting for markdown because the client is handling the
actual markdown rendering
2025-07-25 02:45:56 +02:00