Commit Graph

6733 Commits

Author SHA1 Message Date
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