Commit Graph

8310 Commits

Author SHA1 Message Date
Kazu Hirata 3850edd9e0 Use llvm::count_if (NFC) 2022-09-03 11:17:35 -07:00
Alexander Shaposhnikov a7395b860b [clang-tidy] Skip copy assignment operators with nonstandard return types
Skip copy assignment operators with nonstandard return types
since they cannot be defaulted.

Test plan: ninja check-clang-tools

Differential revision: https://reviews.llvm.org/D133006
2022-09-02 22:43:39 +00:00
Alexander Shaposhnikov 47dbacbc8a [clang-tidy] Restrict use-equals-default to c++11-or-later
Restrict use-equals-default to c++11-or-later.

Test plan: ninja check-all

Differential revision: https://reviews.llvm.org/D132998
2022-09-02 22:19:11 +00:00
Chris Bieneman 5b5329bd41 [NFC] Make MultiplexExternalSemaSource own sources
This change refactors the MuiltiplexExternalSemaSource to take ownership
of the underlying sources. As a result it makes a larger cleanup of
external source ownership in Sema and the ChainedIncludesSource.

Reviewed By: aaron.ballman, aprantl

Differential Revision: https://reviews.llvm.org/D133158
2022-09-02 13:57:39 -05:00
Aleksandr Platonov cc4b86cfc0 [clangd] Fix tests for implicit C function declaration
clangd code fixes at D122983 were not right.
We need to check that clangd provides IncludeFixer fixits for implicit function declaration even if this is not an error (e.g. implicit function declaration in C89).

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D133043
2022-09-01 23:46:20 +03:00
Nathan James cc09b81265
[CTE][docs] Fix bad links in ReleaseNotes 2022-09-01 12:10:53 +01:00
corona10 495d984e14
[clang-tidy] Fix modernize-use-emplace to support alias cases
Fix modernize-use-emplace to support alias cases

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D132640
2022-08-31 10:21:10 +01:00
isuckatcs cd40245f54 [clang-tidy] Fix false positive on ArrayInitIndexExpr inside ProBoundsConstantArrayIndexCheck
Sometimes in the AST we can have an ArraySubscriptExpr,
where the index is an ArrayInitIndexExpr.
ArrayInitIndexExpr is not a constant, so
ProBoundsConstantArrayIndexCheck reports a warning when
it sees such expression. This expression can only be
implicitly generated, and always appears inside an
ArrayInitLoopExpr, so we shouldn't report a warning.

Differential Revision: https://reviews.llvm.org/D132654
2022-08-30 20:27:38 +02:00
Utkarsh Saxena c338735020 [clangd] Enable folding ranges by default.
Differential Revision: https://reviews.llvm.org/D132919
2022-08-30 12:04:59 +02:00
ziqingluo-90 7df0f0b410 [clang-tidy] Fixing a bug in `InfiniteLoopCheck` that raises false alarms on finite loops
A loop can recursively increase/decrease a function local static
variable and make itself finite.  For example,

```
void f() {
  static int i = 0;
  i++;
  while (i < 10)
     f();
}

```

Such cases are not considered by `InfiniteLoopCheck`.  This commit
fixes this problem by detecting usages of static local variables
and recursions.

Reviewed by: NoQ, njames93
Differential Revision: https://reviews.llvm.org/D128401
2022-08-29 11:18:44 -07:00
Utkarsh Saxena a11ec00afe FoldingRanges: Handle LineFoldingsOnly clients.
Do not fold the endline which contains tokens after the end of range.

Differential Revision: https://reviews.llvm.org/D131154
2022-08-29 19:03:48 +02:00
Nathan Ridge 9af0a142e4 [clangd] Fail more gracefully if QueryDriverDatabase cannot determine file type
Currently, QueryDriverDatabase returns an empty compile command
if it could not determine the file type.

This failure mode is unnecessarily destructive; it's better to
just return the incoming compiler command, which is still more
likely to be useful than an empty command.

Differential Revision: https://reviews.llvm.org/D132833
2022-08-29 12:59:05 -04:00
Jonas Toth b5b7503463 [docs] improve documentation for misc-const-correctness
Improve the documentation for 'misc-const-correctness' to:

- include better examples
- improve the english
- fix links to other checks that were broken due to the directory-layout changes
- mention the limitation that the check does not run on `C` code.

Addresses #56749, #56958

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D132244
2022-08-29 11:20:47 +02:00
Kazu Hirata 20f0f15a40 Use StringRef::contains (NFC) 2022-08-28 23:29:02 -07:00
Kazu Hirata 33b9304435 Use llvm::is_contained (NFC) 2022-08-27 21:21:00 -07:00
Nathan James 32d88239ae
[clang-tidy] Tweak diagnostics for bugprone-assign-in-if-condition
Currently the diagnostic is printed at the start of the assignment expression, This can be misleading.
Having the location for the diagnostic be the location of the assignment operator is much more intuitive.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D132795
2022-08-28 00:21:40 +01:00
Nathan James 2a0870c9d3
[clang-tidy] Add missing header from 6bd98b4f2d 2022-08-27 19:59:16 +01:00
Nathan James 6bd98b4f2d
[clang-tidy] Fix a false positive in bugprone-assignment-in-if-condition
Fixed a false positive where a lambda expression in the condition which contained an assignement would trigger a warning.
Fixes #56729

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D132786
2022-08-27 19:55:08 +01:00
Nathan James 69c20a1f49
[clang-tidy] Move bugprone-assignment-in-if-condition check to correct folder 2022-08-27 11:24:57 +01:00
ziqingluo-90 9343ec861a [clang-tidy] Adding the missing handling of "noreturn" attributes for Obj-C nodes in `InfiniteLoopChecker`
With this commit, the `InfiniteLoopChecker` now recognizes message
expressions to "noreturn" methods as well as calls to "noreturn"
blocks.

Reviewed by NoQ, njames93
Differential Revision: https://reviews.llvm.org/D128314
2022-08-26 12:44:59 -07:00
Sam McCall 56c54cf66b [pseudo] Placeholder disambiguation strategy: always choose second
Mostly mechanics here. Interesting decisions:
 - apply disambiguation in-place instead of copying the forest
   debatable, but even the final tree size is significant
 - split decide/apply into different functions - this allows the hard part
   (decide) to be tested non-destructively and combined with HTML forest easily
 - add non-const accessors to forest to enable apply
 - unit tests but no lit tests: my plan is to test actual C++ disambiguation
   heuristics with lit, generic disambiguation mechanics without the C++ grammar

Differential Revision: https://reviews.llvm.org/D132487
2022-08-26 13:16:09 +02:00
Sockke 2d8e91a5d3 [clang-tidy] Ignore other members in a union if any member of it is initialized in cppcoreguidelines-pro-type-member-init
If a union member is initialized, the other members of the union are still suggested to be initialized in this check.  This patch fixes this behavior.
Reference issue: https://github.com/llvm/llvm-project/issues/54748

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D127293
2022-08-25 18:47:38 +08:00
Balázs Kéri ab9ee471df [clang-tidy] Add test to cert-dcl58-cpp (NFC).
Add a test to cert-dcl58-cpp.cpp to verify that crash in github
issue #56902 does not happen.

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D131686
2022-08-25 10:11:40 +02:00
Alexander Shaposhnikov 083e3a173d [clang-tidy] Skip unions in use-equals-default
For unions constructors with empty bodies behave differently
(in comparison with structs/classes) and clang-tidy's fix
might break the code. This diff adjusts the check to skip unions
for now (it seems to be a relatively rare case).

Test plan: ninja check-all

Differential revision: https://reviews.llvm.org/D132290
2022-08-23 20:09:47 +00:00
Kadir Cetinkaya 552b59b9e6
[clangd] Bump timeout for a flaky test
This has been failing on some build bots with timeout, increasing it to
5 seconds.
2022-08-23 18:18:17 +02:00
Haojian Wu f7dc91ad56 [pseudo] Eliminate a false parse of structured binding declaration.
Using the guard to implement part of the rule https://eel.is/c++draft/dcl.pre#6.

```
void foo() {
  // can be parsed as
  //   - structured-binding declaration (a false parse)
  //   - assignment expression
  array[index] = value;
}
```

Differential Revision: https://reviews.llvm.org/D132260
2022-08-23 15:25:52 +02:00
Haojian Wu edb8fb2659 [pseudo] Fix HeadsPartition is not initialized correctly.
The bug was that if we recover from the token 0, we will make the
Heads empty (Line646), which results no recovery being applied.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D132388
2022-08-23 15:08:33 +02:00
Kadir Cetinkaya 3c2cb8e2f0
[clangd] Disable IncludeCleaner for ObjC 2022-08-22 11:28:06 +02:00
Kazu Hirata 8b1b0d1d81 Revert "Use std::is_same_v instead of std::is_same (NFC)"
This reverts commit c5da37e42d.

This patch seems to break builds with some versions of MSVC.
2022-08-20 23:00:39 -07:00
Kazu Hirata c5da37e42d Use std::is_same_v instead of std::is_same (NFC) 2022-08-20 22:36:26 -07:00
Kazu Hirata 8e494b85a5 Use llvm::drop_begin (NFC) 2022-08-20 21:18:30 -07:00
Kazu Hirata 258531b7ac Remove redundant initialization of Optional (NFC) 2022-08-20 21:18:28 -07:00
eahcmrh 9e1a4ce0b5 [clang-tidy] Fix for bugprone-sizeof-expression PR57167
This addresses a change in behavior of the bugprone-sizeof-expression
checker after upstream commit 15f3cd6bfc, which cleaned up
ElaboratedType sugaring in the AST.  This restores (mostly) the
beahvior of the checker prior to that commit, which may or may not have
been consistent with the intent of the checker, but at least gave a
tolerable level of what users would consider false positives.

Bug: https://github.com/llvm/llvm-project/issues/57167

Reviewed By: mizvekov, aaron.ballman

Differential Revision: https://reviews.llvm.org/D131926

Change-Id: Ibe5aad77ad00977134aa7fa67efbbd6bd725fd79
2022-08-19 23:29:32 +02:00
Denis Fatkulin ee648c0ce0 [clang][index] Index unresolved member expression as reference
Unresolved member expressions aren't indexed as references.

Example code:

```
struct Foo {
  template <typename T> void bar(T t);
};
template <typename T> void test(Foo F, T t) {
  F.bar(t); // Not indexed
}
```

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D131091
2022-08-19 19:02:42 +03:00
Sam McCall bd5cc6575b [pseudo] Start rules are `_ := start-symbol EOF`, improve recovery.
Previously we were calling glrRecover() ad-hoc at the end of input.
Two main problems with this:
 - glrRecover() on two separate code paths is inelegant
 - We may have to recover several times in succession (e.g. to exit from
   nested scopes), so we need a loop at end-of-file
Having an actual shift action for an EOF terminal allows us to handle
both concerns in the main shift/recover/reduce loop.

This revealed a recovery design bug where recovery could enter a loop by
repeatedly choosing the same parent to identically recover from.
Addressed this by allowing each node to be used as a recovery base once.

Differential Revision: https://reviews.llvm.org/D130550
2022-08-19 16:49:37 +02:00
Haojian Wu e32799d1d6 [pseudo] NFC, remove redundant ; 2022-08-19 15:55:19 +02:00
Sam McCall ac31781759 [Sema] Tweak diagnostic logic so suppress-in-header logic works in tools too.
Certain idioms are ignored by -Wunused in header files only.
The current "is a header" check assumes that if headers are the main file, we're
building a PCH or a module or something. However in tools we may be parsing the
header in its own right, but still want to treat it as a header.

Fixes https://github.com/clangd/vscode-clangd/issues/360

Differential Revision: https://reviews.llvm.org/D129642
2022-08-19 15:16:10 +02:00
Sam McCall 605035bf45 [pseudo] Changes omitted from previous commit 2022-08-19 15:15:37 +02:00
Sam McCall 2cc7463c85 [pseudo] Perform unconstrained reduction prior to recovery.
Our GLR uses lookahead: only perform reductions that might be consumed by the
shift immediately following. However when shift fails and so reduce is followed
by recovery instead, this restriction is incorrect and leads to missing heads.

In turn this means certain recovery strategies can't be made to work. e.g.
```
ns := NAMESPACE { namespace-body } [recover=Skip]
ns-body := namespace_opt
```
When `namespace { namespace {` is parsed, we can recover the inner `ns` (using
the `Skip` strategy to ignore the missing `}`). However this `namespace` will
not be reduced to a `namespace-body` as EOF is not in the follow-set, and so we
are unable to recover the outer `ns`.

This patch fixes this by tracking which heads were produced by constrained
reduce, and discarding and rebuilding them before performing recovery.

This is a prerequisite for the `Skip` strategy mentioned above, though there are
some other limitations we need to address too.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D130523
2022-08-19 15:07:36 +02:00
Sam McCall 13b2a0c69b [clangd] Support hover on __func__ etc (PredefinedExpr)
Expose these as variables as that's what the standard calls them (and D131175).

To make this work, we also fix a bug in SelectionTree: PredefinedExpr has
an implicit/invisible StringLiteral, and SelectionTree should not traverse
implicit things.

Reviewed By: ckandeler

Differential Revision: https://reviews.llvm.org/D132135
2022-08-19 14:51:46 +02:00
Carlos Galvez 3fd4213059 [clang-tidy] Do not trigger cppcoreguidelines-avoid-const-or-ref-data-members on lambda captures
Lambdas are implemented as regular classes internally,
and the captured variables end up as members there.
Do not diagnose those - the check should cover only
regular classes and structs.

Differential Revision: https://reviews.llvm.org/D131780
2022-08-19 08:26:34 +00:00
Joey Watts b8655f7ff2
[clang-tidy] Improve modernize-use-emplace check
This patch improves the modernize-use-emplace check by adding support for
detecting inefficient invocations of the `push` and `push_front` methods on
STL-style containers and replacing them with their `emplace`-style equivalent.

Fixes #56996.

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D131623
2022-08-19 07:57:42 +01:00
Kadir Cetinkaya 7f2a079a12
[clangd] Fix a tsan failure in PreambleThrottle tests 2022-08-18 18:36:01 +02:00
Christian Kandeler 1c056f8df2 [clangd] Use the "macro" semantic token for pre-defined identifiers
This matches user expectations.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D131175
2022-08-18 16:12:55 +02:00
Martin Storsjö 9ad0ace2ba [clang-tidy] Rename a local cmake variables to match the new tool name. NFC.
This shouldn't have any externally visible effect.

This matches the new name from 18b4a8bcf3.

Differential Revision: https://reviews.llvm.org/D130701
2022-08-18 14:27:45 +03:00
Vladimir Plyashkun fa8f861602
[clang-tidy] hicpp-signed-bitwise - Return location of the operand (and not of the operator beginning)
Currently, the "hicpp/signed-bitwise" check returns the beginning of the binary/unary operator as location, which sometimes confuses users in the IDE due to incorrect [[ https://youtrack.jetbrains.com/issue/CPP-12445/Clang-Tidy-highlighting-for-binary-operators-applied-to-wrong-operand | highlighting ]].
Yes, the offset from Ranges can be used for this particular check, but i suppose better solution is to return begin location of the problematic operand instead of operator.

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D131678
2022-08-17 19:25:59 +01:00
Haojian Wu 6a9f79e102 [pseudo] Eliminate the type-name identifier ambiguities in the grammar.
See https://reviews.llvm.org/D130626 for motivation.

Identifier in the grammar has different categories (type-name, template-name,
namespace-name), they requires semantic information to resolve. This patch is
to eliminate the "local" ambiguities in type-name, and namespace-name, which
gives us a performance boost of the parser:

  - eliminate all different type rules (class-name, enum-name, typedef-name), and
    fold them into a unified type-name, this removes the #1 type-name ambiguity, and
    gives us a big performance boost;
  - remove the namespace-alis rules, as they're hard and uninteresting;

Note that we could eliminate more and gain more performance (like fold template-name,
type-name, namespace together), but at current stage, we'd like keep all existing
categories of the identifier (as they might assist in correlated disambiguation &
keep the representation of important concepts uniform).

| file               |ambiguous nodes |  forest size     | glrParse performance |
|SemaCodeComplete.cpp|  11k -> 5.7K   | 10.4MB -> 7.9MB  | 7.1MB/s -> 9.98MB/s  |
|       AST.cpp      |  1.3k -> 0.73K | 0.99MB -> 0.77MB | 6.7MB/s -> 8.4MB/s   |

Differential Revision: https://reviews.llvm.org/D130747
2022-08-17 14:30:53 +02:00
Kadir Cetinkaya 83411bf06f
[clangd] Support for standard type hierarchy
This is mostly a mechanical change to adapt standard type hierarchy
support proposed in LSP 3.17 on top of clangd's existing extension support.

This does mainly two things:
- Incorporate symbolids for all the parents inside resolution parameters, so
  that they can be retrieved from index later on. This is a new code path, as
  extension always resolved them eagerly.
- Propogate parent information when resolving children, so that at least one
  branch of parents is always preserved. This is to address a shortcoming in the
  extension.

This doesn't drop support for the extension, but it's deprecated from now on and
will be deleted in upcoming releases. Currently we use the same struct
internally but don't serialize extra fields.

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

Differential Revision: https://reviews.llvm.org/D131385
2022-08-17 09:29:15 +02:00
Sam McCall 0b90e136ee [pseudo] Style tweaks forgotten in D130337. NFC 2022-08-16 10:26:25 +02:00
Kazu Hirata f5a68feab3 Use llvm::none_of (NFC) 2022-08-14 16:25:39 -07:00