Commit Graph

50 Commits

Author SHA1 Message Date
Alexander Kornienko f1a6552a95 [clang-tidy] 'implicit cast' -> 'implicit conversion'
Summary:
This patch renames checks, check options and changes messages to use correct
term "implicit conversion" instead of "implicit cast" (which has been in use in
Clang AST since ~10 years, but it's still technically incorrect w.r.t. C++
standard).

  * performance-implicit-cast-in-loop -> performance-implicit-conversion-in-loop
  * readability-implicit-bool-cast -> readability-implicit-bool-conversion
    - readability-implicit-bool-cast.AllowConditionalIntegerCasts ->
      readability-implicit-bool-conversion.AllowIntegerConditions
    - readability-implicit-bool-cast.AllowConditionalPointerCasts ->
      readability-implicit-bool-conversion.AllowPointerConditions

Reviewers: hokein, jdennett

Reviewed By: hokein

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

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

llvm-svn: 310366
2017-08-08 14:53:52 +00:00
Manuel Klimek 7b9c117b82 Adapt clang-tidy checks to changing semantics of hasDeclaration.
Differential Revision: https://reviews.llvm.org/D36154

llvm-svn: 309810
2017-08-02 13:13:11 +00:00
Felix Berger 603ea2df2a [clang-tidy] Do not issue fixit for explicit template specializations
Summary:

Do not issue fixit in UnnecessaryValueParamCheck if the function is an explicit template specialization as this could cause build breakages.

Reviewers: alexfh

Subscribers: JDevlieghere, xazax.hun, cfe-commits

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

llvm-svn: 309067
2017-07-26 00:45:41 +00:00
Alexander Kornienko b1c7432117 [clang-tidy] Unify the way IncludeStyle and HeaderFileExtesions options are used
llvm-svn: 308605
2017-07-20 12:02:03 +00:00
Alexander Kornienko 0055d97d4b [clang-tidy] Use getLocalOrGlobal for the StrictMode option
llvm-svn: 304154
2017-05-29 13:59:27 +00:00
Alexander Kornienko b215d473dd [clang-tidy] Speed up performance-unnecessary-value-param check
Moved slower matchers closer to the end. The total speed up on a large file I
was interested in is not huge, just about 10%, since the check seems to be doing
a lot in the check() method.

llvm-svn: 303191
2017-05-16 17:28:17 +00:00
Haojian Wu be6ef0eff9 [clang-tidy] Add "emplace_back" detection in inefficient-vector-operation.
Reviewers: alexfh, aaron.ballman

Reviewed By: alexfh

Subscribers: cfe-commits, Prazek, malcolm.parsons, xazax.hun

Tags: #clang-tools-extra

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

llvm-svn: 303157
2017-05-16 10:39:55 +00:00
Haojian Wu ce4b17fdf3 [clang-tidy] Fix a typo: dequeue => deque
llvm-svn: 303095
2017-05-15 18:18:28 +00:00
Haojian Wu 489f363380 [clang-tidy] Support detecting for-range loop in inefficient-vector-operation check.
Summary:
Also add an option "VectorLikeClasses" allowing user specify customized
vectors.

Reviewers: alexfh, aaron.ballman

Reviewed By: alexfh

Subscribers: Eugene.Zelenko, cfe-commits

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

llvm-svn: 301440
2017-04-26 18:13:05 +00:00
Haojian Wu 8fd72968d4 [clang-tidy] Some Cleanups for performance-faster-string-find check.
NFC

llvm-svn: 301188
2017-04-24 16:41:00 +00:00
Haojian Wu c2c2283223 [clang-tidy] Address a few late comments.
llvm-svn: 300588
2017-04-18 20:47:34 +00:00
Haojian Wu c5cc03377e [clang-tidy] Add a clang-tidy check for possible inefficient vector operations
Summary:
The "performance-inefficient-vector-operation" check finds vector oprations in
for-loop statements which may cause multiple memory reallocations.

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

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

// or

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

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

Reviewers: alexfh, aaron.ballman

Reviewed By: aaron.ballman

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

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

llvm-svn: 300534
2017-04-18 07:46:39 +00:00
Malcolm Parsons 3de05a2fda [clang-tidy] Ignore implicit functions in performance-unnecessary-value-param
Summary:
The performance-unnecessary-value-param check mangled inherited
constructors, as the constructors' parameters do not have useful source
locations. Fix this by ignoring implicit functions.

Fixes PR31684.

Reviewers: flx, alexfh, aaron.ballman

Subscribers: madsravn, JDevlieghere, cfe-commits

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

llvm-svn: 292786
2017-01-23 13:18:08 +00:00
Malcolm Parsons cfa7d3748e [clang-tidy] Handle constructors in performance-unnecessary-value-param
Summary:
modernize-pass-by-value doesn't warn about value parameters that
cannot be moved, so performance-unnecessary-value-param should.

Reviewers: aaron.ballman, flx, alexfh

Subscribers: JDevlieghere, cfe-commits

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

llvm-svn: 290883
2017-01-03 12:10:44 +00:00
Malcolm Parsons 79578cc936 [clang-tidy] Remove duplicated check from move-constructor-init
Summary:
An addition to the move-constructor-init check was duplicating the
modernize-pass-by-value check.
Remove the additional check and UseCERTSemantics option.
Run the move-constructor-init test with both checks enabled.
Fix modernize-pass-by-value false-positive when initializing a base
class.
Add option to modernize-pass-by-value to only warn about parameters
that are already values.

Reviewers: alexfh, flx, aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 290051
2016-12-17 20:23:14 +00:00
Felix Berger 519de4b692 [clang-tidy] Do not move parameter if only DeclRefExpr occurs inside of a loop
Summary: This fixes a bug where the performance-unnecessary-value-param check suggests a fix to move the parameter inside of a loop which could be invoked multiple times.

Reviewers: sbenza, aaron.ballman, alexfh

Subscribers: JDevlieghere, cfe-commits

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

llvm-svn: 289912
2016-12-16 02:47:56 +00:00
Justin Lebar 2edf6f1683 [clang-tidy] Suggest including <cmath> if necessary in type-promotion-in-math-fn-check.
Reviewers: alexfh

Subscribers: JDevlieghere, cfe-commits

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

llvm-svn: 289637
2016-12-14 06:52:23 +00:00
Justin Lebar ecb10f4a9a [ClangTidy] Add new performance-type-promotion-in-math-fn check.
Summary:
This checks for calls to double-precision math.h with single-precision
arguments.  For example, it suggests replacing ::sin(0.f) with
::sinf(0.f).

Subscribers: mgorny, cfe-commits

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

llvm-svn: 289627
2016-12-14 03:15:01 +00:00
Felix Berger e4ab0602f2 [clang-tidy] Do not trigger unnecessary-value-param check on methods marked as final
Summary: Virtual method overrides of dependent types cannot be recognized unless
they are marked as override or final.

Exclude methods marked as final from check and add test.

Reviewers: sbenza, hokein, alexfh

Subscribers: malcolm.parsons, JDevlieghere, cfe-commits

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

llvm-svn: 288502
2016-12-02 14:44:16 +00:00
Felix Berger 85f9e8b316 [clang-tidy] Do not issue fix for functions that are referenced outside of callExpr
Summary: Suppress fixes for functions that are referenced within the
compilation unit outside of a call expression as the signature change
could break the code referencing the function.

We still issue a warning in this case so that users can decide to
manually change the function signature.

Reviewers: alexfh, sbenza, aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 286424
2016-11-10 01:28:22 +00:00
Mandeep Singh Grang 7c7ea7d0ae [clang-tools-extra] Format sources with clang-format. NFC.
Summary:
Ran clang-format on all .c/.cpp/.h files in clang-tools-extra.
Excluded the test, unittests, clang-reorder-fields, include-fixer, modularize and pptrace directories.

Reviewers: klimek, alexfh

Subscribers: nemanjai

Tags: #clang-tools-extra

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

llvm-svn: 286221
2016-11-08 07:50:19 +00:00
Haojian Wu 06e39a3aed [clang-tidy] Don't warn implicit variables in peformance-unnecessary-copy-initialization.
Summary:

This will prevent the check warning the variables which have been
implicitly added by compiler, like the following case (in for-range loop):

  the variable '__end' is copy-constructed from a const reference...

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 286186
2016-11-08 00:45:34 +00:00
Felix Berger 7c6d289d66 [ClangTidy - performance-unnecessary-value-param] Only add "const" when current parameter is not already const qualified
Reviewers: alexfh, sbenza, aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 286010
2016-11-04 20:51:31 +00:00
Alexander Kornienko dcbf57d198 [clang-tidy] Inefficient string operation
Patch by Bittner Barni!

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

llvm-svn: 277677
2016-08-03 23:06:03 +00:00
Kirill Bobyrev 11cea45cce [clang-tidy] remove trailing whitespaces and retab
llvm-svn: 277340
2016-08-01 12:06:18 +00:00
Felix Berger 17934da767 [clang-tidy] UnnecessaryValueParamCheck - only warn for virtual methods
Summary:

As changing virtual methods could break method overrides disable applying the fix and just warn.

Reviewers: alexfh, sbenza

Subscribers: cfe-commits

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

llvm-svn: 274552
2016-07-05 14:40:44 +00:00
Felix Berger 7f8827576c [clang-tidy] UnnecessaryValueParamCheck - suggest std::move() if non-const value parameter can be moved.
Summary:

Make check more useful in the following two cases:

The parameter is passed by non-const value, has a non-deleted move constructor and is only referenced once in the function as argument to the type's copy constructor.
The parameter is passed by non-const value, has a non-deleted move assignment operator and is only referenced once in the function as argument of the the type's copy assignment operator.
In this case suggest a fix to move the parameter which avoids the unnecessary copy and is closest to what the user might have intended.

Reviewers: alexfh, sbenza

Subscribers: cfe-commits, Prazek

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

llvm-svn: 274380
2016-07-01 20:12:15 +00:00
Felix Berger 98e4019a58 [clang-tidy] UnnecessaryCopyInitialization - Extend to trigger on non-const "this" object argument if it is not modified.
Summary:

Also trigger the check in the following case:

void foo() {
  ExpensiveToCopy Obj;
  const auto UnnecessaryCopy = Obj.constReference();
  Obj.onlyUsedAsConst();
}

i.e. when the object the method is called on is not const but is never
modified.

Reviewers: alexfh, fowles

Subscribers: cfe-commits

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

llvm-svn: 271239
2016-05-31 00:25:57 +00:00
Etienne Bergeron e15ef2f609 [clang-tidy] Lift common matchers to utils namespace
Summary:
This patch is lifting matchers used by more than one checkers
to the common namespace.

Reviewers: aaron.ballman, alexfh

Subscribers: aaron.ballman, cfe-commits

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

llvm-svn: 269804
2016-05-17 19:36:09 +00:00
Felix Berger 6d3d746ff5 [clang-tidy] - PerformanceUnnecesaryCopyInitialization - only trigger for decl stmts with single VarDecl.
Summary: This fixes bug: https://llvm.org/bugs/show_bug.cgi?id=27325

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 269389
2016-05-13 02:47:56 +00:00
Etienne Bergeron de1ec03779 [clang-tidy] Lift parsing of sequence of names functions to utils.
Summary:
Lift some common code used by multiple checkers.

This function is also used by checkers that are coming.
It is quite common for a checker to parse a list of names.

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 269065
2016-05-10 15:31:15 +00:00
Etienne Bergeron 2a4c00f243 [clang-tidy] Cleanup namespace in utils folder.
Summary:
This is a step forward cleaning up the namespaces in clang-tidy/utils.
There is no behavior change.

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 268356
2016-05-03 02:54:05 +00:00
Etienne Bergeron 456177b98f [clang-tidy] Cleaning namespaces to be more consistant across checkers.
Summary:
The goal of the patch is to bring checkers in their appropriate namespace.
This path doesn't change any behavior.

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 268264
2016-05-02 18:00:29 +00:00
Etienne Bergeron 2c82ebe813 [clang-tidy] fix a crash with -fdelayed-template-parsing in UnnecessaryValueParamCheck.
Summary:
This is the same kind of bug than [[ http://reviews.llvm.org/D18238 | D18238 ]].

Fix crashes caused by deferencing null pointer when declarations parsing may be delayed.
The body of the declarations may be null.

The crashes were observed with a Windows build of clang-tidy and the following command-line.
```
command-line switches: -fms-compatibility-version=19 -fms-compatibility
```

Reviewers: alexfh

Subscribers: kimgr, LegalizeAdulthood, cfe-commits

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

llvm-svn: 265681
2016-04-07 14:58:13 +00:00
Benjamin Kramer a62e223281 [clang-tidy] Remove unnecessary getName() on Decls and Types feeding into a DiagnosticBuilder
Going through a string removes some of the smarts of the diagnosic printer
and makes the code more complicated. This change has some cosmetic impact
on the output but that's mostly minor.

llvm-svn: 265680
2016-04-07 14:55:25 +00:00
Felix Berger 3c8edde141 [clang-tidy] Add performance check to flag function parameters of expensive to copy types that can be safely converted to const references.
Reviewers: alexfh

Subscribers: fowles, cfe-commits

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

llvm-svn: 264694
2016-03-29 02:42:38 +00:00
Haojian Wu 6ccb1dd9f0 Add check for unneeded copies of locals
Summary: Extends the UnnecessaryCopyInitialization to detect copies of local variables and parameters that are unneeded.

Patch by Matt Kulukundis!

Reviewers: alexfh, hokein

Subscribers: cfe-commits

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

llvm-svn: 264146
2016-03-23 09:33:07 +00:00
Felix Berger adfdc14832 [clang-tidy] Extend UnnecessaryCopyInitialization check to trigger on non-const copies that can be safely converted to const references.
Summary:
Move code shared between UnnecessaryCopyInitialization and ForRangeCopyCheck into utilities files.
Add more test cases for UnnecessaryCopyInitialization and disable fixes inside of macros.

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 262781
2016-03-05 21:17:58 +00:00
Felix Berger f4fdc8aba0 [clang-tidy] Only invoke ForRangeCopyCheck on expensive-to-copy types.
Summary:
Fix oversight not checking the value of the Optional<bool> returned by
isExpensiveToCopy().

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 260870
2016-02-15 03:36:23 +00:00
Samuel Benzaquen 51e1523d70 [clang-tidy] Add check performance-faster-string-find
Summary:
Add check performance-faster-string-find.
It replaces single character string literals to character literals in calls to string::find and friends.

Reviewers: alexfh

Subscribers: cfe-commits

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

llvm-svn: 260712
2016-02-12 19:28:14 +00:00
Alexander Kornienko d0d8878fb6 [clang-tidy] Don't use delegating constructors, since they are not supported by MSVC 2013
llvm-svn: 259214
2016-01-29 17:35:53 +00:00
Alexander Kornienko 5aebfe2e4a [clang-tidy] ForRangeCopyCheck that warns on and fixes unnecessary copies of loop variables.
Patch by Felix Berger!

Differential revision: http://reviews.llvm.org/D13849

llvm-svn: 259199
2016-01-29 15:54:26 +00:00
Alexander Kornienko bfee5f7352 [clang-tidy] Fix minor style issues. NFC
llvm-svn: 259198
2016-01-29 15:22:20 +00:00
Alexander Kornienko 42e8cf4a70 [clang-tidy] Fix style issues. NFC
llvm-svn: 259196
2016-01-29 15:21:43 +00:00
Alexander Kornienko 40d307d120 [clang-tidy] Move implicit-cast-in-loop check to upstream.
Summary: This is implemented originally by Alex Pilkiewicz (pilki@google.com).

Reviewers: alexfh

Subscribers: cfe-commits

Patch by Haojian Wu!

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

llvm-svn: 259195
2016-01-29 15:21:32 +00:00
Chris Bieneman 2cc7fec76a Remove autoconf support
Summary:
This patch is provided in preparation for removing autoconf on 1/26. The proposal to remove autoconf on 1/26 was discussed on the llvm-dev thread here: http://lists.llvm.org/pipermail/llvm-dev/2016-January/093875.html

"Now I am become Death, the destroyer of worlds."
-J. Robert Oppenheimer

Reviewers: chandlerc, grosbach, bob.wilson, echristo

Subscribers: cfe-commits, klimek

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

llvm-svn: 258864
2016-01-26 21:31:36 +00:00
Alexander Kornienko 1589071288 [clang-tidy] Don't use delegating constructors
llvm-svn: 256637
2015-12-30 11:39:30 +00:00
Alexander Kornienko 8d228dda41 [clang-tidy] Use hasLocalStorage() to identify unnecessary copy initializations to exclude static local variables.
Summary: Since local static variables can outlive other local variables exclude them from the unnecessary copy initialization check.

Reviewers: alexfh

Patch by Felix Berger!

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

llvm-svn: 256636
2015-12-30 11:35:50 +00:00
Alexander Kornienko 72a96c66b2 [clang-tidy] Add the missing Makefile
llvm-svn: 256634
2015-12-30 10:56:00 +00:00
Alexander Kornienko b959f4c338 [clang-tidy] Add UnnecessaryCopyInitialization check to new "performance" module in ClangTidy
Summary:
The patch adds a new ClangTidy check that detects when expensive-to-copy types are unnecessarily copy initialized from a const reference that has the same or are larger scope than the copy.

It currently only detects this when the copied variable is const qualified. But this will be extended to non const variables if they are only used in a const fashion.

Reviewers: alexfh

Subscribers: cfe-commits

Patch by Felix Berger!

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

llvm-svn: 256632
2015-12-30 10:24:40 +00:00