Commit Graph

799 Commits

Author SHA1 Message Date
Benjamin Kramer 610ba533d0 [clang-tidy] Make the named parameter check only warn on declarations if a definition is visible.
Summary:
This allows us to copy the parameter name from the definition (as a comment)
or insert /*unused*/ in both places.

Reviewers: alexfh, klimek

Subscribers: cfe-commits

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

llvm-svn: 214701
2014-08-04 09:33:58 +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 6e9142474d Plug memory leaks.
Most of the changes are mechanic std::unique_ptr insertions. All leaks were
detected by LeakSanitizer.

llvm-svn: 213851
2014-07-24 10:23:33 +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
Benjamin Kramer ddf36dea13 [clang-tidy] Fix a false positive in the make_pair checker if an argument has a explicit template argument.
This required a rather ugly workaround for a problem in ASTMatchers where
callee() is only overloaded for Stmt and Decl but not for Expr.

llvm-svn: 213509
2014-07-21 09:40:52 +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
David Blaikie 5bae2c87d5 Revert "unique_ptr-ify ownership of ASTConsumers"
This reverts commit r213308.

Reverting to have some on-list discussion/confirmation about the ongoing
direction of smart pointer usage in the LLVM project.

llvm-svn: 213324
2014-07-17 22:33:56 +00:00
David Blaikie b9574aceae unique_ptr-ify ownership of ASTConsumers
llvm-svn: 213308
2014-07-17 20:40:47 +00:00
Benjamin Kramer 01f5686298 [clang-tidy] MemsetZeroLenghtChecker: Don't crash trying to evaluate dependent values.
llvm-svn: 213238
2014-07-17 08:56:55 +00:00
Benjamin Kramer 1f14262720 [clang-tidy] Provide links to the google style guide for checks derived from it.
llvm-svn: 213233
2014-07-17 08:23:24 +00:00
Alp Toker e208dfc2af Track clang r213171
The clang rewriter is now a core facility.

llvm-svn: 213172
2014-07-16 16:50:17 +00:00
Benjamin Kramer 806bcabcda [clang-tidy] As a simple heuristic don't emit a swap fixit that would create
negative-sized memsets.

memset(x, -1, 0) is still useless but swapping makes no sense here. Just emit
a warning.

llvm-svn: 213157
2014-07-16 14:52:07 +00:00
Benjamin Kramer d6a499077a [clang-tidy] Also emit a warning for memset(x, 0, 0)
It doesn't make sense to suggest swapping the arguments here but it's
still useless code

llvm-svn: 213156
2014-07-16 14:42:43 +00:00
Benjamin Kramer ebab1500e0 [clang-tidy] Add a checker for zero-length memset.
If there's memset(x, y, 0) in the code it's most likely a mistake. The
checker suggests a fix-it to swap 'y' and '0'.

I think this has the potential to be promoted into a general clang warning
after some testing in clang-tidy.

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

llvm-svn: 213155
2014-07-16 14:30:19 +00:00
Benjamin Kramer 2252cbf4e8 [clang-tidy] Add namespaces checkers.
This change contains of two checkers that warn about
1. anonymous namespaces in header files.
2. 'using namespace' directives everywhere.

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

llvm-svn: 213153
2014-07-16 14:16:56 +00:00
Alexander Kornienko 1f317d6c05 Avoid adding redundant parens.
Reviewers: bkramer

Reviewed By: bkramer

Subscribers: cfe-commits, sbenza

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

llvm-svn: 213149
2014-07-16 13:38:48 +00:00
Benjamin Kramer b1039759fb [clang-tidy] Add a checker that warns on const string & members.
Summary:
Those are considered unsafe and should be replaced with simple pointers or
full copies. It recognizes both std::string and ::string.

Reviewers: alexfh, djasper

Subscribers: cfe-commits

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

llvm-svn: 213133
2014-07-16 10:00:14 +00:00
Benjamin Kramer 14d42d9d1e [clang-tidy] Add a checker that flags unnamed parameters.
Summary:
We still allow the escape hatch foo(int /*x*/) and also suggest this
in a fixit. This is more powerful than the corresponding cpplint.py check
it also flags functions with multiple arguments as naming all arguments is
recommended by the google style guide.

Reviewers: alexfh, djasper

Subscribers: cfe-commits

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

llvm-svn: 213075
2014-07-15 16:47:09 +00:00
Benjamin Kramer feff134142 [clang-tidy] Add a checker that flags all instances of overloaded unary operator&
This handles both methods and freestanding overloads.

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

llvm-svn: 213067
2014-07-15 12:48:14 +00:00
Benjamin Kramer 47c4d101e0 [clang-tidy] Add a checker that removes deducible arguments from std::make_pair
Those may be incompatible with C++11 and are unnecessary. We suggest
removing the template arguments when they match the types of the make_pair
arguments or replace it with std::pair and explicit template arguments when
not.

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

llvm-svn: 213058
2014-07-15 09:50:32 +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
Alexander Kornienko ad21688625 Set up clang-tidy diagnostic consumer to print types etc.
Reviewers: bkramer

Reviewed By: bkramer

Subscribers: cfe-commits

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

llvm-svn: 212941
2014-07-14 14:10:03 +00:00
Alexander Kornienko 7366616a93 Suggest automated replacements of C-style casts with C++ casts.
Summary:
This patch implements a subset of possible replacements of C-style
casts with const_cast/static_cast/reinterpret_cast. This should cover a large
portion of cases in real code. Handling of a few more cases may be implemented
eventually.

Reviewers: sbenza, djasper

Reviewed By: djasper

Subscribers: cfe-commits

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

llvm-svn: 212924
2014-07-14 07:37:05 +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
Benjamin Kramer ee58721875 [clang-tidy] Address review comments for the Twine checker.
- Remove unused includes.
- Minor wording fix.
- Added support to check for clang-tidy messages to check_clang_tidy_fix.sh
= Updated test case.

llvm-svn: 212540
2014-07-08 15:41:20 +00:00
Benjamin Kramer 190e2cfd74 [clang-tidy] Add a little checker for Twine locals in LLVM.
Those often cause use after free bugs and should be generally avoided.
Technically it is safe to have a Twine with >=2 components in a variable
but I don't think it is a good pattern to follow. The almost trivial checker
comes with elaborated fix-it hints that turn the Twine into a std::string
if necessary and otherwise fall back to the original type if the Twine
is created from a single value.

llvm-svn: 212535
2014-07-08 14:32:17 +00:00
NAKAMURA Takumi 71b982b41f clang-tidy: Instantiate llvm::Registry<clang::tidy::ClangTidyModule>.
llvm-svn: 212271
2014-07-03 14:12:47 +00:00
Alexander Kornienko 742790cd9f Consistently handle clang-tidy check names in ClangTidyError.
Summary:
This patch removes " [check-name]" from the end of
ClangTidyMessage::Message. The " [check-name]" part is only appended when
printing diagnostics on the console. Clang errors are now marked with
"clang-diagnostic-error" check name, remarks and unknown warnings are marked
with "clang-diagnostic-unknown".

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits

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

llvm-svn: 212180
2014-07-02 15:05:04 +00:00
Alexander Kornienko 94a656477d Initialize ClangTidyMessage::FileOffset field to avoid unitialized variable access when sorting errors on output.
llvm-svn: 212042
2014-06-30 14:29:03 +00:00
Alexander Kornienko e3b7839bfc Added a comment to document relation of this check to -Wold-style-cast.
llvm-svn: 212033
2014-06-30 09:54:12 +00:00
Alexander Kornienko 276fc642d3 Another attempt to add a clang-tidy check for flagging C-style casts.
Summary:
The first version failed the SubstNonTypeTempateParmExpr-related test
on some buildbots. This one uses the new substNonTypeTempateParmExpr matcher to
filter out implicit C-style casts.

This patch depends on D4327.

Reviewers: djasper

Reviewed By: djasper

Subscribers: aemerson, cfe-commits

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

llvm-svn: 212002
2014-06-29 22:19:53 +00:00
NAKAMURA Takumi 360096e701 Make clang-tidy-diff.py py3-compatible.
llvm-svn: 211834
2014-06-27 01:10:18 +00:00
Alexander Kornienko cd11179374 Rolling back, as the test fails on one of the buildbots:
http://lab.llvm.org:8011/builders/clang-hexagon-elf/builds/13505/steps/check-all/logs/Clang%20Tools%3A%3Ac-style-casts.cpp

llvm-svn: 211708
2014-06-25 15:33:35 +00:00
Alexander Kornienko 73ba424506 Add a check to flag the usage of C-style casts (Google Style).
Summary:
Add a check to flag the usage of C-style casts, as per Google Style
Guide:
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Casting#Casting

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits

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

llvm-svn: 211702
2014-06-25 14:52:44 +00:00
Alexander Kornienko 1de35e719f Add clang-tidy-diff.py script to run clang-tidy and display warnings on changed lines only.
Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits

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

llvm-svn: 211698
2014-06-25 14:09:52 +00:00
Alp Toker b5fbfa2bab Track changes from clang r211448.
llvm-svn: 211450
2014-06-21 23:33:00 +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
Alexander Kornienko 72f1e754a7 Move google-explicit-constructor check to a separate source file.
Summary: No functional changes.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits

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

llvm-svn: 211154
2014-06-18 09:33:46 +00:00
Rafael Espindola fd85bb3424 include system_error directly.
llvm-svn: 210797
2014-06-12 16:53:02 +00:00
Rafael Espindola 15c5784d3c Replace llvm::error_code with std::error_code.
llvm-svn: 210776
2014-06-12 13:32:11 +00:00
Alexander Kornienko 3095b420f4 A follow-up to r210260: updated a comment. No functional changes.
llvm-svn: 210767
2014-06-12 11:25:45 +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
Craig Topper f61be9c971 [C++11] Use 'nullptr'.
llvm-svn: 210447
2014-06-09 02:03:06 +00:00
Alexander Kornienko a46952221e Allow per-file clang-tidy options.
Summary:
This patch makes it possible for clang-tidy clients to provide
different options for different translation units. The option, which doesn't
make sense to be file-dependent, was moved to a separate ClangTidyGlobalOptions
struct. Added parsing of ClangTidyOptions.

Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

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

llvm-svn: 210260
2014-06-05 13:31:45 +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
Alexander Kornienko 348cae8e2b Never filter-out compile errors in clang-tidy, display them as errors.
Summary:
No filters should affect the display of errors. Fixed a few tests,
which had compile errors.

We need to think what we should do with mapped errors (-Werror).

Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

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

llvm-svn: 210044
2014-06-02 20:44:32 +00:00
Alexander Kornienko fbf9258582 Exit with error when no checks enabled.
Summary:
This seems like a more appropriate reaction to the user specifying a
single check with a wrong name, for example.

Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

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

llvm-svn: 210043
2014-06-02 20:32:06 +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
Alexander Kornienko 1e1ad5cf9c Renamed runClangTidy argument Ranges to InputFiles, removed a TODO comment.
No functional changes.

llvm-svn: 209743
2014-05-28 15:21:14 +00:00
Daniel Jasper 39f9f726bc clang-tidy: Only add 'override' before inlined bodies.
llvm-svn: 209505
2014-05-23 08:52:10 +00:00
Alexander Kornienko e1f62eca2d Update the code according to the changes in r209468.
llvm-svn: 209470
2014-05-22 20:19:46 +00:00
Alexander Kornienko dad4acbc52 Add clang-tidy -line-filter option to filter findings by line ranges.
Summary:
This is going to be used for a clang-tidy-diff script to display
warnings in changed lines only. The option uses JSON, as its value is not
intended to be entered manually.

Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

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

llvm-svn: 209450
2014-05-22 16:07:11 +00:00
Alexander Kornienko 16ff5c71ba Added a comment
llvm-svn: 209146
2014-05-19 17:46:28 +00:00
Alexander Kornienko bef51cdf05 Improved llvm-namespace-comment check.
Summary:
Handle various forms of existing namespace closing comments, fix
existing comments with wrong namespace name, ignore short namespaces.

The state of this check now seems to be enough to enable it by default to gather
user feedback ;)

Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

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

llvm-svn: 209141
2014-05-19 16:39:08 +00:00
Daniel Jasper 993a906af3 Address review comments on r208954. No functional changes.
llvm-svn: 209111
2014-05-19 07:23:03 +00:00
Alp Toker 124084e238 Track clang changes from r209061
llvm-svn: 209062
2014-05-17 04:54:13 +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
Alexander Kornienko 3ab3467cef Update clang-tidy documentation.
Summary:
Updated the help message, updated description of -checks=, removed
mentions of -disable-checks.

Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

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

llvm-svn: 208979
2014-05-16 13:07:18 +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
Alexander Kornienko 6262d2349c Fixed incorrect StringRef::find usage.
llvm-svn: 208898
2014-05-15 15:56:58 +00:00
Alexander Kornienko 23fe95904c Change the behavior of clang-tidy -checks=, remove -disable-checks.
Summary:
Make checks filtering more intuitive and easy to use. Remove
-disable-checks and change the format of -checks= to a comma-separated list of
globs with optional '-' prefix to denote exclusion. The -checks= option is now
cumulative, so it modifies defaults, not overrides them. Each glob adds or
removes to the current set of checks, so the filter can be refined or overriden
by adding globs.

Example:
  The default value for -checks= is
  '*,-clang-analyzer-alpha*,-llvm-include-order,-llvm-namespace-comment,-google-*',
  which allows all checks except for the ones named clang-analyzer-alpha* and
  others specified with the leading '-'. To allow all google-* checks one can
  write:
    clang-tidy -checks=google-* ...
  If one needs only google-* checks, we first need to remove everything (-*):
    clang-tidy -checks=-*,google-*
  etc.

I'm not sure if we need to change something here, so I didn't touch the docs
yet.

Reviewers: klimek, alexfh

Reviewed By: alexfh

Subscribers: cfe-commits

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

llvm-svn: 208883
2014-05-15 14:27:36 +00:00
Benjamin Kramer 281f9d0e97 Update for Clang API change and move ClangTidyDiagnosticRenderer into an anonymous namespace while there.
llvm-svn: 208471
2014-05-10 16:32:07 +00:00
Alexander Kornienko c0093609b0 Allow ClangTidyDiagnosticConsumer to be reused.
llvm-svn: 208420
2014-05-09 15:50:15 +00:00
Alexander Kornienko 826b5adb6c Store Errors inside ClangTidyContext instead of just pointer to an external
array. This simplifies usage of ClangTidyContext a bit and seems to be more
consistent.

Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

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

llvm-svn: 208407
2014-05-09 12:24:09 +00:00
Alexander Kornienko 5d174547a9 Print stats on displayed and ignored warnings.
Summary:
Also displays a hint to use -header-filter='.*' in case any warnings
are in non-user code. This will help discoverability of this option.

Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

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

llvm-svn: 208174
2014-05-07 09:06:53 +00:00
Alexander Kornienko 238795e9c6 Fix a crash when diagnostic points to a macro definition on command line.
Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

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

llvm-svn: 208068
2014-05-06 08:10:00 +00:00
Alexander Kornienko 4aab579d07 Fix assertion in google-explicit-constructor check when the constructor is
defined in a macro.

Summary:
We shouldn't suggest replacements in macros anyway, as we can't see all
usages of the macro and ensure the replacement is safe for all of them.

Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

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

llvm-svn: 207987
2014-05-05 18:49:31 +00:00
Alexander Kornienko 9ff5b6f3ca Add clang-tidy -header-filter option
Summary:
Add clang-tidy -header-filter option to specify from which headers we
want diagnostics to be printed. By default we don't print diagnostics from
headers. We always print diagnostics from the main file of each translation
unit.

Reviewers: djasper, klimek

Reviewed By: klimek

Subscribers: klimek, cfe-commits

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

llvm-svn: 207970
2014-05-05 14:54:47 +00:00
Alex McCarthy 3b510bc43d Fix ClangTidyOptions constructor to initialize all members. Fixes bug introduced in r207652.
Reviewers: rsmith

Subscribers: cfe-commits, alexfh, klimek

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

llvm-svn: 207715
2014-04-30 22:32:51 +00:00
Alex McCarthy fec08c72be Add a clang-tidy flag to support temporary destructor-aware analysis (workaround for bug 15599).
Reviewers: alexfh

Subscribers: jordan_rose, klimek, djasper, cfe-commits

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

llvm-svn: 207652
2014-04-30 14:09:24 +00:00
Alexander Kornienko 3b26849f38 Fix the message for "Move constructor declared explicit".
Make the tests for removal of 'explicit' more diverse.

llvm-svn: 207534
2014-04-29 15:50:14 +00:00
Alexander Kornienko 33a9bcce29 Add ClangTidyOptions to encapsulate all clang-tidy options.
Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits

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

llvm-svn: 207532
2014-04-29 15:20:10 +00:00
Alexander Kornienko 014225e11e Warn on explicit copy constructors.
Summary:
The Google C++ Style Guide doesn't require copy constructors to be
declared explicit, but some people do this by mistake. Make this check detect
and fix such cases.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits

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

llvm-svn: 207531
2014-04-29 15:07:08 +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
Alex McCarthy 5bc902e8e1 Fix typo (first commit to test commit access).
llvm-svn: 207490
2014-04-29 02:33:58 +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
Alexander Kornienko 9eb8c92b52 Output clang-tidy errors in a consistent order.
Summary: Sort errors by path, file offset and message.

Reviewers: djasper, klimek

Reviewed By: djasper

CC: cfe-commits

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

llvm-svn: 205759
2014-04-08 12:27:49 +00:00
Daniel Jasper 7b8d263998 Fix regex bug in clang-tidy.
Also make tests slightly less dependent on default flags. Once we have
implemented configuration file support, we might want to store the
clang-tidy configuration for the tests there.

llvm-svn: 205408
2014-04-02 08:52:06 +00:00
Daniel Jasper a3b8f0cf7d Disable a few clang-tidy checks by default.
The goal is to be able to run clang-tidy on LLVM files without further
configuration for now. Once llvm.org/PR19306 is addressed, we can add a
configuration file instead and choose other defaults.

llvm-svn: 205407
2014-04-02 08:27:12 +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 4dd1813043 ClangTidy.cpp: Don't use non-static member initializer, for msc17.
llvm-svn: 204931
2014-03-27 14:53:37 +00:00
Alexander Kornienko 38d81b41eb Output messages when clang-tidy applies fix-its.
Reviewers: djasper, klimek

Reviewed By: djasper

CC: cfe-commits

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

llvm-svn: 204909
2014-03-27 10:24:11 +00:00
NAKAMURA Takumi 338eee1964 ClangTidyContext: Don't use initializer on non-static member.
llvm-svn: 204333
2014-03-20 10:53:03 +00:00
Alexander Kornienko f65a549a82 clang-tidy explicit constructor check: don't warn on copy or move constructors.
Summary:
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Explicit_Constructors
"The exception is copy constructors, which, in the rare cases when we allow
them, should probably not be explicit."

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 204322
2014-03-20 09:39:36 +00:00
Alexander Kornienko 09952d2d71 Post-filter clang-tidy diagnostic messages.
Summary:
This patch implements filtering of clang-tidy diagnostic messages by
the check name, so that "clang-tidy -checks=^llvm-" won't output any clang
warnings, for example. This is also helpful to run specific static-analyzer
checks: static analyzer always needs core checks to be enabled, but the user may
be interested only in the checks he asked for.

This patch also exposes warning option names for built-in diagnostics. We need
to have a namespace for these names to avoid collisions and to allow convenient
filtering, so I prefix them with "-W". I'm not sure it's the best thing to do,
and maybe "W" or "clang-diagnostic-" or something like this would be better.

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 204321
2014-03-20 09:38:22 +00:00
Alexander Kornienko f9a7b46ec6 clang-tidy explicit constructors check: don't warn on deleted constructors.
Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 204226
2014-03-19 12:48:22 +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 6fbc619ab9 Use DiagnosticRenderer to convert clang diagnostics to clang-tidy ones.
Summary:
This is immediately useful for generating macro expansion notes, and
may be useful for other things later on.

Reviewers: klimek, djasper

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 203457
2014-03-10 13:11:17 +00:00
Alexander Kornienko 33a0bce133 Deduplicate clang-tidy error messages by file, offset and message.
Summary: Peter, I guess, this can help you in testing your check.

Reviewers: djasper, pcc, klimek

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 203451
2014-03-10 09:45:49 +00:00
Ahmed Charles 6a2dc5c381 [C++11] Replace OwningPtr with std::unique_ptr.
This removes all references to OwningPtr, which should be fairly
undisruptive to out-of-tree projects since they are unlikely to use
clang-tools-extra as a library instead of a set of tools.

llvm-svn: 203382
2014-03-09 09:24:40 +00:00
Alexander Kornienko 95cd50f6d1 Use the appropriate operator<< instead of addRanges.
llvm-svn: 203118
2014-03-06 13:24:28 +00:00
Alexander Kornienko df1e3cb157 Use range-based for loops for better readability. No functional changes intended.
Reviewers: chandlerc

Reviewed By: chandlerc

CC: cfe-commits

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

llvm-svn: 203101
2014-03-06 10:17:46 +00:00
Alexander Kornienko 9de3a98c4e Fixed a crash when handling diagnostics without a valid file location, e.g. 'error reading <file>'.
llvm-svn: 202987
2014-03-05 15:44:36 +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
Alexander Kornienko 21f3b77707 Fixed formatting.
llvm-svn: 202969
2014-03-05 13:01:24 +00:00
Chandler Carruth edc9e38810 [cleanup] Re-sort headers with llvm/utils/sort_includes.py.
llvm-svn: 202809
2014-03-04 10:03:05 +00:00
Craig Topper 6d73f449b8 Determine support for colored output from stdout instead of stderr since that's where the diagnostics go.
llvm-svn: 202680
2014-03-03 07:37:42 +00:00
Peter Collingbourne b17a3b3d33 Add a level parameter to ClangTidyCheck::diag.
The goal is to make it possible for checks to emit diagnostics at levels
other than 'warning'.

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

llvm-svn: 202668
2014-03-02 23:34:48 +00:00
Craig Topper a3dbe84166 [C++11] Replace LLVM_OVERRIDE with 'override'
llvm-svn: 202632
2014-03-02 10:20:11 +00:00
Alexander Kornienko 31219d3abd Added a naive NOLINT implementation.
Summary:
Added a naive NOLINT implementation. It doesn't care about specific
linter categories, just the "// NOLINT" on the same line as a diagnostic.

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 202452
2014-02-28 00:27:50 +00:00
Alexander Kornienko cb9272fe66 Normalized "virtual" and "LLVM_OVERRIDE" usage in clang-tidy.
Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 202392
2014-02-27 13:14:51 +00:00
NAKAMURA Takumi 9698686505 [CMake] Use LINK_LIBS instead of target_link_libraries().
llvm-svn: 202238
2014-02-26 06:41:29 +00:00
NAKAMURA Takumi 871d104e1c [CMake] Apply DEPENDS to clangTidy.
llvm-svn: 201977
2014-02-23 13:43:01 +00:00
Alexander Kornienko d68aa4c0fc Re-add the '!' removed by mistake.
llvm-svn: 201343
2014-02-13 16:29:39 +00:00
Alexander Kornienko 298b3823b5 Clang-tidy: don't create ASTConsumers not needed for the set of checks we perform.
Summary:
This doesn't have any significant effect on the performance, but it
looks like a good thing to do.

Reviewers: djasper, klimek

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 201340
2014-02-13 16:10:47 +00:00
Alexander Kornienko 32eaa37b15 Fix ExplicitConstructorCheck to warn only on in-class declarations.
Summary:
I'm not absolutely sure this is 100% correct solution, but it seems to
do what I expect.

Reviewers: djasper, klimek

Reviewed By: djasper

CC: cfe-commits

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

llvm-svn: 201308
2014-02-13 10:11:48 +00:00
Alexander Kornienko d1afc70795 Consume checker names from clang static analyzer.
Summary: This patch depends on patches D2556 and D2557.

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits, jordan_rose, krememek

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

llvm-svn: 201221
2014-02-12 09:52:07 +00:00
Nick Lewycky ccf8e29060 The diagnostic printer expects the LangOptions to still be alive. Give it one that lives at least as long as all the uses of it. This is still wrong though, we should be passing in the correct LangOpts for a given source file.
llvm-svn: 200952
2014-02-06 22:57:16 +00:00
Alexander Kornienko 54461eb389 Improve clang-tidy diagnostic output and filtering.
Summary:
This patch introduces several improvements to clang-tidy diagnostic;
  1. Make filtering of messages from non-user code more reliable. Output an
     error when it or any of the related notes touches user code. This fixes an
     assertion when an error has a location in a system header, and one of the
     notes relates to user code.
  2. In order for 1. to work, subscribe to the static analyzer diagnostics using
     a custom PathDiagnosticConsumer.
  3. Enable colors on supported terminals.
  4. Output FixItHints.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits

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

llvm-svn: 200924
2014-02-06 14:50:10 +00:00
Alexander Kornienko 99c9d6a0f6 Make the OptionCategory variable static.
llvm-svn: 200841
2014-02-05 13:43:27 +00:00
Alexander Kornienko 6d129d5454 Fix crash when handling an argument parsing-related warning.
Summary: Don't crash on warnings coming before the translation unit starts.

Reviewers: klimek, djasper

Reviewed By: djasper

CC: cfe-commits

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

llvm-svn: 200702
2014-02-03 15:55:35 +00:00
Alp Toker a143676664 Fix another invalid getCustomDiagID() use to unbreak the build
It was calling the utility wrapper that now requires a constant string
following clang r200132. The StringRef version on DiagnosticIDs appears to have
been what was intended so change to that.

llvm-svn: 200142
2014-01-26 08:36:03 +00:00
Alp Toker 82f8c50a73 Prospective build fix for unsafe usage of getCustomDiagID()
This now requires a compile-time constant string so let's build proper
diagnostic IDs and pass through the inputs as arguments.

Tracks clang changes in r200132.

llvm-svn: 200139
2014-01-26 06:58:01 +00:00
Alexander Kornienko 41bfe8dde1 Add the check name to the clang-tidy diagnostic output.
Summary:
Pass check names all the way from ClangTidyModule through
ClangTidyCheck and ClangTidyContext to ClangTidyError, and output it in
handleErrors. This allows to find mis-behaving check and disable it easily.

Reviewers: djasper, klimek

Reviewed By: djasper

CC: cfe-commits

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

llvm-svn: 199094
2014-01-13 10:50:51 +00:00
Alexander Kornienko 0ba86b73aa Re-applied r198807, r198808 with an additional change to fix linking in configure Release+Asserts build.
llvm-svn: 198875
2014-01-09 16:31:25 +00:00
Alexander Kornienko 73f7b0273e Reverted r198807, r198808, as they cause link errors in configure builds. Will look at this later.
llvm-svn: 198832
2014-01-09 02:21:52 +00:00
Alexander Kornienko 875288bd82 Updated file comment.
llvm-svn: 198808
2014-01-08 23:35:01 +00:00
Alexander Kornienko a89f99c1e2 Restructured code, no functional changes.
Summary:
Moved implementation of classes declared in
ClangTidyDiagnosticConsumer.h to ClangTidyDiagnosticConsumer.cpp.
Added a FIXME note in ClangTidyDiagnosticConsumer::HandleDiagnostic.

Reviewers: klimek, djasper

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 198807
2014-01-08 23:30:40 +00:00
Alexander Kornienko 86d305c779 Don't emit diagnostics for system headers.
Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits

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

llvm-svn: 198767
2014-01-08 15:21:08 +00:00
Chandler Carruth 85e6e87171 Run llvm/utils/sort_includes.py over the Clang tools code. This doesn't
always produce as pretty of results as it does in LLVM and Clang, but
I don't mind and the value of having a single canonical ordering is very
high IMO.

Let me know if you spot really serious problems here.

llvm-svn: 198703
2014-01-07 20:05:01 +00:00
Alexander Kornienko d1199cb4f0 A follow-up to r198426: move AnalysisConsumer.h to include/clang/...
llvm-svn: 198427
2014-01-03 17:24:20 +00:00
Alexander Kornienko fc58987f00 Clear the diagnostic buffer after flushing it.
Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 198423
2014-01-03 15:34:40 +00:00
Alexander Kornienko b045d8bc07 Rework of r198404 to avoid changes in the build configuration.
llvm-svn: 198405
2014-01-03 10:50:17 +00:00
NAKAMURA Takumi 321b7d35e5 clang-tody: Rework r198403, to fix build.
llvm-svn: 198404
2014-01-03 10:24:51 +00:00
NAKAMURA Takumi 4fd9913803 clang-tidy: Fix build since r198402 in the case that the source tree of clang-tools-extra is not located on clang/tools/extra.
FIXME: Get rid of private headers in other modules.
llvm-svn: 198403
2014-01-03 09:49:13 +00:00
Alexander Kornienko 175fefbda3 Refactored Clang-tidy for better reusability.
Summary:
Made ClangTidyAction more slim and moved its declaration to header to
allow easy creation of Clang-tidy ASTConsumer. Don't derive from
clang::ento::AnalysisAction, use clang::ento::CreateAnalysisConsumer instead
(I'll propose making this function a part of a public API in a separate patch).

Use MultiplexConsumer instead of a custom class.

Don't re-filter checkers list for each TU.

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits

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

llvm-svn: 198402
2014-01-03 09:31:57 +00:00
Alexander Kornienko fb9e92b167 Clang-tidy: added --disable-checks, --list-checks options.
Summary:
Allow disabling checks by regex. By default, disable alpha.* checks,
that are not particularly good tested (e.g. IdempotentOperationChecker, see
http://llvm-reviews.chandlerc.com/D2427).

Fixed a bug, that would disable all analyzer checks, when using a regex more
strict, than 'clang-analyzer-', for example --checks='clang-analyzer-deadcode-'.

Added --list-checks to list all enabled checks. This is useful to test specific
values in --checks/--disable-checks.

Reviewers: djasper, klimek

Reviewed By: klimek

CC: cfe-commits, klimek

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

llvm-svn: 197717
2013-12-19 19:57:05 +00:00
Alexander Kornienko 06ff5a7235 Fix the usage of the CommonOptionsParser ctor changed in r197139.
llvm-svn: 197141
2013-12-12 10:01:39 +00:00
NAKAMURA Takumi 78f534d689 [CMake] clang-tools-extra: Update dependencies.
llvm-svn: 196860
2013-12-10 01:41:10 +00:00
NAKAMURA Takumi ff9225f3d7 [CMake] clang-tools-extra may not depend on LLVM CodeGen.
llvm-svn: 196805
2013-12-09 19:27:57 +00:00
Alp Toker 9a5134e6be Fix a variety of user-visible and comment typos
llvm-svn: 196038
2013-12-01 05:08:12 +00:00
Manuel Klimek fe3f34e50b Always add core checkers if static analyzer checks are enabled.
In response to post-commit feedback by Jordan, this is required to
make sure path-sensitive checks work correctly.

llvm-svn: 194807
2013-11-15 11:19:56 +00:00
Manuel Klimek 814f9bd93a Make clang's static analyzer checks available through clang-tidy.
This is implemented in a way that the current static analyzer
architecture allows, in the future we might want to revisit this.

With this change static analyzer checks are available from clang-tidy
by specifying -checks=clang-analyzer-<name>.

This change also fixes the use of the compilation database to allow
clang-tidy to be used like any other clang tool.

llvm-svn: 194707
2013-11-14 15:49:44 +00:00
Benjamin Kramer d989ef4373 clang-tidy's modules depend on it.
Fixes shared cmake build.

llvm-svn: 187708
2013-08-04 16:06:43 +00:00
Daniel Jasper 89bbab09dd Fix clang-tidy dependencies and bad file comment.
This addresses comments in post-commit review of r187345.

llvm-svn: 187707
2013-08-04 15:56:30 +00:00
Hans Wennborg 97dd3d207a Remove dead #includes.
llvm-svn: 187536
2013-07-31 22:28:46 +00:00
Daniel Jasper 03524b774a Fix build error caused by r187345.
llvm-svn: 187346
2013-07-29 08:43:57 +00:00
Daniel Jasper d07c840e6a Initial architecture for clang-tidy.
This is the first version of a possible clang-tidy architecture. The
purpose of clang-tidy is to detect errors in adhering to common coding
patterns, e.g. described in the LLVM Coding Standards.

This is still heavily in flux.

Review: http://llvm-reviews.chandlerc.com/D884
llvm-svn: 187345
2013-07-29 08:19:24 +00:00