Commit Graph

6383 Commits

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