Commit Graph

3323 Commits

Author SHA1 Message Date
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
Marc-Andre Laperle 20c5e14ae1 [clangd] Mark "Source Hover" as implemented in the docs
Summary: Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>

Reviewers: simark

Reviewed By: simark

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

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

llvm-svn: 328792
2018-03-29 14:49:21 +00:00
Reid Kleckner 93e2228648 Attempt to fix clangd test on Windows by wildcarding drive letters
llvm-svn: 328645
2018-03-27 17:44:12 +00:00
Krasimir Georgiev 20505898cb [clang-move] Fix test failing due to clang-format change
r328621 reverted the removal of empty lines before the closing `}` in
namespaces.

llvm-svn: 328622
2018-03-27 13:39:33 +00:00
Julie Hockett 9345d982d0 [clang-doc] Removing -Wunused-variable warning
Warning was appearing in release with debug info build, this removes it.

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

llvm-svn: 328588
2018-03-26 22:37:31 +00:00
Simon Marchi 9808262ede [clangd] Support incremental document syncing
Summary:
This patch adds support for incremental document syncing, as described
in the LSP spec.  The protocol specifies ranges in terms of Position (a
line and a character), and our drafts are stored as plain strings.  So I
see two things that may not be super efficient for very large files:

- Converting a Position to an offset (the positionToOffset function)
  requires searching for end of lines until we reach the desired line.
- When we update a range, we construct a new string, which implies
  copying the whole document.

However, for the typical size of a C++ document and the frequency of
update (at which a user types), it may not be an issue.  This patch aims
at getting the basic feature in, and we can always improve it later if
we find it's too slow.

Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>

Reviewers: malaperle, ilya-biryukov

Reviewed By: ilya-biryukov

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

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

llvm-svn: 328500
2018-03-26 14:41:40 +00:00
Jonathan Coe 96d81916b0 [clang-tidy] Enable Python 3 support for add_new_check.py
Summary: In Python 3, filters are lazily evaluated and strings are not bytes.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 328418
2018-03-24 10:49:17 +00:00
Jordan Rose 9d0d2ac327 Fix misuse of llvm::YAML in clangd test.
Caught by LLVM r328345!

llvm-svn: 328354
2018-03-23 19:16:07 +00:00
Ilya Biryukov 976b6975e4 [clangd] Remove 'static' from a function inside anonymous ns. NFC
llvm-svn: 328302
2018-03-23 10:39:15 +00:00
Julie Hockett e975a473b7 [clang-doc] Reland "[clang-doc] Setup clang-doc frontend framework"
Fixed windows release build tests.

llvm-svn: 328270
2018-03-22 23:34:46 +00:00
Alexander Kornienko 301faac18b clang-tidy, modularize: return non-zero exit code on errors
When no inputs given, the tools should not only produce the help message, but
also return a non-zero exit code. Fixed tests accordingly.

llvm-svn: 328199
2018-03-22 14:18:20 +00:00
Julie Hockett 2a0373a2db Revert "[clang-doc] Reland "[clang-doc] Setup clang-doc frontend framework""
This reverts commit r328150 until we can fix the test that are failing
on the Windows release build.

llvm-svn: 328172
2018-03-22 02:05:51 +00:00
Julie Hockett 1442a5dd3a [clang-doc] Reland "[clang-doc] Setup clang-doc frontend framework"
Fixing the the failing Windows tests.

llvm-svn: 328150
2018-03-21 21:21:45 +00:00
Jan Korous cd0efec2b4 [clangd][nfc] Correct header name in comment
llvm-svn: 328149
2018-03-21 21:04:10 +00:00
Julie Hockett 6f22226d6c Reland "[lit] Adding config initialization to lit tests in clang-tools-extra"
Adding the config initialization to clang-tools-extra so that tests that
use REQUIRES, UNSUPPORTED, and XFAIL based on platform or target triple
work properly.

llvm-svn: 328131
2018-03-21 18:50:26 +00:00
Julie Hockett 6e79ac5339 [clang-tidy] Marking hicpp-no-assembler-msvc unsupported on Windows
After changes to lit.site.cfg.in, the test is now running (and failing)
on windows, so temporarily marking it unsupported. See PR36855 for more
details.

llvm-svn: 328127
2018-03-21 18:03:41 +00:00
Eugene Zelenko 3f9ef8dfff [clang-tidy] Use :doc: for check links in Release Notes.
Differential revision: https://reviews.llvm.org/D44694

llvm-svn: 328115
2018-03-21 17:06:13 +00:00
Jonas Toth b5c42067c8 [Fix] fix type deduction on ARM and MSVC
llvm-svn: 328108
2018-03-21 15:50:15 +00:00
Jonas Toth bf50a7f880 [clang-tidy] Resubmit hicpp-multiway-paths-covered without breaking test
The original check did break the green buildbot in the sanitizer build.
It took a while to redroduce and understand the issue.

There occured a stackoverflow while parsing the AST. The testcase with
256 case labels was the problem because each case label added another
stackframe. It seemed that the issue occured only in 'RelWithDebInfo' builds
and not in normal sanitizer builds.

To simplify the matchers the recognition for the different kinds of switch
statements has been moved into a seperate function and will not be done with
ASTMatchers. This is an attempt to reduce recursion and stacksize as well.

The new check removed this big testcase. Covering all possible values is still
implemented for bitfields and works there. The same logic on integer types
will lead to the issue.

Running it over LLVM gives the following results:


Differential: https://reviews.llvm.org/D40737
llvm-svn: 328107
2018-03-21 15:34:15 +00:00
Alexander Kornienko 670c6315ac [clang-tidy][modernize-make-unique] Checks c++14 flag before using std::make_unique
Summary: For a c++11 code, the clang-tidy rule "modernize-make-unique" should return immediately, as std::make_unique is not supported.

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

Reviewed By: hokein, aaron.ballman, alexfh

Subscribers: Quuxplusone, xazax.hun, cfe-commits

Tags: #clang-tools-extra

Patch by Frederic Tingaud!

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

llvm-svn: 328101
2018-03-21 14:39:24 +00:00
Simon Marchi 766338ad7f Make positionToOffset return llvm::Expected<size_t>
Summary:

To implement incremental document syncing, we want to verify that the
ranges provided by the front-end are valid.  Currently, positionToOffset
deals with invalid Positions by returning 0 or Code.size(), which are
two valid offsets.  Instead, return an llvm:Expected<size_t> with an
error if the position is invalid.

According to the LSP, if the character value exceeds the number of
characters of the given line, it should default back to the end of the
line.  It makes sense in some contexts to have this behavior, and does
not in other contexts.  The AllowColumnsBeyondLineLength parameter
allows to decide what to do in that case, default back to the end of the
line, or return an error.

Reviewers: ilya-biryukov

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

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

llvm-svn: 328100
2018-03-21 14:36:46 +00:00
Petr Hosek 98c1aefdff Revert "[lit] Adding config initialization to lit tests in clang-tools-extra"
This reverts commit r328060 because a test that was inteded to run on
Windows but never ran before due to the missing config initialization
is now being executed and is failing.

llvm-svn: 328069
2018-03-21 02:28:22 +00:00
Julie Hockett bb059deacb [lit] Adding config initialization to lit tests in clang-tools-extra
Adding the config initialization to clang-tools-extra so that tests that
use REQUIRES, UNSUPPORTED, and XFAIL based on platform or target triple
work properly.

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

llvm-svn: 328060
2018-03-20 23:22:50 +00:00
Douglas Yung 2ecc0d3954 Fixup test to explicitly use -fexceptions since exceptions are disabled by default on the PS4 target.
llvm-svn: 327911
2018-03-19 21:22:58 +00:00
Jan Korous bd5ff79dd0 [clangd] Fix undefined behavior due to misaligned type cast
The current code was casting pointer to a misaligned type which is undefined behavior.
Found by compiling with Undefined Behavior Sanitizer and running tests (check-clang-tools).

llvm-svn: 327902
2018-03-19 20:26:18 +00:00
Jan Korous ee1f4586f6 [clangd][nfc] Give name to a magic constant
llvm-svn: 327901
2018-03-19 20:26:15 +00:00
Haojian Wu 4f3eecdf87 [clang-move] Fix the failing test caused by changes in clang-format.
llvm-svn: 327887
2018-03-19 19:13:03 +00:00
Fangrui Song db937c9e45 [clang-move] Fix move-used-helper-decls.cpp test.
llvm-svn: 327885
2018-03-19 19:05:53 +00:00
Miklos Vajna 10fe9bc79e run-clang-tidy: forward clang-tidy exit status
Exit with a non-zero value in case any of the underlying clang-tidy
invocations exit with a non-zero value.

This is useful in case WarningsAsErrors is enabled for some of the
checks: if any of those checks find something, the exit status now
reflects that.

Also add the ability to use run-clang-tidy.py via lit, and assert that
the exit code is not 0 when modernize-use-auto is triggered
intentionally.

Reviewers: alexfh, aaron.ballman

Reviewed By: aaron.ballman

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

llvm-svn: 327854
2018-03-19 14:43:59 +00:00
Alexander Kornienko fcefdb877c [clang-tidy] New check bugprone-unused-return-value
Summary:
Detects function calls where the return value is unused.

Checked functions can be configured.

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

Reviewed By: alexfh, aaron.ballman

Subscribers: hintonda, JonasToth, Eugene.Zelenko, mgorny, xazax.hun, cfe-commits

Tags: #clang-tools-extra

Patch by Kalle Huttunen!

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

llvm-svn: 327833
2018-03-19 13:02:32 +00:00
Ilya Biryukov 94da7bdde6 [clangd] Handle multiple callbacks from Sema's completion
Summary:
When parser backtracks, we might receive multiple code completion
callbacks.
Previously we had a failing assertion there, now we take first results
and hope they are good enough.

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 327717
2018-03-16 15:23:44 +00:00
Simon Marchi 9569fd51ac Move DraftMgr from ClangdServer to ClangdLSPServer
Summary:
This patch moves the draft manager closer to the edge of Clangd, from
ClangdServer to ClangdLSPServer.  This will make it easier to implement
incremental document sync, by making ClangdServer only deal with
complete documents.

As a result, DraftStore doesn't have to deal with versioning, and thus
its API can be simplified.  It is replaced by a StringMap in
ClangdServer holding a current version number for each file.

Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>

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

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

llvm-svn: 327711
2018-03-16 14:30:42 +00:00
Eric Liu 9a54397f81 [change-namespace] Don't match a function call/ref multiple times.
Summary:
Previously, the matcher matches a function call/ref multiple times, one
for each decl ancestor. This might cause problems. For example, in the following
case, `func()` would be matched once (with namespace context) before using decl is
seen and once after using decl is seeing, which would result in different conflicting
replacements as the first match would replace `func` with "ns::func" as it doesn't
know about the using decl.

```
namespace x {
namespace {
using ::ns::func;
void f() { func(); }
}
}
```

Switching from `hasDescendant` matching to `hasAncestor` matching solves the
problem.

Reviewers: hokein

Subscribers: klimek, cfe-commits

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

llvm-svn: 327629
2018-03-15 14:45:02 +00:00
Alexander Kornienko 67112853c2 [clang-tidy] rename_check.py misc-unused-raii bugprone-unused-raii --check_class_name=UnusedRAIICheck
llvm-svn: 327610
2018-03-15 08:27:42 +00:00
Alexander Kornienko b9694abc29 Fixed filename in a comment. NFC
llvm-svn: 327609
2018-03-15 08:26:58 +00:00
Alexander Kornienko 68fb65f413 [clang-tidy] rename_check.py misc-sizeof-container bugprone-sizeof-container
llvm-svn: 327608
2018-03-15 08:26:47 +00:00
Alexander Kornienko 3273888536 [clang-tidy] rename_check.py misc-sizeof-expression bugprone-sizeof-expression
llvm-svn: 327607
2018-03-15 08:26:19 +00:00
Alexander Kornienko 7ff6076129 [clang-tidy] rename_check.py {misc,bugprone}-macro-parentheses
llvm-svn: 327606
2018-03-15 08:25:39 +00:00
Julie Hockett b6f7c934ac [clang-tidy] Add Zircon module to clang-tidy
Adding a Zircon module to clang-tidy for checks specific to the Zircon
kernel, and adding a checker to fuchsia-zx (for zircon) to flag instances
where specific objects are temporarily created.

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

llvm-svn: 327590
2018-03-14 23:47:50 +00:00
Simon Marchi 5a48cf86f1 [clangd] Use Contents from inputs in codeComplete and signatureHelp
Summary:
ClangdServer::{codeComplete,signatureHelp} both use the Contents from
the draft manager.  Since we want to move the draft manager from
ClangdServer to ClangdLSPServer, this patch changes those methods to
find the file contents from InputsAndPreamble, which contains the source
passed in previously.

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

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

llvm-svn: 327550
2018-03-14 18:31:48 +00:00
Ilya Biryukov fe3aae2a76 [clangd] Fix indentation in the comment. NFC
llvm-svn: 327539
2018-03-14 17:49:19 +00:00
Ilya Biryukov f1f3d57eb2 [clangd] Don't expose vfs in TUScheduler::runWithPreamble.
Summary:
It was previously an easy way to concurrently access a mutable vfs,
which is a recipe for disaster.

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 327537
2018-03-14 17:46:52 +00:00
Ilya Biryukov bec5df2d05 [clangd] Remove forceReparse, add a flag to addDocument instead
Summary: To make the removal of DraftMgr from ClangdServer easier (D44408).

Reviewers: sammccall, simark

Reviewed By: sammccall, simark

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

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

llvm-svn: 327532
2018-03-14 17:08:41 +00:00
Eric Liu 9ec459ff6b [clangd] Add an interface that finds symbol by SymbolID in SymbolIndex.
Summary:
Potential use case: argument go-to-definition result with symbol
information (e.g. function definition in cc file) that might not be in the AST.

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 327487
2018-03-14 09:48:05 +00:00
Julie Hockett c12d753fad [clang-tidy] Fixing incorrect comment
llvm-svn: 327452
2018-03-13 21:24:08 +00:00
Haojian Wu 0259e7d872 [clangd] Use the macro name range as the definition range.
Summary: This also aligns with the behavior of declarations.

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 327401
2018-03-13 14:31:31 +00:00
Haojian Wu 2658cb65bd [clangd] Fix irrelevant declaratations in goto definition (on macros).
Summary:
DeclrationAndMacrosFinder will find some declarations (not macro!) that are
referened inside the macro somehow, isSearchedLocation() is not sufficient, we
don't know whether the searched source location is macro or not.

Reviewers: ilya-biryukov

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

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

llvm-svn: 327387
2018-03-13 12:30:59 +00:00
Haojian Wu 797f32e084 [clangd] Remove extra ";", NFC.
llvm-svn: 327386
2018-03-13 12:26:28 +00:00
Julie Hockett 729d9f868b Revert "Reland "[clang-doc] Setup clang-doc frontend framework""
This reverts commit r327295 since it was causing the Windows bots to
fail.

llvm-svn: 327346
2018-03-12 23:23:24 +00:00
Sam McCall a7bb0cc09e [clangd] Remove Tagged and some related APIs from ClangdServer.
Context can do what Tagged was intended to support (snapshot filesystems),
and less intrusively.
getTaggedFileSystem() no longer needs a filename.

Cleanups while here:
 - code-complete now returns errors as Expected, like other functions
 - added an alias Callback<T> for the usual callback function type

llvm-svn: 327344
2018-03-12 23:22:35 +00:00
Julie Hockett 7147f32ec5 [docs] Adding clang-doc to CTE toctree to fix docs build error
llvm-svn: 327333
2018-03-12 21:39:01 +00:00
Julie Hockett 93be22f418 Reland "[clang-doc] Setup clang-doc frontend framework"
There was a missing newline in the docs, and a static_assert that needed
to be a normal assert.

llvm-svn: 327295
2018-03-12 17:05:14 +00:00
Haojian Wu 144b0c8036 [clangd] Fix diagnostic errors in the test code, NFC.
Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

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

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

llvm-svn: 327293
2018-03-12 16:49:24 +00:00
Ilya Biryukov 71028b83e7 [clangd] Revamp handling of diagnostics.
Summary:
The new implementation attaches notes to diagnostic message and shows
the original diagnostics in the message of the note.

Reviewers: hokein, ioeric, sammccall

Reviewed By: sammccall

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

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

llvm-svn: 327282
2018-03-12 15:28:22 +00:00
Sam McCall 93f99bf31f [clangd] Collect the number of files referencing a symbol in the static index.
Summary:
This is an important ranking signal.
It's off for the dynamic index for now. Correspondingly, tell the index
infrastructure only to report declarations for the dynamic index.

Reviewers: ioeric, hokein

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

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

llvm-svn: 327275
2018-03-12 14:49:09 +00:00
Julie Hockett c3716ca219 [clang-tidy] Update run-clang-tidy.py with config arg
Updating the run-clang-tidy.py script to allow specification of the
config argument to the clang-tidy invocation.

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

llvm-svn: 327186
2018-03-09 23:26:56 +00:00
Matt Morehouse afacada94b [clangd-fuzzer] Update ClangdLSPServer constructor call.
Build was broken by r326719.

llvm-svn: 327184
2018-03-09 23:02:22 +00:00
Haojian Wu 06eeb5c00f [clangd] Fix failing lit test.
This test is missed in r327129.

llvm-svn: 327131
2018-03-09 14:16:46 +00:00
Eric Liu ff56b9c7a9 [clangd-vscode] Add package-lock.json to .gitignore
llvm-svn: 327130
2018-03-09 14:06:43 +00:00
Haojian Wu 5f10026258 [clangd] Use identifier range as the definition range.
Summary: This also matches the range in symbol index.

Reviewers: sammccall

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

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

llvm-svn: 327129
2018-03-09 14:00:34 +00:00
Sam McCall 824913bdb7 [clangd] Don't index template specializations.
Summary:
These have different USRs than the underlying entity, but are not typically
interesting in their own right and can be numerous (e.g. generated traits).

Reviewers: ioeric

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

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

llvm-svn: 327127
2018-03-09 13:25:29 +00:00
Sam McCall 893cbc25fb [clang-tidy] fix header guard
llvm-svn: 327115
2018-03-09 11:47:37 +00:00
Haojian Wu 40571b7c1c [clang-tidy] Add check: replace string::find(...) == 0 with absl::StartsWith
Patch by Niko Weh!

Reviewers: hokein

Subscribers: klimek, cfe-commits, ioeric, ilya-biryukov, ahedberg

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

llvm-svn: 327111
2018-03-09 10:47:14 +00:00
Julie Hockett c8922c16fb Revert "[clang-doc] Setup clang-doc frontend framework"
This reverts commit r327102, since it was breaking the linux-abi-test on
x86.

llvm-svn: 327103
2018-03-09 03:47:18 +00:00
Julie Hockett 671812462a [clang-doc] Setup clang-doc frontend framework
Setting up the mapper part of the frontend framework for a clang-doc
tool. It creates a series of relevant matchers for declarations, and
uses the ToolExecutor to traverse the AST and extract the matching
declarations and comments. The mapper serializes the extracted
information to individual records for reducing and eventually doc
generation.

For a more detailed overview of the tool, see the design document on the
mailing list: http://lists.llvm.org/pipermail/cfe-dev/2017-December/056203.html

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

llvm-svn: 327102
2018-03-09 03:16:39 +00:00
Haojian Wu c6a64d9239 [clangd] Early return for #include goto definition.
Summary: This would save cost of walking over the AST, NFC.

Reviewers: ilya-biryukov

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

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

llvm-svn: 327023
2018-03-08 16:28:12 +00:00
Eric Liu 0df75fec3f [clangd] Bump vscode extension version to 0.0.5
llvm-svn: 327019
2018-03-08 16:14:11 +00:00
Eric Liu 2e1980bde1 [clangd:vscode] Resolve symlinks for file paths from clangd.
Summary:
For features like go-to-definition, clangd can point clients to symlink paths
(e.g. in bazel execroot) which might not be desired if the symlink points to a
file in the workspace. Clangd might not be able to build the file, and users
might prefer to edit the file on the real path.

This change converts file paths from clangd to real path (e.g. resolving symlinks).
Long term, we might want to the symlink handling logic to clangd where clangd
can better decide whether symlinks should be resolved according to e.g. compile
commands.

Reviewers: sammccall

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

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

llvm-svn: 327009
2018-03-08 15:28:42 +00:00
Eugene Zelenko f62e1ccbeb [Documentation] Fix Clang-tidy checks list broken in r326909.
llvm-svn: 326954
2018-03-07 22:30:50 +00:00
Simon Marchi 6e8eb9d21c [clangd] Remove unused field in HandlerRegisterer
Summary: Tested by rebuilding.

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

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

llvm-svn: 326947
2018-03-07 21:47:25 +00:00
Yan Zhang c7faee73cc do not register matcher for objc-only checks when analyzing non-objc sources to save resources
Summary: I did not put lang opt check in AvoidSpinlockCheck since OSSpinLock is not objc specific. We won't want to skip it when analyzing some C++ target used by other ObjC sources.

Reviewers: hokein, benhamilton

Reviewed By: benhamilton

Subscribers: klimek, cfe-commits

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

llvm-svn: 326928
2018-03-07 18:59:25 +00:00
Fangrui Song c0e768df90 [clang-tidy] Add "portability" module and rename readability-simd-intrinsics to portability-simd-intrinsics
Reviewers: alexfh

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

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

llvm-svn: 326909
2018-03-07 16:57:42 +00:00
Ilya Biryukov 53d6d9369b [clangd] Don't end completion item labels with '::'
llvm-svn: 326809
2018-03-06 16:45:21 +00:00
Haojian Wu 0dc8fd7460 [clang-tidy] Fix one corner case in make-unique check.
Summary:
Previously, we tried to cover all "std::initializer_list" implicit conversion
cases in the code, but there are some corner cases that not covered (see
newly-added test in the patch).

Sipping all implicit AST nodes is a better way to filter out all these cases.

Reviewers: ilya-biryukov

Subscribers: klimek, xazax.hun, cfe-commits

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

llvm-svn: 326799
2018-03-06 14:34:35 +00:00
Sam McCall 37c4d6d725 [clangd] Address missed comments from D44003
llvm-svn: 326798
2018-03-06 14:30:07 +00:00
Haojian Wu 33caf89970 [clangd] Fix -Wpedantic warning, NFC.
llvm-svn: 326778
2018-03-06 12:56:18 +00:00
Eric Liu e3395b9016 [clangd] Sort includes when formatting code or inserting new includes.
Reviewers: hokein, ilya-biryukov

Subscribers: klimek, jkorous-apple, cfe-commits

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

llvm-svn: 326773
2018-03-06 10:42:50 +00:00
Sam McCall 77a719cb9e [clangd] Fix unintentionally loose fuzzy matching, and the tests masking it.
Summary:
The intent was that [ar] doesn't match "FooBar"; the first character must match
a Head character (hard requirement, not just a low score).
This matches VSCode, and was "tested" but the tests were defective.

The tests expected matches("FooBar") to fail for lack of a match. But instead
it fails because the string should be annotated - matches("FooB[ar]").
This patch makes matches("FooBar") ignore annotations, as was intended.

Fixing the code to reject weak matches for the first char causes problems:
-  [bre] no longer matches "HTMLBRElement".
   We allow matching against an uppercase char even if we don't think it's head.
   Only do this if there's at least one lowercase, to avoid triggering on MACROS
-  [print] no longer matches "sprintf".
   This is hard to fix without false positives (e.g. [int] vs "sprintf"])
   This patch leaves this case broken. A future patch will add a dictionary
   providing custom segmentation to common names from the standard library.

Fixed a couple of index tests that indirectly relied on broken fuzzy matching.
Added const in a couple of missing places for consistency with new code.

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

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

llvm-svn: 326721
2018-03-05 17:34:33 +00:00
Sam McCall 7363a2f270 [clangd] Extract ClangdServer::Options struct.
Summary:
This subsumes most of the params to ClangdServer and ClangdLSPServer.
Adjacent changes:
 - tests use a consistent set of options, except when testing specific options
 - tests that previously used synchronous mode for convenience no longer do
 - added a runAddDocument helper to SyncAPIs to mitigate the extra code
 - rearranged main a bit to follow the structure of the options

Reviewers: ilya-biryukov

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

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

llvm-svn: 326719
2018-03-05 17:28:54 +00:00
Aaron Ballman ada5234b6e Adds a clang-tidy test for a failing assertion in the misc-misplaced-const check.
The test case previously triggered an assertion in the AST matchers because the QualType being matched is invalid. That is no longer the case after r326604.

llvm-svn: 326605
2018-03-02 19:14:34 +00:00
Ilya Biryukov ddedde9aa0 [clangd] Use higher timoout values in TUSchedulerTest::Debounce
Should unbreak windows buildbots.

llvm-svn: 326598
2018-03-02 18:23:41 +00:00
Ilya Biryukov ddf6a33306 [clang] Fix use-after-free on code completion
Summary:
Found by asan. Fiddling with code completion AST after
FrontendAction::Exceute can lead to errors.
Calling the callback in ProcessCodeCompleteResults to make sure we
don't access uninitialized state.

This particular issue comes from the fact that Sema::TUScope is
deleted when destructor of ~Parser runs, but still present in
Sema::TUScope and accessed when building completion items.

I'm still struggling to come up with a small repro. The relevant
stackframes reported by asan are:
ERROR: AddressSanitizer: heap-use-after-free on address
READ of size 8 at 0x61400020d090 thread T175
    #0 0x5632dff7821b in llvm::SmallPtrSetImplBase::isSmall() const include/llvm/ADT/SmallPtrSet.h:195:33
    #1 0x5632e0335901 in llvm::SmallPtrSetImplBase::insert_imp(void const*) include/llvm/ADT/SmallPtrSet.h:127:9
    #2 0x5632e067347d in llvm::SmallPtrSetImpl<clang::Decl*>::insert(clang::Decl*) include/llvm/ADT/SmallPtrSet.h:372:14
    #3 0x5632e065df80 in clang::Scope::AddDecl(clang::Decl*) tools/clang/include/clang/Sema/Scope.h:287:18
    #4 0x5632e0623eea in clang::ASTReader::pushExternalDeclIntoScope(clang::NamedDecl*, clang::DeclarationName) clang/lib/Serialization/ASTReader.cpp
    #5 0x5632e062ce74 in clang::ASTReader::finishPendingActions() tools/clang/lib/Serialization/ASTReader.cpp:9164:9
    ....
    #30 0x5632e02009c4 in clang::index::generateUSRForDecl(clang::Decl const*, llvm::SmallVectorImpl<char>&) tools/clang/lib/Index/USRGeneration.cpp:1037:6
    #31 0x5632dff73eab in clang::clangd::(anonymous namespace)::getSymbolID(clang::CodeCompletionResult const&) tools/clang/tools/extra/clangd/CodeComplete.cpp:326:20
    #32 0x5632dff6fe91 in clang::clangd::CodeCompleteFlow::mergeResults(std::vector<clang::CodeCompletionResult, std::allocator<clang::CodeCompletionResult> > const&, clang::clangd::SymbolSlab const&)::'lambda'(clang::CodeCompletionResult const&)::operator()(clang::CodeCompletionResult const&) tools/clang/tools/extra/clangd/CodeComplete.cpp:938:24
    #33 0x5632dff6e426 in clang::clangd::CodeCompleteFlow::mergeResults(std::vector<clang::CodeCompletionResult, std::allocator<clang::CodeCompletionResult> > const&, clang::clangd::SymbolSlab const&) third_party/llvm/llvm/tools/clang/tools/extra/clangd/CodeComplete.cpp:949:38
    #34 0x5632dff7a34d in clang::clangd::CodeCompleteFlow::runWithSema() llvm/tools/clang/tools/extra/clangd/CodeComplete.cpp:894:16
    #35 0x5632dff6df6a in clang::clangd::CodeCompleteFlow::run(clang::clangd::(anonymous namespace)::SemaCompleteInput const&) &&::'lambda'()::operator()() const third_party/llvm/llvm/tools/clang/tools/extra/clangd/CodeComplete.cpp:858:35
    #36 0x5632dff6cd42 in clang::clangd::(anonymous namespace)::semaCodeComplete(std::unique_ptr<clang::CodeCompleteConsumer, std::default_delete<clang::CodeCompleteConsumer> >, clang::CodeCompleteOptions const&, clang::clangd::(anonymous namespace)::SemaCompleteInput const&, llvm::function_ref<void ()>) tools/clang/tools/extra/clangd/CodeComplete.cpp:735:5

0x61400020d090 is located 80 bytes inside of 432-byte region [0x61400020d040,0x61400020d1f0)
freed by thread T175  here:
    #0 0x5632df74e115 in operator delete(void*, unsigned long) projects/compiler-rt/lib/asan/asan_new_delete.cc:161:3
    #1 0x5632e0b06973 in clang::Parser::~Parser() tools/clang/lib/Parse/Parser.cpp:410:3
    #2 0x5632e0b06ddd in clang::Parser::~Parser() clang/lib/Parse/Parser.cpp:408:19
    #3 0x5632e0b03286 in std::unique_ptr<clang::Parser, std::default_delete<clang::Parser> >::~unique_ptr() .../bits/unique_ptr.h:236:4
    #4 0x5632e0b021c4 in clang::ParseAST(clang::Sema&, bool, bool) tools/clang/lib/Parse/ParseAST.cpp:182:1
    #5 0x5632e0726544 in clang::FrontendAction::Execute() tools/clang/lib/Frontend/FrontendAction.cpp:904:8
    #6 0x5632dff6cd05 in clang::clangd::(anonymous namespace)::semaCodeComplete(std::unique_ptr<clang::CodeCompleteConsumer, std::default_delete<clang::CodeCompleteConsumer> >, clang::CodeCompleteOptions const&, clang::clangd::(anonymous namespace)::SemaCompleteInput const&, llvm::function_ref<void ()>) tools/clang/tools/extra/clangd/CodeComplete.cpp:728:15

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 326569
2018-03-02 12:28:27 +00:00
Eric Liu fdaeb9bfb2 [clangd:vscode] Bump clangd-vscode version to 0.0.4.
llvm-svn: 326548
2018-03-02 09:26:17 +00:00
Eric Liu 5e4dbb4f0a [clangd:vscode] check empty/null string correctly.
llvm-svn: 326547
2018-03-02 09:21:41 +00:00
Sam McCall d1e0deb271 [clangd] Debounce streams of updates.
Summary:
Don't actually start building ASTs for new revisions until either:
- 500ms have passed since the last revision, or
- we actually need the revision for something (or to unblock the queue)

In practice, this avoids the "first keystroke results in diagnostics" problem.
This is kind of awkward to test, and the test is pretty bad.
It can be observed nicely by capturing a trace, though.

Reviewers: hokein, ilya-biryukov

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

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

llvm-svn: 326546
2018-03-02 08:56:37 +00:00
Eric Liu 39195e64e2 [clangd] Make symbol name a required parameter for CanonicalIncludes::mapHeader
llvm-svn: 326458
2018-03-01 18:30:48 +00:00
Eric Liu b96363da76 [clangd] Support include canonicalization in symbol leve.
Summary:
Symbols with different canonical includes might be defined in the same header
(e.g. symbols defined in STL <iosfwd>). This patch adds support for mapping from
qualified symbol names to canonical headers and special mapping for symbols in <iosfwd>

Reviewers: sammccall, hokein

Reviewed By: sammccall

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

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

llvm-svn: 326456
2018-03-01 18:06:40 +00:00
Eric Liu 621cef600b [clangd] Forward all environment variables along with CLANGD_TRACE to clangd.
llvm-svn: 326452
2018-03-01 17:42:27 +00:00
Alexander Kornienko eb9d944419 [clang-tidy] Another batch of checks to rename from misc- to bugprone-.
Summary:
clang-tidy/rename_check.py {misc,bugprone}-suspicious-semicolon
clang-tidy/rename_check.py {misc,bugprone}-suspicious-string-compare
clang-tidy/rename_check.py {misc,bugprone}-swapped-arguments
clang-tidy/rename_check.py {misc,bugprone}-undelegated-constructor --check_class_name UndelegatedConstructor

Reviewers: hokein, sammccall, aaron.ballman

Subscribers: klimek, mgorny, xazax.hun, cfe-commits

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

llvm-svn: 326386
2018-02-28 23:47:15 +00:00
Alexander Kornienko cb6d320345 Rename more checks from misc- to bugprone-.
Summary:
clang-tidy/rename_check.py {misc,bugprone}-string-integer-assignment
clang-tidy/rename_check.py {misc,bugprone}-string-literal-with-embedded-nul
clang-tidy/rename_check.py {misc,bugprone}-suspicious-enum-usage
clang-tidy/rename_check.py {misc,bugprone}-suspicious-missing-comma

Reviewers: hokein, sammccall, aaron.ballman

Subscribers: klimek, cfe-commits, mgorny

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

llvm-svn: 326384
2018-02-28 23:30:29 +00:00
Eric Liu 771daeda32 [clangd] Try to fix failures on clang-x64-ninja-win7 build bot.
llvm-svn: 326365
2018-02-28 20:31:00 +00:00
Eugene Zelenko 3fd8901928 [Documentation] Split Clang-tidy changes in Release Notes into sections: new checks, new aliases, renamed checks; sort all of them alphabetically. Enforce 80 characters line length limit. Highlight C++ keywords.
llvm-svn: 326354
2018-02-28 19:15:49 +00:00
Alexander Kornienko a1a2933634 Rename a few checks from misc- to bugprone-.
Summary:
rename_check.py {misc,bugprone}-forwarding-reference-overload
rename_check.py {misc,bugprone}-macro-repeated-side-effects
rename_check.py {misc,bugprone}-lambda-function-name
rename_check.py {misc,bugprone}-misplaced-widening-cast

Reviewers: hokein, sammccall, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: klimek, cfe-commits, mgorny

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

llvm-svn: 326327
2018-02-28 14:47:20 +00:00
Eric Liu 06d4181140 [clangd] A few more fixes for STL header mapping.
llvm-svn: 326325
2018-02-28 14:02:18 +00:00
Alexander Kornienko 9ac01b074b [clang-tidy] Fix 'add_new_check.py --udpate-docs'
llvm-svn: 326321
2018-02-28 12:21:38 +00:00
Alexander Kornienko a94a4308e1 [clang-tidy] Add a test for readability-implicit-bool-conversion with bitfields.
llvm-svn: 326314
2018-02-28 10:30:25 +00:00
Eric Liu cf8601b009 [clangd] Prefer the definition of a TagDecl (e.g. class) as CanonicalDeclaration.
Summary:
Currently, we pick the first declaration of a symbol in a TU, which is considered
canonical in the clangIndex, as the canonical declaration in clangd. This causes
forward declarations that might appear in a random header to be used as a
canonical declaration, which is not desirable for features like go-to-declaration
or include insertion.

For example, for class X, we would consider the forward declaration in fwd.h to
be the canonical declaration, while the preferred canonical declaration should
be the actual definition in x.h.
```
// fwd.h
class X;  // forward decl

// x.h
class X {};
```

This patch fixes the issue by making symbol collector favor the actual definition of
a TagDecl (i.e. class/struct/enum/union) found in a header file over the first seen
declarations in a TU. Other symbol types like functions are not handled because
using the first seen declarations as canonical declarations is usually a good
heuristic for them.

Reviewers: sammccall

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

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

llvm-svn: 326313
2018-02-28 09:33:15 +00:00
Eric Liu 212e67619a [clangd] A few minor fixes for STL internal header mapping.
llvm-svn: 326310
2018-02-28 08:56:11 +00:00
Yan Zhang ee6303921b add UUID to the acronyms list of objc property name checks
Reviewers: benhamilton, hokein

Reviewed By: benhamilton

Subscribers: klimek, cfe-commits

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

llvm-svn: 326222
2018-02-27 18:35:53 +00:00
Sam McCall db3ea4c0d9 [clangd] Remove codecomplete override content API. Long live addDocument!
llvm-svn: 326211
2018-02-27 17:15:50 +00:00
Roman Lebedev 12b40745ab Revert "[Tooling] [1/1] Refactor FrontendActionFactory::create() to return std::unique_ptr<>"
This reverts commit rL326202

This broke gcc4.8 builds, compiler just segfaults:
http://lab.llvm.org:8011/builders/clang-atom-d525-fedora-rel/builds/14909
http://lab.llvm.org:8011/builders/clang-x86_64-linux-abi-test/builds/22673

llvm-svn: 326203
2018-02-27 15:54:41 +00:00
Roman Lebedev 6b56a11961 [Tooling] [1/1] Refactor FrontendActionFactory::create() to return std::unique_ptr<>
Summary:
I'm not sure whether there are any principal reasons why it returns raw owning pointer,
or it is just a old code that was not updated post-C++11.

I'm not too sure what testing i should do, because `check-all` is not error clean here for some reason,
but it does not //appear// asif those failures are related to these changes.

This is Clang-tools-extra part.
Clang part is D43779.

Reviewers: klimek, bkramer, alexfh, pcc

Reviewed By: alexfh

Subscribers: ioeric, jkorous-apple, cfe-commits

Tags: #clang, #clang-tools-extra

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

llvm-svn: 326202
2018-02-27 15:19:28 +00:00
David Zarzycki 6daad9da6d Fix for LLVM r326109
llvm-svn: 326118
2018-02-26 20:21:30 +00:00
Eric Liu 6c8e858551 [clangd] don't insert new includes if either original header or canonical header is already included.
Summary:
Changes:
o Store both the original header and the canonical header in LSP command.
o Also check that both original and canonical headers are not already included
by comparing both resolved header path and written literal includes.

This addresses the use case where private IWYU pragma is defined in a private
header while it would still be preferrable to include the private header, in the
internal implementation file. If we have seen that the priviate header is already
included, we don't try to insert the canonical include.

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 326070
2018-02-26 08:32:13 +00:00
Kirill Bobyrev bcaf38051c [clangd] Address FIXME and fix comment
* Address a FIXME by warning the user that both -run-synchronously and -j X are
  passed.
* Fix a comment to suppress clang-tidy warning by passing the correct argument
  name.

Reviewers: ioeric

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

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

llvm-svn: 326051
2018-02-25 07:21:16 +00:00
Yan Zhang 2d83647007 [clang-tidy/google] Improve the Objective-C global variable declaration check 🔧
Summary:
The current Objective-C global variable declaration check restricts naming that is permitted by the Google Objective-C style guide.

The Objective-C style guide states the following:
"Global and file scope constants should have an appropriate prefix. [...] Constants may use a lowercase k prefix when appropriate"
http://google.github.io/styleguide/objcguide#constants

This change fixes the check to allow two or more capital letters as an appropriate prefix. This change intentionally avoids making a decision regarding whether to flag constants that use a two letter prefix (two letter prefixes are reserved by Apple¹ but many projects seem to violate this guideline).

This change eliminates an important category of false positives (constants prefixed with '[A-Z]{2,}') at the cost of introducing a less important category of false negatives (constants prefixed with only '[A-Z]'). The false positives are observed in standard recommended code while the false negatives occur in non-standard unrecommended code. The number of eliminated false positives is expected to be significantly larger than the number of exposed false negatives.

❧

(1)
"Two-letter prefixes like these are reserved by Apple for use in framework classes."
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Conventions/Conventions.html

Reviewers: aaron.ballman, Wizard, hokein, benhamilton

Reviewed By: aaron.ballman, Wizard

Subscribers: aaron.ballman, cfe-commits

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

llvm-svn: 326046
2018-02-25 04:11:26 +00:00
Sam McCall 091557d2a8 [clangd] BindWithForward -> Bind. NFC
llvm-svn: 325868
2018-02-23 07:54:17 +00:00
Eric Liu 51fed18342 [clangd] Extend textDocument/didChange to specify whether diagnostics should be generated.
Summary:
This would allow us to disable diagnostics when didChange is called but
diagnostics are not wanted (e.g. code completion).

Reviewers: sammccall

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

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

llvm-svn: 325813
2018-02-22 18:40:39 +00:00
Simon Pilgrim cadaf755f3 Fix "not all control paths return a value" MSVC warning. NFCI.
llvm-svn: 325802
2018-02-22 16:12:27 +00:00
Sam McCall b1ac64927f [clangd] fix test use-after-free from r325774
llvm-svn: 325801
2018-02-22 15:33:33 +00:00
Simon Marchi 5178f924c4 [clangd] DidChangeConfiguration Notification
Summary:

Implementation of DidChangeConfiguration notification handling in
clangd.  This currently only supports changing one setting: the path of
the compilation database to be used for the current project.   In other
words, it is no longer necessary to restart clangd with a different
command line argument in order to change the compilation database.

Reviewers: malaperle, krasimir, bkramer, ilya-biryukov

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

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

Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
Signed-off-by: William Enright <william.enright@polymtl.ca>
llvm-svn: 325784
2018-02-22 14:00:39 +00:00
Haojian Wu b603a5e0e3 [clangd] Correct setting ignoreWarnings in CodeCompletion.
Summary:
We should set the flag before creating ComplierInstance -- when
CopmilerInstance gets initialized, it also initializes the DiagnosticsEngine
using the DiagnosticOptions.

This was hidden deeply -- as clang suppresses all diagnostics when we
hit the code-completion (but internally it does do unnecessary analysis stuff).

As a bonus point, this fix will optmize the completion speed -- clang won't do
any analysis (e.g. -Wunreachable-code, -Wthread-safety-analysisi) at all internally.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

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

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

llvm-svn: 325779
2018-02-22 13:35:01 +00:00
Sam McCall 568e17f1e6 [clangd] Allow embedders some control over when diagnostics are generated.
Summary:
Through the C++ API, we support for a given snapshot version:
 - Yes: make sure we generate diagnostics for exactly this version
 - Auto: generate eventually-consistent diagnostics for at least this version
 - No: don't generate diagnostics for this version
Eventually auto should be debounced for better UX.

Through LSP, we force diagnostics for initial load (bypassing future debouncing)
and all updates follow the "auto" policy.

This is complicated to implement under the CancellationFlag design, so
rewrote that part to just inspect the queue instead.

It turns out we never pass None to the diagnostics callback, so remove Optional
from the signature. The questionable behavior of not invoking the callback at
all if CppFile::rebuild fails is not changed.

Reviewers: ilya-biryukov

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

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

llvm-svn: 325774
2018-02-22 13:11:12 +00:00
Eric Liu 02ce01f1e8 [clangd] Not collect include headers for dynamic index for now.
Summary:
The new behaviors introduced by this patch:
o When include collection is enabled, we always set IncludeHeader field in Symbol
even if it's the same as FileURI in decl.
o Disable include collection in FileIndex which is currently only used to build
dynamic index. We should revisit when we actually want to use FileIndex to global
index.
o Code-completion only uses IncludeHeader to insert headers but not FileURI in
CanonicalDeclaration. This ensures that inserted headers are always canonicalized.
Note that include insertion can still be triggered for symbols that are already
included if they are merged from dynamic index and static index, but we would
only use includes that are already canonicalized (e.g. from static index).

Reason for change:
Collecting header includes in dynamic index enables inserting includes for headers
that are not indexed but opened in the editor. Comparing to inserting includes for
symbols in global/static index, this is nice-to-have but would probably require
non-trivial amount of work to get right. For example:
o Currently it's not easy to fully support CanonicalIncludes in dynamic index, given the way
we run dynamic index.
o It's also harder to reason about the correctness of include canonicalization for dynamic index
(i.e. symbols in the current file/TU) than static index where symbols are collected
offline and sanity check is possible before shipping to production.
o We have less control/flexibility over symbol info in the dynamic index
(e.g. URIs, path normalization), which could be used to help make decision when inserting includes.

As header collection (especially canonicalization) is relatively new, and enabling
it for dynamic index would immediately affect current users with only dynamic
index support, I propose we disable it for dynamic index for now to avoid
compromising other hot features like code completion and only support it for
static index where include insertion would likely to bring more value.

Reviewers: ilya-biryukov, sammccall, hokein

Subscribers: klimek, jkorous-apple, cfe-commits

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

llvm-svn: 325764
2018-02-22 10:14:05 +00:00
Eric Liu 352f92c8d6 [clangd] Update canonical header mapping for STL
llvm-svn: 325694
2018-02-21 16:17:25 +00:00