Commit Graph

857 Commits

Author SHA1 Message Date
Daniel Marjamaki 03ea468a1c [clang-tidy] readability-misplaced-array-index: add new check that warns when array index is misplaced.
Reviewers: alexfh

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

llvm-svn: 281206
2016-09-12 12:04:13 +00:00
Ahmed Bougacha 7d61594f33 Revert "Resubmit "Add a test for clang-tidy using the clang-cl driver.""
This reverts commit r280839.
It's problematic on OS X, where the '/Users/...' paths are interpreted
as '/U' options.

Investigation ongoing in http://llvm.org/PR30328.

llvm-svn: 280975
2016-09-08 18:02:14 +00:00
Zachary Turner b7a619c1fa Resubmit "Add a test for clang-tidy using the clang-cl driver."
This was originally reverted because the patch on the clang
tooling side was reverted.  That patch is being resubmitted,
so this patch is resubmitted as well.

llvm-svn: 280839
2016-09-07 18:28:42 +00:00
Haojian Wu cd63701245 [include-fixer] Support finding headers for the symbol under cursor.
Summary:
* Add a `query-symbol` option to query symbol without parsing the source file.
* Update Vim & Emacs integration scripts.

Reviewers: bkramer, massberg

Subscribers: cfe-commits

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

llvm-svn: 280824
2016-09-07 16:34:35 +00:00
Kirill Bobyrev 9504e3a4f0 [clang-rename] add failing test
For some reason clang-rename fails to rename method of templated class. Add
XFAIL test reproducing the issue.

llvm-svn: 280639
2016-09-04 22:28:39 +00:00
Alexander Shaposhnikov bf3c84cff7 Add clang-reorder-fields to clang-tools-extra
This diff adds v0 of clang-reorder-fields tool to clang/tools/extra.
The main idea behind this tool is to simplify and make less error-prone refactoring of large codebases when
someone needs to change the order fields of a struct/class (for example to remove excessive padding).

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

llvm-svn: 280456
2016-09-02 02:56:07 +00:00
Alexander Shaposhnikov 3efddd22b9 Revert https://reviews.llvm.org/D23279 because the tests have failed on several platforms
llvm-svn: 280438
2016-09-02 00:24:06 +00:00
Alexander Shaposhnikov ae4ff453a4 Add clang-reorder-fields to clang-tools-extra
This diff adds v0 of clang-reorder-fields tool to clang/tools/extra.
The main idea behind this tool is to simplify and make less error-prone refactoring of large codebases when
someone needs to change the order fields of a struct/class (for example to remove excess padding).

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

llvm-svn: 280431
2016-09-01 23:49:48 +00:00
Piotr Padlewski d57be707b8 [clang-tidy] modernize-make-{smart_ptr} private ctor bugfix
Summary:
Bugfix for 27321. When the constructor of stored pointer
type is private then it is invalid to change it to
make_shared or make_unique.

Reviewers: alexfh, aaron.ballman, hokein

Subscribers: cfe-commits

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

llvm-svn: 280180
2016-08-31 00:06:55 +00:00
NAKAMURA Takumi 795a1e9a15 clang-tools-extra/test/clang-tidy/misc-move-forwarding-reference.cpp: Appease ms targets with -fno-delayed-template-parsing.
llvm-svn: 280078
2016-08-30 12:34:03 +00:00
Martin Bohme b1ce6c6d57 [clang-tidy] Add check 'misc-move-forwarding-reference'
Summary:
The check emits a warning if std::move() is applied to a forwarding reference, i.e. an rvalue reference of a function template argument type.

If a developer is unaware of the special rules for template argument deduction on forwarding references, it will seem reasonable to apply std::move() to the forwarding reference, in the same way that this would be done for a "normal" rvalue reference.

This has a consequence that is usually unwanted and possibly surprising: If the function that takes the forwarding reference as its parameter is called with an lvalue, that lvalue will be moved from (and hence placed into an indeterminate state) even though no std::move() was applied to the lvalue at the callsite.

As a fix, the check will suggest replacing the std::move() with a std::forward().

This patch requires D23004 to be submitted before it.

Reviewers: sbenza, aaron.ballman

Subscribers: klimek, etienneb, alexfh, aaron.ballman, Prazek, Eugene.Zelenko, mgehre, cfe-commits

Projects: #clang-tools-extra

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

llvm-svn: 280077
2016-08-30 12:11:12 +00:00
Miklos Vajna 2e5fca77a6 clang-rename: improve error message when -old-name is used and could not find symbol
Old output was:

clang-rename: could not find symbol at tools/clang/tools/extra/test/clang-rename/ClassFindByName.cpp:1:1 (offset 0).

Reviewers: omtcyfz

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

llvm-svn: 280062
2016-08-30 07:23:24 +00:00
Alexander Kornienko eedcd9c1ea [clang-tidy misc-move-const-arg] more specific messages + suggest alternative solution
llvm-svn: 279666
2016-08-24 21:23:24 +00:00
Alexander Kornienko 42fd75ea86 [clang-tidy] Fix the order of ExtraArgsBefore
Added tests for the relative order of -extra-arg(-before) and ExtraArgs(Before).

llvm-svn: 279516
2016-08-23 14:13:31 +00:00
Daniel Marjamaki 9e4ecfaec7 [clang-tidy] readability-non-const-parameter: add new check that warns when function parameters should be const
The check will warn when the constness will make the function interface safer.

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 279507
2016-08-23 10:09:08 +00:00
Zachary Turner 4178b0b611 Revert "Add a test for clang-tidy using the clang-cl driver."
This reverts commit fd1908ce445eba4544d64cc68b3c03249e4bf614.

This should be the correct CL to revert.  The clang-side patch
that enabled this functionality was reverted, so this test needs
to be reverted until it gets fixed.

llvm-svn: 278979
2016-08-17 21:01:13 +00:00
Zachary Turner e4d8225e72 Add a test for clang-tidy using the clang-cl driver.
Reviewed By: alexfh
Differential Revision: https://reviews.llvm.org/D23480

llvm-svn: 278968
2016-08-17 20:14:10 +00:00
Reid Kleckner 23c2eac34d Remove most instances of REQUIRES: shell from the tools/extra tests
None of these tests actually require bash, they just have quoting bugs
when paths contain backslashes and colons. Fix them with the "%/T" lit
substitution variants.

llvm-svn: 278815
2016-08-16 16:07:46 +00:00
Alexander Droste 1512f9a0f9 [clang-tidy] MPIBufferDerefCheck
...
This check verifies if a buffer passed to an MPI (Message Passing Interface)
function is sufficiently dereferenced. Buffers should be passed as a single
pointer or array. As MPI function signatures specify void * for their buffer
types, insufficiently dereferenced buffers can be passed, like for example
as double pointers or multidimensional arrays, without a compiler warning
emitted.

Instructions on how to apply the check can be found at:
https://github.com/0ax1/MPI-Checker/tree/master/examples

Reviewers: Haojian Wu
Differential revision: https://reviews.llvm.org/D22729

llvm-svn: 278553
2016-08-12 19:30:31 +00:00
Zachary Turner 6a91af7eb7 Remove accidentally committed file.
llvm-svn: 278547
2016-08-12 18:39:05 +00:00
Zachary Turner 18cfbc4b8e Analyze include order on a per-file basis.
The include order check would get notified of all include
directives in a depth-first manner.  This created the
possibility of an include directive from a header file
interfering with the sort order of a set of two distinct
blocks from the top level cpp file, if that include directive
was on just the right line.

With this patch we bucket the include directives by the file
in which they appear in and process one bucket at a time,
so that directives from different files do not get mixed
together into the same list.

Reviewed By: alexfh
Differential Revision: https://reviews.llvm.org/D23434

llvm-svn: 278546
2016-08-12 18:38:26 +00:00
Kirill Bobyrev c018e4d665 [clang-tidy] fix readability-else-after-return test
As pointed by Yung Douglas, exceptions in
test/clang-tidy/readability-else-after-return.cpp are causing PS4 bots to be
red, because exceptions aren't enabled by default on PS4 target. This patch is a
fix.

llvm-svn: 278324
2016-08-11 08:18:39 +00:00
Kirill Bobyrev 34789edbbf [clang-tidy] enhance readability-else-after-return
`readability-else-after-return` only warns about `return` calls, but LLVM Coding
Standars stat that `throw`, `continue`, `goto`, etc after `return` calls are
bad, too.

Reviwers: alexfh, aaron.ballman

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

llvm-svn: 278257
2016-08-10 18:05:47 +00:00
Kirill Bobyrev 8694cb97c2 [clang-tidy] minor improvements in modernise-deprecated-headers check
This patch introduces a minor list of changes as proposed by Richard Smith in
the mailing list.

See original comments with an impact on the future check state below:

[comments.begin

> +                          {"complex.h", "ccomplex"},

It'd be better to convert this one to <complex>, or leave it alone.
<ccomplex> is an unnecessary wart.

(The contents of C++11's <complex.h> / <ccomplex> / <complex> (all of
which are identical) aren't comparable to C99's <complex.h>, so if
this was C++98 code using the C99 header, the code will be broken with
or without this transformation.)

> +                          {"iso646.h", "ciso646"},

Just delete #includes of this one. <ciso646> does nothing.

> +              {"stdalign.h", "cstdalign"},
> +              {"stdbool.h", "cstdbool"},

We should just delete these two includes. These headers do nothing in C++.

comments.end]

Reviewers: alexfh, aaron.ballman

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

llvm-svn: 278254
2016-08-10 18:01:45 +00:00
Kirill Bobyrev 607f50cdb3 [clang-rename] fix test introduced in r278221
llvm-svn: 278225
2016-08-10 13:46:36 +00:00
Kirill Bobyrev 3168418a7c [clang-rename] remove bunch of deprecated tests
llvm-svn: 278223
2016-08-10 13:32:37 +00:00
Kirill Bobyrev 77f522cb42 [clang-rename] merge tests when possible
The only difference between some tests is -offset passed to clang-rename. It
makes sense to merge them into a single file and add multiple tool invocations.

Reviewers: alexfh

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

llvm-svn: 278221
2016-08-10 13:28:30 +00:00
Miklos Vajna 3d71b51bc5 clang-rename rename-all: support reading old/newname pairs from a YAML file
This is handy in case by the time clang-rename is invoked, an external
tool already genereated a list of oldname -> newname pairs to handle.

Reviewers: omtcyfz

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

llvm-svn: 278145
2016-08-09 18:20:41 +00:00
Haojian Wu c99f72868d [include-fixer] Support processing multiple files in one run.
Summary:
Previously, if we pass multiple files or a file pattern (e.g. /path/to/*.cc) to
include-fixer, include-fixer will apply all replacements to the first argument,
which probably causes crashes.

With this patch, include-fixer can process multiple files now.

Vim and Emacs integration are tested manually.

Reviewers: bkramer

Subscribers: cfe-commits

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

llvm-svn: 278102
2016-08-09 08:26:19 +00:00
Eric Liu 7e5445267f Fix clang-tidy crash when a single fix is applied on multiple files.
Summary:
tooling::Replacements only holds replacements for a single file, so
this patch makes Fix a map from file paths to tooling::Replacements so that it
can be applied on multiple files.

Reviewers: hokein, alexfh

Subscribers: Prazek, cfe-commits

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

llvm-svn: 278101
2016-08-09 07:54:49 +00:00
Kirill Bobyrev 31fd7fb5e6 [clang-rename] fix bug with initializer lists
Clang-rename is currently not able to find a symbol in initializer list. This
patch fixes described issue.

Reviewers: alexfh

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

llvm-svn: 278099
2016-08-09 07:14:48 +00:00
Kirill Bobyrev 75de8968b6 [clang-tidy] enhance modernize-use-bool-literals to check ternary operator
modernize-use-bool-literals doesn't checks operands in ternary operator.

For example:

``` c++
static int Value = 1;

bool foo() {
  bool Result = Value == 1 ? 1 : 0;
  return Result;
}

bool boo() {
  return Value == 1 ? 1 : 0;
}
```

This issue was reported in bug 28854. The patch fixes it.

Reviewers: alexfh, aaron.ballman, Prazek

Subscribers: Prazek, Eugene.Zelenko

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

llvm-svn: 278022
2016-08-08 17:11:56 +00:00
Alexander Kornienko 6b2a4d5e8f [clang-tidy] misc-argument-comment non-strict mode
Summary:
The misc-argument-comment check now ignores leading and trailing underscores and
case. The new `StrictMode` local/global option can be used to switch back to
strict checking.

Add getLocalOrGlobal version for integral types, minor cleanups.

Reviewers: hokein, aaron.ballman

Subscribers: aaron.ballman, Prazek, cfe-commits

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

llvm-svn: 277729
2016-08-04 14:54:54 +00:00
Alexander Kornienko dcbf57d198 [clang-tidy] Inefficient string operation
Patch by Bittner Barni!

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

llvm-svn: 277677
2016-08-03 23:06:03 +00:00
Kirill Bobyrev d6ab7d4508 [clang-rename] improve USRFindingAction
1. Improve templated class renaming, namely add capabilities of finding partial
and full specializations. Every class partial specialization has reference to
the specialized class. Thus, storing all partial specializations and
comparing specialized class decls to the FoundDecl solves this. All full class
specializations can be found by calling ClassTemplateDecl::specializations().

2. Fix virtual function and its overriding functions renaming. Renaming a
virtual function requires renaming every other function in its "overriding
graph".

3. Merge TemplateClassInstantiationFindBy{Declaration|TypeUse}.cpp tests into
one test by adding multiple invocations of clang-rename to one test, because
the only different thing across these tests is -offset passed to clang-rename.

Reviewers: alexfh

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

llvm-svn: 277663
2016-08-03 23:00:32 +00:00
Jonathan Coe 77ec263e60 [clang-tidy] Fix segfault in cppcore-guidelines-special-member-functions check
Summary:
Use a set rather than a vector of defined special member functions so
that multiple declarations of the same function are only counted once.

Move some private static member functions into the cpp file.

Run clang-format on header.

Reviewers: ericLemanissier, Prazek, aaron.ballman

Subscribers: Prazek, cfe-commits, nemanjai

Projects: #clang-tools-extra

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

llvm-svn: 277523
2016-08-02 21:18:37 +00:00
Alexander Kornienko 5e0a50c2d7 [clang-tidy] MPITypeMismatchCheck
This check verifies if buffer type and MPI (Message Passing Interface)
datatype pairs match. All MPI datatypes defined by the MPI standard (3.1)
are verified by this check. User defined typedefs, custom MPI datatypes and
null pointer constants are skipped, in the course of verification.

Instructions on how to apply the check can be found at:
https://github.com/0ax1/MPI-Checker/tree/master/examples

Patch by Alexander Droste!

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

llvm-svn: 277516
2016-08-02 20:29:35 +00:00
NAKAMURA Takumi b650462007 clang-tools-extra/test/clang-rename/TemplateTypenameFindBy*.cpp: Appease targeting ms mode.
llvm-svn: 277452
2016-08-02 13:17:40 +00:00
NAKAMURA Takumi acf37a9234 clang-tools-extra/test/clang-rename/TemplateTypenameFindBy*.cpp: Move RUN: lines below not to be affected by tweaks of parameters.
llvm-svn: 277451
2016-08-02 13:17:36 +00:00
Haojian Wu da2a58dd0b [clang-tidy] Fix an unused-using-decl false positive about template arguments in
function call expression.

Summary:
The check doesn't mark the template argument as used when the template
argument is a template.

Reviewers: djasper, alexfh

Subscribers: klimek, cfe-commits

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

llvm-svn: 277444
2016-08-02 11:26:35 +00:00
Miklos Vajna aaec9b6cfc clang-rename: split existing options into two new subcommands
- rename-at is meant to be integrated with editors and works mainly off
  of a location in a file, and this is the default
- rename-all is optimized for one or more oldname->newname renames, and
  works with clang-apply-replacements

Reviewers: bkramer, klimek

Subscribers: omtcyfz

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

llvm-svn: 277438
2016-08-02 09:51:31 +00:00
Kirill Bobyrev 9e0dab9352 [clang-rename] add support for template parameter renaming
Few simple tweaks allow template parameters to be renamed. See
TemplateTypenameFindBy{TemplateParam|TypeInside}.cpp

Reviewers: alexfh

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

llvm-svn: 277437
2016-08-02 09:38:38 +00:00
Kirill Bobyrev 91053e0675 [clang-rename] handle overridden functions correctly
1. Renaming overridden functions only works for two levels of "overriding
   hierarchy". clang-rename should recursively add overridden methods.
2. Make use of forEachOverridden AST Matcher.
3. Fix two tests.

Reviewers: alexfh

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

llvm-svn: 277356
2016-08-01 17:15:57 +00:00
Kirill Bobyrev 08c47b37d3 [clang-rename] revert r276836
Revert r276836, which resulted in tests passing regardless of the actual tool
replacements.

llvm-svn: 277354
2016-08-01 16:48:33 +00:00
Jonathan Coe 5d304b2456 [clang-tidy] add check cppcoreguidelines-special-member-functions
Summary:
Check for classes that violate the rule of five and zero as specified in CppCoreGuidelines:

"If a class defines or deletes a default operation then it should define or delete them all."

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c21-if-you-define-or-delete-any-default-operation-define-or-delete-them-all.

Reviewers: alexfh, sbenza, aaron.ballman

Subscribers: Prazek, Eugene.Zelenko, cfe-commits, ericLemanissier, nemanjai

Projects: #clang-tools-extra

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

llvm-svn: 277262
2016-07-30 08:58:54 +00:00
Piotr Padlewski 8f80229109 [clang-tidy] Fixes to modernize-use-emplace
Not everything is valid, but it should works for 99.8% cases

https://reviews.llvm.org/D22208

llvm-svn: 277097
2016-07-29 02:10:23 +00:00
Saleem Abdulrasool 6fbf18ca24 test: fix typo in file name (NFC)
llvm-svn: 276949
2016-07-28 00:43:14 +00:00
Saleem Abdulrasool c67dd95697 clang-rename: adjust NamedDeclFindingASTVisitor for RecordDecls
Ensure that Context is always properly initialised in the constructor.  It is
used for querying the LangOpts in VisitTypeLoc.  Prevent a null pointer
dereference in setResult by ensuring that a RecordDecl is being handled.

Patch by Alexander Shaposhnikov!

llvm-svn: 276948
2016-07-28 00:42:01 +00:00
Kirill Bobyrev 5b7f016f41 [clang-rename] skip CXXConversionDecl while searching for NamedDecl
llvm-svn: 276866
2016-07-27 13:37:22 +00:00
Saleem Abdulrasool 8357ccf7fb test: simplify commands, NFC
Rather than copying the file and then doing an in-place edit, perform the
replacements to stdout and pass the output to FileCheck directly.  Avoids
unnecessary copying and seds.

llvm-svn: 276836
2016-07-27 04:43:15 +00:00