Commit Graph

6072 Commits

Author SHA1 Message Date
Yitzhak Mandelbaum a1b88afe46 [clang-tidy] Fix build broken by commit 7cfdff7b4a (D80023) 2020-05-28 13:39:58 -04:00
Tom Lokovic 7cfdff7b4a [clang-tidy] Add abseil-string-find-str-contains checker.
Summary: This adds a checker which suggests replacing string.find(...) == npos with absl::StrContains.

Reviewers: alexfh, hokein, aaron.ballman, njames93, ymandel

Reviewed By: ymandel

Subscribers: ymandel, Eugene.Zelenko, xazax.hun, mgorny, Charusso, phosek, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D80023
2020-05-28 12:35:57 -04:00
Sam McCall 8e325cfc14 [clangd] Work around PS4 -fno-exceptions, easier than disabling tests? 2020-05-28 17:14:23 +02:00
Sam McCall a56141b8f9 [clangd] Highlight related control flow.
Summary:
This means e.g. highlighting "return" will show other returns/throws
from the same function, highlighting a case will show all the
return/breaks etc.

This is a bit of an abuse of textDocument/highlight, but seems useful.

Reviewers: adamcz

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D78454
2020-05-28 13:25:11 +02:00
Daniel Martín 6407aa9d2e
[clangd] Add access specifier information to hover contents
Summary:
For https://github.com/clangd/clangd/issues/382

This commit adds access specifier information to the hover
contents. For example, the hover information of a class field or
member function will now indicate if the field or member is private,
public, or protected. This can be particularly useful when a developer
is in the implementation file and wants to know if a particular member
definition is public or private.

Reviewers: kadircet

Reviewed By: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80472
2020-05-27 19:36:46 +02:00
Sam McCall 1abb883a04 [clangd] Don't traverse the AST within uninteresting files during indexing
Summary:
We already skip function bodies from these files while parsing, and drop symbols
found in them. However, traversing their ASTs still takes a substantial amount
of time.

Non-scientific benchmark on my machine:
  background-indexing llvm-project (llvm+clang+clang-tools-extra), wall time
  before: 7:46
  after: 5:13
  change: -33%

Indexer.cpp libclang should be updated too, I'm less familiar with that code,
and it's doing tricky things with the ShouldSkipFunctionBody callback, so it
needs to be done separately.

Reviewers: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80296
2020-05-26 10:27:28 +02:00
Kadir Cetinkaya 34e39eb2ad
[clangd] Change PreambleOnlyAction with content truncation
Summary:
Lexing until the token location is past preamble bound could be wrong
in some cases as preprocessor lexer can lex multiple tokens in a single call.

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79426
2020-05-26 07:37:03 +02:00
Kadir Cetinkaya eeedbd0336
[clangd] Make use of SourceOrder to find first initializer in DefineOutline
Summary:
Constructors can have implicit initializers, this was crashing define
outline. Make sure we find the first "written" ctor initializer to figure out
`:` location.

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

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80521
2020-05-26 07:32:07 +02:00
Haojian Wu 72c5ea1d73 [clangd] Enable cross-file-rename by default.
Summary:
The cross-file rename feature is stable enough to enable it (has been
rolled out internally for a few weeks).

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80507
2020-05-25 10:46:57 +02:00
Sam McCall b752a2743a [clangd] Log use of heuristic go-to-def. NFC
Generally:
 - found results using this method -> log
 - no results using this method -> vlog
 - method wasn't applied because ineligible -> no log
2020-05-25 10:19:34 +02:00
Stephen Kelly 2be92b7f7e Fix ignore-traversal to call correct method
As is done by ignoreParenImpCasts(). We were not previously calling the
correct internal method.  Adjust tests to account for this.
2020-05-24 22:33:10 +01:00
Nathan James 4c5818dd8c [clang-tidy] Fix potential assert in use-noexcept check
Summary: Fix a potential assert in use-noexcept check if there is an issue getting the `TypeSourceInfo` as well as a small clean up.

Reviewers: aaron.ballman, alexfh, gribozavr2

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80371
2020-05-24 14:40:58 +01:00
Stephen Kelly 5e9392deaf Add explicit traversal mode to matchers for implicit constructors 2020-05-24 12:36:15 +01:00
Stephen Kelly 10f0f98eac Add a way to set traversal mode in clang-query
Reviewers: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73037
2020-05-23 14:57:10 +01:00
Stephen Kelly 8d62eba105 Add some explicit use of TK_AsIs 2020-05-23 01:04:44 +01:00
Joe Ranieri e4bb3e25e4 [clang-tidy] Expand the list of functions in bugprone-unused-return-value
This change adds common C, C++, and POSIX functions to the clang-tidy unused return value checker.

Differential Revision: https://reviews.llvm.org/D76083
2020-05-22 12:57:58 -04:00
Stephen Kelly a72307c3a6 Set traversal explicitly where needed in clang-tidy
Reviewers: aaron.ballman

Subscribers: nemanjai, kbarton, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D72530
2020-05-21 22:34:37 +01:00
Kirill Bobyrev c6b2b78429 [clangd-remote] Replace YAML serialization with proper Protobuf messages
Summary:
YAML serialization was used in the Proof of Concept for simplicity.
This patch replaces implements Protobuf (de) serialization of almost all
types that need to be transferred over the protocol.

Reviewers: sammccall

Reviewed By: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79862
2020-05-19 17:07:38 +02:00
Sam McCall 5bc0c8f009 [clangd] Avoid StringRef entirely with gmock 2020-05-19 16:50:35 +02:00
Sam McCall b0d94964da [clangd] findExplicitReferences supports goto labels
Summary:
This means they're renamable and textDocument/highlight works

This fell out of D78454

Reviewers: adamcz

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80170
2020-05-19 16:50:35 +02:00
Sam McCall 7ebf7d91e6 [clangd] Delete regex assertion, breaking on windows too... 2020-05-19 16:07:01 +02:00
Haojian Wu fcf0764998 [AST] Fix an assertion violation in FieldDecl::getParent.
Summary:
FieldDecl::getParent assumes that the FiledDecl::getDeclContext returns a
RecordDecl, this is true for C/C++, but not for ObjCIvarDecl:

The Decls hierarchy is like following

FieldDecl <-- ObjCIvarDecl

DeclContext <-- ObjCContainerDecl <-- ObjCInterfaceDecl
         ^
         |----- TagDecl <-- RecordDecl

calling getParent() on ObjCIvarDecl will:
1. invoke getDeclContext(), which returns a DeclContext*, which points to an ObjCInterfaceDecl;
2. then downcast the "DeclContext" pointer to a RecordDecl*, and we will hit
the "is_a<RecordDecl>" assertion in llvm::cast (undefined behavior
in release build without assertion enabled);

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

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: rsmith, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79627
2020-05-19 15:35:04 +02:00
Haojian Wu 0320ce8916 [clangd] Add a flag to preserve type for recovery expression.
Reviewers: sammccall

Reviewed By: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79938
2020-05-19 15:21:57 +02:00
Simon Pilgrim 6e99199419 Fix "not all control paths return a value" warning on MSVC builds.
Use llvm_unreachable as typeName(Metric::MetricType T) should handle all enum values.
2020-05-19 13:16:24 +01:00
Sam McCall 61559d0458 [clangd] Squash GCC error with StringRef + gtest MatchesRegex() 2020-05-19 13:58:23 +02:00
Sam McCall 9b88a190b4 [clangd] Add CSV export for trace metrics
Summary: Example: https://docs.google.com/spreadsheets/d/1VZKGetSUTTDe9p4ooIETmdcwUod1_aE3vgD0E9x7HhI/edit

Reviewers: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79678
2020-05-19 13:35:31 +02:00
Sam McCall 032727f4f8 [clangd] Complete filenames after < / ".
Summary:
Extract prefix filters to CodeComplete so it can be easily tested.

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

Reviewers: adamcz

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79456
2020-05-19 13:32:26 +02:00
Mikael Holmen e408b54290 [clangd] Fix gcc compiler warning by removing extra ";" [NFC]
gcc complained with:

/data/repo/master/clang-tools-extra/clangd/index/Ref.h:189:2: warning: extra ';' [-Wpedantic]
 }; // namespace llvm
  ^
2020-05-19 11:57:15 +02:00
Sam McCall e3e15836af [clangd] Tidy up SelectionTree dumps with newlines 2020-05-19 01:48:01 +02:00
Sam McCall d19265b31e [clangd] Avoid wasteful data structures in RefSlab::Builder
Summary: This is worth another 10% or so on InedxBenchmark.DexBuild.

Reviewers: kbobyrev

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79950
2020-05-18 22:34:59 +02:00
Kirill Bobyrev 968d293063 [clang-tidy] NFC: Cleanup Python scripts
Summary: Silence few PEP8 warnings.

Reviewers: hokein

Reviewed By: hokein

Subscribers: Eugene.Zelenko, xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D78985
2020-05-18 12:21:27 +02:00
Nathan James 4f0cc10bf5 [NFC][clang-tidy] use hasOperands in place of hasEitherOperand 2020-05-18 10:11:22 +01:00
Nathan James 7af0c8559b [clang-tidy] Transformer checks now store IncludeStyle option 2020-05-16 01:14:55 +01:00
Nathan James aef778d4d3 [clang-tidy] Fix assertion in RenamerClangTidyChecks 2020-05-15 12:15:35 +01:00
Alex Lorenz 10b49315fa [test] NFC, add missing declarations and include to test files to avoid 'implicit-function-declaration' diagnostics in the tests 2020-05-14 10:01:50 -07:00
Haojian Wu 0e5706d018 [clangd] Correct the elog message, NFC. 2020-05-14 14:15:21 +02:00
Sam McCall 17ba631d13 [clangd] Remove extra qualification 2020-05-14 14:06:05 +02:00
Sam McCall 735ab46cb4 [clangd] Don't create as much garbage while building Dex index.
Summary:
The Token objects are relatively expensive and we were spending a lot of
CPU creating them for each trigram emitted. Instead, use a tiny trigram
structure until we're ready to finalize the index.

This improves the new BuildDex benchmark by 20%. This code is hot and on
the critical path in clangd: it runs after a new preamble is built.

Reviewers: kbobyrev

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79918
2020-05-14 13:35:44 +02:00
Haojian Wu 2045189043 [clangd] Setting recovery-ast flag in buildCompilerInvocation, NFC.
This saves some duplicated code (in buildPreamble and buildAST).
2020-05-14 13:16:59 +02:00
Haojian Wu dbc9e1c39a [clangd] Only emit default error/fatal diagnostices from included files.
Summary:
This would avoid adding too much noise when there is a "-Wall" in the
compile command.

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79923
2020-05-14 11:09:06 +02:00
Haojian Wu 774acdfb8c [clangd] Add metrics for selection tree and recovery expressions.
Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79701
2020-05-12 16:14:48 +02:00
Nathan Ridge 5a7276b354 [clangd] Have suppression comments take precedence over warning-as-error
Summary: This matches the clang-tidy behaviour.

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

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79691
2020-05-12 02:29:03 -04:00
Kadir Cetinkaya cc9fefec43
[clangd] Make version in PublishDiagnosticsParams optional
Summary: We were serializing it no matter what, which was against the spec

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79692
2020-05-11 10:31:10 +02:00
Richard Smith c7ebf00670 Fix clangd test that depended on a diagnostic removed in Clang. 2020-05-10 14:13:25 -07:00
Kadir Cetinkaya 35d867a790
[clangd] Filter pch related flags coming from the user
Summary:
PCH format is unstable, hence using a preamble built with a different
version of clang (or even worse, a different compiler) might result in
unexpected behaviour.

PCH creation on the other hand is something clangd wouldn't want to perform, as
it doesn't generate any output files.

This patch makes sure clangd drops any PCH related compile commands after
parsing the command line args.

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

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79669
2020-05-10 13:03:59 +02:00
Sylvestre Ledru a832fc4b0c Revert two patches, not ready to be shared
Revert "clang-tidy doc: add a note for checkers with an autofix"

This reverts commit dc0f79ea5b.

Revert "add_new_check.py: Update of the template to add an autofix section"

This reverts commit f97f92e5b0.
2020-05-10 11:27:13 +02:00
Sylvestre Ledru b0828135db clang-tidy doc: Fix the syntax to use rst list type 2020-05-10 11:25:20 +02:00
Sylvestre Ledru dc0f79ea5b clang-tidy doc: add a note for checkers with an autofix
Summary:
Currently, when looking at a checker documentation, we have to go back
to the whole list or look at the sources to figure out if an autofix
is available or not.

Reviewers: alexfh, aaron.ballman

Subscribers: wuzish, Eugene.Zelenko, nemanjai, kbarton, arphaman, Charusso, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77983
2020-05-10 11:25:19 +02:00
Sylvestre Ledru f97f92e5b0 add_new_check.py: Update of the template to add an autofix section
Summary: As discussed here: https://reviews.llvm.org/D77983

Reviewers: alexfh

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D78052
2020-05-10 11:25:19 +02:00
Nathan James 0e49ac73ea [NFC] Small rework to RenamerClangTidyCheck addUsage 2020-05-09 18:57:05 +01:00