Commit Graph

6542 Commits

Author SHA1 Message Date
Sam McCall 6342b38c5f [clangd] Fix member/type name conflict caught by buildbots. 2020-09-30 10:56:43 +02:00
Sam McCall 8392685c2b [clangd] Mark code action as "preferred" if it's the sole quickfix action
Differential Revision: https://reviews.llvm.org/D88489
2020-09-30 10:11:30 +02:00
Sam McCall 7ba0779fbb [clangd] Extract options struct for ClangdLSPServer. NFC
In preparation for making moving TweakFilter from ClangdServer::Options to
a ClangdLSPServer option, and letting it vary per-request.
(In order to implement CodeActionParams.only)

Also a general overdue cleanup.

Differential Revision: https://reviews.llvm.org/D88470
2020-09-30 10:09:52 +02:00
Nathan James 01a30fa678
[clangd] Trivial setter support when moving items to fields
Extend the Trivial setter documentation to support cases where the value is moved into a field using `std::move`.

Reviewed By: sammccall, kadircet

Differential Revision: https://reviews.llvm.org/D88297
2020-09-29 21:51:15 +01:00
Kadir Cetinkaya 962a247aeb
[clangd] Fix assertion in remote-index marshalling
convert_to_slash is a no-op on posix style.
2020-09-29 20:40:19 +02:00
Aleksandr Platonov d8ba6b4ab3 [clangd] findNearbyIdentifier(): guaranteed to give up after 2^N lines
As @kadircet mentions in D84912#2184144, `findNearbyIdentifier()` traverses the whole file if there is no identifier for the word.
This patch ensures give up after 2^N lines in any case.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D87891
2020-09-29 19:54:55 +03:00
Utkarsh Saxena a9f63d22fa [clangd] Disable msan instrumentation for generated Evaluate().
MSAN build times out for generated DecisionForest inference runtime.

A solution worth trying is splitting the function into 300 smaller
functions and then re-enable msan.

For now we are disabling instrumentation for the generated function.

Differential Revision: https://reviews.llvm.org/D88495
2020-09-29 17:44:10 +02:00
Tadeo Kondrak 4fb303f340 [clangd] Improve PopulateSwitch tweak to work on non-empty switches
Improve the recently-added PopulateSwitch tweak to work on non-empty switches.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D88434
2020-09-29 16:37:51 +02:00
Nathan Ridge cc6d1f8029 [clangd] When finding refs for a renaming alias, do not return refs to underlying decls
Fixes https://github.com/clangd/clangd/issues/515

Differential Revision: https://reviews.llvm.org/D87225
2020-09-28 21:18:31 -04:00
Utkarsh Saxena 9b1666f3ce [clangd] Rename evaluate() to evaluateHeuristics()
Since we have 2 scoring functions (heuristics and decision forest),
renaming the existing evaluate() function to be more descriptive of the
Heuristics being evaluated in it.

Differential Revision: https://reviews.llvm.org/D88431
2020-09-28 20:05:01 +02:00
Utkarsh Saxena a8b55b6939 [clangd] Use Decision Forest to score code completions.
By default clangd will score a code completion item using heuristics model.

Scoring can be done by Decision Forest model by passing `--ranking_model=decision_forest` to
clangd.

Features omitted from the model:
- `NameMatch` is excluded because the final score must be multiplicative in `NameMatch` to allow rescoring by the editor.
- `NeedsFixIts` is excluded because the generating dataset that needs 'fixits' is non-trivial.

There are multiple ways (heuristics) to combine the above two features with the prediction of the DF:
- `NeedsFixIts` is used as is with a penalty of `0.5`.

Various alternatives of combining NameMatch `N` and Decision forest Prediction `P`
- N * scale(P, 0, 1): Linearly scale the output of model to range [0, 1]
- N * a^P:
  - More natural: Prediction of each Decision Tree can be considered as a multiplicative boost (like NameMatch)
  - Ordering is independent of the absolute value of P. Order of two items is proportional to `a^{difference in model prediction score}`. Higher `a` gives higher weightage to model output as compared to NameMatch score.

Baseline MRR = 0.619
MRR for various combinations:
N * P = 0.6346, advantage%=2.5768
N * 1.1^P = 0.6600, advantage%=6.6853
N * **1.2**^P = 0.6669, advantage%=**7.8005**
N * **1.3**^P = 0.6668, advantage%=**7.7795**
N * **1.4**^P = 0.6659, advantage%=**7.6270**
N * 1.5^P = 0.6646, advantage%=7.4200
N * 1.6^P = 0.6636, advantage%=7.2671
N * 1.7^P = 0.6629, advantage%=7.1450
N * 2^P = 0.6612, advantage%=6.8673
N * 2.5^P = 0.6598, advantage%=6.6491
N * 3^P = 0.6590, advantage%=6.5242
N * scaled[0, 1] = 0.6465, advantage%=4.5054

Differential Revision: https://reviews.llvm.org/D88281
2020-09-28 18:59:29 +02:00
Utkarsh Saxena b5f7e9e26c [clangd] Add a trained DecisionForest for code completion.
Replaces the dummy CodeCompletion model with a trained DecisionForest
model.
The features.json needs to be manually curated specifying the features
to be used. This is a one-time cost and does not change if the model
changes until we decide to add/remove features.

Differential Revision: https://reviews.llvm.org/D88071
2020-09-28 18:35:10 +02:00
Alexander Kornienko fdfe324da1 [clang-tidy] IncludeInserter: allow <> in header name
This adds a pair of overloads for create(MainFile)?IncludeInsertion methods that
use the presence of the <> in the file name to control whether the #include
directive will use angle brackets or quotes. Motivating examples:
https://reviews.llvm.org/D82089#inline-789412 and
https://github.com/llvm/llvm-project/blob/master/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp#L433

The overloads with the IsAngled parameter can be removed after the users are
updated.

Update usages of createIncludeInsertion.

Update (almost all) usages of createMainFileIncludeInsertion.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D85666
2020-09-28 15:14:04 +02:00
Tadeo Kondrak 018066d947 [clangd] Add a tweak for filling in enumerators of a switch statement.
Add a tweak that populates an empty switch statement of an enumeration type with all of the enumerators of that type.

Before:
```
enum Color { RED, GREEN, BLUE };
void f(Color color) {
  switch (color) {}
}
```

After:
```
enum Color { RED, GREEN, BLUE };
void f(Color color) {
  switch (color) {
  case RED:
  case GREEN:
  case BLUE:
    break;
  }
}
```

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D88383
2020-09-28 13:37:18 +02:00
Whisperity 9d2ef5e74e [CMake][CTE] Add "check-clang-extra-..." targets to test only a particular Clang extra tool
Create targets `check-clang-extra-clang-tidy`, `check-clang-extra-clang-query`
similar to how `check-clang-sema`, `check-clang-parser`, etc. are
auto-generated from the directory structure.

This allows running only a particular sub-tool's tests, not having to wait
through the entire `check-clang-tools` execution.

Differential Revision: http://reviews.llvm.org/D84176
2020-09-25 13:32:56 +02:00
Reid Kleckner 3453b6928d Revert "Recommit "[CUDA][HIP] Defer overloading resolution diagnostics for host device functions""
This reverts commit e39da8ab6a.

This depends on a change that needs additional design review and needs
to be reverted.
2020-09-24 11:16:54 -07:00
Yaxun (Sam) Liu e39da8ab6a Recommit "[CUDA][HIP] Defer overloading resolution diagnostics for host device functions"
This recommits 7f1f89ec8d and
40df06cdaf after fixing memory
sanitizer failure.
2020-09-24 08:44:37 -04:00
Sam McCall 00e05b12c7 [clangd] Reorder a little bit of init code. NFC
This makes it possible to do something else (run checks) instead of
starting the server, with all config applied.
2020-09-24 11:57:31 +02:00
Sam McCall 98756d865b [clangd] Fix comment. NFC 2020-09-24 10:49:39 +02:00
Kadir Cetinkaya 64168c6d99
[clangd] Disable suffix matching fallback for C during include insertion
Clangd currently doesn't respect language and breaks the builds with
include insertion for C. This patch aims to stop the bleeding by not mapping
back to CPP standard library headers.

Improves https://github.com/clangd/clangd/issues/376.

Differential Revision: https://reviews.llvm.org/D88144
2020-09-24 10:46:10 +02:00
Sam McCall 2bd5e3fb3c [clangd] Improve bad-RPC-payload error messages slightly 2020-09-24 01:51:37 +02:00
Sam McCall fa69b60806 [JSON] Add error reporting to fromJSON and ObjectMapper
Translating between JSON objects and C++ strutctures is common.
From experience in clangd, fromJSON/ObjectMapper work well and save a lot of
code, but aren't adopted elsewhere at least partly due to total lack of error
reporting beyond "ok"/"bad".

The recently-added error model should be rich enough for most applications.
It requires tracking the path within the root object and reporting local
errors at appropriate places.
To do this, we exploit the fact that the call graph of recursive
parse functions mirror the structure of the JSON itself.
The current path is represented as a linked list of segments, each of which is
on the stack as a parameter. Concretely, fromJSON now looks like:
  bool fromJSON(const Value&, T&, Path);

Beyond the signature change, this is reasonably unobtrusive: building
the path segments is mostly handled by ObjectMapper and the vector<T> fromJSON.
However the root caller of fromJSON must now create a Root object to
store the errors, which is a little clunky.

I've added high-level parse<T>(StringRef) -> Expected<T>, but it's not
general enough to be the primary interface I think (at least, not usable in
clangd).

All existing users (mostly just clangd) are updated in this patch,
making this change backwards-compatible is a bit hairy.

Differential Revision: https://reviews.llvm.org/D88103
2020-09-24 01:20:09 +02:00
Utkarsh Saxena 158af0d3d1 [clangd] Refactor code completion signal's utility properties.
Current implementation of heuristic-based scoring function also contains
computation of derived signals (e.g. whether name contains a word from
context, computing file distances, scope distances.)
This is an attempt to separate out the logic for computation of derived
signals from the scoring function.
This will allow us to have a clean API for scoring functions that will
take only concrete code completion signals as input.

Differential Revision: https://reviews.llvm.org/D88146
2020-09-23 16:12:18 +02:00
Nathan Ridge aa3c7638ba [clang] Traverse init-captures while indexing
Fixes https://github.com/clangd/clangd/issues/496

Differential Revision: https://reviews.llvm.org/D87257
2020-09-22 02:32:09 -04:00
Nathan Ridge f18f8f34d3 [clangd] Link libclangdSupport into clangd-index-server
Fixes https://github.com/clangd/clangd/issues/534

Differential Revision: https://reviews.llvm.org/D87979
2020-09-22 02:28:48 -04:00
Adam Balogh 4fc0214a10 [clang-tidy] New check cppcoreguidelines-prefer-member-initializer
Finds member initializations in the constructor body which can be placed
into the initialization list instead. This does not only improves the
readability of the code but also affects positively its performance.
Class-member assignments inside a control statement or following the
first control statement are ignored.

Differential Revision: https://reviews.llvm.org/D71199
2020-09-21 14:42:58 +02:00
Nathan Ridge 90a8c44d92 [clangd] Fix typo in field name
Differential Revision: https://reviews.llvm.org/D87995
2020-09-20 19:52:39 -04:00
Utkarsh Saxena 985deba931 Revert "Temporarily Revert "[clangd] Add Random Forest runtime for code completion.""
We intend to replace heuristics based code completion ranking with a Decision Forest Model.

This patch introduces a format for representing the model and an inference runtime that is code-generated at build time.
- Forest.json contains all the trees as an array of trees.
- Features.json describes the features to be used.
- Codegen file takes the above two files and generates CompletionModel containing Feature struct and corresponding Evaluate function.
   The Evaluate function maps a feature to a real number describing the relevance of this candidate.
- The codegen is part of build system and these files are generated at build time.
- Proposes a way to test the generated runtime using a test model.
  - Replicates the model structure in unittests.
  - unittest tests both the test model (for correct tree traversal) and the real model (for sanity).

This reverts commit 549e55b3d5.
2020-09-19 10:54:04 +02:00
Eric Christopher 549e55b3d5 Temporarily Revert "[clangd] Add Random Forest runtime for code completion."
as a header doesn't appear to have made it into the commit.

This reverts commit 9b6765e784 and followup
2020-09-18 14:47:43 -07:00
Nico Weber 807777913e CompletionModelCodegen: Remove unused import
The unused import is 3.4+, so it also breaks py2.7 compat.
But this is easy to fix :)
2020-09-18 16:24:58 -04:00
Nico Weber 0ea2a57274 clangd: Make ompletionModelCodegen.py tpy2.7 compatible
LLVM still supports Python 2.7, so unbreak bots that still run that.
In a separate commit so that this is easy to revert once we drop
support :)
2020-09-18 15:26:58 -04:00
Utkarsh Saxena 9b6765e784 [clangd] Add Random Forest runtime for code completion.
Summary:
[WIP]
- Proposes a json format for representing Random Forest model.
- Proposes a way to test the generated runtime using a test model.

TODO:
- Add generated source code snippet for easier review.
- Fix unused label warning.
- Figure out required using declarations for CATEGORICAL columns from Features.json.
- Necessary Google3 internal modifications for blaze before landing.
- Add documentation for format of the model.
- Document more.

Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83814
2020-09-18 19:25:56 +02:00
Adam Czachorowski c894bfd1f5 [clangd] Add option for disabling AddUsing tweak on some namespaces.
For style guides forbid "using" declarations for namespaces like "std".
With this new config option, AddUsing can be selectively disabled on
those.

Differential Revision: https://reviews.llvm.org/D87775
2020-09-18 16:46:09 +02:00
Yaxun (Sam) Liu 772bd8a7d9 Revert "[CUDA][HIP] Defer overloading resolution diagnostics for host device functions"
This reverts commit 7f1f89ec8d.

This reverts commit 40df06cdaf.
2020-09-17 13:55:31 -04:00
Yaxun (Sam) Liu 7f1f89ec8d Fix build failure in clangd 2020-09-17 11:51:09 -04:00
Adam Balogh dbd45b2db8 [ASTMatchers] Fix `hasBody` for the descendants of `FunctionDecl`
//AST Matcher// `hasBody` is a polymorphic matcher that behaves
differently for loop statements and function declarations. The main
difference is the for functions declarations it does not only call
`FunctionDecl::getBody()` but first checks whether the declaration in
question is that specific declaration which has the body by calling
`FunctionDecl::doesThisDeclarationHaveABody()`. This is achieved by
specialization of the template `GetBodyMatcher`. Unfortunately template
specializations do not catch the descendants of the class for which the
template is specialized. Therefore it does not work correcly for the
descendants of `FunctionDecl`, such as `CXXMethodDecl`,
`CXXConstructorDecl`, `CXXDestructorDecl` etc. This patch fixes this
issue by using a template metaprogram.

The patch also introduces a new matcher `hasAnyBody` which matches
declarations which have a body present in the AST but not necessarily
belonging to that particular declaration.

Differential Revision: https://reviews.llvm.org/D87527
2020-09-16 13:16:51 +02:00
Adam Balogh 779a2a2edc [clang-tidy] Crash fix for bugprone-misplaced-pointer-arithmetic-in-alloc
Placement new operators on non-object types cause crash in
`bugprone-misplaced-pointer-arithmetic-in-alloc`. This patch fixes this
issue.

Differential Revision: https://reviews.llvm.org/D87683
2020-09-16 13:16:44 +02:00
Adam Czachorowski 7029e5d4ca [clangd] Actually parse Index section of the YAML file.
This fixes a bug in dbf486c0de, which
introduced the Index section of the config, but did not register the
parse method, so it didn't work in a YAML file (but did in a test).

Differential Revision: https://reviews.llvm.org/D87710
2020-09-16 13:11:02 +02:00
Kirill Bobyrev 3e5a4ef51a Fix table formatting after D87686 2020-09-16 12:27:59 +02:00
Kirill Bobyrev a909a84ef2
[clang-tidy] Improve documentation on Clangd integration
The integration is already complete; this patch updates information as well as
suggests using Clang-Tidy via Clangd integration that is vastly available
in most editors through LSP client plugins.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D87686
2020-09-16 12:10:00 +02:00
Kirill Bobyrev 3a0a2a6347 [clangd] Implement hot index reloading for clangd-index-server
This patch adds a mechanism to load new versions of index into
clangd-index-server using SwapIndex and FileStatus information about last
modification time without downtime.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D87450
2020-09-16 11:12:14 +02:00
Aleksandr Platonov d427df6369 [clangd] Don't use zlib when it's unavailable.
Without this patch `clangd` crashes at try to load compressed string table when `zlib` is not available.
Example:
- Build `clangd` with MinGW (`zlib` found)
- Build index
- Build `clangd` with Visual Studio compiler (`zlib` not found)
- Try to load index

Reviewed By: sammccall, adamcz

Differential Revision: https://reviews.llvm.org/D87673
2020-09-16 11:05:18 +03:00
Zinovy Nis 96c6d012df [clang-tidy] Fix crash in modernize-use-noexcept on uninstantiated throw class
Bug: https://bugs.llvm.org/show_bug.cgi?id=47446

Differential Revision: https://reviews.llvm.org/D87627
2020-09-16 08:13:00 +03:00
Felix Berger 98e07b5596 Restrict UnnecessaryCopyInitialization check to variables initialized from free functions without arguments
This restriction avoids cases where an alias is returned to an argument and
which could lead to to a false positive change.
2020-09-15 08:46:04 -04:00
Sam McCall 687e1d7121 [clangd] makeStringError,make_error<StringError> -> error() 2020-09-14 11:48:31 +02:00
Kadir Cetinkaya 574dd60547
[clangd] Track tweaks that fail the apply stage
Differential Revision: https://reviews.llvm.org/D87501
2020-09-14 11:24:02 +02:00
Sam McCall 30667c967d [clangd] Add error() function for creating formatv-style llvm::Errors. NFC
Summary:
This is considerably terser than the makeStringError and friends, and
avoids verbosity cliffs that discourage adding log information.

It follows the syntax used in log/elog/vlog/dlog that have been successful.

The main caveats are:
 - it's strictly out-of-place in logger.h, though kind of fits thematically and
   in implementation
 - it claims the "error" identifier, which seems a bit too opinionated
   to put higher up in llvm

I've updated some users of StringError mostly at random - there are lots
more mechanical changes but I'd like to get this reviewed before making
them all.

Reviewers: kbobyrev, hokein

Subscribers: mgorny, ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83419
2020-09-14 10:43:42 +02:00
Kadir Cetinkaya bceca7a996
[clangd][NFC] Get rid of an `else after return` 2020-09-11 11:31:16 +02:00
Aaron Ballman 66ac212ea9 Speculatively fix the Sphinx builder. 2020-09-10 11:35:10 -04:00
Nico Weber 29cecbc5d6 Fix clangd build after 33c9dbbd38 2020-09-10 11:05:53 -04:00
Nico Weber 33c9dbbd38 Add an explicit toggle for the static analyzer in clang-tidy
Instead of using CLANG_ENABLE_STATIC_ANALYZER for use of the
static analyzer in both clang and clang-tidy, add a second
toggle CLANG_TIDY_ENABLE_STATIC_ANALYZER.

This allows enabling the static analyzer in clang-tidy while
disabling it in clang.

Differential Revison: https://reviews.llvm.org/D87118
2020-09-10 10:48:17 -04:00
Roman Lebedev ebf496d805
Revert "[clang-tidy] New check readability-prefer-member-initializer"
Either contains unbounded loops, or has *very* high runtime,
100+x of all the current clang-tidy checks.

This reverts commit f5fd7486d6.
2020-09-10 16:32:18 +03:00
serge-sans-paille 875b8537ee [clang-tidy] Fix reST syntax
Authored by Eisuke Kawashima [https://github.com/llvm/llvm-project/pull/245]
2020-09-10 13:56:57 +02:00
Heejin Ahn 71133e8b5b [clang-tidy] Fix linking for FrontendOpenMP
Without this, builds with `-DBUILD_SHARED_LIBS=ON` fail.
2020-09-08 09:22:22 -07:00
Haojian Wu 32ae37b038 [clang-tidy] Fix dynamic build failures after 156b127945 2020-09-08 16:26:48 +02:00
Nico Weber 9933188c90 StructPackAlignCheck: Fix a -Winconsistent-missing-override warning 2020-09-08 10:02:00 -04:00
Frank Derry Wanye 156b127945 Add a new altera check for structure packing and alignment.
The altera struct pack align lint check finds structs that are inefficiently
packed or aligned and recommends packing/aligning of the structs using the
packed and aligned attributes as needed in a warning.
2020-09-08 09:35:14 -04:00
Eduardo Caldas 1a7a2cd747 [Ignore Expressions][NFC] Refactor to better use `IgnoreExpr.h` and nits
This change groups
* Rename: `ignoreParenBaseCasts` -> `IgnoreParenBaseCasts` for uniformity
* Rename: `IgnoreConversionOperator` -> `IgnoreConversionOperatorSingleStep` for uniformity
* Inline `IgnoreNoopCastsSingleStep` into a lambda inside `IgnoreNoopCasts`
* Refactor `IgnoreUnlessSpelledInSource` to make adequate use of `IgnoreExprNodes`

Differential Revision: https://reviews.llvm.org/D86880
2020-09-07 09:32:30 +00:00
Aaron Puchert da6b3aa4c6 Attempt to fix Sphinx build failure, NFC
A code block wasn't properly introduced.
2020-09-05 18:25:27 +02:00
Nathan Ridge ca842c825a [clangd] Handle templates more consistently in type hierarchy
If the tree includes types derived from all specializations of
a template, do not misleadingly label the root node with the
name of a single specialization.

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

Differential Revision: https://reviews.llvm.org/D86861
2020-09-01 19:18:37 -04:00
Adam Balogh 22808d693e [clang-tidy] Buildbot failure fix for commit rGf5fd7486d6c0
Commit `rGf5fd7486d6c0` caused a buildbot failure because exceptions are
disabled by default on one of the buildbots. This patch forcibly enables
exceptions for the affected test.
2020-08-31 16:32:10 +02:00
Adam Balogh 14dd073782 [Clang-Tidy] New check `bugprone-redundant-branch-condition`
Checking the same condition again in a nested `if` usually make no sense,
except if the value of the expression could have been changed between
the two checks. Although compilers may optimize this out, such code is
suspicious: the programmer may have meant to check something else.
Therefore it is worth to find such places in the code and notify the
user about the problem.

This patch implements a basic check for this problem. Currently it
only detects redundant conditions where the condition is a variable of
integral type. It also detects the possible bug if the variable is in an
//or// or //and// logical expression in the inner if and/or the variable
is in an //and// logical expression in the outer if statement. Negated
cases are not handled yet.

Differential Revision: https://reviews.llvm.org/D81272
2020-08-31 16:00:59 +02:00
Adam Balogh f5fd7486d6 [clang-tidy] New check readability-prefer-member-initializer
Finds member initializations in the constructor body which can
be placed to the member initializers of the constructor instead.
This does not only improves the readability of the code but also
affects positively its performance. Class-member assignments
inside a control statement or following the first control
statement are ignored.

Differential Revision: https://reviews.llvm.org/D71199
2020-08-31 15:59:29 +02:00
Nathan James 3776999b49
[clang-query][NFC] Silence a few lint warnings 2020-08-28 01:06:46 +01:00
Kirill Bobyrev 9d11e6789c
[clangd] Use string[] for allCommitCharacters
As per LSP specification, allCommitCharacters should be string[] instead of
string:

https://microsoft.github.io/language-server-protocol/specification#textDocument_completion

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D86604
2020-08-26 17:08:19 +02:00
Haojian Wu 667867e0df [clangd] Enable recovery-ast-type by default.
Differential Revision: https://reviews.llvm.org/D86602
2020-08-26 16:47:04 +02:00
Haojian Wu 0aaa2acc4c [clangd] Compute the inactive code range for semantic highlighting.
Differential Revision: https://reviews.llvm.org/D85635
2020-08-26 10:50:31 +02:00
Adam Czachorowski 4d90ff59ac [clangd] When inserting "using", add "::" in front if that's the style.
We guess the style based on the existing using declarations. If there
are any and they all start with ::, we add it to the newly added one
too.

Differential Revision: https://reviews.llvm.org/D86473
2020-08-25 14:07:49 +02:00
Nathan James df5335a36d
[clang-tidy] readability-simplify-boolean-expr detects negated literals
Adds support for detecting cases like `if (!true) ...`.
Addresses [[ https://bugs.llvm.org/show_bug.cgi?id=47166 | readability-simplify-boolean-expr not detected for negated boolean literals. ]]

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D86176
2020-08-22 13:57:36 +01:00
Adam Czachorowski b488935320 [clangd] Discard diagnostics from another SourceManager.
This can happen when building implicit modules, as demonstrated in test.
The CompilerInstance uses the same StoredDiags, but different
SourceManager. This used to crash clangd when it tried to relocate the
diagnostic to the main file, which, according to SourceManager from the
diagnostic, is a fake <module-includes> file.

Differential Revision: https://reviews.llvm.org/D85753
2020-08-21 13:11:21 +02:00
Richard Smith efeb65d53b Fix up clangd after Clang 038edf6029.
Now that Clang is able to constant-evaluate void-typed expressions,
disable showing hover-card values for them. It's not useful to say that
an expression cast to void has value '<no value>', even if we can
constant-evaluate it to that result!
2020-08-20 16:36:25 -07:00
Joachim Priesner 03ded5497a Fix -allow-enabling-analyzer-alpha-checkers always being passed to run-clang-tidy.py
The action='store_true' option of argparse.add_argument implicitly
generates a default value of False if the argument is not specified.
Thus, the allow_enabling_alpha_checkers argument of
get_tidy_invocation is never None.
2020-08-20 09:15:29 -04:00
Aleksandr Platonov 4457398265 [clangd] Don't crash on `#pragma clang __debug parser_crash`
Currently, clangd crashes when opening a file with `#pragma clang __debug parser_crash` (e.g. clang/test/Modules/Inputs/crash.h).
This patch disables these crashes.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D86279
2020-08-20 15:53:21 +03:00
Adam Czachorowski 707138d677 [clangd] Remove useless stderr logging.
This was accidentally added in 53b9199a5c

Differential Revision: https://reviews.llvm.org/D86284
2020-08-20 14:52:04 +02:00
Adam Czachorowski baeff989b0 [clang] When loading preamble from AST file, re-export modules in Sema.
This addresses a FIXME in ASTReader.

Modules were already re-exported for Preprocessor, but not for Sema.
The result was that, with -fmodules-local-submodule-visibility, all AST
nodes belonging to a module that was loaded in a premable where not
accesible from the main part of the file and a diagnostic recommending
importing those modules would be generated.

Differential Revision: https://reviews.llvm.org/D86069
2020-08-20 14:19:52 +02:00
Adam Czachorowski 53b9199a5c [clangd] Fix crash-bug in preamble indexing when using modules.
When preamble contains #undef, indexing code finds the matching #define
and uses that during indexing. However, it would only look for local
definitions. If the macro was defined in a module, MacroInfo
would be nullptr and clangd would crash.

This change makes clangd ignore any #undef without a matching #define
inside the same TU.

The indexing of macros happens for preamble only, so then #undef must be
in the preamble, which is why we need two .h files in a test.

Note that clangd is currently not ready for module support, but this
brings us one step closer.

This was previously attempted in
4061d9e42c, but had to be reverted due to
broken test. This version fixes that test-only bug by setting a custom module
cache path to avoid re-use of modules across test invocations.

Differential Revision: https://reviews.llvm.org/D85923
2020-08-20 14:19:52 +02:00
Simon Pilgrim 1014a93a4e Fix unused variable warnings. NFCI. 2020-08-19 14:34:32 +01:00
Nathan James 8c9ffe34d9 [NFC][clang-tidy] Put abseil headers in alphabetical order 2020-08-18 15:52:47 +01:00
Nathan Ridge e33ec9d904 [clangd] Target member of dependent base made visible via a using-decl
Fixes https://github.com/clangd/clangd/issues/307

Differential Revision: https://reviews.llvm.org/D86047
2020-08-18 03:03:49 -04:00
Nathan Ridge 00d7b7d014 [clang] Fix visitation of ConceptSpecializationExpr in constrained-parameter
Summary: RecursiveASTVisitor needs to traverse TypeConstraint::ImmediatelyDeclaredConstraint

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D84136
2020-08-18 00:32:34 -04:00
Nathan Ridge 15673d748a [clangd] Index refs to main-file symbols as well
Summary: This will be needed to support call hierarchy

Reviewers: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83536
2020-08-18 00:30:07 -04:00
Kadir Cetinkaya 53c593c2c8
[clang] Make signature help work with dependent args
Fixes https://github.com/clangd/clangd/issues/490

Differential Revision: https://reviews.llvm.org/D85826
2020-08-17 10:06:36 +02:00
Bernhard Manfred Gruber 345053390a Add support for C++20 concepts and decltype to modernize-use-trailing-return-type. 2020-08-15 10:40:22 -04:00
zacharyselk caac40fa5a [clang-tools-extra] Added missing comma
The new diagnostic tool (D85545) caught a missing comma, adding one to fix the warning.

Differential Revision: https://reviews.llvm.org/D85978
2020-08-14 12:27:30 -06:00
Vy Nguyen 114c9fa0e4 Add "status" to the list of absl libraries.
The Abseil-NoInternalDependenciesCheck currently mistakenly triggers on any usage of internal helpers even if it is within absl/status.

Differential Revision: https://reviews.llvm.org/D85843
2020-08-13 16:08:14 -04:00
Kadir Cetinkaya 0464acd019
[clangd] Move clang-tidy check modifications into ClangdServer
Summary:
This enables sharing the logic between standalone clangd and embedders
of it. The new approach should be same performance-wise, as it is only called
once per addDocument call.

This patch also introduces a blacklisting code path for disabling crashy or
high-noise tests, until we figure out a way to make them work with clangd-setup.

The biggest difference is the way we make use of preambles, hence those checks
can't see directives coming from the preamble section of the file. The second
thing is the fact that code might-not be compiling while clangd is trying to
build an AST, hence some checks might choke on those incomplete ASTs.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, aaron.ballman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83224
2020-08-13 18:32:59 +02:00
Kadir Cetinkaya 66a2e3a525
[clangd] Send EOF before resetting diagnostics consumer
Summary:
Some clang-tidy checkers, e.g. llvm-include-order can emit diagnostics
at this callback (as mentioned in the comments).

Clangd was resetting diag consumer to IgnoreDiags before sending EOF, hence we
were unable to emit diagnostics for such checkers.

This patch changes the order of that reset and preprocosser event to make sure
we emit that diag.

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

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83178
2020-08-13 18:32:59 +02:00
Sam McCall b36e22d644 [clangd] Extract BackgroundIndex::Options struct. NFC
I've dropped the background context parameter, since we in practice just pass the
current context there, and we now have a different way to specify context too.
While here, clean up a couple of comments.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D83157
2020-08-13 18:12:54 +02:00
Sam McCall 98cf77e337 [clangd] Clean up old test fixture/names a little. NFC 2020-08-13 17:43:11 +02:00
Adam Czachorowski 73f0772c0b [clangd] Revert "[clangd] Fix crash-bug in preamble indexing when using modules."
This reverts commit 4061d9e42c.
Tests are failing in some configuration, likely due to not cleaning up
module cache path before running the test.

Differential Revision: https://reviews.llvm.org/D85907
2020-08-13 17:09:54 +02:00
Sam McCall 41d0edd54e [clangd] Express dumpAST in tests as a customAction() 2020-08-13 14:27:32 +02:00
Sam McCall 32626bcc0b [clangd] Add ClangdServer::customAction() extension point
This lets basic AST-consuming actions be defined outside clangdserver.
(it essentially exposes TUScheduler::runWithAST).

Two use cases for now:
 - replace ClangdServer::dumpAST, which doesn't really belong in the public
   interface (a followup patch will do this)
 - allow embedders to add/experiment with extra features
   (e.g. I know some who want to try crazy AST+ML code completion...)

Maybe in the future we should use this sort of mechanism to make ClangdServer
less of a monolith, but that's not in scope for now.
This would probably require a richer and more carefully-thought-out API.

Differential Revision: https://reviews.llvm.org/D85883
2020-08-13 12:26:32 +02:00
Erik Pilkington fc915d13b8 [clang-tidy] use stable_sort instead of sort to fix EXPENSIVE_CHECKS tests
http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-expensive/17317/console
2020-08-12 12:12:10 -04:00
Bogdan Serea 35bee3503f [clang-tidy] prevent generated checks from triggering assertions on anonymous functions
Skeleton checks generated by clang-tidy add_check.py cause assertions to fail when run over anonymous functions(lambda functions). This patch introduces an additional check to verify that the target function is not anonymous before calling getName().
The code snippet from the [[ https://clang.llvm.org/extra/clang-tidy/Contributing.html | clang-tidy tutorial  ]]is also updated.

Reviewed By: alexfh, DavidTruby

Differential Revision: https://reviews.llvm.org/D85218
2020-08-12 12:43:40 +01:00
Yitzhak Mandelbaum d8c1f43dcc [libTooling] Move RewriteRule include edits to ASTEdit granularity.
Currently, changes to includes are applied to an entire rule. However,
include changes may be specific to particular edits within a rule (for example,
they may apply to one file but not another). Also, include changes may need to
carry metadata, just like other changes. So, we make include changes first-class
edits.

Reviewed By: tdl-g

Differential Revision: https://reviews.llvm.org/D85734
2020-08-11 16:47:14 +00:00
David Goldman cb29c33984 [clangd][ObjC] Improve xrefs for protocols and classes
Summary:
Previously clangd would jump to forward declarations for protocols
and classes instead of their definition/implementation.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83501
2020-08-11 12:36:31 -04:00
Kadir Cetinkaya 24a816c7d3
[clangd] Disable ExtractFunction for C
This tweak uses constructs like auto and refs, which are not available
in C.

Differential Revision: https://reviews.llvm.org/D85727
2020-08-11 16:00:39 +02:00
Kadir Cetinkaya b626f45329
[clangd] Unify macro matching in code completion for AST and Index based macros
fixes https://github.com/clangd/clangd/issues/489

Differential Revision: https://reviews.llvm.org/D85721
2020-08-11 16:00:39 +02:00
Kirill Bobyrev bd1013a482
[clangd] Enforce trailing slash for remote index's project root
Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D85711
2020-08-11 13:24:43 +02:00
Simon Pilgrim 73a6a36469 [clangd] RIFF.cpp - Use logical && instead of bitwise & for padding check
Fixes PR47070
2020-08-11 11:38:43 +01:00
Kirill Bobyrev c6d2078a35 [clangd] Improve diagnostics in dexp interface
When running dexp in remote mode without --project-root it shuts down
with an assertion. This is not the desired behaviour: instruct user on
how to run it properly when the configuration is incorrect.
2020-08-11 09:50:33 +02:00
Nathan Ridge 70d583ad12 [clangd] Have template template arguments target their referenced template decl
Fixes https://github.com/clangd/clangd/issues/473

Differential Revision: https://reviews.llvm.org/D85503
2020-08-10 13:27:23 -04:00
Adam Czachorowski 4061d9e42c [clangd] Fix crash-bug in preamble indexing when using modules.
Summary:
When preamble contains #undef, indexing code finds the matching #define
and uses that during indexing. However, it would only look for local
definitions. If the macro was defined in a module, MacroInfo
would be nullptr and clangd would crash.

This change makes clangd ignore any #undef without a matching #define
inside the same TU.

The indexing of macros happens for preamble only, so then #undef must be
in the preamble, which is why we need two .h files in a test.

Note that clangd is currently not ready for module support, but this
brings us one step closer.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80525
2020-08-10 18:42:57 +02:00
Adam Czachorowski e2d61ae573 Correctly set CompilingPCH in PrecompilePreambleAction.
This fixes a crash bug in clangd when used with modules. ASTWriter would
end up writing references to submodules into the PCH file, but upon
reading the submodules would not exists and
HeaderFileInfoTrait::ReadData would crash.

Differential Revision: https://reviews.llvm.org/D85532
2020-08-10 17:49:23 +02:00
Aleksandr Platonov dcb8d3b722 [clang-tidy] Fix a crash in bugprone-not-null-terminated-result check when `__STDC_WANT_LIB_EXT1__` is not a literal.
If `__STDC_WANT_LIB_EXT1__` is not a literal (e.g. `#define __STDC_WANT_LIB_EXT1__ ((unsigned)1)`) bugprone-not-null-terminated-result check crashes.
Stack dump:
```
 #0 0x0000000002185e6a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/llvm-project/build/bin/clang-tidy+0x2185e6a)
 #1 0x0000000002183e8c llvm::sys::RunSignalHandlers() (/llvm-project/build/bin/clang-tidy+0x2183e8c)
 #2 0x0000000002183ff3 SignalHandler(int) (/llvm-project/build/bin/clang-tidy+0x2183ff3)
 #3 0x00007f08d91b1390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
 #4 0x00000000021338bb llvm::StringRef::getAsInteger(unsigned int, llvm::APInt&) const (/llvm-project/build/bin/clang-tidy+0x21338bb)
 #5 0x000000000052051c clang::tidy::bugprone::NotNullTerminatedResultCheck::check(clang::ast_matchers::MatchFinder::MatchResult const&) (/llvm-project/build/bin/clang-tidy+0x52051c)
```

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D85525
2020-08-10 15:12:03 +03:00
Haojian Wu 3d2cf72943 [clangd] Fix the background index is not disabled when using remote-index.
Differential Revision: https://reviews.llvm.org/D85637
2020-08-10 14:02:22 +02:00
Aleksandr Platonov 5965fbf81b [clang-tidy] Fix a crash in bugprone-not-null-terminated-result check when `__STDC_WANT_LIB_EXT1__` was undefined after definition.
PP->getMacroInfo() returns nullptr for undefined macro, so we need to check this return value before dereference.
Stack dump:
```
 #0 0x0000000002185e6a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/llvm-project/build/bin/clang-tidy+0x2185e6a)
 #1 0x0000000002183e8c llvm::sys::RunSignalHandlers() (/llvm-project/build/bin/clang-tidy+0x2183e8c)
 #2 0x0000000002183ff3 SignalHandler(int) (/llvm-project/build/bin/clang-tidy+0x2183ff3)
 #3 0x00007f37df9b1390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
 #4 0x000000000052054e clang::tidy::bugprone::NotNullTerminatedResultCheck::check(clang::ast_matchers::MatchFinder::MatchResult const&) (/llvm-project/build/bin/clang-tidy+0x52054e)
```

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D85523
2020-08-10 10:24:38 +03:00
Kirill Bobyrev 836f937a1f
[clangd] Add more error details on the remote index server side
Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D85502
2020-08-09 22:12:56 +02:00
Haojian Wu 90d1c66c7c [clangd] Fix a typo, NFC. 2020-08-07 15:02:06 +02:00
Haojian Wu a70161808b [clangd] Include the underlying decls in go-to-definition.
Fixes https://github.com/clangd/clangd/issues/277

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D74054
2020-08-07 11:39:49 +02:00
Nathan James 01bc708126 [NFC] Replace hasName in loop for hasAnyName 2020-08-07 10:22:45 +01:00
Nathan Ridge 57f9518bf0 [clangd] Highlight structured bindings at local scope as LocalVariable
Differential Revision: https://reviews.llvm.org/D85500
2020-08-07 03:23:10 -04:00
Richard Smith b2847671b8 Reinstate check that we don't crash. 2020-08-06 19:07:50 -07:00
Richard Smith 2f1fffab73 Disable clang-tidy test that started failing after clang commit ed5a18f.
This checker appears to be intentionally not diagnosing cases where an
operator appearing in a duplicated expression might have side-effects;
Clang is now modeling fold-expressions as having an unresolved operator
name within them, so they now trip up this check.
2020-08-06 19:06:06 -07:00
Nathan Ridge f4ba7a100a [clangd] Semantic highlighting for dependent template name in template argument
Fixes https://github.com/clangd/clangd/issues/484

Differential Revision: https://reviews.llvm.org/D85272
2020-08-06 21:23:49 -04:00
Aleksandr Platonov 9f24148b21 [clangd] Fix crash in bugprone-bad-signal-to-kill-thread clang-tidy check.
Inside clangd, clang-tidy checks don't see preprocessor events in the preamble.
This leads to `Token::PtrData == nullptr` for tokens that the macro is defined to.
E.g. `#define SIGTERM 15`:
- Token::Kind == tok::numeric_constant (Token::isLiteral() == true)
- Token::UintData == 2
- Token::PtrData == nullptr

As the result of this, bugprone-bad-signal-to-kill-thread check crashes at null-dereference inside clangd.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D85417
2020-08-06 21:45:21 +03:00
Aleksandr Platonov 216ad2da74 [clang-tidy] Fix bugprone-bad-signal-to-kill-thread crash when `SIGTERM` is not a literal.
If `SIGTERM` is not a literal (e.g. `#define SIGTERM ((unsigned)15)`) bugprone-bad-signal-to-kill-thread check crashes.
Stack dump:
```
 #0 0x000000000217d15a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/llvm-project/build/bin/clang-tidy+0x217d15a)
 #1 0x000000000217b17c llvm::sys::RunSignalHandlers() (/llvm-project/build/bin/clang-tidy+0x217b17c)
 #2 0x000000000217b2e3 SignalHandler(int) (/llvm-project/build/bin/clang-tidy+0x217b2e3)
 #3 0x00007f6a7efb1390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
 #4 0x000000000212ac9b llvm::StringRef::getAsInteger(unsigned int, llvm::APInt&) const (/llvm-project/build/bin/clang-tidy+0x212ac9b)
 #5 0x0000000000593501 clang::tidy::bugprone::BadSignalToKillThreadCheck::check(clang::ast_matchers::MatchFinder::MatchResult const&) (/llvm-project/build/bin/clang-tidy+0x593501)
```

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D85398
2020-08-06 10:32:03 +03:00
Aleksandr Platonov 8671166833 [clang-tidy] Fix bugprone-bad-signal-to-kill-thread crash when `SIGTERM` was undefined after definition.
`PP->getMacroInfo()` returns nullptr for undefined macro, which leads to null-dereference at `MI->tockens().back()`.
Stack dump:
```
 #0 0x000000000217d15a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/llvm-project/build/bin/clang-tidy+0x217d15a)
 #1 0x000000000217b17c llvm::sys::RunSignalHandlers() (/llvm-project/build/bin/clang-tidy+0x217b17c)
 #2 0x000000000217b2e3 SignalHandler(int) (/llvm-project/build/bin/clang-tidy+0x217b2e3)
 #3 0x00007f39be5b1390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
 #4 0x0000000000593532 clang::tidy::bugprone::BadSignalToKillThreadCheck::check(clang::ast_matchers::MatchFinder::MatchResult const&) (/llvm-project/build/bin/clang-tidy+0x593532)
```

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D85401
2020-08-06 10:28:20 +03:00
Kadir Cetinkaya 618db6803d
[clangd][NFC] Delete dead code in ExtractFunction code action 2020-08-05 21:14:39 +02:00
Kadir Cetinkaya d3ac301886
[clangd] Disable define out-of-line code action on templates
Differential Revision: https://reviews.llvm.org/D85310
2020-08-05 20:57:28 +02:00
Haojian Wu 9a7b8b22a7 [clangd] Hide "swap if branch" tweak
This tweak is more like a demo, and doesn't provide much value in
practice.

Differential Revision: https://reviews.llvm.org/D85318
2020-08-05 20:03:21 +02:00
Kadir Cetinkaya 011732852c
[clangd] Fix a crash in DefineInline
Differential Revision: https://reviews.llvm.org/D85291
2020-08-05 17:38:17 +02:00
Bruno Ricci 19701458d4
[clang][nearly-NFC] Remove some superfluous uses of NamedDecl::getNameAsString
`OS << ND->getDeclName();` is equivalent to `OS << ND->getNameAsString();`
without the extra temporary string.

This is not quite a NFC since two uses of `getNameAsString` in a
diagnostic are replaced, which results in the named entity being
quoted with additional "'"s (ie: 'var' instead of var).
2020-08-05 13:54:37 +01:00
Alex Cameron a44161692a Support member expressions in bugprone-bool-pointer-implicit-conversion.
This addresses PR45189.
2020-08-05 07:14:28 -04:00
Nathan James 7c4782ce91
[clang-tidy] Fix regression in RenamerClangTidy
See bug https://bugs.llvm.org/show_bug.cgi\?id\=46976
2020-08-04 09:27:01 +01:00
Nathan Ridge 4ede396849 [clang] Include trailing-requires-clause in FunctionDecl's source range
Fixes https://github.com/clangd/clangd/issues/476

Differential Revision: https://reviews.llvm.org/D85108
2020-08-04 02:52:01 -04:00
Nathan James 3b44b6c900
[clang-tidy][NFC] Use correct size call for reserve 2020-08-04 00:31:19 +01:00
Haojian Wu 5191f70ab1 [clangd] Support new/deleta operator in TargetFinder.
Differential Revision: https://reviews.llvm.org/D85028
2020-08-03 14:10:21 +02:00
Ilya Golovenko d76057c1fe
Add document outline symbols from unnamed contexts, e.g. extern "C".
It is necessary to traverse children of unnamed declaration contexts
to get symbols which are currently missing in document outline, e.g.:

extern "C" {
void foo();
}

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D84839
2020-08-03 11:34:56 +02:00
Nathan James 9f21947a33
[clang-tidy][NFC] Small refactor 2020-08-01 11:04:29 +01:00
Nathan James 4888c9ce97
[clang-tidy] readability-identifier-naming checks configs for included files
When checking for the style of a decl that isn't in the main file, the check will now search for the configuration that the included files uses to gather the style for its decls.

This can be useful to silence warnings in header files that follow a different naming convention without using header-filter to silence all warnings(even from other checks) in the header file.

Reviewed By: aaron.ballman, gribozavr2

Differential Revision: https://reviews.llvm.org/D84814
2020-08-01 10:35:32 +01:00
Nathan James 1fd2049e38
[clang-tidy][NFC] Added convienence methods for getting optional options
These methods abstract away Error handling when trying to read options that can't be parsed by logging the error automatically and returning None.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D84812
2020-08-01 01:45:34 +01:00
Haojian Wu 638f0cf565 [clangd] Be more explicit on testing the optional DefLoc in LocatedSymbol.
And also fix a bug where we may return a meaningless location.

Differential Revision: https://reviews.llvm.org/D84919
2020-07-31 14:34:56 +02:00
Bjorn Pettersson 0d25d3b7e3 [clang-tidy] Fix build problem after commit 45a720a864
When building with LLVM8.0 on RHEL7.8 I got failures like this
after commit 45a720a864320bbbe:

/app/llvm/8.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/
5.4.0/../../../../include/c++/5.4.0/ext/new_allocator.h:120:23:
error: no matching constructor for initialization of
'std::pair<std::__cxx11::basic_string<char>,
std::__cxx11::basic_string<char> >'
{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }

...

../../clang-tools-extra/clang-tidy/ClangTidyOptions.cpp:73:15:
note: in instantiation of function template specialization
'std::vector<std::pair<std::__cxx11::basic_string<char>,
std::__cxx11::basic_string<char> >,
std::allocator<std::pair<std::__cxx11::basic_string<char>,
std::__cxx11::basic_string<char> > > >::emplace_back<llvm::StringRef,
const std::__cxx11::basic_string<char> &>' requested here
Options.emplace_back(KeyValue.getKey(), KeyValue.getValue().Value);

This is an attempt to avoid such build problems.
2020-07-31 14:29:03 +02:00
Kirill Bobyrev fb5588b0ad
[clangd] Propagate remote index errors via Expected
This is a refactoring: errors should be logged only on the highest level.
Switch from Optional to Expected in the serialization code.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D84939
2020-07-31 11:48:32 +02:00
Nathan James c23ae3f18e
[clang-tidy][NFC] Use StringMap for ClangTidyCheckFactories::FacoryMap
Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D84926
2020-07-30 22:57:33 +01:00
Artem Dergachev 6a043ecc0c [clang-tidy] Fix ODR violation in unittests.
Both tests define clang::tidy::test::TestCheck::registerMatchers().
This is UB and causes linker to sometimes choose the wrong overload.

Put classes into anonymous namespaces to avoid the problem.

Differential Revision: https://reviews.llvm.org/D84902
2020-07-30 08:52:47 -07:00
Kirill Bobyrev c4b7bfdff6
[clangd] NFC: Spell out types in index callback arguments 2020-07-30 17:12:29 +02:00
Kirill Bobyrev a262f0fea4
[clangd] Implement Relations request for remote index
This is the last missing bit in the core remote index implementation. The only
remaining bits are some API refactorings (replacing Optional with Expected and
being better at reporting errors).

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D84894
2020-07-30 12:57:33 +02:00
Aleksandr Platonov 05b1734661 [clangd] findNearbyIdentifier(): fix the word search in the token stream.
Without this patch the word occurrence search always returns the first token of the file.
Despite of that, `findNeardyIdentifier()` returns the correct result (but inefficently) until there are several matched tokens with the same value `floor(log2(<token line> - <word line>))` (e.g. several matched tokens on the same line).

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D84912
2020-07-30 12:45:58 +03:00
Nathan James 45a720a864
[clang-tidy] Use StringMap for ClangTidyOptions::OptionsMap
Ordering of options isn't important so an `llvm::StringMap` is a much better container for this purpose.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D84868
2020-07-30 10:31:13 +01:00
Haojian Wu cd4e8d7f6f [clangd] Fix an assertion failure in TargetFinder's heuristic resolution of dependent type.
The assertion is not true anymore after D82739, this patch just removes
it, and rename related functions.

And also fixes a missing cases.

Differential Revision: https://reviews.llvm.org/D84837
2020-07-30 08:54:22 +02:00
Richard Smith 6ce97eee35 Fix invalid attempted explicit instantiation, which Clang now rejects. 2020-07-29 13:07:34 -07:00
Nathan James bbc2ddecbd
[clang-tidy] Handled insertion only fixits when determining conflicts.
Handle insertion fix-its when removing incompatible errors by introducting a new EventType `ET_Insert`
This has lower prioirty than End events, but higher than begin.
Idea being If an insert is at the same place as a begin event, the insert should be processed first to reduce unnecessary conflicts.
Likewise if its at the same place as an end event, process the end event first for the same reason.

This also fixes https://bugs.llvm.org/show_bug.cgi?id=46511.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82898
2020-07-29 16:35:44 +01:00
Nathan James 62beb7c6f4
[clang-tidy] Fix module options being registered with different priorities
Not a bug that is ever likely to materialise, but still worth fixing

Reviewed By: DmitryPolukhin

Differential Revision: https://reviews.llvm.org/D84850
2020-07-29 16:19:07 +01:00
Nathan James b99630e432
[clang-tidy] Fix RedundantStringCStrCheck with r values
The previous fix for this, https://reviews.llvm.org/D76761, Passed test cases but failed in the real world as std::string has a non trivial destructor so creates a CXXBindTemporaryExpr.

This handles that shortfall and updates the test case std::basic_string implementation to use a non trivial destructor to reflect real world behaviour.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D84831
2020-07-29 15:35:31 +01:00
Kirill Bobyrev 1603470e59
[clangd] Fix clangd-indexeer builds after D84697
Some buildbots require explicit clangdSupport dependency:

http://lab.llvm.org:8011/builders/llvm-avr-linux/builds/3996/steps/build%20stage%201/logs/stdio
2020-07-29 10:27:11 +02:00
Anh Tuyen Tran 8dbe9b2498 [Clang-tools-extra] Mark override a function which overrides a virtual one
Function void run() on line 286 overrides a virtual function on line 92 of
clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp.  Not marking it override will
cause a build failure when we use -Werror (every warning is treated as an error).

Reviewed By: kbobyrev (Kirill Bobyrev)

Differential Revision: https://reviews.llvm.org/D84794
2020-07-29 05:30:33 +00:00
Kirill Bobyrev fb22678cd6 [clangd] Use elog instead of llvm::errs, log instead of llvm::outs
Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D84697
2020-07-29 01:48:24 +02:00
Nathan James 7bae3188e0 [clang-tidy][NFC] Make OptionsView methods as const where missing 2020-07-28 14:52:43 +01:00