Commit Graph

2357 Commits

Author SHA1 Message Date
Jakub Kuderski 57fa1de516 [clang-tidy] Fix naming convention in modernize-use-emplace
Summary: Conform to the llvm naming convention for local variables in modernize-use-emplace check.

Reviewers: Prazek, JonasToth, alexfh

Reviewed By: Prazek, JonasToth, alexfh

Subscribers: cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 301780
2017-04-30 21:12:56 +00:00
NAKAMURA Takumi 68ce7c3b0d clang-tools-extra/test/CMakeLists.txt: Rework r297806 (D29851) to make sure test utils should be built.
FIXME: This may be moved to llvm's add_lit_target().
llvm-svn: 301762
2017-04-30 03:19:04 +00:00
Alexander Kornienko 4e001b5bd7 [clang-tidy] Expand AllowConditional*Casts to binary logical operators
llvm-svn: 301743
2017-04-29 12:06:45 +00:00
Jakub Kuderski 2a43d71765 [clang-tidy] modernize-use-emplace: remove unnecessary make_pair calls
Summary:
When there is a push_back with a call to make_pair, turn it into emplace_back and remove the unnecessary make_pair call.

Eg.

```
std::vector<std::pair<int, int>> v;
v.push_back(std::make_pair(1, 2)); // --> v.emplace_back(1, 2);
```

make_pair doesn't get removed when explicit template parameters are provided, because of potential problems with type conversions.

Reviewers: Prazek, aaron.ballman, hokein, alexfh

Reviewed By: Prazek, alexfh

Subscribers: JDevlieghere, JonasToth, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 301651
2017-04-28 16:25:45 +00:00
David Blaikie 5c4ec7cca4 Fix API breaks
llvm-svn: 301468
2017-04-26 20:58:03 +00:00
Haojian Wu 489f363380 [clang-tidy] Support detecting for-range loop in inefficient-vector-operation check.
Summary:
Also add an option "VectorLikeClasses" allowing user specify customized
vectors.

Reviewers: alexfh, aaron.ballman

Reviewed By: alexfh

Subscribers: Eugene.Zelenko, cfe-commits

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

llvm-svn: 301440
2017-04-26 18:13:05 +00:00
Alexander Kornienko eec01adde3 [clang-tidy] Update IdentifierNamingCheck to remove extra leading/trailing underscores
Summary:
The goal of this change is to fix the following suboptimal replacements currently suggested by clang-tidy:
```
// with MemberPrefix == "_"
int __foo;  // accepted without complaint
```
```
// with MemberPrefix == "m_"
int _foo;
    ^~~~~~
    m__foo
```

I fixed this by
- updating `matchesStyle()` to reject names which have a leading underscore after a prefix has already been stripped, or a trailing underscore if a suffix has already been stripped;
- updating `fixupWithStyle()` to strip leading & trailing underscores before adding the user-defined prefix and suffix.

The replacements are now:
```
// MemberPrefix == "_"
int __foo;
    ^~~~~~
    _foo
```
```
// MemberPrefix == "m_"
int _foo;
    ^~~~~
    m_foo
```

Future improvements might elect to add .clang-tidy flags to improve what is being stripped. For instance, stripping `m_` could allow `m_foo` to be automatically replaced with `_foo`.

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: cfe-commits

Patch by Jacob Bandes-Storch!

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

llvm-svn: 301431
2017-04-26 16:39:11 +00:00
Jakub Kuderski a7410fdbee [clang-tidy] run-clang-tidy.py: check if clang-apply-replacements succeeds
Summary:
When running run-clang-tidy.py with -fix it tries to apply found replacements at the end.
If there are errors running clang-apply-replacements, the script currently crashes or displays no error at all.

This patch checks for errors running clang-apply-replacements the same way clang-tidy binary is handled.

Another option would be probably checking for clang-apply-replacements (when -fix is passed) even before running clang-tidy.

Reviewers: Prazek, alexfh, bkramer, mfherbst

Reviewed By: Prazek, alexfh

Subscribers: kimgr, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 301365
2017-04-25 22:38:39 +00:00
Haojian Wu 8fd72968d4 [clang-tidy] Some Cleanups for performance-faster-string-find check.
NFC

llvm-svn: 301188
2017-04-24 16:41:00 +00:00
Aaron Ballman 72163a9da5 Extend readability-container-size-empty to add comparisons to empty-state objects.
Patch by Josh Zimmerman.

llvm-svn: 301185
2017-04-24 14:57:09 +00:00
Mads Ravn a301498783 [clang-tidy] New check: modernize-replace-random-shuffle.
This check will find occurrences of ``std::random_shuffle`` and replace it with ``std::shuffle``. In C++17 ``std::random_shuffle`` will no longer be available and thus we need to replace it.

Example of case that it fixes

```
  std::vector<int> v;

  // First example
  std::random_shuffle(vec.begin(), vec.end());

```

Reviewers: hokein, aaron.ballman, alexfh, malcolm.parsons, mclow.lists

Subscribers: cfe-commits

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

llvm-svn: 301167
2017-04-24 09:27:20 +00:00
Miklos Vajna a60cae2648 clang-rename: fix formatting
As detected by clang-format.

llvm-svn: 301130
2017-04-23 16:07:06 +00:00
Benjamin Kramer d3326a04e0 [Clangd] Failed to decode params using 1.x-compatible request message
textDocument/completion sends a TextDocumentPositionParams message in the 2.x
and 3.x. But in 1.x it was instead a TextDocumentPosition with inlined
parameters. This means that the "uri" field is at the top level and not in
textDocument. Because of this, some clients that maintain compability with 1.x
have both uri and textDocument.uri. Clangd, however, early returns in the
presence of anything but 'textDocument' or 'position' which prevents a client
compatible with both 3.x and 1.x to work correctly. If Clangd was a bit more
permissive (no early return), clients implementing all the versions of the
protocol would work.

Patch by Marc-Andre Laperle!

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

llvm-svn: 300991
2017-04-21 15:51:23 +00:00
Benjamin Kramer 8c3ba63d07 [Clangd] Support Authority-less URIs
Clangd strips URIs by removing the file:// part but some clients can send file:
which is also valid according to RFC 3896. For example, if a client sends
file:///home/user, it gets converted to /home/user but if a client sends
file:/home/user, it is left untouched and problems arise.

Patch by Marc-Andre Laperle!

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

llvm-svn: 300990
2017-04-21 15:51:18 +00:00
Gabor Horvath 1a92506f36 [clang-tidy] misc-misplaced-widening-cast: Disable checking of implicit widening casts by default.
Patch by Ádám Balogh!

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

llvm-svn: 300699
2017-04-19 14:55:58 +00:00
Haojian Wu c2c2283223 [clang-tidy] Address a few late comments.
llvm-svn: 300588
2017-04-18 20:47:34 +00:00
Alexander Kornienko 04e5ab3501 [clang-tidy] Fix google-explicit-constructor issue with out-of-line conversions
llvm-svn: 300569
2017-04-18 17:26:00 +00:00
Haojian Wu d8ad303f15 Make the test pass on x86_64-win32 target.
llvm-svn: 300563
2017-04-18 16:25:03 +00:00
NAKAMURA Takumi 7db18e9b66 clang-tools-extra/test/clang-tidy/performance-inefficient-vector-operation.cpp: Appease targeting msvc with -fno-ms-extensions.
FIXME: This may work with -target x86_64-win32.
llvm-svn: 300545
2017-04-18 12:13:30 +00:00
Haojian Wu c5cc03377e [clang-tidy] Add a clang-tidy check for possible inefficient vector operations
Summary:
The "performance-inefficient-vector-operation" check finds vector oprations in
for-loop statements which may cause multiple memory reallocations.

This is the first version, only detects typical for-loop:

```
std::vector<int> v;
for (int i = 0; i < n; ++i) {
  v.push_back(i);
}

// or

for (int i = 0; i < v2.size(); ++i) {
  v.push_back(v2[i]);
}
```

We can extend it to handle more cases like for-range loop in the future.

Reviewers: alexfh, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: zaks.anna, Eugene.Zelenko, mgorny, cfe-commits, djasper

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

llvm-svn: 300534
2017-04-18 07:46:39 +00:00
Alexander Shaposhnikov ffb997a8eb [clang-move] Create ClangMoveActionFactory on stack
This diff removes unnecessary using of unique_ptr with ClangMoveActionFactory (pico cleanup).
NFC

Test plan: make check-clang-tools

Differential revision: https://reviews.llvm.org/D32063

llvm-svn: 300356
2017-04-14 18:12:11 +00:00
Nirav Dave 21d5d4fbbf Silence -Wlogical-op-parentheses warning NFC
llvm-svn: 300324
2017-04-14 14:36:45 +00:00
Gabor Horvath 6f0e2ac858 [clang-tidy] Fixes to misc-forwarding-reference-overload check.
* Style fixes to tests
* Make it work consistently on all platforms

Patch by András Leitereg!

llvm-svn: 300320
2017-04-14 12:31:36 +00:00
Eric Fiselier 6eee3a3fca Fix clang-tidy shared link with libc++
Currently the ClangTidyMain.cpp fails to link against shared LLVM/Clang libraries
due to the missing symbol:

  clang::tooling::operator<(clang::tooling::Replacement const&,
                            clang::tooling::Replacement const&);

This patch fixes the issue by correctly linking clangToolingCore which contains
the definition.

llvm-svn: 300115
2017-04-12 22:07:47 +00:00
Krasimir Georgiev 95ef171797 [clangd] Rename ClangDMain.cpp -> ClangdMain.cpp, NFC
llvm-svn: 300077
2017-04-12 17:13:08 +00:00
Sylvestre Ledru c94f320bd8 Add the definition of P in the clang tidy example
llvm-svn: 299961
2017-04-11 16:28:15 +00:00
Krasimir Georgiev 4714f7cba9 [clangd] Implement item kind for completion results
Summary: The patch implements the conversion method from CXCursorKind to clangd::CompletionItemKind.
Contributed by stanionascu!

Reviewers: cfe-commits, bkramer, krasimir

Reviewed By: krasimir

Tags: #clang-tools-extra

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

llvm-svn: 299935
2017-04-11 13:27:15 +00:00
Sylvestre Ledru 09ffef2c10 Add more examples to clang tidy checkers
Reviewers: alexfh

Reviewed By: alexfh

Subscribers: cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 299920
2017-04-11 07:10:48 +00:00
Reid Kleckner 65f015ac7f [clangd] Relax absolute path checking assertion
clangd can process absolute paths from systems that don't use the native
path style, so this assertion needs to check both Windows and Posix path
styles.

Fixes PR32596

llvm-svn: 299854
2017-04-10 17:03:44 +00:00
Reid Kleckner 08126372e3 Revert "XFAIL clangd tests on Windows"
This reverts r299849, apparently these tests only fail on my machine.

llvm-svn: 299850
2017-04-10 16:55:48 +00:00
Reid Kleckner 7e1548d6db XFAIL clangd tests on Windows
They all assert. Filed as PR32596.

llvm-svn: 299849
2017-04-10 16:50:55 +00:00
Krasimir Georgiev 5776e2f8e1 [clangd] Fix nondeterminism in clangd test
llvm-svn: 299844
2017-04-10 14:06:54 +00:00
Krasimir Georgiev 561ba5e667 [clangd] Remove ASTUnits for closed documents and cache CompilationDatabase per directory.
Contributed by ilya-biryukov!

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

llvm-svn: 299843
2017-04-10 13:31:39 +00:00
Haojian Wu 0bc5e02799 Fix compiler warnings: "ISO c99 requires rest arguments to be used" on
the test file.

llvm-svn: 299764
2017-04-07 12:37:32 +00:00
Krasimir Georgiev 50117372db [clangd] Extract FsPath from file:// uri
Patch contributed by stanionascu!

rfc8089#appendix-E.2 specifies that paths can begin with a drive letter e.g. as file:///c:/.
In this case just consuming front file:// is not enough and the 3rd slash must be consumed to produce a valid path on windows.

The patch introduce a generic way of converting an uri to a filesystem path and back.

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

llvm-svn: 299758
2017-04-07 11:03:26 +00:00
Alexander Kornienko 434b333afd [clang-tidy] A couple of minor fixes in modernize-use-using tests
llvm-svn: 299752
2017-04-07 09:41:27 +00:00
Chih-Hung Hsieh 90fccec5ee [clang-tidy] Reuse FileID in getLocation
One FileID per warning will increase and overflow NextLocalOffset
when input file is large with many warnings.
Reusing FileID avoids this problem.

This requires changes in getColumnNumber, D31406, rL299681.

Differential Revision: http://reviews.llvm.org/D31406

llvm-svn: 299700
2017-04-06 20:19:26 +00:00
Gabor Horvath edaf907d36 [clang-tidy] Temporarily disable a test-case that does not work on windows.
llvm-svn: 299657
2017-04-06 15:58:57 +00:00
Alexander Kornienko 215604c252 [clang-tidy] Update docs and help message
llvm-svn: 299651
2017-04-06 14:27:00 +00:00
Alexander Kornienko 2561320f80 [clang-tidy] Add FormatStyle configuration option.
llvm-svn: 299649
2017-04-06 13:41:29 +00:00
Gabor Horvath e228f68811 Attempt to fix build bots after r299638.
llvm-svn: 299645
2017-04-06 12:49:35 +00:00
Simon Pilgrim 4e682348a2 Wdocumentation fix
llvm-svn: 299642
2017-04-06 10:49:02 +00:00
Gabor Horvath b3856d65ea [clang-tidy] Check for forwarding reference overload in constructors.
Patch by András Leitereg!

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

llvm-svn: 299638
2017-04-06 09:56:42 +00:00
David Blaikie 0c0c8c4d38 Fix -Wmissing-field-initializer warnings to unbreak the -Werror build
llvm-svn: 299561
2017-04-05 16:50:19 +00:00
Jonas Devlieghere c45b03bddc [clangd] Link against clangSema
Fixes linking issue introduced by rL299421 when building LLVM with
shared libraries.

llvm-svn: 299461
2017-04-04 19:42:29 +00:00
Krasimir Georgiev beaff10d39 [clangd] Fix completion test to not depend on the standard library
llvm-svn: 299440
2017-04-04 15:08:42 +00:00
Krasimir Georgiev d7f1512897 [clangd] Remove private vector fields from completion test.
llvm-svn: 299426
2017-04-04 10:42:22 +00:00
Haojian Wu 43ba525357 Fix windows buildbot error.
llvm-svn: 299422
2017-04-04 09:53:55 +00:00
Krasimir Georgiev 6d2131a04c [clangd] Add code completion support
Summary: Adds code completion support to clangd.

Reviewers: bkramer, malaperle-ericsson

Reviewed By: bkramer, malaperle-ericsson

Subscribers: stanionascu, malaperle-ericsson, cfe-commits

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

llvm-svn: 299421
2017-04-04 09:46:39 +00:00
Haojian Wu 74f823a045 [clang-rename] Support renaming qualified symbol
Summary:
The patch adds a new feature for renaming qualified symbol references.
Unlike orginal clang-rename behavior, when renaming a qualified symbol to a new
qualified symbol (e.g "A::Foo" => "B::Bar"), this new rename behavior will
consider the prefix qualifiers of the symbol, and calculate the new prefix
qualifiers.  It aims to add as few additional qualifiers as possible.

As this is an early version (only supports renaming classes), I don't change
current clang-rename interfaces at the moment, and would like to keep its
(command-line tool) behavior. So I added new interfaces for the prototype.
In the long run, these interfaces should be unified.

No functionality changes in original clang-rename command-line tool.

This patch also contains a few bug fixes of clang-rename which are discovered by
the new unittest:

* fix a potential nullptr accessment when class declaration doesn't have definition.
* add USRs of nested declartaions in "getNamedDeclFor".

Reviewers: ioeric

Reviewed By: ioeric

Subscribers: alexfh, cfe-commits, mgorny

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

llvm-svn: 299419
2017-04-04 09:30:06 +00:00