Commit Graph

1884 Commits

Author SHA1 Message Date
Sam McCall 6525a6b7b2 [clangd] Use structured PublishDiagnosticsParams. NFC 2020-03-03 12:44:40 +01:00
Sam McCall 6f7dca97fb [clangd] Send InitializeResult.serverInfo 2020-03-03 12:25:58 +01:00
serge-sans-paille 1454c27b60 Syndicate, test and fix base64 implementation
llvm/Support/Base64, fix its implementation and provide a decent test suite.

Previous implementation code was using + operator instead of | to combine

results, which is a problem when shifting signed values. (0xFF << 16) is
implicitly converted to a (signed) int, and thus results in 0xffff0000,
h is
negative. Combining negative numbers with a + in that context is not what we
want to do.

This is a recommit of 5a1958f267 with UB removved.

This fixes https://github.com/llvm/llvm-project/issues/149.

Differential Revision: https://reviews.llvm.org/D75057
2020-03-03 12:17:53 +01:00
Sam McCall 8a2d294ed0 [clangd] Handle `initialized` notification (no-op to suppress log message) 2020-03-03 12:12:30 +01:00
Nathan James b2666ccca0 [clangd] DefineOutline won't copy virtual specifiers on methods
Summary:
The define out of line refactor tool previously would copy the `virtual`, `override` and `final` specifier into the out of line method definition.
This results in malformed code as those specifiers aren't allowed outside the class definition.

Reviewers: hokein, kadircet

Reviewed By: kadircet

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

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D75429
2020-03-03 09:59:14 +00:00
Sam McCall e7de00cf97 [clangd] Split locateSymbolAt into several component functions, to allow later reuse. NFC 2020-03-02 18:45:25 +01:00
Mitch Phillips 49684f9db5 Revert "Syndicate, test and fix base64 implementation"
This reverts commit 5a1958f267.

This change broke the UBSan build bots. See
https://reviews.llvm.org/D75057 for more information.
2020-03-02 09:33:22 -08:00
Haojian Wu 9ad1099224 [clangd] No need to query ctor refs in cross-file rename.
Summary:
This patch reverts 2c5ee78de1,
now kythe (https://github.com/kythe/kythe/issues/4381) supports returning ctors refs as part of class references, so
there is no need to query the ctor refs in the index (this would also
make the results worse, lots of duplications)

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75439
2020-03-02 15:21:32 +01:00
Kadir Cetinkaya 3ae2fc7a8b
[clangd] Get rid of lexer usage in locateMacroAt
Reviewers: sammccall, hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75331
2020-03-02 13:31:12 +01:00
Kadir Cetinkaya c24c89d6f0
[clangd] Get rid of unnecessary source transformations in locateMacroAt
Summary:
All callers are already passing spelling locations to locateMacroAt.
Also there's no point at looking at macro expansion for figuring out undefs as
it is forbidden to have PP directives inside macro bodies.
Also fixes a bug when the previous sourcelocation is unavailable.

Reviewers: sammccall, hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75259
2020-03-02 13:31:12 +01:00
serge-sans-paille 5a1958f267 Syndicate, test and fix base64 implementation
Move Base64 implementation from clangd/SemanticHighlighting to
llvm/Support/Base64, fix its implementation and provide a decent test suite.

Previous implementation code was using + operator instead of | to combine some
results, which is a problem when shifting signed values. (0xFF << 16) is
implicitly converted to a (signed) int, and thus results in 0xffff0000, which is
negative. Combining negative numbers with a + in that context is not what we
want to do.

This fixes https://github.com/llvm/llvm-project/issues/149.

Differential Revision: https://reviews.llvm.org/D75057
2020-03-02 10:02:25 +01:00
Haojian Wu c443b610bf [clangd] Remove the deprecated clangdServer::rename API, NFC.
There is no actual user of it now.
2020-03-02 09:48:25 +01:00
Nathan James 39c4246e1e [clang-tidy] Added virtual isLanguageVersionSupported to ClangTidyCheck
Summary:
Motivated by [[ https://bugs.llvm.org/show_bug.cgi?id=45045 | Tune inspections to a specific C++ standard. ]]
Moves the isLanguageVersionSupported virtual function from `MakeSmartPtrCheck` to the base `ClangTidyCheck` class.
This will disable registering matchers or pp callbacks on unsupported language versions for a check.
Having it as a standalone function is cleaner than manually disabling the check in the register function and should hopefully
encourage check developers to actually restrict the check based on language version.
As an added bonus this could enable automatic detection of what language version a check runs on for the purpose of documentation generation

Reviewers: aaron.ballman, gribozavr2, Eugene.Zelenko, JonasToth, alexfh, hokein

Reviewed By: gribozavr2

Subscribers: xazax.hun, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75289
2020-02-28 13:05:05 +00:00
Kadir Cetinkaya 48fad110e0
[clangd] Get rid of lexer usage in ObjCLocalizeStringLiteral tweak
Reviewers: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75230
2020-02-28 09:38:26 +01:00
Kadir Cetinkaya 98bb094c1e
[clangd] Use tokenize instead of raw lexer in SourceCode/lex
Reviewers: hokein, sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75249
2020-02-28 09:38:26 +01:00
Haojian Wu aa324c5441 [clangd][NFC] Don't query the index if the rename symbol is function
local.

This would save an unnecessary index query when renaming a function
local symbol in cross-file rename mode.
2020-02-27 15:04:51 +01:00
Kadir Cetinkaya f31fc1043d
[clangd] Get rid of lexer usage in AST.cpp
Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75193
2020-02-27 09:54:21 +01:00
Kadir Cetinkaya 2bb7774ddf
[clangd] Get rid of getBeginningOfIdentifier helper
Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75176
2020-02-27 09:34:45 +01:00
Kadir Cetinkaya 2011d14296
[clangd] Clean-up XRefs.cpp from Lexer usages and unnecessary SourceLoc transformations
Summary:
Get rid of calls to lexer and unnecessary source location
transformations.

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75166
2020-02-26 17:51:27 +01:00
Haojian Wu 02323a3d5f [clangd] use printQualifiedName to skip the inlinenamespace qualifiers.
Summary:
symbols in libcpp are inside the inline namespace, printQualifierAsString will
print the inline namespace, which is unexpected.

Reviewers: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75174
2020-02-26 16:22:45 +01:00
Haojian Wu 5560a78820 [clangd] Bump index version number.
Summary:
Though we don't have new changes to the index format, we have changes to
symbol collector, e.g. collect marcos, spelled references. Bump the
version to force background-index to rebuild.

Reviewers: kadircet

Reviewed By: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74127
2020-02-26 13:43:16 +01:00
Haojian Wu 4feca71df0 Fix the clangd-fuzzer build error. 2020-02-26 10:13:13 +01:00
Haojian Wu 34d0e1bd6d [clangd] Expose the rename LimitFiles option to the C++ API, NFC.
Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74834
2020-02-26 09:33:58 +01:00
Haojian Wu e6d0bad843 [clang-rename] Add the USR of incomplete decl to the USRSet.
Summary:
This fixes a clangd rename issue, which is missing the reference of
an incomplete specialization.

Unfortunately, I didn't reproduce this issue in clang-rename, I guess
the input `FoundDecl` of AdditionalUSRFinder is different in clangd vs
clang-rename, clang-rename uses the underlying CXXRecordDecl of the
ClassTemplateDecl, which is fixed in 5d862c042b;
while clangd-rename uses the ClassTemplateDecl.

Reviewers: kbobyrev

Reviewed By: kbobyrev

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74829
2020-02-25 16:56:35 +01:00
Kadir Cetinkaya e09754ccef
[clangd] Migrate Lexer usages in TypeHierarchy to TokenBuffers
Summary:
Also fixes a bug, resulting from directly using ND.getEndLoc() for end
location of the range. As ND.getEndLoc() points to the begining of the last
token, whereas it should point one past the end, since LSP ranges are half open
(exclusive on the end).

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74850
2020-02-25 15:36:45 +01:00
Kadir Cetinkaya 555d5ad85a
[clangd] Disable ExtractVariable for C
Summary:
Currently extract variable doesn't spell the type explicitly and just
uses an `auto` instead, which is not available in C.

Reviewers: usaxena95

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75053
2020-02-25 12:15:15 +01:00
Sam McCall e9997cfb4d [clangd] Try to fix buildbots - copy elision not happening here? 2020-02-23 21:12:26 +01:00
Sam McCall be6d07c920 [clangd] Reapply b60896fad9 Fall back to selecting token-before-cursor if token-after-cursor fails.
This reverts commit b4b9706d5d.
Now avoiding expected<vector<selection>> in favor of expected<vector<unique_ptr<selection>>>
2020-02-23 20:17:30 +01:00
Sam McCall b4b9706d5d Revert "[clangd] Reapply b60896fad9 Fall back to selecting token-before-cursor if token-after-cursor fails."
This reverts commit a2ce807eb7.

Buildbot failures on GCC due to SelectionTree not being copyable, and
instantiating vector<Selection> in the tweak-handling in ClangdServer.
2020-02-23 16:34:49 +01:00
Sam McCall a2ce807eb7 [clangd] Reapply b60896fad9 Fall back to selecting token-before-cursor if token-after-cursor fails.
This reverts commit 6af1ad20d6.
2020-02-23 16:17:46 +01:00
Sam McCall 7d3f8b1e2d [clangd] Debounce rebuilds responsively to rebuild times.
Summary:
Old: 500ms always. New: rebuild time, up to 500ms.

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

Reviewers: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73949
2020-02-23 15:34:28 +01:00
Haojian Wu bc498198b5 [clangd] Allow renaming class templates in cross-file rename.
Summary:
It was disabled because we don't handle explicit template
specialization well (due to the index limitation).

renaming templates is normal in practic, rather than disabling it, this patch
allows to rename them though it is not perfect (just a known limitation).

Context: https://github.com/clangd/clangd/issues/280

Reviewers: kbobyrev

Reviewed By: kbobyrev

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74709
2020-02-21 09:57:10 +01:00
Haojian Wu e326f52430 [clangd] Fix the incomplete template specialization in findTarget.
Summary:
FindTarget doesn't report the TemplatePattern for incomplete
specialization.

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74900
2020-02-21 09:42:02 +01:00
Haojian Wu bb9e92bad5 [clang][Index] Fix the incomplete instantiations in libindex.
Summary:
libindex will canonicalize references to template instantiations:
- 1) reference to an explicit template specialization, report the specializatiion
- 2) otherwise, report the primary template

but 2) is not true for incomplete instantiations, this patch fixes this.

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

Reviewers: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74830
2020-02-20 14:42:30 +01:00
Kirill Bobyrev 4921e79192 Fix build after D74606 2020-02-19 09:19:15 +01:00
Kirill Bobyrev 2a095ff6f5
[clangd] Add add commit characters to the server capabilities
Summary:
Make it more convinient for the clients to select completion items by
providing a set of default characters (punctuation).

Related issue: https://github.com/clangd/clangd/issues/284

Reviewers: sammccall

Reviewed By: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74606
2020-02-19 08:32:00 +01:00
Gokturk Yuksek 351ed50dcb Reland "[clang-tools-extra] fix the check for if '-latomic' is necessary""
The buildbot failures on MSVC should have been fixed by f128f442a3.
2020-02-17 16:53:29 +00:00
Haojian Wu af8b0cd58d [clang][Index] Visit the default parameter arguements in libindex.
Summary:
We are missing the default parmeter arguments when IndexFunctionLocals
is true.

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

Reviewers: kadircet

Subscribers: kristof.beyls, ilya-biryukov, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74610
2020-02-17 16:45:04 +01:00
Alexandre Ganea 8404aeb56a [Support] On Windows, ensure hardware_concurrency() extends to all CPU sockets and all NUMA groups
The goal of this patch is to maximize CPU utilization on multi-socket or high core count systems, so that parallel computations such as LLD/ThinLTO can use all hardware threads in the system. Before this patch, on Windows, a maximum of 64 hardware threads could be used at most, in some cases dispatched only on one CPU socket.

== Background ==
Windows doesn't have a flat cpu_set_t like Linux. Instead, it projects hardware CPUs (or NUMA nodes) to applications through a concept of "processor groups". A "processor" is the smallest unit of execution on a CPU, that is, an hyper-thread if SMT is active; a core otherwise. There's a limit of 32-bit processors on older 32-bit versions of Windows, which later was raised to 64-processors with 64-bit versions of Windows. This limit comes from the affinity mask, which historically is represented by the sizeof(void*). Consequently, the concept of "processor groups" was introduced for dealing with systems with more than 64 hyper-threads.

By default, the Windows OS assigns only one "processor group" to each starting application, in a round-robin manner. If the application wants to use more processors, it needs to programmatically enable it, by assigning threads to other "processor groups". This also means that affinity cannot cross "processor group" boundaries; one can only specify a "preferred" group on start-up, but the application is free to allocate more groups if it wants to.

This creates a peculiar situation, where newer CPUs like the AMD EPYC 7702P (64-cores, 128-hyperthreads) are projected by the OS as two (2) "processor groups". This means that by default, an application can only use half of the cores. This situation could only get worse in the years to come, as dies with more cores will appear on the market.

== The problem ==
The heavyweight_hardware_concurrency() API was introduced so that only *one hardware thread per core* was used. Once that API returns, that original intention is lost, only the number of threads is retained. Consider a situation, on Windows, where the system has 2 CPU sockets, 18 cores each, each core having 2 hyper-threads, for a total of 72 hyper-threads. Both heavyweight_hardware_concurrency() and hardware_concurrency() currently return 36, because on Windows they are simply wrappers over std:🧵:hardware_concurrency() -- which can only return processors from the current "processor group".

== The changes in this patch ==
To solve this situation, we capture (and retain) the initial intention until the point of usage, through a new ThreadPoolStrategy class. The number of threads to use is deferred as late as possible, until the moment where the std::threads are created (ThreadPool in the case of ThinLTO).

When using hardware_concurrency(), setting ThreadCount to 0 now means to use all the possible hardware CPU (SMT) threads. Providing a ThreadCount above to the maximum number of threads will have no effect, the maximum will be used instead.
The heavyweight_hardware_concurrency() is similar to hardware_concurrency(), except that only one thread per hardware *core* will be used.

When LLVM_ENABLE_THREADS is OFF, the threading APIs will always return 1, to ensure any caller loops will be exercised at least once.

Differential Revision: https://reviews.llvm.org/D71775
2020-02-14 10:24:22 -05:00
Luís Marques 13700c383f Revert "[clang-tools-extra] fix the check for if '-latomic' is necessary"
This reverts commit 1d40c41506.
This seemed to have caused build failures on ARM/AArch64.
2020-02-14 15:01:52 +00:00
Haojian Wu 5dc2314d5e [clangd] Update the CompletionItemKind.
Summary: Fix some FIXMEs.

Reviewers: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74609
2020-02-14 15:48:30 +01:00
Haojian Wu 74c97ca1b4 [clangd] Add tracer to the rename workflow, NFC
Reviewers: kbobyrev

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74395
2020-02-14 15:39:29 +01:00
Gokturk Yuksek 1d40c41506 [clang-tools-extra] fix the check for if '-latomic' is necessary
Summary:
The CheckAtomic module performs two tests to determine if passing
'-latomic' to the linker is required: one for 64-bit atomics, and
another for non-64-bit atomics. clangd only uses the result from
HAVE_CXX_ATOMICS64_WITHOUT_LIB. This is incomplete because there are
uses of non-64-bit atomics in the code, such as the ReplyOnce::Replied
of type std::atomic<bool> defined in clangd/ClangdLSPServer.cpp.

Fix by also checking for the result of HAVE_CXX_ATOMICS_WITHOUT_LIB.

See also: https://reviews.llvm.org/D68964

Reviewers: ilya-biryukov, nridge, kadircet, beanz, compnerd, luismarques
Reviewed By: luismarques
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69869
2020-02-14 14:16:10 +00:00
Kadir Cetinkaya 84240e0db8
[clang][Index] Introduce a TemplateParm SymbolKind
Summary:
Currently template parameters has symbolkind `Unknown`. This patch
introduces a new kind `TemplateParm` for templatetemplate, templatetype and
nontypetemplate parameters.

Also adds tests in clangd hover feature.

Reviewers: sammccall

Subscribers: kristof.beyls, ilya-biryukov, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73696
2020-02-14 13:20:34 +01:00
Kadir Cetinkaya c45fb35b5e
[clang][DeclPrinter] Implement visitors for {TemplateType,NonTypeTemplate}Parms
Reviewers: sammccall, hokein

Subscribers: kristof.beyls, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73693
2020-02-14 13:20:34 +01:00
Kirill Bobyrev ff7b5bac04
[clangd] Expose Code Completion score to the client
Summary:
Make it possible for the client to adjust the ranking by using the score Clangd
calculates for the completion items.

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74547
2020-02-13 15:05:18 +01:00
Haojian Wu b1309a18ba [clangd] Print the Spelled RefKind. 2020-02-13 13:28:11 +01:00
Haojian Wu 9f63255a74 Fix the mac buildbot failure. 2020-02-13 12:39:55 +01:00
Haojian Wu 2c5ee78de1 [clangd] Query constructors in the index during rename.
Summary:
Though this is not needed when using clangd's own index, other indexes
(e.g. kythe) need it, as classes and their constructors are different
symbols, otherwise we will miss renaming constructors.

Reviewers: kbobyrev

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74411
2020-02-13 10:10:12 +01:00
Justin Lebar 1bd6123b78 Use std::foo_t rather than std::foo in LLVM.
Summary: C++14 migration. No functional change.

Reviewers: bkramer, JDevlieghere, lebedev.ri

Subscribers: MatzeB, hiraditya, jkorous, dexonsmith, arphaman, kadircet, lebedev.ri, usaxena95, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D74384
2020-02-11 15:12:51 -08:00