Commit Graph

9078 Commits

Author SHA1 Message Date
Haojian Wu
6585dd3b83 [clangd] Replace the hacky include-cleaner macro-reference implementation.
Now MainFileMacros preserves enough information, we perform a just-in-time
convertion to interop with include-cleaner::Macro for include-cleaer features.

Differential Revision: https://reviews.llvm.org/D147034
2023-06-23 14:08:55 +02:00
Haojian Wu
7298bcf7f0 [clangd] Store offsets in MacroOccurrence
Remove the existing `Rng` field.

From the review comment: https://reviews.llvm.org/D147034

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D153259
2023-06-23 09:21:08 +02:00
Haojian Wu
e339b07944 [include-cleaner] No need to overwrite the source file if there is no
cleanups
2023-06-22 14:37:11 +02:00
Piotr Zegar
3889c8214d [clang-tidy][NFC] Add missing argument comment to LexerUtils.cpp
D148697 post commit review change.
2023-06-22 09:12:40 +00:00
Elliot Goodrich
cea0eea28e [llvm] Split out DenseMapInfo<variant> specialization
Remove the `DenseMapInfo<std::variant<Ts...>>` variant out from
`llvm/ADT/DenseMapInfo.h` into a separate header
`llvm/ADT/DenseMapInfoVariant.h`

This allows us to remove the `<variant>` include, which is being
transitively and unncessary included in all translation units that
include `llvm/ADT/DenseMap.h`.

There have been similar changes to move out specializations for

    * `APInt.h` fd7e309e02 and
    * `StringRef.h`/`ArrayRef.h`
      983565a6fe

to reduce the compilation time. As we are unable to move the
specialization into `<variant>`, we create a separate
`DenseMapInfoVariant.h` header that can be used by anyone who needs this
specialization.

This reduces the total number of preprocessing tokens across the LLVM
source files in lib from (roughly) 1,964,876,961 to 1,936,551,496 - a
reduction of ~1.44%. This should result in a small improvement in
compilation time.

Differential Revision: https://reviews.llvm.org/D150997
2023-06-22 06:50:54 +01:00
Nathan Ridge
6fe9cfe413 [clangd] Use resolveTypeToRecordDecl() to resolve the type of a base specifier during heuristic resolution
The code for resolving the type of a base specifier was inside
CXXRecordDecl::lookupDependentName(), so this patch reimplements
lookupDependentName() in HeuristicResolver.

Fixes https://github.com/clangd/clangd/issues/1657

Differential Revision: https://reviews.llvm.org/D153248
2023-06-20 13:40:26 -04:00
Haojian Wu
149f309f50 [include-cleaner] Ignore the ParmVarDecl itself in WalkAST.cpp
This fixes a false positive where a ParamVarDecl happend to be the
same name of some C standard symbol and has a global namespace.

```
using A = int(int time); // we suggest <ctime> for the `int time`.
```

Differential Revision: https://reviews.llvm.org/D153330
2023-06-20 14:26:55 +02:00
Haojian Wu
ab32cc6c02 [include-cleaner] Bailout on invalid code for the command-line tool
The binary tool only works on working source code, if the source code is
not compilable, don't perform any analysis and edits.

Differential Revision: https://reviews.llvm.org/D153271
2023-06-20 09:07:27 +02:00
Felix
87a3253a39 [clang-tidy] Reserved-identifier: Improved AllowedIdentifiers option to support regular expressions
Fixes: https://github.com/llvm/llvm-project/issues/59119

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D152764
2023-06-19 07:22:20 +00:00
AMS21
82d4dc20ef [clang-tidy] Improve performance-move-const-arg message when no move constructor is available
We now display a simple note if the reason is that the used class does not
support move semantics.

This fixes llvm#62550

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D153220
2023-06-18 11:40:47 +00:00
AMS21
c96306db2c [clang-tidy] Fix llvmlibc-inline-function-decl false positives for templated function definitions
For a declaration the `FunctionDecl` begin location does not include the
template parameter lists, but for some reason if you have a separate
definitions to the declaration the begin location does include them.
With this patch we now correctly handle that case.

This fixes llvm#62746

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D153218
2023-06-18 11:40:33 +00:00
AMS21
845618cf69 [clang-tidy] Refactor common code from the Noexcept*Checks into NoexceptFunctionCheck
As discussed in the https://reviews.llvm.org/D148697 review.

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D153198
2023-06-18 06:50:05 +00:00
Nathan Ridge
7a709689bc [clangd] Handle DependentNameType in HeuristicResolver::resolveTypeToRecordDecl()
Fixes https://github.com/clangd/clangd/issues/1671

Differential Revision: https://reviews.llvm.org/D152645
2023-06-16 15:19:50 -04:00
Haojian Wu
b472176829 [clangd] Remove unused includes in IncludeCleaner.cpp, NFC 2023-06-16 15:15:07 +02:00
Viktoriia Bakalova
c9888dce44 [clangd] Skip function parameter decls when evaluating variables on hover.
Differential Revision: https://reviews.llvm.org/D153015
2023-06-16 12:09:28 +00:00
Haojian Wu
3b59842a72 [include-cleaner] Reorder SymbolReference fields to avoid padding space, NFC
This will bring down the size from 40 bytes to 32 bytes.

Differential Revision: https://reviews.llvm.org/D153018
2023-06-16 10:21:44 +02:00
Haojian Wu
eed4a4d02e [clang-tidy] Correct the include-cleaner-check diagnostic message for missing-includes.
We should print the symbol name rather than the header name in the
message.

Differential Revision: https://reviews.llvm.org/D153013
2023-06-15 15:26:48 +02:00
Jan Svoboda
1dee56aed7 [clang] NFC: Use DirectoryEntryRef in FileManager::getCanonicalName()
This patch removes the last use of deprecated `DirectoryEntry::getName()`.

Depends on D151855.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D151922
2023-06-15 11:22:31 +02:00
Piotr Zegar
cf1c6dae84 [clang-tidy][NFC] Update ReleaseNotes to mention some performance changes in checks
Included a note in the release documentation about the improved
performance of certain checks, allowing users who had previously
disabled them due to slowness to reconsider their decision.
2023-06-14 21:20:37 +00:00
AMS21
dc4359fecf [clang-tidy] Fix wrong code generation for modernize-loop-convert with structured bindings.
Fixes llvm#62951

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D152852
2023-06-14 18:57:29 +00:00
Nathan Ridge
19c9af81b1 [clangd] Unwrap type sugar in HeuristicResolver::resolveTypeToRecordDecl()
Fixes https://github.com/clangd/clangd/issues/1663

Differential Revision: https://reviews.llvm.org/D152500
2023-06-14 13:51:00 -04:00
Viktoriia Bakalova
6a6c7ed5cd [clangd] Use include_cleaner spelling strategies in clangd.
Differential Revision: https://reviews.llvm.org/D152913
2023-06-14 14:06:35 +00:00
Nemanja Ivanovic
ffd7a200fd [clang-tidy] Fix build bot break after 474a2b9367
The commmit added clang-tidy checks without adding
the required library to the link step.
Caused failures with shared library builds.
2023-06-14 06:47:34 -05:00
AMS21
474a2b9367 [clang-tidy] Add more checks for functions which should be noexcept
Added new checks
- `performance-noexcept-destructor`
- `performance-noexcept-swap`

Also added cppcoreguidlines aliases for the 2 new checks as well as `performance-noexcept-move-constructor`

This fixes llvm#62154

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D148697
2023-06-13 18:56:57 +00:00
Mike Crowe
6eb6ee3cfe [clang-tidy] Move formatDereference to FixitHintUtils
I'd like to use RedundantStringCStrCheck's formatDereference function
from the up-coming modernize-use-std-print check. Let's move it to
FixItHintUtils so that the implementation can be shared.

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D150602
2023-06-13 18:54:49 +00:00
AMS21
311091e2b0 [clang-tidy] Fix crash in modernize-use-default-member-init
This was causes by `getValueOfValueInit` unconditionally calling
`getScalarTypeKind` on the member type, which would then trigger an
assertions since arrays are not scalar type.

This fixes llvm#63285

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D152802
2023-06-13 18:13:52 +00:00
AMS21
92420f4aef [clang-tidy] Fix false positive in readability-named-parameter for defaulted out-of-line special member functions
This fixes llvm#63056

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D152825
2023-06-13 18:13:52 +00:00
Haojian Wu
48967c6e55 [include-cleaner] Don't apply the PreferredHeader hint for standard headers.
Fixes https://github.com/llvm/llvm-project/issues/62635

Differential Revision: https://reviews.llvm.org/D152801
2023-06-13 18:57:45 +02:00
Vitaly Buka
0e8384a0fe [clangd] Initialize local variable
desugarForDiagnostic only sets value to true.
2023-06-13 08:58:46 -07:00
Younan Zhang
5cdb906f1e [clangd] Unify printing policy for type hints
(This patch addresses the comment from https://reviews.llvm.org/D151785#4402460.)

Previously, we used a special printing policy that enabled `PrintCanonicalTypes`
to print type hints for structure bindings. This was intended to
eliminate type aliases like `tuple_element::type`. However, this also
caused TypePrinter to print default template arguments, which could
result in losing the ability to see types like `std::basic_string<char>`
if the fully expanded template-id exceeded the default inlay hint threshold.

Simply getting the canonical type at the call site could help us get rid of
the side effect.

This also merges overloaded `addTypeHint` into one function without
`PrintingPolicy`.

Reviewed By: nridge

Differential Revision: https://reviews.llvm.org/D152520
2023-06-13 21:31:10 +08:00
Younan Zhang
7d68f2ef41 [clangd] Desugar template parameter aliases in type hints
This patch alleviates https://github.com/clangd/clangd/issues/1298.

Containers in C++ such as `std::vector` or `llvm::SmallVector`,
introduce a series of type aliases to adapt to generic algorithms.

Currently, If we write an declarator involving expressions with
these containers and `auto` placeholder, we probably obtain opaque
type alias like following:

```
std::vector<int> v = {1, 2, 3};
auto value = v[1]; // hint for `value`: value_type
auto *ptr = &v[0]; // hint for `ptr`: value_type *
```

These hints are useless for most of the time. It would be nice if we
desugar the type of `value_type` and print `int`, `int *` respectively
in this situation. But note we can't always prefer desugared type
since user might introduce type-aliases for brevity, where printing
sugared types makes more sense.

This patch introduces a heuristic method that displays the desugared
type that is an alias of template parameter. It merges
analogous method `shouldPrintCanonicalType` into `maybeDesugar` as well.

Previous commit for shouldPrintCanonicalType: dde8a0fe91

Reviewed By: nridge

Differential Revision: https://reviews.llvm.org/D151785
2023-06-13 19:15:24 +08:00
indev
2499beeb5a [clang-tidy] run-clang-tidy: forward warnings-as-errors argument
Forward `warnings-as-errors` argument to clang-tidy.

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D152625
2023-06-12 12:24:08 +00:00
Kugan Vivekanandarajah
a8ad413f0d [RFC][clangd] Move preamble index out of document open critical path
We would like to move the preamble index out of the critical path.
This patch is an RFC to get feedback on the correct implementation and potential pitfalls to keep into consideration.

I am not entirely sure if the lazy AST initialisation would create using Preamble AST in parallel. I tried with tsan enabled clangd but it seems to work OK (at least for the cases I tried)

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D148088
2023-06-12 12:56:41 +01:00
Kadir Cetinkaya
ea20f339d9
[clangd] Enforce strict unused includes by default
Depends on D152685

Differential Revision: https://reviews.llvm.org/D152686
2023-06-12 11:47:03 +02:00
Kadir Cetinkaya
031ffc3e06
[clangd] Decouple IncludeCleaner implementation from Config
This should help managing tests as we change defaults in configs.

Differential Revision: https://reviews.llvm.org/D152685
2023-06-12 11:38:58 +02:00
Piotr Zegar
529633ccfd Revert "[clang-tidy] Move formatDereference to FixitHintUtils"
This reverts commit 636c672751.
2023-06-12 06:27:20 +00:00
Mike Crowe
636c672751 [clang-tidy] Move formatDereference to FixitHintUtils
I'd like to use RedundantStringCStrCheck's formatDereference function
from the up-coming modernize-use-std-print check. Let's move it to
FixItHintUtils so that the implementation can be shared.

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D150602
2023-06-12 06:09:17 +00:00
Piotr Zegar
4099053646 [clang-tidy][NFC] Sort changes by check name in ReleaseNotes
Sort changes listed in ClangTidy release notes by
a check name.
2023-06-12 06:07:27 +00:00
Felix
90bbe97036 [clang-tidy] Readability-container-data-pointer adds new option to ignore Containers
Adds a new option to the clang-tidy's check : readability-container-data-pointer to ignore some containers.

This option is useful in the case of std::array where the size is known at compile time and there is no real risk to access the first index of the container. In that case some users might prefer to ignore this type of container.

Relates to : https://github.com/llvm/llvm-project/issues/57445

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D133244
2023-06-12 06:07:27 +00:00
Deniz Evrenci
daac014fec [clang-tidy] Check functions called from catch blocks
These functions can rethrow a current exception that is caught by the
catch block. We can pass the currently caught excections to the function
declaration analyzer just like the statement analyzer to handle this
case.

Differential Revision: https://reviews.llvm.org/D152330
2023-06-11 16:40:29 +01:00
Piotr Zegar
8fdedcd1a2 [clang-tidy] Optimize misc-confusable-identifiers
This is final optimization for this check. Main
improvements comes from changing a logic order
in mayShadow function, to first validate result
of mayShadowImpl, then search primary context in
a vectors. Secondary improvement comes from excluding
all implicit code by using TK_IgnoreUnlessSpelledInSource.
All other changes are just cosmetic improvements.

Tested on Cataclysm-DDA open source project, result in
check execution time reduction from 3682 seconds to
100 seconds (~0.25s per TU). That's 97.2% reduction for
this change alone. Resulting in cumulative improvement for
this check around -99.6%, finally bringing this check
into a cheap category.

Reviewed By: serge-sans-paille

Differential Revision: https://reviews.llvm.org/D151594
2023-06-10 11:06:49 +00:00
Yitzhak Mandelbaum
2adf9c9f50 [clang-tidy] Fix error in documentation of bugprone-unchecked-optional-access.
The documentation claims that the check recognizes `ASSERT_THAT`, but it doesn't
recognize any googletest macros at the moment. This patch removes the reference.
2023-06-09 20:42:09 +00:00
Christian Kandeler
e72baa76b9 [clangd] Add semantic token for labels
Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D143260
2023-06-07 12:28:06 +02:00
Haojian Wu
100ffbf991 [include-cleaner] Report all specializations if the primary template is introduced by a using-decl.
This will fix unused-include false positive.

```
// primary.h
namespace ns {
template<class T1, class T2> class Z {}; // primary template
}

// partial.h
namespace ns {
template<class T> class Z<T, T*> {};     // partial specialization
}

// main.cpp

using ns::Z; // refs to the primary
void k() {
  Z<int, int*> z; // use the partial specialization
}
```

Differential Revision: https://reviews.llvm.org/D152345
2023-06-07 10:52:36 +02:00
Sam McCall
3f9f146371 [clangd] Move completion signatures and labelDetails
(When clients support it, otherwise keep the existing rendering).

In VSCode this makes the signature darker.

Differential Revision: https://reviews.llvm.org/D151253
2023-06-05 18:05:18 +02:00
SR_team
4cb5e436ae [clangd] Show size, offset and padding for bit fields on hover
Examle:
```
struct test {
	char a;
	char b : 3;
	char c : 5;
	int d;
	int e : 27;
};
```

{F27617774}
{F27617776}
{F27617777}
{F27617780}

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D151128
2023-06-05 17:52:34 +02:00
Viktoriia Bakalova
cd5fcea6d4 [clangd] Revert to older include spelling approach. 2023-06-05 15:18:28 +00:00
Philipp Stephani
f69110dcc9 Check for a ‘buffer’ type instead of ‘buffer-live’.
Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D148918
2023-06-05 15:10:31 +02:00
Haojian Wu
fc4a8bf7da [clang-tidy] Move the misc system header dir to Inputs subdir, NFC.
Follows the existing patterns, and makes life easier for bazel build
system.
2023-06-05 13:57:01 +02:00
Viktoriia Bakalova
90c5fe9822 [include-cleaner] Allow multiple strategies for spelling includes.
Summary:

Reviewers:

Subscribers:

Differential Revision: https://reviews.llvm.org/D150185
2023-06-05 09:47:12 +00:00