Commit Graph

6524 Commits

Author SHA1 Message Date
Richard Smith c7a7bba8c1 Fixup clang-tidy after recent Clang change. 2020-10-19 20:13:56 -07:00
Duncan P. N. Exon Smith b3eff6b7bb Lexer: Update the Lexer to use MemoryBufferRef, NFC
Update `Lexer` / `Lexer::Lexer` to use `MemoryBufferRef` instead of
`MemoryBuffer*`. Callers that were acquiring a `MemoryBuffer*` via
`SourceManager::getBuffer` were updated, such that if they checked
`Invalid` they use `getBufferOrNone` and otherwise `getBufferOrFake`.

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

Reviewed By: aaron.ballman

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

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

Reviewed By: alexfh

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

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

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

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

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

Reviewed By: alexfh

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

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

Reviewed By: alexfh, gribozavr2

Patch by Joe Turner.

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

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

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

No functionality change intended here.

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

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

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

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

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

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

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

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

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

Depends on D88411

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

Depends on D88411

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

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

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

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

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

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

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

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

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

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

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

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

Differential Revision: https://reviews.llvm.org/D88814
2020-10-09 10:20:41 +02:00
Kadir Cetinkaya 2ff44935a5
[clangd] Reduce availability of extract function
This patch introduces hoisting detection logic into prepare state with
a partial AST traversal of the enclosing function.

We had some complaints from the users about this code action being almost always
available but failing most of the time. Hopefully this should reduce that noise.

The latency/correctness tradeoff is a bunch of hand-waving, but at least today
we don't have any other actions that are available on selection of statements,
so when we get to do the traversal it is quite likely that all the other checks
will bail out early. But this is still up for discussion, I am happy to abandon
the patch if you believe this is not practical.

Differential Revision: https://reviews.llvm.org/D85354
2020-10-09 10:12:48 +02:00
Haojian Wu efd8c9ed72 [clangd] Add more incomplete_type diagnostics that could be fixed by include-fixer.
Differential Revision: https://reviews.llvm.org/D89036
2020-10-09 08:51:18 +02:00
Utkarsh Saxena a0a6fd435c [clangd] New CC Ranking Model to fix bad inference due to overflow.
Unreachable file distances are represented as
`std::numeric_limits<unsigned>::max()`.
The previous dataset recorded the signals as `signed int` capturing this default
value as `-1`.

A new dataset was regenerated and a new model is trained that
interprets this unreachable as the intended value.

Distribution of `SymbolScopeDistance`:
Value         Normalised Frequency
0             46.6184
4294967295    29.5342
6             14.5666
4              6.4433
2              1.4534
8              0.5760
10             0.3581
....

Distribution of `FileProximityDistance`:
Value         Normalised Frequency
4294967295    39.9378
12             5.1997
14             4.9828
15             4.4221
16             4.3820
13             4.2765
17             3.8957
11             3.6387
19             3.4799
18             3.4076
....

Differential Revision: https://reviews.llvm.org/D89035
2020-10-08 15:30:00 +02:00
Haojian Wu a4e27220c2 [clangd] Add a missing include-fixer test for incomplete_type, NFC.
Also sort the list to make it easier to verify with the implementation
code.

Differential Revision: https://reviews.llvm.org/D88964
2020-10-08 13:33:38 +02:00