Commit Graph

84 Commits

Author SHA1 Message Date
Nathan James e40a742a50 [clang-tidy] Change checks to use new isLanguageVersionSupported restriction
Summary: Modifies all checks that are language version dependent to use `isLanguageVersionSupported`

Reviewers: jdoerfert, lebedev.ri, aaron.ballman, gribozavr2, Eugene.Zelenko

Reviewed By: gribozavr2

Subscribers: wuzish, nemanjai, xazax.hun, hiraditya, kbarton, steven_wu, dexonsmith, arphaman, lebedev.ri, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75340
2020-03-03 16:43:45 +00:00
Benjamin Kramer adcd026838 Make llvm::StringRef to std::string conversions explicit.
This is how it should've been and brings it more in line with
std::string_view. There should be no functional change here.

This is mostly mechanical from a custom clang-tidy check, with a lot of
manual fixups. It uncovers a lot of minor inefficiencies.

This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-28 23:25:25 +01:00
Kazuaki Ishizaki b7ecf1c1c3 NFC: Fix trivial typos in comments 2020-01-04 10:28:41 -05:00
Jonas Toth cf48101200 [clang-tidy] implement utility-function to add 'const' to variables
Summary:
This patch extends the already existing facility to add 'const' to variables
to be more flexible and correct. The previous version did not consider pointers
as value AND pointee. For future automatic introduction for const-correctness
this shortcoming needs to be fixed.
It always allows configuration where the 'const' token is inserted, either on
the left side (if possible) or the right side.
It adds many unit-tests to the utility-function that did not exist before, as
the function was implicitly tested through clang-tidy checks. These
tests were not changed, as the API is still compatible.

Reviewers: aaron.ballman, hokein, alexfh, shuaiwang, lebedev.ri

Reviewed By: aaron.ballman

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D54395
2020-01-03 20:37:47 +01:00
Clement Courbet 95fe54931f [clang-tidy] new performance-no-automatic-move check.
Summary: The check flags constructs that prevent automatic move of local variables.

Reviewers: aaron.ballman

Subscribers: mgorny, xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70390
2019-11-22 08:47:55 +01:00
Tyker b0561b3346 [NFC] Refactor representation of materialized temporaries
Summary:
this patch refactor representation of materialized temporaries to prevent an issue raised by rsmith in https://reviews.llvm.org/D63640#inline-612718

Reviewers: rsmith, martong, shafik

Reviewed By: rsmith

Subscribers: thakis, sammccall, ilya-biryukov, rnkovacs, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69360
2019-11-19 18:20:45 +01:00
Nico Weber c9276fbfdf Revert "[NFC] Refactor representation of materialized temporaries"
This reverts commit 08ea1ee2db.
It broke ./ClangdTests/FindExplicitReferencesTest.All
on the bots, see comments on https://reviews.llvm.org/D69360
2019-11-17 02:09:25 -05:00
Tyker 08ea1ee2db [NFC] Refactor representation of materialized temporaries
Summary:
this patch refactor representation of materialized temporaries to prevent an issue raised by rsmith in https://reviews.llvm.org/D63640#inline-612718

Reviewers: rsmith, martong, shafik

Reviewed By: rsmith

Subscribers: rnkovacs, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69360
2019-11-16 17:56:09 +01:00
Anton Bikineev d36a033310 [clang-tidy] New checker performance-trivially-destructible-check
Checks for types which can be made trivially-destructible by removing
out-of-line defaulted destructor declarations.

The check is motivated by the work on C++ garbage collector in Blink
(rendering engine for Chrome), which strives to minimize destructors and
improve runtime of sweeping phase.

In the entire chromium codebase the check hits over 2000 times.

Differential Revision: https://reviews.llvm.org/D69435
2019-11-01 16:16:49 +01:00
Haojian Wu ad7a7cea89 [clang-tidy] performance-inefficient-vector-operation: Support proto repeated field
Summary:
Finds calls that add element to protobuf repeated field in a loop
without calling Reserve() before the loop. Calling Reserve() first can avoid
unnecessary memory reallocations.

A new option EnableProto is added to guard this feature.

Patch by Cong Liu!

Reviewers: gribozavr, alexfh, hokein, aaron.ballman

Reviewed By: hokein

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

Tags: #clang, #clang-tools-extra

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

llvm-svn: 371963
2019-09-16 08:54:10 +00:00
Dmitri Gribenko 282dc72c8b Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

  for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done

[This is analogous to LLVM r331272 and CFE r331834]

Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits

Tags: #clang

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

llvm-svn: 369643
2019-08-22 11:32:57 +00:00
Jonas Devlieghere 1c705d9c53 [clang-tools-extra] Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances across the monorepo.

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

llvm-svn: 368944
2019-08-14 23:52:23 +00:00
Zinovy Nis 6d83ab0870 [clang-tidy] Add FixItHint for performance-noexcept-move-constructor
Differential Revision: https://reviews.llvm.org/D65104

llvm-svn: 367785
2019-08-04 13:32:39 +00:00
Alexander Kornienko 478fc5c83e [clang-tidy] Switch checks to #include "ClangTidyCheck.h"
llvm-svn: 356892
2019-03-25 12:38:26 +00:00
Alexander Kornienko b6c4db9981 [clang-tidy] Move all checks to the new registerPPCallbacks API
llvm-svn: 356796
2019-03-22 18:58:12 +00:00
Fangrui Song ffe9f00cfe Fix file headers. NFC
llvm-svn: 355188
2019-03-01 09:52:53 +00:00
Chandler Carruth 2946cd7010 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351636
2019-01-19 08:50:56 +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
Bill Wendling ec54d6121c Ignore implicit things like ConstantExpr.
llvm-svn: 346461
2018-11-09 01:32:30 +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
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
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
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
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
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
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
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
Richard Smith 800508b825 Update to match clang r331428.
llvm-svn: 331429
2018-05-03 03:59:50 +00:00
Ben Hamilton b4ab4b6317 [clang-tidy] ObjC ARC objects should not trigger performance-unnecessary-value-param
Summary:
The following Objective-C code currently incorrectly triggers
clang-tidy's performance-unnecessary-value-param check:

```
% cat /tmp/performance-unnecessary-value-param-arc.m
void foo(id object) { }

clang-tidy /tmp/performance-unnecessary-value-param-arc.m
-checks=-\*,performance-unnecessary-value-param -- -xobjective-c
-fobjc-abi-version=2 -fobjc-arc
1 warning generated.
/src/llvm/tools/clang/tools/extra/test/clang-tidy/performance-unnecessary-value-param-arc.m:10:13:
warning: the parameter 'object' is copied for each invocation but only
used as a const reference; consider making it a const reference
[performance-unnecessary-value-param]
void foo(id object) { }
         ~~ ^
         const &
```

This is wrong for a few reasons:

1) Objective-C doesn't have references, so `const &` is not going to help
2) ARC heavily optimizes the "expensive" copy which triggers the warning

This fixes the issue by disabling the warning for non-C++, as well as
disabling it for objects under ARC memory management for
Objective-C++.

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

Test Plan: New tests added. Ran tests with `make -j12 check-clang-tools`.

Reviewers: alexfh, hokein

Reviewed By: hokein

Subscribers: stephanemoore, klimek, xazax.hun, cfe-commits, Wizard

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

llvm-svn: 324097
2018-02-02 15:34:33 +00:00
Alexander Kornienko 1bfcba8cea [clang-tidy] Move more checks from misc- to performance-
Summary:
rename_check.py misc-move-const-arg performance-move-const-arg
rename_check.py misc-noexcept-move-constructor performance-noexcept-move-constructor

Reviewers: hokein, xazax.hun

Reviewed By: xazax.hun

Subscribers: rnkovacs, klimek, mgorny, xazax.hun, cfe-commits

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

llvm-svn: 319183
2017-11-28 16:41:03 +00:00
Alexander Kornienko 6e39e68983 [clang-tidy] Move checks from misc- to performance-
Summary:
rename_check.py misc-move-constructor-init performance-move-constructor-init
rename_check.py misc-inefficient-algorithm performance-inefficient-algorithm

Reviewers: hokein, aaron.ballman

Reviewed By: hokein, aaron.ballman

Subscribers: aaron.ballman, mgorny, xazax.hun, cfe-commits

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

llvm-svn: 319023
2017-11-27 13:06:28 +00:00
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