Commit Graph

3913 Commits

Author SHA1 Message Date
Mikael Holmen fa41add2e5 Fix warning about unused variable [NFC]
llvm-svn: 344724
2018-10-18 06:00:39 +00:00
Julie Hockett bf445b87de [clang-doc] Bringing bitcode tests in line
Makes bitcode tests line up with what's actually called in the tool.
Should fix the failing bot.

Also fixes a warning that was being thrown about initialization braces.

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

llvm-svn: 344707
2018-10-17 20:16:05 +00:00
Eric Liu 3fac4ef1fd [clangd] Support scope proximity in code completion.
Summary:
This should make all-scope completion more usable. Scope proximity for
indexes will be added in followup patch.

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 344688
2018-10-17 11:19:02 +00:00
Haojian Wu c014d863be [clangd] Fix buildbot failure.
llvm-svn: 344680
2018-10-17 08:54:48 +00:00
Haojian Wu 0404855529 [clangd] Print numbers of symbols and refs as well when loading the
index.

llvm-svn: 344679
2018-10-17 08:48:04 +00:00
Haojian Wu 7dd4950ea5 [clangd] Collect refs from headers.
Summary:
Add a flag to SymbolCollector to collect refs fdrom headers.

Note that we collect refs from headers in static index, and we don't do it for
dynamic index because of the preamble (we skip function body in preamble,
collecting it will result incomplete results).

Reviewers: sammccall

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

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

llvm-svn: 344678
2018-10-17 08:38:36 +00:00
Sam McCall 4340cc7336 [clangd] Hide unused function. NFC
llvm-svn: 344676
2018-10-17 07:41:53 +00:00
Sam McCall 645203a8c5 [clangd] Rename and move trivial logger to Logger.cpp. NFC
llvm-svn: 344675
2018-10-17 07:39:32 +00:00
Sam McCall bf6a2fc329 [clangd] Simplify client capabilities parsing.
Summary:
Instead of parsing into structs that mirror LSP, simply parse into a flat struct
that contains the info we need.
This is an exception to our strategy with Protocol.h, which seems justified:
 - the structure here is very large and deeply nested
 - we care about almost none of it
 - we should never have to serialize client capabilities

Reviewers: kadircet

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

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

llvm-svn: 344673
2018-10-17 07:33:42 +00:00
Sam McCall dc8f3cf8b0 [clangd] Refactor JSON-over-stdin/stdout code into Transport abstraction. (re-land r344620)
Summary:
This paves the way for alternative transports (mac XPC, maybe messagepack?),
and also generally improves layering: testing ClangdLSPServer becomes less of
a pipe dream, we split up the JSONOutput monolith, etc.

This isn't a final state, much of what remains in JSONRPCDispatcher can go away,
handlers can call reply() on the transport directly, JSONOutput can be renamed
to StreamLogger and removed, etc. But this patch is sprawling already.

The main observable change (see tests) is that hitting EOF on input is now an
error: the client should send the 'exit' notification.
This is defensible: the protocol doesn't spell this case out. Reproducing the
current behavior for all combinations of shutdown/exit/EOF clutters interfaces.
We can iterate on this if desired.

Reviewers: jkorous, ioeric, hokein

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

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

llvm-svn: 344672
2018-10-17 07:32:05 +00:00
Julie Hockett 229c63b021 [clang-doc] Limit integration tests
Now that the clang-doc libraries are covered by unit tests, we don't
need to have extensive (and unmaintainable) integration tests. This
replaces the integration test suite with a smaller one that just tests
the tool itself and removes extraneous dumping logic from the tool
itself.

Includes tests that cover the parse->serialize->merge->generate
pipeline, as well as tests for the --public, --format, --doxygen, and
--output flags.

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

llvm-svn: 344655
2018-10-16 23:07:37 +00:00
Julie Hockett 7f87ca62a2 [clang-doc] Add unit tests for Markdown generation
Add unit tests for Markdown generation.

This is part of a move to convert clang-doc's tests to a more
maintainable unit test framework, with a smaller number of integration
tests to maintain and more granular failure feedback.

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

llvm-svn: 344654
2018-10-16 23:07:26 +00:00
Julie Hockett 55974d3b93 [clang-doc] Add unit tests for YAML generation
Adds unit tests for the YAML generator library.

This is part of a move to convert clang-doc's tests to a more
maintainable unit test framework, with a smaller number of integration
tests to maintain and more granular failure feedback.

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

llvm-svn: 344653
2018-10-16 23:07:16 +00:00
Julie Hockett 8fc72fcb31 [clang-doc] Add unit tests for merging
Adds unit tests for the merging logic in Respresentation.cpp.

This is part of a move to convert clang-doc's tests to a more
maintainable unit test framework, with a smaller number of integration
tests to maintain and more granular failure feedback.

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

llvm-svn: 344652
2018-10-16 23:07:04 +00:00
Julie Hockett f276624e87 [clang-doc] Add unit tests for bitcode
Adds unit tests for the BitcodeWriter and BitcodeReader libraries.

This is part of a move to convert clang-doc's tests to a more
maintainable unit test framework, with a smaller number of integration
tests to maintain and more granular failure feedback.

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

llvm-svn: 344651
2018-10-16 23:06:53 +00:00
Julie Hockett 68049b1a8e [clang-doc] Add unit tests for serialization
Adds unit tests for the Serialize library.

This is part of a move to convert clang-doc's tests to a more
maintainable unit test framework, with a smaller number of integration
tests to maintain and more granular failure feedback.

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

llvm-svn: 344650
2018-10-16 23:06:42 +00:00
Krasimir Georgiev ae4e75fd6e Revert "[clangd] Refactor JSON-over-stdin/stdout code into Transport abstraction."
This reverts commit r344620.
Breaks upstream bots.

llvm-svn: 344637
2018-10-16 18:44:41 +00:00
Sam McCall 818ec5e965 [clangd] Refactor JSON-over-stdin/stdout code into Transport abstraction.
Summary:
This paves the way for alternative transports (mac XPC, maybe messagepack?),
and also generally improves layering: testing ClangdLSPServer becomes less of
a pipe dream, we split up the JSONOutput monolith, etc.

This isn't a final state, much of what remains in JSONRPCDispatcher can go away,
handlers can call reply() on the transport directly, JSONOutput can be renamed
to StreamLogger and removed, etc. But this patch is sprawling already.

The main observable change (see tests) is that hitting EOF on input is now an
error: the client should send the 'exit' notification.
This is defensible: the protocol doesn't spell this case out. Reproducing the
current behavior for all combinations of shutdown/exit/EOF clutters interfaces.
We can iterate on this if desired.

Reviewers: jkorous, ioeric, hokein

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

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

llvm-svn: 344620
2018-10-16 16:48:06 +00:00
Sam McCall 20841d41e7 [clangd] Send CodeAction responses to textDocument/codeAction (LSP 3.8)
Summary:
I don't bother mirroring the full capabilities struct, just parse the
bits we care about. I'll send a new patch to use this approach elsewhere too.

Reviewers: kadircet

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

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

llvm-svn: 344617
2018-10-16 16:29:41 +00:00
Simon Marchi abeed66056 Remove possibility to change compile database path at runtime
Summary:
This patch removes the possibility to change the compilation database
path at runtime using the didChangeConfiguration request.  Instead, it
is suggested to use the setting on the initialize request, and clangd
whenever the user wants to use a different build configuration.

Subscribers: ilya-biryukov, ioeric, jkorous, arphaman, kadircet, cfe-commits

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

llvm-svn: 344614
2018-10-16 15:55:03 +00:00
Eric Liu 0c29722c60 [clangd] Allow disble down traversals from root.
Summary:
This is useful for symbo scope proximity, where down traversals from
the global scope if not desired.

Reviewers: sammccall

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

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

llvm-svn: 344604
2018-10-16 10:41:17 +00:00
Sam McCall bca624ab03 [clangd] Fix threading bugs in (not-yet-used) BackgroundIndex, re-enable test.
Summary:
One relatively boring bug: forgot to notify the CV after enqueue.

One much more fun bug: the thread member could access instance variables before
they were initialized. Although the thread was last in the init list, QueueCV
etc were listed after Thread in the class, so their default constructors raced
with the thread itself.
We have to get very unlucky to lose this race, I saw it 0.02% of the time.

Reviewers: ioeric

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

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

llvm-svn: 344595
2018-10-16 09:05:13 +00:00
Sam McCall 96f2489557 [clangd] Optionally use dex for the preamble parts of the dynamic index.
Summary:
Reuse the old -use-dex-index experiment flag for this.

To avoid breaking the tests, make Dex deduplicate symbols, addressing an old FIXME.

Reviewers: hokein

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

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

llvm-svn: 344594
2018-10-16 08:53:52 +00:00
Sam McCall f12a43d38a [clangd] Disable timeouting test while investigating
llvm-svn: 344586
2018-10-16 06:32:14 +00:00
Leonard Chan 0f11b73f96 [Fixed Point Arithmetic] Fix for clang-tools-extra warning
Fix for warnings generated on unhandled enum value `STK_FixedPoint`.

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

llvm-svn: 344549
2018-10-15 20:00:03 +00:00
Leonard Chan 88ccbd7543 added fix
llvm-svn: 344548
2018-10-15 19:59:52 +00:00
Sam McCall bc8aee15a2 [clangd] Revert include path change in Dexp. NFC
llvm-svn: 344533
2018-10-15 16:47:45 +00:00
Haojian Wu 397704ca40 [clangd] Add createIndex in dexp
Summary:
This would allow easily injecting our internal customization.

Also updates the stale "symbol-collection-file" flag.

Reviewers: sammccall

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

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

llvm-svn: 344521
2018-10-15 15:12:40 +00:00
Sam McCall 2b24ce61a0 [clangd] Use SyncAPI in more places in tests. NFC
llvm-svn: 344520
2018-10-15 15:04:03 +00:00
Sam McCall 8dc9dbb61a [clangd] Minimal implementation of automatic static index (not enabled).
Summary:
See tinyurl.com/clangd-automatic-index for design and goals.

Lots of limitations to keep this patch smallish, TODOs everywhere:
 - no serialization to disk
 - no changes to dynamic index, which now has a much simpler job
 - no partitioning of symbols by file to avoid duplication of header symbols
 - no reindexing of edited files
 - only a single worker thread
 - compilation database is slurped synchronously (doesn't scale)
 - uses memindex, rebuilds after every file (should be dex, periodically)

It's not hooked up to ClangdServer/ClangdLSPServer yet: the layering
isn't clear (it should really be in ClangdServer, but ClangdLSPServer
has all the CDB interactions).

Reviewers: ioeric

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

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

llvm-svn: 344513
2018-10-15 13:34:10 +00:00
Haojian Wu 82ba7121e8 [clangd] Remove an unused include header, NFC.
llvm-svn: 344510
2018-10-15 12:39:45 +00:00
Haojian Wu ddec850ceb [clangd] dump xrefs information in dexp tool.
Reviewers: sammccall

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

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

llvm-svn: 344508
2018-10-15 12:32:49 +00:00
Haojian Wu e83caccb58 [clangd] Fix some references missing in dynamic index.
Summary:
Previously, SymbolCollector postfilters all references at the end to
find all references of interesting symbols.
It was incorrect when indxing main AST where we don't see locations
of symbol declarations and definitions in the main AST (as those are in
preamble AST).

The fix is to do earily check during collecting references.

Reviewers: sammccall

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

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

llvm-svn: 344507
2018-10-15 11:46:26 +00:00
Benjamin Kramer c55e997556 Move some helpers from the global namespace into anonymous ones.
llvm-svn: 344468
2018-10-13 22:18:22 +00:00
Adam Balogh af1f374ece [clang-tidy] Fix for typos in the tests for `bugprone-exception-escape`
llvm-svn: 344445
2018-10-13 11:17:59 +00:00
Adam Balogh d053f5c616 [clang-tidy] Optimize query in bugprone-exception-escape
Checking whether a functions throws indirectly may be very expensive because it
needs to visit its whole call graph. Therefore we should first check whether the
function is forbidden to throw and only check whether it throws afterward. This
also seems to solve bug https://bugs.llvm.org/show_bug.cgi?id=39167 where the
execution time is so long that it seems to hang.

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

llvm-svn: 344444
2018-10-13 10:34:52 +00:00
Jonas Toth cd3e370504 Revert "[clang-tidy] New checker for not null-terminated result caused by strlen(), size() or equal length"
This reverts commit r344374.

llvm-svn: 344442
2018-10-13 09:30:58 +00:00
Jonas Toth bbbebeb928 Revert "[doc] fix markup in clang-tidy bugprone-not-null-terminated-result"
This reverts commit r344379.

llvm-svn: 344441
2018-10-13 09:30:46 +00:00
Miklos Vajna abfccc2cf6 [clang-tidy] add IgnoreMacros option to modernize-use-equals-delete
And also enable it by default to be consistent with e.g. modernize-use-using.
This improves consistency inside the check itself as well: both checks are now
disabled in macros by default.

This helps e.g. when running this check on client code where the macro is
provided by the system, so there is no easy way to modify it.

Reviewed By: alexfh

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

llvm-svn: 344440
2018-10-13 07:58:05 +00:00
Jonas Toth f79f8eecce [clangd] NFC fix semicolon warning
llvm-svn: 344384
2018-10-12 17:47:43 +00:00
Jonas Toth 6042235450 [doc] fix markup in clang-tidy bugprone-not-null-terminated-result
llvm-svn: 344379
2018-10-12 17:36:04 +00:00
Jonas Toth 78886233b3 [clang-tidy] New checker for not null-terminated result caused by strlen(), size() or equal length
New checker called bugprone-not-null-terminated-result. This check finds function calls where it is possible to cause a not null-terminated result. Usually the proper length of a string is strlen(src) + 1 or equal length of this expression, because the null terminator needs an extra space. Without the null terminator it can result in undefined behaviour when the string is read.

The following function calls are checked:
memcpy, wmemcpy, memcpy_s, wmemcpy_s, memchr, wmemchr, memmove, wmemmove, memmove_s, wmemmove_s, memset, wmemset, strerror_s, strncmp, wcsncmp, strxfrm, wcsxfrm

The following is a real-world example where the programmer forgot to increase the passed third argument, which is size_t length. That is why the length of the allocated memory is problematic too.

static char *StringCpy(const std::string &str) {
  char *result = reinterpret_cast<char *>(malloc(str.size()));
  memcpy(result, str.data(), str.size());
  return result;
}

After running the tool fix-it rewrites all the necessary code according to the given options. If it is necessary, the buffer size will be increased to hold the null terminator.

static char *StringCpy(const std::string &str) {
  char *result = reinterpret_cast<char *>(malloc(str.size() + 1));
  strcpy(result, str.data());
  return result;
}

Patch by Charusso.

Differential ID: https://reviews.llvm.org/D45050

llvm-svn: 344374
2018-10-12 17:22:36 +00:00
Sam McCall cbf497f452 [clangd] Return Command objects from onCodeAction, rather than ad-hoc JSON. NFC
llvm-svn: 344363
2018-10-12 16:51:48 +00:00
Zachary Turner 359544acc7 Fix one additional test broken by the YAML quoting change.
llvm-svn: 344362
2018-10-12 16:41:37 +00:00
Zinovy Nis 608dfb2bc7 [clang-tidy] Fix check_clang_tidy.py trivially passing default CHECK
Differential Revision: https://reviews.llvm.org/D53194

llvm-svn: 344343
2018-10-12 13:35:47 +00:00
Adam Balogh abd72e9851 [clang-tidy] White List Option for performance-unnecessary-value-param, performance-unnecessary-copy-initialization and performance-for-range-copy
New option added to these three checks to be able to silence false positives on
types that are intentionally passed by value or copied. Such types are e.g.
intrusive reference counting pointer types like llvm::IntrusiveRefCntPtr. The
new option is named WhiteListTypes and can contain a semicolon-separated list of
names of these types. Regular expressions are allowed. Default is empty.

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

llvm-svn: 344340
2018-10-12 13:05:21 +00:00
Haojian Wu 903f2a71a4 [clangd] Support hover on "aut^o *".
Reviewers: kadircet

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

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

llvm-svn: 344330
2018-10-12 10:11:02 +00:00
Eugene Zelenko 724a3b728a [Documentation] Rephrase modernize-deprecated-ios-base-aliases description. Add clangd and clang-doc placeholders in Release Notes.
llvm-svn: 344299
2018-10-11 21:40:32 +00:00
Fangrui Song 95b45cb4fd [clang-move] Remove clang:: qualifier
Summary:
The use sites are enclosed by `namespace clang`, so clang:: is not
necessary. Many unqualified names have already been used, e.g. SourceManager SourceLocation LangOptions. This change makes the code terser and more consistent.

Reviewers: hokein

Reviewed By: hokein

Subscribers: ioeric, cfe-commits

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

llvm-svn: 344256
2018-10-11 16:09:26 +00:00
Sam McCall 0f80d9f27d [clangd] Remove no-op crash handler, we never set a crash context.
Summary:
I think this was just copied from somewhere with the belief that it actually
did some crash handling.

Of course the question arises: *should* we set one? I don't think so:
 - clangd used to crash a lot, now it's pretty stable, because we found and
   fixed the crashes. I think the long-term effects of crashing hard are good.
 - the implementation can't do any magic, it just uses longjmp to return without
   running any destructors by default. This is unsafe in general (e.g. mutexes
   won't unlock) and will certainly end up leaking memory. Whatever UB caused
   the crash may still stomp all over global state, etc.

I think there's an argument for isolating the background indexer (autoindex)
because it's not directly under the user's control, the crash surface is larger,
and it doesn't particularly need to interact with the rest of clangd.
But there, fork() and communicate through the FS is safer.

Reviewers: ioeric, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

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

llvm-svn: 344245
2018-10-11 13:06:10 +00:00