summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy
Commit message (Collapse)AuthorAgeFilesLines
...
* [clang-tidy] Use getLocalOrGlobal for the StrictMode optionAlexander Kornienko2017-05-292-2/+4
| | | | llvm-svn: 304154
* (no commit message)Florian Gross2017-05-251-1/+1
| | | | llvm-svn: 303849
* [clang-tidy] Do not dereference a null BaseTypeChih-Hung Hsieh2017-05-231-0/+2
| | | | | | | | | Check BaseType before dereference. Simplified test case is derived from Android Open Source code. Differential Revision: https://reviews.llvm.org/D33430 llvm-svn: 303645
* [clang-tidy] misc-move-const-arg shouldn't complain on std::move(lambda)Alexander Kornienko2017-05-221-0/+6
| | | | llvm-svn: 303554
* [clang-tidy] readability-redundant-declaration false positive for defaulted ↵Alexander Kornienko2017-05-221-5/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | function Summary: ``` template <class T> struct C { C(); }; template <class T> C<T>::C() = default; ``` Causes a readability-redundant-declaration diagnostic. This is caused by `isDefinition` not matching defaulted functions. Reviewers: alexfh, danielmarjamaki Reviewed By: alexfh Subscribers: xazax.hun, cfe-commits Patch by Florian Gross! Differential Revision: https://reviews.llvm.org/D33358 llvm-svn: 303552
* [clang-tidy] readability-braces-around-statements false positive with char ↵Alexander Kornienko2017-05-221-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | literals Summary: Single-line if statements cause a false positive when the last token in the conditional statement is a char constant: ``` if (condition) return 'a'; ``` For some reason `findEndLocation` seems to skips too many (vertical) whitespaces in this case. The same problem already occured with string literals (https://reviews.llvm.org/D25558), and was fixed by adding a special check for this very case. I just extended the condition to also include char constants. No idea what really causes the issue though. Reviewers: alexfh Reviewed By: alexfh Subscribers: xazax.hun, cfe-commits Patch by Florian Gross! Differential Revision: https://reviews.llvm.org/D33354 llvm-svn: 303551
* Fix 'not all control paths return a value' warning on windows buildbots.Simon Pilgrim2017-05-181-0/+1
| | | | llvm-svn: 303344
* [clang-tidy] Optimize GlobList::containsAlexander Kornienko2017-05-182-8/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With large lists of checks and large number of warnings GlobList::contains starts being ridiculously CPU hungry, since it runs regexp match per glob. Caching results of glob matching in a StringMap significantly speeds up check filtering even for small GlobLists. /tmp/q.cc: void f() { int I; {int I;} {int I;} {int I;} ... // 200k times } Before the patch: GlobList with 2 entries: $ time clang-tidy-old -checks=-*,modernize-use-override /tmp/q.cc -- -Wshadow 200000 warnings generated. Suppressed 200000 warnings (200000 with check filters). real 0m3.826s user 0m3.176s sys 0m0.504s GlobList with 28 entries: $ time clang-tidy-old -checks=-*,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,modernize-use-override /tmp/q.cc -- -Wshadow 200000 warnings generated. Suppressed 200000 warnings (200000 with check filters). real 0m5.000s user 0m4.744s sys 0m0.060s GlobList with 158 entries: $ time clang-tidy-old -checks=-*,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,modernize-use-override /tmp/q.cc -- -Wshadow 200000 warnings generated. Suppressed 200000 warnings (200000 with check filters). real 0m13.920s user 0m13.636s sys 0m0.104s With the patch runtime is practically independent from the length of the GlobList: $ time clang-tidy-new -checks=-*,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,modernize-use-override /tmp/q.cc -- -Wshadow 200000 warnings generated. Suppressed 200000 warnings (200000 with check filters). real 0m2.300s user 0m2.104s sys 0m0.044s llvm-svn: 303321
* Change getChecksFilter() interface to hide implementation details.Alexander Kornienko2017-05-174-23/+21
| | | | llvm-svn: 303264
* [clang-tidy] Replace matchesName with hasName where no regex is neededAlexander Kornienko2017-05-172-9/+9
| | | | llvm-svn: 303263
* [clang-tidy] A bit of refactoring of modernize-replace-auto-ptr. NFCAlexander Kornienko2017-05-171-141/+69
| | | | llvm-svn: 303256
* [clang-tidy] Optimize misc-unused-parameters. NFCIAlexander Kornienko2017-05-172-17/+72
| | | | | | | | | Don't traverse AST each time we need to find references to a certain function. Traverse the AST once using RAV and cache the index of function references. The speed up on a particular large file was about 1000x. llvm-svn: 303230
* [clang-tidy] Speed up performance-unnecessary-value-param checkAlexander Kornienko2017-05-161-5/+4
| | | | | | | | 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
* [clang-tidy] Optimize readability-implicit-bool-cast, NFCAlexander Kornienko2017-05-161-10/+10
| | | | | | | Rearrange matchers to put the most expensive ones closer to the end. Speed up another 3-5x on some files. llvm-svn: 303187
* [clang-tidy] Optimize matchers in readability-implicit-bool-cast. NFCAlexander Kornienko2017-05-161-8/+10
| | | | | | | Don't repeat `isInTemplateInstantiation()` and `hasAncestor()` unnecessarily. This speeds up the check by a factor of up to 3 on some large files. llvm-svn: 303180
* [clang-tidy] Add "emplace_back" detection in inefficient-vector-operation.Haojian Wu2017-05-161-16/+20
| | | | | | | | | | | | | | 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
* [clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple callsJakub Kuderski2017-05-162-18/+33
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch makes modernize-use-emplace remove unnecessary make_ calls from push_back calls and turn them into emplace_back -- the same way make_pair calls are handled. Custom make_ calls can be removed for custom tuple-like types -- two new options that control that are `TupleTypes` and `TupleMakeFunctions`. By default, the check removes calls to `std::make_pair` and `std::make_tuple`. Eq. ``` std::vector<std::tuple<int, char, bool>> v; v.push_back(std::make_tuple(1, 'A', true)); // --> v.emplace_back(1, 'A', true); ``` Reviewers: alexfh, aaron.ballman, Prazek, hokein Reviewed By: Prazek Subscribers: JDevlieghere, xazax.hun, JonasToth, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D32690 llvm-svn: 303145
* Revert "[clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls"Jakub Kuderski2017-05-162-33/+18
| | | | | | This reverts commit r303139. The commit made docs build emit a warning. llvm-svn: 303140
* [clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple callsJakub Kuderski2017-05-162-18/+33
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch makes modernize-use-emplace remove unnecessary make_ calls from push_back calls and turn them into emplace_back -- the same way make_pair calls are handled. Custom make_ calls can be removed for custom tuple-like types -- two new options that control that are `TupleTypes` and `TupleMakeFunctions`. By default, the check removes calls to `std::make_pair` and `std::make_tuple`. Eq. ``` std::vector<std::tuple<int, char, bool>> v; v.push_back(std::make_tuple(1, 'A', true)); // --> v.emplace_back(1, 'A', true); ``` Reviewers: alexfh, aaron.ballman, Prazek, hokein Reviewed By: Prazek Subscribers: JDevlieghere, xazax.hun, JonasToth, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D32690 llvm-svn: 303139
* [clang-tidy] Fix a typo: dequeue => dequeHaojian Wu2017-05-151-1/+1
| | | | llvm-svn: 303095
* Make google-build-using-namespace skip std::.*literalsAlexander Kornienko2017-05-152-0/+23
| | | | | | | | | | | | | | | | | | | | Summary: C++14 added a couple of user-defined literals in the standard library. E.g. std::chrono_literals and std::literals::chrono_literals . Using them requires a using directive so do not warn in google-build-using-namespace if namespace name starts with "std::" and ends with "literals". Reviewers: alexfh Reviewed By: alexfh Subscribers: cfe-commits Patch by Martin Ejdestig! Differential Revision: https://reviews.llvm.org/D33010 llvm-svn: 303085
* [clang-tidy] Partly rewrite readability-simplify-boolean-expr using RAVAlexander Kornienko2017-05-152-120/+101
| | | | | | | | | | The check was using AST matchers in a very inefficient manner. By rewriting the BinaryOperator-related parts using RAV, the check was sped up by a factor of up to 10000 on some files (mostly, generated code using binary operators in tables), but also significantly sped up for regular large files. As a side effect, the code became clearer and more readable. llvm-svn: 303081
* [clang-tidy] TwineLocalCheck: add param # checkingYan Wang2017-05-141-1/+4
| | | | | | | | | | | | | | | | | | | Summary: The statement **getArg** tries to get the first one without checking, which may cause segmentation fault. Reviewers: chh, bkramer Reviewed By: bkramer Subscribers: cfe-commits, xazax.hun Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D33103 llvm-svn: 303001
* [clang-tidy][CMake] Make clang-tidy usable as distribution componentPetr Hosek2017-05-101-1/+1
| | | | | | | | | Use add_clang_tool rather than add_clang_executable to support clang-tidy as a distribution component. Differential Revision: https://reviews.llvm.org/D32815 llvm-svn: 302688
* [clang-tidy] Add new cert-dcl21-cpp check Gabor Horvath2017-05-104-0/+128
| | | | | | | | | This check flags postfix operator++/-- declarations, where the return type is not a const object. Differential Revision: https://reviews.llvm.org/D32743 llvm-svn: 302637
* [clang-tidy] Allow disabling compatibility check for generated fixes.Alexander Kornienko2017-05-092-5/+11
| | | | llvm-svn: 302536
* Change EOL style to LF. NFCAlexander Kornienko2017-05-092-765/+765
| | | | llvm-svn: 302534
* [clang-tidy] Minor cleanup + a disabled test case for PR26228. NFCAlexander Kornienko2017-05-091-5/+5
| | | | llvm-svn: 302522
* [clang-tidy] Fix readability-implicit-bool-cast false positivesAlexander Kornienko2017-05-081-1/+2
| | | | | | | | The patch makes the check treat binary conditional operator (`x ?: y`), `while` and regular `for` loops as conditional statements for the purpose of AllowConditional*Cast options. llvm-svn: 302431
* clang-tidy: add IgnoreMacros option to modernize-use-default-member-initMiklos Vajna2017-05-083-2/+9
| | | | | | | | | | | | | | | | | | | Summary: And also enable it by default to be consistent with e.g. modernize-use-using. This helps e.g. when running this check on cppunit client code where the macro is provided by the system, so there is no easy way to modify it. Reviewers: alexfh, malcolm.parsons Reviewed By: malcolm.parsons Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D32945 llvm-svn: 302429
* [clang-tidy] Ignore private =deleted methods in macros.Alexander Kornienko2017-05-081-2/+7
| | | | | | | | modernize-use-equals-delete is extremely noisy in code using DISALLOW_COPY_AND_ASSIGN-style macros and there's no easy way to automatically fix the warning when macros are in play. llvm-svn: 302425
* [clang-tidy] Use cxxStdInitializerListExpr in modernize-use-emplaceJakub Kuderski2017-05-051-9/+1
| | | | | | | | | | | | | | | | Summary: Use the cxxStdInitializerListExp matcher from ASTMatchers.h instead of a local one. Reviewers: aaron.ballman, alexfh, Prazek Reviewed By: aaron.ballman Subscribers: xazax.hun, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D32923 llvm-svn: 302317
* [clang-tidy] Fix PR32896: detect initializer lists in modernize-use-empalceJakub Kuderski2017-05-051-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch fixes [[ https://bugs.llvm.org/show_bug.cgi?id=32896 | PR32896 ]]. The problem was that modernize-use-emplace incorrectly removed changed push_back into emplace_back, removing explicit constructor call with initializer list parameter, resulting in compiler error after applying fixits. modernize-use-emplace used to check if matched constructor had InitListExpr, but didn't check against CXXStdInitializerListExpr. Eg. ``` std::vector<std::vector<int>> v; v.push_back(std::vector<int>({1})); // --> v.emplace_back({1}); ``` Reviewers: Prazek, alexfh, aaron.ballman Reviewed By: Prazek, alexfh, aaron.ballman Subscribers: xazax.hun, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D32767 llvm-svn: 302281
* [clang-tidy] Fix misc-move-const-arg for move-only types.Alexander Kornienko2017-05-051-0/+6
| | | | | | | | | | | | | | Summary: Fix misc-move-const-arg false positives on move-only types. Reviewers: sbenza Reviewed By: sbenza Subscribers: xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D31160 llvm-svn: 302261
* [clang-tidy] fix readability-implicit-bool-cast false positive with xorAlexander Kornienko2017-05-041-15/+17
| | | | llvm-svn: 302164
* [clang-tidy] fix readability-implicit-bool-cast false alarm on |=, &=Alexander Kornienko2017-05-041-24/+24
| | | | llvm-svn: 302161
* [clang-tidy] Code cleanup, (almost) NFC (*).Alexander Kornienko2017-05-041-148/+91
| | | | | | | (*) Printed types of member pointers don't use elaborated type specifiers (`int struct S::*` -> `int S::*`). llvm-svn: 302160
* [clang-tidy] Fix naming convention in modernize-use-emplaceJakub Kuderski2017-04-301-20/+20
| | | | | | | | | | | | | | | | Summary: Conform to the llvm naming convention for local variables in modernize-use-emplace check. Reviewers: Prazek, JonasToth, alexfh Reviewed By: Prazek, JonasToth, alexfh Subscribers: cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D32678 llvm-svn: 301780
* [clang-tidy] Expand AllowConditional*Casts to binary logical operatorsAlexander Kornienko2017-04-291-12/+22
| | | | llvm-svn: 301743
* [clang-tidy] modernize-use-emplace: remove unnecessary make_pair callsJakub Kuderski2017-04-281-14/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: When there is a push_back with a call to make_pair, turn it into emplace_back and remove the unnecessary make_pair call. Eg. ``` std::vector<std::pair<int, int>> v; v.push_back(std::make_pair(1, 2)); // --> v.emplace_back(1, 2); ``` make_pair doesn't get removed when explicit template parameters are provided, because of potential problems with type conversions. Reviewers: Prazek, aaron.ballman, hokein, alexfh Reviewed By: Prazek, alexfh Subscribers: JDevlieghere, JonasToth, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D32395 llvm-svn: 301651
* [clang-tidy] Support detecting for-range loop in ↵Haojian Wu2017-04-262-19/+82
| | | | | | | | | | | | | | | | | | 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
* [clang-tidy] Update IdentifierNamingCheck to remove extra leading/trailing ↵Alexander Kornienko2017-04-261-4/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | underscores Summary: The goal of this change is to fix the following suboptimal replacements currently suggested by clang-tidy: ``` // with MemberPrefix == "_" int __foo; // accepted without complaint ``` ``` // with MemberPrefix == "m_" int _foo; ^~~~~~ m__foo ``` I fixed this by - updating `matchesStyle()` to reject names which have a leading underscore after a prefix has already been stripped, or a trailing underscore if a suffix has already been stripped; - updating `fixupWithStyle()` to strip leading & trailing underscores before adding the user-defined prefix and suffix. The replacements are now: ``` // MemberPrefix == "_" int __foo; ^~~~~~ _foo ``` ``` // MemberPrefix == "m_" int _foo; ^~~~~ m_foo ``` Future improvements might elect to add .clang-tidy flags to improve what is being stripped. For instance, stripping `m_` could allow `m_foo` to be automatically replaced with `_foo`. Reviewers: alexfh Reviewed By: alexfh Subscribers: cfe-commits Patch by Jacob Bandes-Storch! Differential Revision: https://reviews.llvm.org/D32333 llvm-svn: 301431
* [clang-tidy] run-clang-tidy.py: check if clang-apply-replacements succeedsJakub Kuderski2017-04-251-7/+31
| | | | | | | | | | | | | | | | | | | | | | Summary: When running run-clang-tidy.py with -fix it tries to apply found replacements at the end. If there are errors running clang-apply-replacements, the script currently crashes or displays no error at all. This patch checks for errors running clang-apply-replacements the same way clang-tidy binary is handled. Another option would be probably checking for clang-apply-replacements (when -fix is passed) even before running clang-tidy. Reviewers: Prazek, alexfh, bkramer, mfherbst Reviewed By: Prazek, alexfh Subscribers: kimgr, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D32294 llvm-svn: 301365
* [clang-tidy] Some Cleanups for performance-faster-string-find check.Haojian Wu2017-04-241-22/+12
| | | | | | NFC llvm-svn: 301188
* Extend readability-container-size-empty to add comparisons to empty-state ↵Aaron Ballman2017-04-243-5/+81
| | | | | | | | objects. Patch by Josh Zimmerman. llvm-svn: 301185
* [clang-tidy] New check: modernize-replace-random-shuffle.Mads Ravn2017-04-244-0/+155
| | | | | | | | | | | | | | | | | | | | | | This check will find occurrences of ``std::random_shuffle`` and replace it with ``std::shuffle``. In C++17 ``std::random_shuffle`` will no longer be available and thus we need to replace it. Example of case that it fixes ``` std::vector<int> v; // First example std::random_shuffle(vec.begin(), vec.end()); ``` Reviewers: hokein, aaron.ballman, alexfh, malcolm.parsons, mclow.lists Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D30158 llvm-svn: 301167
* [clang-tidy] misc-misplaced-widening-cast: Disable checking of implicit ↵Gabor Horvath2017-04-191-1/+1
| | | | | | | | | | widening casts by default. Patch by Ádám Balogh! Differential Revision: https://reviews.llvm.org/D32164 llvm-svn: 300699
* [clang-tidy] Address a few late comments.Haojian Wu2017-04-181-7/+8
| | | | llvm-svn: 300588
* [clang-tidy] Fix google-explicit-constructor issue with out-of-line conversionsAlexander Kornienko2017-04-181-0/+2
| | | | llvm-svn: 300569
* [clang-tidy] Add a clang-tidy check for possible inefficient vector operationsHaojian Wu2017-04-184-0/+189
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
OpenPOWER on IntegriCloud