Commit Graph

6928 Commits

Author SHA1 Message Date
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
Stephen Kelly 5e1801813d Remove the IgnoreImplicitCastsAndParentheses traversal kind
Differential Revision: https://reviews.llvm.org/D91918
2020-11-23 14:27:48 +00:00
Utkarsh Saxena b31486ad97 [clangd] textDocument/implementation (LSP layer)
Differential Revision: https://reviews.llvm.org/D91721
2020-11-23 13:50:44 +01:00
Kadir Cetinkaya 61e538b15d
Revert "[clangd] testPath's final result agrees with the passed in Style"
This reverts commit 8cec8de2a4 as it
breaks windows buildbots.
2020-11-23 13:12:59 +01:00
Kadir Cetinkaya 8cec8de2a4
[clangd] testPath's final result agrees with the passed in Style
This was confusing, as testRoot on windows results in C:\\clangd-test
and testPath generated with posix explicitly still contained backslashes.

This patch ensures not only the relative part, but the whole final result
respects passed in Style.

Differential Revision: https://reviews.llvm.org/D91947
2020-11-23 12:45:06 +01:00
Kirill Bobyrev 1319c6624e [clangd] Get rid of clangToolingRefactoring dependency
D71880 makes this dependency redundant and we can safely remove it. Tested for
both shared lib build and static lib build.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D91951
2020-11-23 11:59:38 +01:00
Kirill Bobyrev cf39bdb490
[clangd] Implement Decl canonicalization rules for rename
This patch introduces new canonicalization rules which are used for AST-based
rename in Clangd. By comparing two canonical declarations of inspected nodes,
Clangd determines whether both of them belong to the same entity user would
like to rename. Such functionality is relatively concise compared to the
Clang-Rename API that is used right now. It also helps to overcome the
limitations that Clang-Rename originally had and helps to eliminate several
classes of bugs.

Clangd AST-based rename currently relies on Clang-Rename which has design
limitations and also lacks some features. This patch breaks this dependency and
significantly reduces the amount of code to maintain (Clang-Rename is ~2000 LOC,
this patch is just <30 LOC of replacement code).

We eliminate technical debt by simultaneously

* Maintaining feature parity and ensuring no regressions
* Opening a straightforward path to improving existing rename bugs
* Making it possible to add more capabilities to rename feature which would not
  be possible with Clang-Rename

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D71880
2020-11-23 11:42:56 +01:00
Kadir Cetinkaya fee78fb004
[clangd] Second attempt at fixing windows buildbots 2020-11-23 10:06:48 +01:00
Haojian Wu 66ace4dc02 [clang-tidy] Fix a nullptr-access crash in unused-raii-check.
I saw this crash in our internal production, but unfortunately didn't get
reproduced testcase, we likely hit this crash when the AST is ill-formed
(e.g. broken code).

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D91614
2020-11-23 09:44:19 +01:00
Kadir Cetinkaya 0dc2589d4a
[clangd] Attempt at fixing ExternalIndex tests on windows 2020-11-23 09:16:06 +01:00
Kadir Cetinkaya 655360096f
[clangd] Fix use-after-free in ProjectAwareIndex tests 2020-11-22 21:29:45 +01:00
Kadir Cetinkaya cab3136807
[clangd] Use ProjectAwareIndex in ClangdMain
Put project-aware-index between command-line specified static index and
ClangdServer indexes.

This also moves remote-index dependency from clangDaemon to ClangdMain
in an attempt to prevent cyclic dependency between clangDaemon and
remote-index-marshalling.

Differential Revision: https://reviews.llvm.org/D91860
2020-11-22 20:59:38 +01:00
Kadir Cetinkaya 067ffbfe60
[clangd] Introduce ProjectAwareIndex
An index implementation that can dispatch to a variety of indexes
depending on the file path. Enables clangd to work with multiple indexes in the
same instance, configured via config files.

Depends on D90749, D90746

Differential Revision: https://reviews.llvm.org/D90750
2020-11-22 20:59:37 +01:00
Kadir Cetinkaya c9776c8d4e
[clangd] Introduce config compilation for External blocks
Compilation logic for External blocks. A few of the high level points:
- Requires exactly one-of File/Server at a time:
  - Server is ignored in case of both, with a warning.
  - Having none is an error, would render ExternalBlock void.
- Ensures mountpoint is an absolute path:
  - Interprets it as relative to FragmentDirectory.
  - Defaults to FragmentDirectory when empty.
- Marks Background as Skip.

Depends on D90748.

Differential Revision: https://reviews.llvm.org/D90749
2020-11-22 20:59:37 +01:00
Kadir Cetinkaya 359e2f988d
[clangd] Introduce config parsing for External blocks
Enable configuration of remote and static indexes through config files
in addition to command line arguments.

Differential Revision: https://reviews.llvm.org/D90748
2020-11-22 20:59:37 +01:00
Nathan James 82c22f1248
[clangd] Fix compile error after 20b69af7
Some of the buildbots were failing due to what seems to be them using a non c++14 compilant std::string implementation.
Since c++14 std::basic_string::append(const basic_string, size_t, size_t) has a defaulted 3rd paramater, but some of the build bots were reporting that it wasn't defaulted in their implementation.
2020-11-22 10:48:48 +00:00
Nathan James 20b69af7c9
[clangd] Add clang-tidy options to config
First step of implementing clang-tidy configuration into clangd config.
This is just adding support for reading and verifying the clang tidy options from the config fragments.
No support is added for actually using the options within clang-tidy yet.

That will be added in a follow up as its a little more involved.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D90531
2020-11-22 10:04:01 +00:00
Sam McCall de5b0b776f [clangd] semanticTokens: fields are 'property', not 'member'
This isn't obvious, but vscode maps member as 'entity.name.function.member',
so it's really for member functions.

Fixes https://github.com/clangd/vscode-clangd/issues/105
2020-11-20 20:53:12 +01:00
Yitzhak Mandelbaum 88e6208562 [libTooling] Update Transformer's `node` combinator to include the trailing semicolon for decls.
Currently, `node` only includes the semicolon for (some) statements. However,
declarations have the same issue of (potentially) trailing semicolons, so `node`
should behave the same for them.

Differential Revision: https://reviews.llvm.org/D91872
2020-11-20 18:11:50 +00:00
Chris Kennelly e4f9b5d442 [clang-tidy] Include std::basic_string_view in readability-redundant-string-init.
std::string_view("") produces a string_view instance that compares
equal to std::string_view(), but requires more complex initialization
(storing the address of the string literal, rather than zeroing).

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D91009
2020-11-20 10:06:57 -05:00
Simon Pilgrim 44c96becc9 Fix MSVC "not all control paths return a value" warnings. NFCI. 2020-11-20 11:41:20 +00:00
Kirill Bobyrev da14ae23a5
[clangd] NFC: Reorder headers in tests accordig to Clang-Tidy 2020-11-20 10:38:41 +01:00
Sam McCall 8adc4d1ec7 [clangd] Add textDocument/ast extension method to dump the AST
This is a mass-market version of the "dump AST" tweak we have behind
-hidden-features.
I think in this friendlier form it'll be useful for people outside clang
developers, which would justify making it a real feature.
It could be useful as a step towards lightweight clang-AST tooling in clangd
itself (like matcher-based search).

Advantages over the tweak:
 - simplified information makes it more accessible, likely somewhat useful
   without learning too much clang internals
 - can be shown in a tree view
 - structured information gives some options for presentation (e.g.
   icon + two text colors + tooltip in vscode)
 - clickable nodes jump to the corresponding code
Disadvantages:
 - a bunch of code to handle different node types
 - likely missing some important info vs dump-ast due to brevity/oversight
 - may end up chasing/maintaining support for the long tail of nodes

Demo with VSCode support: https://imgur.com/a/6gKfyIV

Differential Revision: https://reviews.llvm.org/D89571
2020-11-20 01:13:28 +01:00
Sam McCall ad5a195ae5 [clangd] Express ASAN interactions of tests more clearly. NFC 2020-11-19 20:14:51 +01:00
Sam McCall d7747dacba [clangd] Also detect corrupt stri table size.
Differential Revision: https://reviews.llvm.org/D91299
2020-11-19 20:11:14 +01:00
Nathan James 617e8e5ee3
[clang-tidy] ElseAfterReturn check wont suggest fixes if preprocessor branches are involved
Consider this code:
```
if (Cond) {
#ifdef X_SUPPORTED
  X();
#else
  return;
#endif
} else {
  Y();
}
Z();```

In this example, if `X_SUPPORTED` is not defined, currently we'll get a warning from the else-after-return check. However If we apply that fix, and then the code is recompiled with `X_SUPPORTED` defined, we have inadvertently changed the behaviour of the if statement due to the else being removed. Code flow when `Cond` is `true` will be:
```
X();
Y();
Z();```
 where as before the fix it was:
 ```
 X();
 Z();```

 This patch adds checks that guard against `#endif` directives appearing between the control flow interrupter and the else and not applying the fix if they are detected.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D91485
2020-11-19 18:20:32 +00:00
Haojian Wu 734d2f98f6 [clangd] No crash on "-verify" mode.
If there is a "-verify" flag in the compile command, clangd will crash
(hit the assertion) inside the `~VerifyDiagnosticConsumer` (Looks like our
compiler invocation doesn't setup correctly?).

This patch disables the verify mode as it is rarely useful in clangd.

Differential Revision: https://reviews.llvm.org/D91777
2020-11-19 15:51:53 +01:00
Kirill Bobyrev 140783347a [clangd] Disable SerializationTest.NoCrashOnBadArraySize with ASAN
Address Sanitizer crashes on large allocations:

```c++
// Try to crash rather than hang on large allocation.
ScopedMemoryLimit MemLimit(1000 * 1024 * 1024); // 1GB
```
2020-11-19 13:24:55 +01:00
Balázs Kéri 47518d6a0a [clang-tidy] Improving bugprone-sizeof-expr check.
Do not warn for "pointer to aggregate" in a `sizeof(A) / sizeof(A[0])`
expression if `A` is an array of pointers. This is the usual way of
calculating the array length even if the array is of pointers.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D91543
2020-11-19 10:26:33 +01:00
Kadir Cetinkaya 7c2990b8af
[clangd] Fix data race in GoToInclude.All test 2020-11-19 08:47:43 +01:00
Chris Kennelly 25f5406f08 [clang-tidy] Extend bugprone-string-constructor-check to std::string_view.
This allows for matching the constructors std::string has in common with
std::string_view.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D91015
2020-11-18 21:16:03 -05:00
Yitzhak Mandelbaum 068da2c749 [clang-tidy] Allow `TransformerClangTidyCheck` clients to set the rule directly.
Adds support for setting the `Rule` field. In the process, refactors the code that accesses that field and adds a constructor that doesn't require a rule argument.

This feature is needed by checks that must set the rule *after* the check class
is constructed. For example, any check that maintains state to be accessed from
the rule needs this support. Since the object's fields are not initialized when
the superclass constructor is called, they can't be (safely) captured by a rule
passed to the existing constructor.  This patch allows constructing the check
superclass fully before setting the rule.

As a driveby fix, removed the "optional" from the rule, since rules are just a
set of cases, so empty rules are evident.

Differential Revision: https://reviews.llvm.org/D91544
2020-11-18 18:25:21 +00:00
Utkarsh Saxena 130da802ff Revert "Revert "[clangd] Implement textDocument/implementation (Xref layer)""
This reverts commit 0016ab6f36.

Fix: Consume error from Expected<T>.
2020-11-18 19:09:16 +01:00
Utkarsh Saxena 0016ab6f36 Revert "[clangd] Implement textDocument/implementation (Xref layer)"
This reverts commit 43243208fa.
2020-11-18 18:05:16 +01:00
Utkarsh Saxena 43243208fa
[clangd] Implement textDocument/implementation (Xref layer)
Xref layer changes for textdocument/implementation (https://microsoft.github.io/language-server-protocol/specification#textDocument_implementation)

This currently shows all functions (implementations) that overrides a virtual function.

Differential Revision: https://reviews.llvm.org/D91702
2020-11-18 17:06:47 +01:00
Haojian Wu aad3ea8983 [clangd] Remove the trailing "." in add-using message.
to be consistent witih other code actions.

Reviewed By: adamcz

Differential Revision: https://reviews.llvm.org/D91694
2020-11-18 14:46:26 +01:00
Nathan Ridge 9d77584fe0 [clangd] Call hierarchy (Protocol layer)
The protocol is based on the spec found here:
https://microsoft.github.io/language-server-protocol/specifications/specification-3-16/#textDocument_prepareCallHierarchy

Differential Revision: https://reviews.llvm.org/D89296
2020-11-18 03:41:31 -05:00
Utkarsh Saxena 4bc085f5b3 [clangd] Add OverridenBy Relation to index.
This was previously explored in reviews.llvm.org/D69094.

Differential Revision: https://reviews.llvm.org/D91610
2020-11-18 06:59:49 +01:00
Kadir Cetinkaya 5a9f386704
[clang-tidy] Make clang-format and include-order-check coherent
LLVM style puts both gtest and gmock to the end of the include list.
But llvm-include-order-check was only moving gtest headers to the end, resulting
in a false tidy-warning.

Differential Revision: https://reviews.llvm.org/D91602
2020-11-17 14:54:10 +01:00
Haojian Wu af0d607e72 [clang-tidy] Fix an abseil-redundant-strcat-calls crash on 0-parameter StrCat().
Differential Revision: https://reviews.llvm.org/D91601
2020-11-17 11:05:24 +01:00
Haojian Wu 218500d823 [clang-tidy] Verify the fixes in abseil-redundant-strcat-calls test, NFC 2020-11-17 10:15:29 +01:00
Felix Berger ace9653c11 [clang-tidy] performance-unnecessary-copy-initialization: Check for const reference arguments that are replaced template parameter type.
This fixes false positive cases where a non-const reference is passed to a
std::function but interpreted as a const reference.

Fix the definition of the fake std::function added in the test to match
std::function and make the bug reproducible.

Reviewed-by: aaron.ballman

Differential Revision: https://reviews.llvm.org/D90042
2020-11-16 17:08:18 -05:00
Zinovy Nis 4364539b3a [clang-tidy] Fix crash in bugprone-redundant-branch-condition on ExprWithCleanups
Bug: https://bugs.llvm.org/show_bug.cgi?id=48008

Differential Revision: https://reviews.llvm.org/D91037
2020-11-14 08:35:21 +03:00
Kadir Cetinkaya 8dc2aa0e41
[clangd] Canonicalize LLVM_ENABLE_ZLIB
It is used in our lit test's configuration now.
2020-11-13 18:20:37 +01:00
Kadir Cetinkaya 8741a76f5d
[clangd] Ensure we test for compatibility of serialized index format
Differential Revision: https://reviews.llvm.org/D91330
2020-11-13 17:06:23 +01:00
Kadir Cetinkaya 6e7dd1e3e1
[clangd] Assert on varint encoding
5th byte of a varint can't be bigger than 0x0f, fix a test and add an
assertion.

Differential Revision: https://reviews.llvm.org/D91405
2020-11-13 17:01:07 +01:00
Kirill Bobyrev a115248282
[clangd] Add missing tests to rename feature
This adds a couple of missed tests from existing clang-rename ones and
introduces several new ones (e.g. static class member). This patch is required
to ensure feature parity for migration off Clang-Rename API D71880.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D91337
2020-11-13 12:27:40 +01:00
Nathan James 06db8f984f
[clang-tidy] Merge options inplace instead of copying
Changed `ClangTidyOptions::mergeWith` to operate on the instance instead of returning a copy. The old mergeWith method has been renamed to merge and marked as nodiscard, to aid in disambiguating which one is which.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D91184
2020-11-12 18:19:12 +00:00
Kadir Cetinkaya 6484aa1add
[clangd] Simplify relations deserialization loop, NFC. 2020-11-12 10:33:39 +01:00
Sam McCall 686d8a0911 [clangd] Add index server request logging
- Add verbose logging of payloads
- Add public logging of request summaries
- fix non-logging of messages in request scopes (oops!)
- add test for public/non-public logging, extending pipeline_helper a bit.

We've accumulated quite a lot of duplication in the request handlers by now.
I should factor that out, but not in this patch...

Differential Revision: https://reviews.llvm.org/D90654
2020-11-11 23:58:18 +01:00
Duncan P. N. Exon Smith 4c55c3b66d Frontend: Change ComputePreambleBounds to take MemoryBufferRef, NFC
Avoid requiring an actual MemoryBuffer in ComputePreambleBounds, when
a MemoryBufferRef will do just fine.

Differential Revision: https://reviews.llvm.org/D90890
2020-11-11 17:19:51 -05:00
Sam McCall 3c09103291 [clangd] Sanity-check array sizes read from disk before allocating them.
Previously a corrupted index shard could cause us to resize arrays to an
arbitrary int32. This tends to be a huge number, and can render the
system unresponsive.

Instead, cap this at the amount of data that might reasonably be read
(e.g. the #bytes in the file). If the specified length is more than that,
assume the data is corrupt.

Differential Revision: https://reviews.llvm.org/D91258
2020-11-11 23:16:53 +01:00
Sam McCall 956c899296 [clangd] Fix serialization error check. 2020-11-11 20:46:04 +01:00
Aleksandr Platonov dad804a193 [clangd] Improve clangd-indexer performance
This is a try to improve clangd-indexer tool performance:
- avoid processing already processed files.
- use different mutexes for different entities (e.g. do not block insertion of references while symbols are inserted)

Results for LLVM project indexing:
- before: ~30 minutes
- after: ~10 minutes

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D91051
2020-11-11 14:38:06 +03:00
Kirill Bobyrev 91ce6fb5a6
[clangd] Abort rename when given the same name
When user wants to rename the symbol to the same name we shouldn't do any work.
Bail out early and return error to save compute.

Resolves: https://github.com/clangd/clangd/issues/580

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D91134
2020-11-11 11:13:47 +01:00
Kirill Bobyrev 8e9bde34e7 [clangd] NFC: Add more logging to remote index test 2020-11-11 08:24:09 +01:00
Nathan James e076fee63d
[clang-tidy][NFC] Tweak GlobList to iterate backwards
By iterating backwards over the globs we can exit the loop as soon as we find a match.

While we're here:
 - Regex doesn't need to be mutable.
 - We can reserve the amount of Globs needed ahead of time.
 - Using a SmallVector with size 0 is slightly more space efficient than a std::vector.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D91033
2020-11-10 14:27:24 +00:00
Haojian Wu a97d7b9159 Fix the buildbot failure.
Looks like we hit a bug in iterator of DeclContextLookupResult, workaround
by a forloop.

http://45.33.8.238/win/27605/step_4.txt
2020-11-10 13:11:54 +01:00
Kirill Bobyrev 47fcf233ce
[clangd] Fix recommended gRPC version
Typo: 1.32.2 does not exist, it should be 1.33.2 https://github.com/grpc/grpc/releases/tag/v1.33.2
2020-11-10 15:07:03 +03:00
Haojian Wu 71064b0270 [clangd] Bump index version number.
https://reviews.llvm.org/D89670 changed the Ref structure, we need to
bump the version to invalidate all stored stale data, otherwise we will
get ` Error while reading shard: malformed or truncated refs` when
building the background index.

Differential Revision: https://reviews.llvm.org/D91131
2020-11-10 10:31:59 +01:00
Kirill Bobyrev 085f900830 [clangd] Update remote index documentation
* Even though remote index is still somewhat experimental, it can now be
  used withing clangd itself: this should be the primary way of trying
  it out
* Remove `protobuf-compiler` from list of needed Debian packages as it
  `protobuf-compiler-grpc` already depends on it
* Bump recommended gRPC version to 1.32.3
2020-11-10 10:18:38 +01:00
Kirill Bobyrev ca892f46fe
[clangd] Enhance Clangd rename testing coverage
We plan to eliminate error-prone and obsolete Clang-Rename API from Clangd. To
do that, we will introduce Decl canonicalization rules that will make renaming
code simpler and easier to maintain (D71880).

To ensure smooth transition to the new implementation, many Clang-Rename tests
will be adopted in Clangd to prevent any possible regressions. This patch is
the first in the chain of test migration patches. It improves existing tests
and adopts tests from Clang-Rename's alias, class and enum testing files.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D91102
2020-11-10 10:08:49 +01:00
Haojian Wu daa736da10 [clangd] Add basic conflict detection for the rename.
With this patch, we reject the rename if the new name would conflict with
any other decls in the decl context of the renamed decl.

Differential Revision: https://reviews.llvm.org/D89790
2020-11-10 08:52:30 +01:00
Kirill Bobyrev 142c6f82fd
[clang] Simplify buildSyntaxTree API
Follow-up on https://reviews.llvm.org/D88553#inline-837013

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D90672
2020-11-09 22:49:54 +01:00
Kadir Cetinkaya 7df6340e6f
[clangd] Fix shared-lib builds
This breaks a cyclic dependency. clangDeamon doesn't need to depend on
clangdRemoteIndex yet.
2020-11-09 22:15:08 +01:00
Kirill Bobyrev 2c2680a470
[clangd] NFC: Fix a typo in Tracer name 2020-11-09 21:18:35 +01:00
Aleksandr Platonov 1bbf87e22a [clangd][remote] Check an index file correctly
There is not reason to check `std::make_unique<...>(..)` return value,
but `clangd::clang::loadIndex()` returns `nullptr` if an index file could not be loaded (e.g. incorrect version).

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D91049
2020-11-09 21:40:45 +03:00
Frank Derry Wanye 9ca6fc4e09 Add a new altera kernel name restriction check to clang-tidy.
The altera kernel name restriction check finds kernel files and include
directives whose filename is "kernel.cl", "Verilog.cl", or "VHDL.cl".
Such kernel file names cause the Altera Offline Compiler to generate
intermediate design files that have the same names as certain internal
files, which leads to a compilation error.

As per the "Guidelines for Naming the Kernel" section in the "Intel FPGA
SDK for OpenCL Pro Edition: Programming Guide."

This reverts the reversion from 43a38a6523.
2020-11-09 09:26:50 -05:00
Nathan James f0922efdde
[clang-tidy] Remove bad assert after 3b9b90a1
Forgot to remove it on push, just there to help debugging
2020-11-09 13:21:55 +00:00
Nathan James 5918ef8b1a
[clangd] Handle duplicate enum constants in PopulateSwitch tweak
If an enum has different names for the same constant, make sure only the first one declared gets added into the switch. Failing to do so results in a compiler error as 2 case labels can't represent the same value.

```
lang=c
enum Numbers{
One,
Un = One,
Two,
Deux = Two,
Three,
Trois = Three
};

// Old behaviour
switch (<Number>) {
  case One:
  case Un:
  case Two:
  case Duex:
  case Three:
  case Trois: break;
}

// New behaviour
switch (<Number>) {
  case One:
  case Two:
  case Three: break;
}
```

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D90555
2020-11-09 12:14:53 +00:00
Sam McCall 053110b22a [clangd] Don't run clang-tidy AST traversal if there are no checks.
While here, clean up ParsedAST::build a bit:
 - remove FIXMEs that were fixed long ago by ReplayPreamble
 - remove redundant if, ClangTidyContext is not actually optional

Differential Revision: https://reviews.llvm.org/D90975
2020-11-09 08:44:06 +01:00
Nathan James 4dde325004
[clang-tidy] Fix build for gcc5.3 after d725f1ce 2020-11-08 17:25:18 +00:00
Nathan James d725f1ce53
[clang-tidy] Use vfs::FileSystem when getting config
The config providers that look for configuration files currently take a pointer to a FileSystem in the constructor.
For some reason this isn't actually used when trying to read those configuration files, Essentially it just follows the behaviour of the real filesystem.
Using clang-tidy standalone this doesn't cause any issue.
But if its used as a library and the user wishes to use say an `InMemoryFileSystem` it will try to read the files from the disc instead.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D90992
2020-11-07 19:18:02 +00:00
Nathan James 062b5c598f
[clangd] Set the User option for clang-tidy to mimick its behaviour
Probably not essential as afaik only one check uses this field. but still good to have consistent behaviour.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D90552
2020-11-06 19:58:21 +00:00
Nathan James 3b9b90a191
[clang-tidy] Extend IdentifierNamingCheck per file config
Add IgnoreMainLikeFunctions to the per file config. This can be extended for new options added to the check easily.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D90832
2020-11-05 19:51:05 +00:00
Utkarsh Saxena f253823398 [clangd] Trivial: Log missing completion signals.
Differential Revision: https://reviews.llvm.org/D90828
2020-11-05 18:52:44 +01:00
Kadir Cetinkaya ed424b4288
[clangd] Cleanup dependencies around RemoteIndex
RemoteIndexClient implementations only depends on clangdSupport for
logging functionality and has no dependence on clangDeamon itself. This clears
out that link time dependency and enables depending on it in clangDeamon itself,
so that we can have other index implementations that makes use of the
RemoteIndex.

Differential Revision: https://reviews.llvm.org/D90746
2020-11-04 16:58:11 +01:00
Balázs Kéri d1b2a52319 [clang-tidy] Add signal-handler-check for SEI CERT rule SIG30-C
SIG30-C. Call only asynchronous-safe functions within signal handlers

First version of this check, only minimal list of functions is allowed
("strictly conforming" case), for C only.

Differential Revision: https://reviews.llvm.org/D87449
2020-11-04 16:42:30 +01:00
Aaron Ballman 45e0f65162 Add a floating-point suffix to silence warnings; NFC
This silences about 6000 warnings about truncating from double to float
with Visual Studio.
2020-11-04 10:09:51 -05:00
Kadir Cetinkaya a57550def1
[clangd] Pass parameters to config apply functions
This will enable some fragments to apply their features selectively.

Depends on D90270.

Differential Revision: https://reviews.llvm.org/D90455
2020-11-04 10:29:24 +01:00
Nathan Ridge 3bec07f91f [clangd] Store the containing symbol for refs
This is needed to implement call hierarchy.

Differential Revision: https://reviews.llvm.org/D89670
2020-11-04 03:21:45 -05:00
Nathan James cb9d0e8819
[clangd][NFC] Make Located::operator->() use pointer sematics
This enables using the arrow operator to access members of the contained item.
```lang=c++
Located<std::string> X;
const char* CStr = X->c_str();
```
This is inline with how classes like `Optional` handle the arrow operator.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D90682
2020-11-04 01:36:14 +00:00
Kadir Cetinkaya 05e0a8e519
[clangd] Fix missing override warnings in remote-index client 2020-11-03 21:46:44 +01:00
Kadir Cetinkaya 7f059a258a
[clangd] Handle absolute/relative path specifications in Config
This introduces a mechanism for providers to interpret paths specified
in a fragment either as absolute or relative to fragment location.
This information should be used during compile stage to handle blocks correctly.

Differential Revision: https://reviews.llvm.org/D90270
2020-11-03 21:45:35 +01:00
Hiral Oza d6a468d622 [clang-tidy] adding "--config-file=<file-path>" to specify custom config file.
Let clang-tidy to read config from specified file.
Example:
$ clang-tidy --config-file=/some/path/myTidyConfig --list-checks --
...this will read config from '/some/path/myTidyConfig'.

ClangTidyMain.cpp reads ConfigFile into string and then assigned read data to 'Config' i.e. makes like '--config' code flow internally.

May speed-up tidy runtime since now it will just look-up <file-path>
instead of searching ".clang-tidy" in parent-dir(s).

Directly specifying config path helps setting build dependencies.

Thanks to @DmitryPolukhin for valuable suggestion. This patch now propose
change only in ClangTidyMain.cpp.

Reviewed By: DmitryPolukhin

Differential Revision: https://reviews.llvm.org/D89936
2020-11-03 11:59:46 +00:00
Sam McCall 65eaec9bd3 [clangd] Add -log=public to redact all request info from index server logs
The index server has access to potentially-sensitive information, e.g. a
sequence of fuzzyFind requests reveals details about code completions in the
editor which in turn reveals details about the code being edited.
This information is necessary to provide the service, and our intention[1] is it
should never be retained beyond the scope of the request (e.g. not logged).

At the same time, some log messages should be exposed:
 - server startup/index reloads etc that don't pertain to a user request
 - basic request logs (method, latency, #results, error code) for monitoring
 - errors while handling requests, without request-specific data
The -log=public design accommodates these by allowing three types of logs:
 - those not associated with any user RPC request (via context-propagation)
 - those explicitly tagged as [public] in the log line
 - logging of format strings only, with no interpolated data (error level only)

[1] Specifically: Google is likely to run public instances of this server
for LLVM and potentially other projects, they will run in this configuration.
The details agreed in a Google-internal privacy review.
As clangd developers, we'd encourage others to use this configuration for public
instances too.

Differential Revision: https://reviews.llvm.org/D90526
2020-11-02 21:25:12 +01:00
Sam McCall c29513f7e0 [clangd] Fix check-clangd with no clang built
- pass required=False to use_clang(), as we don't need it
- fix required=False (which was unused and rotted):
  - make derived substitutions conditional on it
  - add a feature so we can disable tests that need it
- conditionally disable our one test that depends on %resource_dir.
  This doesn't seem right from first principles, but isn't a big deal.

Differential Revision: https://reviews.llvm.org/D90528
2020-11-02 21:10:43 +01:00
Shoaib Meenai 6bd01b8184 [clangd] Account for vendor in version string
The vendor will be prefixed to the "clangd" and can be an arbitrary
string, so account for it in the test.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D90517
2020-11-02 09:04:44 -08:00
Nico Weber c88390468c Revert "Add a new altera kernel name restriction check to clang-tidy."
This reverts commit 43a38a6523,
and follow-up 5a7bc5e259.

The commit breaks check-clang-tools, the test added in the change
does not pass.
2020-11-02 10:30:42 -05:00
Aaron Ballman 5a7bc5e259 Fix link to a new check within the release notes. 2020-11-02 10:19:24 -05:00
Frank Derry Wanye 43a38a6523 Add a new altera kernel name restriction check to clang-tidy.
The altera kernel name restriction check finds kernel files and include
directives whose filename is "kernel.cl", "Verilog.cl", or "VHDL.cl".
Such kernel file names cause the Altera Offline Compiler to generate
intermediate design files that have the same names as certain internal
files, which leads to a compilation error.

As per the "Guidelines for Naming the Kernel" section in the "Intel FPGA
SDK for OpenCL Pro Edition: Programming Guide."
2020-11-02 10:11:38 -05:00
David Sanders a07a2c88d9 Use --use-color in run-clang-tidy.py
Now that clang-tidy supports the --use-color command line option, it's
a better user experience to use --use-color in run-clang-tidy.py and
preserving the colored output.
2020-11-02 08:38:20 -05:00
Kadir Cetinkaya 0df197516b
[clangd] Value initialize SymbolIDs
We were default initializing SymbolIDs before, which would leave
indeterminate values in underlying std::array.

This patch updates the underlying data initalization to be value-init and adds a
way to check for validness of a SymbolID.

Differential Revision: https://reviews.llvm.org/D90397
2020-11-02 11:37:47 +01:00
Kirill Bobyrev d0beda1b66 [clangd] Improve remote-index test
Introduce a separate thread that will kill `clangd-index-server` after 10 seconds regardless. This helps shut down the test if the server hangs and `stderr.readline()` does not contain inititalizatiton message. It prevents "necessary" waiting delay for the server warm-up and only introduces additional delay if the test fails.

It also makes use of `subprocess.Popen.kill()` which is a portable way of handling process shutdown and avoids using signals.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D90590
2020-11-02 10:55:17 +01:00
Kirill Bobyrev 76a168bce0 [clangd] Add lit tests for remote index
Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D90291
2020-11-02 08:38:16 +01:00
Ilya Golovenko 6d15a28a85 [clangd] Fix ParsedASTTest.TopLevelDecls test.
Google test matcher `DeclKind` uses `NamedDecl::getDeclKindName()` to compare its result with expected declaration name.
Both, returned value of this function and the expected kind name argument have type `const char *`, so this matcher effectively
compares two pointers instead of the respective strings.

The test was passing on most platforms because compilers mostly were able to coalesce these string literals.

Patch By: Ilya Golovenko

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D90384
2020-11-02 08:37:04 +01:00
David Sanders d915d403d7 Use ANSI escape codes for --use-color on Windows
On Windows the --use-color option cannot be used for its originally
intended purpose of forcing color when piping stdout, since Windows
does not use ANSI escape codes by default. This change turns on ANSI
escape codes on Windows when forcing color to a non-displayed stdout
(e.g. piped).
2020-10-31 10:36:42 -04:00
Pedro Gonnet 43e451f9f3 Fix gendered documentation
Changed two references to developers as "he" or "him" to the more neutral "they".

Reviewed By: JDevlieghere, sylvestre.ledru

Differential Revision: https://reviews.llvm.org/D78807
2020-10-31 12:17:19 +01:00
Nathan James 8a28a29c73
[clang-tidy][test] Fix test failure when LLVM_ENABLE_WERROR is set.
After https://reviews.llvm.org/D80531 landed, a subtle bug was introduced where the test would fail if `LLVM_ENABLE_WERROR` was set. This just silences that error so the test case runs correctly, down the line it may be worth not enabling `-Werror` for clang-tidy tests even if the cmake flag is passed.
2020-10-30 23:17:11 +00:00
Simon Pilgrim 888969f62a [clangd] Fix MSVC implicit capture build failure.
MSVC builds were failing because the constexpr wasn't couldn't be captured by the lamdba.

Fix an implicit double to float truncation warning as well.
2020-10-30 11:36:59 +00:00
Nico Weber f1e0944fe5 clang-tidy: Make tests more hermetic
Make check_clang_tidy.py not just pass -format-style=none by default
but a full -config={}. Without this, with a build dir outside of
the llvm root dir and a .clang-tidy config further up that contains

  CheckOptions:
    - key:          modernize-use-default-member-init.UseAssignment
      value:        1

these tests would fail:

   Clang Tools :: clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer-modernize-use-default-member-init.cpp
   Clang Tools :: clang-tidy/checkers/modernize-use-default-member-init-bitfield.cpp
   Clang Tools :: clang-tidy/checkers/modernize-use-default-member-init.cpp

After this change, they pass fine, despite the unrelated
.clang-tidy file further up.
2020-10-29 20:14:57 -04:00
Utkarsh Saxena 7df80a1204 [clangd] Add support for multiple DecisionForest model experiments.
With every incremental change, one needs to check-in new model upstream.
This also significantly increases the size of the git repo with every
new model.
Testing and comparing the old and previous model is also not possible as
we run only a single model at any point.

One solution is to have a "staging" decision forest which can be
injected into clangd without pushing it to upstream. Compare the
performance of the staging model with the live model. After a couple of
enhancements have been done to staging model, we can then replace the
live model upstream with the staging model. This reduces upstream churn
and also allows us to compare models with current baseline model.

This is done by having a callback in CodeCompleteOptions which is called
only when we want to use a decision forest ranking model. This allows us
to inject different completion model internally.

Differential Revision: https://reviews.llvm.org/D90014
2020-10-29 19:49:40 +01:00
Sam McCall 1d773a4ff0 [CMake] Support inter-proto dependencies in generate_protos.
Differential Revision: https://reviews.llvm.org/D90215
2020-10-29 10:04:20 +01:00
Sam McCall 5627ae6c50 [clangd] Support CodeActionParams.only
Differential Revision: https://reviews.llvm.org/D89126
2020-10-29 09:44:08 +01:00
Sam McCall 0e94836989 [clangd] Go-to-definition from non-renaming alias is unambiguous.
It's not helpful to show the alias itself as an option.
This fixes a regression accepted in f24649b77d.

Differential Revision: https://reviews.llvm.org/D89238
2020-10-28 20:17:35 +01:00
Sam McCall 87f03e13ce [clangd] Don't offer to expand auto in structured binding declarations.
auto must be used for the code to parse.

Differential Revision: https://reviews.llvm.org/D89700
2020-10-28 18:55:23 +01:00
Kadir Cetinkaya 68b48339e5
[clangd] Fix a null dereference in tests. 2020-10-28 18:24:26 +01:00
Nathan James 556ee675c1
[clang-tidy][NFC] IdentifierNaming: Remove unnecessary string allocations
Remove the need to heap allocate a string for each style option lookup while reading or writing options.p

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D90244
2020-10-28 15:49:51 +00:00
Kirill Bobyrev 5ad6bbacf0
[clangd] Start using SyntaxTrees for folding ranges feature
This is an initial attempt to start using Syntax Trees in clangd while improving state of folding ranges feature and experimenting with Syntax Tree capabilities.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D88553
2020-10-27 16:47:35 +01:00
Kirill Bobyrev d26dd74308 [clangd] Separate final_result into a different message
This is a breaking change in remote index protocol.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D89851
2020-10-27 11:46:16 +01:00
Sam McCall 2ef2841c0d [clangd] Fix proto deps, for real this time.
This is ugly (layering violation) but we can clean it up once we know it
works in CI.
2020-10-27 09:15:42 +01:00
Nathan Ridge 245b61a330 [clangd] Increase the TooMany limit for index-based textual navigation to 5
Differential Revision: https://reviews.llvm.org/D90134
2020-10-27 01:49:09 -04:00
Kirill Bobyrev d071bba9a4 [clangd] Add back dependency on proto generated targets
Previous attempts:

* 15f6bad6d7
* 58d0ef2d04

The combination results in both link- and build-time dependency which is
the desired behavior.
2020-10-26 20:39:10 +01:00
Joe Turner 1e076a8d80 Make sure Objective-C category support in IncludeSorter handles top-level imports
Currently, this would not correctly associate a category with the related include if it was top-level (i.e. no slashes in the path). This ensures that we explicitly think about that case.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D89608
2020-10-26 12:24:43 -07:00
Benjamin Kramer 26750a1264 [clang-tidy] Silence unused variable warning in Release builds. NFCI.
ExpandModularHeadersPPCallbacks.cpp:55:15: warning: unused variable 'FileEntry'
    for (auto FileEntry : FilesToRecord)
              ^
2020-10-26 20:20:23 +01:00
Kirill Bobyrev 1704704e76
[clangd] NFC: Update FIXME comment regarding lack of c/dtor support
Both `SymbolKind` and `indexSymbolKindToSymbolKind` support constructors and
separate them into a different category from regular methods.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D89935
2020-10-26 15:31:59 +01:00
Kirill Bobyrev 58d0ef2d04 [clangd] Fix remote index build failures due to lack of proto dependency
Previous attempt (15f6bad6d7) introduced
add_dependencies but unfortunately it does not actually add a dependency
between RemoteIndexProto and RemoteIndexServiceProto. This is likely due
to some requirements of it that clang_add_library violates.

As a workaround, we will link RemoteIndexProto library to
RemoteIndexServiceProto which is logical because the library can not be
without linking to RemoteIndexProto anyway.
2020-10-26 14:14:47 +01:00
Kirill Bobyrev 15f6bad6d7
[clangd] Add dependency on remote index service proto
It requires Index.proto to be built first. Failed builds:
https://github.com/clangd/clangd/runs/1305985916
2020-10-26 07:08:49 +01:00
Nathan Ridge aaa8b44d19 [clangd] Add a TestWorkspace utility
TestWorkspace allows easily writing tests involving multiple
files that can have inclusion relationships between them.

BackgroundIndexTest.RelationsMultiFile is refactored to use
TestWorkspace, and moved to FileIndexTest as it no longer
depends on BackgroundIndex.

Differential Revision: https://reviews.llvm.org/D89297
2020-10-24 20:15:17 -04:00
Duncan P. N. Exon Smith 434f3774f6 clangd: Stop calling FileEntryRef::FileEntryRef
In `ReplayPreamble::replay`, use `getFileRef` instead of `getFile`, and
then use that `FileEntryRef` later to avoid needing
`FileEntryRef::FileEntryRef`. The latter is going to become private to
`FileManager` in a later commit.
2020-10-23 21:28:09 -04:00
Kadir Cetinkaya 5dd39923a0
[clangd] Fix remote-server build and add it to check-clangd
Differential Revision: https://reviews.llvm.org/D90047
2020-10-23 18:08:02 +02:00
Sam McCall ce63383e45 [clangd] Drop version from remote index proto names, fix clangd-index-server
We only need to version these messages if they actually diverge.
Unlike the service, the namespace name isn't part of the wire format.

clangd-index-server was broken by 81e5f298c4
as the namespace names weren't updated there, this fixes it (by adding
them for the service, and not requiring them elsewhere).
2020-10-23 15:28:11 +02:00
Sam McCall e6c1c3f97f [clang] Split remote index service definition into a separate file.
This allows it to have a separate namespace (grpc versioned service) without
putting versioning info on all of the other protos (before we need it).

clang-index-server is still broken (from 81e5f298c4).

Differential Revision: https://reviews.llvm.org/D90031
2020-10-23 15:20:51 +02:00
Kirill Bobyrev e6c4d880fa [clangd] NFC: Add using directives to avoid spelling out llvm::sys::path
`llvm::sys::path` is used a lot in the remote index marshalling code. We can save space by avoiding spelling it out explicitly for most functions and times.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D90016
2020-10-23 14:38:31 +02:00
Sam McCall 81f7b2ac0f [CMake] generate_grpc_protos -> generate_protos(... GRPC). NFC
Differential Revision: https://reviews.llvm.org/D90027
2020-10-23 14:28:07 +02:00
Kirill Bobyrev 421a2a0dbb [clangd] Migrate to proto2 syntax
This allows us to check whether enum field is actually sent over the wire or missing.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D89882
2020-10-23 14:27:15 +02:00
Dmitry Polukhin 55a2deed07 [clang-tidy] Fix redefinition of module in the same module.modulemap file
In memory VFS cannot handle aceesssing the same file with different paths.
This diff just stops using VFS for modulemap files.

Fixes PR47839

Differential Revision: https://reviews.llvm.org/D89886
2020-10-23 13:20:18 +01:00
Kirill Bobyrev 68486f9c3a [clangd] Get rid of llvm::Optional in Remote- and LocalIndexRoot; NFC
Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D89852
2020-10-22 21:47:48 +02:00
Kirill Bobyrev 81e5f298c4 [clangd] Give the server information about client's remote index protocol version
And also introduce Protobuf package versioning, it will help to deal
with breaking changes. Inroducing package version itself is a breaking
change, clients and servers need to be updated.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D89862
2020-10-22 21:35:18 +02:00
Duncan P. N. Exon Smith 156e8b3702 clang/Basic: Remove ContentCache::getRawBuffer, NFC
Replace `ContentCache::getRawBuffer` with `getBufferDataIfLoaded` and
`getBufferIfLoaded`, excising another accessor for the underlying
`MemoryBuffer*` in favour of `StringRef` and `MemoryBufferRef`.

Differential Revision: https://reviews.llvm.org/D89445
2020-10-22 14:00:44 -04:00
Alexander Kornienko 37558fd29e [clang-tidy] Add links to check docs in comments 2020-10-22 13:31:21 +02:00
Felix Berger 1c1f794c2b Always allow std::function to be copied.
Since its call operator is const but can modify the state of its underlying
functor we cannot tell whether the copy is necessary or not.

This avoids false positives.

Reviewed-by: aaron.ballman, gribozavr2

Differential Revision: https://reviews.llvm.org/D89332
2020-10-21 17:20:35 -04:00
David Goldman d5c022d846 [clangd][ObjC] Support nullability annotations
Nullability annotations are implmented using attributes; previusly
clangd would skip over AttributedTypeLoc since their location
points to the attribute instead of the modified type.

Also add some test cases for this.

Differential Revision: https://reviews.llvm.org/D89579
2020-10-20 17:36:32 -04:00
Mikhail Maltsev 7819411837 [clang] Use SourceLocation as key in hash maps, NFCI
The patch adjusts the existing `llvm::DenseMap<unsigned, T>` and
`llvm::DenseSet<unsigned>` objects that store source locations, so
that they use `SourceLocation` directly instead of `unsigned`.

This patch relies on the `DenseMapInfo` trait added in D89719.

It also replaces the construction of `SourceLocation` objects from
the constants -1 and -2 with calls to the trait's methods `getEmptyKey`
and `getTombstoneKey` where appropriate.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D69840
2020-10-20 16:24:09 +01:00
Mikhail Maltsev 234c47ae2a [clang][Basic] Make SourceLocation usable as key in hash maps, NFCI
This change creates a `DenseMapInfo` trait specialization for the
SourceLocation class. The empty key, the tombstone key, and the hash
function are identical to `DenseMapInfo<unsigned>`, because we already
have hash maps that use raw the representation of `SourceLocation` as
a key.

The update of existing `DenseMap`s containing raw representation of
`SourceLocation`s will be done in a follow-up patch. As an example
the patch makes use of the new trait in one instance:
clang-tidy/google/UpgradeGoogletestCaseCheck.{h,cpp}

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D89719
2020-10-20 15:52:59 +01:00
Georgii Rymar 6487ffafd1 Reland "[yaml2obj][ELF] - Simplify the code that performs sections validation."
This reverts commit 1b589f4d4d and relands the D89463
with the fix: update `MappingTraits<FileFilter>::validate()` in ClangTidyOptions.cpp to
match the new signature (change the return type to "std::string" from "StringRef").

Original commit message:

This:

Changes the return type of MappingTraits<T>>::validate to std::string
instead of StringRef. It allows to create more complex error messages.

It introduces std::vector<std::pair<StringRef, bool>> getEntries():
a new virtual method of Section, which is the base class for all sections.
It returns names of special section specific keys (e.g. "Entries") and flags that says if them exist in a YAML.
The code in validate() uses this list of entries descriptions to generalize validation.
This approach was discussed in the D89039 thread.

Differential revision: https://reviews.llvm.org/D89463
2020-10-20 16:25:33 +03:00
Aleksandr Platonov d99b2a976a [clangd][remote] Add Windows paths support
Without this patch 6 marshalling tests fail on Windows.
This patch contains the following changes:
- Allow paths with Windows slashes (convert to the POSIX style instead of assertion)
- Add support for URI with Windows path.
- Change the value of the second parameter of several `llvm::sys::path::convert_to_slash()` calls: we should use `windows` instead of `posix` to ensure UNIX slashes in the path.
- Port `RemoteMarshallingTest::IncludeHeaderURI` test to Windows.

Reviewed By: kbobyrev

Differential Revision: https://reviews.llvm.org/D89529
2020-10-20 13:04:20 +03:00
Kirill Bobyrev 691eb814c1
[clangd] NFC: Resolve Clang-Tidy warnings in Protocol.cpp
Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D89771
2020-10-20 11:23:40 +02:00
Richard Smith c7a7bba8c1 Fixup clang-tidy after recent Clang change. 2020-10-19 20:13:56 -07:00
Duncan P. N. Exon Smith b3eff6b7bb Lexer: Update the Lexer to use MemoryBufferRef, NFC
Update `Lexer` / `Lexer::Lexer` to use `MemoryBufferRef` instead of
`MemoryBuffer*`. Callers that were acquiring a `MemoryBuffer*` via
`SourceManager::getBuffer` were updated, such that if they checked
`Invalid` they use `getBufferOrNone` and otherwise `getBufferOrFake`.

Differential Revision: https://reviews.llvm.org/D89398
2020-10-19 19:10:21 -04:00
Yaxun (Sam) Liu 52bcd691cb Recommit "[CUDA][HIP] Defer overloading resolution diagnostics for host device functions"
This recommits 7f1f89ec8d and
40df06cdaf with bug fixes for
memory sanitizer failure and Tensile build failure.
2020-10-19 17:48:04 -04:00
Nathan James 86ef379800
[clang-tidy] Add scoped enum constants to identifier naming check
Added option `ScopedEnumConstant(Prefix|Case|Suffix)` to readability-identitied-naming.
This controls the style for constants in scoped enums, declared as enum (class|struct).
If this option is unspecified the EnumConstant style will be used instead.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D89407
2020-10-19 15:57:47 +01:00
Sam McCall cf814fcd39 [clangd] Add test for structured-binding completion. NFC 2020-10-19 16:45:51 +02:00
Aaron Ballman b91a236ee1 Revert "Extend tests of run-clang-tidy"
This reverts commit 627c01bee0.

Some failing build bots:
http://lab.llvm.org:8011/#/builders/109/builds/690
http://lab.llvm.org:8011/#/builders/14/builds/476
2020-10-19 10:37:22 -04:00
Alexander Lanin 627c01bee0 Extend tests of run-clang-tidy
new test: parsing and using compile_commands
new test: export fixes to yaml file
old test extended with CHECK-MESSAGES in order to ensure that they "fail as intended"
2020-10-19 10:29:08 -04:00
Nathan James 866dc09784
[clang-tidy] Better support for Override function in RenamerClangTidy based checks
Methods that override virtual methods will now get renamed if the initial virtual method has a name violation.
Addresses https://bugs.llvm.org/show_bug.cgi?id=34879

Reviewed By: alexfh

Differential Revision: https://reviews.llvm.org/D79674
2020-10-19 15:21:06 +01:00
Kadir Cetinkaya 4074914103
[clangd] Rename edge name for filesymbols to slabs in memorytree
This was causing duplicate `symbols` components on the path as both the
edge from an index to filesymbols and filesymbols to symbolslabs were named
symbols.

Differential Revision: https://reviews.llvm.org/D89685
2020-10-19 16:09:46 +02:00
Nathan James accda625b8
[nfc][clang-change-namespace] Remove unnecessary isScoped EnumDecl Matcher 2020-10-19 12:53:51 +01:00
Kadir Cetinkaya d0f287464d
[clangd] Add $/memoryUsage LSP extension
Performs a detailed profiling of clangd lsp server and conveys the
result to the client as a json object. It is of the form:
   {
     "_self": 0,
     "_total": 8,
     "child1": {
       "_self": 4,
       "_total": 4,
     }
     "child2": {
       "_self": 2,
       "_total": 4,
       "child_deep": {
         "_self": 2,
         "_total": 2,
       }
     }
   }

Differential Revision: https://reviews.llvm.org/D89277
2020-10-19 12:30:25 +02:00
Nathan James ce619f645f
[NFC][clang-tidy] Use isInStdNamespace matcher instead of check defined alternatives 2020-10-18 16:02:11 +01:00
Nathan James 5f88c3b639
[clang tidy] Fix SIMDIntrinsicsCheck not storing options 2020-10-18 15:56:39 +01:00
Nathan James 8a548bc203
[clang-tidy] modernize-loop-convert reverse iteration support
Enables support for transforming loops of the form
```
for (auto I = Cont.rbegin(), E = Cont.rend(); I != E;++I)
```

This is done automatically in C++20 mode using `std::ranges::reverse_view` but there are options to specify a different function to reverse iterator over a container.
This is the first step, down the line I'd like to possibly extend this support for array based loops
```
for (unsigned I = Arr.size() - 1;I >=0;--I) Arr[I]...
```

Currently if you pass a reversing function with no header in the options it will just assume that the function exists, however as we have the ASTContext it may be as wise to check before applying, or at least lower the confidence level if we can't find it.

Reviewed By: alexfh

Differential Revision: https://reviews.llvm.org/D82089
2020-10-16 14:16:30 +01:00
Alexander Kornienko cc175c2cc8 Support ObjC in IncludeInserter
Update IncludeSorter/IncludeInserter to support objective-c google style (part 1):

1) Correctly consider .mm/.m extensions
2) Correctly categorize category headers.
3) Add support for generated files to go in a separate section of imports

Reviewed By: alexfh, gribozavr2

Patch by Joe Turner.

Differential Revision: https://reviews.llvm.org/D89276
2020-10-16 04:12:32 +02:00
Duncan P. N. Exon Smith 0065198166 clang-{tools,unittests}: Stop using SourceManager::getBuffer, NFC
Update clang-tools-extra, clang/tools, clang/unittests to migrate from
`SourceManager::getBuffer`, which returns an always dereferenceable
`MemoryBuffer*`, to `getBufferOrNone` or `getBufferOrFake`, both of
which return a `MemoryBufferRef`, depending on whether the call site was
checking for validity of the buffer. No functionality change intended.

Differential Revision: https://reviews.llvm.org/D89416
2020-10-15 00:35:16 -04:00
Duncan P. N. Exon Smith d758f79e5d clang/Basic: Replace ContentCache::getBuffer with Optional semantics
Remove `ContentCache::getBuffer`, which always returned a
dereferenceable `MemoryBuffer*` and had a `bool*Invalid` out parameter,
and replace it with:

- `ContentCache::getBufferOrNone`, which returns
  `Optional<MemoryBufferRef>`. This is the new API that consumers should
  use. Later it could be renamed to `getBuffer`, but intentionally using
  a different name to root out any unexpected callers.
- `ContentCache::getBufferPointer`, which returns `MemoryBuffer*` with
  "optional" semantics. This is `private` to avoid growing callers and
  `SourceManager` has temporarily been made a `friend` to access it.
  Later paches will update the transitive callers to not need a raw
  pointer, and eventually this will be deleted.

No functionality change intended here.

Differential Revision: https://reviews.llvm.org/D89348
2020-10-14 15:55:18 -04:00
Kadir Cetinkaya fc2fb60bab
[clangd] clang-format TweakTests, NFC 2020-10-14 18:14:27 +02:00
Kadir Cetinkaya 82a71822a5
[clangd] Disable extract variable for RHS of assignments
Differential Revision: https://reviews.llvm.org/D89307
2020-10-14 14:22:47 +02:00
Haojian Wu 3fcca804b2 [clangd] Refine recoveryAST flags in clangd
so that we could start experiment for C.

Previously, these flags in clangd were only meaningful for C++. We need
to flip them for C, this patch repurpose these flags.

- if true, just set it.
- if false, just respect the value in clang.

this would allow us to keep flags on for C++, and optionally flip them on for C.

Differential Revision: https://reviews.llvm.org/D89233
2020-10-14 13:42:11 +02:00
Nathan Ridge cb3c13fab6 [clangd] Propagate CollectMainFileRefs to BackgroundIndex
This appears to have been an omission in D83536.

Differential Revision: https://reviews.llvm.org/D89284
2020-10-13 09:20:18 -04:00
Sylvestre Ledru 002968a320 [clang-tidy] Add an example for misc-unused-alias-decls
Differential Revision: https://reviews.llvm.org/D89270
2020-10-13 13:56:04 +02:00
Nathan Ridge b764edc59f [clangd] Try harder to get accurate ranges for documentSymbols in macros
Fixes https://github.com/clangd/clangd/issues/500

Differential Revision: https://reviews.llvm.org/D88463
2020-10-12 19:26:36 -04:00
Nathan Ridge 1b962fdd5f [clangd] Heuristic resolution for dependent type and template names
Fixes https://github.com/clangd/clangd/issues/543

Differential Revision: https://reviews.llvm.org/D88469
2020-10-12 13:37:22 -04:00
Haojian Wu 16a4b0f0e3 [clangd] Disable a failure TopLevelDecls test.
The test fails on clang-ppc64le-rhel buildbot, needs further
investigation.
2020-10-12 16:03:52 +02:00
Haojian Wu b144cd867b Dump decl when the test matcher fails. 2020-10-12 15:42:18 +02:00
Kadir Cetinkaya 35871fde55
[clangd] Record memory usages after each notification
Depends on D88415

Differential Revision: https://reviews.llvm.org/D88417
2020-10-12 15:25:29 +02:00
Kadir Cetinkaya 20f69ccfe6
[clangd] Add a helper for exposing tracer status 2020-10-12 15:25:29 +02:00
Kadir Cetinkaya 23a53301c5
[clangd] Introduce memory usage dumping to TUScheduler, for Preambles and ASTCache
File-granular information is considered details.

Depends on D88411

Differential Revision: https://reviews.llvm.org/D88415
2020-10-12 15:25:29 +02:00
Kadir Cetinkaya a74d594948
[clangd] Introduce memory dumping to FileIndex, FileSymbols and BackgroundIndex
File-granular information is considered details.

Depends on D88411

Differential Revision: https://reviews.llvm.org/D88414
2020-10-12 15:25:29 +02:00
Kadir Cetinkaya c9d2876da9
[clangd] Add a metric for tracking memory usage
Differential Revision: https://reviews.llvm.org/D88413
2020-10-12 15:25:29 +02:00
Kadir Cetinkaya f9317f7bf6
[clangd] Introduce MemoryTrees
A structure that can be used to represent memory usage of a nested
set of systems.

Differential Revision: https://reviews.llvm.org/D88411
2020-10-12 15:25:29 +02:00
Alexander Kornienko 1968a6155f [clang-tidy] Fix IncludeInserter usage example in a comment. 2020-10-12 15:05:42 +02:00
Kadir Cetinkaya 9407686687
[clangd][NFC] Fix formatting in ClangdLSPServer 2020-10-12 14:24:44 +02:00
Sam McCall 8f1de22c76 [clangd] Stop capturing trace args if the tracer doesn't need them.
The tracer is now expected to allocate+free the args itself.

Differential Revision: https://reviews.llvm.org/D89135
2020-10-12 13:43:05 +02:00
Sam McCall c2d4280328 [clangd] Validate optional fields more strictly.
Differential Revision: https://reviews.llvm.org/D89131
2020-10-12 13:01:59 +02:00
Haojian Wu f1bf41e433 Fix buildbot failure for 702529d899. 2020-10-12 12:04:44 +02:00
Haojian Wu 702529d899 [clang] Fix returning the underlying VarDecl as top-level decl for VarTemplateDecl.
Given the following VarTemplateDecl AST,

```
VarTemplateDecl col:26 X
|-TemplateTypeParmDecl typename depth 0 index 0
`-VarDecl X 'bool' cinit
  `-CXXBoolLiteralExpr 'bool' true
```

previously, we returned the VarDecl as the top-level decl, which was not
correct, the top-level decl should be VarTemplateDecl.

Differential Revision: https://reviews.llvm.org/D89098
2020-10-12 10:46:18 +02:00
Nathan Ridge f82346fd73 [clangd] Avoid relations being overwritten in a header shard
Fixes https://github.com/clangd/clangd/issues/510

Differential Revision: https://reviews.llvm.org/D87256
2020-10-11 15:32:54 -04:00
Zinovy Nis 32d565b461 [clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs
Fix for https://bugs.llvm.org/show_bug.cgi?id=47779

Differential Revision: https://reviews.llvm.org/D89194
2020-10-11 18:52:38 +03:00
Benjamin Kramer 0db08e59c9 [clangd] Map bits/stdint-intn.h and bits/stdint-uintn.h to cstdint.
These are private glibc headers containing parts of the implementation
of stdint.h.
2020-10-10 14:13:42 +02:00
Sam McCall 41d2987c75 [clangd] Stop logging in fromJSON, report instead. 2020-10-09 16:15:45 +02:00
Alexander Kornienko fe4715c47f Remove old create(MainFile)?IncludeInsertion overloads
Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D89117
2020-10-09 15:24:57 +02:00
Sam McCall 7530b254e9 [clangd] Make the tweak filter a parameter to enumerateTweaks. NFC
(Required for CodeActionContext.only)

Differential Revision: https://reviews.llvm.org/D88724
2020-10-09 14:11:19 +02:00
Sam McCall 6ee47f552b [clangd] Fix dead variable, typo. NFC 2020-10-09 10:26:58 +02:00
Kadir Cetinkaya 6f1a56d37a
[clangd] Enable partial namespace matches for workspace symbols
This will enable queries like "clangd::" to find symbols under clangd
namespace, without requiring full "clang::clangd::" qualification.

Since Fuzzyfind performs the search under all scopes and only boosts the symbols
from relevant namespaces, we might get symbols from non-matching namespaces.
This patch chooses to drop those as they clearly do not match the query.

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

Differential Revision: https://reviews.llvm.org/D88814
2020-10-09 10:20:41 +02:00