Commit Graph

1564 Commits

Author SHA1 Message Date
Jonas Toth cd207f1552 [clang-tidy] new check: bugprone-branch-clone
Summary:
Implement a check for detecting if/else if/else chains where two or more
branches are Type I clones of each other (that is, they contain identical code)
and for detecting switch statements where two or more consecutive branches are
Type I clones of each other.

Patch by donat.nagy.

Reviewers: alexfh, hokein, aaron.ballman, JonasToth

Reviewed By: JonasToth

Subscribers: MTC, lebedev.ri, whisperity, xazax.hun, Eugene.Zelenko, mgorny, rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 348343
2018-12-05 09:16:25 +00:00
Jonas Toth c361e0d627 Fix a false positive in misplaced-widening-cast
Summary:
bugprone-misplaced-widening-cast check
used to give a false warning to the
following example.

 enum DaysEnum{
    MON = 0,
    TUE = 1
    };

 day = (DaysEnum)(day + 1);
 //warning: either cast from 'int' to 'DaysEnum' is ineffective...

But i think int to enum cast is not widening neither ineffective.

Patch by dkrupp.

Reviewers: JonasToth, alexfh

Reviewed By: alexfh

Subscribers: rnkovacs, Szelethus, gamesh411, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 348341
2018-12-05 08:29:56 +00:00
Stephane Moore af4755aca8 [clang-tidy/checks] Update objc-property-declaration check to allow arbitrary acronyms and initialisms 🔧
Summary:
§1 Description

This changes the objc-property-declaration check to allow arbitrary acronyms and initialisms instead of using whitelisted acronyms. In Objective-C it is relatively common to use project prefixes in property names for the purposes of disambiguation. For example, the CIColor¹ and CGColor² properties on UIColor both represent symbol prefixes being used in proeprty names outside of Apple's accepted acronyms³. The union of Apple's accepted acronyms and all symbol prefixes that might be used for disambiguation in property declarations effectively allows for any arbitrary sequence of capital alphanumeric characters to be acceptable in property declarations. This change updates the check accordingly.

The test variants with custom configurations are deleted as part of this change because their configurations no longer impact behavior. The acronym configurations are currently preserved for backwards compatibility of check configuration.

[1] https://developer.apple.com/documentation/uikit/uicolor/1621951-cicolor?language=objc
[2] https://developer.apple.com/documentation/uikit/uicolor/1621954-cgcolor?language=objc
[3] https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/APIAbbreviations.html#//apple_ref/doc/uid/20001285-BCIHCGAE

§2 Test Notes

Changes verified by:
• Running clang-tidy unit tests.
• Used check_clang_tidy.py to verify expected output of processing objc-property-declaration.m

Reviewers: benhamilton, Wizard

Reviewed By: benhamilton

Subscribers: jfb, cfe-commits

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

llvm-svn: 348331
2018-12-05 03:44:03 +00:00
Stephane Moore f6d96e0f98 [clang-tidy] Ignore namespaced and C++ member functions in google-objc-function-naming check 🙈
Summary: The google-objc-function-naming check applies to functions that are not namespaced and should not be applied to C++ member functions. Such function declarations should be ignored by the check to avoid false positives in Objective-C++ sources.

Reviewers: benhamilton, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 348317
2018-12-04 23:40:42 +00:00
Jonas Toth 3f51ee19ae [clang-tidy] Fix unordered_map failure with specializing std::hash<> and remove previous wrong attempt at doing so
llvm-svn: 348172
2018-12-03 19:41:04 +00:00
Jonas Toth 00f1d76738 [clang-tidy] Recommit: Add the abseil-duration-comparison check
Summary:
This check finds instances where Duration values are being converted to a numeric value in a comparison expression, and suggests that the conversion happen on the other side of the expression to a Duration.  See documentation for examples.

This also shuffles some code around so that the new check may perform in sone step simplifications also caught by other checks.
Compilation is unbroken, because the hash-function is now directly
specified for std::unordered_map, as 'enum class' does not compile as
key (seamingly only on some compilers).

Patch by hwright.

Reviewers: aaron.ballman, JonasToth, alexfh, hokein

Reviewed By: JonasToth

Subscribers: sammccall, Eugene.Zelenko, xazax.hun, cfe-commits, mgorny

Tags: #clang-tools-extra

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

llvm-svn: 348169
2018-12-03 19:22:08 +00:00
Jonas Toth b77711e297 Revert "[clang-tidy] Add the abseil-duration-comparison check"
This commit broke buildbots and needs adjustments.

llvm-svn: 348165
2018-12-03 18:59:27 +00:00
Jonas Toth 5da1825ebc [clang-tidy] Add the abseil-duration-comparison check
Summary:
This check finds instances where Duration values are being converted to a numeric value in a comparison expression, and suggests that the conversion happen on the other side of the expression to a Duration.  See documentation for examples.

This also shuffles some code around so that the new check may perform in sone step simplifications also caught by other checks.

Patch by hwright.

Reviewers: aaron.ballman, JonasToth, alexfh, hokein

Reviewed By: JonasToth

Subscribers: sammccall, Eugene.Zelenko, xazax.hun, cfe-commits, mgorny

Tags: #clang-tools-extra

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

llvm-svn: 348161
2018-12-03 18:35:56 +00:00
Aaron Ballman e0fddb4e56 Fix false positive with lambda assignments in cert-err58-cpp.
This check is about preventing exceptions from being thrown before main() executes, and assigning a lambda (rather than calling it) to a global object cannot throw any exceptions.

llvm-svn: 347761
2018-11-28 15:04:38 +00:00
Hans Wennborg cab8dd692e Re-commit r347419 "Update call to EvaluateAsInt() to the new syntax."
llvm-svn: 347757
2018-11-28 14:04:26 +00:00
Aaron Ballman dda6290f16 Fix a false-positive with cert-err58-cpp.
If a variable is declared constexpr then its initializer needs to be a constant expression, and thus, cannot throw. This check is about not throwing exceptions before main() runs, and so it doesn't apply if the initializer cannot throw. This silences the diagnostic when initializing a constexpr variable and fixes PR35457.

llvm-svn: 347745
2018-11-28 11:57:13 +00:00
Malcolm Parsons d8851b5def [clang-tidy] Ignore bool -> single bit bitfield conversion in readability-implicit-bool-conversion
Summary: There is no ambiguity / information loss in this conversion

Reviewers: alexfh, aaron.ballman, hokein

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 347671
2018-11-27 16:23:39 +00:00
Hans Wennborg 02f5511ff4 Revert r347419 "Update call to EvaluateAsInt() to the new syntax."
It's pre-requisite was reverted in r347656.

llvm-svn: 347657
2018-11-27 14:15:37 +00:00
Alexander Kornienko 8577dcc533 [clang-tidy] Avoid inconsistent notes in readability-container-size-empty
When a warning is issued in a template instantiation, the check would previously
use template arguments in a note, which would result in inconsistent or
duplicate warnings (depending on how deduplication was done). This patch removes
template arguments from the note.

llvm-svn: 347652
2018-11-27 10:53:44 +00:00
Guillaume Chatelet 10a7ee7044 [clang-tidy] Improving narrowing conversions
Summary:
Newly flagged narrowing conversions:
 - integer to narrower signed integer (this is compiler implementation defined),
 - integer - floating point narrowing conversions,
 - floating point - integer narrowing conversions,
 - constants with narrowing conversions (even in ternary operator).

Reviewers: hokein, alexfh, aaron.ballman, JonasToth

Reviewed By: aaron.ballman, JonasToth

Subscribers: lebedev.ri, courbet, nemanjai, xazax.hun, kbarton, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 347570
2018-11-26 16:25:55 +00:00
Haojian Wu 77c56fffad [clang-tidy] No warning for auto new expression in smart check
Summary: The fix for `auto` new expression is illegal.

Reviewers: aaron.ballman

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 347551
2018-11-26 12:42:08 +00:00
Alexander Kornienko f90bdf73a2 [clang-tidy] PrintStackTraceOnErrorSignal
llvm-svn: 347546
2018-11-26 11:11:52 +00:00
Haojian Wu dbfa9c3e0a [clang-tidy] Don't generate incorrect fixes for class with deleted copy constructor in smart_ptr check.
Summary:
The fix for aggregate initialization (`std::make_unique<Foo>(Foo {1, 2})` needs
to see Foo copy constructor, otherwise we will have a compiler error. So we
only emit the check warning.

Reviewers: JonasToth, aaron.ballman

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 347537
2018-11-26 09:33:08 +00:00
Alexander Kornienko 976e0c07a0 A bit of AST matcher cleanup, NFC.
Removed the uses of the allOf() matcher inside node matchers that are implicit
allOf(). Replaced uses of allOf() with the explicit node matcher where it makes
matchers more readable. Replace anyOf(hasName(), hasName(), ...) with the more
efficient and readable hasAnyName().

llvm-svn: 347520
2018-11-25 02:41:01 +00:00
Alexander Kornienko daa515e6a1 [clang-tidy] Ignore matches in template instantiations (cert-dcl21-cpp)
The test fails with a local modification to
clang-tidy/ClangTidyDiagnosticConsumer.cpp to include fixes into the key when
deduplicating the warnings.

llvm-svn: 347495
2018-11-23 14:30:14 +00:00
Alexander Kornienko b34b6ffa9d [clang-tidy] Ignore template instantiations in modernize-use-using
The test I'm adding passes without the change due to the deduplication logic in
ClangTidyDiagnosticConsumer::take(). However this bug manifests in our internal
integration with clang-tidy.
I've verified the fix by locally changing LessClangTidyError to consider
replacements.

llvm-svn: 347470
2018-11-22 16:10:18 +00:00
Bill Wendling d0b6706c97 Update call to EvaluateAsInt() to the new syntax.
llvm-svn: 347419
2018-11-21 20:45:00 +00:00
Nico Weber 63992b02d0 Revert 347366, its prerequisite 347364 got reverted.
llvm-svn: 347390
2018-11-21 12:49:22 +00:00
Bill Wendling 194c64ef4f Update EvaluateAsInt to the new syntax.
llvm-svn: 347366
2018-11-20 23:24:39 +00:00
Haojian Wu c63d935b23 [clang-tidy] Don't generate incorrect fixes for class constructed from list-initialized arguments
Summary:
Currently the smart_ptr check (modernize-make-unique) generates the
fixes that cannot compile for cases like below -- because brace list can
not be deduced in `make_unique`.

```
struct Bar { int a, b; };
struct Foo { Foo(Bar); };
auto foo = std::unique_ptr<Foo>(new Foo({1, 2}));
```

Reviewers: aaron.ballman

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 347315
2018-11-20 15:45:15 +00:00
Aaron Ballman 639c87ef53 Add the abseil-duration-factory-scale check.
This check removes unneeded scaling of arguments when calling Abseil Time factory functions.

Patch by Hyrum Wright.

llvm-svn: 347163
2018-11-18 16:41:06 +00:00
Stephane Moore e34a761d5b [clang-tidy/checks] Implement a clang-tidy check to verify Google Objective-C function naming conventions 📜
Summary:
§1 Description

This check finds function names in function declarations in Objective-C files that do not follow the naming pattern described in the Google Objective-C Style Guide. Function names should be in UpperCamelCase and functions that are not of static storage class should have an appropriate prefix as described in the Google Objective-C Style Guide. The function `main` is a notable exception. Function declarations in expansions in system headers are ignored.

Example conforming function definitions:
```
static bool IsPositive(int i) { return i > 0; }
static bool ABIsPositive(int i) { return i > 0; }
bool ABIsNegative(int i) { return i < 0; }
```

A fixit hint is generated for functions of static storage class but otherwise the check does not generate a fixit hint because an appropriate prefix for the function cannot be determined.

§2 Test Notes
* Verified clang-tidy tests pass successfully.
* Used check_clang_tidy.py to verify expected output of processing google-objc-function-naming.m

Reviewers: benhamilton, hokein, Wizard, aaron.ballman

Reviewed By: benhamilton

Subscribers: Eugene.Zelenko, mgorny, xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 347132
2018-11-17 02:37:21 +00:00
Stephane Moore 20cd5f2e20 [clang-tidy] Fix reference to -[NSError init] in AvoidNSErrorInitCheck.h
llvm-svn: 347000
2018-11-15 22:38:39 +00:00
Sam McCall 35f3da1925 [clang-tidy] Update checks to play nicely with limited traversal scope added in r346847
Summary: (See D54204 for original review)

Reviewers: hokein

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 346961
2018-11-15 15:06:11 +00:00
Roman Lebedev 2634bd5995 [clang-tidy] Avoid C arrays check
Summary:
[[ https://bugs.llvm.org/show_bug.cgi?id=39224 | PR39224 ]]
As discussed, we can't always do the transform automatically due to that array-to-pointer decay of C array.
In order to detect whether we can do said transform, we'd need to be able to see all usages of said array,
which is, i would say, rather impossible if e.g. it is in the header.
Thus right now no fixit exists.

Exceptions: `extern "C"` code.

References:
* [[ https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es27-use-stdarray-or-stack_array-for-arrays-on-the-stack | CPPCG ES.27: Use std::array or stack_array for arrays on the stack ]]
* [[ https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#slcon1-prefer-using-stl-array-or-vector-instead-of-a-c-array | CPPCG SL.con.1: Prefer using STL array or vector instead of a C array ]]
* HICPP `4.1.1 Ensure that a function argument does not undergo an array-to-pointer conversion`
* MISRA `5-2-12 An identifier with array type passed as a function argument shall not decay to a pointer`

Reviewers: aaron.ballman, JonasToth, alexfh, hokein, xazax.hun

Reviewed By: JonasToth

Subscribers: Eugene.Zelenko, mgorny, rnkovacs, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 346835
2018-11-14 09:01:08 +00:00
Jonas Toth 6b3d33e996 [clang-tidy] new check: bugprone-too-small-loop-variable
The new checker searches for those for loops which has a loop variable with a "too small" type which means this type can't represent all values which are part of the iteration range.

For example:

```
int main() {
  long size = 300000;
  for( short int i = 0; i < size; ++i) {}
}
```

The short type leads to infinite loop here because it can't store all values in the `[0..size]` interval. In a real use case, size means a container's size which depends on the user input. Which means for small amount of objects the algorithm works, but with a larger user input the software will freeze.

The idea of the checker comes from the LibreOffice project, where the same check was implemented as a clang compiler plugin, called `LoopVarTooSmall` (LLVM licensed).
The idea is the same behind this check, but the code is different because of the different framework.

Patch by ztamas.

Reviewers: alexfh, hokein, aaron.ballman, JonasToth, xazax.hun, whisperity

Reviewed By: JonasToth, whisperity

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

llvm-svn: 346665
2018-11-12 16:01:39 +00:00
Jonas Toth ef67ce0f6f [clang-tidy] fix PR39583 - ignoring ParenCast for string-literals in pro-bounds-array-to-pointer-decay
Summary:
The fix to the issue that `const char* p = ("foo")` is diagnosed as decay
is to ignored the ParenCast.
Resolves PR39583

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: aaron.ballman

Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits

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

llvm-svn: 346555
2018-11-09 20:57:28 +00:00
Bill Wendling ec54d6121c Ignore implicit things like ConstantExpr.
llvm-svn: 346461
2018-11-09 01:32:30 +00:00
Sam McCall 3c1f4903b7 [clang-tidy] Untangle layering in ClangTidyDiagnosticConsumer somewhat. NFC
Summary:
Clang's hierarchy is CompilerInstance -> DiagnosticsEngine -> DiagnosticConsumer.
(Ownership is optional/shared, but this structure is fairly clear).

Currently ClangTidyDiagnosticConsumer *owns* the DiagnosticsEngine:
 - this inverts the hierarchy, which is confusing
 - this means ClangTidyDiagnosticConsumer() mutates the passed-in context, which
   is both surprising and limits flexibility
 - it's not possible to use a different DiagnosticsEngine with ClangTidy

This means a little bit more code in the places ClangTidy is used standalone,
but more flexibility in using ClangTidy with other diagnostics configurations.

Reviewers: hokein

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 346418
2018-11-08 17:42:16 +00:00
Sam McCall 80a3c561a7 [clang-tidy] run() doesn't update the SourceManager.
Summary:
By now the context's SourceManager is now initialized everywhere that
ClangTidyCheck::registerMatcher() is called, so the call from run() seems
entirely redundant, and indeed all the tests pass.

This solves a problem with embedding clang-tidy: if using a DiagnosticsEngine
which already has file state, re-setting its SourceManager (to the same value)
causes an assertion.
(There are other ways to solve this problem, but this is the simplest).

Reviewers: hokein, alexfh

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 346219
2018-11-06 09:28:23 +00:00
Alexander Kornienko 3444cb9993 [clang-tidy] Fixed code sample in a comment. NFC
llvm-svn: 345984
2018-11-02 15:29:37 +00:00
Alexander Kornienko 8f810c3cdc [clang-tidy] .reset(new X) -> make_unique<X>() in a comment. NFC
llvm-svn: 345979
2018-11-02 15:03:43 +00:00
Tim Northover 314fbfa1c4 Reapply Logging: make os_log buffer size an integer constant expression.
The size of an os_log buffer is known at any stage of compilation, so making it
a constant expression means that the common idiom of declaring a buffer for it
won't result in a VLA. That allows the compiler to skip saving and restoring
the stack pointer around such buffers.

This also moves the OSLog and other FormatString helpers from
libclangAnalysis to libclangAST to avoid a circular dependency.

llvm-svn: 345971
2018-11-02 13:14:11 +00:00
Sam McCall cb50e23ba8 [clang-tidy] Get ClangTidyContext out of the business of storing diagnostics. NFC
Summary:
Currently ClangTidyContext::diag() sends the diagnostics to a
DiagnosticsEngine, which probably delegates to a ClangTidyDiagnosticsConsumer,
which is supposed to go back and populate ClangTidyContext::Errors.

After this patch, the diagnostics are stored in the ClangTidyDiagnosticsConsumer
itself and can be retrieved from there.

Why?
 - the round-trip from context -> engine -> consumer -> context is confusing
   and makes it harder to establish layering between these things.
 - context does too many things, and makes it hard to use clang-tidy as a library
 - everyone who actually wants the diagnostics has access to the ClangTidyDiagnosticsConsumer

The most natural implementation (ClangTidyDiagnosticsConsumer::take()
finalizes diagnostics) causes a test failure: clang-tidy-run-with-database.cpp
asserts that clang-tidy exits successfully when trying to process a file
that doesn't exist.
In clang-tidy today, this happens because finish() is never called, so the
diagnostic is never flushed. This looks like a bug to me.
For now, this patch carefully preserves that behavior, but I'll ping the
authors to see whether it's deliberate and worth preserving.

Reviewers: hokein

Subscribers: xazax.hun, cfe-commits, alexfh

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

llvm-svn: 345961
2018-11-02 10:01:59 +00:00
Fangrui Song e446f04cb1 Fix -Wimplicit-fallthrough warning in LLVM_ENABLE_ASSERTIONS=Off builds
llvm-svn: 345951
2018-11-02 04:17:17 +00:00
Reid Kleckner 4dc0b1ac60 Fix clang -Wimplicit-fallthrough warnings across llvm, NFC
This patch should not introduce any behavior changes. It consists of
mostly one of two changes:
1. Replacing fall through comments with the LLVM_FALLTHROUGH macro
2. Inserting 'break' before falling through into a case block consisting
   of only 'break'.

We were already using this warning with GCC, but its warning behaves
slightly differently. In this patch, the following differences are
relevant:
1. GCC recognizes comments that say "fall through" as annotations, clang
   doesn't
2. GCC doesn't warn on "case N: foo(); default: break;", clang does
3. GCC doesn't warn when the case contains a switch, but falls through
   the outer case.

I will enable the warning separately in a follow-up patch so that it can
be cleanly reverted if necessary.

Reviewers: alexfh, rsmith, lattner, rtrieu, EricWF, bollu

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

llvm-svn: 345882
2018-11-01 19:54:45 +00:00
Yan Zhang cc1e9c414b Fix the issue that not recognizing single acronym with prefix as ObjC property name.
Summary: This will make clang-tidy accept property names like xyz_URL (URL is a common acronym).

Reviewers: benhamilton, hokein

Reviewed By: benhamilton

Subscribers: jfb, cfe-commits

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

llvm-svn: 345858
2018-11-01 17:36:18 +00:00
Aaron Ballman 3a02722a40 Implement the readability-const-return-type check.
This check flags function top-level const-qualified return types and suggests removing the mostly-superfluous const qualifier where possible.

Patch by Yitzhak Mandelbaum.

llvm-svn: 345764
2018-10-31 19:11:38 +00:00
Jonas Toth 0ea5af7acb [clang-tidy] new check 'readability-isolate-declaration'
Summary:
This patch introduces a new clang-tidy check that matches on all `declStmt` that declare more then one variable
and transform them into one statement per declaration if possible.

It currently only focusses on variable declarations but should be extended to cover more kinds of declarations in the future.
It is related to https://reviews.llvm.org/D27621 and does use it's extensive test-suite. Thank you to firolino for his work!

Reviewers: rsmith, aaron.ballman, alexfh, hokein, kbobyrev

Reviewed By: aaron.ballman

Subscribers: ZaMaZaN4iK, mgehre, nemanjai, kbarton, lebedev.ri, Eugene.Zelenko, mgorny, xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 345735
2018-10-31 16:50:44 +00:00
Sam McCall dd2120c08f [clang-tidy] Remove false decoupling in ClangTidyContext. NFC
These getters/setters don't encapsulate any behavior, and can only be
called by friends.

llvm-svn: 345716
2018-10-31 13:08:19 +00:00
Erik Pilkington fa98390b3c NFC: Remove the ObjC1/ObjC2 distinction from clang (and related projects)
We haven't supported compiling ObjC1 for a long time (and never will again), so
there isn't any reason to keep these separate. This patch replaces
LangOpts::ObjC1 and LangOpts::ObjC2 with LangOpts::ObjC.

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

llvm-svn: 345637
2018-10-30 20:31:30 +00:00
Roman Lebedev c367ba1923 [clang-tidy] cppcoreguidelines-macro-usage: print macro names
Summary:
The macro may not have location (or more generally, the location may not exist),
e.g. if it originates from compiler's command-line.

The check complains on all the macros, even those without the location info.
Which means, it only says it does not like it. What is 'it'? I have no idea.
If we don't print the name, then there is no way to deal with that situation.

And in general, not printing name here forces the user to try to understand,
given, the macro definition location, what is the macro name?
This isn't fun.

Also, ignores-by-default the macros originating from command-line,
with an option to not ignore those.

I suspect some more issues may crop up later.

Reviewers: JonasToth, aaron.ballman, hokein, xazax.hun, alexfh

Reviewed By: JonasToth, aaron.ballman

Subscribers: nemanjai, kbarton, rnkovacs, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 345610
2018-10-30 15:52:36 +00:00
Bruno Ricci 17ff026b73 [AST] Refactor PredefinedExpr
Make the following changes to PredefinedExpr:

1. Move PredefinedExpr below StringLiteral so that it can use its definition.
2. Rename IdentType to IdentKind to be more in line with clang's conventions,
   and propagate the change to its users.
3. Move the location and the IdentKind into the newly available space of
   the bit-fields of Stmt.
4. Only store the function name when needed. When parsing all of Boost,
   of the 1357 PredefinedExpr 919 have no function name.

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

Reviewed By: rjmccall

llvm-svn: 345460
2018-10-27 19:21:19 +00:00
Roman Lebedev 08701ec753 [clang-tidy] Re-commit: Add new 'readability-uppercase-literal-suffix' check (CERT DCL16-C, MISRA C:2012, 7.3, MISRA C++:2008, 2-13-4)
Summary:
Detects when the integral literal or floating point (decimal or hexadecimal)
literal has non-uppercase suffix, and suggests to make the suffix uppercase,
with fix-it.

All valid combinations of suffixes are supported.

```
  auto x = 1;  // OK, no suffix.

  auto x = 1u; // warning: integer literal suffix 'u' is not upper-case

  auto x = 1U; // OK, suffix is uppercase.

  ...
```

This is a re-commit, the original was reverted by me in
rL345305 due to discovered bugs. (implicit code, template instantiation)
Tests were added, and the bugs were fixed.
I'm unable to find any further bugs, hopefully there aren't any..

References:
* [[ https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152241 | CERT DCL16-C ]]
* MISRA C:2012, 7.3 - The lowercase character "l" shall not be used in a literal suffix
* MISRA C++:2008, 2-13-4 - Literal suffixes shall be upper case

Reviewers: JonasToth, aaron.ballman, alexfh, hokein, xazax.hun

Reviewed By: aaron.ballman

Subscribers: Eugene.Zelenko, mgorny, rnkovacs, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 345381
2018-10-26 13:09:27 +00:00
Roman Lebedev 5aa945e7ac [clang-tidy] Revert my readability-uppercase-literal-suffix check.
There are some lurking issues with the handling of the SourceManager.
Somehow sometimes we end up extracting completely wrong
portions of the source buffer.

Reverts r344772, r44760, r344758, r344755.

llvm-svn: 345305
2018-10-25 19:44:51 +00:00
Heejin Ahn d00d449f8e [clant-tidy] abseil: Add clangTooling to CMakeLists.txt
Without this, builds with `-DBUILD_SHARED_LIBS=ON` fail.

llvm-svn: 345191
2018-10-24 20:31:58 +00:00
Jonas Toth 618c0bc363 [clang-tidy] Add the abseil-duration-factory-float check
Summary:
This check finds cases where calls to an absl::Duration factory could use the more efficient integer overload.

For example:
// Original - Providing a floating-point literal.
absl::Duration d = absl::Seconds(10.0);

// Suggested - Use an integer instead.
absl::Duration d = absl::Seconds(10);

Patch by hwright.

Reviewers: alexfh, hokein, aaron.ballman, JonasToth

Reviewed By: hokein, JonasToth

Subscribers: zturner, xazax.hun, Eugene.Zelenko, mgorny, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 345167
2018-10-24 17:40:50 +00:00
Jonas Toth 74f201c37e [clang-tidy] tryfix windows build
llvm-svn: 344947
2018-10-22 20:29:15 +00:00
Jonas Toth 552b62ed1f [clang-tidy] implement cppcoreguidelines macro rules
Summary:
In short macros are discouraged by multiple rules (and sometimes reference randomly). [Enum.1], [ES.30], [ES.31]
This check allows only headerguards and empty macros for annotation.

Reviewers: aaron.ballman, hokein

Reviewed By: aaron.ballman

Subscribers: jbcoe, Eugene.Zelenko, klimek, nemanjai, mgorny, xazax.hun, kbarton, cfe-commits

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

llvm-svn: 344940
2018-10-22 19:20:01 +00:00
Miklos Vajna e967a12733 [clang-tidy] add IgnoreMacros option to readability-redundant-smartptr-get
And also enable it by default to be consistent with e.g. modernize-use-using.

This helps e.g. when running this check on client code where the macro is
provided by the system, so there is no easy way to modify it.

Reviewed By: JonasToth

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

llvm-svn: 344871
2018-10-21 19:16:25 +00:00
Marek Kurdej bc76dc3cec [clang-tidy] Resolve readability-else-after-return false positive for constexpr if.
Summary:
It fixes the false positive when using constexpr if and where else cannot be removed:

Example:
```
  if constexpr (sizeof(int) > 4)
    // ...
    return /* ... */;
  else // This else cannot be removed.
    // ...
    return /* ... */;
```

Reviewers: alexfh, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: lebedev.ri, xazax.hun, cfe-commits

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

llvm-svn: 344785
2018-10-19 15:26:17 +00:00
Roman Lebedev 6cfa38f1f1 [clang-tidy] Non-private member variables in classes (MISRA, CppCoreGuidelines, HICPP)
Summary:
Finds classes that not only contain the data (non-static member variables),
but also have logic (non-static member functions), and diagnoses all member
variables that have any other scope other than `private`. They should be
made `private`, and manipulated exclusively via the member functions.

Optionally, classes with all member variables being `public` could be
ignored, and optionally all `public` member variables could be ignored.

Options
-------

* IgnoreClassesWithAllMemberVariablesBeingPublic

  Allows to completely ignore classes if **all** the member variables in that
  class have `public` visibility.

* IgnorePublicMemberVariables

  Allows to ignore (not diagnose) **all** the member variables with `public`
  visibility scope.

References:
* MISRA 11-0-1 Member data in non-POD class types shall be private.
* https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c2-use-class-if-the-class-has-an-invariant-use-struct-if-the-data-members-can-vary-independently
* https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rc-private
* https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rh-protected

Reviewers: JonasToth, aaron.ballman, alexfh, hokein, xazax.hun

Reviewed By: aaron.ballman

Subscribers: Eugene.Zelenko, zinovy.nis, cfe-commits, rnkovacs, nemanjai, mgorny, xazax.hun, kbarton

Tags: #clang-tools-extra

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

llvm-svn: 344757
2018-10-18 20:16:44 +00:00
Roman Lebedev b2eec586c8 [clang-tidy] Add new 'readability-uppercase-literal-suffix' check (CERT DCL16-C, MISRA C:2012, 7.3, MISRA C++:2008, 2-13-4)
Summary:
Detects when the integral literal or floating point (decimal or hexadecimal)
literal has non-uppercase suffix, and suggests to make the suffix uppercase,
with fix-it.

All valid combinations of suffixes are supported.

```
  auto x = 1;  // OK, no suffix.

  auto x = 1u; // warning: integer literal suffix 'u' is not upper-case

  auto x = 1U; // OK, suffix is uppercase.

  ...
```

References:
* [[ https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152241 | CERT DCL16-C ]]
* MISRA C:2012, 7.3 - The lowercase character "l" shall not be used in a literal suffix
* MISRA C++:2008, 2-13-4 - Literal suffixes shall be upper case

Reviewers: JonasToth, aaron.ballman, alexfh, hokein, xazax.hun

Reviewed By: aaron.ballman

Subscribers: Eugene.Zelenko, mgorny, rnkovacs, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 344755
2018-10-18 20:06:40 +00:00
Haojian Wu 547f89d607 [clang-tidy] Ignore a case where the fix of make_unique check introduces side effect.
Summary:
Previously, ptr.reset(new char[5]) will be replaced with `p =
make_unique<char[]>(5)`, the fix has side effect -- doing
default initialization, it may cause performace regression (we are
bitten by this rececntly)

The check should be conservative for these cases.

Reviewers: alexfh

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 344733
2018-10-18 09:13:34 +00:00
Leonard Chan 0f11b73f96 [Fixed Point Arithmetic] Fix for clang-tools-extra warning
Fix for warnings generated on unhandled enum value `STK_FixedPoint`.

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

llvm-svn: 344549
2018-10-15 20:00:03 +00:00
Leonard Chan 88ccbd7543 added fix
llvm-svn: 344548
2018-10-15 19:59:52 +00:00
Adam Balogh d053f5c616 [clang-tidy] Optimize query in bugprone-exception-escape
Checking whether a functions throws indirectly may be very expensive because it
needs to visit its whole call graph. Therefore we should first check whether the
function is forbidden to throw and only check whether it throws afterward. This
also seems to solve bug https://bugs.llvm.org/show_bug.cgi?id=39167 where the
execution time is so long that it seems to hang.

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

llvm-svn: 344444
2018-10-13 10:34:52 +00:00
Jonas Toth cd3e370504 Revert "[clang-tidy] New checker for not null-terminated result caused by strlen(), size() or equal length"
This reverts commit r344374.

llvm-svn: 344442
2018-10-13 09:30:58 +00:00
Miklos Vajna abfccc2cf6 [clang-tidy] add IgnoreMacros option to modernize-use-equals-delete
And also enable it by default to be consistent with e.g. modernize-use-using.
This improves consistency inside the check itself as well: both checks are now
disabled in macros by default.

This helps e.g. when running this check on client code where the macro is
provided by the system, so there is no easy way to modify it.

Reviewed By: alexfh

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

llvm-svn: 344440
2018-10-13 07:58:05 +00:00
Jonas Toth 78886233b3 [clang-tidy] New checker for not null-terminated result caused by strlen(), size() or equal length
New checker called bugprone-not-null-terminated-result. This check finds function calls where it is possible to cause a not null-terminated result. Usually the proper length of a string is strlen(src) + 1 or equal length of this expression, because the null terminator needs an extra space. Without the null terminator it can result in undefined behaviour when the string is read.

The following function calls are checked:
memcpy, wmemcpy, memcpy_s, wmemcpy_s, memchr, wmemchr, memmove, wmemmove, memmove_s, wmemmove_s, memset, wmemset, strerror_s, strncmp, wcsncmp, strxfrm, wcsxfrm

The following is a real-world example where the programmer forgot to increase the passed third argument, which is size_t length. That is why the length of the allocated memory is problematic too.

static char *StringCpy(const std::string &str) {
  char *result = reinterpret_cast<char *>(malloc(str.size()));
  memcpy(result, str.data(), str.size());
  return result;
}

After running the tool fix-it rewrites all the necessary code according to the given options. If it is necessary, the buffer size will be increased to hold the null terminator.

static char *StringCpy(const std::string &str) {
  char *result = reinterpret_cast<char *>(malloc(str.size() + 1));
  strcpy(result, str.data());
  return result;
}

Patch by Charusso.

Differential ID: https://reviews.llvm.org/D45050

llvm-svn: 344374
2018-10-12 17:22:36 +00:00
Adam Balogh abd72e9851 [clang-tidy] White List Option for performance-unnecessary-value-param, performance-unnecessary-copy-initialization and performance-for-range-copy
New option added to these three checks to be able to silence false positives on
types that are intentionally passed by value or copied. Such types are e.g.
intrusive reference counting pointer types like llvm::IntrusiveRefCntPtr. The
new option is named WhiteListTypes and can contain a semicolon-separated list of
names of these types. Regular expressions are allowed. Default is empty.

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

llvm-svn: 344340
2018-10-12 13:05:21 +00:00
Jonas Devlieghere fc51490baf Lift VFS from clang to llvm (NFC)
This patch moves the virtual file system form clang to llvm so it can be
used by more projects.

Concretely the patch:
 - Moves VirtualFileSystem.{h|cpp} from clang/Basic to llvm/Support.
 - Moves the corresponding unit test from clang to llvm.
 - Moves the vfs namespace from clang::vfs to llvm::vfs.
 - Formats the lines affected by this change, mostly this is the result of
   the added llvm namespace.

RFC on the mailing list:
http://lists.llvm.org/pipermail/llvm-dev/2018-October/126657.html

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

llvm-svn: 344140
2018-10-10 13:27:25 +00:00
Alexander Kornienko c968c98880 [clang-tidy] Fix handling of parens around new expressions in make_<smartptr> checks.
Summary:
Extra parentheses around a new expression result in incorrect code
after applying fixes.

Reviewers: hokein

Reviewed By: hokein

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 344058
2018-10-09 15:58:18 +00:00
Jonas Toth c831f55fb1 [clang-tidy] NFC fix warnings from missing braces
The std::array create multiple StringRef but did not wrap
them in braces. Some compilers warned for that. Adding the
braces is not possible and result in a compilation error.
This commit changes the array to vector which works without warning.

llvm-svn: 344046
2018-10-09 13:29:31 +00:00
Simon Pilgrim b616b809a3 Revert rL343916: Fix -Wmissing-braces warning. NFCI.
llvm-svn: 343917
2018-10-06 11:59:31 +00:00
Simon Pilgrim 2a6bfa0c30 Fix -Wmissing-braces warning. NFCI.
llvm-svn: 343916
2018-10-06 11:46:27 +00:00
Jonas Toth a78c249af6 [clang-tidy] NFC refactor lexer-utils to be usable without ASTContext
Summary:
This patch is a small refactoring necessary for
'readability-isolate-declaration' and does not introduce functional changes.
It allows to use the utility functions without a full `ASTContext` and requires only the `SourceManager` and the `LangOpts`.

Reviewers: alexfh, aaron.ballman, hokein

Reviewed By: alexfh

Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 343850
2018-10-05 14:15:19 +00:00
Jonas Toth d079436571 [clang-tidy] Replace deprecated std::ios_base aliases
This check warns the uses of the deprecated member types of std::ios_base
and replaces those that have a non-deprecated equivalent.

Patch by andobence!

Reviewd by: alexfh

Revision ID: https://reviews.llvm.org/D51332

llvm-svn: 343848
2018-10-05 13:36:00 +00:00
Jonas Toth 9b1cc0121c [clang-tidy] fix PR39167, bugprone-exception-escape hangs-up
Summary:
The check bugprone-exception-escape should not register
if -fno-exceptions is set for the compile options. Bailing out on non-cplusplus
and non-exceptions language options resolves the issue.

Reviewers: alexfh, aaron.ballman, baloghadamsoftware

Reviewed By: alexfh

Subscribers: lebedev.ri, xazax.hun, rnkovacs, cfe-commits

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

llvm-svn: 343789
2018-10-04 15:49:25 +00:00
Jonas Toth c97671e5da [clang-tidy] Added pointer types to clang-tidy readability-identifier-naming check.
Summary:

Option to check for different naming conventions on the following types:

  - GlobalConstantPointer
  - GlobalPointer
  - LocalConstantPointer
  - LocalPointer
  - PointerParameter
  - ConstantPointerParameter

When not specified, the conventions for the non pointer types will be applied (GlobalConstant, GlobalVariable, LocalConstant, ...).

Patch by ffigueras!

Reviewers: alexfh, kbobyrev

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 343788
2018-10-04 15:47:57 +00:00
Martin Bohme 764ad2f732 [clang-tidy] Sequence statements with multiple parents correctly (PR39149)
Summary:
Before this fix, the bugprone-use-after-move check could incorrectly
conclude that a use and move in a function template were not sequenced.
For details, see

https://bugs.llvm.org/show_bug.cgi?id=39149

Reviewers: alexfh, hokein, aaron.ballman, JonasToth

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 343768
2018-10-04 11:36:39 +00:00
Jonas Toth fc07c3d910 [clang-tidy] NFC reorder registering in CppCoreGuidelines module
llvm-svn: 343673
2018-10-03 10:37:19 +00:00
Alexander Kornienko c5016c0a27 [clang-tidy] Ignore singe bit bitfield -> bool conversion in readability-implicit-bool-conversion
llvm-svn: 343578
2018-10-02 11:38:41 +00:00
Stephen Kelly a3c4206e41 [clang-tidy] Build it even without static analyzer
Conditionally compile the parts of clang-tidy which depend on the static
analyzer.

Funnily enough, I made the patch to exclude this from the build in 2013,
and it was committed with the comment that the tool should not be fully
excluded, but only the parts of it which depend on the analyzer should
be excluded.

 http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20130617/081797.html

This commit implements that idea.

Reviewed By: aaron.ballman

Tags: #clang-tools-extra

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

llvm-svn: 343528
2018-10-01 20:24:22 +00:00
Aaron Ballman 873a50901b Reverting r343415 as it breaks at least one of the bots.
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/37336

llvm-svn: 343418
2018-09-30 17:39:39 +00:00
Aaron Ballman bc70c26ef4 Allow clang-tidy to be built without a dependency on the clang static analyzer.
Patch by Stephen Kelly.

llvm-svn: 343415
2018-09-30 17:22:58 +00:00
Fangrui Song b441be0924 [clang-tidy] Add dependency to clangAnalysis after rC343160
llvm-svn: 343168
2018-09-27 04:23:24 +00:00
Fangrui Song 8b9540379e llvm::sort(C.begin(), C.end()) -> llvm::sort(C)
The convenience wrapper in STLExtras is available since rL342102.

llvm-svn: 343166
2018-09-27 04:19:29 +00:00
Jonas Toth d1bd01c318 [clang-tidy] Add modernize-concat-nested-namespaces check
Summary:
Finds instances of namespaces concatenated using explicit syntax, such as `namespace a { namespace b { [...] }}` and offers fix to glue it to `namespace a::b { [...] }`.

Properly handles `inline` and unnamed namespaces. ~~Also, detects empty blocks in nested namespaces and offers to remove them.~~

Test with common use cases included.
I ran the check against entire llvm repository. Except for expected `nested namespace definitions only available with -std=c++17 or -std=gnu++17` warnings I noticed no issues when the check was performed.

Example:
```
namespace a { namespace b {
void test();
}}

```
can become
```
namespace a::b {
void test();
}
```

Patch by wgml!

Reviewers: alexfh, aaron.ballman, hokein

Reviewed By: aaron.ballman

Subscribers: JonasToth, Eugene.Zelenko, lebedev.ri, mgorny, xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 343000
2018-09-25 18:12:28 +00:00
Eugene Zelenko 04d38c5f52 [Clang-tidy] Alphabetical sort of files/checks. Add space after clang-tidy in source code headers.
llvm-svn: 342601
2018-09-20 00:02:55 +00:00
Andi-Bogdan Postelnicu 1a05697e7a [clang-tidy] run-clang-tidy.py - fails using python 3.7
Differential Revision: https://reviews.llvm.org/D51220

llvm-svn: 342540
2018-09-19 11:52:20 +00:00
Artem Belevich fcfcd508e4 [clang-tidy] Replace redundant checks with an assert().
findStyleKind is only called if D is an explicit identifier with a name,
so the checks for operators will never return true. The explicit assert()
enforces this invariant.

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

llvm-svn: 342514
2018-09-18 21:51:02 +00:00
Shuai Wang 4b8452998a [clang-tidy] Remove duplicated logic in UnnecessaryValueParamCheck and use FunctionParmMutationAnalyzer instead.
Reviewers: alexfh, JonasToth, george.karpenkov

Subscribers: xazax.hun, kristof.beyls, chrib, a.sidorin, Szelethus, cfe-commits

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

llvm-svn: 342403
2018-09-17 17:59:51 +00:00
Jonas Toth b1efe51dd9 [clang-tidy] fix PR37913, templated exception factory diagnosed correctly
Summary:
PR37913 documents wrong behaviour for a templated exception factory function.
The check does misidentify dependent types as not derived from std::exception.

The fix to this problem is to ignore dependent types, the analysis works correctly
on the instantiated function.

Reviewers: aaron.ballman, alexfh, hokein, ilya-biryukov

Reviewed By: alexfh

Subscribers: lebedev.ri, nemanjai, mgorny, kbarton, xazax.hun, cfe-commits

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

llvm-svn: 342393
2018-09-17 13:55:10 +00:00
Idriss Riouak 09767acae1 [Clang-Tidy: modernize] Fix for modernize-redundant-void-arg: complains about variable cast to void
Summary:
Hello, i would like to suggest a fix for one of the checks in clang-tidy.The bug was reported in https://bugs.llvm.org/show_bug.cgi?id=32575 where you can find more information.

For example:
```
template <typename T0>
struct S {
  template <typename T>
  void g() const {
    int a;
    (void)a;
  }
};

void f() {
  S<int>().g<int>();
}
```


this piece of code should not trigger any warning by the check modernize-redundant-void-arg but when we execute the following command


```
clang_tidy -checks=-*,modernize-redundant-void-arg test.cpp -- -std=c++11
```

we obtain the following warning:

/Users/eco419/Desktop/clang-tidy.project/void-redundand_2/test.cpp:6:6: warning: redundant void argument list in function declaration [modernize-redundant-void-arg]
    (void)a;
     ^~~~

Reviewers: aaron.ballman, hokein, alexfh, JonasToth

Reviewed By: aaron.ballman, JonasToth

Subscribers: JonasToth, lebedev.ri, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 342388
2018-09-17 12:29:29 +00:00
Benjamin Kramer bb999e507c [modernize-use-transparent-functors] TypeLocs can be implicitly created, don't crash when encountering those.
llvm-svn: 342252
2018-09-14 18:05:30 +00:00
Benjamin Kramer 5265d56c72 [clang-tidy] Abseil: Add more directories that are slated for future absl expansion.
llvm-svn: 342041
2018-09-12 10:04:16 +00:00
Shuai Wang 79b7ce40af [NFC] Fix build breakage due to missing dep caused by D51950
llvm-svn: 342012
2018-09-12 00:32:13 +00:00
Shuai Wang f21e8ebb91 [clangtidy] Remove old copy of ExprMutationAnalyzer
Summary:
This is 2/2 of moving ExprMutationAnalyzer from clangtidy to clang/Analysis.
ExprMutationAnalyzer is moved to clang/Analysis in D51948.
This diff migrates existing usages within clangtidy to point to the new
location and remove the old copy of ExprMutationAnalyzer.

Reviewers: george.karpenkov, JonasToth

Reviewed By: george.karpenkov

Subscribers: mgorny, a.sidorin, Szelethus, cfe-commits

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

llvm-svn: 342006
2018-09-11 22:59:46 +00:00
Shuai Wang 277b808ad3 [clang-tidy] Handle sugared reference types in ExprMutationAnalyzer
Summary:
This handles cases like this:
```
typedef int& IntRef;
void mutate(IntRef);
void f() {
  int x;
  mutate(x);
}
```
where the param type is a sugared type (`TypedefType`) instead of a
reference type directly.

Note that another category of similar but different cases are already
handled properly before:
```
typedef int Int;
void mutate(Int&);
void f() {
  int x;
  mutate(x);
}
```

Reviewers: aaron.ballman, alexfh, george.karpenkov

Subscribers: xazax.hun, a.sidorin, Szelethus, cfe-commits

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

llvm-svn: 341986
2018-09-11 20:05:37 +00:00
Shuai Wang ea85b52732 [clang-tidy] Handle unique owning smart pointers in ExprMutationAnalyzer
Summary:
For smart pointers like std::unique_ptr which uniquely owns the
underlying object, treat the mutation of the pointee as mutation of the
smart pointer itself.

This gives better behavior for cases like this:
```
void f(std::vector<std::unique_ptr<Foo>> v) { // undesirable analyze result of `v` as not mutated.
  for (auto& p : v) {
      p->mutate(); // only const member function `operator->` is invoked on `p`
  }
}
```

Reviewers: hokein, george.karpenkov

Subscribers: xazax.hun, a.sidorin, Szelethus, cfe-commits

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

llvm-svn: 341967
2018-09-11 17:33:12 +00:00
Benjamin Kramer 8f776db7ff [clang-tidy] Insert absl::StrAppend when replacing StrCat.
There might be no using decl for StrAppend around, inserting the
qualified name is less likely to break things.

llvm-svn: 341929
2018-09-11 12:19:45 +00:00
Benjamin Kramer 4f3c0e27b6 [clang-tidy] Add a missing comma after "flags"
llvm-svn: 341925
2018-09-11 10:37:08 +00:00
Shuai Wang 5066ab369d Revert "Revert "[clang-tidy] Handle unresolved expressions in ExprMutationAnalyzer""
This is the same as D50619 plus fixes for buildbot failures on windows.
The test failures on windows are caused by -fdelayed-template-parsing
and is fixed by forcing -fno-delayed-template-parsing on test cases that
requires AST for uninstantiated templates.

llvm-svn: 341891
2018-09-11 02:23:35 +00:00
Shuai Wang cec7d3a055 Revert "[clang-tidy] Handle unresolved expressions in ExprMutationAnalyzer"
Summary:
Tests somehow break on windows (and only on windows)
http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/13003
http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/13747

I have yet figure out why so reverting to unbreak first.

Reviewers: george.karpenkov

Subscribers: xazax.hun, a.sidorin, Szelethus, cfe-commits

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

llvm-svn: 341886
2018-09-10 23:58:04 +00:00
Roman Lebedev a3dc9484e3 [clang-tidy] ExprMutationAnalyzer: construct from references. Fixes PR38888
Summary:
I have hit this the rough way, while trying to use this in D51870.

There is no particular point in storing the pointers, and moreover
the pointers are assumed to be non-null, and that assumption is not
enforced. If they are null, it won't be able to do anything good
with them anyway.

Initially i thought about simply adding asserts() that they are
not null, but taking/storing references looks like even cleaner solution?

Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=38888 | PR38888 ]]

Reviewers: JonasToth, shuaiwang, alexfh, george.karpenkov

Reviewed By: shuaiwang

Subscribers: xazax.hun, a.sidorin, Szelethus, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 341854
2018-09-10 19:59:18 +00:00
Shuai Wang bef0941b6b [clang-tidy] Handle unresolved expressions in ExprMutationAnalyzer
Summary:
- If a function is unresolved, assume it mutates its arguments
- Follow unresolved member expressions for nested mutations

Reviewers: aaron.ballman, JonasToth, george.karpenkov

Subscribers: xazax.hun, a.sidorin, cfe-commits

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

llvm-svn: 341848
2018-09-10 18:05:13 +00:00
Ben Hamilton 2f0a1286f3 [clang-tidy/ObjC] Update list of acronyms in PropertyDeclarationCheck
Summary: This adds a few common acronyms we found were missing from PropertyDeclarationCheck.

Reviewers: Wizard, hokein

Subscribers: cfe-commits

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

llvm-svn: 341720
2018-09-07 22:02:38 +00:00
Benjamin Kramer 14dd35c30b [clang-tidy] Abseil: Allow macros inside of absl to use internal absl things
llvm-svn: 341643
2018-09-07 09:25:23 +00:00
Stephen Kelly 9b11da91c7 Fix reported range of partial token replacement
Summary: Fixes bug: 38678

Reviewers: klimek, rsmith

Subscribers: cfe-commits

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

llvm-svn: 341583
2018-09-06 20:16:34 +00:00
Eric Liu d2eb03aec8 [clang-tidy] minor bug fix to AbseilMatcher.h
This missing directory is not yet released, but is causing some problems
internally. It's gonna be released eventually and received permission to
include it here. This matcher will also be periodically updated by my
team as we have more releases and or problems internally.

Patch by Hugo Gonzalez!

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

llvm-svn: 341488
2018-09-05 19:01:34 +00:00
Kirill Bobyrev 29925890d9 [clang-tidy] Use simple string matching instead of Regex
Instead of parsing and compiling the `llvm::Regex` each time, it's
faster to use basic string matching for filename prefix check.

Reviewed by: hokein

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

llvm-svn: 341061
2018-08-30 12:42:19 +00:00
Jonas Toth 51aadb463e [clang-tidy] Add abseil-no-internal-dependencies check
Finds instances where the user depends on internal details and warns them against doing so.
Should not be run on internal Abseil files or Abseil source code.

Patch by hugoeg!

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

llvm-svn: 340928
2018-08-29 14:23:15 +00:00
Aaron Ballman ca5f775dbe Introduce the abseil-redundant-strcat-calls check.
This flags redundant calls to absl::StrCat where the result is being passed to another call to absl::StrCat or absl::StrAppend. Patch by Hugo Gonzalez and Samuel Benzaquen.

llvm-svn: 340918
2018-08-29 11:29:07 +00:00
Aaron Ballman a22d24a36c Introduce the abseil-str-cat-append check.
This flags uses of absl::StrCat when absl::StrAppend should be used instead. Patch by Hugo Gonzalez and Benjamin Kramer.

llvm-svn: 340915
2018-08-29 11:17:31 +00:00
Haojian Wu d2f7b04d1b [clang-tidy] Abseil: no namepsace check
This check ensures that users of Abseil do not open namespace absl in their code, as that violates our compatibility guidelines.

AbseilMatcher.h written by Hugo Gonzalez.

Patch by Deanna Garcia!

llvm-svn: 340800
2018-08-28 07:48:28 +00:00
Haojian Wu 279d72d37d [clang-tidy] Abseil: faster strsplit delimiter check
This check is an abseil specific check that checks for code using single character string literals as delimiters and transforms the code into characters.

The check was developed internally and has been running at google, this is just
a move to open source the check. It was originally written by @sbenza.

Patch by Deanna Garcia!

llvm-svn: 340411
2018-08-22 13:58:25 +00:00
Haojian Wu 5cd630d341 [clang-tidy] Abseil: integral division of Duration check
This check is an abseil specific test that tests to ensure users utilize abseil specific floating point division when trying to divide with abseil duration types.

Patch by Deanna Garcia!

llvm-svn: 340038
2018-08-17 15:19:19 +00:00
Martin Bohme e47a631d1c [clang-tidy] Recognize [[clang::reinitializes]] attribute in bugprone-use-after-move
Summary:
This allows member functions to be marked as reinitializing the object. After a
moved-from object has been reinitialized, the check will no longer consider it
to be in an indeterminate state.

The patch that adds the attribute itself is at https://reviews.llvm.org/D49911

Reviewers: ilya-biryukov, aaron.ballman, alexfh, hokein, rsmith

Reviewed By: aaron.ballman

Subscribers: dblaikie, xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 339571
2018-08-13 14:24:52 +00:00
Aaron Ballman d824f0cbe3 Adding the readability module to the list of dependencies for the C++ Core Guidelines module. Amends r339516 for a failing bot.
llvm-svn: 339517
2018-08-12 14:47:16 +00:00
Aaron Ballman bc8f5ac754 Add a new check to the readability module that flags uses of "magic numbers" (both floating-point and integral).
Patch by Florin Iucha <florin@signbit.net>

llvm-svn: 339516
2018-08-12 14:35:13 +00:00
Alexander Kornienko f337f5b7a5 [clang-tidy: modernize] modernize-redundant-void-arg crashes when a function body is in a macro
Fixes https://bugs.llvm.org/show_bug.cgi?id=28406

Patch by IdrissRio.

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

llvm-svn: 339433
2018-08-10 13:59:33 +00:00
Andi-Bogdan Postelnicu bebcd6fa4d [clang-tidy] run-clang-tidy.py - add synchronisation to the output
Differential Revision: https://reviews.llvm.org/D49851

llvm-svn: 339427
2018-08-10 11:50:47 +00:00
Haojian Wu 25efa0fad3 [clang-tidy] Omit cases where loop variable is not used in loop body in
performance-for-range-copy check.

Summary:
The upstream change r336737 make the check too smart to fix the case
where loop variable could be used as `const auto&`.

But for the case below, changing to `const auto _` will introduce
an unused complier warning.

```
for (auto _ : state) {
  // no references for _.
}
```

This patch omit this case, and it is safe to do it as the case is very rare.

Reviewers: ilya-biryukov, alexfh

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 339415
2018-08-10 08:25:51 +00:00
Stephen Kelly c09197e086 Port getLocEnd -> getEndLoc
Subscribers: nemanjai, ioeric, kbarton, cfe-commits

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

llvm-svn: 339401
2018-08-09 22:43:02 +00:00
Stephen Kelly 43465bf3fd Port getLocStart -> getBeginLoc
Reviewers: javed.absar

Subscribers: nemanjai, kbarton, ilya-biryukov, ioeric, jkorous, arphaman, jfb, cfe-commits

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

llvm-svn: 339400
2018-08-09 22:42:26 +00:00
Martin Bohme b7d621b7b6 [clang-tidy] Sequence init statements, declarations, and conditions correctly in if, switch, and while
Summary: Fixes https://bugs.llvm.org/show_bug.cgi?id=36516.

Reviewers: ilya-biryukov, alexfh, aaron.ballman, hokein

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 338932
2018-08-03 22:20:04 +00:00
Shuai Wang c2d93d6619 Use ExprMutationAnalyzer in performance-unnecessary-value-param
Summary:
This yields better recall as ExprMutationAnalyzer is more accurate.

One common pattern this check is now able to catch is:
```
void foo(std::vector<X> v) {
  for (const auto& elm : v) {
    // ...
  }
}
```

Reviewers: george.karpenkov

Subscribers: a.sidorin, cfe-commits

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

llvm-svn: 338903
2018-08-03 17:23:37 +00:00
Jonas Toth 0b8fdd2847 [clang-tidy] add all clang-tidy modules to plugin
Summary:
This patch addresses PR38359 and adds all existing clang-tidy
modules to the plugin that can be used together with libclang.

Reviewers: alexfh, aaron.ballman, hokein, ilya-biryukov

Reviewed By: alexfh

Subscribers: srhines, mgorny, xazax.hun, cfe-commits

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

llvm-svn: 338393
2018-07-31 15:23:49 +00:00
Ilya Biryukov 778a33a0bb [clang-tidy] Fix a crash in fuchsia-multiple-inheritance
Summary: See the test case for a repro.

Reviewers: juliehockett, ioeric, hokein, aaron.ballman

Reviewed By: hokein

Subscribers: lebedev.ri, xazax.hun, cfe-commits

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

llvm-svn: 338124
2018-07-27 14:05:39 +00:00
Alexander Kornienko 7b6993d445 [clang-tidy] Fix llvm.org/PR38315 (support type aliases in modernize-shrink-to-fit)
llvm-svn: 338025
2018-07-26 13:13:54 +00:00
Jonas Toth ad2524f9fc [clang-tidy] fix PR36489 - respect deduced pointer types from auto as well
Summary:
The cppcoreguidelines-pro-bounds-pointer-arithmetic warns on all occassion where
pointer arithmetic is used, but does not check values where the pointer types
is deduced via `auto`. This patch adjusts this behaviour and solved
PR36489.
I accidentally commited a wrong patch, this Differential is meant to have a
correct revision description and code attached to it.
Because the patch was accepted by aaron.ballman already, i will just commit
it.
See https://reviews.llvm.org/D48717 for the old differntial (contains wrong
code from the mixup)

Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits

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

llvm-svn: 337716
2018-07-23 17:46:17 +00:00
Jonas Toth e8217f6a1f [clang-tidy] remove private decltypeType in TrailingReturnType
Summary:
This patch removes a private matcher in fuchsia/TrailingReturnType check because
the matcher is now in ASTMatchers

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 337707
2018-07-23 16:30:13 +00:00
Idriss Riouak deb8c7d396 [clang-tidy: modernize] Fix modernize-use-equals-default with {} brackets list initialization: patch
Summary:
Hello, i would like to suggest a fix for one of the checks in clang-tidy. 
The bug was reported in https://bugs.llvm.org/show_bug.cgi?id=38039 where you can find more information.

```
struct UOB{
	UOB(const UOB &Other):j{Other.j}{}
	int j;
};
```
In this case the check modernize-use-equals-default does not detect copy constructors that can be defaulted; that should be:

```
struct UOB{
	UOB(const UOB &Other) = default;
	int j;
};
```

Reviewers: aaron.ballman, hokein, alexfh

Reviewed By: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 337286
2018-07-17 14:35:15 +00:00
Adam Balogh e0e5b4cf2e [clang-tidy] Exception Escape Checker
Finds functions which may throw an exception directly or indirectly, but they
should not: Destructors, move constructors, move assignment operators, the
main() function, swap() functions, functions marked with throw() or noexcept
and functions given as option to the checker.

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

llvm-svn: 336997
2018-07-13 13:09:40 +00:00
Sam McCall 57b66c8ba3 [clang-tidy] readability-inconsistent-declaration-parameter-name: accept approximate name matches.
Summary:
The goal is to reduce false positives when the difference is intentional, like:

foo(StringRef name);
foo(StringRef name_ref) {
  string name = cleanup(name_ref);
  ...
}

Or semantically unimportant, like:
foo(StringRef full_name);
foo(StringRef name) { ... }

There are other matching names we won't recognise (e.g. syns vs synonyms) but
this catches many that we see in practice, and gives people a systematic
workaround.

The old behavior is available as a 'Strict' option.

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 336992
2018-07-13 11:41:56 +00:00
Ben Hamilton 13af794726 [clang-tidy/ObjC] Add SQL to list of acronyms
Summary: SQL is a common acronym.

Reviewers: Wizard, hokein

Reviewed By: Wizard, hokein

Subscribers: cfe-commits

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

llvm-svn: 336919
2018-07-12 17:32:55 +00:00
Shuai Wang 0ed0febb3e Use ExprMutationAnalyzer in performance-for-range-copy
Summary:
This gives better coverage to the check as ExprMutationAnalyzer is more
accurate comparing to isOnlyUsedAsConst.

Majority of wins come from const usage of member field, e.g.:
for (auto widget : container) { // copy of loop variable
  if (widget.type == BUTTON) { // const usage only recognized by ExprMutationAnalyzer
    // ...
  }
}

Reviewers: george.karpenkov

Subscribers: a.sidorin, cfe-commits

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

llvm-svn: 336737
2018-07-10 22:51:06 +00:00
Aaron Ballman 5bee05c57b Add the cert-msc51-cpp and cert-msc32-c checks.
These checks flag use of random number generators with poor seeds that would possibly lead to degraded random number generation.

Patch by Borsik Gábor

llvm-svn: 336301
2018-07-05 01:16:31 +00:00
Alexander Kornienko 785322c5e8 [clang-tidy] Fix http://llvm.org/PR38055
llvm-svn: 336283
2018-07-04 15:19:49 +00:00
Alexander Kornienko f7ad8bfbad [clang-tidy] misc-unused-parameters - retain old behavior under StrictMode
Summary: This addresses https://bugs.llvm.org/show_bug.cgi?id=37467.

Reviewers: klimek, ilya-biryukov, lebedev.ri, aaron.ballman

Reviewed By: lebedev.ri, aaron.ballman

Subscribers: aaron.ballman, lebedev.ri, xazax.hun, cfe-commits

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

llvm-svn: 335863
2018-06-28 15:21:25 +00:00
Ben Hamilton 7ea884c58f [clang-tidy/ObjC] Add hashing algorithm acronyms to objc-property-declaration
Summary:
This PR adds a few acronyms related to hashing algorithms to the standard
list in `objc-property-declaration`.

Reviewers: Wizard

Reviewed By: Wizard

Subscribers: cfe-commits

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

llvm-svn: 335770
2018-06-27 19:13:09 +00:00
Alexander Kornienko 271e181c78 [clang-tidy] Add ExprMutationAnalyzer, that analyzes whether an expression is mutated within a statement.
Summary:
(Originally started as a clang-tidy check but there's already D45444 so shifted to just adding ExprMutationAnalyzer)

`ExprMutationAnalyzer` is a generally useful helper that can be used in different clang-tidy checks for checking whether a given expression is (potentially) mutated within a statement (typically the enclosing compound statement.)

This is a more general and more powerful/accurate version of isOnlyUsedAsConst, which is used in ForRangeCopyCheck, UnnecessaryCopyInitialization.

It should also be possible to construct checks like D45444 (suggest adding const to variable declaration) or https://bugs.llvm.org/show_bug.cgi?id=21981 (suggest adding const to member function) using this helper function.

This function is tested by itself and is intended to stay generally useful instead of tied to any particular check.

Reviewers: hokein, alexfh, aaron.ballman, ilya-biryukov, george.karpenkov

Reviewed By: aaron.ballman

Subscribers: lebedev.ri, shuaiwang, rnkovacs, hokein, alexfh, aaron.ballman, a.sidorin, Eugene.Zelenko, xazax.hun, JonasToth, klimek, mgorny, cfe-commits

Tags: #clang-tools-extra

Patch by Shuai Wang.

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

llvm-svn: 335736
2018-06-27 14:30:55 +00:00
Alexander Kornienko 437e026631 [clang-tidy] Remove the google-readability-redundant-smartptr-get alias
I don't remember why I added it, but it's definitely not needed, since the check
doesn't have any options and the check doesn't have any special relation to the
Google C++ style.

llvm-svn: 335252
2018-06-21 16:14:27 +00:00
Zinovy Nis 65d1cf8b16 [clang-tidy] This patch is a fix for D45405 where spaces were mistakenly considered as a part of a type name. So length("int *") was 5 instead of 3 with RemoveStars=0 or 4 with RemoveStars=1
Differential Revision: https://reviews.llvm.org/D45927

llvm-svn: 334829
2018-06-15 13:35:40 +00:00
Aaron Ballman c3fabd98d6 Reverting r334604 due to failing tests.
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/31500

llvm-svn: 334606
2018-06-13 15:02:34 +00:00
Aaron Ballman 0d78a90a7d Add a new class to analyze whether an expression is mutated within a statement.
ExprMutationAnalyzer is a generally useful helper that can be used in different clang-tidy checks for checking whether a given expression is (potentially) mutated within a statement (typically the enclosing compound statement.) This is a more general and more powerful/accurate version of isOnlyUsedAsConst, which is used in ForRangeCopyCheck, UnnecessaryCopyInitialization.

Patch by Shuai Wang

llvm-svn: 334604
2018-06-13 14:41:42 +00:00
Yan Zhang 72cecf9a63 - Add "AV" as new default acronym. - Add support for "I" and "A" in lowerCamelCase pattern
Summary: Now we can support property names like "hasADog" correctly.

Reviewers: benhamilton, hokein

Reviewed By: benhamilton

Subscribers: cfe-commits

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

llvm-svn: 334448
2018-06-11 22:44:06 +00:00
Alexander Kornienko 5f8ede4f0d Add support for arrays in performance-implicit-conversion-in-loop
Summary:
Add support for arrays (and structure that use naked pointers for their iterator, like std::array) in performance-implicit-conversion-in-loop

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: cfe-commits

Patch by Alex Pilkiewicz.

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

llvm-svn: 334400
2018-06-11 12:46:48 +00:00
Haojian Wu 07996a54ba [clang-tidy] Improve string type matcher for abseil-string-find-starts-with check.
Summary:
This patch improves the check to match the desugared "string" type (so that it
can handle custom-implemented string classes), see the newly-added test.

Reviewers: alexfh

Subscribers: klimek, xazax.hun, cfe-commits

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

llvm-svn: 334270
2018-06-08 08:19:22 +00:00
Ben Hamilton 1ca21bb5e6 [checks/property-decls] Fix comment in clang-tidy/objc/PropertyDeclarationCheck.cpp ✍️
Summary: The comment incorrectly claims that the listed acronyms are all extracted from the linked Apple documentation.

Reviewers: Wizard, benhamilton

Reviewed By: Wizard, benhamilton

Subscribers: cfe-commits

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

Contributed by @stephanemoore.

llvm-svn: 334238
2018-06-07 21:30:56 +00:00
Roman Lebedev a87f1d04ce [clang-tidy] Store checks profiling info as JSON files
Summary:
Continuation of D46504.

Example output:
```
  $ clang-tidy -enable-check-profile -store-check-profile=. -checks=-*,readability-function-size source.cpp
  $ # Note that there won't be timings table printed to the console.
  $ cat *.json
  {
  "file": "/path/to/source.cpp",
  "timestamp": "2018-05-16 16:13:18.717446360",
  "profile": {
    "time.clang-tidy.readability-function-size.wall": 1.0421266555786133e+00,
    "time.clang-tidy.readability-function-size.user": 9.2088400000005421e-01,
    "time.clang-tidy.readability-function-size.sys": 1.2418899999999974e-01
  }
  }
```

There are two arguments that control profile storage:

* `-store-check-profile=<prefix>`

  By default reports are printed in tabulated format to stderr. When this option
  is passed, these per-TU profiles are instead stored as JSON.
  If the prefix is not an absolute path, it is considered to be relative to the
  directory from where you have run :program:`clang-tidy`. All `.` and `..`
  patterns in the path are collapsed, and symlinks are resolved.

  Example:
  Let's suppose you have a source file named `example.cpp`, located in
  `/source` directory.

  * If you specify `-store-check-profile=/tmp`, then the profile will be saved
    to `/tmp/<timestamp>-example.cpp.json`

  * If you run :program:`clang-tidy` from within `/foo` directory, and specify
    `-store-check-profile=.`, then the profile will still be saved to
    `/foo/<timestamp>-example.cpp.json`

Reviewers: alexfh, sbenza, george.karpenkov, NoQ, aaron.ballman

Reviewed By: alexfh, george.karpenkov, aaron.ballman

Subscribers: Quuxplusone, JonasToth, aaron.ballman, llvm-commits, rja, Eugene.Zelenko, xazax.hun, mgrang, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 334101
2018-06-06 15:07:51 +00:00
Clement Courbet 1c0a15c444 [clang-tidy] new cppcoreguidelines-narrowing-conversions check.
Summary:
Checks for narrowing conversions, e.g.

int i = 0;
i += 0.1;

This has what some might consider false positives for:
i += ceil(d);

Reviewers: alexfh, hokein

Subscribers: srhines, nemanjai, mgorny, JDevlieghere, xazax.hun, kbarton

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

llvm-svn: 333066
2018-05-23 07:58:41 +00:00
Zinovy Nis 9bfe932c54 [clang-tidy] SimplifyBoolenExpr doesn't add parens if unary negotiation is of ExprWithCleanups type
bool foo(A &S) {
  if (S != (A)S)
    return false;
  return true;
}
is fixed into (w/o this patch)

...
return !S != (A)S; // negotiation affects first operand only
}
instead of (with this patch)

...
return S == (A)S; // note == instead of !=
}

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

llvm-svn: 333003
2018-05-22 17:24:28 +00:00
Alexander Kornienko 85a92c3f0b [clang-tidy] Add a flag to enable alpha checkers
Summary: The alpha checkers can already be enabled using the clang driver, this allows them to be enabled using the clang-tidy as well. This can make it easier to test the alpha checkers with projects which already support the compile_commands.json. It will also allow more people to give feedback and patches about the alpha checkers since they can run it as part of clang tidy checks.

Reviewers: aaron.ballman, hokein, ilya-biryukov, alexfh, lebedev.ri, xbolva00

Reviewed By: aaron.ballman, alexfh, lebedev.ri, xbolva00

Subscribers: xbolva00, NoQ, dcoughlin, lebedev.ri, xazax.hun, cfe-commits

Patch by Paul Fultz II!

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

llvm-svn: 332609
2018-05-17 14:04:27 +00:00