Commit Graph

3065 Commits

Author SHA1 Message Date
Ilya Biryukov 7e5ee26d1a Resubmit "[clangd] The new threading implementation"
Initially submitted as r324356 and reverted in r324386.

This change additionally contains a fix to crashes of the buildbots.
The source of the crash was undefined behaviour caused by
std::future<> whose std::promise<> was destroyed without calling
set_value().

llvm-svn: 324575
2018-02-08 07:37:35 +00:00
Eric Liu 7deda4f5af [clangd] Do not precent-encode numbers in URI.
Reviewers: ilya-biryukov

Subscribers: klimek, jkorous-apple, cfe-commits, sammccall

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

llvm-svn: 324475
2018-02-07 12:12:06 +00:00
Saleem Abdulrasool 16d26f6f94 test: use target triple for the test
Now that `pragma comment` is also used on ELF-ish targets with a
restricted set of options, we need to specify the full target here for
the test.

llvm-svn: 324441
2018-02-07 02:27:34 +00:00
Julie Hockett 7a76ada901 [clang-tidy] Update fuchsia-multiple-inheritance to check for templates
Updating fuchsia-multiple-inheritance to not crash when a record
inherits a template.

Fixes PR36052.

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

llvm-svn: 324432
2018-02-07 00:33:50 +00:00
Yan Zhang ae5bc5aeea Support special acronyms inside property names and allow plural forms
Reviewers: benhamilton, hokein

Reviewed By: benhamilton, hokein

Subscribers: klimek, cfe-commits

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

llvm-svn: 324407
2018-02-06 21:40:38 +00:00
Benjamin Kramer 5eb6a284b1 [clangd] Make the premble tremble.
No functionality change.

llvm-svn: 324389
2018-02-06 20:08:23 +00:00
Ilya Biryukov 3693f5941a Revert "[clangd] The new threading implementation" (r324356)
And the follow-up changes r324361 and r324363.
These changes seem to break two buildbots:
  - http://lab.llvm.org:8011/builders/clang-atom-d525-fedora-rel/builds/14091
  - http://lab.llvm.org:8011/builders/clang-x86_64-linux-selfhost-modules-2/builds/16001

We will need to investigate what went wrong and resubmit the changes
afterwards.

llvm-svn: 324386
2018-02-06 19:22:40 +00:00
Ilya Biryukov 7e817a2c0c [clangd] Attempt to unbreak windows buildbots.
Some buildbots are breaking on trace.test due to using Linux's path
separators. This commit should unbreak them.

llvm-svn: 324382
2018-02-06 19:09:44 +00:00
Ilya Biryukov 0c904861e6 [clangd] Fixed a bug in the new threading implementation.
This should fix the buildbots.

llvm-svn: 324363
2018-02-06 17:22:58 +00:00
Ilya Biryukov b9cf83b16f [clangd] Fixed compilation on Windows buildbot.
llvm-svn: 324361
2018-02-06 16:32:36 +00:00
Eric Liu 7f24765912 [clangd] Use URIs in index symbols.
Reviewers: hokein, sammccall

Reviewed By: sammccall

Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits

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

llvm-svn: 324358
2018-02-06 16:10:35 +00:00
Ilya Biryukov cce8883094 [clangd] The new threading implementation
Summary:
In the new threading model clangd creates one thread per file to manage
the AST and one thread to process each of the incoming requests.
The number of actively running threads is bounded by the semaphore to
avoid overloading the system.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: klimek, mgorny, jkorous-apple, ioeric, hintonda, cfe-commits

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

llvm-svn: 324356
2018-02-06 15:53:42 +00:00
Eric Liu c42d1431f6 [clangd] Remove unused variable. NFC
llvm-svn: 324354
2018-02-06 15:27:43 +00:00
Sam McCall 3aecc7fd45 [clangd] Don't try pthread, just use thread_local. Reverts r323949.
The pthread solution here breaks standalone builds, which don't have the
relevant cmake magic for feature-detection.

The original reason for trying pthread was fear of libgcc without
support for thread_local (e.g. on the clang-x86_64-linux-selfhost-modules bot).
However the earliest supported GCC is 4.8, and this has __cxa_thread_atexit.

This will probably break that bot, it's not running a supported GCC and needs
to be upgraded. I'll try to find out how to do this.

llvm-svn: 324351
2018-02-06 14:25:02 +00:00
Sam McCall e290a8cd80 [clangd] Cut input-mirror.test down to size. NFC
llvm-svn: 324334
2018-02-06 10:51:22 +00:00
Sam McCall 5ed599eafa [clangd] Support simpler JSON-RPC stream parsing for lit tests.
Summary:
Instead of content-length, we delimit messages with ---.
This also removes the need for (most) dos-formatted test files.

Reviewers: ioeric

Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits

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

llvm-svn: 324333
2018-02-06 10:47:30 +00:00
Haojian Wu 3b8e00c5e0 [clangd] Fix incorrect file path for symbols defined by the compile command-line option.
Summary:

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits

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

llvm-svn: 324328
2018-02-06 09:50:35 +00:00
Benjamin Kramer 53966a4ad8 [clangd] Add a cstring include for strerror.
Apparently this doesn't get included transitively on some systems.

llvm-svn: 324277
2018-02-05 22:10:39 +00:00
Haojian Wu 0b9e6224fc [clang-tidy] Fix incorrect code indention in the doc.
llvm-svn: 324235
2018-02-05 13:23:48 +00:00
Haojian Wu 40f6428530 [clang-tidy] tweak "misc-definitions-in-headers" doc, NFC.
llvm-svn: 324233
2018-02-05 13:04:41 +00:00
Haojian Wu d86ad2e359 [clangd] Expclictly set the init value of -assume-header-dir option, NFC.
llvm-svn: 324220
2018-02-05 10:14:16 +00:00
Sam McCall c40fdcdd7e [clangd] Fix ExternC test broken by r324081
llvm-svn: 324105
2018-02-02 17:01:36 +00:00
Ben Hamilton b4ab4b6317 [clang-tidy] ObjC ARC objects should not trigger performance-unnecessary-value-param
Summary:
The following Objective-C code currently incorrectly triggers
clang-tidy's performance-unnecessary-value-param check:

```
% cat /tmp/performance-unnecessary-value-param-arc.m
void foo(id object) { }

clang-tidy /tmp/performance-unnecessary-value-param-arc.m
-checks=-\*,performance-unnecessary-value-param -- -xobjective-c
-fobjc-abi-version=2 -fobjc-arc
1 warning generated.
/src/llvm/tools/clang/tools/extra/test/clang-tidy/performance-unnecessary-value-param-arc.m:10:13:
warning: the parameter 'object' is copied for each invocation but only
used as a const reference; consider making it a const reference
[performance-unnecessary-value-param]
void foo(id object) { }
         ~~ ^
         const &
```

This is wrong for a few reasons:

1) Objective-C doesn't have references, so `const &` is not going to help
2) ARC heavily optimizes the "expensive" copy which triggers the warning

This fixes the issue by disabling the warning for non-C++, as well as
disabling it for objects under ARC memory management for
Objective-C++.

Fixes https://bugs.llvm.org/show_bug.cgi?id=32075

Test Plan: New tests added. Ran tests with `make -j12 check-clang-tools`.

Reviewers: alexfh, hokein

Reviewed By: hokein

Subscribers: stephanemoore, klimek, xazax.hun, cfe-commits, Wizard

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

llvm-svn: 324097
2018-02-02 15:34:33 +00:00
Benjamin Kramer 26f2eec212 [clang-tidy] Kill marco. No functionality change.
llvm-svn: 324084
2018-02-02 13:39:07 +00:00
Benjamin Kramer a9bef621b0 [clang-tidy] Widen anonymous namespace.
The matchers in this check are prone to create ODR violations otherwise.
No functionality change.

llvm-svn: 324083
2018-02-02 13:39:00 +00:00
Benjamin Kramer 492f1cc8c7 [clang-tidy] Remove global constructor. No functionality change intended.
llvm-svn: 324080
2018-02-02 13:23:24 +00:00
Benjamin Kramer 10db8d6dbc [clang-tidy] Don't reinvent the wheel, use existing log2 functions.
This also makes the code ready for int128, even though I think it's
currently impossible to get an int128 into this code path.

llvm-svn: 324079
2018-02-02 13:23:21 +00:00
Eric Liu 553f267cff [clangd] Remove a unused include. NFC
llvm-svn: 324073
2018-02-02 11:25:38 +00:00
Eric Liu cf1773826f [clangd] Skip inline namespace when collecting scopes for index symbols.
Summary:
Some STL symbols are defined in inline namespaces. For example,
```
namespace std {
inline namespace __cxx11 {
 typedef ... string;
}
}
```
Currently, this will be `std::__cxx11::string`; however, `std::string` is desired.

Inline namespaces are treated as transparent scopes. This
reflects the way they're most commonly used for lookup. Ideally we'd
include them, but at query time it's hard to find all the inline
namespaces to query: the preamble doesn't have a dedicated list.

Reviewers: sammccall, hokein

Reviewed By: sammccall

Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits

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

llvm-svn: 324065
2018-02-02 10:31:42 +00:00
Ilya Biryukov d14dc49dff [clangd] Log dropped diagnostics.
Summary:
clangd drops diagnostics coming outside the main file, but it is still
useful to see that something went wrong in the logs.

Reviewers: hokein, ioeric, sammccall

Reviewed By: sammccall

Subscribers: klimek, jkorous-apple, cfe-commits

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

llvm-svn: 323992
2018-02-01 19:06:45 +00:00
Alexander Kornienko 396fc87694 [clang-tidy] misc-redundant-expression: fix a crash under ubsan
llvm-svn: 323980
2018-02-01 16:39:12 +00:00
Haojian Wu a8d12bbc3f [clangd] remove the unused code NFC.
llvm-svn: 323960
2018-02-01 13:06:58 +00:00
Eric Liu cda2526d86 [clangd] Fix URI scheme conflict and an unused variable warning in tests. NFC
llvm-svn: 323957
2018-02-01 12:44:52 +00:00
Sam McCall e0a3dec9fb [clangd] Use pthread instead of thread_local to support more runtimes.
Summary:
thread_local has nice syntax and semantics, but requires __cxa_thread_atexit,
and some not-ancient runtime libraries don't provide it.
The clang-x86_64-linux-selfhost-modules buildbot is one example :-)

It works on windows, and the other platforms clang-tools-extra supports should
all have the relevant pthread API. So we just use that if it's available,
falling back to thread_local (so if a platform has neither, we'll fail to link).

The fallback should really be the other way, that would require cmake changes.

Reviewers: ilya-biryukov, bkramer

Subscribers: klimek, jkorous-apple, ioeric, cfe-commits

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

llvm-svn: 323949
2018-02-01 10:01:25 +00:00
Ben Hamilton ffd2df0e33 [clang-tidy] New argument --language to add_new_check.py
Summary:
Currently, add_new_check.py assumes all checks are for C++ code.

This adds a new argument --language=[LANG] to add_new_check.py
so authors of new checks can specify that the test file should
be in a different language.

For example, authors can pass --language=objc for Objective-C
clang-tidy checks.

Reviewers: hokein, alexfh

Reviewed By: alexfh

Subscribers: Wizard, xazax.hun

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

llvm-svn: 323919
2018-01-31 21:52:39 +00:00
Eric Liu 5740ff5bed [clangd] Add a test URI scheme for lit tests to unbreak platform-specific URI failures.
Summary:
This should also fix the current windows buildbot breakage
(http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/9838/steps/ninja%20check%201/logs/stdio)

Reviewers: sammccall

Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits

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

llvm-svn: 323885
2018-01-31 16:26:27 +00:00
Sam McCall d1a7a37c22 [clangd] Pass Context implicitly using TLS.
Summary:
Instead of passing Context explicitly around, we now have a thread-local
Context object `Context::current()` which is an implicit argument to
every function.
Most manipulation of this should use the WithContextValue helper, which
augments the current Context to add a single KV pair, and restores the
old context on destruction.

Advantages are:
- less boilerplate in functions that just propagate contexts
- reading most code doesn't require understanding context at all, and
  using context as values in fewer places still
- fewer options to pass the "wrong" context when it changes within a
  scope (e.g. when using Span)
- contexts pass through interfaces we can't modify, such as VFS
- propagating contexts across threads was slightly tricky (e.g.
  copy vs move, no move-init in lambdas), and is now encapsulated in
  the threadpool

Disadvantages are all the usual TLS stuff - hidden magic, and
potential for higher memory usage on threads that don't use the
context. (In practice, it's just one pointer)

Reviewers: ilya-biryukov

Subscribers: klimek, jkorous-apple, ioeric, cfe-commits

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

llvm-svn: 323872
2018-01-31 13:40:48 +00:00
Alexander Kornienko dd48c6b519 Update header guard.
llvm-svn: 323871
2018-01-31 13:31:51 +00:00
Haojian Wu b018906051 [clangd] Better handling symbols defined in macros.
Summary:
For symbols defined inside macros:
 * use expansion location, if the symbol is formed via macro concatenation.
 * use spelling location, otherwise.

This will fix some symbols that have ill-format location (especial invalid filepath).

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits

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

llvm-svn: 323867
2018-01-31 12:56:51 +00:00
Haojian Wu fb68ca1825 [clang-move] Clever on handling header file which includes itself.
Summary:
Previously, we assume only old.cc includes "old.h", which would
introduce incorrect fixes for the cases where old.h also includes `#include "old.h"`

Although it should not be occurred in real projects, clang-move should handle this.

Old.h:

```
class Foo {};
```

after moving to a new old.h:

```
class Foo {};
```

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: cfe-commits, klimek

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

llvm-svn: 323865
2018-01-31 12:12:29 +00:00
Ilya Biryukov 2525870c4e [clangd] Second attempt to fix MSVC compilation breakage.
llvm-svn: 323863
2018-01-31 11:26:43 +00:00
Ilya Biryukov f9fe311ee7 [clangd] Attempt to fix compilation breakage with MSVC.
llvm-svn: 323859
2018-01-31 09:50:21 +00:00
Ilya Biryukov 75f1dd9b98 [clangd] Refactored threading in ClangdServer
Summary:
We now provide an abstraction of Scheduler that abstracts threading
and resource management in ClangdServer.
No changes to behavior are intended with an exception of changed error
messages.
This patch is preliminary work to allow a revamped threading
implementation that will move the threading code out of CppFile.

Reviewers: sammccall, bkramer, jkorous-apple

Reviewed By: sammccall

Subscribers: hokein, mgorny, hintonda, ioeric, jkorous-apple, cfe-commits, klimek

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

llvm-svn: 323851
2018-01-31 08:51:16 +00:00
Sam McCall 2b780160cd [clangd] Trace code completion.
Context passing is a little messy, but will go away with TLS soon.

llvm-svn: 323792
2018-01-30 17:20:54 +00:00
Alexander Kornienko 4256fd0b4b clang-tidy/rename_check.py misc-incorrect-roundings bugprone-incorrect-roundings
More specifically,
clang-tidy/rename_check.py misc-incorrect-roundings \
  bugprone-incorrect-roundings --check_class_name IncorrectRoundings

llvm-svn: 323768
2018-01-30 15:12:24 +00:00
Alexander Kornienko 5c9c0427bb clang-tidy/rename_check.py misc-string-compare readability-string-compare
llvm-svn: 323766
2018-01-30 14:55:50 +00:00
Alexander Kornienko 4170f04576 [clang-tidy] Use a more specific regex
llvm-svn: 323765
2018-01-30 14:55:39 +00:00
Sam McCall 41d2152e87 [clangd] Fix windows path manipulation
llvm-svn: 323751
2018-01-30 11:23:11 +00:00
Sam McCall ea283c7bb8 [clangd] Enable completion index by default, limit results to 100.
Summary:
This should speed up global code completion by avoiding deserializing
preamble declarations to look up names. The tradeoff is memory usage.
Currently the index is fairly naive and may not be much faster, but there's lots
of performance headroom.

These two changes go together because results from the index get copied a couple
of times, so we should avoid it for huge sets.

Also the flag should be -completion-limit, rather than -limit-completion.

Reviewers: hokein, ioeric, ilya-biryukov

Subscribers: klimek, jkorous-apple, cfe-commits

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

llvm-svn: 323734
2018-01-30 09:21:30 +00:00
Yan Zhang 75b3b541d5 add prefix with '_' support for property name. Corresponding apple dev doc: https://developer.apple.com/library/content/qa/qa1908/_index.html
Reviewers: benhamilton, hokein

Reviewed By: benhamilton

Subscribers: klimek, cfe-commits

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

llvm-svn: 323722
2018-01-30 01:44:00 +00:00
Eric Liu b57da098e9 [clangd] Fix r323658 test failure on windows.
llvm-svn: 323703
2018-01-29 22:28:08 +00:00
Eric Liu 78ed91a76c [clangd] Use new URI with scheme support in place of the existing LSP URI
Summary:
o Replace the existing clangd::URI with a wrapper of FileURI which also
carries a resolved file path.
o s/FileURI/URI/
o Get rid of the URI hack in vscode extension.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits

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

llvm-svn: 323660
2018-01-29 15:37:46 +00:00
Eric Liu 278e2d1a26 [clangd] Add a fallback directory for collected symbols with relative paths.
Reviewers: hokein, sammccall

Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits

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

llvm-svn: 323658
2018-01-29 15:13:29 +00:00
Ilya Biryukov cec6335f35 [clangd] Fixed null deference on invalid compile commands.
Code building the AST expected that construction of CompilerInstance
always succeeds. This is not the case.

llvm-svn: 323652
2018-01-29 14:30:28 +00:00
Sam McCall 24f0fa34c2 [clangd] Fix GCC build break 'declaration changes meaning'
llvm-svn: 323518
2018-01-26 11:23:33 +00:00
Sam McCall 1b475a1ad0 [clangd] Modify the Span API so that Spans propagate with contexts.
Summary:
This is probably the right behavior for distributed tracers, and makes unpaired
begin-end events impossible without requiring Spans to be bound to a thread.

The API is conceptually clean but syntactically awkward. As discussed offline,
this is basically a naming problem and will go away if (when) we use TLS to
store the current context.

The apparently-unrelated change to onScopeExit are because its move semantics
broken if Func is POD-like since r322838. This is true of function pointers,
and the lambda I use here that captures two pointers only.
I've raised this issue on llvm-dev and will revert this part if we fix it in
some other way.

Reviewers: ilya-biryukov

Subscribers: klimek, jkorous-apple, ioeric, cfe-commits

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

llvm-svn: 323511
2018-01-26 09:00:30 +00:00
Sam McCall 034e11aca5 [clangd] Add ClangdUnit diagnostics tests using annotated code.
Summary:
This adds checks that our diagnostics emit correct ranges in a bunch of cases,
as promised in D41118.

The diagnostics-preamble test is also converted and extended to be a little more
precise.

diagnostics.test stays around as the smoke test for this feature.

Reviewers: ilya-biryukov

Subscribers: klimek, mgorny, cfe-commits

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

llvm-svn: 323448
2018-01-25 17:29:17 +00:00
Sam McCall b5f5eb6c94 [clangd] Replace homegrown make_scope_exit with one from ADT
llvm-svn: 323443
2018-01-25 17:01:39 +00:00
Alexander Kornienko ffbc2380f6 Removed Unicode BOM.
llvm-svn: 323431
2018-01-25 15:09:33 +00:00
Ilya Biryukov df84234364 [clangd] Provide a helper to report estimated memory usage per-file
Reviewers: sammccall, ioeric, hokein

Reviewed By: ioeric

Subscribers: klimek, cfe-commits, jkorous-apple

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

llvm-svn: 323425
2018-01-25 14:32:21 +00:00
Ilya Biryukov 3ef08a9b40 [clangd] Fixed the file comment of new file. NFC
llvm-svn: 323424
2018-01-25 14:30:46 +00:00
Ilya Biryukov 0d05e2d064 [clangd] Added forgotten files
llvm-svn: 323423
2018-01-25 14:29:29 +00:00
Ilya Biryukov 929697bd55 [clangd] Moved caching of compile commands to ClangdServer
Summary:
It allows to get rid of CppFile::getLastCommand and simplify the
code in the upcoming threading patch.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: klimek, jkorous-apple, ioeric, cfe-commits

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

llvm-svn: 323420
2018-01-25 14:19:21 +00:00
Haojian Wu 58d208d6e4 [clangd] Disable typo correction when doing code completion.
Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: klimek, jkorous-apple, cfe-commits, ioeric

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

llvm-svn: 323410
2018-01-25 09:44:06 +00:00
Haojian Wu 48b4865683 [clangd] Limit completion results.
Summary:
* truncate symbols from static/dynamic index to the limited number
(which would save lots of cost in constructing the merged symbols).
* add an CLI option allowing to limit the number of returned completion results.
(default to 100)

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, cfe-commits

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

llvm-svn: 323408
2018-01-25 09:20:09 +00:00
Sam McCall d5ea3e32a6 [clangd] add test for r323347 CodeComplete behavior we rely on
llvm-svn: 323350
2018-01-24 17:53:32 +00:00
Malcolm Parsons 6e4d53bc2b [clang-tidy] Handle bitfields in cppcoreguidelines-pro-type-member-init if using C++2a
Summary:
C++2a allows bitfields to have default member initializers.
Add support for this to clang-tidy's cppcoreguidelines-pro-type-member-init check.

Reviewers: aaron.ballman, alexfh

Reviewed By: aaron.ballman

Subscribers: klimek, nemanjai, xazax.hun, kbarton, cfe-commits

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

llvm-svn: 323227
2018-01-23 17:13:57 +00:00
Malcolm Parsons e034e5eefe [clang-tidy] Handle bitfields in modernize-use-default-member-init if using C++2a
Summary:
C++2a allows bitfields to have default member initializers.
Add support for this to clang-tidy's modernize-use-default-member-init check.

Reviewers: aaron.ballman, alexfh

Reviewed By: aaron.ballman

Subscribers: klimek, xazax.hun, cfe-commits

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

llvm-svn: 323208
2018-01-23 15:32:42 +00:00
Ilya Biryukov 82b59ae428 [clangd] Simplify code handling compile commands
Summary:
CppFile can now change compilation arguments during rebuild. This allows
simplifying code that manages CppFiles.

Reviewers: sammccall, bkramer, jkorous-apple

Reviewed By: sammccall

Subscribers: ioeric, jkorous-apple, klimek, cfe-commits

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

llvm-svn: 323204
2018-01-23 15:07:52 +00:00
Ilya Biryukov a67b3663de [clang-tidy] Add -vfsoverlay flag
Summary:
It allows to remap and override files and directories on disk when
running clang-tidy. The intended use case for the flag is running
standalone clang-tidy binary for IDE and editor integration.

Patch by Vladimir Plyashkun.

Reviewers: alexfh, benlangmuir, ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: ilya-biryukov, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 323196
2018-01-23 12:31:06 +00:00
Haojian Wu c159aa6aeb [clang-tidy] Don't generate fixes for invalid new expr location in modernize-make-unique.
Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: klimek, xazax.hun, cfe-commits

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

llvm-svn: 323191
2018-01-23 11:43:18 +00:00
Haojian Wu 061c73eb28 [clangd] Use accessible scopes to query indexes for global code completion.
Summary:
 * For qualified completion (foo::a^)
       * unresolved qualifier - use global namespace ("::")
       * resolved qualifier - use all accessible namespaces inside the resolved qualifier.
 * For unqualified completion (vec^), use scopes that are accessible from the
      scope from which code completion occurs.

Reviewers: sammccall, ilya-biryukov

Reviewed By: sammccall

Subscribers: jkorous-apple, ioeric, klimek, cfe-commits

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

llvm-svn: 323189
2018-01-23 11:37:26 +00:00
Sam McCall d2a9592526 [clangd] Drop ~destructor completions - rarely helpful and work inconsistently
llvm-svn: 323149
2018-01-22 21:05:00 +00:00
Ben Hamilton f94c10d91a [clang-tidy objc-property-declaration] New option IncludeDefaultAcronyms
Summary:
The existing option objc-property-declaration.Acronyms
replaces the built-in set of acronyms.

While this behavior is OK for clients that don't want the default
behavior, many clients may just want to add their own custom acronyms
to the default list.

This revision introduces a new option,
objc-property-declaration.IncludeDefaultAcronyms, which controls
whether the acronyms in objc-property-declaration.Acronyms are
appended to the default list (the default behavior) or whether they
replace.

I also updated the documentation.

Test Plan: make -j12 check-clang-tools

Reviewers: Wizard, hokein, klimek

Reviewed By: hokein

Subscribers: Eugene.Zelenko, cfe-commits

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

llvm-svn: 323130
2018-01-22 15:45:25 +00:00
Simon Pilgrim 62dbdf1790 Fix MSVC implicit double-float truncation warning. NFCI.
llvm-svn: 323112
2018-01-22 13:15:16 +00:00
Eric Liu 43cee17cbf [clangd] Try to fix build bot failue in r323101
llvm-svn: 323111
2018-01-22 13:03:25 +00:00
Eric Liu f5b8c82198 [clangd] Add support for different file URI schemas.
Summary: I will replace the existing URI struct in Protocol.h with the new URI and rename FileURI to URI in a followup patch.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: jkorous-apple, klimek, mgorny, ilya-biryukov, cfe-commits

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

llvm-svn: 323101
2018-01-22 11:48:20 +00:00
Dimitry Andric 1dbf609634 Assume the shared library path variable is LD_LIBRARY_PATH on systems
except Darwin and Windows.  This prevents inserting an environment
variable with an empty name (which is illegal and leads to a Python
exception) on any of the BSDs.

llvm-svn: 323040
2018-01-20 14:34:33 +00:00
Julie Hockett 587deb4557 [clang-tidy] Adding Fuchsia checker for multiple inheritance
Adds a check to the Fuchsia module to warn when a class
inherits from multiple classes that are not pure virtual.

See https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md
for reference.

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

llvm-svn: 323011
2018-01-19 23:59:59 +00:00
Sam McCall 8b2faeed02 [clangd] Change index scope convention from "outer::inner" to "outer::inner::"
Global scope is "" (was "")
Top-level namespace scope is "ns::" (was "ns")
Nested namespace scope is "ns::ns::" (was "ns::ns")

This composes more naturally:
- qname = scope + name
- full scope = resolved scope + unresolved scope (D42073 was the trigger)
It removes a wart from the old way: "foo::" has one more separator than "".

Another alternative that has these properties is "::ns", but that lacks
the property that both the scope and the name are substrings of the
qname as produced by clang.

This is re-landing r322996 which didn't build.

llvm-svn: 323000
2018-01-19 22:18:21 +00:00
Sam McCall 50584ea197 Revert "[clangd] Change index scope convention from "outer::inner" to "outer::inner::""
This reverts commit r322996.

llvm-svn: 322998
2018-01-19 22:09:34 +00:00
Sam McCall 1a8c55ecc6 [clangd] Change index scope convention from "outer::inner" to "outer::inner::"
Global scope is "" (was "")
Top-level namespace scope is "ns::" (was "ns")
Nested namespace scope is "ns::ns::" (was "ns::ns")

This composes more naturally:
 - qname = scope + name
 - full scope = resolved scope + unresolved scope (D42073 was the trigger)
It removes a wart from the old way: "foo::" has one more separator than "".

Another alternative that has these properties is "::ns", but that lacks
the property that both the scope and the name are substrings of the
qname as produced by clang.

llvm-svn: 322996
2018-01-19 21:58:58 +00:00
Sam McCall eb74ab8633 [clangd] Fix memcpy(?, null, 0) UB by switching to std::copy
llvm-svn: 322949
2018-01-19 15:03:49 +00:00
Sam McCall 545a20d90b [clangd] Merge index-provided completions with those from Sema.
Summary:
 - we match on USR, and do a field-by-field merge if both have results
 - scoring is post-merge, with both sets of information available
   (for now, sema priority is used if available, static score for index results)
 - limit is applied to the complete result set (previously index ignored limit)
 - CompletionItem is only produces for the returned results
 - If the user doesn't type a scope, we send the global scope for completion
   (we can improve this after D42073)

Reviewers: ioeric

Subscribers: klimek, ilya-biryukov, mgrang, cfe-commits

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

llvm-svn: 322945
2018-01-19 14:34:02 +00:00
Haojian Wu 9873fdd4f5 [clangd] Collect enum constants in SymbolCollector
Summary:
* ignore nameless symbols
* include enum constant declarataion

Reviewers: ilya-biryukov, jkorous-apple

Reviewed By: ilya-biryukov

Subscribers: ioeric, cfe-commits, klimek

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

llvm-svn: 322929
2018-01-19 09:35:55 +00:00
Ben Hamilton 55c3a321a8 [clang-tidy objc-property-declaration] Expand list of ObjC acronyms
Summary:
We were missing some pretty common acronyms in the camelCase
property name check objc-property-declaration.

This expands the list and sorts it lexicographically, so we can
avoid duplicates.

Test Plan: make -j12 check-clang-tools

Reviewers: Wizard, hokein, klimek

Reviewed By: Wizard

Subscribers: cfe-commits

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

llvm-svn: 322886
2018-01-18 20:51:24 +00:00
Sam McCall d8169a85cc [clangd] Remove unused IncludeGlobals completion option, always pass true to sema
llvm-svn: 322856
2018-01-18 15:31:30 +00:00
Ilya Biryukov 295c8e1e2d [clangd] Always use preamble (even stale) for code completion
Summary:
This improves performance of code completion, because we avoid stating
the files from the preamble and never attempt to parse the files
without using the preamble if it's provided.

However, the change comes at a cost of sometimes providing incorrect
results when doing code completion after making actually considerable
changes to the files used in the preamble or the preamble itself.
Eventually the preamble will get rebuilt and code completion will
be providing the correct results.

Reviewers: bkramer, sammccall, jkorous-apple

Reviewed By: sammccall

Subscribers: klimek, cfe-commits

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

llvm-svn: 322854
2018-01-18 15:17:00 +00:00
Sam McCall 2082fe156d [clangd] Output log messages to stderr when not configured (e.g. in tests). NFC
llvm-svn: 322827
2018-01-18 10:24:01 +00:00
Sam McCall a15c2d683e [clangd] CodeCompleteTests cleanup: naming, ordering, helpers. NFC
llvm-svn: 322824
2018-01-18 09:27:56 +00:00
Haojian Wu 0e9a8a5f6f [clang-tidy] Don't generate fix for argument constructed from std::initializer_list.
Summary:
A follow-up fix of rL311652.

The previous `vector` in our test is different with `std::vector`, so
The check still generates fixes for std::vector (`auto p =
std::unique_ptr<Foo>(new Foo({1,2,3}))`) in real world, the patch makes the
vector behavior in test align with std::vector (both AST nodes are the same now).

Reviewers: ilya-biryukov, alexfh

Reviewed By: ilya-biryukov

Subscribers: klimek, xazax.hun, cfe-commits

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

llvm-svn: 322822
2018-01-18 08:58:18 +00:00
Sam McCall a5ce243fa3 [clangd] Use fuzzy match to select top N index results.
Summary:
This makes performance slower but more predictable (it always processes
every symbol). We need to find ways to make this fast, possibly by precomputing
short queries or capping the number of scored results. But our current approach
is too naive.

It also no longer returns results in a "good" order. In fact it's pathological:
the top N results are ranked from worst to best. Indexes aren't responsible for
ranking and MergedIndex can't do a good job, so I'm pleased that this will make
any hidden assumptions we have more noticeable :-)

Reviewers: hokein

Subscribers: klimek, ilya-biryukov, cfe-commits

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

llvm-svn: 322821
2018-01-18 08:35:04 +00:00
Julie Hockett 93a88e33ef [clang-tidy] Adding Fuchsia checker for trailing returns
Adds a check to the Fuchsia module to warn if a function has a trailing
return.

See https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md for
reference.

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

llvm-svn: 322759
2018-01-17 21:18:15 +00:00
Eric Liu 31300c7d8b [clangd] Deduplicate symbols collected in global-symbol-builder tool.
Summary: After D42111, the executor framework no longer deduplicate tool results.

Reviewers: bkramer, sammccall

Subscribers: klimek, ilya-biryukov, cfe-commits

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

llvm-svn: 322722
2018-01-17 18:27:41 +00:00
Julie Hockett 996a8c1a66 [clang-tidy] Fixing Fuchsia overloaded operator warning message
Updating Fuchsia overloaded operator warning message for clarity.

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

llvm-svn: 322692
2018-01-17 17:41:50 +00:00
Sam McCall 5668cd3e57 [clangd] Avoid divide-by-zero
llvm-svn: 322668
2018-01-17 15:25:55 +00:00
Ilya Biryukov 261c72e8f9 [clangd] Don't crash on LSP calls for non-added files
Summary:
We will return errors for non-added files for now.
Another alternative for clangd would be to read non-added files from
disk and provide useful features anyway.

There are still some cases that fail with assertion (e.g., code
complete). We should address those too, but they require more subtle
changes to the code and therefore out of scope of this patch.

Reviewers: sammccall, ioeric, hokein

Reviewed By: sammccall

Subscribers: klimek, cfe-commits

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

llvm-svn: 322637
2018-01-17 12:30:24 +00:00
Jonas Toth f22f3489d7 [clang-tidy] implement check for goto
The usage of `goto` is discourage in C++ since forever. This check implements
a warning for every `goto`. Even though there are (rare) valid use cases for
`goto`, better high level constructs should be used.

`goto` is used sometimes in C programs to free resources at the end of 
functions in the case of errors. This pattern is better implemented with
RAII in C++.

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: aaron.ballman

Subscribers: lebedev.ri, jbcoe, Eugene.Zelenko, klimek, nemanjai, mgorny, xazax.hun, kbarton, cfe-commits

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

llvm-svn: 322626
2018-01-17 10:27:41 +00:00
Jonas Toth fe7ef82cc5 [clang-tidy] fix minor formatting issue
llvm-svn: 322624
2018-01-17 10:23:50 +00:00
Yan Zhang 8c298d2ff2 add ID as a special acronym to objc property declaration check for property names like bundleID.allow using acronyms as suffix.
Reviewers: benhamilton, hokein

Reviewed By: benhamilton

Subscribers: klimek, cfe-commits

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

llvm-svn: 322602
2018-01-17 00:19:35 +00:00