Commit Graph

3237 Commits

Author SHA1 Message Date
Ilya Biryukov f118d51fff [clangd] Fix label and snippet for funcs in the index
This is a follow-up to r330004 to fix functions with required template args,
e.g. std::make_shared.

llvm-svn: 330087
2018-04-14 16:27:35 +00:00
Ilya Biryukov cf124bd828 [clangd] Match AST and Index label for template Symbols
Summary:
Previsouly, class completions items from the index were missing
template parameters in both the snippet and the label.

Reviewers: sammccall, hokein

Reviewed By: sammccall

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

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

llvm-svn: 330004
2018-04-13 11:03:07 +00:00
Zinovy Nis 258d607b9f [clang-tidy] Fix ParentVirtualCallCheck for old MSVS compilers
llvm-svn: 329999
2018-04-13 08:43:47 +00:00
Haojian Wu 545c02a710 [clangd] Add line and column number to the index symbol.
Summary:
LSP is using Line & column as symbol position, clangd needs to transfer file
offset to Line & column when sending results back to LSP client, which is a high
cost, especially for finding workspace symbol -- we have to read the file
content from disk (if it isn't loaded in memory).

Saving these information in the index will make the clangd life eaiser.

Reviewers: sammccall

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

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

llvm-svn: 329997
2018-04-13 08:30:39 +00:00
Zinovy Nis 963b4b8a19 [clang-tidy] [bugprone-parent-virtual-call] Minor cosmetic changes. NFC
llvm-svn: 329994
2018-04-13 07:46:27 +00:00
Jan Korous 6269d34404 [clangd][nfc] Simplify readDelimitedMessage()
istream::eof() is always false after successful getline()

llvm-svn: 329958
2018-04-12 21:33:24 +00:00
Zinovy Nis 5ef2b52e5b Revert "[clang-tidy] [modernize-use-auto] Get only a length of token, not the token itself"
This reverts r329873 as getting only a single token length is wrong for multi-token type names,
like 'unsigned long int'.

llvm-svn: 329949
2018-04-12 20:33:24 +00:00
Eugene Zelenko b0389fc616 [Documentation] Order of changes in existing checks in Release Notes.
llvm-svn: 329927
2018-04-12 17:19:09 +00:00
Roman Lebedev 4d37af003f [clang-tidy] readability-function-size: add VariableThreshold param.
Summary:
Pretty straight-forward, just count all the variable declarations in the function's body, and if more than the configured threshold - do complain.

Note that this continues perverse practice of disabling the new option by default.
I'm not certain where is the balance point between not being too noisy, and actually enforcing the good practice.
If we really want to not disable this by default, but also to not cause too many new warnings, we could default to 50 or so.
But that is a lot of variables too...

I was able to find one coding style referencing variable count:
  - https://www.kernel.org/doc/html/v4.15/process/coding-style.html#functions

    > Another measure of the function is the number of local variables. They shouldn’t exceed 5-10, or you’re doing something wrong.

Reviewers: hokein, xazax.hun, JonasToth, aaron.ballman, alexfh

Reviewed By: aaron.ballman

Subscribers: kimgr, Eugene.Zelenko, rnkovacs, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 329902
2018-04-12 12:06:42 +00:00
Benjamin Kramer 8d2acfd8e8 [clang-apply-replacements] Always initialize FormatStyle.
The cleanup logic reads from this for cleanups even if reformatting is
not requested.

Found by msan.

llvm-svn: 329894
2018-04-12 10:35:24 +00:00
Roman Lebedev 34812c0d0d [clang-apply-replacements] Don't forget to link to clangToolingRefactor
Fixes build:

[1/3] Linking CXX shared library lib/libclangApplyReplacements.so.7svn
FAILED: lib/libclangApplyReplacements.so.7svn
<...>
/usr/local/bin/ld.lld: error: undefined symbol: clang::tooling::AtomicChange::replace(clang::SourceManager const&, clang::SourceLocation, unsigned int, llvm::StringRef)
>>> referenced by ApplyReplacements.cpp
>>>               tools/clang/tools/extra/clang-apply-replacements/CMakeFiles/clangApplyReplacements.dir/lib/Tooling/ApplyReplacements.cpp.o:(clang::replace::mergeAndDeduplicate(std::vector<clang::tooling::TranslationUnitReplacements, std::allocator<clang::tooling::TranslationUnitReplacements> > const&, std::vector<clang::tooling::TranslationUnitDiagnostics, std::allocator<clang::tooling::TranslationUnitDiagnostics> > const&, llvm::DenseMap<clang::FileEntry const*, std::vector<clang::tooling::AtomicChange, std::allocator<clang::tooling::AtomicChange> >, llvm::DenseMapInfo<clang::FileEntry const*>, llvm::detail::DenseMapPair<clang::FileEntry const*, std::vector<clang::tooling::AtomicChange, std::allocator<clang::tooling::AtomicChange> > > >&, clang::SourceManager&))

/usr/local/bin/ld.lld: error: undefined symbol: clang::tooling::applyAtomicChanges[abi:cxx11](llvm::StringRef, llvm::StringRef, llvm::ArrayRef<clang::tooling::AtomicChange>, clang::tooling::ApplyChangesSpec const&)
>>> referenced by ApplyReplacements.cpp
>>>               tools/clang/tools/extra/clang-apply-replacements/CMakeFiles/clangApplyReplacements.dir/lib/Tooling/ApplyReplacements.cpp.o:(clang::replace::applyChanges[abi:cxx11](llvm::StringRef, std::vector<clang::tooling::AtomicChange, std::allocator<clang::tooling::AtomicChange> > const&, clang::tooling::ApplyChangesSpec const&, clang::DiagnosticsEngine&))
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Refs. D43764, rL329813

llvm-svn: 329892
2018-04-12 10:01:20 +00:00
Zinovy Nis 60874d4faf [clang-tidy] [modernize-use-auto] Fix test modernize-use-auto-new-remove-stars.cpp after improvement
'tooling::fixit::getText' considers a length of "int *" to be 5 instead of 3 
in a new algorithm in https://reviews.llvm.org/rCTE329873. It was the root of 
the test failure.

llvm-svn: 329881
2018-04-12 06:45:47 +00:00
Zinovy Nis 0b0b882356 [Documentation] Fix options order for Release Notes in modernize-use-auto.
llvm-svn: 329875
2018-04-12 05:45:16 +00:00
Zinovy Nis dfaa021e99 [clang-tidy] [modernize-use-auto] Get only a length of token, not the token itself
llvm-svn: 329873
2018-04-12 05:41:24 +00:00
Eugene Zelenko b7a747e6a3 [Documentation] Fix formatting and order in Release Notes for recent changes in modernize-use-auto.
llvm-svn: 329833
2018-04-11 18:03:57 +00:00
Malcolm Parsons 7c3e14b63b [clang-apply-replacements] Convert tooling::Replacements to tooling::AtomicChange for conflict resolving of changes, code cleanup, and code formatting.
Summary:
By converting Replacements by AtomicChange, clang-apply-replacements is able like clang-tidy to automatically cleanup and format changes.
This should permits to close this ticket: https://bugs.llvm.org/show_bug.cgi?id=35051 and attempt to follow hints from https://reviews.llvm.org/D43500 comments.

Reviewers: klimek, ioeric

Reviewed By: ioeric

Subscribers: malcolm.parsons, mgorny, cfe-commits

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

Patch by Jeremy Demeule.

llvm-svn: 329813
2018-04-11 14:39:17 +00:00
Jonas Toth 057f5a1259 [clang-tidy] fix buildbots from hicpp-signed-bitwise
The applied patch to diagnose assignment operators introduced
breakage on some architectures. This patch tries to rectify that.

llvm-svn: 329790
2018-04-11 10:22:25 +00:00
Jonas Toth 0f5f41df93 [clang-tidy] add missing assignment operations in hicpp-signed-bitwise
This patch resolves the bug https://bugs.llvm.org/show_bug.cgi?id=36963.

- implement missing assignment operators for hicpp-signed-bitwise
- mention fix in release notes

Reviewers:
aaron.ballman, hokein, alexfh

Differential: https://reviews.llvm.org/D45414
llvm-svn: 329789
2018-04-11 09:53:08 +00:00
George Burgess IV 3b151b2189 [clang-tidy] Add a `android-comparison-in-temp-failure-retry` check
This check attempts to catch buggy uses of the `TEMP_FAILURE_RETRY`
macro, which is provided by both Bionic and glibc.

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

llvm-svn: 329759
2018-04-10 21:22:22 +00:00
Roman Lebedev 9f742bc2e9 [clang-tidy] Unbreak run-clang-tidy.cpp test (modernize-use-auto.MinTypeNameLength)
Again, refs. D45405, rL329730.

llvm-svn: 329756
2018-04-10 20:59:27 +00:00
Roman Lebedev feaaa8c7a0 [clang-tidy][modernize]: don't forget to actually link to Tooling.
Fixes build for me:

[1/5] Linking CXX shared library lib/libclangTidyModernizeModule.so.7svn
FAILED: lib/libclangTidyModernizeModule.so.7svn
<...>
/usr/local/bin/ld.lld: error: undefined symbol: clang::tooling::fixit::internal::getText(clang::SourceRange, clang::ASTContext const&)
>>> referenced by UseAutoCheck.cpp
>>>               tools/clang/tools/extra/clang-tidy/modernize/CMakeFiles/clangTidyModernizeModule.dir/UseAutoCheck.cpp.o:(clang::tidy::modernize::UseAutoCheck::replaceExpr(clang::DeclStmt const*, clang::ASTContext*, llvm::function_ref<clang::QualType (clang::Expr const*)>, llvm::StringRef))


Refs. D45405, rL329730.

llvm-svn: 329750
2018-04-10 20:07:06 +00:00
Roman Lebedev 6bd27152e1 [clang-tidy][Fuchsia]: don't forget to actually link to Google Module.
Fixes build for me:

[1/7] Linking CXX shared library lib/libclangTidyFuchsiaModule.so.7svn
FAILED: lib/libclangTidyFuchsiaModule.so.7svn
<...>
/usr/local/bin/ld.lld: error: undefined symbol: clang::tidy::google::build::UnnamedNamespaceInHeaderCheck::UnnamedNamespaceInHeaderCheck(llvm::StringRef, clang::tidy::ClangTidyContext*)
>>> referenced by FuchsiaTidyModule.cpp
>>>               tools/clang/tools/extra/clang-tidy/fuchsia/CMakeFiles/clangTidyFuchsiaModule.dir/FuchsiaTidyModule.cpp.o:(std::_Function_handler<clang::tidy::ClangTidyCheck* (llvm::StringRef, clang::tidy::ClangTidyContext*), void clang::tidy::ClangTidyCheckFactories::registerCheck<clang::tidy::google::build::UnnamedNamespaceInHeaderCheck>(llvm::StringRef)::'lambda'(llvm::StringRef, clang::tidy::ClangTidyContext*)>::_M_invoke(std::_Any_data const&, llvm::StringRef&&, clang::tidy::ClangTidyContext*&&))

Refs. D45447, rCTE329720

llvm-svn: 329749
2018-04-10 20:07:02 +00:00
Zinovy Nis 032cc77b37 [clang-tidy] [modernize-use-auto] Fix members initialization order
llvm-svn: 329740
2018-04-10 18:56:29 +00:00
Zinovy Nis e68c7fa1e5 [clang-tidy] [modernize-use-auto] Add a threshold for minimal type name length to be replaced with 'auto'
The threshold option is 'MinTypeNameLength' with default value '5'. 
With MinTypeNameLength == 5 'int'/'bool' and 'const int'/'const bool' 
will not be converted to 'auto', while 'unsigned' will be. 

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

llvm-svn: 329730
2018-04-10 18:05:24 +00:00
Marc-Andre Laperle 90a937e3e1 [clangd] Use operator<< to prevent printers issues in Gtest
Summary:
It is possible that there will be two different instantiations of
the printer template for a given type and some tests could end up calling the
wrong (default) one. For example, it was seen in CodeCompleteTests.cpp when
printing CompletionItems that it would use the wrong printer because the default
is also instantiated in ClangdTests.cpp.

With this change, objects that were previously printed with a custom Printer now
get printed through the operator<< which is declared alongside the class.
This rule of the thumb should make it less error-prone.

Reviewers: simark, ilya-biryukov, sammccall

Reviewed By: simark, ilya-biryukov, sammccall

Subscribers: bkramer, hokein, sammccall, klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits

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

llvm-svn: 329725
2018-04-10 17:34:46 +00:00
Julie Hockett 8c1ee67c3f [clang-tidy] Adding alias for anon namespaces in header (fuchsia module)
Adding alias to google-build-namespaces to the Fuchsia module (checks
for anonymous namespaces in headers).

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

llvm-svn: 329720
2018-04-10 16:53:51 +00:00
Nico Weber 0da2290958 s/LLVM_ON_WIN32/_WIN32/, clang-tools-extra
LLVM_ON_WIN32 is set exactly with MSVC and MinGW (but not Cygwin) in
HandleLLVMOptions.cmake, which is where _WIN32 defined too.  Just use the
default macro instead of a reinvented one.

See thread "Replacing LLVM_ON_WIN32 with just _WIN32" on llvm-dev and cfe-dev.
No intended behavior change.

llvm-svn: 329695
2018-04-10 13:14:03 +00:00
Michal Gorny 698fdfab75 [cmake] Include LLVMTestingSupport when doing stand-alone build
Explicitly include and build lib/Testing/Support from LLVM sources when
doing a stand-alone build. This is necessary since clangd tests started
to depend on LLVMTestingSupport library which is neither installed
by LLVM, nor built by clang itself.

Since completely separate build of clang-tools-extra is not supported,
this relies on variables set by clang CMakeLists.

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

llvm-svn: 329594
2018-04-09 17:08:14 +00:00
Haojian Wu b0847554b5 [clangd] Bump v0.0.6 for vscode-clangd.
llvm-svn: 329583
2018-04-09 15:37:09 +00:00
Sam McCall 307c4837cc [clang] Use compile-command interpolation to provide commands for header files.
Summary: This uses the inferring wrapper introduced in D45006.

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

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

llvm-svn: 329582
2018-04-09 15:22:08 +00:00
Alexander Kornienko c3ad02e840 [clang-tidy] Return non-zero exit code for clang errors.
Summary:
Updated tests broken by this change.
Fixes https://bugs.llvm.org/show_bug.cgi?id=27628

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: klimek, xazax.hun, cfe-commits

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

llvm-svn: 329579
2018-04-09 15:12:10 +00:00
Haojian Wu e9a5a2f10c [clangd] Allow using customized include path in URI.
Summary:
Calculating the include path from absolute file path does not always
work for all build system, e.g. bazel uses symlink as the build working
directory. The absolute file path from editor and clang is diverged from
each other. We need to address it properly in build sysmtem integration.

This patch worksarounds the issue by providing a hook in URI which allows
clients to provide their customized include path.

Reviewers: sammccall

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

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

llvm-svn: 329578
2018-04-09 15:09:44 +00:00
Marc-Andre Laperle c1d6b5e458 [clangd-vscode] Update VScode dependencies
Summary:
This allows the extension to work with LSP 3.0 and is useful for testing.

Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>

Reviewers: ilya-biryukov

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

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

llvm-svn: 329574
2018-04-09 14:32:12 +00:00
Sam McCall b9d57118fb [clangd] Adapt index interfaces to D45014, and fix the old bugs.
Summary:
Fix bugs:
- don't count occurrences of decls where we don't spell the name
- findDefinitions at MACRO(^X) goes to the definition of MACRO

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

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

llvm-svn: 329571
2018-04-09 14:28:52 +00:00
Philipp Stephani f8ff2ef966 Improve completion experience for headers
Summary: When calling `completing-read', we should provide a default to prevent the behavior described in https://github.com/DarwinAwardWinner/ido-completing-read-plus#why-does-ret-sometimes-not-select-the-first-completion-on-the-list--why-is-there-an-empty-entry-at-the-beginning-of-the-completion-list--what-happened-to-old-style-default-selection.  Also, don't use an assertion to check whether the user selected a header; raise a proper signal instead.

Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

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

llvm-svn: 329566
2018-04-09 13:31:44 +00:00
Chandler Carruth 324edae831 Fix unused variable warning.
llvm-svn: 329550
2018-04-09 07:26:42 +00:00
Zinovy Nis be119ca712 [clang-tidy] Fix compilation for MSVS@PSP4 for ParentVirtualCallCheck.cpp
There's an error for PSP4 platform only: 
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\algorithm(95): 
error C2719: '_Pred': formal parameter with requested alignment of 8 won't be aligned

llvm-svn: 329495
2018-04-07 11:22:01 +00:00
Zinovy Nis a093b160dc [clang-tidy] One more fix compilation for ParentVirtualCallCheck.cpp: find_if predicate
llvm-svn: 329454
2018-04-06 21:00:18 +00:00
Zinovy Nis 7e9745dd4c [clang-tidy] Fix compilation for ParentVirtualCallCheck.cpp
llvm-svn: 329452
2018-04-06 20:39:23 +00:00
Zinovy Nis 95ea1b05fd [clang-tidy] Check if grand-..parent's virtual method was called instead of overridden parent's.
class A {...int virtual foo() {...}...}; 
class B: public A {...int foo() override {...}...}; 
class C: public B {...int foo() override {... A::foo()...}};
                                              ^^^^^^^^ warning: qualified name A::foo refers to a member overridden in subclass; did you mean 'B'? [bugprone-parent-virtual-call] 

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

llvm-svn: 329448
2018-04-06 20:02:50 +00:00
George Burgess IV e0c2c49a15 [clang-tidy] Sort includes; NFC
llvm-svn: 329428
2018-04-06 17:22:36 +00:00
Sam McCall c8de52ed15 [clangd] move comment to the right place. NFC
llvm-svn: 329380
2018-04-06 07:48:21 +00:00
Benjamin Kramer be92ce14e1 [clang-tidy] Remove google-runtime-member-string-references
This is triggering on a pattern that's both too broad (const
std::string& members can be used safely) and too narrow (std::string is
not the only class with this problem). It has a very low true positive
rate, just remove it until we find a better solution for dangling string
references.

llvm-svn: 329292
2018-04-05 14:51:01 +00:00
Alexander Kornienko b1c746ef04 [clang-tidy] Rename -warnings-as-errors tests. NFC.
The tests will be more discoverable with proper names.

llvm-svn: 329182
2018-04-04 12:40:00 +00:00
Sam McCall ba3c02e461 [clangd] synthesize fix message when the diagnostic doesn't provide one.
Summary:
Currently if a fix is attached directly to a diagnostic, we repeat the
diagnostic message as the fix message. From eyeballing the top diagnostics,
it seems describing the textual replacement would be much clearer.

e.g.
error: use of undeclared identifier 'goo'; did you mean 'foo'?
action before: use of undeclared identifier 'goo'; did you mean 'foo'?
action after: change 'goo' to 'foo'

Reviewers: ilya-biryukov

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

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

llvm-svn: 329090
2018-04-03 17:35:57 +00:00
Haojian Wu dc62da4e0b [clang-tidy] Check for sizeof that call functions
Summary:
A common mistake that I have found in our codebase is calling a function to get an integer or enum that represents the type such as:

```
int numBytes = numElements * sizeof(x.GetType());
```

So this extends the `sizeof` check to check for these cases. There is also a `WarnOnSizeOfCall` option so it can be disabled.

Patch by Paul Fultz II!

Reviewers: hokein, alexfh, aaron.ballman, ilya-biryukov

Reviewed By: alexfh

Subscribers: lebedev.ri, xazax.hun, jkorous-apple, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 329073
2018-04-03 15:10:24 +00:00
Simon Dardis a826ca7079 [clangd][cmake] Provide libatomic when there is no native support for 64bit atomics
This addresses a persistent failure on clang-cmake-mips buildbot.

Reviewers: ioeric

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

llvm-svn: 329053
2018-04-03 09:40:07 +00:00
Mike Edwards ac6a6577d9 Revert r328932 as it caused Windows and MacOS bot failures.
http://green.lab.llvm.org/green/job/clang-stage1-configure-RA/43991/

llvm-svn: 328997
2018-04-02 18:02:36 +00:00
Zinovy Nis c16815ca8a [clang-tidy] Define __clang_analyzer__ macro for clang-tidy for compatibility with clang static analyzer
This macro is widely used in many well-known projects, ex. Chromium.
But it's not set for clang-tidy, so for ex. DCHECK in Chromium is not considered as [[no-return]], and a lot of false-positive warnings about nullptr dereferenced are emitted.
This patch fixes the issue by explicitly added macro definition.

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

llvm-svn: 328932
2018-04-01 11:51:57 +00:00
Fangrui Song 943e12e1c5 [clangd] Fix repeated word typo. NFC
llvm-svn: 328819
2018-03-29 20:03:16 +00:00