Commit Graph

6615 Commits

Author SHA1 Message Date
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
Haojian Wu ba268d2fb0 [clangd] Fix a typo, NFC. 2020-10-08 09:35:49 +02:00
Haojian Wu 9c09e2055e [clangd] Add a NewName optional parameter to clangdServer::prepareRename.
If the NewName is provided, prepareRename would perform a name
validation.

The motivation is to allow our internal embeder implement the customized
"canRenameInto" functionality on top of prepareRename.

Differential Revision: https://reviews.llvm.org/D88881
2020-10-07 21:18:51 +02:00
Sam McCall 69daa368ca [clangd] Disambiguate overloads of std::move for header insertion.
Up until now, we relied on matching the filename.
This depends on unstable details of libstdc++ and doesn't work well on other
stdlibs. Also we'd like to remove it (see D88204).

Differential Revision: https://reviews.llvm.org/D88885
2020-10-07 19:42:41 +02:00
Adam Czachorowski bcd8422d75 [clangd] Fix argument type (bool->float).
The default value is 1.3f, but it was cast to true, which is not a good
base for code completion score.

Differential Revision: https://reviews.llvm.org/D88970
2020-10-07 17:22:00 +02:00
Haojian Wu f24649b77d [clangd] Don't set the Underlying bit on targets of UsingDecls.
With this patch, we don't treat `using ns::X` as a first-class declaration like `using Z = ns::Y`, reference to X that goes through this using-decl is considered a direct reference (without the Underlying bit).

Fix the workaround in https://reviews.llvm.org/D87225 and https://reviews.llvm.org/D74054.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D88472
2020-10-07 10:01:04 +02:00
Haojian Wu 8a3cbb1535 [clangd] Add basic keyword-name-validation in rename.
Differential Revision: https://reviews.llvm.org/D88875
2020-10-06 15:47:57 +02:00
Adam Balogh d6c9dc3c17 [clang-tidy] Remove obsolete checker google-runtime-references
The rules which is the base of this checker is removed from the
//Google C++ Style Guide// in May:
[[ https://github.com/google/styleguide/pull/553 | Update C++ styleguide ]].
Now this checker became obsolete.

Differential Revision: https://reviews.llvm.org/D88831
2020-10-06 14:03:55 +02:00
Sam McCall 3cb1220709 [clangd] Add `score` extension to workspace/symbol response.
The protocol doesn't really incorporate ranking.
As with code completion, most clients respect what the server sends, but
VSCode re-ranks items, with predictable results.
See https://github.com/clangd/vscode-clangd/issues/81

There's no filterText field so we may be unable to construct a good workaround.
But expose the score so we may be able to do this on the client in future.

Differential Revision: https://reviews.llvm.org/D88844
2020-10-06 11:57:38 +02:00
Haojian Wu 48a82c4245 [clangd] Verify the diagnostic code in include-fixer diagnostic tests, NFC.
Make it easier to spot which diagnostics in the include-fixer list are tested.

Differential Revision: https://reviews.llvm.org/D88828
2020-10-06 11:02:22 +02:00
Haojian Wu 77d3b14458 [clangd] Fix an inconsistent ReasonToReject enum usage, NFC. 2020-10-06 10:17:47 +02:00
Sam McCall 95262ee2be [clangd] Describe non-handling of most IWYU pragmas. NFC
Differential Revision: https://reviews.llvm.org/D88822
2020-10-05 20:50:26 +02:00
Haojian Wu 1425c72236 [clangd] Add isKeyword function.
This will be used in rename for doing basic name validation.

Differential Revision: https://reviews.llvm.org/D88810
2020-10-05 15:11:24 +02:00
Haojian Wu 96c8a17c80 [clangd] Remove unused using-decls in TypeHierarchyTests, NFC. 2020-10-05 13:14:53 +02:00
Aaron Ballman 089e628b61 Add a break statement to appease the build bots; NFC 2020-10-03 11:10:26 -04:00
Bernhard Manfred Gruber 07028cd5db modernize-use-trailing-return-type fix for PR44206
Prevent rewrite when an unqualified id in a typedef type collides
with a function argument name. Fixes PR44206.
2020-10-03 10:08:44 -04:00
Roman Lebedev 1596cc8350
[NFCI][clang-tidy] FunctionCognitiveComplexityCheck::check(): try to fix windows arm build bots
http://lab.llvm.org:8011/builders/llvm-clang-win-x-armv7l/builds/1482/steps/build-llvm-project/logs/stdio
http://lab.llvm.org:8011/builders/llvm-clang-win-x-aarch64/builds/3285/steps/build-llvm-project/logs/stdio
2020-10-03 16:02:19 +03:00
Roman Lebedev ace644030e
[clang-tidy] Implement readability-function-cognitive-complexity check
Currently, there is basically just one clang-tidy check to impose
some sanity limits on functions - `clang-tidy-readability-function-size`.
It is nice, allows to limit line count, total number of statements,
number of branches, number of function parameters (not counting
implicit `this`), nesting level.

However, those are simple generic metrics. It is still trivially possible
to write a function, which does not violate any of these metrics,
yet is still rather unreadable.

Thus, some additional, slightly more complicated metric is needed.
There is a well-known [[ https://en.wikipedia.org/wiki/Cyclomatic_complexity | Cyclomatic complexity]], but certainly has its downsides.
And there is a [[ https://www.sonarsource.com/docs/CognitiveComplexity.pdf | COGNITIVE COMPLEXITY by SonarSource ]], which is available for opensource on https://sonarcloud.io/.

This check checks function Cognitive Complexity metric, and flags
the functions with Cognitive Complexity exceeding the configured limit.
The default limit is `25`, same as in 'upstream'.

The metric is implemented as per [[ https://www.sonarsource.com/docs/CognitiveComplexity.pdf | COGNITIVE COMPLEXITY by SonarSource ]] specification version 1.2 (19 April 2017), with two notable exceptions:
   * `preprocessor conditionals` (`#ifdef`, `#if`, `#elif`, `#else`,
     `#endif`) are not accounted for.
      Could be done. Currently, upstream does not account for them either.
   * `each method in a recursion cycle` is not accounted for.
      It can't be fully implemented, because cross-translational-unit
      analysis would be needed, which is not possible in clang-tidy.
      Thus, at least right now, i completely avoided implementing it.

There are some further possible improvements:
* Are GNU statement expressions (`BinaryConditionalOperator`) really free?
  They should probably cause nesting level increase,
  and complexity level increase when they are nested within eachother.
* Microsoft SEH support
* ???

Reviewed By: aaron.ballman, JonasToth, lattner

Differential Revision: https://reviews.llvm.org/D36836
2020-10-03 00:27:13 +03:00
Utkarsh Saxena db2a646c5f [clangd] Add bencmark for measuring latency of DecisionForest model.
Differential Revision: https://reviews.llvm.org/D88590
2020-10-02 18:04:31 +02:00
Haojian Wu 0f0cbcc4b1 [clangd] Extend the rename API.
several changes:
- return a structure result in rename API;
- prepareRename now returns more information (main-file occurrences);
- remove the duplicated detecting-touch-identifier code in prepareRename (which is implemented in rename API);

Differential Revision: https://reviews.llvm.org/D88634
2020-10-02 16:03:44 +02:00
Sam McCall 57ac47d788 [clangd] Make PopulateSwitch a fix.
It fixes the -Wswitch warning, though we mark it as a fix even if that is off.
This makes it the "recommended" action on an incomplete switch, which seems OK.

Differential Revision: https://reviews.llvm.org/D88726
2020-10-02 13:24:24 +02:00
Kadir Cetinkaya 54c03d8f7d
[clangd][lit] Update document-link.test to respect custom resource-dir locations
Differential Revision: https://reviews.llvm.org/D88721
2020-10-02 12:24:06 +02:00
Sam McCall 17747d2ec8 [clangd] Remove Tweak::Intent, use CodeAction kind directly. NFC
Intent was a nice idea but it ends up being a bit awkward/heavyweight
without adding much.

In particular, it makes it hard to implement `CodeActionParams.only` properly
(there's an inheritance hierarchy for kinds).

Differential Revision: https://reviews.llvm.org/D88427
2020-10-02 11:14:23 +02:00
Sam McCall bc18d8d9b7 [clangd] Drop dependence on standard library in check.test 2020-10-02 09:53:06 +02:00
Florian Mayer 9d40fb808f Allow to specify macro names for android-comparison-in-temp-failure-retry
Some projects do not use the TEMP_FAILURE_RETRY macro but define their
own one, as not to depend on glibc / Bionic details. By allowing the
user to override the list of macros, these projects can also benefit
from this check.

Differential Revision: https://reviews.llvm.org/D83144
2020-10-01 10:09:26 -07:00
Utkarsh Saxena 45698ac005 [clangd] Split DecisionForest Evaluate() into one func per tree.
This allows us MSAN to instrument this function. Previous version is not
instrumentable due to it shear volume.

Differential Revision: https://reviews.llvm.org/D88536
2020-10-01 18:07:23 +02:00
Sam McCall f6b1323bc6 Reland [clangd] clangd --check: standalone diagnosis of common problems
This reverts commit 30d07b14a2.

Test failures have (hopefully) been fixed.
2020-10-01 16:18:18 +02:00
Sam McCall 30d07b14a2 Revert "[clangd] clangd --check: standalone diagnosis of common problems"
This reverts commit 79fbcbff41.

The fallback command fails to parse for the test files if there's no
compile_commands.json in the tree.
2020-10-01 16:10:03 +02:00
Sam McCall 79fbcbff41 [clangd] clangd --check: standalone diagnosis of common problems
This is a tool to simply parse a file as clangd would, and run some
common features (code actions, go-to-definition, hover) in an attempt to
trigger or reproduce crashes, error diagnostics, etc.

This is easier and more predictable than loading the file in clangd, because:
 - there's no editor/plugin variation to worry about
 - there's no accidental variation of user behavior or other extraneous requests
 - we trigger features at every token, rather than guessing
 - everything is synchronoous, logs are easier to reason about
 - it's easier to (get users to) capture logs when running on the command-line

This is a fairly lightweight variant of this idea.
We could do a lot more with it, and maybe we should.
But I can't in the near future, and experience will tell us if we made
the right tradeoffs and if it's worth investing further.

Differential Revision: https://reviews.llvm.org/D88338
2020-10-01 15:47:47 +02:00
Sam McCall 85fc5bf341 [clangd] Remove dead variable. NFC 2020-09-30 23:19:15 +02:00
Sam McCall 216af81c39 [clangd] Fix invalid UTF8 when extracting doc comments.
Differential Revision: https://reviews.llvm.org/D88567
2020-09-30 16:05:12 +02:00
Kadir Cetinkaya 64e8fd540e
[clangd][remote] Make sure relative paths are absolute with respect to posix style
Relative paths received from the server are always in posix style. So
we need to ensure they are relative using that style, and not the native one.

Differential Revision: https://reviews.llvm.org/D88507
2020-09-30 11:08:49 +02:00
Sam McCall d99f46c6eb [clangd] Fix fuzzer build after 7ba0779fbb 2020-09-30 11:02:05 +02:00
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