Commit Graph

6379 Commits

Author SHA1 Message Date
Richard Smith 2f1fffab73 Disable clang-tidy test that started failing after clang commit ed5a18f.
This checker appears to be intentionally not diagnosing cases where an
operator appearing in a duplicated expression might have side-effects;
Clang is now modeling fold-expressions as having an unresolved operator
name within them, so they now trip up this check.
2020-08-06 19:06:06 -07:00
Nathan Ridge f4ba7a100a [clangd] Semantic highlighting for dependent template name in template argument
Fixes https://github.com/clangd/clangd/issues/484

Differential Revision: https://reviews.llvm.org/D85272
2020-08-06 21:23:49 -04:00
Aleksandr Platonov 9f24148b21 [clangd] Fix crash in bugprone-bad-signal-to-kill-thread clang-tidy check.
Inside clangd, clang-tidy checks don't see preprocessor events in the preamble.
This leads to `Token::PtrData == nullptr` for tokens that the macro is defined to.
E.g. `#define SIGTERM 15`:
- Token::Kind == tok::numeric_constant (Token::isLiteral() == true)
- Token::UintData == 2
- Token::PtrData == nullptr

As the result of this, bugprone-bad-signal-to-kill-thread check crashes at null-dereference inside clangd.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D85417
2020-08-06 21:45:21 +03:00
Aleksandr Platonov 216ad2da74 [clang-tidy] Fix bugprone-bad-signal-to-kill-thread crash when `SIGTERM` is not a literal.
If `SIGTERM` is not a literal (e.g. `#define SIGTERM ((unsigned)15)`) bugprone-bad-signal-to-kill-thread check crashes.
Stack dump:
```
 #0 0x000000000217d15a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/llvm-project/build/bin/clang-tidy+0x217d15a)
 #1 0x000000000217b17c llvm::sys::RunSignalHandlers() (/llvm-project/build/bin/clang-tidy+0x217b17c)
 #2 0x000000000217b2e3 SignalHandler(int) (/llvm-project/build/bin/clang-tidy+0x217b2e3)
 #3 0x00007f6a7efb1390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
 #4 0x000000000212ac9b llvm::StringRef::getAsInteger(unsigned int, llvm::APInt&) const (/llvm-project/build/bin/clang-tidy+0x212ac9b)
 #5 0x0000000000593501 clang::tidy::bugprone::BadSignalToKillThreadCheck::check(clang::ast_matchers::MatchFinder::MatchResult const&) (/llvm-project/build/bin/clang-tidy+0x593501)
```

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D85398
2020-08-06 10:32:03 +03:00
Aleksandr Platonov 8671166833 [clang-tidy] Fix bugprone-bad-signal-to-kill-thread crash when `SIGTERM` was undefined after definition.
`PP->getMacroInfo()` returns nullptr for undefined macro, which leads to null-dereference at `MI->tockens().back()`.
Stack dump:
```
 #0 0x000000000217d15a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/llvm-project/build/bin/clang-tidy+0x217d15a)
 #1 0x000000000217b17c llvm::sys::RunSignalHandlers() (/llvm-project/build/bin/clang-tidy+0x217b17c)
 #2 0x000000000217b2e3 SignalHandler(int) (/llvm-project/build/bin/clang-tidy+0x217b2e3)
 #3 0x00007f39be5b1390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
 #4 0x0000000000593532 clang::tidy::bugprone::BadSignalToKillThreadCheck::check(clang::ast_matchers::MatchFinder::MatchResult const&) (/llvm-project/build/bin/clang-tidy+0x593532)
```

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D85401
2020-08-06 10:28:20 +03:00
Kadir Cetinkaya 618db6803d
[clangd][NFC] Delete dead code in ExtractFunction code action 2020-08-05 21:14:39 +02:00
Kadir Cetinkaya d3ac301886
[clangd] Disable define out-of-line code action on templates
Differential Revision: https://reviews.llvm.org/D85310
2020-08-05 20:57:28 +02:00
Haojian Wu 9a7b8b22a7 [clangd] Hide "swap if branch" tweak
This tweak is more like a demo, and doesn't provide much value in
practice.

Differential Revision: https://reviews.llvm.org/D85318
2020-08-05 20:03:21 +02:00
Kadir Cetinkaya 011732852c
[clangd] Fix a crash in DefineInline
Differential Revision: https://reviews.llvm.org/D85291
2020-08-05 17:38:17 +02:00
Bruno Ricci 19701458d4
[clang][nearly-NFC] Remove some superfluous uses of NamedDecl::getNameAsString
`OS << ND->getDeclName();` is equivalent to `OS << ND->getNameAsString();`
without the extra temporary string.

This is not quite a NFC since two uses of `getNameAsString` in a
diagnostic are replaced, which results in the named entity being
quoted with additional "'"s (ie: 'var' instead of var).
2020-08-05 13:54:37 +01:00
Alex Cameron a44161692a Support member expressions in bugprone-bool-pointer-implicit-conversion.
This addresses PR45189.
2020-08-05 07:14:28 -04:00
Nathan James 7c4782ce91
[clang-tidy] Fix regression in RenamerClangTidy
See bug https://bugs.llvm.org/show_bug.cgi\?id\=46976
2020-08-04 09:27:01 +01:00
Nathan Ridge 4ede396849 [clang] Include trailing-requires-clause in FunctionDecl's source range
Fixes https://github.com/clangd/clangd/issues/476

Differential Revision: https://reviews.llvm.org/D85108
2020-08-04 02:52:01 -04:00
Nathan James 3b44b6c900
[clang-tidy][NFC] Use correct size call for reserve 2020-08-04 00:31:19 +01:00
Haojian Wu 5191f70ab1 [clangd] Support new/deleta operator in TargetFinder.
Differential Revision: https://reviews.llvm.org/D85028
2020-08-03 14:10:21 +02:00
Ilya Golovenko d76057c1fe
Add document outline symbols from unnamed contexts, e.g. extern "C".
It is necessary to traverse children of unnamed declaration contexts
to get symbols which are currently missing in document outline, e.g.:

extern "C" {
void foo();
}

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D84839
2020-08-03 11:34:56 +02:00
Nathan James 9f21947a33
[clang-tidy][NFC] Small refactor 2020-08-01 11:04:29 +01:00
Nathan James 4888c9ce97
[clang-tidy] readability-identifier-naming checks configs for included files
When checking for the style of a decl that isn't in the main file, the check will now search for the configuration that the included files uses to gather the style for its decls.

This can be useful to silence warnings in header files that follow a different naming convention without using header-filter to silence all warnings(even from other checks) in the header file.

Reviewed By: aaron.ballman, gribozavr2

Differential Revision: https://reviews.llvm.org/D84814
2020-08-01 10:35:32 +01:00
Nathan James 1fd2049e38
[clang-tidy][NFC] Added convienence methods for getting optional options
These methods abstract away Error handling when trying to read options that can't be parsed by logging the error automatically and returning None.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D84812
2020-08-01 01:45:34 +01:00
Haojian Wu 638f0cf565 [clangd] Be more explicit on testing the optional DefLoc in LocatedSymbol.
And also fix a bug where we may return a meaningless location.

Differential Revision: https://reviews.llvm.org/D84919
2020-07-31 14:34:56 +02:00
Bjorn Pettersson 0d25d3b7e3 [clang-tidy] Fix build problem after commit 45a720a864
When building with LLVM8.0 on RHEL7.8 I got failures like this
after commit 45a720a864320bbbe:

/app/llvm/8.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/
5.4.0/../../../../include/c++/5.4.0/ext/new_allocator.h:120:23:
error: no matching constructor for initialization of
'std::pair<std::__cxx11::basic_string<char>,
std::__cxx11::basic_string<char> >'
{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }

...

../../clang-tools-extra/clang-tidy/ClangTidyOptions.cpp:73:15:
note: in instantiation of function template specialization
'std::vector<std::pair<std::__cxx11::basic_string<char>,
std::__cxx11::basic_string<char> >,
std::allocator<std::pair<std::__cxx11::basic_string<char>,
std::__cxx11::basic_string<char> > > >::emplace_back<llvm::StringRef,
const std::__cxx11::basic_string<char> &>' requested here
Options.emplace_back(KeyValue.getKey(), KeyValue.getValue().Value);

This is an attempt to avoid such build problems.
2020-07-31 14:29:03 +02:00
Kirill Bobyrev fb5588b0ad
[clangd] Propagate remote index errors via Expected
This is a refactoring: errors should be logged only on the highest level.
Switch from Optional to Expected in the serialization code.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D84939
2020-07-31 11:48:32 +02:00
Nathan James c23ae3f18e
[clang-tidy][NFC] Use StringMap for ClangTidyCheckFactories::FacoryMap
Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D84926
2020-07-30 22:57:33 +01:00
Artem Dergachev 6a043ecc0c [clang-tidy] Fix ODR violation in unittests.
Both tests define clang::tidy::test::TestCheck::registerMatchers().
This is UB and causes linker to sometimes choose the wrong overload.

Put classes into anonymous namespaces to avoid the problem.

Differential Revision: https://reviews.llvm.org/D84902
2020-07-30 08:52:47 -07:00
Kirill Bobyrev c4b7bfdff6
[clangd] NFC: Spell out types in index callback arguments 2020-07-30 17:12:29 +02:00
Kirill Bobyrev a262f0fea4
[clangd] Implement Relations request for remote index
This is the last missing bit in the core remote index implementation. The only
remaining bits are some API refactorings (replacing Optional with Expected and
being better at reporting errors).

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D84894
2020-07-30 12:57:33 +02:00
Aleksandr Platonov 05b1734661 [clangd] findNearbyIdentifier(): fix the word search in the token stream.
Without this patch the word occurrence search always returns the first token of the file.
Despite of that, `findNeardyIdentifier()` returns the correct result (but inefficently) until there are several matched tokens with the same value `floor(log2(<token line> - <word line>))` (e.g. several matched tokens on the same line).

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D84912
2020-07-30 12:45:58 +03:00
Nathan James 45a720a864
[clang-tidy] Use StringMap for ClangTidyOptions::OptionsMap
Ordering of options isn't important so an `llvm::StringMap` is a much better container for this purpose.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D84868
2020-07-30 10:31:13 +01:00
Haojian Wu cd4e8d7f6f [clangd] Fix an assertion failure in TargetFinder's heuristic resolution of dependent type.
The assertion is not true anymore after D82739, this patch just removes
it, and rename related functions.

And also fixes a missing cases.

Differential Revision: https://reviews.llvm.org/D84837
2020-07-30 08:54:22 +02:00
Richard Smith 6ce97eee35 Fix invalid attempted explicit instantiation, which Clang now rejects. 2020-07-29 13:07:34 -07:00
Nathan James bbc2ddecbd
[clang-tidy] Handled insertion only fixits when determining conflicts.
Handle insertion fix-its when removing incompatible errors by introducting a new EventType `ET_Insert`
This has lower prioirty than End events, but higher than begin.
Idea being If an insert is at the same place as a begin event, the insert should be processed first to reduce unnecessary conflicts.
Likewise if its at the same place as an end event, process the end event first for the same reason.

This also fixes https://bugs.llvm.org/show_bug.cgi?id=46511.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82898
2020-07-29 16:35:44 +01:00
Nathan James 62beb7c6f4
[clang-tidy] Fix module options being registered with different priorities
Not a bug that is ever likely to materialise, but still worth fixing

Reviewed By: DmitryPolukhin

Differential Revision: https://reviews.llvm.org/D84850
2020-07-29 16:19:07 +01:00
Nathan James b99630e432
[clang-tidy] Fix RedundantStringCStrCheck with r values
The previous fix for this, https://reviews.llvm.org/D76761, Passed test cases but failed in the real world as std::string has a non trivial destructor so creates a CXXBindTemporaryExpr.

This handles that shortfall and updates the test case std::basic_string implementation to use a non trivial destructor to reflect real world behaviour.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D84831
2020-07-29 15:35:31 +01:00
Kirill Bobyrev 1603470e59
[clangd] Fix clangd-indexeer builds after D84697
Some buildbots require explicit clangdSupport dependency:

http://lab.llvm.org:8011/builders/llvm-avr-linux/builds/3996/steps/build%20stage%201/logs/stdio
2020-07-29 10:27:11 +02:00
Anh Tuyen Tran 8dbe9b2498 [Clang-tools-extra] Mark override a function which overrides a virtual one
Function void run() on line 286 overrides a virtual function on line 92 of
clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp.  Not marking it override will
cause a build failure when we use -Werror (every warning is treated as an error).

Reviewed By: kbobyrev (Kirill Bobyrev)

Differential Revision: https://reviews.llvm.org/D84794
2020-07-29 05:30:33 +00:00
Kirill Bobyrev fb22678cd6 [clangd] Use elog instead of llvm::errs, log instead of llvm::outs
Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D84697
2020-07-29 01:48:24 +02:00
Nathan James 7bae3188e0 [clang-tidy][NFC] Make OptionsView methods as const where missing 2020-07-28 14:52:43 +01:00
Artem Dergachev 8c9241a051 [clang-tidy] Suppress one unittest on macOS.
Possibly a linker bug but I'm in a hurry to fix a buildbot.

Differential Revision: https://reviews.llvm.org/D84453
2020-07-27 22:38:53 -07:00
Kirill Bobyrev 731043c0c4
[clangd] Add more logs and attach tracers to remote index server routines
Reviewers: kadircet

Reviewed By: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D84499
2020-07-27 20:45:18 +02:00
Logan Smith a52aea0ba6 Use INTERFACE_COMPILE_OPTIONS to disable -Wsuggest-override for any target that links to gtest
This cleans up several CMakeLists.txt's where -Wno-suggest-override was manually specified. These test targets now inherit this flag from the gtest target.

Some unittests CMakeLists.txt's, in particular Flang and LLDB, are not touched by this patch. Flang manually adds the gtest sources itself in some configurations, rather than linking to LLVM's gtest target, so this fix would be insufficient to cover those cases. Similarly, LLDB has subdirectories that manually add the gtest headers to their include path without linking to the gtest target, so those subdirectories still need -Wno-suggest-override to be manually specified to compile without warnings.

Differential Revision: https://reviews.llvm.org/D84554
2020-07-27 08:37:01 -07:00
Hans Wennborg 08e9556d5d llvm_canonicalize_cmake_booleans(CLANGD_ENABLE_REMOTE)
Otherwise it got defined as e.g. OFF in Features.inc.
2020-07-27 14:42:04 +02:00
Aleksandr Platonov 90684d1545 [clangd] Collect references for externally visible main-file symbols
Summary:
Without this patch clangd does not collect references for main-file symbols if there is no public declaration in preamble.
Example:
`test1.c`
```
void f1() {}
```

`test2.c`
```
extern void f1();
void f2() {
  f^1();
}
```
`Find all references` does not show definition of f1() in the result, but GTD works OK.

Reviewers: sammccall, kadircet

Reviewed By: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D84513
2020-07-27 15:35:53 +03:00
Kirill Bobyrev f49a7ad8c0
[clangd] Add marshalling code for all request types
Summary:
Only FuzzyFindRequest is implemented via Marshaller even though other requests
also follow a similar pattern. Unify them under the marshalling umbrella and
make the server requests even more uniform to complement D84499.

Reviewers: kadircet

Reviewed By: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D84525
2020-07-27 14:16:03 +02:00
Hans Wennborg 529441e88e Fix another #ifdef CLANGD_ENABLE_REMOTE 2020-07-27 14:11:29 +02:00
Hans Wennborg 40d11a8780 ClangdMain.cpp: this #ifdef should be an #if
CLANGD_ENABLE_REMOTE is always defined; to 0 or 1.
2020-07-27 14:05:02 +02:00
Nathan James 13c9bbc28e
[clang-tidy] Refactor IncludeInserter
Simplified how `IncludeInserter` is used in Checks by abstracting away the SourceManager and PPCallbacks inside the method `registerPreprocessor`.
Changed checks that use `IncludeInserter` to no longer use a `std::unique_ptr`, instead the IncludeInserter is just a member of the class thats initialized with an `IncludeStyle`.
Saving an unnecessary allocation.

This results in the removal of the field `IncludeSorter::IncludeStyle` from the checks, as its wrapped in the `IncludeInserter`.
No longer need to create an instance of the `IncludeInserter` in the registerPPCallbacks, now that method only needs to contain:
```
Inserter.registerPreprocessor(PP);
```
Also added a helper method to `IncludeInserter` called `createMainFileInclusionInsertion`, purely sugar but does better express intentions.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D83680
2020-07-27 12:48:55 +01:00
Hans Wennborg 47a0254229 Speculative build fix for clangd/Features.inc.in 2020-07-27 13:39:54 +02:00
Kirill Bobyrev 37ac559fcc [clangd] Add option to use remote index as static index
Reviewers: hokein

Reviewed By: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83817
2020-07-27 11:24:15 +02:00
Kirill Bobyrev 974ffee9cc [clangd] Switch from EXPECT_TRUE to ASSERT_TRUE in remote marshalling tests
Summary:
When dereferencing Optional's it makes sense to use ASSERT_TRUE for better
test failures readability. Switch from EXPECT_TRUE to ASSERT_TRUE where
it is appropriate.

Reviewers: kadircet

Reviewed By: kadircet

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

Tags: #clang

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

Signed-off-by: Kirill Bobyrev <kbobyrev@google.com>
2020-07-27 10:44:23 +02:00
Hannes Käufler 3bbf3e026d Replace comment by private method; NFC. 2020-07-26 13:59:45 -04:00
Logan Smith 77e0e9e17d Reapply "Try enabling -Wsuggest-override again, using add_compile_options instead of add_compile_definitions for disabling it in unittests/ directories."
add_compile_options is more sensitive to its location in the file than add_definitions--it only takes effect for sources that are added after it. This updated patch ensures that the add_compile_options is done before adding any source files that depend on it.

Using add_definitions caused the flag to be passed to rc.exe on Windows and thus broke Windows builds.
2020-07-22 17:50:19 -07:00
Logan Smith 97a0f80c46 Revert "Try enabling -Wsuggest-override again, using add_compile_options instead of add_compile_definitions for disabling it in unittests/ directories."
This reverts commit 388c9fb1af.
2020-07-22 15:07:01 -07:00
Logan Smith 388c9fb1af Try enabling -Wsuggest-override again, using add_compile_options instead of add_compile_definitions for disabling it in unittests/ directories.
Using add_compile_definitions caused the flag to be passed to rc.exe on Windows and thus broke Windows builds.
2020-07-22 14:19:34 -07:00
Hans Wennborg 3eec657825 Revert "Enable -Wsuggest-override in the LLVM build" and the follow-ups.
After lots of follow-up fixes, there are still problems, such as
-Wno-suggest-override getting passed to the Windows Resource Compiler
because it was added with add_definitions in the CMake file.

Rather than piling on another fix, let's revert so this can be re-landed
when there's a proper fix.

This reverts commit 21c0b4c1e8.
This reverts commit 81d68ad27b.
This reverts commit a361aa5249.
This reverts commit fa42b7cf29.
This reverts commit 955f87f947.
This reverts commit 8b16e45f66.
This reverts commit 308a127a38.
This reverts commit 274b6b0c7a.
This reverts commit 1c7037a2a5.
2020-07-22 20:23:58 +02:00
Logan Smith 1c7037a2a5 [clangd] Disable -Wsuggest-override for unittests/ 2020-07-22 10:49:09 -07:00
Aleksandr Platonov 98b56c09be [clangd] Fixes in lit tests
Summary:
Changes:
- `background-index.test` Add Windows support, don't create redundant `*-e` files on macOS
- `did-change-configuration-params.test` Replace `cat | FileCheck` with `FileCheck --input-file`
- `test-uri-windows.test` This test did not run on Windows displite `REQUIRES: windows-gnu || windows-msvc` (replacement: `UNSUPPORTED: !(windows-gnu || windows-msvc)`).

Reviewers: sammccall, kadircet

Reviewed By: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83759
2020-07-22 16:00:34 +03:00
Ilya Golovenko 3975c3be80 [clangd] Fix conversion from Windows UNC paths to file URI format.
Summary:
The fix improves handling of Windows UNC paths to align with Appendix E. Nonstandard Syntax Variations of RFC 8089.

Before this fix it was difficult to use Windows UNC paths in compile_commands.json database as such paths were converted to file URIs using 'file:////auth/share/file.cpp' notation instead of recommended 'file://auth/share/file.cpp'.

As an example, VS.Code cannot understand file URIs with 4 starting slashes, thus such features as go-to-definition, jump-to-file, hover tooltip, etc. stop working. This also applicable to files which reside on Windows network-mapped drives because clangd internally resolves file paths to real paths in some cases and such paths get resolved to UNC paths.

Reviewers: sammccall, kadircet

Reviewed By: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D84172
2020-07-22 12:13:09 +02:00
Kadir Cetinkaya a69f9a8584
[clangd] Fix Origin and MainFileOnly-ness for macros
Summary:
This was resulting in macros coming from preambles vanishing when user
have opened the source header. For example:

```
// test.h:
 #define X
```

and

```
// test.cc
 #include "test.h
^
```

If user only opens test.cc, we'll get `X` as a completion candidate,
since it is indexed as part of the preamble. But if the user opens
test.h afterwards we would index it as part of the main file and lose
the symbol (as new index shard for test.h will override the existing one
in dynamic index).

Also we were not setting origins for macros correctly, this patch also
fixes it.

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

Reviewers: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D84297
2020-07-22 11:24:31 +02:00
Haojian Wu 82dbb1b2b4 Fix the clang-tidy build after get/isIntegerConstantExpression
refactoring.
2020-07-22 09:38:56 +02:00
Aleksandr Platonov 23ff4e4f5d Revert "[clangd] Fixes in lit tests"
This reverts commit ff63d6be93.
2020-07-21 23:32:47 +03:00
Aleksandr Platonov ff63d6be93 [clangd] Fixes in lit tests
Summary:
Changes:
- `background-index.test` Add Windows support.
- `did-change-configuration-params.test` Replace `cat | FileCheck` with `FileCheck --input-file`
- `test-uri-windows.test` This test did not run on Windows displite `REQUIRES: windows-gnu || windows-msvc` (replacement: `UNSUPPORTED: !(windows-gnu || windows-msvc)`).

Reviewers: sammccall, kadircet

Reviewed By: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83759
2020-07-21 21:21:40 +03:00
Logan Smith fa42b7cf29 [clang-tools-extra] Disable -Wsuggest-override for unittests/
This avoids massive warning spam due to the unit tests' use of gtest and gmock, which do not use the 'override' keyword in their sources.

Differential Revision: https://reviews.llvm.org/D84213
2020-07-21 09:11:53 -07:00
Haojian Wu 3ad0181169 [clangd] Fix null check after D82739.
I hit the null-deference crash when opening ASTReaderDecl.cpp.

The BaseType can be a nullptr,
2020-07-21 12:15:17 +02:00
Kirill Bobyrev 7d591e123e [clangd] Complete the fix for (Local|Remote)IndexRoot confusion
Related revision: https://reviews.llvm.org/D83826
2020-07-21 11:53:17 +02:00
Kirill Bobyrev 4470b8c6a6 [clangd] Fix assertions for D83826
FuzzyFindRequest's toProtobuf is called on the client side (hence
LocalIndexRoot must be present) and fromProtobuf - on the server.
2020-07-21 11:20:31 +02:00
Kirill Bobyrev eef162c330
[clangd] Don't send invalid messages from remote index
Summary:
Remote server should not send messages that are invalid and will cause problems
on the client side. The client should not be affected by server's failures
whenever possible.

Also add more error messages and logs.

Reviewers: sammccall

Reviewed By: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83826
2020-07-21 11:05:03 +02:00
Haojian Wu 566b49884d [clang] Set the error-bit for ill-formed semantic InitListExpr.
When a semantic checking fails on a syntactic InitListExpr, we will
get an ill-formed semantic InitListExpr (e.g. some inits are nullptr),
using this semantic InitListExpr in clang (without setting the err-bits) is crashy.

Differential Revision: https://reviews.llvm.org/D84140
2020-07-21 09:39:44 +02:00
Nathan Ridge 9946dcd3e9 [clangd] Improve heuristic resolution of dependent types in TargetFinder
* Try to apply heuristic resolution recursively to the base
   expression of a CXXDependentScopeMemberExpr.

 * Try to apply heuristic resolution recursively to the callee
   expression in a call expression.

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

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82739
2020-07-21 02:03:06 -04:00
Nathan Ridge 100dbd1562 [clangd] Handle deduction guides in TargetFinder and ExplicitReferenceCollector
Summary: Fixes https://github.com/clangd/clangd/issues/463.

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D84122
2020-07-21 01:44:48 -04:00
Aleksandr Platonov c911803d5d
[clangd] Remove TokenBuffer usage in TypeHierarchy
Summary:
This patch mostly reverts D74850.
We could not use `AST.getTokens()` here, because it does not have tokens from the preamble.

Reviewers: sammccall, kadircet

Reviewed By: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D84144
2020-07-20 21:00:49 +02:00
Haojian Wu 61d664c938 Fix clangd build, NFC 2020-07-20 15:13:20 +02:00
Sam McCall 72f2fb1db4 [clangd] Exclude preprocessed-to-nothing tokens from selection
This prevents selection of empty preprocessor entities (like #define directives,
or text in disabled sections) creating a selection in the parent element.

Summary: Based on D83508 by Aleksandr Platonov.

Reviewers: ArcsinX, kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D84012
2020-07-20 14:50:12 +02:00
Aaron Ballman 97914164f8 Silence a "logical operation on address of string constant" via CMake instead. 2020-07-19 11:19:48 -04:00
Aaron Ballman b79ca34530 Revert 7dfff42f01 as it broke non-Windows builds. 2020-07-19 11:12:39 -04:00
Aaron Ballman 7dfff42f01 Silencing some 'logical operation on address of string constant diagnostics; NFC 2020-07-19 10:53:51 -04:00
Michael Spencer 7fcc1bb4b6 [clangd] Fix the build with clang <3.9.
In clang <3.9 the `unique_ptr` constructor that is supposed to allow
for Derived to Base conversion does not work. Remove this if we drop
support for such configurations.

This is the same fix as in fda901a987, and it updates the comments
to better reflect the actual issue. The same thing reproduces with
libc++ with older clangs.
2020-07-17 16:12:31 -06:00
Kadir Cetinkaya 46c921003c
[clangd] Always retrieve ProjectInfo from Base in OverlayCDB
Summary:
Clangd is returning current working directory for overriden commands.
This can cause inconsistencies between:
- header and the main files, as OverlayCDB only contains entries for the main
  files it direct any queries for the headers to the base, creating a
  discrepancy between the two.
- different clangd instances, as the results will be different depending on the
  timing of execution of the query and override of the command. hence clangd
  might see two different project infos for the same file between different
  invocations.
- editors and the way user has invoked it, as current working directory of
  clangd will depend on those, hence even when there's no underlying base CWD
  might change depending on the editor, or the directory user has started the
  editor in.

This patch gets rid of that discrepency by always directing queries to base or
returning llvm::None in absence of it.

For a sample bug see https://reviews.llvm.org/D83099#2154185.

Reviewers: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83934
2020-07-16 12:33:54 +02:00
Mikael Holmen 274332282c [clangd] Fix a few gcc warnings [NFC] 2020-07-16 09:36:17 +02:00
Kirill Bobyrev c11c78a1bd
[clangd] Use llvm::errs() instead of outs() for errors
Summary: errs() is more appropriate for error messages in dexp and clangd-index-server.

Reviewers: sammccall

Reviewed By: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83827
2020-07-15 14:34:29 +02:00
Sam McCall cf7160c0b0 [clangd] Config: also propagate in sync (testing) mode
Summary:
I hit this while trying to add a config-over-LSP lit test, which I think
is an appropriate way to test this feature.

That needs a few more changes though...

Reviewers: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83802
2020-07-15 12:30:08 +02:00
Hans Wennborg 7ab7b979d2 Bump the trunk major version to 12
and clear the release notes.
2020-07-15 12:05:05 +02:00
Sam McCall f782d9c700 [clangd] Fix use-after-free in ArgStripper 2020-07-15 11:03:11 +02:00
Nathan James fcf0f75a59
[clang-tidy] OptionsView::store specialized on bool
Following on fcf7cc268f and 672207c319 which granted checks the ability to read boolean configuration arguments as `true` or `false`.
This enables storing the options back to the configuration file using `true` and `false`.
This is in line with how clang-format dumps boolean options in its style config.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D83053
2020-07-14 22:19:37 +01:00
Sam McCall 00d97b758e [clangd] Config: on by default
Summary: (Possible to flip back on the branch if this breaks things)

Reviewers: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83790
2020-07-14 21:44:25 +02:00
Sam McCall f88ce078f7 [clangd] Make config::Provider::combine non-owning. NFC
This is a prerequisite for having ClangdLSPServer inject its own.
2020-07-14 20:45:02 +02:00
Sam McCall dbf486c0de [clangd] Config: Index.Background
Summary:
We only support Build/Skip for now, but with 'Load' or similar as an
option for future (load existing shards but don't build new ones).

This requires creating the config for each TU on startup. In LLVM, this
is 4000 occurrences for a total of 800ms on my machine.
But together with caching from D83755 it is only 25ms.

Reviewers: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83768
2020-07-14 19:04:11 +02:00
Sam McCall 50a5fa8b9b [clangd] Add missing link dep after 8eb8c92eb4 2020-07-14 17:03:45 +02:00
Sam McCall ff616f74c3 [clangd] Cache config files for 5 seconds, without revalidating with stat.
Summary:
This is motivated by:
 - code completion: nice to do no i/o on the request path
 - background index: deciding whether to enqueue each file would stat the config
   file thousands of times in quick succession.

Currently it's applied uniformly to all requests though.

This gives up on performing stat() outside the lock, all this achieves is
letting multiple threads stat concurrently (and thus finish without contention
for nonexistent files).
The ability to finish without IO (just mutex lock + integer check) should
outweigh this, and is less sensitive to platform IO characteristics.

Reviewers: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83755
2020-07-14 17:00:41 +02:00
Sam McCall 6c16fbd0ac [clangd] Config: CompileFlags.Remove
Summary: While here, add documentation to CompileFlags and CompileFlags.Add.

Reviewers: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83705
2020-07-14 15:56:44 +02:00
Sam McCall 8eb8c92eb4 [clangd] Add library to semantically strip flags by name.
Summary:
This is designed for tweaking compile commands by specifying flags to add/remove
in a config file. Something like:
  CompileFlags: { Remove: -fcolor-diagnostics }

Having users tweak raw argv (e.g. with a regex) is going to end in tears: bugs
around clang-cl, xclang, aliases, joined-vs-separate args etc are inevitable.

This isn't in tooling because of the performance choices: build a big table
up-front to make subsequent actions fast. Maybe it should be though.

Reviewers: adamcz, hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81958
2020-07-14 15:41:46 +02:00
Kirill Bobyrev 7a514c9bf8
[clangd] Implement textDocument/foldingRange
Summary:
This patch introduces basic textDocument/foldingRange support. It relies on
textDocument/documentSymbols to collect all symbols and uses takes ranges
to create folds.

The next steps for textDocument/foldingRange support would be:

* Implementing FoldingRangeClientCapabilities and respecting respect client
  preferences
* Specifying folding range kind
* Migrating from DocumentSymbol implementation to custom RecursiveASTVisitor flow that will allow more flexibility
* Supporting more folding range types: comments, PP conditional regions, includes and other code regions (e.g. public/private/protected sections of classes, control flow statement bodies)

Tested: (Neo)Vim (coc-clangd) and VSCode.

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

Reviewers: sammccall

Reviewed By: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82436
2020-07-14 09:28:42 +02:00
Sam McCall 9d3e9a3e3c [clangd] Remove const_cast. NFC 2020-07-13 20:44:11 +02:00
Kirill Bobyrev d7d1af3916
[clangd] Fix DocumentSymbol ranges
Summary:
DocumentSymbol ranges were not previously tested and, as a result, had invalid
end location. This patch addresses the issue.

Reviewers: sammccall

Reviewed By: sammccall

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83668
2020-07-13 15:02:53 +02:00
Haojian Wu 26cf6c1513 [clangd] Add metrics for recovery-expr type propagation.
Differential Revision: https://reviews.llvm.org/D83657
2020-07-13 11:26:45 +02:00
Aleksandr Platonov 07c4c7e795
[clangd] Fix tests build for GCC5
Summary:
Build log:
```
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp: In member function ‘virtual void clang::clangd::{anonymous}::PreamblePatchTest_Define_Test::TestBody()’:
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:267:3: error: could not convert ‘(const char*)"\012        #define BAR\012        [[BAR]]"’ from ‘const char*’ to ‘llvm::StringLitera ’
   };
   ^
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:267:3: error: could not convert ‘(const char*)"#line 0 \".*main.cpp\"\012#line 2\012#define         BAR\012"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:267:3: error: could not convert ‘(const char*)"\012        #define BAR \\\012\012        [[BAR]]"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:267:3: error: could not convert ‘(const char*)"#line 0 \".*main.cpp\"\012#line 2\012#define         BAR\012"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:267:3: error: could not convert ‘(const char*)"\012        #define \\\012                BAR\012        [[BAR]]"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:267:3: error: could not convert ‘(const char*)"#line 0 \".*main.cpp\"\012#line 3\012#define         BAR\012"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp: In member function ‘virtual void clang::clangd::{anonymous}::PreamblePatchTest_LocateMacroAtWorks_Test::TestBody()’:
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:357:3: error: could not convert ‘(const char*)""’ from ‘const char*’ to ‘llvm::StringLiteral’
   };
   ^
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:357:3: error: could not convert ‘(const char*)"\012            #define $def^FOO\012            $use^FOO"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:357:3: error: could not convert ‘(const char*)""’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:357:3: error: could not convert ‘(const char*)"\012            #define $def^FOO\012            #undef $use^FOO"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:357:3: error: could not convert ‘(const char*)""’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:357:3: error: could not convert ‘(const char*)"\012            #define $def^FOO\012            #undef FOO\012            $use^FOO"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:357:3: error: could not convert ‘(const char*)""’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:357:3: error: could not convert ‘(const char*)"\012            #define \\\012              $def^FOO\012            $use^FOO"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:357:3: error: could not convert ‘(const char*)""’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:357:3: error: could not convert ‘(const char*)"\012            #\\\012              define /* FOO */\\\012              /* FOO */ $def^FOO\012            $use^FOO"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:357:3: error: could not convert ‘(const char*)"#define FOO"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:357:3: error: could not convert ‘(const char*)"\012            #define BAR\012            #define $def^FOO\012            $use^FOO"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp: In member function ‘virtual void clang::clangd::{anonymous}::PreamblePatchTest_RefsToMacros_Test::TestBody()’:
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:445:3: error: could not convert ‘(const char*)""’ from ‘const char*’ to ‘llvm::StringLiteral’
   };
   ^
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:445:3: error: could not convert ‘(const char*)"\012            #define ^FOO\012            ^[[FOO]]"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:445:3: error: could not convert ‘(const char*)"#define FOO"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:445:3: error: could not convert ‘(const char*)"\012            #define BAR\012            #define ^FOO\012            ^[[FOO]]"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:445:3: error: could not convert ‘(const char*)""’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:445:3: error: could not convert ‘(const char*)"\012            #define ^FOO\012            #undef ^FOO"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp: In member function ‘virtual void clang::clangd::{anonymous}::PreamblePatch_ModifiedBounds_Test::TestBody()’:
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:512:3: error: could not convert ‘(const char*)""’ from ‘const char*’ to ‘llvm::StringLiteral’
   };
   ^
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:512:3: error: could not convert ‘(const char*)"\012            #define FOO\012            FOO"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:512:3: error: could not convert ‘(const char*)"#define FOO"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:512:3: error: could not convert ‘(const char*)"#define BAR"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:512:3: error: could not convert ‘(const char*)"\012            #define FOO\012            #undef FOO"’ from ‘const char*’ to ‘llvm::StringLiteral’
llvm-project/clang-tools-extra/clangd/unittests/PreambleTests.cpp:512:3: error: could not convert ‘(const char*)"#define FOO"’ from ‘const char*’ to ‘llvm::StringLiteral’
```

Patch by @ArcsinX !

Reviewers: kadircet, sammccall

Reviewed By: kadircet

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83548
2020-07-13 09:06:20 +02:00
Atmn Patel 78443666bc [OpenMP] Add firstprivate as a default data-sharing attribute to clang
This implements the default(firstprivate) clause as defined in OpenMP
Technical Report 8 (2.22.4).

Reviewed By: jdoerfert, ABataev

Differential Revision: https://reviews.llvm.org/D75591
2020-07-12 23:01:40 -05:00
Nathan James c3bdc9814d
[clang-tidy] Reworked enum options handling(again)
Reland b9306fd after fixing the issue causing mac builds to fail unittests.

Following on from D77085, I was never happy with the passing a mapping to the option get/store functions. This patch addresses this by using explicit specializations to handle the serializing and deserializing of enum options.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82188
2020-07-11 10:13:20 +01:00
Zequan Wu dcd76c0c07 [Lexer] Fix missing coverage line after #endif
Summary: bug reported here: https://bugs.llvm.org/show_bug.cgi?id=46660

Reviewers: vsk, efriedma, arphaman

Reviewed By: vsk

Subscribers: dexonsmith, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83514
2020-07-10 09:05:20 -07:00
Sam McCall 5fea54bc05 [clangd] Update semanticTokens support to reflect latest LSP draft
Summary: Mostly a few methods and message names have been renamed.

Reviewers: hokein

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83556
2020-07-10 16:52:57 +02:00
Haojian Wu 015a0faa5e [clangd] Fix hover crash on InitListExpr.
Fixes https://github.com/clangd/clangd/issues/455

Differential Revision: https://reviews.llvm.org/D83546
2020-07-10 16:18:16 +02:00