Commit Graph

7268 Commits

Author SHA1 Message Date
David Goldman ba06ac8b45 [clangd] Support `#pragma mark` in the outline
Xcode uses `#pragma mark -` to draw a divider in the outline view
and `#pragma mark Note` to add `Note` in the outline view. For more
information, see https://nshipster.com/pragma/.

Since the LSP spec doesn't contain dividers for the symbol outline,
instead we treat `#pragma mark -` as a group with children - the
decls that come after it, implicitly terminating when the symbol's
parent ends.

The following code:

```
@implementation MyClass

- (id)init {}

- (int)foo;
@end
```

Would give an outline like

```
MyClass
        > Overrides
                    > init
        > Public Accessors
                    > foo
```

Differential Revision: https://reviews.llvm.org/D105904
2021-08-09 16:23:53 -04:00
Sam McCall c5c3cdb9c9 [clangd] Populate-switch triggers when the whole condition is selected.
This allows vscode to find it as a diagnostic quickfix for -Wswitch.

While here, group the code into chunks and add a couple more comments.
2021-08-08 21:06:08 +02:00
Sam McCall bb81e7083d [clangd] Add basic support for attributes (selection, hover)
These aren't terribly common, but we currently mishandle them badly.
Not only do we not recogize the attributes themselves, but we often end up
selecting some node other than the parent (because source ranges aren't accurate
in the presence of attributes).

Differential Revision: https://reviews.llvm.org/D89785
2021-08-06 22:49:14 +02:00
Sam McCall c8f148274f Reapply "Support Attr in DynTypedNode and ASTMatchers."
This reverts commit 3241680f11.
Fixed mangled post-test formatting :-(
2021-08-06 22:30:32 +02:00
Sam McCall 3241680f11 Revert "Support Attr in DynTypedNode and ASTMatchers."
This reverts commit a4bdcdadc6.

Fails bots:
https://lab.llvm.org/buildbot/#/builders/109/builds/20231/steps/6/logs/stdio
2021-08-06 22:27:54 +02:00
Sam McCall a4bdcdadc6 Support Attr in DynTypedNode and ASTMatchers.
Differential Revision: https://reviews.llvm.org/D89743
2021-08-06 22:06:04 +02:00
Sam McCall 4ad9ec8a32 [clangd] Rename Features.h -> Feature.h to avoid confilct with libstdc++
Fixes https://github.com/clangd/clangd/issues/835

Differential Revision: https://reviews.llvm.org/D107624
2021-08-06 18:56:41 +02:00
Kadir Cetinkaya 79c2616d31
[clangd] Canonicalize inputs provided with `--`
We already strip all the inputs provided without `--`, this patch also
handles the cases with `--`.

Differential Revision: https://reviews.llvm.org/D107637
2021-08-06 15:04:04 +02:00
Kadir Cetinkaya 3bf77980d9
[clangd] Strip mutliple arch options
This patch strips all the arch options in case of multiple ones. As it
results in multiple compiler jobs, which clangd cannot handle.

It doesn't pick any over the others as it is unclear which one the user wants
and defaulting to host architecture seems less surprising. Users also have the
ability to explicitly specify the architecture they want via clangd config
files.

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

Differential Revision: https://reviews.llvm.org/D107634
2021-08-06 15:04:04 +02:00
Christian Kandeler 159a269648 [clangd] Add new semantic token modifier "virtual"
This is needed for clients that want to highlight virtual functions
differently.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D107145
2021-08-03 19:53:01 -07:00
Douglas Chen 559d142331 [clang-tidy] Fix command line is too long issue which breaks test on Windows
This patch tries to fix command line too long problem on Windows for
https://reviews.llvm.org/D86671.

The command line is too long with check_clang_tidy.py program on Windows,
because the configuration is long for regression test. Fix this issue by
passing the settings in file instead.

Differential Revision: https://reviews.llvm.org/D107325
2021-08-03 22:12:46 +02:00
George Burgess IV 2e75986a21 bugprone-argument-comment: ignore mismatches from system headers
As of 2a3498e24f, we ignore parameter name mismatches for functions
in the `std::` namespace, since those aren't standardized. It seems
reasonable to extend this to all functions which are declared in system
headers, since this lint can be a bit noisy otherwise
(https://bugs.chromium.org/p/chromium/issues/detail?id=1191507).

Differential Revision: https://reviews.llvm.org/D99993
2021-08-03 19:56:27 +00:00
Andy Yankovsky 307b1fddd4 [clang-tidy] Always open files using UTF-8 encoding
The encoding used for opening files depends on the OS and might be different
from UTF-8 (e.g. on Windows it can be CP-1252). The documentation files use
UTF-8 and might be incompatible with other encodings. For example, right now
`clang-tools-extra/docs/clang-tidy/checks/abseil-no-internal-dependencies.rst`
has non-ASCII quotes and running `add_new_check.py` fails on Windows, because
it tries to read the file with incompatible encoding.

Use `io.open` for compatibility with both Python 2 and Python 3.

Reviewed By: kbobyrev

Differential Revision: https://reviews.llvm.org/D106792
2021-08-02 11:36:04 +02:00
Kirill Bobyrev e0f2d4af03
[clangd] Fix the crash in getQualification
Happens when DestContext is LinkageSpecDecl and hense CurContext happens to be
both not TagDecl and NamespaceDecl.

Minimal reproducer: trigger define outline in

```
namespace ns {
extern "C" {
typedef int foo;
}
foo Fo^o(int id) { return id; }
}
```

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D107047
2021-08-02 09:08:25 +02:00
Douglas Chen 2b9b5bc040 [clang-tidy] Add new case type to check variables with Hungarian notation
Add IdentifierNamingCheck::CaseType, CT_HungarianNotation, supporting
naming check with Hungarian notation.

Differential Revision: https://reviews.llvm.org/D86671
2021-08-01 15:22:17 -07:00
Liuke Gehry 4a097efe77 [clang-tidy] Fix cppcoreguidelines-init-variables by removing the enum
FixIt, and add support for initialization check of scoped enum

In C++, the enumeration is never Integer, and the enumeration condition judgment is added to avoid compiling errors when it is initialized to an integer.
Add support for initialization check of scope enum.

As the following case show, clang-tidy will give a wrong automatic fix:

    enum Color {Red, Green, Blue};
    enum class Gender {Male, Female};
    void func() {
      Color color; // Color color = 0; <--- fix bug
      Gender gender; // <--- no warning
    }

Reviewd By: aaron.ballman, whisperity

Differential Revision: http://reviews.llvm.org/D106431
2021-07-30 18:24:47 +02:00
Kadir Cetinkaya 8070bf8c6e
[clangd] Record remote index usage
This is a gauage metric that sets particular remote-index instances as
used. It should enable accumulation of multiple streams to see number of clangd
processes making use of remote index, broken down by remote index address.

Differential Revision: https://reviews.llvm.org/D106796
2021-07-30 15:24:22 +02:00
Kadir Cetinkaya 41e2422286
[clangd] Unify compiler invocation creation
Background-indexing is fine, because it uses GlobalCompilationDatabase
to fetch the compile commands (hence uses CommandMangler), and creates
invocation through buildCompilerInvocation.

Depends on D106639.

Differential Revision: https://reviews.llvm.org/D106669
2021-07-30 15:22:51 +02:00
Kadir Cetinkaya 57346526c8
[clangd] Make use of diagnostic tags for some clang diags
It is not great to list diag ids by hand, but I don't see any other
solution unless diagnostics are annotated with these explicitly, which is a
bigger change in clang and I am not sure if would be worth it.

Diagnostics handled by this patch is by no means exhaustive, there might be
other checks that don't mention "unused"/"deprecated" in their names. But it
feels like this should be enough to catch common diagnostics and can be extended
over time.

Differential Revision: https://reviews.llvm.org/D107040
2021-07-30 15:11:46 +02:00
Kadir Cetinkaya c3682a22c2
[clangd] Enable relative configs in check mode
See https://github.com/clangd/clangd/issues/649#issuecomment-885903316.
Also disables config support in lit tests to make sure tests are not affected by
clangd config files lying around.

Differential Revision: https://reviews.llvm.org/D107130
2021-07-30 14:23:48 +02:00
Fangrui Song 72a83674dd Replace LLVM_ATTRIBUTE_NORETURN with C++11 [[noreturn]]. NFC
[[noreturn]] can be used since Oct 2016 when the minimum compiler requirement was bumped to GCC 4.8/MSVC 2015.
2021-07-29 09:59:45 -07:00
Jesse Towner 68546c9d6f bugprone-forwarding-reference-overload: support non-type template parameters
Many concepts emulation libraries, such as the one found in Range v3, tend to
use non-type template parameters for the enable_if type expression, due to
their versatility in template functions and constructors containing variadic
template parameter packs.

Unfortunately the bugprone-forwarding-reference-overload check does not
handle non-type template parameters, as was first noted in this bug report:
https://bugs.llvm.org/show_bug.cgi?id=38081

This patch fixes this long standing issue and allows for the check to be suppressed
with the use of a non-type template parameter containing enable_if or enable_if_t in
the type expression, so long as it has a default literal value.
2021-07-29 07:01:19 -04:00
Kirill Bobyrev d8fd2146da
NFC: Change quotes from Unicode to ASCII
This was causing some problems for Python scripts that we have.

Context: https://reviews.llvm.org/D106792
2021-07-29 11:37:10 +02:00
Whisperity 21832121e1 [clang-tidy] Fix crash on "reference-to-array" parameters in 'bugprone-easily-swappable-parameters'
An otherwise unexercised code path related to trying to model
"array-to-pointer decay" resulted in a null pointer dereference crash
when parameters of type "reference to array" were encountered.

Fixes crash report http://bugs.llvm.org/show_bug.cgi?id=50995.

Reviewed By: aaron.ballman

Differential Revision: http://reviews.llvm.org/D106946
2021-07-28 14:44:20 +02:00
Tom Stellard 08c766a731 Bump the trunk major version to 14
and clear the release notes.
2021-07-27 21:58:25 -07:00
Kadir Cetinkaya 259e365dea
Revert "Revert "[clangd] Adjust compile flags to contain only the requested file as input""
This reverts commit 04e21fbc44.
2021-07-27 14:49:53 +02:00
Kadir Cetinkaya ab714ba056
Revert "Revert "[clangd] Canonicalize compile flags before applying edits""
Set driver mode before parsing arglist.

Depends on D106789.

Differential Revision: https://reviews.llvm.org/D106794
2021-07-27 14:49:53 +02:00
Sam McCall e2559e5dc6 [clangd] Add platform triple (host & target) to version info
Useful in logs to understand issues around some platforms we don't have much
experience with (e.g. m1, mingw)

Differential Revision: https://reviews.llvm.org/D105681
2021-07-27 14:25:17 +02:00
Sam McCall ec1fb95333 [clangd] Use function pointer instead of function_ref to avoid GCC 5 bug
With GCC <6 constructing a function_ref from a free function reference
leads to it referencing a temporary function pointer. If the lifetime of
that temporary is insufficient it can crash.

Fixes https://github.com/clangd/clangd/issues/800
2021-07-27 14:01:35 +02:00
Sam McCall e9274af718 Revert "[clangd] Avoid range-loop init-list lifetime subtleties."
This reverts commit 253b8145de.

This doesn't actually fix anything - I should stop guessing.
See https://github.com/clangd/clangd/issues/800 for update
2021-07-26 11:38:47 +02:00
Kadir Cetinkaya 0a3c7960cb
Revert "Revert D106562 "[clangd] Get rid of arg adjusters in CommandMangler""
This reverts commit 2aa0cf19e7.
Get rid of reference to the temporary.
2021-07-26 11:13:22 +02:00
Fangrui Song 2aa0cf19e7 Revert D106562 "[clangd] Get rid of arg adjusters in CommandMangler"
This reverts commit 1c0d0085bc.

This commit made unittest BuildCompilerInvocation.DropsPlugins crash.
2021-07-23 09:50:43 -07:00
Kadir Cetinkaya e7590d748a
Revert "[clangd] Canonicalize compile flags before applying edits"
This reverts commit 7cc8a8e384.
2021-07-23 18:20:52 +02:00
Kadir Cetinkaya 04e21fbc44
Revert "[clangd] Adjust compile flags to contain only the requested file as input"
This reverts commit ba5dd945ad.
2021-07-23 17:58:11 +02:00
Kadir Cetinkaya ba5dd945ad
[clangd] Adjust compile flags to contain only the requested file as input
Depends on D106527.

Differential Revision: https://reviews.llvm.org/D106639
2021-07-23 17:15:06 +02:00
Kadir Cetinkaya 7cc8a8e384
[clangd] Canonicalize compile flags before applying edits
Pushes input for the compile action to the end while separating with a
`--` before applying other manglings. This ensures edits that effect only the
arguments that come after them works, like changing parse language via -x.

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

Differential Revision: https://reviews.llvm.org/D106527
2021-07-23 17:15:06 +02:00
Kadir Cetinkaya 1c0d0085bc
[clangd] Get rid of arg adjusters in CommandMangler
Differential Revision: https://reviews.llvm.org/D106562
2021-07-23 17:15:06 +02:00
Kadir Cetinkaya d2a6ec8eae
[clangd] Use CommandMangler in TestTU
This makes testing setup look closer to production.

Differential Revision: https://reviews.llvm.org/D106535
2021-07-23 17:15:05 +02:00
Sam McCall 253b8145de [clangd] Avoid range-loop init-list lifetime subtleties.
The original code appears to be OK per the spec, but we've had 3 reports of
crashes with certain unofficial builds of clangd that look a lot like old
compilers (GCC 5.4?) getting lifetime rules wrong.

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

Differential Revision: https://reviews.llvm.org/D106654
2021-07-23 15:33:04 +02:00
Kirill Bobyrev a0987e350c
[clangd] Improve performance of dex by 45-60%
Take full advantage of AND's iterator children size estimation: use early reset
in sync() and prevent large overhead. The idea is that the children at the
beginning of the list are smaller and cheaper to advance. Very large children
negate the effect of this performance optimisation and hence should be
advanced only when absolutely necessary. By reducing the number of large
iterators' updates, we increase the performance by a large margin.

This change was tested on a comprehensive query dataset. The performance
boost increases with the average length of the query, on small queries it is
close to 45% but the longer they go the closer it gets to 60% and beyond.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D106528
2021-07-23 15:28:35 +02:00
Whisperity 8b0cc4a65d [clang-tidy] Improve "common type" diagnostic output in 'bugprone-easily-swappable-parameters'
Make the check handle cases of the "common type" involved in the mix
being non-trivial, e.g. pointers, references, attributes, these things
coming from typedefs, etc.

This results in clearer diagnostics that have more coverage in their
explanation, such as saying `const int &` as common type instead of
`int`.

Reviewed By: aaron.ballman

Differential Revision: http://reviews.llvm.org/D106442
2021-07-23 10:26:22 +02:00
Felix Berger cb4c12b611 [clang-tidy] performance-unnecessary-copy-initialization: Create option to exclude container types from triggering the check.
Add string list option of type names analagous to `AllowedTypes` which lets
users specify a list of ExcludedContainerTypes.

Types matching this list will not trigger the check when an expensive variable
is copy initialized from a const accessor method they provide, i.e.:

```
ExcludedContainerTypes = 'ExcludedType'

void foo() {
  ExcludedType<ExpensiveToCopy> Container;
  const ExpensiveToCopy NecessaryCopy = Container.get();
}
```

Even though an expensive to copy variable is copy initialized the check does not
trigger because the container type is excluded.

This is useful for container types that don't own their data, such as view types
where modification of the returned references in other places cannot be reliably
tracked, or const incorrect types.

Differential Revision: https://reviews.llvm.org/D106173

Reviewed-by: ymandel
2021-07-22 16:20:20 -04:00
Felix Berger 00edae9203 [clang-tidy] performance-unnecessary-copy-initialization: Disable check when variable and initializer have different replaced template param types.
This can happen when a template with two parameter types is instantiated with a
single type. The fix would only be valid for this instantiation but fail for
others that rely on an implicit type conversion.

The test cases illustrate when the check should trigger and when not.

Differential Revision: https://reviews.llvm.org/D106011
2021-07-22 15:17:24 -04:00
Whisperity 473eff1c30 [clang-tidy] Fix crash and handle AttributedType in 'bugprone-easily-swappable-parameters'
@vabridgers identified a way to crash the check by running on code that
involve `AttributedType`s. This patch fixes the check to first and
foremost not crash, but also improves the logic handling qualifiers.

If the types contain any additional (not just CVR) qualifiers that are
not the same, they will not be deemed mixable. The logic for CVR-Mixing
and the `QualifiersMix` check option remain unchanged.

Reviewed By: aaron.ballman, vabridgers

Differential Revision: http://reviews.llvm.org/D106361
2021-07-22 10:20:17 +02:00
Nathan Ridge f443793d26 [clangd] Ensure Ref::Container refers to an indexed symbol
Fixes https://github.com/clangd/clangd/issues/806

Differential Revision: https://reviews.llvm.org/D105083
2021-07-22 03:33:40 -04:00
David Blaikie a46c63c878 Fix assigned-but-unused (except in an assert) warning with a void cast 2021-07-21 17:12:22 -07:00
Kirill Bobyrev 907efdf95d [clangd] Cleanup FuzzyFindRequest serialization and dex benchmark
* Due to the LLVM's JSON library changes (?), FuzzyFindRequest serialization is
  no longer valid since arrays are serialized as llvm::json::Array already.
  Hence, current implementation creates a nested array.
* YAML format is no longer the default, mention this for the benchmark.
* FIXME is no longer relevant. I ran benchmarks that showed no improvement with
  priority_queue years ago.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D106432
2021-07-21 14:51:16 +02:00
Sam McCall 91670f5f20 [clangd] Remove big PreambleData constructor. NFC 2021-07-21 11:31:52 +02:00
Sam McCall fd22785054 [Lex] Consider a PCH header-guarded even with #endif truncated
This seems to be a more useful behavior for tools that use preambles.
I believe it doesn't affect real compiles: the PCH is only included once
when used, and recursive inclusion of the main-file *within* the PCH
isn't supported in any case.

Differential Revision: https://reviews.llvm.org/D106204
2021-07-20 14:25:36 +02:00
Haojian Wu eb03fa1d2c [clang-tidy] Don't suggest "inline" fix for main function in
definitions-in-headers check.
2021-07-20 14:24:38 +02:00