Commit Graph

7111 Commits

Author SHA1 Message Date
Haojian Wu 573348ab9b [clangd] Retire the cross-file-rename command-line flag.
This patch only focuses on the flag. Removing actual single-file mode
(and the flag in RenameOption) will come in a follow-up.

Differential Revision: https://reviews.llvm.org/D96495
2021-02-11 20:28:50 +01:00
Alex Hoppen 7e3b9aba60 [Timer] On macOS count number of executed instructions
In addition to wall time etc. this should allow us to get less noisy
values for time measurements.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D96049
2021-02-11 17:26:37 +01:00
Haojian Wu 6c47eafb39 [clang][index] report references from unreslovedLookupExpr.
Fix https://github.com/clangd/clangd/issues/675

Differential Revision: https://reviews.llvm.org/D96262
2021-02-11 11:08:26 +01:00
Sam McCall 5c55d3747b [CodeComplete] Member completion: heuristically resolve some dependent base exprs
Today, inside a template, you can get completion for:

Foo<T> t;
t.^

t has dependent type Foo<T>, and we use the primary template to find its members.
However we also want this to work:

t.foo.bar().^

The type of t.foo.bar() is DependentTy, so we attempt to resolve using similar
heuristics (e.g. primary template).

Differential Revision: https://reviews.llvm.org/D96376
2021-02-11 11:03:40 +01:00
Sam McCall bda5e57742 [clangd] Remove redundant -fno-delayed-template-parsing in tests. NFCI
We now (since a while) turn this off centrally in ParsedAST and CodeComplete.
2021-02-10 22:20:23 +01:00
Sam McCall 4dc8365f80 [clangd] Remove support for pre-standard semanticHighlighting notification
This is obsoleted by the standard semanticTokens request family.
As well as the protocol details, this allows us to remove a bunch of plumbing
around pushing highlights to clients.

This should not land until the new protocol has feature parity, see D77702.

Differential Revision: https://reviews.llvm.org/D95576
2021-02-10 22:09:03 +01:00
Sam McCall 59c1139d3e [clangd] Expose more dependent-name detail via semanticTokens
This change makes dependentName a modifier, rather than a token type.
It can be combined with:
- type (new, standard) - this combination replaces dependentType like T::typename Foo
- unknown (new, nonstandard) - for general dependent names
- Field, etc - when the name is dependent but we heuristically resolve it

While here, fix cases where template-template-parameter cases were
incorrectly flagged as type-dependent.
And the merging of modifiers when resolving conflicts accidentally
happens to work around a bug that showed up in a test.

The behavior observed through the pre-standard protocol should be mostly
unchanged (it'll see the bugfixes only). This is done in a somehat
fragile way but it's not expected to live long.

Differential Revision: https://reviews.llvm.org/D95706
2021-02-09 20:40:59 +01:00
Sam McCall 46cc7ce35a [clangd] Add semanticTokens modifiers for function/class/file/global scope
These allow (function-) local variables to be distinguished, but also a
bunch more cases.
It's not quite independent with existing information (e.g. the
field/variable distinction is redundant if you have class-scope + static
attributes) but I don't think this is terribly important.

Depends on D77811

Differential Revision: https://reviews.llvm.org/D95701
2021-02-09 17:57:36 +01:00
Sam McCall dd8fb21227 [clangd] Implement semanticTokens modifiers
- Infrastructure to support modifiers (protocol etc)
- standard modifiers:
  - declaration (but no definition, yet)
  - deprecated
  - readonly (based on a fairly fuzzy const checking)
  - static (for class members and locals, but *not* file-scope things!)
  - abstract (for C++ classes, and pure-virtual methods)
- nonstandard modifier:
  - deduced (on "auto" whose Kind is Class etc)
    Happy to drop this if it's controversial at all.
- While here, update sample tweak to use our internal names, in
  anticipation of theia TM scopes going away.

This addresses some of the goals of D77702, but leaves some things undone.
Mostly because I think these will want some discussion.
 - no split between dependent type/name.
   (We may want to model this as a modifier, type+dependent vs ???+dependent)
 - no split between primitive/typedef.
   (Is introducing a nonstandard kind is worth this distinction?)
 - no nonstandard local attribute
   This probably makes sense, I'm wondering if we want others and how
   they fit together.

There's one minor regression in explicit template specialization declarations
due to a latent bug in findExplicitReferences, but fixing it after seems OK.

Differential Revision: https://reviews.llvm.org/D77811
2021-02-09 16:31:22 +01:00
poelmanc 98146c1f5d
[clang-tidy] fix modernize-use-nullptr false positive with spaceship operator comparisons
`clang-tidy -std=c++20` with `modernize-use-nullptr` mistakenly inserts `nullptr` in place of the comparison operator if the comparison internally expands in the AST to a rewritten spaceship operator. This can be reproduced by running the new `modernize-use-nullptr-cxx20.cpp` test without applying the supplied patch to `UseNullptrCheck.cpp`; the current clang-tidy will mistakenly replace:
```result = (a1 < a2);```
with
```result = (a1 nullptr a2);```

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D95714
2021-02-09 14:02:45 +00:00
Kirill Bobyrev b60428c7ea [clangd] Fix false positive in local rename collision detetction
Fixes https://github.com/clangd/clangd/issues/685

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D96247
2021-02-09 11:51:18 +01:00
poelmanc 5229edd667
[clang-tidy] fix modernize-loop-convert to retain needed array-like operator[]
`modernize-loop-convert` handles //array-like// objects like vectors fairly well, but strips slightly too much information from the iteration expression by converting:
```
  Vector<Vector<int>> X;
  for (int J = 0; J < X[5].size(); ++J)
    copyArg(X[5][J]);
```
to
```
  Vector<Vector<int>> X;
  for (int J : X) // should be for (int J : X[5])
    copyArg(J);
```
The `[5]` is a call to `operator[]` and gets stripped by `LoopConvertCheck::getContainerString`. This patch fixes that and adds several test cases.

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D95771
2021-02-07 16:36:34 +00:00
Sam McCall fed995ef90 [clangd] Trace queue state for each TUScheduler action.
The new trace event includes what's already in the queue when adding.
For tracers that follow contexts, the trace event will span the time that the action
spends in the queue.
For tracers that follow threads, the trace will be a tiny span on the enqueuing thread.

Differential Revision: https://reviews.llvm.org/D96027
2021-02-05 17:56:51 +01:00
Stephen Kelly 2cba22c23a [clang-tidy] Simplify implementation of container-size-empty
Use IgnoreUnlessSpelledInSource to make the matcher code smaller and
more visibly-related to the code.

Differential Revision: https://reviews.llvm.org/D91303
2021-02-05 14:03:41 +00:00
Kadir Cetinkaya d1978fa4bf
[clangd] Deduplicate scopes in IncludeFixer queries
Differential Revision: https://reviews.llvm.org/D95942
2021-02-05 14:02:50 +01:00
Simon Pilgrim edc8f0b407 TypeMismatchCheck.cpp - fix Wdocumentation warning. NFCI. 2021-02-05 10:57:39 +00:00
Aleksandr Platonov 91698fe45f [clangd] Take into account what is in the index (symbols, references, etc.) at indexes merge
Current indexes merge logic skip data from the static index if the file is in the dynamic index, but sometimes the dynamic index does not contain references (e.g. preamble (dynamic) index vs background (static) index).
This problem is masked with the fact, that the preamble index file list consists of file URI's and other indexes file lists consist of file paths.
This patch introduces the index contents (symbols, references, etc.), which makes indexes merge more flexible and makes it able to use URI's for the index file list.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D94952
2021-02-05 13:35:07 +03:00
Kirill Bobyrev e8a2b7c915 [clangd] Improve name conflict detection
Follow-up on D95925: adds better detection for function arguments and also
checks for conflicts in muli-variable init statements in ForStmt.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D96009
2021-02-04 21:37:41 +01:00
Kirill Bobyrev 5eec9a380a
[clangd] Detect rename conflicits within enclosing scope
This patch allows detecting conflicts with variables defined in the current
CompoundStmt or If/While/For variable init statements.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D95925
2021-02-04 09:45:42 +01:00
Stephen Kelly c0199b2a21 [clang-tidy] Use new mapping matchers
Use mapAnyOf() and matchers based on it.

Use of binaryOperation() means that modernize-loop-convert and
readability-container-size-empty can now be used with rewritten binary
operators.

Differential Revision: https://reviews.llvm.org/D94131
2021-02-03 23:21:17 +00:00
Utkarsh Saxena 54afcade3b
[clangd] Report xref for base methods.
See: https://github.com/clangd/clangd/issues/668

```
struct A { virtual void foo() = 0; };
struct B : A { void foo() override; };
```

Find refs on `B::foo()` will show:
- decls of `A::foo()` (new)
- decls of `B::foo()`
- refs to `A::foo()` (new)
- refs to `B::foo()`.

Differential Revision: https://reviews.llvm.org/D95852
2021-02-03 12:07:43 +01:00
Sam McCall 08274d7d5d [clang-include-fixer] Pre-reserve vector size. NFC 2021-02-03 08:30:45 +01:00
Nathan James 4454a9cd77 [NFC] Fix typo in comment 2021-02-03 05:18:07 +00:00
Nathan James c97592c5df [clang-tidy] Fix crash in readability-identifier-naming check
`isParamInMainLikeFunction` didn't check if the function had an identifer name before calling getName() which could lead to an assert.
2021-02-03 05:11:56 +00:00
Sam McCall 6ac3fd9706 [clangd] Fix race in Global CDB shutdown
I believe the atomic write can be reordered after the notify, and that
seems to be happening on mac m1: http://45.33.8.238/macm1/2654/step_8.txt
In practice maybe seq_cst is enough? But no reason not to lock here.

https://bugs.llvm.org/show_bug.cgi?id=48998
2021-02-02 15:24:14 +01:00
Utkarsh Saxena fbeff2ec2b
[clangd] Report only decl of overridding method in xref.
See: https://github.com/clangd/clangd/issues/668

```
struct A { virtual void foo() = 0; };
struct B : A { void foo() override; };
```

Find refs on `A::foo()` will show:
- decls of `A::foo()`
- decls of `B::foo()`
- refs to `A::foo()`
- no refs to `B::foo()`.

Differential Revision: https://reviews.llvm.org/D95812
2021-02-02 13:06:20 +01:00
Fangrui Song af6be9a7bb [test] Fix unused FileCheck prefixes in clang-tidy and one llvm/test/Reduce test 2021-02-01 22:51:29 -08:00
Conrad Poelman 0b70c86e20
clang-extra: fix incorrect use of std::lock_guard by adding variable name (identified by MSVC [[nodiscard]] error)
`std::lock_guard` is an RAII class that needs a variable name whose scope determines the guard's lifetime. This particular usage lacked a variable name, meaning the guard could be destroyed before the line that it was indented to protect.

This line was identified by building clang with the latest MSVC preview release, which declares the std::lock_guard constructor to be `[[nodiscard]]` to draw attention to such issues.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D95725
2021-02-02 06:02:59 +01:00
Sam McCall 1eb7fd089e [clangd] Remove some obsolete options that are now always on
- always collect main-file refs when indexing
 - always build preambles asynchronously
 - always use dex for fast preamble index

Retire associated flags

Differential Revision: https://reviews.llvm.org/D95571
2021-02-01 17:24:03 +01:00
Sam McCall 8712df7a62 [clangd] references: decls of overrides of x are refs to x, not decls
This requires a second index query for refs to overrides, as the refs
call doesn't tell you which ref points at which symbol.

Differential Revision: https://reviews.llvm.org/D95451
2021-02-01 17:19:19 +01:00
Sam McCall ff4832dbff [clangd] Respect ReferencesParams.context.includeDeclarations
Unfortunately this treats overrides declarations as declarations, not as
references. I don't plan to land this until I have a fix for that issue.

Differential Revision: https://reviews.llvm.org/D95450
2021-02-01 17:07:02 +01:00
Haojian Wu 78c22fbce9 [clangd] Don't rely on builtin headers for document-link.test.
This test seems to be failing at HEAD.

Reviewed By: kadircet, sammccall

Differential Revision: https://reviews.llvm.org/D95670
2021-02-01 15:36:34 +01:00
Sam McCall b63cd4db91 [clangd] Rename: merge index/AST refs path-insensitively where needed
If you have c:\foo open, and C:\foo indexed (case difference) then these
need to be considered the same file. Otherwise we emit edits to both,
and editors do... something that isn't pretty.

Maybe more centralized normalization is called for, but it's not trivial
to do this while also being case-preserving. see
https://github.com/clangd/clangd/issues/108

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

Differential Revision: https://reviews.llvm.org/D95759
2021-02-01 15:15:21 +01:00
xgupta 94fac81fcc [Branch-Rename] Fix some links
According to the [[ https://foundation.llvm.org/docs/branch-rename/ | status of branch rename ]], the master branch of the LLVM repository is removed on 28 Jan 2021.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D95766
2021-02-01 16:43:21 +05:30
Sam McCall 7de711ecca Reland [clangd] Quote/escape argv included in log messages.
... but don't apply it where we're using hasSubstr

This reverts commit 7a8008d0e8.
2021-01-31 16:39:47 +01:00
Sam McCall 7a8008d0e8 Revert "[clangd] Quote/escape argv included in log messages."
This reverts commit 0962f1d72b.
http://45.33.8.238/win/32346/step_9.txt
2021-01-31 16:22:00 +01:00
Sam McCall 60053a9ce2 [clangd] Remove references to old future-based API. NFC 2021-01-31 12:13:20 +01:00
Sam McCall 0962f1d72b [clangd] Quote/escape argv included in log messages.
https://github.com/clangd/clangd/issues/637
2021-01-31 12:00:08 +01:00
Michał Górny 632545e8ce [clang-tidy] Fix linking tests to LLVMTestingSupport
LLVMTestingSupport is not part of libLLVM, and therefore can not
be linked to via LLVM_LINK_COMPONENTS.  Instead, it needs to be
specified explicitly to ensure that it is linked explicitly
even if LLVM_LINK_LLVM_DYLIB is used.  This is consistent with handling
in clangd.

Fixes PR#48931

Differential Revision: https://reviews.llvm.org/D95653
2021-01-29 21:54:09 +01:00
Sam McCall 7d1b499cae Revert "[clangd] Extract symbol-scope logic out of Quality, add tests. NFC"
On second thought, this can't properly be reused for highlighting.

Consider this example, which Quality wants to consider function-scope,
but highlighting must consider class-scope:

void foo() {
  class X {
    int ^y;
  };
}
2021-01-29 14:59:16 +01:00
Sam McCall d0817b5f18 [clangd] Extract symbol-scope logic out of Quality, add tests. NFC
This prepares for reuse from the semantic highlighting code.

There's a bit of yak-shaving here:
 - when the enum is moved into the clangd namespace, promote it to a
   scoped enum. This means teaching the decision forest infrastructure
   to deal with scoped enums.
 - AccessibleScope isn't quite the right name: e.g. public class members
   are treated as accessible, but still have class scope. So rename to
   SymbolScope.
 - Rename some QualitySignals members to avoid name conflicts.
   (the string) SymbolScope -> Scope
   (the enum) Scope -> ScopeKind
2021-01-29 14:44:28 +01:00
serge-sans-paille d47ee525f9 [clang-tooling] Prevent llvm::fatal_error on invalid CLI option
Fail gracefully instead. Prevent further misuse by enforcing the factory builder
instead of the constructor.

Differential Revision: https://reviews.llvm.org/D94420
2021-01-29 10:15:06 +01:00
Haojian Wu f25a57e248 [clangd] Add include-fixer fixit for field_incomplete_or_sizeless diagnostic.
Differential Revision: https://reviews.llvm.org/D95439
2021-01-29 08:22:23 +01:00
Artem Dergachev b92a39ac13 [clang-tidy] bugprone-assert-side-effect: Warn on NSAssert by default.
NSAssert and NSCAssert are Objective-C Foundation's standard assert macros.

Differential Revision: https://reviews.llvm.org/D95519
2021-01-28 22:31:49 -08:00
Artem Dergachev ec81289831 [clang-tidy] bugprone-assert-side-effect: Improve warning message.
Drop redundant "found", specify what exactly is wrong with side effects
in assert conditions.

Differential Revision: https://reviews.llvm.org/D95515
2021-01-28 22:31:49 -08:00
Alexander Kornienko ab2d3ce47d [clang-tidy] Applied clang-tidy fixes. NFC
Applied fixes enabled by the LLVM's .clang-tidy configs. Reverted files where
fixes introduced compile errors:
  clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.cpp
  clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp

$ clang-tools-extra/clang-tidy/tool/run-clang-tidy.py -fix clang-tools-extra/clang-tidy/
Enabled checks:
    llvm-else-after-return
    llvm-header-guard
    llvm-include-order
    llvm-namespace-comment
    llvm-prefer-isa-or-dyn-cast-in-conditionals
    llvm-prefer-register-over-unsigned
    llvm-qualified-auto
    llvm-twine-local
    misc-definitions-in-headers
    misc-misplaced-const
    misc-new-delete-overloads
    misc-no-recursion
    misc-non-copyable-objects
    misc-redundant-expression
    misc-static-assert
    misc-throw-by-value-catch-by-reference
    misc-unconventional-assign-operator
    misc-uniqueptr-reset-release
    misc-unused-alias-decls
    misc-unused-using-decls
    readability-identifier-naming

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D95614
2021-01-29 01:01:19 +01:00
Alexander Kornienko dfd2374ab6 [clang-tidy] Remove unnecessary #ifdef
The code was likely used to verify other changes in c3b9d85bd4.
2021-01-28 15:00:07 +01:00
Sam McCall c3df9d58c7 [clangd] Parse Diagnostics block, and nest ClangTidy block under it.
(ClangTidy configuration block hasn't been in any release, so we should be OK
to move it around like this)

Differential Revision: https://reviews.llvm.org/D95362
2021-01-28 01:36:23 +01:00
Sam McCall 29472bb769 [clangd] Log warning when using legacy (theia) semantic highlighting.
The legacy protocol will be removed on trunk after the 12 branch cut,
and gone in clangd 13.

Differential Revision: https://reviews.llvm.org/D95031
2021-01-28 01:29:28 +01:00
Kadir Cetinkaya af20232b8e
[clangd] Treat "null" optional fields as missing
Clangd currently throws away any protocol messages whenever an optional
field has an unexpected type. This patch changes the behaviour to treat
`null` fields as missing.

This enables clangd to be more tolerant against small violations to the
LSP spec.

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

Differential Revision: https://reviews.llvm.org/D95229
2021-01-27 15:51:33 +01:00
Sam McCall 12de8e1399 [clangd] Work around GCC bug 66735 2021-01-27 15:32:05 +01:00
Tom Stellard 5369517d20 Bump the trunk major version to 13
and clear the release notes.
2021-01-26 19:37:55 -08:00
Nathan James 7730599c41
[clangd] FindTarget resolves base specifier
FindTarget on the virtual keyword or access specifier of a base specifier will now resolve to type of the base specifier.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D95338
2021-01-26 18:59:29 +00:00
Nathan James d92413a45e
[clangd] Selection handles CXXBaseSpecifier
Selection now includes the virtual and access modifier as part of their range for cxx base specifiers.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D95231
2021-01-26 18:58:53 +00:00
Kadir Cetinkaya 9190f17a7c
[clangd] Add std::size_t to StdSymbol mapping
This is a common symbol that's missing from our mapping because
cppreference yields multiple headers.

Add it manually by picking cstddef to prevent insertion of some stdlib-internal
headers instead.

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

Differential Revision: https://reviews.llvm.org/D95423
2021-01-26 17:53:07 +01:00
Simon Pilgrim 110837fbf6 Fix signed/unsigned comparison warning. NFCI. 2021-01-26 15:04:49 +00:00
Haojian Wu 68dbd1aefe [clangd] Add include-fixer fixit for no_member_template diagnostic.
Differential Revision: https://reviews.llvm.org/D95365
2021-01-26 10:11:06 +01:00
Kadir Cetinkaya 64cdba65bb
[clangd] Fix filename completion at the end of file
Fixes https://github.com/clangd/clangd/issues/433

Differential Revision: https://reviews.llvm.org/D95419
2021-01-26 09:45:21 +01:00
Duncan P. N. Exon Smith f4d02fbe41 Frontend: Take VFS and MainFileBuffer by reference in PrecompiledPreamble::CanReuse, NFC
Clarify that `PrecompiledPreamble::CanReuse` requires non-null arguments
for `VFS` and `MainFileBuffer`, taking them by reference instead of by
pointer.

Differential Revision: https://reviews.llvm.org/D91297
2021-01-25 17:50:56 -08:00
Sam McCall 118c33ef47 [clangd] Allow configuration database to be specified in config.
This allows for more flexibility than -compile-commands-dir or ancestor
discovery.

See https://github.com/clangd/clangd/issues/116

Differential Revision: https://reviews.llvm.org/D95057
2021-01-25 23:15:48 +01:00
Quentin Chateau 3680cb99a7 [clangd] ignore parallelism level for quick tasks
This allows quick tasks without dependencies that
need to run fast to run ASAP. This is mostly useful
for code formatting.

----------------------------

This fixes something that's been annoying me:
- Open your IDE workspace and its 20 open files
- Clangd spends 5 minutes parsing it all
- In the meantime you start to work
- Save a file, trigger format-on-save, which hangs because clangd is busy
- You're stuck waiting until clangd is done parsing your files before the formatting and save takes place

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D94875
2021-01-25 23:03:43 +01:00
Nathan James 71af5a19cb Reland"[clangd][NFC] Simplify handing on methods with no params"
This reverts commit 9d9ceb3745.

First time round caused some build bot failures due to older compilers not patched with the Defect Report about full specialization being allowed at class scope.
2021-01-25 20:19:57 +00:00
Keith Smiley 9d9ceb3745 Revert "[clangd][NFC] Simplify handing on methods with no params"
This broke the build http://lab.llvm.org:8011/#/builders/7/builds/1405

This reverts commit f05b492aae.

Differential Revision: https://reviews.llvm.org/D95385
2021-01-25 11:56:18 -08:00
Nathan James f05b492aae [clangd][NFC] Simplify handing on methods with no params
Add bind methods handling the case when a method has an empty params interface and when it has no parameters.

Remove ShutdownParams and ExitParams from Protocol, In LSP they aren't defined, instead the methods are defined to have void as the params. This signature now better reflects that.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D95270
2021-01-25 19:08:10 +00:00
Sam McCall 7e506b30a1 [clangd] Allow diagnostics to be suppressed with configuration
This has been specifically requested:
  https://github.com/clangd/vscode-clangd/issues/114
and various issues can be addressed with this as a workaround, e.g.:
  https://github.com/clangd/clangd/issues/662

Differential Revision: https://reviews.llvm.org/D95349
2021-01-25 15:59:07 +01:00
Adam Czachorowski 00054382b9 [clangd] Fix a crash when indexing invalid ObjC method declaration
This fix will make us not crash, but ideally we would handle this case
better.

Differential Revision: https://reviews.llvm.org/D94919
2021-01-25 15:43:11 +01:00
Tom Ritter d6d36baa33 Add a --use-color option to clang-query to allow forcing the behavior
D62056 makes the output color if clang auto-detects a tty, but if it
does not, there is no way to force it to use colors anyway.

This patch adjusts the command-lines given to ClangTool which will
force color on or off if --use-color is specified.
2021-01-25 08:06:54 -05:00
Sam McCall 60cd75a098 [clangd] Inject context provider rather than config into ClangdServer. NFC
This is a step towards allowing CDB behavior to being configurable.

Previously ClangdServer itself created the configs and installed them into
contexts. This was natural as it knows how to deal with resulting diagnostics.

However this prevents config being used in CDB, which must be created before
ClangdServer. So we extract the context provider (config loader) as a separate
object, which publishes diagnostics to a ClangdServer::Callbacks itself.

Now initialization looks like:
 - First create the config::Provider
 - Then create the ClangdLSPServer, passing config provider
 - Next, create the context provider, passing config provider + diagnostic callbacks
 - now create the CDB, passing context provider
 - finally create ClangdServer, passing CDB, context provider, and diagnostic callbacks

Differential Revision: https://reviews.llvm.org/D95087
2021-01-22 14:34:30 +01:00
Aleksandr Platonov 7388c34685 [clangd][SwapIndex] ensure that the old index is alive while we are using it via the function returned by `SwapIndex::indexedFiles()` call
Without this patch the old index could be freed, but there still could be tries to access it via the function returned by `SwapIndex::indexedFiles()` call.
This leads to hard to reproduce clangd crashes at code completion.
This patch keeps the old index alive until the function returned by `SwapIndex::indexedFiles()` call is alive.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D95206
2021-01-22 16:26:39 +03:00
Kadir Cetinkaya 4cca222279
[clangd] Add documentation for building and testing clangd
Adds minimal cmake configuration required to build and test clangd,
while telling target names. Should be helpful for people unfamiliar with the
LLVM repo.

See https://github.com/clangd/clangd/issues/579 for a request.

Differential Revision: https://reviews.llvm.org/D91186
2021-01-22 11:53:31 +01:00
Haojian Wu facea4a2d4 [clangd] Fix a missing override keyword, NFC. 2021-01-21 11:06:43 +01:00
Hans Wennborg 8ba442bc21 Revert "Following up on PR48517, fix handling of template arguments that refer"
Combined with 'da98651 - Revert "DR2064:
decltype(E) is only a dependent', this change (5a391d3) caused verifier
errors when building Chromium. See https://crbug.com/1168494#c1 for a
reproducer.

Additionally it reverts changes that were dependent on this one, see
below.

> Following up on PR48517, fix handling of template arguments that refer
> to dependent declarations.
>
> Treat an id-expression that names a local variable in a templated
> function as being instantiation-dependent.
>
> This addresses a language defect whereby a reference to a dependent
> declaration can be formed without any construct being value-dependent.
> Fixing that through value-dependence turns out to be problematic, so
> instead this patch takes the approach (proposed on the core reflector)
> of allowing the use of pointers or references to (but not values of)
> dependent declarations inside value-dependent expressions, and instead
> treating template arguments as dependent if they evaluate to a constant
> involving such dependent declarations.
>
> This ends up affecting a bunch of OpenMP tests, due to OpenMP
> imprecisely handling instantiation-dependent constructs, bailing out
> early instead of processing dependent constructs to the extent possible
> when handling the template.
>
> Previously committed as 8c1f2d15b8, and
> reverted because a dependency commit was reverted.

This reverts commit 5a391d38ac.

It also restores clang/test/SemaCXX/coroutines.cpp to its state before
da986511fb.

Revert "[c++20] P1907R1: Support for generalized non-type template arguments of scalar type."

> Previously committed as 9e08e51a20, and
> reverted because a dependency commit was reverted. This incorporates the
> following follow-on commits that were also reverted:
>
> 7e84aa1b81 by Simon Pilgrim
> ed13d8c667 by me
> 95c7b6cadb by Sam McCall
> 430d5d8429 by Dave Zarzycki

This reverts commit 4b574008ae.

Revert "[msabi] Mangle a template argument referring to array-to-pointer decay"

> [msabi] Mangle a template argument referring to array-to-pointer decay
> applied to an array the same as the array itself.
>
> This follows MS ABI, and corrects a regression from the implementation
> of generalized non-type template parameters, where we "forgot" how to
> mangle this case.

This reverts commit 18e093faf7.
2021-01-20 15:55:35 +01:00
Haojian Wu 42830f8bdc [clangd] Extend find-refs to include overrides.
find-references on `virtual void meth^od() = 0` will include override references.

Differential Revision: https://reviews.llvm.org/D94390
2021-01-20 13:23:20 +01:00
Kadir Cetinkaya a1d4649a5b
[clangd] Fix division by zero when computing scores
NameMatch could be a float close to zero, in such cases we were
dividing by zero and moreover propogating a "NaN" to clients, which is invalid
per JSON.

This fixes the issue by only using Quality scores whenever the NameMatch is low,
as we do in CodeCompletion ranking.

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

Differential Revision: https://reviews.llvm.org/D94755
2021-01-20 12:50:25 +01:00
Sam McCall 2ab5fd2c85 [clangd] Retire some flags for uncontroversial, stable features.
And mark a couple to be retired afther the next release branch.

Differential Revision: https://reviews.llvm.org/D94727
2021-01-20 11:47:12 +01:00
Sam McCall e6be5c7cd6 [clangd] Remove the recovery-ast options.
These force a couple of flags or that are now on by default.
So the flags don't currently do anything unless the compile command has
-fno-recovery-ast explicitly.

(For turning recovery *off* for debugging we can inject the flag with config)

This leaves the command-line flags around with no effect, I'm planning to add
a "retired flag" mechanism shortly in a separate patch.

Differential Revision: https://reviews.llvm.org/D94724
2021-01-20 11:23:57 +01:00
Sam McCall de4ba7073b [clangd] Move DirBasedCDB broadcasting onto its own thread.
This is on the critical path (it blocks getting the compile command for
the first file).

It's not trivially fast: it involves processing all filenames in the CDB
and doing some IO to look for shadowing CDBs.

And we may make this slower soon - making CDB configurable implies evaluating
the config for each listed to see which ones really are owned by the
broadcasted CDB.

Differential Revision: https://reviews.llvm.org/D94606
2021-01-20 11:22:55 +01:00
Sam McCall 536a1b0ea2 [clangd] Allow CDBs to have background work to block on.
In preparation for moving DirectoryBasedCompilationDatabase broadcasting off
the main thread.

Differential Revision: https://reviews.llvm.org/D94603
2021-01-20 11:11:01 +01:00
Utkarsh Saxena 17846ed5af [clangd] Use ASTSignals in Heuristics CC Ranking.
Differential Revision: https://reviews.llvm.org/D94927
2021-01-19 19:48:42 +01:00
Utkarsh Saxena 8bf7116d50 [clangd] Index local classes, virtual and overriding methods.
Previously we did not record local class declarations. Now with features like
findImplementation and typeHierarchy, we have a need to index such local
classes to accurately report subclasses and implementations of methods.

Performance testing results:
- No changes in indexing timing.
- No significant change in memory usage.
- **1%** increase in #relations.
- **0.17%** increase in #refs.
- **0.22%** increase #symbols.

**New index stats**
Time to index: **4:13 min**
memory usage **543MB**
number of symbols: **521.5K**
number of refs: **8679K**
number of relations: **49K**

**Base Index stats**
Time to index: **4:15 min**
memory usage **542MB**
number of symbols: **520K**
number of refs: **8664K**
number of relations: **48.5K**

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

Differential Revision: https://reviews.llvm.org/D94785
2021-01-19 16:18:48 +01:00
Richard Smith 4b574008ae [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.
Previously committed as 9e08e51a20, and
reverted because a dependency commit was reverted. This incorporates the
following follow-on commits that were also reverted:

7e84aa1b81 by Simon Pilgrim
ed13d8c667 by me
95c7b6cadb by Sam McCall
430d5d8429 by Dave Zarzycki
2021-01-18 21:05:01 -08:00
Utkarsh Saxena 275716d6db [clangd] Derive new signals in CC from ASTSignals.
This patch only introduces new signals but does not use their value
in scoring a CC candidate. Usage of these signals in CC ranking in both
heiristics and ML model will be introduced in later patches.

Differential Revision: https://reviews.llvm.org/D94473
2021-01-18 17:37:27 +01:00
Utkarsh Saxena 9abbc05097
[clangd] Use !empty() instead of size()>0 2021-01-17 15:26:40 +01:00
Utkarsh Saxena 0f9908a7c9
[clangd] Use empty() instead of size()>0 2021-01-17 15:13:01 +01:00
Utkarsh Saxena d5047d762f [clangd] Update CC Ranking model with better sampling.
A better sampling strategy was used to generate the dataset for this
model.
New signals introduced in this model:
- NumNameInContext: Number of words in the context that matches the name
of the candidate.
- FractionNameInContext: Fraction of the words in context matching the
name of the candidate.

We remove the signal `IsForbidden` from the model and down rank
forbidden signals aggresively.

Differential Revision: https://reviews.llvm.org/D94697
2021-01-15 18:13:24 +01:00
Adam Czachorowski c77c3d1d18 [clangd] Set correct CWD when using compile_flags.txt
This fixes a bug where clangd would attempt to set CWD to the
compile_flags.txt file itself.

Differential Revision: https://reviews.llvm.org/D94699
2021-01-15 14:26:24 +01:00
Adam Czachorowski aeaeb9e6bd [clangd] Make ExpandAutoType not available on template params.
We cannot expand auto when used inside a template param (C++17 feature),
so do not offer it there.

Differential Revision: https://reviews.llvm.org/D94719
2021-01-15 14:19:05 +01:00
Ilya Golovenko 9cc221b99b [clangd] exclude symbols from document outline which do not originate from the main file
Differential Revision: https://reviews.llvm.org/D94753
2021-01-15 13:23:12 +03:00
Sam McCall 4183999e0f [clangd] Reduce logspam for CDB scanning 2021-01-14 23:55:02 +01:00
Douglas Yung f85b153166 Add -fexceptions to test as it uses them and fails on platforms where it is not on by default (like the PS4). 2021-01-14 13:27:06 -08:00
Utkarsh Saxena 8b09cf7956
[clangd] Trivial: Documentation fix in ASTSignals. 2021-01-14 18:38:42 +01:00
Utkarsh Saxena 2f395b7092 [clangd] Make AST-based signals available to runWithPreamble.
Many useful signals can be derived from a valid AST which is regularly updated by
the ASTWorker. `runWithPreamble` does not have access to the ParsedAST
but it can be provided access to some signals derived from a (possibly
stale) AST.

Differential Revision: https://reviews.llvm.org/D94424
2021-01-14 18:34:50 +01:00
Sam McCall 17fb21f875 [clangd] Remove another option that was effectively always true. NFC 2021-01-14 17:19:47 +01:00
Mikhail Maltsev 176f5e95e1 [clang-tidy] Use DenseSet<SourceLocation> in UpgradeDurationConversionsCheck, NFCI
This change replaces `unordered_set<unsigned>` (which used to store
internal representation of `SourceLocation`-s) with
`DenseSet<SourceLocation>` (which stores `SourceLocation`-s directly).

Reviewed By: aaron.ballman, njames93

Differential Revision: https://reviews.llvm.org/D94601
2021-01-14 13:50:16 +00:00
Aleksandr Platonov 2e25be0b61 [clangd] Add main file macros into the main-file index.
This patch is a try to fix `WorkspaceSymbols.Macros` test after D93796.
If a macro definition is in the preamble section, then it appears to be in the preamble (static) index and not in the main-file (dynamic) index.
Thus, a such macro could not be found at a symbol search according to the logic that we skip symbols from the static index if the location of these symbols is inside the dynamic index files.
To fix this behavior this patch adds main file macros into the main-file (dynamic) index.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D94477
2021-01-14 15:10:17 +03:00
Kazu Hirata fb98a1be43 Fix the warnings on unused variables (NFC) 2021-01-13 13:32:40 -08:00
Sam McCall 0bbc6a6bb6 [clangd] Remove some old CodeCompletion options that are never (un)set. NFC 2021-01-13 18:01:48 +01:00
Utkarsh Saxena a4f3866882 [clangd] Remove "decision-forest-base" experimental flag.
The value of this flag can only be fine tuned by using A/B testing on large
user base.
We do not expect individual users to use and fine tune this flag.

Differential Revision: https://reviews.llvm.org/D94513
2021-01-13 17:54:38 +01:00
Sam McCall 466acd6948 [clangd] Avoid reallocating buffers for each message read:
- reuse std::string we read messages into
 - when reading line-wise, use SmallVector<128> and read in chunks of 128
   (this affects headers, which are short, and tests, which don't matter)

Differential Revision: https://reviews.llvm.org/D93653
2021-01-13 17:40:33 +01:00
Sam McCall 66d5994bd3 [clangd] Explicitly avoid background-indexing the same file twice.
This used to implicitly never happen due to only discovering each CDB
once.

We may want to carefully support reindexing one day, but we need to do
it carefully (tricky tradeoffs) and it would need further support in
background indexer.

Making this explicit here rather than just turning off rebroadcast in
background index for a few reasons:
- allows *new* files in the same CDB to be indexed
- relying on bugs-at-a-distance cancelling each other out is bound to bite us
- gets us closer to actually supporting reindexing, which requires similar tracking

Differential Revision: https://reviews.llvm.org/D94503
2021-01-13 17:29:30 +01:00
Sam McCall 90164ba957 [clangd] Split out a base class for delegating GlobalCompilationDatabases. NFC
This prepares for adding another delegatable method (blockUntilIdle) to GCDB.
2021-01-13 16:20:33 +01:00
Yitzhak Mandelbaum 922a5b8941 [clang-tidy] Add test for Transformer-based checks with diagnostics.
Adds a test that checks the diagnostic output of the tidy.

Differential Revision: https://reviews.llvm.org/D94453
2021-01-12 20:15:22 +00:00
Nathan Ridge 4718ec0166 [clangd] Avoid recursion in TargetFinder::add()
Fixes https://github.com/clangd/clangd/issues/633

Differential Revision: https://reviews.llvm.org/D94382
2021-01-12 13:57:54 -05:00
Nathan James 31732e6f52
[clangd] Remove ScratchFS from tests
This can lead to issues if files in the tmp directory we don't care about / control are found.
This was partially addressed in D94321, but this is a more permanent fix.
Fixes https://github.com/clangd/clangd/issues/354

Reviewed By: adamcz, sammccall

Differential Revision: https://reviews.llvm.org/D94359
2021-01-11 16:14:26 +00:00
Haojian Wu a2dbf3443a [clangd] Fix -check mode doesn't respect any tidy configs.
Differential Revision: https://reviews.llvm.org/D94411
2021-01-11 16:43:33 +01:00
Haojian Wu 1677c86124 [clangd] Add metrics for go-to-implementation.
Differential Revision: https://reviews.llvm.org/D94393
2021-01-11 10:26:50 +01:00
Nathan James 467cbd2981
[clangd][NFC] Remove unnecessary copy in CodeComplete
All tests still pass with ASAN so fairly confident no use-after-free going on here.
2021-01-09 02:32:23 +00:00
Haojian Wu 8e36d21fab [clangd] Add go-to-def metric.
to track the number of different "special" go-to-def request.

Differential Revision: https://reviews.llvm.org/D94289
2021-01-08 21:03:59 +01:00
Adam Czachorowski 2e1bb7940a [clangd] Add missing "override" to fix the build.
Follow-up to d4af86581e

Differential Revision: https://reviews.llvm.org/D94314
2021-01-08 17:24:47 +01:00
Adam Czachorowski d4af86581e [clangd] Fix type printing in the presence of qualifiers
When printing QualType with qualifiers like "const", or pointing to an
elaborated type, we would print garbage like:
  std::const std::vector<int>&
with the initial std:: being calculated correctly, but inserted in the
wrong place and the second std:: not removed (due to elaborated type).

This affected, among others, ExtractFunction and ExpandAuto tweaks.

This change introduces a new callback to PrintingPolicy, which allows us
to influence the printing of namespace qualifiers. In the future, the
same callback can be used to improve handling of "using namespace"
directives as well.

Fixes:
  https://github.com/clangd/clangd/issues/640 (ExtractFunction)
  https://github.com/clangd/clangd/issues/264 (ExpandAuto)
  First point of https://github.com/clangd/clangd/issues/524

Differential Revision: https://reviews.llvm.org/D94259
2021-01-08 17:00:39 +01:00
Haojian Wu ed3b1f9061 [clangd] go-to-implementation on a base class jumps to all subclasses.
Differential Revision: https://reviews.llvm.org/D92749
2021-01-08 13:50:57 +01:00
Haojian Wu c909512fdb [clangd] Cleanup a remaining Optional<SymbolID> usage, NFC. 2021-01-08 13:44:20 +01:00
Haojian Wu b83b7d0873 [clangd] NFC, avoid potential ODR violation. 2021-01-08 13:29:11 +01:00
Sam McCall 213329d7c6 [clangd] Add server capability advertising hot-reloading of CDBs.
Currently some clients watch for CDB changes and restart clangd, now that we
can reload compile_commands.json ourselves this is counterproductive.
The capability allows this behavior to be phased out.

This is going to be a mild regression, as we do not actually watch for files on
disk and so new diagnostics need to wait until a rebuild is requested e.g. due
to file change (and the internal caches have expired).
However this is still a better tradeoff (and if it's important, we can request
the client to watch files for us in the future).

Differential Revision: https://reviews.llvm.org/D94222
2021-01-07 13:39:21 +01:00
Nathan James 3505d8dc07 [clangd][NFC] Use PathRef for getCorrespondingHeaderOrSource 2021-01-07 02:41:19 +00:00
Nathan James 0bfe100145
[NFC] Test case refactor 2021-01-06 20:00:15 +00:00
Aleksandr Platonov 979228f120 [clangd][fuzzyFind] Do not show stale symbols in the result.
This is follow up to D93393.
Without this patch `MergedIndex::fuzzyFind()` returns stale symbols from the static index even if these symbols were removed.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93796
2021-01-06 11:17:12 +03:00
Yitzhak Mandelbaum 9eb2284f60 [clang-tidy] Update uses of deprecated Transformer APIs in StringFindStrContainsCheck.
Migrates `change` to `changeTo`; changes to new constructor API (2-arg construct
+ `setRule`); refactors use of `addInclude` to newer version.

Differential Revision: https://reviews.llvm.org/D93695
2021-01-05 16:49:29 +00:00
Stephen Kelly 53c3acb89f [clang-tidy] Add extra tests
By default, check_clang_tidy runs tests in c++11-or-later mode.

Differential Revision: https://reviews.llvm.org/D94029
2021-01-05 15:43:56 +00:00
Giulio Girardi 2f8d1e9eb2 [clangd] When querying drivers by binary, look in PATH too
Sometimes compile_commands.json databases are created without an
absolute path for the driver in the command field. By default the driver
name is appended to the current directory, however if no driver is found
in that location assume it was in the default PATH and try finding it
there

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93600
2021-01-05 12:54:07 +01:00
Thorsten Schütt 2fd11e0b1e Revert "[NFC, Refactor] Modernize StorageClass from Specifiers.h to a scoped enum (II)"
This reverts commit efc82c4ad2.
2021-01-04 23:17:45 +01:00
Thorsten Schütt efc82c4ad2 [NFC, Refactor] Modernize StorageClass from Specifiers.h to a scoped enum (II)
Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D93765
2021-01-04 22:58:26 +01:00
Nathan James 59810c51e7
[clang-tidy] Fix windows tests
Attempt to fix the 2 failing tests identifier in 48646.
Appears that python3 doesn't like nested double quotes in single quoted strings, hopefully nested single quotes in double quoted strings is a-ok.

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D93979
2021-01-04 00:39:34 +00:00
Nathan James 7af6a13450
[NFC] Switch up some dyn_cast calls 2021-01-02 19:56:27 +00:00
Nico Weber b4c5e19da7 Temporarily disable to clang-tidy tests on Windows
They fail at least on my Win bot after switching it to Py3.
See PR48646 for details.
2021-01-01 23:19:48 -05:00
Yang Fan d5324c052b [clang-tidy][NFC] Fix a build warning due to an extra semicolon
Differential Revision: https://reviews.llvm.org/D93961
2021-01-01 16:00:20 +08:00
Nathan James c3b9d85bd4
[clang-tidy][NFC] Remove unnecessary headers 2020-12-28 15:01:51 +00:00
Adam Czachorowski 0999408aea [clangd] Add error handling (elog) in code completion.
Differential Revision: https://reviews.llvm.org/D93220
2020-12-28 15:22:54 +01:00
Sam McCall 74b3acefc7 [clangd] Fix case mismatch crash on in CDB on windows after 92dd077af1
See https://github.com/clangd/clangd/issues/631
2020-12-23 22:42:45 +01:00
Aleksandr Platonov 2522fa053b [clangd] Do not take stale definition from the static index.
This is follow up to D93393.
Without this patch clangd takes the symbol definition from the static index if this definition was removed from the dynamic index.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93683
2020-12-23 18:21:38 +03:00
Sam McCall f7a26127f2 [clangd] Release notes for b8c37153d5 2020-12-22 22:58:45 +01:00
Sam McCall 3dbe471a26 [clangd] Use atomics instead of locks to track periodic memory trimming
Instead of always locking/unlocking a contended mutex, we now do one atomic read
in the common case, and one read + one exchange if the timer has expried.

Also use this for memory profiling which has similar/compatible requirements.

Differential Revision: https://reviews.llvm.org/D93726
2020-12-22 22:32:22 +01:00
Stephen Kelly 7ec7788ac1 Try to fix build on Windows 2020-12-22 20:25:58 +00:00
Stephen Kelly a5311d731e [clang-tidy] Handle template instantiations in container size check
readability-container-size-empty currently modifies source code based on
AST nodes in template instantiations, which means that it makes
transformations based on substituted types.  This can lead to
transforming code to be broken.

Change the matcher implementation to ignore template instantiations
explicitly, and add a matcher to explicitly handle template declarations
instead of instantiations.

Differential Revision: https://reviews.llvm.org/D91302
2020-12-22 18:44:45 +00:00
Arthur Eubanks b2e734d5f4 Revert "[clangd] zap a few warnings"
This reverts commit 95c7b6cadb.

Depends on a reverted change.
2020-12-22 10:34:03 -08:00
Nathan James 4b3633cf2c
[clangd] Reuse buffer for JSONTransport::sendMessage
Allocate a Buffer in the JSONTransport to be used when sending messages to the client.
This gets reused each time a message is sent, reducing in fewer malloc, which is always a bonus.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93531
2020-12-22 11:30:56 +00:00
Quentin Chateau b8c37153d5 [clangd] Trim memory periodically when using glibc malloc
This diff addresses the issue of the ever increasing memory usage of clangd. The key to understand what happens is to use `malloc_stats()`: malloc arenas keep getting bigger, although the actual memory used does not. It seems some operations while bulding the indices (both dynamic and background) create this problem. Specifically, 'FileSymbols::update' and 'FileSymbols::buildIndex' seem especially affected.

This diff adds a call to `malloc_trim()` periodically in
ClangdLSPServer.

Fixes: https://github.com/clangd/clangd/issues/251
Fixes: https://github.com/clangd/clangd/issues/115

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93452
2020-12-22 08:54:28 +01:00
Quentin Chateau 3fa2d37eb3 [clangd][NFC] Improve clangd status messages
clangd actions have various naming schemes, the most
common being PascalCase. This commit applies PascalCase
to all clangd actions, and fix the status rendering
in `renderTUAction` to look more consistent.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93546
2020-12-21 20:19:25 +01:00
Chris Warner 35f2c3a8b4 [clang-tidy] cppcoreguidelines-pro-type-member-init: suppress warning for default member funcs
Modify the cppcoreguidelines-pro-type-member-init checker to ignore warnings from the move and copy-constructors when they are compiler defined with `= default` outside of the type declaration.

Reported as [LLVM bug 36819](https://bugs.llvm.org/show_bug.cgi?id=36819)

Reviewed By: malcolm.parsons

Differential Revision: https://reviews.llvm.org/D93333
2020-12-20 11:22:41 +00:00
Sam McCall 2b62e62328 [clangd] Fix windows path handling in .clang-tidy parsing 2020-12-19 02:24:25 +01:00
Sam McCall 2fced5a07b [clangd] Don't cancel requests based on "updates" with same content
There's an unfortunate collision between two features:
 - we implicitly cancel certain requests when the file changes, to avoid
   the queue getting clogged building old revisions to service stale requests
 - we "reparse-if-needed" by synthesizing a file change, e.g. on didSave

We could explicitly mark these synthetic requests to avoid this, but
looking for changes in file content clutters our APIs less and is
arguably the correct thing to do in any case.

Fixes https://github.com/clangd/clangd/issues/620
2020-12-19 02:03:40 +01:00
Sam McCall b0615642f6 [clangd] Make our printing policies for Hover more consistent, especially tags
Different cases were using a bunch of different variants of the printing policy.
Each of these had something going for it, but the result was inconsistent.

Goals:
  - single printing policy used (almost) everywhere
  - avoid unidiomatic tags like `class vector<class X>`
  - be informative and easy to understand

For tags, the solution I wound up with is: we print only the outer tag and only
in the simplest cases where this elaboration won't cause confusion.

For example:
 - class X
 - enum Foo
 - vector<int>
 - X*

This seems to strike a nice balance of providing plenty of info/context in common
cases while never being confusing.

Differential Revision: https://reviews.llvm.org/D93553
2020-12-19 00:52:55 +01:00
Sam McCall 95c7b6cadb [clangd] zap a few warnings 2020-12-18 16:34:34 +01:00
Quentin Chateau c46c7c9bcf [clangd] Smarter hover on auto and decltype
Only show the keyword as the hover "Name".

Show whether the type is deduced or undeduced as
the hover "Documentation".

Show the deduced type (if any) as the "Definition".

Don't show any hover information for:
- the "auto" word of "decltype(auto)"
- "auto" in lambda parameters
- "auto" in template arguments

---------------

This diff is a suggestion based on what @sammccall  suggested in https://reviews.llvm.org/D92977 about hover on "auto". It somehow "hacks" onto the "Documentation" and "Definition" fields of `HoverInfo`. It sure looks good on VSCode, let me know if this seem acceptable to you.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93227
2020-12-18 16:27:09 +01:00
Sam McCall 0336ff0a17 [clangd] Fix broken JSON test on windows 2020-12-18 15:11:08 +01:00
Frank Derry Wanye e69e551e0e new altera single work item barrier check
This lint check is a part of the FLOCL (FPGA Linters for OpenCL)
project out of the Synergy Lab at Virginia Tech.

FLOCL is a set of lint checks aimed at FPGA developers who write code
in OpenCL.

The altera single work item barrier check finds OpenCL kernel functions
that call a barrier function but do not call an ID function. These
kernel functions will be treated as single work-item kernels, which
could be inefficient or lead to errors.

Based on the "Altera SDK for OpenCL: Best Practices Guide."
2020-12-18 07:52:20 -05:00
Aleksandr Platonov e35f9229dc [clangd] Ignore the static index refs from the dynamic index files.
This patch fixes the following problem:
- open a file with references to the symbol `Foo`
- remove all references to `Foo` (from the dynamic index).
- `MergedIndex::refs()` result will contain positions of removed references (from the static index).

The idea of this patch is to keep a set of files which were used during index build inside the index.
Thus at processing the static index references we can check if the file of processing reference is a part of the dynamic index or not.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93393
2020-12-18 15:36:30 +03:00
Sam McCall 98993193e9 [clangd] Add hot-reload of compile_commands.json and compile_flags.txt
When querying the CDB, we stat the underlying file to check it hasn't changed.
We don't do this every time, but only if we didn't check within 5 seconds.

This behavior only exists for compile_commands.json and compile_flags.txt.
The CDB plugin system doesn't expose enough information to handle others.

Slight behavior change: we now only look for `build/compile_commands.json`
rather than trying every CDB strategy under `build` subdirectories.

Differential Revision: https://reviews.llvm.org/D92663
2020-12-18 11:16:46 +01:00
Nathan James 2808f597f8
[clangd] Print .clang-tidy configuration parsing errors using [ev]?log.
Currently warnings when parsing .clang-tidy are printed directly to errs.
This is less than ideal as there is no synchronisation printing to errs, leading to potential races.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93436
2020-12-18 02:07:27 +00:00
Nathan James 64badecd44
[clang-tidy][NFC] Reduce copies of Intrusive..FileSystem
Swapped a few instances where a move is more optimal or the target doesn't need to hold a reference.
2020-12-17 14:09:08 +00:00
Sam McCall 894c4761c6 [clangd] Add llvm:: qualifier to work around GCC bug. NFC
Some old GCC versions seem to miss the default template parameter when
using the clang/Basic/LLVM.h forward declarations of SmallVector.

See D92788
2020-12-17 12:51:12 +01:00
Fangrui Song c70f36865e Use basic_string::find(char) instead of basic_string::find(const char *s, size_type pos=0)
Many (StringRef) cannot be detected by clang-tidy performance-faster-string-find.
2020-12-16 23:28:32 -08:00
Nathan James ddffcdf0a6
[clang-tidy] Add a diagnostic callback to parseConfiguration
Currently errors detected when parsing the YAML for .clang-tidy files are always printed to errs.
For clang-tidy binary workflows this usually isn't an issue, but using clang-tidy as a library for integrations may want to handle displaying those errors in their own specific way.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D92920
2020-12-17 00:24:58 +00:00
Emma Blink 7685d818ef Mark implicit coroutine variables as being implicit
This prevents the clang-tidy readability-identifier-naming check from
triggering on implicit __coro_gro and __promise variables in coroutines.
2020-12-16 14:42:07 -05:00
Stephen Kelly 0dd8f6f903 [ClangTidy] NFC: Add more tests for container-size-empty 2020-12-15 23:27:38 +00:00
Nathan James 68e642cad0
[clang-tidy] Support all YAML supported spellings for bools in CheckOptions.
Depends on D92755

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D92756
2020-12-15 21:15:16 +00:00
Nathan James dfac97d557
[clangd] Validate clang-tidy Checks in clangd config.
Add instrumentation in ConfigCompile to validate that items in ClangTidy:[Add|Remove] correspond to actual clang-tidy checks.
If they don't a warning will be presented to the user.

This is especially useful for catching typos in the glob items.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D92874
2020-12-15 21:10:57 +00:00
Kirill Bobyrev 0545680cb8 Reland dcdef5b5b3
Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D92198
2020-12-15 20:54:55 +01:00
Nathan James cfa1010c42
[clangd] Provide suggestions with invalid config keys
Update the config file warning when an unknown key is detected which is likely a typo by suggesting the likely key.
This won't suggest a key that has already been seen in the block.

Appends the fix to the diag, however right now there is no support for presenting that fix to the user.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D92990
2020-12-15 18:16:17 +00:00
Kirill Bobyrev 32e7a9cab6 Revert "[clangd] Log remote index connectivity status"
This reverts commit dcdef5b5b3.

This commit breaks clangd-ubuntu-tsan builds:
http://lab.llvm.org:8011/#builders/131/builds/1392
2020-12-15 18:42:42 +01:00
Kirill Bobyrev dcdef5b5b3 [clangd] Log remote index connectivity status
Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D92198
2020-12-15 18:29:48 +01:00
Quentin Chateau bda7d0af97 [clangd] Improve goToDefinition on auto and dectype
locateSymbolAt (used in goToDeclaration) follows the
deduced type instead of failing to locate the declaration.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D92977
2020-12-15 16:32:22 +01:00
Sam McCall 5186eda326 [clangd] Oops, fix code in #ifdef WIN32 2020-12-15 14:17:54 +01:00
Sam McCall 92dd077af1 Reland [clangd] Extract per-dir CDB cache to its own threadsafe class. NFC
This reverts commit 4d956af594.

Assertion failures on windows fixed by
965d71c69a
2020-12-15 14:00:03 +01:00
Sam McCall 965d71c69a [clangd] Avoid traversing C:\ -> C: when looking for CDBs
Boost in its infinite wisdom considers C: a parent of C:\, and we've
inherited that. This breaks the assumption that after canonicalizing a
path, the path parents are the directory's parents.
2020-12-15 13:59:00 +01:00
xndcn 9c328e7afa [clangd] Add hover info for `this` expr
How about add hover information for `this` expr?
It seems useful to show related information about the class for `this` expr sometimes.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D92041
2020-12-15 09:47:29 +01:00
Nico Weber 7799ef7121 Revert "Lex: Migrate HeaderSearch::LoadedModuleMaps to FileEntryRef"
This reverts commit a40db5502b.
and follow-up d636b881bb

Somewhat speculative, likely broke check-clang on Windows:
https://reviews.llvm.org/D92975#2453482
2020-12-14 22:05:08 -05:00
Duncan P. N. Exon Smith a40db5502b Lex: Migrate HeaderSearch::LoadedModuleMaps to FileEntryRef
Migrate `HeaderSearch::LoadedModuleMaps` and a number of APIs over to
`FileEntryRef`. This should have no functionality change. Note that two
`FileEntryRef`s hash the same if they point at the same `FileEntry`.

Differential Revision: https://reviews.llvm.org/D92975
2020-12-14 14:35:11 -08:00
Haojian Wu 63ec9e40d1 [clangd] Go-to-definition on pure virtual method decls jumps to all overrides.
Reviewed By: usaxena95

Differential Revision: https://reviews.llvm.org/D92299
2020-12-14 08:56:24 +01:00
Nathan Ridge fef242c32e [clangd] Fix locateMacroAt() for macro definition outside preamble
Fixes https://github.com/clangd/clangd/issues/577

Differential Revision: https://reviews.llvm.org/D91025
2020-12-13 18:33:33 -05:00
Zinovy Nis 709112bce4 [clang-tidy] false-positive for bugprone-redundant-branch-condition in case of passed-by-ref params
Inspired by discussion in https://reviews.llvm.org/D91037

Differential Revision: https://reviews.llvm.org/D91495
2020-12-11 21:09:51 +03:00
Sam McCall 4d956af594 Revert [clangd] Extract per-dir CDB cache to its own threadsafe class. NFC
This reverts commit 8a4390dc47.

(The reland did not have the bugfix, just trying to get more details
from the buildbots)
2020-12-11 17:35:50 +01:00
Sam McCall 8a4390dc47 Reland [clangd] Extract per-dir CDB cache to its own threadsafe class. NFC
This reverts commit de4f551901.

More debug output to try to pin down an impossible condition.
2020-12-11 17:34:53 +01:00
Nathan James 62b4a69969
[clangd] Use enumMember instead of enumConstant
We should be using enumMember as thats defined in LSP, enumConstant is non standard so clients aren't likely to support it
Fixes https://github.com/clangd/clangd/issues/622n

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93113
2020-12-11 14:46:13 +00:00
Alexander Kornienko 4c5e0c7fd8 Remove references to the ast_type_traits namespace
Follow up to https://reviews.llvm.org/D92994
2020-12-11 12:39:33 +01:00
Haojian Wu 38d32e4fd7 [clangd] Reorder the class field to avoid -Wreorder-ctor warning, NFC. 2020-12-11 10:46:54 +01:00
Alexander Kornienko 027899dab6 Remove references to the ast_type_traits namespace
Follow up to cd62511496 /
https://reviews.llvm.org/D74499

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D92994
2020-12-11 00:58:46 +01:00
Felix Berger 671ad58061 [clang-tidy] performance-unnecessary-copy-initialization: Prevent false positives when dependent variable is modified.
Extend the check to not only look at the variable the unnecessarily copied
variable is initialized from, but also ensure that any variable the old variable
references is not modified.

Extend DeclRefExprUtils to also count references and pointers to const assigned
from the DeclRef we check for const usages.

Reviewed-by: aaron.ballman

Differential Revision: https://reviews.llvm.org/D91893
2020-12-10 16:58:17 -05:00
Utkarsh Saxena 4ce242a163 [clangd] Find relations in Dex exploration tool.
Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D93029
2020-12-10 16:54:03 +01:00
Nathan James a0cf2b8f71
[clangd][NFC] Remove unnecessary vector.
As pointed out in D92788.

Reviewed By: kbobyrev

Differential Revision: https://reviews.llvm.org/D92986
2020-12-10 14:59:17 +00:00
Nathan James 34d2688a50
[clang-tidy] Use a MemoryBufferRef when parsing configuration files.
Using a MemoryBufferRef, If there is an error parsing, we can point the user to the location of the file.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D93024
2020-12-10 14:52:45 +00:00
Kirill Bobyrev ee02e20c08
[clangd] NFC: Use SmallVector<T> where possible
SmallVector<T> with default size is now the recommended version (D92522).

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D92788
2020-12-10 13:36:49 +01:00
Nathan James bedf3a0f50
[clang-tidy][NFC] Use moves instead of copies when constructing OptionsProviders.
Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D92267
2020-12-10 11:34:57 +00:00
Nico Weber de4f551901 Revert "[clangd] Extract per-dir CDB cache to its own threadsafe class. NFC"
This reverts commit 634a377bd8.
Breaks tests on Windows, see https://reviews.llvm.org/D92381#2443407
2020-12-09 20:11:19 -05:00
Duncan P. N. Exon Smith 028e55d2d4 clangd: Migrate to FileEntryRef in TweakTests, NFC 2020-12-09 17:00:42 -08:00
Kirill Bobyrev 5a1bc69f81 [clangd] NFC: Add client-side logging for remote index requests
Figuring out whether the server is responding and debugging issues with remote
index setup is no easy task: add verbose logging for client side RPC requests
to relieve some pain.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D92181
2020-12-09 21:40:37 +01:00
Sam McCall 634a377bd8 [clangd] Extract per-dir CDB cache to its own threadsafe class. NFC
This is a step towards making compile_commands.json reloadable.

The idea is:
 - in addition to rare CDB loads we're soon going to have somewhat-rare CDB
   reloads and fairly-common stat() of files to validate the CDB
 - so stop doing all our work under a big global lock, instead using it to
   acquire per-directory structures with their own locks
 - each directory can be refreshed from disk every N seconds, like filecache
 - avoid locking these at all in the most common case: directory has no CDB

Differential Revision: https://reviews.llvm.org/D92381
2020-12-09 17:40:12 +01:00
Adam Czachorowski 5934a79196 [clangd] Split tweak tests into one file per tweak.
No changes to the tests themselves, other than some auto -> const auto
diagnostic fixes and formatting.

Differential Revision: https://reviews.llvm.org/D92939
2020-12-09 17:17:06 +01:00
Duncan P. N. Exon Smith 5207f19d10 ADT: Allow IntrusiveRefCntPtr construction from std::unique_ptr, NFC
Allow a `std::unique_ptr` to be moved into the an `IntrusiveRefCntPtr`,
and remove a couple of now-unnecessary `release()` calls.

Differential Revision: https://reviews.llvm.org/D92888
2020-12-08 17:33:19 -08:00
Nathan James 86436a4343
[clang-tidy][NFC] Made Globlist::contains const 2020-12-08 22:26:55 +00:00
Nathan James 27553933a8 [clang-tidy] Add support for diagnostics with no location
Add methods for emitting diagnostics with no location as well as a special diagnostic for configuration errors.
These show up in the errors as [clang-tidy-config].
The reason to use a custom name rather than the check name is to distinguish the error isn't the same category as the check that reported it.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D91885
2020-12-08 20:29:31 +00:00
Roman Lebedev 39431e479f
[clang-tidy] Introduce misc No Integer To Pointer Cast check
While casting an (integral) pointer to an integer is obvious - you just get
the integral value of the pointer, casting an integer to an (integral) pointer
is deceivingly different. While you will get a pointer with that integral value,
if you got that integral value via a pointer-to-integer cast originally,
the new pointer will lack the provenance information from the original pointer.

So while (integral) pointer to integer casts are effectively no-ops,
and are transparent to the optimizer, integer to (integral) pointer casts
are *NOT* transparent, and may conceal information from optimizer.

While that may be the intention, it is not always so. For example,
let's take a look at a routine to align the pointer up to the multiple of 16:
The obvious, naive implementation for that is:

```
  char* src(char* maybe_underbiased_ptr) {
    uintptr_t maybe_underbiased_intptr = (uintptr_t)maybe_underbiased_ptr;
    uintptr_t aligned_biased_intptr = maybe_underbiased_intptr + 15;
    uintptr_t aligned_intptr = aligned_biased_intptr & (~15);
    return (char*)aligned_intptr; // warning: avoid integer to pointer casts [misc-no-inttoptr]
  }
```

The check will rightfully diagnose that cast.

But when provenance concealment is not the goal of the code, but an accident,
this example can be rewritten as follows, without using integer to pointer cast:

```
  char*
  tgt(char* maybe_underbiased_ptr) {
      uintptr_t maybe_underbiased_intptr = (uintptr_t)maybe_underbiased_ptr;
      uintptr_t aligned_biased_intptr = maybe_underbiased_intptr + 15;
      uintptr_t aligned_intptr = aligned_biased_intptr & (~15);
      uintptr_t bias = aligned_intptr - maybe_underbiased_intptr;
      return maybe_underbiased_ptr + bias;
  }
```

See also:
* D71499
* [[ https://www.cs.utah.edu/~regehr/oopsla18.pdf | Juneyoung Lee, Chung-Kil Hur, Ralf Jung, Zhengyang Liu, John Regehr, and Nuno P. Lopes. 2018. Reconciling High-Level Optimizations and Low-Level Code in LLVM. Proc. ACM Program. Lang. 2, OOPSLA, Article 125 (November 2018), 28 pages. ]]

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D91055
2020-12-08 22:55:13 +03:00
Adam Czachorowski 3c5bed734f [clangd] ExpandAutoType: Do not offer code action on lambdas.
We can't expand lambda types anyway. Now we simply not offer the code
action instead of showing it and then returning an error in apply().

Differential Revision: https://reviews.llvm.org/D92847
2020-12-08 20:03:16 +01:00
Eric Seidel c6348e8c95 cppcoreguidelines Narrowing Conversions Check: detect narrowing conversions involving typedefs
The check 'cppcoreguidelines-narrowing-conversions' does not detect conversions
involving typedef. This notably includes the standard fixed-width integer types
like int32_t, uint64_t, etc. Now look through the typedefs at the desugared type.
2020-12-08 13:10:41 -05:00
Nathan James 4a0528e4a0
[clangd][NFC] Small tweak to combined provider
This should address the FIXME about clang3.9 dervied to base unique_ptr constructor not working.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D91925
2020-12-08 17:12:56 +00:00
Chris Kennelly 8d2c095e5a [clang-tidy] Omit std::make_unique/make_shared for default initialization.
This extends the check for default initialization in arrays added in
547f89d607 to include scalar types and exclude them from the suggested fix for
make_unique/make_shared.

Rewriting std::unique_ptr<int>(new int) as std::make_unique<int>() (or for
other, similar trivial T) switches from default initialization to value
initialization, a performance regression for trivial T.  For these use cases,
std::make_unique_for_overwrite is more suitable alternative.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D90392
2020-12-08 10:34:17 -05:00
Chris Kennelly 16622d535c [clang-tidy] Recognize single character needles for absl::StrContains.
Commit fbdff6f3ae0b in the Abseil tree adds an overload for
absl::StrContains to accept a single character needle for optimized
lookups.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D92810
2020-12-08 10:01:30 -05:00
Adam Czachorowski f6b205dae1 [clangd] ExtractFunction: disable on regions that sometimes, but not always return.
apply() will fail in those cases, so it's better to detect it in
prepare() already and hide code action from the user.

This was especially annoying on code bases that use a lot of
RETURN_IF_ERROR-like macros.

Differential Revision: https://reviews.llvm.org/D92408
2020-12-08 15:55:32 +01:00
Nathan James 8625f5bc79
[clang-tidy][NFC] Streamline CheckOptions error reporting. 2020-12-07 14:05:49 +00:00
Nathan James 980618145b
[clang-tidy][docs] Update check options with boolean values instead of non-zero/0/1
Using bools instead of integers better conveys the expected value of the option.

Reviewed By: Eugene.Zelenko, aaron.ballman

Differential Revision: https://reviews.llvm.org/D92652
2020-12-07 12:13:57 +00:00
Sam McCall 2542ef83ed [clangd] Fix windows slashes in project config diagnostics 2020-12-07 12:54:38 +01:00
Sam McCall f1357264b8 [clangd] Temporarily test that uncovered broken behavior on windows 2020-12-07 12:34:17 +01:00
Sam McCall fed9af29c2 [clangd] Publish config file errors over LSP
We don't act as a language server for these files (e.g. don't get open/close
notifications for them), but just blindly publish diagnostics for them.

This works reasonably well in coc.nvim and vscode: they show up in the
workspace diagnostic list and when you open the file.
The only update after the file is reparsed, not as you type which is a bit
janky, but seems a lot better than nothing.

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

Differential Revision: https://reviews.llvm.org/D92704
2020-12-07 11:07:32 +01:00
Haojian Wu 1df0677e6a [clangd] Add language metrics for recovery AST usage.
Differential Revision: https://reviews.llvm.org/D92157
2020-12-07 10:52:05 +01:00
Mark de Wever f687b4ac84 [NFC][clang-tidy] Fixes comment typos. 2020-12-05 16:31:16 +01:00
Haojian Wu 445289aa63 [clangd] Fix an assertion violation in rename.
NamedDecl::getName() asserts the name must be an identifier.

Differential Revision: https://reviews.llvm.org/D92642
2020-12-04 12:23:26 +01:00
Adam Czachorowski c282b7de5a [clangd] AddUsing: Fix a crash on ElaboratedTypes without NestedNameSpecfiiers.
Differential Revision: https://reviews.llvm.org/D92579
2020-12-03 20:25:38 +01:00
Adam Czachorowski 517828a31b [clangd] Bundle code completion items when the include paths differ, but resolve to the same file.
This can happen when, for example, merging results from an external
index that generates IncludeHeaders with full URI rather than just
literal include.

Differential Revision: https://reviews.llvm.org/D92494
2020-12-03 16:33:15 +01:00
Ilya Golovenko 2d539d7854 [clangd] Relation slabs should not be accounted when computing backing storage size
Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D92484
2020-12-03 16:56:53 +03:00
Haojian Wu a59e504a61 [clangd] Fix a nullptr-access crash in canonicalRenameDecl. 2020-12-03 12:59:00 +01:00
Arthur O'Dwyer e181a6aedd s/instantate/instantiate/ throughout. NFCI.
The static_assert in "libcxx/include/memory" was the main offender here,
but then I figured I might as well `git grep -i instantat` and fix all
the instances I found. One was in user-facing HTML documentation;
the rest were in comments or tests.
2020-12-01 22:13:40 -05:00
Roman Lebedev ae7ec47fc6
[NFC][clang-tidy] Port rename_check.py to Python3 2020-12-01 20:10:19 +03:00
Yitzhak Mandelbaum fdff677a95 [libTooling] Remove deprecated Clang Transformer declarations
A number of declarations were leftover after the move from `clang::tooling` to
`clang::transformer`. This patch removes those declarations and upgrades the
handful of references to the deprecated declarations.

Differential Revision: https://reviews.llvm.org/D92340
2020-11-30 20:15:26 +00:00
Roman Lebedev 317ca3ecf8
[NFC][clang-tidy] Do link FrontendOpenMP into concurrency module after all
It seems that while clangASTMatchers does add FrontendOpenMP into
it's LLVM_LINK_COMPONENTS, it's still not being propagated transitively.
2020-11-30 13:34:00 +03:00
Vasily Kulikov cac5be495e
[clang-tidy] implement concurrency-mt-unsafe
Checks for some thread-unsafe functions against a black list
of known-to-be-unsafe functions. Usually they access static variables
without synchronization (e.g. gmtime(3)) or utilize signals
in a racy way (e.g. sleep(3)).

The patch adds a check instead of auto-fix as thread-safe alternatives
usually have API with an additional argument
(e.g. gmtime(3) v.s. gmtime_r(3)) or have a different semantics
(e.g. exit(3) v.s. __exit(3)), so it is a rather tricky
or non-expected fix.

An option specifies which functions in libc should be considered
thread-safe, possible values are `posix`, `glibc`,
or `any` (the most strict check). It defaults to 'any' as it is
unknown what target libc type is - clang-tidy may be run
on linux but check sources compiled for other *NIX.

The check is used in Yandex Taxi backend and has caught
many unpleasant bugs. A similar patch for coroutine-unsafe API
is coming next.

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D90944
2020-11-30 12:27:17 +03:00
Vasily Kulikov 8da7efbb0d
[clang-tidy] add concurrency module
The module will contain checks related to concurrent programming (including threads, fibers, coroutines, etc.).

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D91656
2020-11-30 12:27:17 +03:00
Nathan Ridge f15b7869e5 [clang-tidy] [clangd] Avoid multi-line diagnostic range for else-after-return diagnostic
Fixes https://bugs.llvm.org/show_bug.cgi?id=47809

Differential Revision: https://reviews.llvm.org/D92272
2020-11-29 18:32:23 -05:00
Sam McCall d99da80841 [clangd] Fix path edge-case condition. 2020-11-29 13:40:29 +01:00
Sam McCall 67d16b6da4 [clangd] Cache .clang-tidy files again.
This cache went away in 73fdd99870

This time, the cache is periodically validated against disk, so config
is still mostly "live".

The per-file cache reuses FileCache, but the tree-of-file-caches is
duplicated from ConfigProvider. .clangd, .clang-tidy, .clang-format, and
compile_commands.json all have this pattern, we should extract it at some point.
TODO for now though.

Differential Revision: https://reviews.llvm.org/D92133
2020-11-29 13:28:53 +01:00
Kirill Bobyrev 4169c520f6
[clangd] Add symbol origin for remote index
Makes it easier to diagnose remote index issues with --debug-origins flag.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D92202
2020-11-28 15:38:11 +01:00
Nathan James ca64c8948f
[NFC] SmallVector<char...> to SmallString<...> 2020-11-27 20:36:09 +00:00
Kirill Bobyrev abfcb606c2
[clangd] Add support for within-file rename of complicated fields
This was originally a part of D71880 but is separated for simplicity and ease
of reviewing.

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

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D91952
2020-11-27 03:59:28 +01:00
Adam Czachorowski 9d87739f66 [clangd] AddUsing: do not crash on non-namespace using decls.
Differential Revision: https://reviews.llvm.org/D92186
2020-11-26 20:07:56 +01:00
Aleksandr Platonov 1ca174b642 [clangd][query-driver] Extract target
In some cases system includes extractions is not enough, we also need target specific defines.
The problems appears when clang default target is not the same as toolchain's one (GCC cross-compiler, MinGW on Windows).
After this patch `query-driver` also extracts target and adds `--target=<extracted target>` compile option.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D92012
2020-11-26 15:08:26 +03:00
Nathan Ridge d1fd91ddaf [clangd] Do not treat line as inactive if skipped range ends at character position 0
Fixes https://github.com/clangd/clangd/issues/602

Differential Revision: https://reviews.llvm.org/D92148
2020-11-26 03:42:42 -05:00
Nathan Ridge c6cb47b640 [clangd] Collect main file refs by default
This is needed for call hierarchy to be able to find callers of
main-file-only functions.

Differential Revision: https://reviews.llvm.org/D92000
2020-11-25 20:33:57 -05:00
Richard Smith 3fb0879867 Refactor and simplify class scope name lookup.
This is partly in preparation for an upcoming change that can change the
order in which DeclContext lookup results are presented.

In passing, fix some obvious errors where name lookup's notion of a
"static member function" missed static member function templates, and
where its notion of "same set of declarations" was confused by the same
declarations appearing in a different order.
2020-11-25 16:25:33 -08:00
Sam McCall cbf336ad76 [clangd] Track deprecation of 'member' semantic token type in LSP. 2020-11-25 21:31:46 +01:00
Nathan James 73fdd99870
[clangd] Implement clang-tidy options from config
Added some new ClangTidyOptionsProvider like classes designed for clangd work flow.
These providers are designed to source the options on the worker thread but in a thread safe manner.
This is done through making the options getter take a pointer to the filesystem used by the worker thread which natuarally is from a ThreadsafeFS.
Internal caching in the providers is also guarded.

The providers don't inherit from `ClangTidyOptionsProvider` instead they share a base class which is able to create a provider for the `ClangTidyContext` using a specific FileSystem.
This approach means one provider can be used for multiple contexts even though `ClangTidyContext` owns its provider.

Depends on D90531

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D91029
2020-11-25 18:35:35 +00:00
Adam Czachorowski f6970503d2 [clangd] PopulateSwitch: disable on dependent enums.
If the enum is a dependent type, we would crash somewhere in
getIntWidth(). -Wswitch diagnostic doesn't work on dependent enums
either.

Differential Revision: https://reviews.llvm.org/D92051
2020-11-25 14:12:29 +01:00
Aaron Ballman ed242da0ff Fix a typo in the documentation to unbreak the sphinx builder. 2020-11-25 07:34:08 -05:00
Sam McCall a38d13ed36 [clangd] Use TimePoint<> instead of system_clock::time_point, it does matter after all. 2020-11-25 12:49:24 +01:00
Sam McCall d95db1693c [clangd] Extract common file-caching logic from ConfigProvider.
The plan is to use this to use this for .clang-format, .clang-tidy, and
compile_commands.json. (Currently the former two are reparsed every
time, and the latter is cached forever and changes are never seen).

Differential Revision: https://reviews.llvm.org/D88172
2020-11-25 12:09:13 +01:00
Haojian Wu 0cb38699a0 [clangd] Fix a tsan failure.
Tracer must be set up before calling any clangd-specific functions.
2020-11-25 11:47:44 +01:00
Haojian Wu fb6f425d1b [clangd] Add metrics for invalid name.
Differential Revision: https://reviews.llvm.org/D92082
2020-11-25 10:50:43 +01:00
Nathan Ridge 3d2c681f28 [clangd] Avoid type hierarchy crash on incomplete type
Fixes https://github.com/clangd/clangd/issues/597

Differential Revision: https://reviews.llvm.org/D92077
2020-11-25 03:45:00 -05:00
smhc 9c4df9eecb [clang-tidy] Support IgnoredRegexp configuration to selectively suppress identifier naming checks
The idea of suppressing naming checks for variables is to support code bases that allow short variables named e.g 'x' and 'i' without prefix/suffixes or casing styles. This was originally proposed as a 'ShortSizeThreshold' however has been made more generic with a regex to suppress identifier naming checks for those that match.

Reviewed By: njames93, aaron.ballman

Differential Revision: https://reviews.llvm.org/D90282
2020-11-25 01:18:44 +00:00
Adam Czachorowski a200501bca [clangd] Addusing tweak: find insertion point after definition
When type/function is defined in the middle of the file, previuosly we
would sometimes insert a "using" line before that definition, leading to
a compilation error. With this fix, we pick a point after such
definition in translation unit.

This is not a perfect solution. For example, it still doesn't handle
"using namespace" directives. It is, however, a significant improvement.

Differential Revision: https://reviews.llvm.org/D92053
2020-11-24 22:57:02 +01:00
Haojian Wu 1e821217cb [clangd] Add more trace spans for rename, NFC. 2020-11-24 19:57:05 +01:00
Adam Czachorowski f6e59294b6 [clangd] AddUsing: Used spelled text instead of type name.
This improves the behavior related to type aliases, as well as cases of
typo correction.

Differential Revision: https://reviews.llvm.org/D91966
2020-11-24 18:59:09 +01:00
Sam McCall 9e83d0bcdf [clangd] Mention when CXXThis is implicit in exposed AST.
Seeing an implicit this in the AST is pretty confusing I think.
While here, also mention when `this` is const.

Differential Revision: https://reviews.llvm.org/D91868
2020-11-24 16:57:56 +01:00
Kadir Cetinkaya f726101b62
[clangd] Fix shared-lib builds
Differential Revision: https://reviews.llvm.org/D91859
2020-11-24 13:05:20 +01:00
Nathan Ridge 5b6f47595b [clangd] Sort results of incomingCalls request by container name
Differential Revision: https://reviews.llvm.org/D92009
2020-11-24 03:29:02 -05:00
Nathan Ridge dced150375 [clangd] Use WorkScheduler.run() in ClangdServer::resolveTypeHierarchy()
Differential Revision: https://reviews.llvm.org/D91941
2020-11-23 20:44:14 -05:00
Nathan Ridge 0a4f99c494 [clangd] Call hierarchy (ClangdLSPServer layer)
Differential Revision: https://reviews.llvm.org/D91124
2020-11-23 20:44:07 -05:00
Nathan Ridge 4cb976e014 [clangd] Call hierarchy (ClangdServer layer)
Differential Revision: https://reviews.llvm.org/D91123
2020-11-23 20:43:41 -05:00
Nathan Ridge 3e6e6a2db6 [clangd] Call hierarchy (XRefs layer, incoming calls)
Support for outgoing calls is left for a future change.

Differential Revision: https://reviews.llvm.org/D91122
2020-11-23 20:43:38 -05:00
smhc 269ef315d1 [clang-tidy] Use compiled regex for AllowedRegexp in macro usage check
Current check compiles the regex on every attempt at matching. The check also populates and enables a regex value by default so the default behaviour results in regex re-compilation for every macro - if the check is enabled. If people used this check there's a reasonable chance they would have relatively complex regexes in use.

This is a quick and simple fix to store and use the compiled regex.

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D91908
2020-11-23 20:46:43 +00:00
Nathan James 9f3edc323a
[clang-tidy] Fix RenamerClangTidy checks trying to emit a fix that isnt a valid identifier
Addresses https://bugs.llvm.org/show_bug.cgi?id=48230.
Handle the case when the Fixup suggested isn't a valid c/c++ identifer.

Reviewed By: aaron.ballman, gribozavr2

Differential Revision: https://reviews.llvm.org/D91915
2020-11-23 20:04:51 +00:00
Stephen Kelly 76bd4444e3 Fix tests for clang-query completion 2020-11-23 15:23:13 +00:00