Commit Graph

6615 Commits

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