Commit Graph

45 Commits

Author SHA1 Message Date
Chandler Carruth 3cbd71c03b [cleanup] Re-sort the #include lines with llvm/utils/sort_includes.py
No functionality changed, this is just a mechanical cleanup to keep the
order of #include lines consistent across the project.

llvm-svn: 225976
2015-01-14 11:24:38 +00:00
Daniel Jasper e73cfbf6ba clang-tidy: [misc-use-override] Fix 'override' insertion.
Before:
  void f() __attribute__((override unused))

After:
  void f() override __attribute__((unused))

llvm-svn: 225519
2015-01-09 13:56:35 +00:00
Alexander Kornienko bc0c423a46 [clang-tidy] Add clang-tidy check for unique_ptr's reset+release -> move
Replace x.reset(y.release()); with x = std::move(y);
If y is rvalue, replace with x = y; instead.

http://reviews.llvm.org/D6485

Patch by Alexey Sokolov!

llvm-svn: 223460
2014-12-05 11:59:05 +00:00
Daniel Jasper 4525be4ebc clang-tidy: Add override before the first attribute.
Apparently attributes aren't sorted by source location.

llvm-svn: 222751
2014-11-25 10:45:23 +00:00
Alexander Kornienko 2192a8e519 [clang-tidy] Bring order to check registration.
Summary:
Register readability checks in a separate module. Renamed the checks
and test file names accordingly.

Reviewers: djasper, klimek

Reviewed By: klimek

Subscribers: curdeius, cfe-commits

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

llvm-svn: 220631
2014-10-26 01:41:14 +00:00
Alexander Kornienko 35ddae4a9b [clang-tidy] Move some of the misc checks to readability/
Summary:
Some of the misc checks belong to readability/. I'm moving them there
without changing check names for now. As the next step, I want to register some
of these checks in the google and llvm modules with suitable settings (e.g.
BracesAroundStatementsCheck). I'm not sure if we want to create a "readability"
module, probably not.

Reviewers: djasper

Reviewed By: djasper

Subscribers: curdeius, cfe-commits

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

llvm-svn: 219786
2014-10-15 10:51:57 +00:00
Alexander Kornienko f305000a91 [clang-tidy] misc-braces-around-statements.ShortStatementLines option
Add option ShortStatementLines to trigger this check only if the statement spans
over at least a given number of lines.

Modifications from the original patch:
  merged test/clang-tidy/misc-braces-around-statements-always.cpp into
  test/clang-tidy/misc-braces-around-statements.cpp and removed unnecessary
  CHECK-NOTs from the tests.

http://reviews.llvm.org/D5642

Patch by Marek Kurdej!

llvm-svn: 219611
2014-10-13 12:46:22 +00:00
Alexander Kornienko 8f7e7f73ea [clang-tidy] Add check misc-braces-around-statements.
This check looks for if statements and loops: for, range-for, while and
do-while, and verifies that the inside statements are inside braces '{}'.
If not, proposes to add braces around them.

Example:

  if (condition)
    action();

becomes

  if (condition) {
    action();
  }

This check ought to be used with the -format option, so that the braces be
well-formatted.


Patch by Marek Kurdej!

http://reviews.llvm.org/D5395

llvm-svn: 218898
2014-10-02 19:09:56 +00:00
Benjamin Kramer 6e195426e7 [clang-tidy] Add a checker for long functions.
As this is very dependent on the code base it has some ways of configuration.
It's possible to pick between 3 modes of operation:

- Line counting: number of lines including whitespace and comments
- Statement counting: number of statements within compoundStmts.
- Branch counter

In addition a threshold can be picked, warnings are only emitted when it is met.
The thresholds can be configured via a .clang-tidy file.

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

llvm-svn: 217768
2014-09-15 12:48:25 +00:00
Alexander Kornienko 6e0cbc8947 Implemented clang-tidy-check-specific options.
Summary:
Each check can implement readOptions and storeOptions methods to read
and store custom options. Each check's options are stored in a local namespace
to avoid name collisions and provide some sort of context to the user.

Reviewers: bkramer, klimek

Reviewed By: klimek

Subscribers: cfe-commits

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

llvm-svn: 217661
2014-09-12 08:53:36 +00:00
Alexander Kornienko be8c143dd6 Unique-ptrify ClangTidyCheckFactories. Add a more convenient alternative to
addCheckFactory: registerCheck.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits

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

llvm-svn: 217489
2014-09-10 11:06:43 +00:00
Alexander Kornienko 805b44d124 ClangTidy misc-argument-comment check: don't check arguments to template
parameter packs.

Summary:
This disables this check for std::bind and similar functions that use
parameter packs to forward arguments to a different function. Name of the
parameter pack argument doesn't matter.

Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

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

llvm-svn: 217039
2014-09-03 14:56:30 +00:00
Benjamin Kramer 6bcbe6e04d [clang-tidy] Eliminate inline copies of InTemplateInstantiation matcher.
llvm-svn: 217036
2014-09-03 13:30:28 +00:00
Benjamin Kramer b7f59d6bbd [clang-tidy] Use new ASTMatchers to identify template instantiations instead of copying it everywhere.
No intended functionality change.

llvm-svn: 217035
2014-09-03 13:21:51 +00:00
Benjamin Kramer 242b5b808b [clang-tidy] Disable the warning on implicit bool* to bool conversion in macros.
It's just too noisy and the warning isn't very helpful in those cases.

llvm-svn: 215439
2014-08-12 12:12:57 +00:00
Benjamin Kramer f5847cf84c [clang-tidy] Rewrite a for-range loop in the old style.
Haven't thought that I ever needed to do this, but in this case comparing the
index using pointer arithmetic turns out to be really ugly. It also generates
nasty sign-compare warnings on 32 bit targets.

llvm-svn: 214705
2014-08-04 10:11:47 +00:00
Benjamin Kramer 1188792480 [clang-tidy] Add a checker for code that looks like a delegate constructors but doesn't delegate.
Summary:
class Foo {
  Foo() {
    Foo(42); // oops
  }
  Foo(int);
};

This is valid code but it does nothing and we can't emit a warning in clang
because there might be side effects. The checker emits a warning for this
pattern and also for base class initializers written in this style.

There is some overlap with the unused-rtti checker but they follow different
goals and fire in different places most of the time.

Reviewers: alexfh, djasper

Subscribers: cfe-commits

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

llvm-svn: 214397
2014-07-31 09:58:52 +00:00
Alexander Kornienko 326e48cd09 Don't warn on NewCallback argument comments, as they are arguments for the
function the callback points to.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits

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

llvm-svn: 214307
2014-07-30 14:31:36 +00:00
Daniel Jasper 2d9e0b782c clang-tidy: [use-override] Tweak messages.
It doesn't make sense to suggest 'virtual' as clang-tidy would complain
about that on the next iteration (we are never issuing warnings for the
base function).

llvm-svn: 214063
2014-07-28 07:29:29 +00:00
Benjamin Kramer c1730e9bb9 [clang-tidy] Fix a heap use-after-free bug detected by asan.
llvm-svn: 213845
2014-07-24 08:34:42 +00:00
Benjamin Kramer 4ff1ffa1ce Add the fix that should've accompanied r213738.
llvm-svn: 213740
2014-07-23 11:50:54 +00:00
Benjamin Kramer da3658e2b7 Reapply r213647 with a fix.
ASTMatchers currently have problems mixing bound TypeLoc nodes with Decl/Stmt
nodes. That should be fixed soon but for this checker there we only need the
TypeLoc to generate a fixit so postpone the potentially heavyweight AST walking
until after we know that we're going to emit a warning.

This is covered by existing test cases.

Original message:
[clang-tidy] Add a check for RAII temporaries.

This tries to find code similar that immediately destroys
an object that looks like it's trying to follow RAII.
  {
    scoped_lock(&global_mutex);
    critical_section();
  }

This checker will have false positives if someone uses this pattern
to legitimately invoke a destructor immediately (or the statement is
at the end of a scope anyway). To reduce the number we ignore this
pattern in macros (this is heavily used by gtest) and ignore objects
with no user-defined destructor.

llvm-svn: 213738
2014-07-23 11:49:46 +00:00
Richard Smith a714469d02 Revert r213647; the added test triggers an assertion.
llvm-svn: 213722
2014-07-23 04:13:00 +00:00
Benjamin Kramer 8ca8651171 [clang-tidy] Add a check for RAII temporaries.
Summary:
This tries to find code similar that immediately destroys
an object that looks like it's trying to follow RAII.
  {
    scoped_lock(&global_mutex);
    critical_section();
  }

This checker will have false positives if someone uses this pattern
to legitimately invoke a destructor immediately (or the statement is
at the end of a scope anyway). To reduce the number we ignore this
pattern in macros (this is heavily used by gtest) and ignore objects
with no user-defined destructor.

Reviewers: alexfh, djasper

Subscribers: cfe-commits

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

llvm-svn: 213647
2014-07-22 12:30:35 +00:00
Daniel Jasper 58ed9c9167 clang-tidy: [misc-use-override] Slightly tweak the wording of warning.
'final' should really be used with care.

llvm-svn: 213501
2014-07-21 06:06:38 +00:00
Benjamin Kramer 082bf7f637 [clang-tidy] Add a checker for swapped arguments.
This looks for swapped arguments by looking at implicit conversions of arguments

void Foo(int, double);
Foo(1.0, 3); // Most likely a bug

llvm-svn: 212942
2014-07-14 14:24:30 +00:00
NAKAMURA Takumi 23b702c8de [CMake] Update libdeps.
llvm-svn: 212920
2014-07-14 05:01:53 +00:00
Benjamin Kramer 1c8b31753b [clang-tidy] Add a checker for implicit bool conversion of a bool*.
The goal is to find code like the example below, which is likely a typo
where someone meant to write "if (*b)".
bool *b = SomeFunction();
 if (b) {
   // b never dereferenced
 }

This checker naturally has a relatively high false positive rate so it
applies some heuristics to avoid cases where the pointer is checked for
nullptr before being written.

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

llvm-svn: 212797
2014-07-11 08:08:47 +00:00
Daniel Jasper 024ebf4a65 clang-tidy: [misc-use-override] Correctly handle defaulted destructors.
Also, minor implementation and test fixes.

llvm-svn: 211345
2014-06-20 09:12:46 +00:00
Daniel Jasper 05bdb09da1 clang-tidy: [use-override] Remove 'override' if 'final' is also present.
Also, make warning more precise by distinguishing different cases.

llvm-svn: 210651
2014-06-11 12:18:24 +00:00
Daniel Jasper 0ab7902755 clang-tidy use override: Don't generate incorrect warnings without fixes
Add basic testing for the emitted diagnostics.

llvm-svn: 210171
2014-06-04 08:26:02 +00:00
Daniel Jasper 88996755cb clang-tidy: Extend the use-override check to understand 'final'.
llvm-svn: 210031
2014-06-02 15:22:22 +00:00
Daniel Jasper a2332425c4 Revert "Remove redundant check discovered in post-commit review of r209505."
This breaks with MSVC.
With IsLateTemplateParsed, FunctionDecl::doesThisDeclarationHaveABody() returns true regardless of Body.

This reinstates what was fixed in r208985.

llvm-svn: 209896
2014-05-30 13:31:14 +00:00
Daniel Jasper 5070c18928 Remove redundant check discovered in post-commit review of r209505.
llvm-svn: 209882
2014-05-30 09:21:17 +00:00
Daniel Jasper 39f9f726bc clang-tidy: Only add 'override' before inlined bodies.
llvm-svn: 209505
2014-05-23 08:52:10 +00:00
Daniel Jasper 993a906af3 Address review comments on r208954. No functional changes.
llvm-svn: 209111
2014-05-19 07:23:03 +00:00
NAKAMURA Takumi 81774baf4d Initializer list is unavailable. Use the constructor instead.
llvm-svn: 208986
2014-05-16 13:37:20 +00:00
NAKAMURA Takumi 2dd94635d4 clang-tidy/misc/UseOverride.cpp: Appease targeting msvc.
With IsLateTemplateParsed, FunctionDecl::doesThisDeclarationHaveABody() returns True regardless of Body.

llvm-svn: 208985
2014-05-16 13:37:08 +00:00
Daniel Jasper 2378ebd537 Initial version of clang-tidy check to use override instead of virual.
Review: http://reviews.llvm.org/D3688
llvm-svn: 208954
2014-05-16 09:30:09 +00:00
Samuel Benzaquen 20e93f39c1 Do not touch get() calls on 'this' object.
Summary:
These calls are part of the implementation of the smart pointer itself
and chaning it is likely to be wrong.
Example:
  T& operator*() const { return *get(); }

Reviewers: djasper

Subscribers: cfe-commits

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

llvm-svn: 207525
2014-04-29 13:41:23 +00:00
Samuel Benzaquen 110f3cc45a Extend the check to detect patterns like 'ptr.get() == nullptr'
Summary:
Extend the check to detect patterns like 'ptr.get() == nullptr'
It detects == and != when any argument is a ptr.get() and the other is a
nullptr.
Only supports standard smart pointer types std::unique_ptr and std::shared_ptr.
Does not support the case 'ptr.get() == other.get()' yet.

Reviewers: djasper

CC: cfe-commits, alexfh

Differential Revision: http://llvm-reviews.chandlerc.com/D3294

llvm-svn: 205854
2014-04-09 14:17:23 +00:00
Samuel Benzaquen 3a571019c8 Add clang-tidy check to remove redundant .get() calls on smart pointers.
Summary:
This check finds and removes redundant .get() calls on smart pointers.
Example:
  ptr.get()->Foo()   ==>   ptr->Foo()

Reviewers: alexfh

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D3186

llvm-svn: 204947
2014-03-27 17:42:26 +00:00
NAKAMURA Takumi afc4965d4d clang-tidy/ArgumentCommentCheck: Initializer list in non-static members is unavailable on msc17.
llvm-svn: 204121
2014-03-18 07:22:43 +00:00
Peter Collingbourne 35c3f61d74 Add an argument comment checker to clang-tidy.
This checks that parameters named in comments that appear before arguments in
function and constructor calls match the parameter name used in the callee's
declaration. For example:

void f(int x, int y);

void g() {
  f(/*y=*/0, /*z=*/0);
}

contains two violations of the policy, as the names 'x' and 'y' used in the
declaration do not match names 'y' and 'z' used at the call site.

I think there is significant value in being able to check/enforce this policy
as a way of guarding against accidental API misuse and silent breakages
caused by API changes.

Although this pattern appears somewhat frequently in the LLVM codebase,
this policy is not prescribed by the LLVM coding standards at the moment,
so it lives under 'misc'.

Differential Revision: http://llvm-reviews.chandlerc.com/D2914

llvm-svn: 204113
2014-03-18 04:46:45 +00:00
Alexander Kornienko 16ac6cebcf Added a module for checks not related to LLVM or Google coding style.
llvm-svn: 202970
2014-03-05 13:14:32 +00:00