Commit Graph

2708 Commits

Author SHA1 Message Date
Eric Liu b0b8f03874 Use ToolExecutor framework in the sample tool-template.
llvm-svn: 317333
2017-11-03 16:03:56 +00:00
Marc-Andre Laperle e7ec16aaa6 [clangd] Handle clangd.applyFix server-side
Summary:
When the user selects a fix-it (or any code action with commands), it is
possible to let the client forward the selected command to the server.
When the clangd.applyFix command is handled on the server, it can send a
workspace/applyEdit request to the client. This has the advantage that
the client doesn't explicitly have to know how to handle
clangd.applyFix. Therefore, the code to handle clangd.applyFix in the VS
Code extension (and any other Clangd client) is not required anymore.

Reviewers: ilya-biryukov, sammccall, Nebiroth, hokein

Reviewed By: hokein

Subscribers: ioeric, hokein, rwols, puremourning, bkramer, ilya-biryukov

Tags: #clang-tools-extra

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

llvm-svn: 317322
2017-11-03 13:39:15 +00:00
Ben Hamilton 82b077db3a Update release notes (check SVN commit-after-approval access)
Summary:
I was just granted commit-after-approval access to SVN,
and @clattner recommended I try a test commit.

So, this tweaks the release notes as a test.

Reviewers: hokein, alexfh

Reviewed By: hokein

Subscribers: Wizard

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

llvm-svn: 317261
2017-11-02 20:00:17 +00:00
Sam McCall 32995b3056 Fix clangd test on platforms where get_thread_name does nothing.
llvm-svn: 317194
2017-11-02 09:48:55 +00:00
Sam McCall 8567cb3720 Performance tracing facility for clangd.
Summary:
This lets you visualize clangd's activity on different threads over time,
and understand critical paths of requests and object lifetimes.
The data produced can be visualized in Chrome (at chrome://tracing), or
in a standalone copy of catapult (http://github.com/catapult-project/catapult)

This patch consists of:
 - a command line flag "-trace" that causes clangd to emit JSON trace data
 - an API (in Trace.h) allowing clangd code to easily add events to the stream
 - several initial uses of this API to capture JSON-RPC requests, builds, logs

Example result: https://photos.app.goo.gl/12L9swaz5REGQ1rm1

Caveats:
 - JSON serialization is ad-hoc (isn't it everywhere?) so the API is
   limited to naming events rather than attaching arbitrary metadata.
   I'd like to fix this (I think we could use a JSON-object abstraction).
 - The recording is very naive: events are written immediately by
   locking a mutex. Contention on the mutex might disturb performance.
 - For now it just traces instants or spans on the current thread.
   There are other things that make sense to show (cross-thread flows,
   non-thread resources such as ASTs). But we have to start somewhere.

Reviewers: ioeric, ilya-biryukov

Subscribers: cfe-commits, mgorny

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

llvm-svn: 317193
2017-11-02 09:21:51 +00:00
Shoaib Meenai 99cfb67ad2 [clangd] Remove redundant install
`add_clang_tool` already adds the install command, so the one here is
redundant.

llvm-svn: 317187
2017-11-02 05:02:24 +00:00
Shoaib Meenai 09d4efee52 [clang-tidy] Clean up installation rules
An installation rule for the executable with the correct component is
already created by `add_clang_tool`, so the rule in this file is
redundant. Correct the installation component for the Python scripts so
that they also get installed by `install-clang-tidy`.

llvm-svn: 317155
2017-11-02 01:48:20 +00:00
Shoaib Meenai c40419d94b [clang-reorder-fields] Switch to add_clang_tool
`add_clang_tool` invokes `add_clang_executable` internally, but it also
takes care of setting up the install rule. It also adds an `install-*`
build target, which is required for `LLVM_DISTRIBUTION_COMPONENTS`.

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

llvm-svn: 317149
2017-11-02 01:10:05 +00:00
Simon Pilgrim 948c0bcbd6 Add LLVM_FALLTHROUGH to silence warning. NFCI.
llvm-svn: 317083
2017-11-01 09:22:03 +00:00
Benjamin Kramer 5349eedfdd [clangd] Fix clang-tidy warnings.
No functionality change intended.

llvm-svn: 316832
2017-10-28 17:32:56 +00:00
Benjamin Kramer 1d053791a1 [clangd] Don't crash on extremely large JSON messages.
Found by clangd-fuzzer.

llvm-svn: 316774
2017-10-27 17:06:41 +00:00
Benjamin Kramer decd8a702a [clangd] Harden clangd a bit against garbage input.
There can be nullptrs here if the YAML fails to parse. Found by
clangd-fuzzer!

llvm-svn: 316770
2017-10-27 16:33:15 +00:00
Jonas Toth 8ba28c7200 [clang-tidy] Fix bug 34845, offending standard bitmask types
Summary:
The C++ standard allows implementations to choose the underlying type for
bitmask types (e.g. std::ios_base::openmode). MSVC implemented some of them
as signed integers resulting in warnings for usual code like
`auto dd = std::ios_base::badbit | std::ios_base::failbit;`

These false positives were reported in https://bugs.llvm.org/show_bug.cgi?id=34845

The fix allows bitwise |,&,^ for known standard bitmask types under the condition
that both operands are such bitmask types.
Shifting and bitwise complement are still forbidden.

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: aaron.ballman

Subscribers: xazax.hun

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

llvm-svn: 316767
2017-10-27 14:44:08 +00:00
Haojian Wu e010406e28 [clang-tidy ObjC] [3/3] New check objc-forbidden-subclassing
Summary:
This is part 3 of 3 of a series of changes to improve Objective-C
linting in clang-tidy.

This adds a new clang-tidy check `objc-forbidden-subclassing` which
ensures clients do not create subclasses of Objective-C classes which
are not designed to be subclassed.

(Note that for code under your control, you should use
__attribute__((objc_subclassing_restricted)) instead -- this
is intended for third-party APIs which cannot be modified.)

By default, the following classes (which are publicly documented
as not supporting subclassing) are forbidden from subclassing:

ABNewPersonViewController
ABPeoplePickerNavigationController
ABPersonViewController
ABUnknownPersonViewController
NSHashTable
NSMapTable
NSPointerArray
NSPointerFunctions
NSTimer
UIActionSheet
UIAlertView
UIImagePickerController
UITextInputMode
UIWebView

Clients can set a CheckOption
`objc-forbidden-subclassing.ClassNames` to a semicolon-separated
list of class names, which overrides this list.

Test Plan: `ninja check-clang-tools`

Patch by Ben Hamilton!

Reviewers: hokein, alexfh

Reviewed By: hokein

Subscribers: saidinwot, Wizard, srhines, mgorny, xazax.hun

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

llvm-svn: 316744
2017-10-27 07:41:36 +00:00
Benjamin Kramer ee19f16633 [clangd] Report an error on findDefinitions/signatureHelp on an unopened file instead of crashing.
Found by clangd-fuzzer.

llvm-svn: 316659
2017-10-26 12:28:13 +00:00
Benjamin Kramer b560a9a1b8 [clangd] Don't crash on empty textDocument/didChange.
Found by clangd-fuzzer.

llvm-svn: 316652
2017-10-26 10:36:20 +00:00
Benjamin Kramer 74a1895422 [clangd] Don't use /// for non-doxygen comments.
llvm-svn: 316650
2017-10-26 10:07:04 +00:00
Benjamin Kramer 09113ae2c5 [clangd] Add a simple fuzzer. It crashes a lot :)
llvm-svn: 316649
2017-10-26 10:03:11 +00:00
Haojian Wu d2825825f8 [clang-tidy ObjC] [2/3] Support non-C++ files in ClangTidyTest
Summary:
This is part 2 of 3 of a series of changes to improve
Objective-C linting in clang-tidy.

Currently, `clang::tidy::test::runCheckOnCode()` assumes all files
are C++ and unconditionally adds `-std=c++11` to the list of
`clang-tidy` options.

This updates the logic to check the extension of the source file
and only add `-std=c++11` if the extension indicates C++ or
Objective-C++.

Depends On D39188

Test Plan:

  ninja ClangTidyTests && \
  ./tools/clang/tools/extra/unittests/clang-tidy/ClangTidyTests

Patch by Ben Hamilton!

Reviewers: hokein, alexfh

Reviewed By: hokein

Subscribers: Wizard

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

llvm-svn: 316645
2017-10-26 08:37:25 +00:00
Haojian Wu abcd64ccbf [clang-tidy ObjC] [1/3] New module `objc` for Objective-C checks
Summary:
This is part 1 of 3 of a series of changes to improve Objective-C
linting in clang-tidy.

This introduces a new clang-tidy module, `objc`, specifically for
Objective-C / Objective-C++ checks.

The module is currently empty; D39142 adds the first check.

Test Plan: `ninja check-clang-tools`

Patch by Ben Hamilton!

Reviewers: hokein, alexfh

Reviewed By: hokein

Subscribers: Wizard, mgorny

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

llvm-svn: 316643
2017-10-26 08:23:20 +00:00
Alex Lorenz fbd17e17f5 Handle PragmaDebug in PPChainedCallbacks
The test is in clang-tools-extra/test/pp-trace

llvm-svn: 316621
2017-10-25 22:01:23 +00:00
Ilya Biryukov 90bbcfd350 [clangd] Added a callback-based codeComplete in clangd.
Reviewers: klimek, bkramer, sammccall, krasimir

Reviewed By: sammccall

Subscribers: rwols, cfe-commits

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

llvm-svn: 316565
2017-10-25 09:35:10 +00:00
Ilya Biryukov 0d9b8a3ee8 [clangd] Handle exit notification (proper shutdown)
Summary:
This changes the onShutdown handler to do essentially nothing (for now), and
instead exits the runloop when we receive the exit notification from the client.

Some clients may wait on the reply from the shutdown request before sending an
exit notification. If we exit the runloop already in the shutdown request, a
client might block forever.

This also gives us the opportunity to do any global cleanups and/or
serializations of PCH preambles to disk, but I've left that out for now.

See the LSP protocol documentation for details.

Reviewers: malaperle, krasimir, bkramer, sammccall, ilya-biryukov

Reviewed By: malaperle, sammccall, ilya-biryukov

Subscribers: cfe-commits

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

llvm-svn: 316564
2017-10-25 08:45:41 +00:00
Ilya Biryukov b080cb155b [clangd] Allow to pass code completion opts to ClangdServer.
Reviewers: bkramer, krasimir, sammccall

Reviewed By: krasimir

Subscribers: klimek, cfe-commits

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

llvm-svn: 316327
2017-10-23 14:46:48 +00:00
Ilya Biryukov a7e3763a2b [clangd] Updated outdated test comment. NFC.
llvm-svn: 316323
2017-10-23 14:08:52 +00:00
Ilya Biryukov 01e3bf8afd [clangd] Report proper kinds for 'Keyword' and 'Snippet' completion items.
Reviewers: rwols, malaperle, krasimir, bkramer, sammccall

Reviewed By: rwols, sammccall

Subscribers: klimek, cfe-commits

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

llvm-svn: 316311
2017-10-23 06:06:21 +00:00
NAKAMURA Takumi f793fa3335 clang-tidy: Fix deps.
llvm-svn: 316260
2017-10-21 11:02:30 +00:00
Zachary Turner afc4b3857b [clang-tidy] Remove MSVC inline assembly test from cross-plat test.
This originally started out here in dev, but I moved it to another
file when it became clear this wouldn't work on non-Windows.
Unfortunately I forgot to remove it from this file.  Test is still
live, just in another source file.

llvm-svn: 316247
2017-10-20 23:09:20 +00:00
Zachary Turner fbdca1daec [clang-tidy] Don't error on MS-style inline assembly.
To get MS-style inline assembly, we need to link in the various
backends.  Some other clang tools already do this, and this issue
has been raised with clang-tidy several times, indicating there
is sufficient desire to make this work.

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

llvm-svn: 316246
2017-10-20 23:00:51 +00:00
Haojian Wu 49b8e94478 [clang-tidy] Add missing test files in r316090.
llvm-svn: 316221
2017-10-20 17:54:53 +00:00
Jonas Toth f00509c3a5 [clang-tidy] Fix 32bit platform MSVC
The previous fix only worked for 64bit MSVC, this one should fix all different
architectures.

llvm-svn: 316094
2017-10-18 16:40:19 +00:00
Jonas Toth 876b8ce52f [clang-tidy] Fix buildbot for msvc
The testcase defined `FILE` as `unsigned long`, but MSVC expect `unsigned long long`.

llvm-svn: 316093
2017-10-18 16:28:06 +00:00
Jonas Toth c9aea86e6a [clang-tidy] introduce legacy resource functions to 'cppcoreguidelines-owning-memory'
Summary:
This patch introduces support for legacy C-style resource functions that must obey
the 'owner<>' semantics.

- added legacy creators like malloc,fopen,...
- added legacy consumers like free,fclose,...

This helps codes that mostly benefit from owner:
Legacy, C-Style code that isn't feasable to port directly to RAII but needs a step in between
to identify actual resource management and just using the resources.

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: aaron.ballman

Subscribers: nemanjai, JDevlieghere, xazax.hun, kbarton

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

llvm-svn: 316092
2017-10-18 16:14:15 +00:00
Haojian Wu 9e0f7f1a23 Support Objective-C/C++ source files in check_clang_tidy.py
check_clang_tidy.py currently only handles C and C++ source files.

This extends the logic to also handle Objective-C (.m) and
Objective-C++ (.mm) files.

However, by default, clang compiles .m/.mm files using Objective-C 1.0
syntax. Objective-C 2.0 has been the default in Xcode for about 10
years, and Objective-C Automatic Reference Counting (ARC) for about 6
years, so this enables both by default.

(Clients which actually want to test clang-tidy checks for Objective-C
 1.0 or non-ARC files can pass custom flags to check_clang_tidy.py
 after --, which will disable the Objective-C 2.0 and ARC flags).

I did not add logic to handle running clang-tidy on Objective-C header
files alone; they also use the .h file extension, so we'd need to
look inside their contents.

I included a new test to confirm the new behavior.

Depends On D38963

Patch by Ben Hamilton!

llvm-svn: 316090
2017-10-18 15:56:39 +00:00
Haojian Wu a08422e0e4 New -assume-filename=param to check_clang_tidy.py (like clang-format)
Summary:
Currently, check_clang_tidy.py includes logic to select default
clang flags based on the extension of the source filename passed
as the first argument.

Since the source filename might be a temporary or test file with an
arbitrary extension unrelated to the file type, this adds the ability
to override the logic the same way `clang-format`'s -assume-filename=
parameter does.

I included a test with a nonstandard file extension. I confirmed
when I modified the warning message that the new test failed,
and that it passed again when I restored the warning message.

Ran tests with:

% cmake -G Ninja /path/to/llvm
% ninja check-clang-tools

Patch by Ben Hamilton!

Reviewers: hokein, alexfh

Reviewed By: hokein

Subscribers: alexfh

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

llvm-svn: 316066
2017-10-18 07:48:40 +00:00
Eric Liu b583a7ead4 [change-namespace] do not change type locs in defaulted functions.
Reviewers: hokein

Subscribers: cfe-commits

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

llvm-svn: 315892
2017-10-16 08:20:10 +00:00
Alexander Kornienko 75cd6a663f [clang-tidy] Add a regression test for google-readability-namespace-comments
Add a regression test for the google-readability-namespace-comments bug
introduced in r315057 (reverted in r315580).

llvm-svn: 315682
2017-10-13 14:11:14 +00:00
Alexander Kornienko 5d62569b04 Revert "Fix nested namespaces in google-readability-nested-namespace-comments."
This reverts r315057. The revision introduces assertion failures:
assertion failed at llvm/tools/clang/include/clang/Basic/SourceManager.h:428 in
const clang::SrcMgr::ExpansionInfo &clang::SrcMgr::SLocEntry::getExpansion()
const: isExpansion() && "Not a macro expansion SLocEntry!"
Stack trace:
    __assert_fail
    clang::SrcMgr::SLocEntry::getExpansion()
    clang::SourceManager::getExpansionLocSlowCase()
    clang::SourceManager::getExpansionLoc()
    clang::Lexer::getRawToken()
    clang::tidy::readability::NamespaceCommentCheck::check()
    clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::MatchVisitor::visitMatch()
    clang::ast_matchers::internal::BoundNodesTreeBuilder::visitMatches()
    clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchWithFilter()
    clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchDispatch()
    clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl()
    clang::RecursiveASTVisitor<>::TraverseDeclContextHelper()
    clang::RecursiveASTVisitor<>::TraverseDecl()
    clang::RecursiveASTVisitor<>::TraverseDeclContextHelper()
    clang::RecursiveASTVisitor<>::TraverseDecl()
    clang::RecursiveASTVisitor<>::TraverseDeclContextHelper()
    clang::RecursiveASTVisitor<>::TraverseDecl()
    clang::ast_matchers::MatchFinder::matchAST()
    clang::MultiplexConsumer::HandleTranslationUnit()
    clang::ParseAST()
    clang::FrontendAction::Execute()
    clang::CompilerInstance::ExecuteAction()
    clang::tooling::FrontendActionFactory::runInvocation()
    clang::tooling::ToolInvocation::runInvocation()
    clang::tooling::ToolInvocation::run()

Still working on an isolated test case.

llvm-svn: 315580
2017-10-12 14:25:16 +00:00
Sam McCall 8a5dded8a5 [clangd] less boilerplate in RPC dispatch
Summary:
Make the ProtocolHandlers glue between JSONRPCDispatcher and
ClangdLSPServer generic.
Eliminate small differences between methods, de-emphasize the unimportant
distinction between notifications and methods.

ClangdLSPServer is no longer responsible for producing a complete
JSON-RPC response, just the JSON of the result object. (In future, we
should move that JSON serialization out, too).
Handler methods now take a context object that we may hang more
functionality off in the future.

Added documentation to ProtocolHandlers.

Reviewers: ilya-biryukov, bkramer

Reviewed By: ilya-biryukov

Subscribers: cfe-commits

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

llvm-svn: 315577
2017-10-12 13:29:58 +00:00
Alexander Kornienko 7853351af8 Fix the google-readability-namespace-comments-cxx17 test after r315060.
Restore the file extension. Make the namespace longer than the
ShortNamespaceLines so that the check triggers.

llvm-svn: 315574
2017-10-12 10:41:22 +00:00
Peter Collingbourne 0dfdb44797 Support: Have directory_iterator::status() return FindFirstFileEx/FindNextFile results on Windows.
This allows clients to avoid an unnecessary fs::status() call on each
directory entry. Because the information returned by FindFirstFileEx
is a subset of the information returned by a regular status() call,
I needed to extract a base class from file_status that contains only
that information.

On my machine, this reduces the time required to enumerate a ThinLTO
cache directory containing 520k files from almost 4 minutes to less
than 2 seconds.

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

llvm-svn: 315378
2017-10-10 22:19:46 +00:00
Ilya Biryukov 98a1fd7f96 [clangd] Use UniqueFunction for deferred computations.
Previsouly, `std::future` that were results of
`std::async(std::launch::deferred, ...` were used.

llvm-svn: 315325
2017-10-10 16:12:54 +00:00
Ilya Biryukov eab499d31b [clangd] Added missing #includes to Function.h
llvm-svn: 315324
2017-10-10 16:12:50 +00:00
Ilya Biryukov cfcc0d3eb6 [clangd] Added forgotten return in UniqueFunction.
This hasn't bitten us because we only used functions returning
'void'.

llvm-svn: 315323
2017-10-10 16:12:47 +00:00
Ilya Biryukov 3847be5514 [clangd] clang-format the source code. NFC.
llvm-svn: 315317
2017-10-10 14:21:04 +00:00
Ilya Biryukov e6dbb58f95 Revert "Revert r315214 since diff -Z isn't portable, this is breaking:"
This reverts commit r315242 and restores r315214.

To fix original failure, replaced non-portable `diff -Z` with portable
alternative: `diff -b`.

llvm-svn: 315287
2017-10-10 09:08:47 +00:00
Ilya Biryukov 4923a80f00 [clangd] Fix compilation on gcc.
llvm-svn: 315284
2017-10-10 08:40:57 +00:00
Benjamin Kramer 252dd8b745 [clang-tidy] Use a more efficient map for the virtual near miss check.
DenseMap performs better here. No functionality change intended.

llvm-svn: 315277
2017-10-10 07:21:51 +00:00
Bruno Cardoso Lopes c084589877 Revert r315214 since diff -Z isn't portable, this is breaking:
http://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-expensive
http://green.lab.llvm.org/green/job/clang-stage1-configure-RA

llvm-svn: 315242
2017-10-09 20:22:05 +00:00
Ilya Biryukov de0cc39462 [clangd] Added a command-line arg to mirror clangd input into a file.
Summary: The arg is useful for debugging and creating test cases.

Reviewers: bkramer, krasimir

Reviewed By: bkramer

Subscribers: klimek, cfe-commits

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

llvm-svn: 315214
2017-10-09 16:58:16 +00:00